aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Python
diff options
context:
space:
mode:
Diffstat (limited to 'Python')
-rw-r--r--Python/bltinmodule.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c
index 17df9208f22..fb9868b3740 100644
--- a/Python/bltinmodule.c
+++ b/Python/bltinmodule.c
@@ -13,6 +13,7 @@
#include "pycore_pythonrun.h" // _Py_SourceAsString()
#include "pycore_sysmodule.h" // _PySys_GetAttr()
#include "pycore_tuple.h" // _PyTuple_FromArray()
+#include "pycore_cell.h" // PyCell_GetRef()
#include "clinic/bltinmodule.c.h"
@@ -209,7 +210,7 @@ builtin___build_class__(PyObject *self, PyObject *const *args, Py_ssize_t nargs,
PyObject *margs[3] = {name, bases, ns};
cls = PyObject_VectorcallDict(meta, margs, 3, mkw);
if (cls != NULL && PyType_Check(cls) && PyCell_Check(cell)) {
- PyObject *cell_cls = PyCell_GET(cell);
+ PyObject *cell_cls = PyCell_GetRef((PyCellObject *)cell);
if (cell_cls != cls) {
if (cell_cls == NULL) {
const char *msg =
@@ -221,9 +222,13 @@ builtin___build_class__(PyObject *self, PyObject *const *args, Py_ssize_t nargs,
"__class__ set to %.200R defining %.200R as %.200R";
PyErr_Format(PyExc_TypeError, msg, cell_cls, name, cls);
}
+ Py_XDECREF(cell_cls);
Py_SETREF(cls, NULL);
goto error;
}
+ else {
+ Py_DECREF(cell_cls);
+ }
}
}
error: