bpo-43503: Make limited API objects effectively immutable. by ericsnowcurrently · Pull Request #24828 · python/cpython · GitHub
Skip to content
Closed
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
49 changes: 49 additions & 0 deletions Include/internal/pycore_object.h
8 changes: 5 additions & 3 deletions Include/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,7 @@ static inline int _Py_IS_TYPE(const PyObject *ob, const PyTypeObject *type) {
#define Py_IS_TYPE(ob, type) _Py_IS_TYPE(_PyObject_CAST_CONST(ob), type)


static inline void _Py_SET_REFCNT(PyObject *ob, Py_ssize_t refcnt) {
ob->ob_refcnt = refcnt;
}
PyAPI_FUNC(void) _Py_SET_REFCNT(PyObject *ob, Py_ssize_t refcnt);
#define Py_SET_REFCNT(ob, refcnt) _Py_SET_REFCNT(_PyObject_CAST(ob), refcnt)


Expand Down Expand Up @@ -427,6 +425,10 @@ PyAPI_FUNC(void) _Py_NegativeRefcount(const char *filename, int lineno,

PyAPI_FUNC(void) _Py_Dealloc(PyObject *);

#ifdef Py_IMMORTAL_CONST_REFCOUNTS
static inline int _py_is_immortal(PyObject *); // forward
#endif

static inline void _Py_INCREF(PyObject *op)
{
#ifdef Py_REF_DEBUG
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
There is now internal support for "immortal" objects (with a "private"
C-API). Those are objects that will never be deleted, like the
singletons and static types. This will benefit the C-API and
subinterpreters. For now the API is currently intended only
for internal use.
36 changes: 36 additions & 0 deletions Objects/object.c