https://github.com/python/cpython/commit/ba363894bb70556dd7a72e724808bc37d5705f59
commit: ba363894bb70556dd7a72e724808bc37d5705f59
branch: 3.12
author: Alexandra <[email protected]>
committer: encukou <[email protected]>
date: 2025-03-13T15:06:39Z
summary:
[3.12] gh-131181: Assert that PyObject_stgdict isn't NULL for PyCData (#131188)
PyCData types have stgdict, so `PyObject_stgdict` can not return NULL.
Add an assert to make this clear.
files:
M Modules/_ctypes/_ctypes.c
diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c
index 96a057554960e2..d3b496887b5692 100644
--- a/Modules/_ctypes/_ctypes.c
+++ b/Modules/_ctypes/_ctypes.c
@@ -2826,6 +2826,7 @@ PyCData_NewGetBuffer(PyObject *myself, Py_buffer *view,
int flags)
StgDictObject *item_dict = PyType_stgdict(item_type);
if (view == NULL) return 0;
+ assert(dict);
view->buf = self->b_ptr;
view->obj = Py_NewRef(myself);
@@ -2862,7 +2863,10 @@ PyCData_reduce(PyObject *myself, PyObject *args)
{
CDataObject *self = (CDataObject *)myself;
- if (PyObject_stgdict(myself)->flags &
(TYPEFLAG_ISPOINTER|TYPEFLAG_HASPOINTER)) {
+ StgDictObject *stgdict = PyObject_stgdict(myself);
+ assert(stgdict);
+
+ if (stgdict->flags & (TYPEFLAG_ISPOINTER|TYPEFLAG_HASPOINTER)) {
PyErr_SetString(PyExc_ValueError,
"ctypes objects containing pointers cannot be
pickled");
return NULL;
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]