Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 20cfab9

Browse filesBrowse files
authored
gh-111506: Implement Py_SET_REFCNT() as opaque function in limited C API (#111508)
In the limited C API version 3.13, Py_SET_REFCNT() function is now implemented as an opaque function call. Add _Py_SetRefcnt() to the stable ABI.
1 parent e0afed7 commit 20cfab9
Copy full SHA for 20cfab9

File tree

Expand file treeCollapse file tree

6 files changed

+26
-2
lines changed
Filter options
Expand file treeCollapse file tree

6 files changed

+26
-2
lines changed

‎Include/object.h

Copy file name to clipboardExpand all lines: Include/object.h
+11-2Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,15 +327,23 @@ static inline int Py_IS_TYPE(PyObject *ob, PyTypeObject *type) {
327327
#endif
328328

329329

330+
// Py_SET_REFCNT() implementation for stable ABI
331+
PyAPI_FUNC(void) _Py_SetRefcnt(PyObject *ob, Py_ssize_t refcnt);
332+
330333
static inline void Py_SET_REFCNT(PyObject *ob, Py_ssize_t refcnt) {
334+
#if defined(Py_LIMITED_API) && Py_LIMITED_API+0 >= 0x030d0000
335+
// Stable ABI implements Py_SET_REFCNT() as a function call
336+
// on limited C API version 3.13 and newer.
337+
_Py_SetRefcnt(ob, refcnt);
338+
#else
331339
// This immortal check is for code that is unaware of immortal objects.
332340
// The runtime tracks these objects and we should avoid as much
333341
// as possible having extensions inadvertently change the refcnt
334342
// of an immortalized object.
335343
if (_Py_IsImmortal(ob)) {
336344
return;
337345
}
338-
#if !defined(Py_NOGIL)
346+
#ifndef Py_NOGIL
339347
ob->ob_refcnt = refcnt;
340348
#else
341349
if (_Py_IsOwnedByCurrentThread(ob)) {
@@ -352,7 +360,8 @@ static inline void Py_SET_REFCNT(PyObject *ob, Py_ssize_t refcnt) {
352360
ob->ob_ref_local = 0;
353361
ob->ob_ref_shared = _Py_REF_SHARED(refcnt, _Py_REF_MERGED);
354362
}
355-
#endif
363+
#endif // Py_NOGIL
364+
#endif // Py_LIMITED_API+0 < 0x030d0000
356365
}
357366
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
358367
# define Py_SET_REFCNT(ob, refcnt) Py_SET_REFCNT(_PyObject_CAST(ob), (refcnt))

‎Lib/test/test_stable_abi_ctypes.py

Copy file name to clipboardExpand all lines: Lib/test/test_stable_abi_ctypes.py
+1Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
In the limited C API version 3.13, :c:func:`Py_SET_REFCNT` function is now
2+
implemented as an opaque function call. Patch by Victor Stinner.

‎Misc/stable_abi.toml

Copy file name to clipboardExpand all lines: Misc/stable_abi.toml
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2480,3 +2480,6 @@
24802480
added = '3.13'
24812481
[function.PyUnicode_AsUTF8]
24822482
added = '3.13'
2483+
[function._Py_SetRefcnt]
2484+
added = '3.13'
2485+
abi_only = true

‎Objects/object.c

Copy file name to clipboardExpand all lines: Objects/object.c
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2931,3 +2931,11 @@ int Py_IsFalse(PyObject *x)
29312931
{
29322932
return Py_Is(x, Py_False);
29332933
}
2934+
2935+
2936+
// Py_SET_REFCNT() implementation for stable ABI
2937+
void
2938+
_Py_SetRefcnt(PyObject *ob, Py_ssize_t refcnt)
2939+
{
2940+
Py_SET_REFCNT(ob, refcnt);
2941+
}

‎PC/python3dll.c

Copy file name to clipboardExpand all lines: PC/python3dll.c
+1Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.