Commit a110817c authored by Zackery Spytz's avatar Zackery Spytz Committed by Serhiy Storchaka

bpo-36150: Fix possible assertion failures due to _ctypes.c's...

bpo-36150: Fix possible assertion failures due to _ctypes.c's PyCData_reduce(). (GH-12106) (GH-12643)

(cherry picked from commit 5f2c5081)
parent dffe90ee
...@@ -2795,16 +2795,18 @@ static PyObject * ...@@ -2795,16 +2795,18 @@ static PyObject *
PyCData_reduce(PyObject *_self, PyObject *args) PyCData_reduce(PyObject *_self, PyObject *args)
{ {
CDataObject *self = (CDataObject *)_self; CDataObject *self = (CDataObject *)_self;
PyObject *dict;
if (PyObject_stgdict(_self)->flags & (TYPEFLAG_ISPOINTER|TYPEFLAG_HASPOINTER)) { if (PyObject_stgdict(_self)->flags & (TYPEFLAG_ISPOINTER|TYPEFLAG_HASPOINTER)) {
PyErr_SetString(PyExc_ValueError, PyErr_SetString(PyExc_ValueError,
"ctypes objects containing pointers cannot be pickled"); "ctypes objects containing pointers cannot be pickled");
return NULL; return NULL;
} }
return Py_BuildValue("O(O(NN))", dict = PyObject_GetAttrString(_self, "__dict__");
_unpickle, if (dict == NULL) {
Py_TYPE(_self), return NULL;
PyObject_GetAttrString(_self, "__dict__"), }
return Py_BuildValue("O(O(NN))", _unpickle, Py_TYPE(_self), dict,
PyString_FromStringAndSize(self->b_ptr, self->b_size)); PyString_FromStringAndSize(self->b_ptr, self->b_size));
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment