https://github.com/python/cpython/commit/ce51c1881889b6ed9f806d2f3c6551cb03c515da
commit: ce51c1881889b6ed9f806d2f3c6551cb03c515da
branch: main
author: Victor Stinner <[email protected]>
committer: vstinner <[email protected]>
date: 2026-05-04T15:37:45+02:00
summary:

gh-146063: Add PyObject_CallFinalizerFromDealloc() to the limited C API 
(#146172)

Co-authored-by: Petr Viktorin <[email protected]>

files:
A Misc/NEWS.d/next/C_API/2026-03-19-15-28-14.gh-issue-146063.Sc-1RU.rst
M Doc/data/stable_abi.dat
M Doc/whatsnew/3.15.rst
M Include/cpython/object.h
M Include/object.h
M Lib/test/test_stable_abi_ctypes.py
M Misc/stable_abi.toml
M PC/python3dll.c

diff --git a/Doc/data/stable_abi.dat b/Doc/data/stable_abi.dat
index 4ae5e999f0bf21..2ef2bccf2b7728 100644
--- a/Doc/data/stable_abi.dat
+++ b/Doc/data/stable_abi.dat
@@ -565,6 +565,7 @@ func,PyObject_ASCII,3.2,,
 func,PyObject_AsFileDescriptor,3.2,,
 func,PyObject_Bytes,3.2,,
 func,PyObject_Call,3.2,,
+func,PyObject_CallFinalizerFromDealloc,3.15,,
 func,PyObject_CallFunction,3.2,,
 func,PyObject_CallFunctionObjArgs,3.2,,
 func,PyObject_CallMethod,3.2,,
diff --git a/Doc/whatsnew/3.15.rst b/Doc/whatsnew/3.15.rst
index 2a493010ece0fd..a8a779fefa0c85 100644
--- a/Doc/whatsnew/3.15.rst
+++ b/Doc/whatsnew/3.15.rst
@@ -2050,6 +2050,10 @@ New features
 
   (Contributed by Victor Stinner in :gh:`141510`.)
 
+* Add :c:func:`PyObject_CallFinalizerFromDealloc` function to the limited C
+  API.
+  (Contributed by Victor Stinner in :gh:`146063`.)
+
 * Add :c:func:`PySys_GetAttr`, :c:func:`PySys_GetAttrString`,
   :c:func:`PySys_GetOptionalAttr`, and :c:func:`PySys_GetOptionalAttrString`
   functions as replacements for :c:func:`PySys_GetObject`.
diff --git a/Include/cpython/object.h b/Include/cpython/object.h
index 0b50d2a9dd8698..d0b3d0cb14de3d 100644
--- a/Include/cpython/object.h
+++ b/Include/cpython/object.h
@@ -307,7 +307,6 @@ Py_DEPRECATED(3.15) PyAPI_FUNC(PyObject*) 
_PyObject_GetAttrId(PyObject *, _Py_Id
 
 PyAPI_FUNC(PyObject **) _PyObject_GetDictPtr(PyObject *);
 PyAPI_FUNC(void) PyObject_CallFinalizer(PyObject *);
-PyAPI_FUNC(int) PyObject_CallFinalizerFromDealloc(PyObject *);
 
 PyAPI_FUNC(void) PyUnstable_Object_ClearWeakRefsNoCallbacks(PyObject *);
 
diff --git a/Include/object.h b/Include/object.h
index d51132be1a6656..043be0260b1aec 100644
--- a/Include/object.h
+++ b/Include/object.h
@@ -782,6 +782,7 @@ PyAPI_FUNC(int) PyType_Freeze(PyTypeObject *type);
 #endif
 
 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= _Py_PACK_VERSION(3, 15)
+PyAPI_FUNC(int) PyObject_CallFinalizerFromDealloc(PyObject *);
 PyAPI_FUNC(PyObject *) PyType_GetModuleByToken(PyTypeObject *type,
                                                const void *token);
 PyAPI_FUNC(void *) PyObject_GetTypeData_DuringGC(PyObject *obj,
diff --git a/Lib/test/test_stable_abi_ctypes.py 
b/Lib/test/test_stable_abi_ctypes.py
index ed0868e0017fce..5dae5dfccac5d3 100644
--- a/Lib/test/test_stable_abi_ctypes.py
+++ b/Lib/test/test_stable_abi_ctypes.py
@@ -552,6 +552,7 @@ def test_windows_feature_macros(self):
     "PyObject_AsWriteBuffer",
     "PyObject_Bytes",
     "PyObject_Call",
+    "PyObject_CallFinalizerFromDealloc",
     "PyObject_CallFunction",
     "PyObject_CallFunctionObjArgs",
     "PyObject_CallMethod",
diff --git 
a/Misc/NEWS.d/next/C_API/2026-03-19-15-28-14.gh-issue-146063.Sc-1RU.rst 
b/Misc/NEWS.d/next/C_API/2026-03-19-15-28-14.gh-issue-146063.Sc-1RU.rst
new file mode 100644
index 00000000000000..e20e11a754f694
--- /dev/null
+++ b/Misc/NEWS.d/next/C_API/2026-03-19-15-28-14.gh-issue-146063.Sc-1RU.rst
@@ -0,0 +1,2 @@
+Add :c:func:`PyObject_CallFinalizerFromDealloc` function to the limited C API.
+Patch by Victor Stinner.
diff --git a/Misc/stable_abi.toml b/Misc/stable_abi.toml
index 101737a27829c9..e6c63227d20446 100644
--- a/Misc/stable_abi.toml
+++ b/Misc/stable_abi.toml
@@ -2691,7 +2691,6 @@
     added = '3.15'
 
 # PEP 757 import/export API.
-
 [function.PyLong_GetNativeLayout]
     added = '3.15'
 [function.PyLong_Export]
@@ -2715,3 +2714,6 @@
     # Note: The `_reserved` member of this struct is for interal use only.
     # (The definition of 'full-abi' was clarified when this entry was added.)
     struct_abi_kind = 'full-abi'
+
+[function.PyObject_CallFinalizerFromDealloc]
+    added = '3.15'
diff --git a/PC/python3dll.c b/PC/python3dll.c
index abbe35c342c13e..6b9ef0a4164c16 100755
--- a/PC/python3dll.c
+++ b/PC/python3dll.c
@@ -489,6 +489,7 @@ EXPORT_FUNC(PyObject_AsReadBuffer)
 EXPORT_FUNC(PyObject_AsWriteBuffer)
 EXPORT_FUNC(PyObject_Bytes)
 EXPORT_FUNC(PyObject_Call)
+EXPORT_FUNC(PyObject_CallFinalizerFromDealloc)
 EXPORT_FUNC(PyObject_CallFunction)
 EXPORT_FUNC(PyObject_CallFunctionObjArgs)
 EXPORT_FUNC(PyObject_CallMethod)

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to