Skip to content

Commit 4c003fb

Browse files
committed
pythongh-111506: Rename _Py_SetRefcnt() to Py_SET_REFCNT()
1 parent f8c0198 commit 4c003fb

10 files changed

+81
-65
lines changed

Doc/data/stable_abi.dat

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/object.h

+11-9
Original file line numberDiff line numberDiff line change
@@ -352,15 +352,17 @@ static inline int Py_IS_TYPE(PyObject *ob, PyTypeObject *type) {
352352
#endif
353353

354354

355-
// Py_SET_REFCNT() implementation for stable ABI
356-
PyAPI_FUNC(void) _Py_SetRefcnt(PyObject *ob, Py_ssize_t refcnt);
357-
358-
static inline void Py_SET_REFCNT(PyObject *ob, Py_ssize_t refcnt) {
359355
#if defined(Py_LIMITED_API) && Py_LIMITED_API+0 >= 0x030d0000
360-
// Stable ABI implements Py_SET_REFCNT() as a function call
361-
// on limited C API version 3.13 and newer.
362-
_Py_SetRefcnt(ob, refcnt);
356+
// Stable ABI implements Py_SET_REFCNT() as a function call
357+
// on limited C API version 3.13 and newer.
358+
PyAPI_FUNC(void) Py_SET_REFCNT(PyObject *ob, Py_ssize_t refcnt);
363359
#else
360+
361+
#ifdef _Py_STABLE_ABI_IMPL
362+
# define Py_SET_REFCNT _Py_SET_REFCNT
363+
#endif
364+
365+
static inline void Py_SET_REFCNT(PyObject *ob, Py_ssize_t refcnt) {
364366
// This immortal check is for code that is unaware of immortal objects.
365367
// The runtime tracks these objects and we should avoid as much
366368
// as possible having extensions inadvertently change the refcnt
@@ -394,11 +396,11 @@ static inline void Py_SET_REFCNT(PyObject *ob, Py_ssize_t refcnt) {
394396
ob->ob_ref_shared = _Py_REF_SHARED(refcnt, _Py_REF_MERGED);
395397
}
396398
#endif // Py_GIL_DISABLED
397-
#endif // Py_LIMITED_API+0 < 0x030d0000
398399
}
399-
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
400+
#if (!defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000) && !defined(_Py_STABLE_ABI_IMPL)
400401
# define Py_SET_REFCNT(ob, refcnt) Py_SET_REFCNT(_PyObject_CAST(ob), (refcnt))
401402
#endif
403+
#endif
402404

403405

404406
static inline void Py_SET_TYPE(PyObject *ob, PyTypeObject *type) {

Lib/test/test_stable_abi_ctypes.py

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Makefile.pre.in

+1
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,7 @@ OBJECT_OBJS= \
508508
Objects/moduleobject.o \
509509
Objects/namespaceobject.o \
510510
Objects/object.o \
511+
Objects/object_abi.o \
511512
Objects/obmalloc.o \
512513
Objects/picklebufobject.o \
513514
Objects/rangeobject.o \

Misc/stable_abi.toml

+1-2
Original file line numberDiff line numberDiff line change
@@ -2478,6 +2478,5 @@
24782478
added = '3.13'
24792479
[function.PySys_AuditTuple]
24802480
added = '3.13'
2481-
[function._Py_SetRefcnt]
2481+
[function.Py_SET_REFCNT]
24822482
added = '3.13'
2483-
abi_only = true

Objects/object.c

-52
Original file line numberDiff line numberDiff line change
@@ -2886,55 +2886,3 @@ PyObject_GET_WEAKREFS_LISTPTR(PyObject *op)
28862886
{
28872887
return _PyObject_GET_WEAKREFS_LISTPTR(op);
28882888
}
2889-
2890-
2891-
#undef Py_NewRef
2892-
#undef Py_XNewRef
2893-
2894-
// Export Py_NewRef() and Py_XNewRef() as regular functions for the stable ABI.
2895-
PyObject*
2896-
Py_NewRef(PyObject *obj)
2897-
{
2898-
return _Py_NewRef(obj);
2899-
}
2900-
2901-
PyObject*
2902-
Py_XNewRef(PyObject *obj)
2903-
{
2904-
return _Py_XNewRef(obj);
2905-
}
2906-
2907-
#undef Py_Is
2908-
#undef Py_IsNone
2909-
#undef Py_IsTrue
2910-
#undef Py_IsFalse
2911-
2912-
// Export Py_Is(), Py_IsNone(), Py_IsTrue(), Py_IsFalse() as regular functions
2913-
// for the stable ABI.
2914-
int Py_Is(PyObject *x, PyObject *y)
2915-
{
2916-
return (x == y);
2917-
}
2918-
2919-
int Py_IsNone(PyObject *x)
2920-
{
2921-
return Py_Is(x, Py_None);
2922-
}
2923-
2924-
int Py_IsTrue(PyObject *x)
2925-
{
2926-
return Py_Is(x, Py_True);
2927-
}
2928-
2929-
int Py_IsFalse(PyObject *x)
2930-
{
2931-
return Py_Is(x, Py_False);
2932-
}
2933-
2934-
2935-
// Py_SET_REFCNT() implementation for stable ABI
2936-
void
2937-
_Py_SetRefcnt(PyObject *ob, Py_ssize_t refcnt)
2938-
{
2939-
Py_SET_REFCNT(ob, refcnt);
2940-
}

Objects/object_abi.c

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Stable ABI implementation for PyObject functions.
2+
3+
4+
// Rename static inline functions with macros
5+
#define _Py_STABLE_ABI_IMPL
6+
7+
#include "Python.h"
8+
9+
10+
#undef Py_NewRef
11+
#undef Py_XNewRef
12+
13+
// Export Py_NewRef() and Py_XNewRef() as regular functions for the stable ABI.
14+
PyObject*
15+
Py_NewRef(PyObject *obj)
16+
{
17+
return _Py_NewRef(obj);
18+
}
19+
20+
PyObject*
21+
Py_XNewRef(PyObject *obj)
22+
{
23+
return _Py_XNewRef(obj);
24+
}
25+
26+
27+
#undef Py_Is
28+
#undef Py_IsNone
29+
#undef Py_IsTrue
30+
#undef Py_IsFalse
31+
32+
// Export Py_Is(), Py_IsNone(), Py_IsTrue(), Py_IsFalse() as regular functions
33+
// for the stable ABI.
34+
int Py_Is(PyObject *x, PyObject *y)
35+
{
36+
return (x == y);
37+
}
38+
39+
int Py_IsNone(PyObject *x)
40+
{
41+
return Py_Is(x, Py_None);
42+
}
43+
44+
int Py_IsTrue(PyObject *x)
45+
{
46+
return Py_Is(x, Py_True);
47+
}
48+
49+
int Py_IsFalse(PyObject *x)
50+
{
51+
return Py_Is(x, Py_False);
52+
}
53+
54+
55+
#undef Py_SET_REFCNT
56+
57+
void
58+
Py_SET_REFCNT(PyObject *ob, Py_ssize_t refcnt)
59+
{
60+
_Py_SET_REFCNT(ob, refcnt);
61+
}

PC/python3dll.c

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

PCbuild/pythoncore.vcxproj

+1
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,7 @@
503503
<ClCompile Include="..\Objects\moduleobject.c" />
504504
<ClCompile Include="..\Objects\namespaceobject.c" />
505505
<ClCompile Include="..\Objects\object.c" />
506+
<ClCompile Include="..\Objects\object_abi.c" />
506507
<ClCompile Include="..\Objects\obmalloc.c" />
507508
<ClCompile Include="..\Objects\odictobject.c" />
508509
<ClCompile Include="..\Objects\picklebufobject.c" />

PCbuild/pythoncore.vcxproj.filters

+3
Original file line numberDiff line numberDiff line change
@@ -1142,6 +1142,9 @@
11421142
<ClCompile Include="..\Objects\object.c">
11431143
<Filter>Objects</Filter>
11441144
</ClCompile>
1145+
<ClCompile Include="..\Objects\object_abi.c">
1146+
<Filter>Objects</Filter>
1147+
</ClCompile>
11451148
<ClCompile Include="..\Objects\obmalloc.c">
11461149
<Filter>Objects</Filter>
11471150
</ClCompile>

0 commit comments

Comments
 (0)