Skip to content

Commit

Permalink
pythongh-102013: Move PyUnstable_GC_VisitObjects() to Include/cpython…
Browse files Browse the repository at this point in the history
…/objimpl.h

Include/objimpl.h must only contain the limited C API, whereas
PyUnstable_GC_VisitObjects() is excluded from the limited C API.
  • Loading branch information
vstinner committed Feb 16, 2024
1 parent 351c103 commit 994daa0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
17 changes: 17 additions & 0 deletions Include/cpython/objimpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,20 @@ 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
* supplied callback is called on every such object with the void* arg set
* to the supplied arg. Returning 0 from the callback ends iteration, returning
* 1 allows iteration to continue. Returning any other value may result in
* undefined behaviour.
*
* If new objects are (de)allocated by the callback it is undefined if they
* will be visited.
* Garbage collection is disabled during operation. Explicitly running a
* collection in the callback may lead to undefined behaviour e.g. visiting the
* same objects multiple times or not at all.
*/
typedef int (*gcvisitobjects_t)(PyObject*, void*);
PyAPI_FUNC(void) PyUnstable_GC_VisitObjects(gcvisitobjects_t callback, void* arg);
19 changes: 0 additions & 19 deletions Include/objimpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,25 +153,6 @@ PyAPI_FUNC(int) PyGC_Enable(void);
PyAPI_FUNC(int) PyGC_Disable(void);
PyAPI_FUNC(int) PyGC_IsEnabled(void);


#if !defined(Py_LIMITED_API)
/* Visit all live GC-capable objects, similar to gc.get_objects(None). The
* supplied callback is called on every such object with the void* arg set
* to the supplied arg. Returning 0 from the callback ends iteration, returning
* 1 allows iteration to continue. Returning any other value may result in
* undefined behaviour.
*
* If new objects are (de)allocated by the callback it is undefined if they
* will be visited.
* Garbage collection is disabled during operation. Explicitly running a
* collection in the callback may lead to undefined behaviour e.g. visiting the
* same objects multiple times or not at all.
*/
typedef int (*gcvisitobjects_t)(PyObject*, void*);
PyAPI_FUNC(void) PyUnstable_GC_VisitObjects(gcvisitobjects_t callback, void* arg);
#endif

/* Test if a type has a GC head */
#define PyType_IS_GC(t) PyType_HasFeature((t), Py_TPFLAGS_HAVE_GC)

Expand Down

0 comments on commit 994daa0

Please sign in to comment.