Skip to content

Commit

Permalink
pythongh-111506: Rename _Py_SetRefcnt() to Py_SET_REFCNT()
Browse files Browse the repository at this point in the history
  • Loading branch information
vstinner committed Dec 6, 2023
1 parent f8c0198 commit 22fcb01
Show file tree
Hide file tree
Showing 11 changed files with 85 additions and 65 deletions.
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
4 changes: 4 additions & 0 deletions Include/pyport.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@ typedef Py_ssize_t Py_ssize_clean_t;
# define Py_LOCAL_INLINE(type) static inline type
#endif

#if defined(Py_LIMITED_API) && Py_LIMITED_API+0 < 0x030d0000 && defined(Py_GIL_DISABLED)
# error "Free threading build doesn't support limited C API 3.12 and older"
#endif

#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
# define Py_MEMCPY memcpy
#endif
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

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

0 comments on commit 22fcb01

Please sign in to comment.