Skip to content

gh-111506: Rename _Py_SetRefcnt() to Py_SET_REFCNT() #112794

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
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
1 change: 1 addition & 0 deletions Doc/data/stable_abi.dat

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 11 additions & 9 deletions Include/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -352,15 +352,17 @@ static inline int Py_IS_TYPE(PyObject *ob, PyTypeObject *type) {
#endif


// Py_SET_REFCNT() implementation for stable ABI
PyAPI_FUNC(void) _Py_SetRefcnt(PyObject *ob, Py_ssize_t refcnt);

static inline void Py_SET_REFCNT(PyObject *ob, Py_ssize_t refcnt) {
#if defined(Py_LIMITED_API) && Py_LIMITED_API+0 >= 0x030d0000
// Stable ABI implements Py_SET_REFCNT() as a function call
// on limited C API version 3.13 and newer.
_Py_SetRefcnt(ob, refcnt);
// Stable ABI implements Py_SET_REFCNT() as a function call
// on limited C API version 3.13 and newer.
PyAPI_FUNC(void) Py_SET_REFCNT(PyObject *ob, Py_ssize_t refcnt);
#else

#ifdef _Py_STABLE_ABI_IMPL
# define Py_SET_REFCNT _Py_SET_REFCNT
#endif

static inline void Py_SET_REFCNT(PyObject *ob, Py_ssize_t refcnt) {
// This immortal check is for code that is unaware of immortal objects.
// The runtime tracks these objects and we should avoid as much
// as possible having extensions inadvertently change the refcnt
Expand Down Expand Up @@ -394,11 +396,11 @@ static inline void Py_SET_REFCNT(PyObject *ob, Py_ssize_t refcnt) {
ob->ob_ref_shared = _Py_REF_SHARED(refcnt, _Py_REF_MERGED);
}
#endif // Py_GIL_DISABLED
#endif // Py_LIMITED_API+0 < 0x030d0000
}
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
#if (!defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000) && !defined(_Py_STABLE_ABI_IMPL)
# define Py_SET_REFCNT(ob, refcnt) Py_SET_REFCNT(_PyObject_CAST(ob), (refcnt))
#endif
#endif


static inline void Py_SET_TYPE(PyObject *ob, PyTypeObject *type) {
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_stable_abi_ctypes.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Makefile.pre.in
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,7 @@ OBJECT_OBJS= \
Objects/moduleobject.o \
Objects/namespaceobject.o \
Objects/object.o \
Objects/object_abi.o \
Objects/obmalloc.o \
Objects/picklebufobject.o \
Objects/rangeobject.o \
Expand Down
3 changes: 1 addition & 2 deletions Misc/stable_abi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2478,6 +2478,5 @@
added = '3.13'
[function.PySys_AuditTuple]
added = '3.13'
[function._Py_SetRefcnt]
[function.Py_SET_REFCNT]
added = '3.13'
abi_only = true
52 changes: 0 additions & 52 deletions Objects/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -2886,55 +2886,3 @@ PyObject_GET_WEAKREFS_LISTPTR(PyObject *op)
{
return _PyObject_GET_WEAKREFS_LISTPTR(op);
}


#undef Py_NewRef
#undef Py_XNewRef

// Export Py_NewRef() and Py_XNewRef() as regular functions for the stable ABI.
PyObject*
Py_NewRef(PyObject *obj)
{
return _Py_NewRef(obj);
}

PyObject*
Py_XNewRef(PyObject *obj)
{
return _Py_XNewRef(obj);
}

#undef Py_Is
#undef Py_IsNone
#undef Py_IsTrue
#undef Py_IsFalse

// Export Py_Is(), Py_IsNone(), Py_IsTrue(), Py_IsFalse() as regular functions
// for the stable ABI.
int Py_Is(PyObject *x, PyObject *y)
{
return (x == y);
}

int Py_IsNone(PyObject *x)
{
return Py_Is(x, Py_None);
}

int Py_IsTrue(PyObject *x)
{
return Py_Is(x, Py_True);
}

int Py_IsFalse(PyObject *x)
{
return Py_Is(x, Py_False);
}


// Py_SET_REFCNT() implementation for stable ABI
void
_Py_SetRefcnt(PyObject *ob, Py_ssize_t refcnt)
{
Py_SET_REFCNT(ob, refcnt);
}
61 changes: 61 additions & 0 deletions Objects/object_abi.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Stable ABI implementation for PyObject functions.


// Rename static inline functions with macros
#define _Py_STABLE_ABI_IMPL

#include "Python.h"


#undef Py_NewRef
#undef Py_XNewRef

// Export Py_NewRef() and Py_XNewRef() as regular functions for the stable ABI.
PyObject*
Py_NewRef(PyObject *obj)
{
return _Py_NewRef(obj);
}

PyObject*
Py_XNewRef(PyObject *obj)
{
return _Py_XNewRef(obj);
}


#undef Py_Is
#undef Py_IsNone
#undef Py_IsTrue
#undef Py_IsFalse

// Export Py_Is(), Py_IsNone(), Py_IsTrue(), Py_IsFalse() as regular functions
// for the stable ABI.
int Py_Is(PyObject *x, PyObject *y)
{
return (x == y);
}

int Py_IsNone(PyObject *x)
{
return Py_Is(x, Py_None);
}

int Py_IsTrue(PyObject *x)
{
return Py_Is(x, Py_True);
}

int Py_IsFalse(PyObject *x)
{
return Py_Is(x, Py_False);
}


#undef Py_SET_REFCNT

PyAPI_FUNC(void)
Py_SET_REFCNT(PyObject *ob, Py_ssize_t refcnt)
{
_Py_SET_REFCNT(ob, refcnt);
}
2 changes: 1 addition & 1 deletion PC/python3dll.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions PCbuild/pythoncore.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,7 @@
<ClCompile Include="..\Objects\moduleobject.c" />
<ClCompile Include="..\Objects\namespaceobject.c" />
<ClCompile Include="..\Objects\object.c" />
<ClCompile Include="..\Objects\object_abi.c" />
<ClCompile Include="..\Objects\obmalloc.c" />
<ClCompile Include="..\Objects\odictobject.c" />
<ClCompile Include="..\Objects\picklebufobject.c" />
Expand Down
3 changes: 3 additions & 0 deletions PCbuild/pythoncore.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -1142,6 +1142,9 @@
<ClCompile Include="..\Objects\object.c">
<Filter>Objects</Filter>
</ClCompile>
<ClCompile Include="..\Objects\object_abi.c">
<Filter>Objects</Filter>
</ClCompile>
<ClCompile Include="..\Objects\obmalloc.c">
<Filter>Objects</Filter>
</ClCompile>
Expand Down