Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1328b52

Browse files
author
Thomas Heller
committed
Two new public API functions, Py_IncRef and Py_DecRef. Useful for
dynamic embedders of Python.
1 parent 1a9d32b commit 1328b52

4 files changed

Lines changed: 28 additions & 0 deletions

File tree

Doc/api/refcounting.tex

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ \chapter{Reference Counting \label{countingRefs}}
4242
applies.
4343
\end{cfuncdesc}
4444

45+
The following functions are for runtime dynamic embedding of Python:
46+
\cfunction{Py_IncRef(PyObject *o)}, \cfunction{Py_DecRef(PyObject *o)}.
47+
They are simply exported function versions of \cfunction{Py_XINCREF()} and
48+
\cfunction{Py_XDECREF()}, respectively.
49+
4550
The following functions or macros are only for use within the
4651
interpreter core: \cfunction{_Py_Dealloc()},
4752
\cfunction{_Py_ForgetReference()}, \cfunction{_Py_NewReference()}, as

Include/object.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,13 @@ PyAPI_FUNC(void) _Py_AddToAllObjects(PyObject *, int force);
624624
#define Py_XINCREF(op) if ((op) == NULL) ; else Py_INCREF(op)
625625
#define Py_XDECREF(op) if ((op) == NULL) ; else Py_DECREF(op)
626626

627+
/*
628+
These are provided as conveniences to Python runtime embedders, so that
629+
they can have object code that is not dependent on Python compilation flags.
630+
*/
631+
PyAPI_FUNC(void) Py_IncRef(PyObject *);
632+
PyAPI_FUNC(void) Py_DecRef(PyObject *);
633+
627634
/*
628635
_Py_NoneStruct is an object of undefined type which can be used in contexts
629636
where NULL (nil) is not suitable (since NULL often means 'error').

Misc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,10 @@ Build
471471
C API
472472
-----
473473

474+
- New public functions Py_IncRef() and Py_DecRef(), exposing the
475+
functionality of the Py_XINCREF() and Py_XDECREF macros. Useful for
476+
runtime dynamic embedding of Python.
477+
474478
- Added a new macro, PySequence_Fast_ITEMS, which retrieves a fast sequence's
475479
underlying array of PyObject pointers. Useful for high speed looping.
476480

Objects/object.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,18 @@ _Py_NegativeRefcount(const char *fname, int lineno, PyObject *op)
146146

147147
#endif /* Py_REF_DEBUG */
148148

149+
void
150+
Py_IncRef(PyObject *o)
151+
{
152+
Py_XINCREF(o);
153+
}
154+
155+
void
156+
Py_DecRef(PyObject *o)
157+
{
158+
Py_XDECREF(o);
159+
}
160+
149161
PyObject *
150162
PyObject_Init(PyObject *op, PyTypeObject *tp)
151163
{

0 commit comments

Comments
 (0)