Skip to content

Commit 5b6efe0

Browse files
committed
Avoid NPE in ctypes
1 parent ad8fb1d commit 5b6efe0

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/PyCFuncPtrBuiltins.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
*/
4141
package com.oracle.graal.python.builtins.modules.ctypes;
4242

43+
import static com.oracle.graal.python.builtins.PythonBuiltinClassType.NotImplementedError;
4344
import static com.oracle.graal.python.builtins.PythonBuiltinClassType.RuntimeError;
4445
import static com.oracle.graal.python.builtins.modules.ctypes.CDataTypeBuiltins.T__HANDLE;
4546
import static com.oracle.graal.python.builtins.modules.ctypes.CtypesModuleBuiltins.FUNCFLAG_CDECL;
@@ -126,6 +127,7 @@
126127
import com.oracle.graal.python.runtime.PythonContext;
127128
import com.oracle.graal.python.runtime.exception.PException;
128129
import com.oracle.graal.python.runtime.object.PythonObjectFactory;
130+
import com.oracle.truffle.api.CompilerDirectives;
129131
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
130132
import com.oracle.truffle.api.dsl.Bind;
131133
import com.oracle.truffle.api.dsl.Cached;
@@ -499,6 +501,11 @@ Object PyCFuncPtr_call(VirtualFrame frame, PyCFuncPtrObject self, Object[] inarg
499501

500502
int[] props = new int[3];
501503
NativeFunction pProc = handleFromPointerNode.getNativeFunction(inliningTarget, readPointerNode.execute(inliningTarget, self.b_ptr));
504+
if (pProc == null) {
505+
CompilerDirectives.transferToInterpreterAndInvalidate();
506+
// TODO this happens in numpy/core/tests/test_ufunc.py::TestLowlevelAPIAccess::test_loop_access
507+
throw PRaiseNode.raiseUncached(inliningTarget, NotImplementedError, ErrorMessages.CTYPES_FUNCTION_CALL_COULD_NOT_OBTAIN_FUNCTION_POINTER);
508+
}
502509
Object[] callargs = _build_callargs(frame, inliningTarget, self, argtypes, inargs, kwds, props,
503510
pyTypeCheck, getArray, castToJavaIntExactNode, castToTruffleStringNode, pyTypeStgDictNode, callNode, getNameNode, equalNode);
504511
int inoutmask = props[pinoutmask_idx];

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/ErrorMessages.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,6 +1279,7 @@ public abstract class ErrorMessages {
12791279
public static final TruffleString OTHER_ARG_MUST_BE_KEY = tsLiteral("other argument must be K instance");
12801280
public static final TruffleString INVALID_PARTIAL_STATE = tsLiteral("invalid partial state");
12811281
public static final TruffleString LOST_S = tsLiteral("lost %s");
1282+
public static final TruffleString CTYPES_FUNCTION_CALL_COULD_NOT_OBTAIN_FUNCTION_POINTER = tsLiteral("ctypes function call could not obtain function pointer");
12821283

12831284
// ssl error messages
12841285
public static final TruffleString SSL_ERR_DECODING_PEM_FILE_S = tsLiteral("Error decoding PEM-encoded file: %s");

0 commit comments

Comments
 (0)