diff options
author | Neil Schemenauer <nas-github@arctrix.com> | 2024-12-03 18:33:06 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-12-03 18:33:06 (GMT) |
commit | fc5a0dc22483a35068888e828c65796d7a792c14 (patch) | |
tree | f3c92006e7f12df9515e20346d31abe01c21c800 /Python | |
parent | 276cd66ccbbf85996a57bd1db3dd29b93a6eab64 (diff) | |
download | cpython-fc5a0dc22483a35068888e828c65796d7a792c14.zip cpython-fc5a0dc22483a35068888e828c65796d7a792c14.tar.gz cpython-fc5a0dc22483a35068888e828c65796d7a792c14.tar.bz2 |
gh-127271: Replace use of PyCell_GET/SET (gh-127272)
* Replace uses of `PyCell_GET` and `PyCell_SET`. These macros are not
safe to use in the free-threaded build. Use `PyCell_GetRef()` and
`PyCell_SetTakeRef()` instead.
* Since `PyCell_GetRef()` returns a strong rather than borrowed ref, some
code restructuring was required, e.g. `frame_get_var()` returns a strong
ref now.
* Add critical sections to `PyCell_GET` and `PyCell_SET`.
* Move critical_section.h earlier in the Python.h file.
* Add `PyCell_GET` to the free-threading howto table of APIs that return
borrowed refs.
* Add additional unit tests for free-threading.
Diffstat (limited to 'Python')
-rw-r--r-- | Python/bltinmodule.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index 17df920..fb9868b 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: |