Skip to content

Commit d95e3ed

Browse files
committed
gh-148498: Promote PyUnstable_Object_GC_NewWithExtraData() to the stable API
Rename ``PyUnstable_Object_GC_NewWithExtraData`` to ``PyObject_GC_NewWithExtraData`` and add it to the limited API.
1 parent afaf58b commit d95e3ed

File tree

12 files changed

+25
-13
lines changed

12 files changed

+25
-13
lines changed

Doc/c-api/gcsupport.rst

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ rules:
100100
* :c:member:`~PyTypeObject.tp_alloc`
101101

102102

103-
.. c:function:: PyObject* PyUnstable_Object_GC_NewWithExtraData(PyTypeObject *type, size_t extra_size)
103+
.. c:function:: PyObject* PyObject_GC_NewWithExtraData(PyTypeObject *type, size_t extra_size)
104104
105105
Analogous to :c:macro:`PyObject_GC_New` but allocates *extra_size*
106106
bytes at the end of the object (at offset
@@ -115,15 +115,18 @@ rules:
115115
:c:func:`PyObject_GC_Del` (usually called via the object's
116116
:c:member:`~PyTypeObject.tp_free` slot).
117117
118-
.. warning::
119-
The function is marked as unstable because the final mechanism
120-
for reserving extra data after an instance is not yet decided.
121-
For allocating a variable number of fields, prefer using
122-
:c:type:`PyVarObject` and :c:member:`~PyTypeObject.tp_itemsize`
123-
instead.
118+
For allocating a variable number of fields, prefer using
119+
:c:type:`PyVarObject` and :c:member:`~PyTypeObject.tp_itemsize`
120+
instead.
124121
125122
.. versionadded:: 3.12
126123
124+
.. versionchanged:: 3.15
125+
The function is now part of the :ref:`limited API <limited-c-api>`.
126+
127+
Previously, the function was named
128+
``PyUnstable_Object_GC_NewWithExtraData``.
129+
127130
128131
.. c:macro:: PyObject_GC_Resize(TYPE, op, newsize)
129132

Doc/c-api/typeobj.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ and :c:data:`PyType_Type` effectively act as defaults.)
599599
:c:member:`!tp_itemsize` field. For a type with fixed-length instances, all
600600
instances have the same size, given in :c:member:`!tp_basicsize`.
601601
(Exceptions to this rule can be made using
602-
:c:func:`PyUnstable_Object_GC_NewWithExtraData`.)
602+
:c:func:`PyObject_GC_NewWithExtraData`.)
603603

604604
For a type with variable-length instances, the instances must have an
605605
:c:member:`~PyVarObject.ob_size` field, and the instance size is

Doc/data/stable_abi.dat

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

Include/cpython/objimpl.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@ PyAPI_FUNC(int) PyType_SUPPORTS_WEAKREFS(PyTypeObject *type);
8383

8484
PyAPI_FUNC(PyObject **) PyObject_GET_WEAKREFS_LISTPTR(PyObject *op);
8585

86-
PyAPI_FUNC(PyObject *) PyUnstable_Object_GC_NewWithExtraData(PyTypeObject *,
87-
size_t);
86+
8887

8988

9089
/* Visit all live GC-capable objects, similar to gc.get_objects(None). The

Include/objimpl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@ PyAPI_FUNC(void) PyObject_GC_Del(void *);
182182
#define PyObject_GC_NewVar(type, typeobj, n) \
183183
_Py_CAST(type*, _PyObject_GC_NewVar((typeobj), (n)))
184184

185+
PyAPI_FUNC(PyObject *) PyObject_GC_NewWithExtraData(PyTypeObject *, size_t);
186+
185187
PyAPI_FUNC(int) PyObject_GC_IsTracked(PyObject *);
186188
PyAPI_FUNC(int) PyObject_GC_IsFinalized(PyObject *);
187189

Lib/test/test_stable_abi_ctypes.py

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Rename :c:func:`!PyUnstable_Object_GC_NewWithExtraData` to
2+
:c:func:`PyObject_GC_NewWithExtraData` and add it to the
3+
:ref:`limited API <limited-c-api>`.

Misc/stable_abi.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2706,3 +2706,5 @@
27062706
# Note: The `_reserved` member of this struct is for interal use only.
27072707
# (The definition of 'full-abi' was clarified when this entry was added.)
27082708
struct_abi_kind = 'full-abi'
2709+
[function.PyObject_GC_NewWithExtraData]
2710+
added = '3.15'

Modules/_testcapi/gc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ static PyObject *
228228
obj_extra_data_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
229229
{
230230
size_t extra_size = sizeof(PyObject *);
231-
PyObject *obj = PyUnstable_Object_GC_NewWithExtraData(type, extra_size);
231+
PyObject *obj = PyObject_GC_NewWithExtraData(type, extra_size);
232232
if (obj == NULL) {
233233
return PyErr_NoMemory();
234234
}

PC/python3dll.c

Lines 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)