Skip to content

Commit 60bde52

Browse files
lukasstadlerfangerer
authored andcommitted
create unique addresses for zero-size allocations
1 parent 8b8ba34 commit 60bde52

File tree

1 file changed

+4
-2
lines changed
  • graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/structs

1 file changed

+4
-2
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/structs/CStructAccess.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ protected boolean nativeAccess() {
114114
@Specialization(guards = {"!allocatePyMem", "nativeAccess()"})
115115
static Object allocLong(long size, @SuppressWarnings("unused") boolean allocatePyMem) {
116116
assert size >= 0;
117-
long memory = UNSAFE.allocateMemory(size);
117+
// non-zero size to get unique pointers
118+
long memory = UNSAFE.allocateMemory(size == 0 ? 1 : size);
118119
UNSAFE.setMemory(memory, size, (byte) 0);
119120
return new NativePointer(memory);
120121
}
@@ -123,7 +124,8 @@ static Object allocLong(long size, @SuppressWarnings("unused") boolean allocateP
123124
static Object allocLong(long size, @SuppressWarnings("unused") boolean allocatePyMem,
124125
@Shared @Cached PCallCapiFunction call) {
125126
assert size >= 0;
126-
return call.call(NativeCAPISymbol.FUN_CALLOC, size);
127+
// non-zero size to get unique pointers
128+
return call.call(NativeCAPISymbol.FUN_CALLOC, size == 0 ? 1 : size);
127129
}
128130

129131
@Specialization(guards = "allocatePyMem")

0 commit comments

Comments
 (0)