-
-
Notifications
You must be signed in to change notification settings - Fork 32.8k
gh-91353: Fix void return type handling in ctypes (GH-32246) #32246
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
ctypes used to mishandle ``void`` return types, so that for instance a | ||
function declared like ``ctypes.CFUNCTYPE(None, ctypes.c_int)`` would be | ||
called with signature ``int f(int)`` instead of ``void f(int)``. Wasm | ||
targets require function pointers to be called with the correct signatures | ||
so this led to crashes. The problem is now fixed. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1209,7 +1209,12 @@ PyObject *_ctypes_callproc(PPROC pProc, | |
} | ||
} | ||
|
||
rtype = _ctypes_get_ffi_type(restype); | ||
if (restype == Py_None) { | ||
rtype = &ffi_type_void; | ||
} else { | ||
rtype = _ctypes_get_ffi_type(restype); | ||
} | ||
Comment on lines
+1212
to
+1216
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not familiar with ctypes. Would it make sense to check for None in
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is better? I ran into a similar issue when writing the if (obj == Py_None)
// Set an error, arguments can't have type None! but I'm not that familiar with the ctypes interface -- are we supposed to use if (obj == NULL)
return &ffi_type_sint; looks kind of scary to me. Why did we pass in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
|
||
resbuf = alloca(max(rtype->size, sizeof(ffi_arg))); | ||
|
||
#ifdef _Py_MEMORY_SANITIZER | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change makes sense.
p->ffi_restype
is set about 15 lines earlier.