Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
The C function ``property_descr_get()`` uses a "cached" tuple to optimize
function calls. But this tuple can be discovered in debug mode with
:func:`sys.getobjects()`. Remove the optimization, it's not really worth it
and it causes 3 different crashes last years.
33 changes: 5 additions & 28 deletions Objects/descrobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -1331,42 +1331,19 @@ property_dealloc(PyObject *self)
static PyObject *
property_descr_get(PyObject *self, PyObject *obj, PyObject *type)
{
static PyObject * volatile cached_args = NULL;
PyObject *args;
PyObject *ret;
propertyobject *gs = (propertyobject *)self;

if (obj == NULL || obj == Py_None) {
Py_INCREF(self);
return self;
}

propertyobject *gs = (propertyobject *)self;
if (gs->prop_get == NULL) {
PyErr_SetString(PyExc_AttributeError, "unreadable attribute");
return NULL;
}
args = cached_args;
cached_args = NULL;
if (!args) {
args = PyTuple_New(1);
if (!args)
return NULL;
_PyObject_GC_UNTRACK(args);
}
Py_INCREF(obj);
PyTuple_SET_ITEM(args, 0, obj);
ret = PyObject_Call(gs->prop_get, args, NULL);
if (cached_args == NULL && Py_REFCNT(args) == 1) {
assert(PyTuple_GET_SIZE(args) == 1);
assert(PyTuple_GET_ITEM(args, 0) == obj);
cached_args = args;
Py_DECREF(obj);
}
else {
assert(Py_REFCNT(args) >= 1);
_PyObject_GC_TRACK(args);
Py_DECREF(args);
}
return ret;

PyObject *args[1] = {obj};
return _PyObject_FastCall(gs->prop_get, args, 1);
}

static int
Expand Down