8289570: SegmentAllocator:allocateUtf8String(String str) default behavior mismatch to spec

Reviewed-by: alanb, psandoz
This commit is contained in:
Maurizio Cimadamore 2022-07-01 21:46:07 +00:00
parent 20124ac755
commit 8e01ffb3a7
2 changed files with 20 additions and 1 deletions

View File

@ -146,7 +146,7 @@ public final class Utils {
}
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);
return addr;
}

View File

@ -185,6 +185,25 @@ public class TestSegmentAllocators {
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")
public <Z> void testArray(AllocationFactory allocationFactory, ValueLayout layout, AllocationFunction<Object, ValueLayout> allocationFunction, ToArrayHelper<Z> arrayHelper) {