Skip to content

Commit 144eb56

Browse files
authored
gh-102013: Move PyUnstable_GC_VisitObjects() to Include/cpython/objimpl.h (#115560)
Include/objimpl.h must only contain the limited C API, whereas PyUnstable_GC_VisitObjects() is excluded from the limited C API.
1 parent b178eae commit 144eb56

File tree

2 files changed

+17
-19
lines changed

2 files changed

+17
-19
lines changed

Include/cpython/objimpl.h

+17
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,20 @@ PyAPI_FUNC(PyObject **) PyObject_GET_WEAKREFS_LISTPTR(PyObject *op);
8585

8686
PyAPI_FUNC(PyObject *) PyUnstable_Object_GC_NewWithExtraData(PyTypeObject *,
8787
size_t);
88+
89+
90+
/* Visit all live GC-capable objects, similar to gc.get_objects(None). The
91+
* supplied callback is called on every such object with the void* arg set
92+
* to the supplied arg. Returning 0 from the callback ends iteration, returning
93+
* 1 allows iteration to continue. Returning any other value may result in
94+
* undefined behaviour.
95+
*
96+
* If new objects are (de)allocated by the callback it is undefined if they
97+
* will be visited.
98+
99+
* Garbage collection is disabled during operation. Explicitly running a
100+
* collection in the callback may lead to undefined behaviour e.g. visiting the
101+
* same objects multiple times or not at all.
102+
*/
103+
typedef int (*gcvisitobjects_t)(PyObject*, void*);
104+
PyAPI_FUNC(void) PyUnstable_GC_VisitObjects(gcvisitobjects_t callback, void* arg);

Include/objimpl.h

-19
Original file line numberDiff line numberDiff line change
@@ -153,25 +153,6 @@ PyAPI_FUNC(int) PyGC_Enable(void);
153153
PyAPI_FUNC(int) PyGC_Disable(void);
154154
PyAPI_FUNC(int) PyGC_IsEnabled(void);
155155

156-
157-
#if !defined(Py_LIMITED_API)
158-
/* Visit all live GC-capable objects, similar to gc.get_objects(None). The
159-
* supplied callback is called on every such object with the void* arg set
160-
* to the supplied arg. Returning 0 from the callback ends iteration, returning
161-
* 1 allows iteration to continue. Returning any other value may result in
162-
* undefined behaviour.
163-
*
164-
* If new objects are (de)allocated by the callback it is undefined if they
165-
* will be visited.
166-
167-
* Garbage collection is disabled during operation. Explicitly running a
168-
* collection in the callback may lead to undefined behaviour e.g. visiting the
169-
* same objects multiple times or not at all.
170-
*/
171-
typedef int (*gcvisitobjects_t)(PyObject*, void*);
172-
PyAPI_FUNC(void) PyUnstable_GC_VisitObjects(gcvisitobjects_t callback, void* arg);
173-
#endif
174-
175156
/* Test if a type has a GC head */
176157
#define PyType_IS_GC(t) PyType_HasFeature((t), Py_TPFLAGS_HAVE_GC)
177158

0 commit comments

Comments
 (0)