Skip to content

Commit d2e330c

Browse files
committed
handle null shape/strides in PMemoryView wrapper
1 parent 8a03a40 commit d2e330c

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/PyMemoryViewBufferWrapper.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,14 +237,24 @@ static Object getFormat(PMemoryView object, @SuppressWarnings("unused") String k
237237

238238
@Specialization(guards = {"eq(J_SHAPE, key)"})
239239
static Object getShape(PMemoryView object, @SuppressWarnings("unused") String key,
240+
@Shared("toSulong") @Cached CExtNodes.ToSulongNode toSulongNode,
240241
@Shared("toArray") @Cached IntArrayToNativePySSizeArray intArrayToNativePySSizeArray) {
241-
return intArrayToNativePySSizeArray.execute(object.getBufferShape());
242+
int[] shape = object.getBufferShape();
243+
if (shape == null) {
244+
return toSulongNode.execute(PythonContext.get(toSulongNode).getNativeNull());
245+
}
246+
return intArrayToNativePySSizeArray.execute(shape);
242247
}
243248

244249
@Specialization(guards = {"eq(J_STRIDES, key)"})
245250
static Object getStrides(PMemoryView object, @SuppressWarnings("unused") String key,
251+
@Shared("toSulong") @Cached CExtNodes.ToSulongNode toSulongNode,
246252
@Shared("toArray") @Cached IntArrayToNativePySSizeArray intArrayToNativePySSizeArray) {
247-
return intArrayToNativePySSizeArray.execute(object.getBufferStrides());
253+
int[] strides = object.getBufferStrides();
254+
if (strides == null) {
255+
return toSulongNode.execute(PythonContext.get(toSulongNode).getNativeNull());
256+
}
257+
return intArrayToNativePySSizeArray.execute(strides);
248258
}
249259

250260
@Specialization(guards = {"eq(J_SUBOFFSETS, key)"})

0 commit comments

Comments
 (0)