Skip to content

Commit d4342b4

Browse files
committed
gh-145921: Add PyObject_GetItemData to the limited C API and stable ABI
Move PyObject_GetItemData and PyObject_GetItemData_DuringGC from the unstable CPython API (Include/cpython/object.h) to the limited C API (Include/object.h), gated on Py_LIMITED_API >= 3.15, and declare them as part of the stable ABI in Misc/stable_abi.toml.
1 parent 1a0edb1 commit d4342b4

File tree

8 files changed

+21
-3
lines changed

8 files changed

+21
-3
lines changed

Doc/c-api/object.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,10 @@ Object Protocol
624624
625625
.. versionadded:: 3.12
626626
627+
.. versionchanged:: 3.15
628+
629+
Added to the limited C API.
630+
627631
.. c:function:: int PyObject_VisitManagedDict(PyObject *obj, visitproc visit, void *arg)
628632
629633
Visit the managed dictionary of *obj*.

Doc/data/stable_abi.dat

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/cpython/object.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -441,9 +441,6 @@ PyAPI_FUNC(void) _PyTrash_thread_destroy_chain(PyThreadState *tstate);
441441
#define Py_TRASHCAN_END
442442

443443

444-
PyAPI_FUNC(void *) PyObject_GetItemData(PyObject *obj);
445-
PyAPI_FUNC(void *) PyObject_GetItemData_DuringGC(PyObject *obj);
446-
447444
PyAPI_FUNC(int) PyObject_VisitManagedDict(PyObject *obj, visitproc visit, void *arg);
448445
PyAPI_FUNC(void) PyObject_ClearManagedDict(PyObject *obj);
449446

Include/object.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,9 @@ PyAPI_FUNC(PyObject *) PyType_FromMetaclass(PyTypeObject*, PyObject*, PyType_Spe
355355
PyAPI_FUNC(void *) PyObject_GetTypeData(PyObject *obj, PyTypeObject *cls);
356356
PyAPI_FUNC(Py_ssize_t) PyType_GetTypeDataSize(PyTypeObject *cls);
357357
#endif
358+
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= _Py_PACK_VERSION(3, 15)
359+
PyAPI_FUNC(void *) PyObject_GetItemData(PyObject *obj);
360+
#endif
358361
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030E0000
359362
PyAPI_FUNC(int) PyType_GetBaseByToken(PyTypeObject *, void *, PyTypeObject **);
360363
#define Py_TP_USE_SPEC NULL
@@ -781,6 +784,7 @@ PyAPI_FUNC(PyObject *) PyType_GetModuleByToken(PyTypeObject *type,
781784
const void *token);
782785
PyAPI_FUNC(void *) PyObject_GetTypeData_DuringGC(PyObject *obj,
783786
PyTypeObject *cls);
787+
PyAPI_FUNC(void *) PyObject_GetItemData_DuringGC(PyObject *obj);
784788
PyAPI_FUNC(void *) PyType_GetModuleState_DuringGC(PyTypeObject *);
785789
PyAPI_FUNC(int) PyType_GetBaseByToken_DuringGC(PyTypeObject *,
786790
void *, PyTypeObject **);

Lib/test/test_stable_abi_ctypes.py

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Add :c:func:`PyObject_GetItemData` and
2+
:c:func:`PyObject_GetItemData_DuringGC` to the limited C API and stable ABI.

Misc/stable_abi.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2666,8 +2666,13 @@
26662666
[function.Py_SET_SIZE]
26672667
# Before 3.15, this was a macro that accessed the PyObject member
26682668
added = '3.15'
2669+
[function.PyObject_GetItemData]
2670+
# Before 3.15, this was only available in the unstable CPython API
2671+
added = '3.15'
26692672
[function.PyObject_GetTypeData_DuringGC]
26702673
added = '3.15'
2674+
[function.PyObject_GetItemData_DuringGC]
2675+
added = '3.15'
26712676
[function.PyType_GetModuleState_DuringGC]
26722677
added = '3.15'
26732678
[function.PyModule_GetState_DuringGC]

PC/python3dll.c

Lines changed: 2 additions & 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)