Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions Doc/c-api/gcsupport.rst
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ rules:
* :c:member:`~PyTypeObject.tp_alloc`


.. c:function:: PyObject* PyUnstable_Object_GC_NewWithExtraData(PyTypeObject *type, size_t extra_size)
.. c:function:: PyObject* PyObject_GC_NewWithExtraData(PyTypeObject *type, size_t extra_size)

Analogous to :c:macro:`PyObject_GC_New` but allocates *extra_size*
bytes at the end of the object (at offset
Expand All @@ -115,15 +115,18 @@ rules:
:c:func:`PyObject_GC_Del` (usually called via the object's
:c:member:`~PyTypeObject.tp_free` slot).

.. warning::
The function is marked as unstable because the final mechanism
for reserving extra data after an instance is not yet decided.
For allocating a variable number of fields, prefer using
:c:type:`PyVarObject` and :c:member:`~PyTypeObject.tp_itemsize`
instead.
For allocating a variable number of fields, prefer using
:c:type:`PyVarObject` and :c:member:`~PyTypeObject.tp_itemsize`
instead.

.. versionadded:: 3.12

.. versionchanged:: 3.15
The function is now part of the :ref:`limited API <limited-c-api>`.

Previously, the function was named
``PyUnstable_Object_GC_NewWithExtraData``.


.. c:macro:: PyObject_GC_Resize(TYPE, op, newsize)

Expand Down
2 changes: 1 addition & 1 deletion Doc/c-api/typeobj.rst
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ and :c:data:`PyType_Type` effectively act as defaults.)
:c:member:`!tp_itemsize` field. For a type with fixed-length instances, all
instances have the same size, given in :c:member:`!tp_basicsize`.
(Exceptions to this rule can be made using
:c:func:`PyUnstable_Object_GC_NewWithExtraData`.)
:c:func:`PyObject_GC_NewWithExtraData`.)

For a type with variable-length instances, the instances must have an
:c:member:`~PyVarObject.ob_size` field, and the instance size is
Expand Down
1 change: 1 addition & 0 deletions Doc/data/stable_abi.dat

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions Include/cpython/objimpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ PyAPI_FUNC(int) PyType_SUPPORTS_WEAKREFS(PyTypeObject *type);

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

PyAPI_FUNC(PyObject *) PyUnstable_Object_GC_NewWithExtraData(PyTypeObject *,
size_t);



/* Visit all live GC-capable objects, similar to gc.get_objects(None). The
Expand Down
2 changes: 2 additions & 0 deletions Include/objimpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ PyAPI_FUNC(void) PyObject_GC_Del(void *);
#define PyObject_GC_NewVar(type, typeobj, n) \
_Py_CAST(type*, _PyObject_GC_NewVar((typeobj), (n)))

PyAPI_FUNC(PyObject *) PyObject_GC_NewWithExtraData(PyTypeObject *, size_t);

PyAPI_FUNC(int) PyObject_GC_IsTracked(PyObject *);
PyAPI_FUNC(int) PyObject_GC_IsFinalized(PyObject *);

Expand Down
1 change: 1 addition & 0 deletions Lib/test/test_stable_abi_ctypes.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Rename :c:func:`!PyUnstable_Object_GC_NewWithExtraData` to
:c:func:`PyObject_GC_NewWithExtraData` and add it to the
:ref:`limited API <limited-c-api>`.
2 changes: 2 additions & 0 deletions Misc/stable_abi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2706,3 +2706,5 @@
# 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_GC_NewWithExtraData]
added = '3.15'
2 changes: 1 addition & 1 deletion Modules/_testcapi/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ static PyObject *
obj_extra_data_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
size_t extra_size = sizeof(PyObject *);
PyObject *obj = PyUnstable_Object_GC_NewWithExtraData(type, extra_size);
PyObject *obj = PyObject_GC_NewWithExtraData(type, extra_size);
if (obj == NULL) {
return PyErr_NoMemory();
}
Expand Down
1 change: 1 addition & 0 deletions PC/python3dll.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Python/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -2489,7 +2489,7 @@ _PyObject_GC_NewVar(PyTypeObject *tp, Py_ssize_t nitems)
}

PyObject *
PyUnstable_Object_GC_NewWithExtraData(PyTypeObject *tp, size_t extra_size)
PyObject_GC_NewWithExtraData(PyTypeObject *tp, size_t extra_size)
{
size_t presize = _PyType_PreHeaderSize(tp);
size_t size = _PyObject_SIZE(tp) + extra_size;
Expand Down
2 changes: 1 addition & 1 deletion Python/gc_free_threading.c
Original file line number Diff line number Diff line change
Expand Up @@ -2983,7 +2983,7 @@ _PyObject_GC_NewVar(PyTypeObject *tp, Py_ssize_t nitems)
}

PyObject *
PyUnstable_Object_GC_NewWithExtraData(PyTypeObject *tp, size_t extra_size)
PyObject_GC_NewWithExtraData(PyTypeObject *tp, size_t extra_size)
{
size_t presize = _PyType_PreHeaderSize(tp);
size_t size = _PyObject_SIZE(tp) + extra_size;
Expand Down
Loading