diff options
author | Jacob Bower <1978924+jbower-fb@users.noreply.github.com> | 2023-03-14 01:35:54 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-14 01:35:54 (GMT) |
commit | cbd3fbfb6e5c1cc96bbeb99483a580f165b01671 (patch) | |
tree | 7e0e0ea4c7dc40b48528702c1c0c32914d9798f7 /Include/objimpl.h | |
parent | 457e4d1a516c2b83edeff2f255f4cd6e7b114feb (diff) | |
download | cpython-cbd3fbfb6e5c1cc96bbeb99483a580f165b01671.zip cpython-cbd3fbfb6e5c1cc96bbeb99483a580f165b01671.tar.gz cpython-cbd3fbfb6e5c1cc96bbeb99483a580f165b01671.tar.bz2 |
gh-102013: Add PyUnstable_GC_VisitObjects (#102014)
Diffstat (limited to 'Include/objimpl.h')
-rw-r--r-- | Include/objimpl.h | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/Include/objimpl.h b/Include/objimpl.h index dde8df3..ef871c5 100644 --- a/Include/objimpl.h +++ b/Include/objimpl.h @@ -157,6 +157,25 @@ 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) |