8289570: SegmentAllocator:allocateUtf8String(String str) default behavior mismatch to spec
Reviewed-by: alanb, psandoz
This commit is contained in:
parent
20124ac755
commit
8e01ffb3a7
@ -146,7 +146,7 @@ public final class Utils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static MemorySegment toCString(byte[] bytes, SegmentAllocator allocator) {
|
public static MemorySegment toCString(byte[] bytes, SegmentAllocator allocator) {
|
||||||
MemorySegment addr = allocator.allocate(bytes.length + 1, 1L);
|
MemorySegment addr = allocator.allocate(bytes.length + 1);
|
||||||
copy(addr, bytes);
|
copy(addr, bytes);
|
||||||
return addr;
|
return addr;
|
||||||
}
|
}
|
||||||
|
@ -185,6 +185,25 @@ public class TestSegmentAllocators {
|
|||||||
assertEquals(calls.get(), 7);
|
assertEquals(calls.get(), 7);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testStringAllocateDelegation() {
|
||||||
|
AtomicInteger calls = new AtomicInteger();
|
||||||
|
SegmentAllocator allocator = new SegmentAllocator() {
|
||||||
|
@Override
|
||||||
|
public MemorySegment allocate(long bytesSize, long bytesAlignment) {
|
||||||
|
return MemorySegment.allocateNative(bytesSize, bytesAlignment, MemorySession.openImplicit());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MemorySegment allocate(long size) {
|
||||||
|
calls.incrementAndGet();
|
||||||
|
return allocate(size, 1);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
allocator.allocateUtf8String("Hello");
|
||||||
|
assertEquals(calls.get(), 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test(dataProvider = "arrayAllocations")
|
@Test(dataProvider = "arrayAllocations")
|
||||||
public <Z> void testArray(AllocationFactory allocationFactory, ValueLayout layout, AllocationFunction<Object, ValueLayout> allocationFunction, ToArrayHelper<Z> arrayHelper) {
|
public <Z> void testArray(AllocationFactory allocationFactory, ValueLayout layout, AllocationFunction<Object, ValueLayout> allocationFunction, ToArrayHelper<Z> arrayHelper) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user