Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[3.13] gh-144100: Fix crash for POINTER(str) used in ctypes argtypes (#144108)#144245

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
vstinner wants to merge1 commit intopython:3.13
base:3.13
Choose a base branch
Loading
fromvstinner:ctypes13
Open
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletionsLib/test/test_ctypes/test_pointers.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -235,6 +235,17 @@ class C(Structure):
ptr.set_type(c_int)
self.assertIs(ptr._type_, c_int)

def test_pointer_proto_missing_argtypes_error(self):
class BadType(ctypes._Pointer):
# _type_ is intentionally missing
pass

func = ctypes.pythonapi.Py_GetVersion
func.argtypes = (BadType,)

with self.assertRaises(ctypes.ArgumentError):
func(object())


if __name__ == '__main__':
unittest.main()
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
Fixed a crash in ctypes when using a deprecated ``POINTER(str)`` type in
``argtypes``. Instead of aborting, ctypes now raises a proper Python
exception when the pointer target type is unresolved.
8 changes: 7 additions & 1 deletionModules/_ctypes/_ctypes.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1338,7 +1338,13 @@ PyCPointerType_from_param_impl(PyObject *type, PyTypeObject *cls,
/* If we expect POINTER(<type>), but receive a <type> instance, accept
it by calling byref(<type>).
*/
assert(typeinfo->proto);
if (typeinfo->proto == NULL) {
PyErr_SetString(
PyExc_TypeError,
"cannot convert argument: POINTER _type_ type is not set"
);
return NULL;
}
switch (PyObject_IsInstance(value, typeinfo->proto)) {
case 1:
Py_INCREF(value); /* _byref steals a refcount */
Expand Down
Loading

[8]ページ先頭

©2009-2026 Movatter.jp