Skip to content

Commit 6ca7710

Browse files
committed
Fix: avoid writing Java null to native
1 parent 4e46046 commit 6ca7710

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1246,11 +1246,10 @@ public final boolean accepts(ArgDescriptor desc) {
12461246
return desc.isPyObject();
12471247
}
12481248

1249-
public final void writeArray(Object pointer, Object[] values) {
1250-
writeArray(pointer, values, values.length, 0, 0);
1251-
}
1252-
12531249
public final void writeArray(Object pointer, Object[] values, int length, int sourceOffset, int targetOffset) {
1250+
if (length > values.length) {
1251+
throw CompilerDirectives.shouldNotReachHere();
1252+
}
12541253
for (int i = 0; i < length; i++) {
12551254
execute(pointer, (i + targetOffset) * POINTER_SIZE, values[i + sourceOffset]);
12561255
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/SequenceStorageNodes.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1448,19 +1448,19 @@ public final NativeSequenceStorage execute(Node inliningTarget, Object obj, int
14481448

14491449
@Specialization
14501450
static NativeByteSequenceStorage doByte(byte[] arr, int length, boolean createRef,
1451-
@Exclusive @Cached(inline = false) CStructAccess.AllocateNode alloc,
1451+
@Shared @Cached(inline = false) CStructAccess.AllocateNode alloc,
14521452
@Cached(inline = false) CStructAccess.WriteByteNode write) {
1453-
Object mem = alloc.alloc(arr.length + 1);
1453+
Object mem = alloc.calloc(arr.length + 1, java.lang.Byte.BYTES);
14541454
write.writeByteArray(mem, arr);
14551455
return NativeByteSequenceStorage.create(mem, length, arr.length, createRef);
14561456
}
14571457

14581458
@Specialization
14591459
static NativeSequenceStorage doObject(Object[] arr, int length, boolean createRef,
1460-
@Exclusive @Cached(inline = false) CStructAccess.AllocateNode alloc,
1460+
@Shared @Cached(inline = false) CStructAccess.AllocateNode alloc,
14611461
@Cached(inline = false) CStructAccess.WriteObjectNewRefNode write) {
1462-
Object mem = alloc.alloc((arr.length + 1) * CStructAccess.POINTER_SIZE);
1463-
write.writeArray(mem, arr);
1462+
Object mem = alloc.calloc(arr.length + 1, CStructAccess.POINTER_SIZE);
1463+
write.writeArray(mem, arr, length, 0, 0);
14641464
return NativeObjectSequenceStorage.create(mem, length, arr.length, createRef);
14651465
}
14661466
}

0 commit comments

Comments
 (0)