diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2023-06-01 22:24:55 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-01 22:24:55 (GMT) |
commit | c38ceb032d59d6c8f2006ab9a347d7e207f9f84e (patch) | |
tree | a75d62f7309df274b9608acf59edfba201c129c4 /Include | |
parent | 83c7386cee59d8dfe9fa8f5db80ab4afeb3a7b8a (diff) | |
download | cpython-c38ceb032d59d6c8f2006ab9a347d7e207f9f84e.zip cpython-c38ceb032d59d6c8f2006ab9a347d7e207f9f84e.tar.gz cpython-c38ceb032d59d6c8f2006ab9a347d7e207f9f84e.tar.bz2 |
[3.12] gh-105020: Share tp_bases and tp_mro Between Interpreters For All Static Builtin Types (gh-105115) (gh-105124)
In gh-103912 we added tp_bases and tp_mro to each PyInterpreterState.types.builtins entry. However, doing so ignored the fact that both PyTypeObject fields are public API, and not documented as internal (as opposed to tp_subclasses). We address that here by reverting back to shared objects, making them immortal in the process.
(cherry picked from commit 7be667d)
Co-authored-by: Eric Snow ericsnowcurrently@gmail.com
Diffstat (limited to 'Include')
-rw-r--r-- | Include/internal/pycore_object.h | 15 | ||||
-rw-r--r-- | Include/internal/pycore_typeobject.h | 6 |
2 files changed, 17 insertions, 4 deletions
diff --git a/Include/internal/pycore_object.h b/Include/internal/pycore_object.h index 500b3ee..0981d11 100644 --- a/Include/internal/pycore_object.h +++ b/Include/internal/pycore_object.h @@ -76,6 +76,21 @@ static inline void _Py_SetImmortal(PyObject *op) } #define _Py_SetImmortal(op) _Py_SetImmortal(_PyObject_CAST(op)) +/* _Py_ClearImmortal() should only be used during runtime finalization. */ +static inline void _Py_ClearImmortal(PyObject *op) +{ + if (op) { + assert(op->ob_refcnt == _Py_IMMORTAL_REFCNT); + op->ob_refcnt = 1; + Py_DECREF(op); + } +} +#define _Py_ClearImmortal(op) \ + do { \ + _Py_ClearImmortal(_PyObject_CAST(op)); \ + op = NULL; \ + } while (0) + static inline void _Py_DECREF_SPECIALIZED(PyObject *op, const destructor destruct) { diff --git a/Include/internal/pycore_typeobject.h b/Include/internal/pycore_typeobject.h index c7d0000..8f3fbbc 100644 --- a/Include/internal/pycore_typeobject.h +++ b/Include/internal/pycore_typeobject.h @@ -46,11 +46,9 @@ typedef struct { PyTypeObject *type; int readying; int ready; - // XXX tp_dict, tp_bases, and tp_mro can probably be statically - // allocated, instead of dynamically and stored on the interpreter. + // XXX tp_dict can probably be statically allocated, + // instead of dynamically and stored on the interpreter. PyObject *tp_dict; - PyObject *tp_bases; - PyObject *tp_mro; PyObject *tp_subclasses; /* We never clean up weakrefs for static builtin types since they will effectively never get triggered. However, there |