@@ -344,6 +344,55 @@ extern void _PyGC_VisitObjectsWorldStopped(PyInterpreterState *interp,
344344 gcvisitobjects_t callback , void * arg );
345345#endif
346346
347+ struct _Ci_PyGCImpl ;
348+
349+ /*
350+ * Collect cyclic garbage.
351+ *
352+ * impl - Pointer to the collection implementation.
353+ * tstate - Indirectly specifies (via tstate->interp) the interpreter
354+ for which collection should be performed.
355+ * generation - Collect generations <= this value
356+ * reason - Why we're collecting
357+ */
358+ typedef Py_ssize_t (* Ci_gc_collect_t )(struct _Ci_PyGCImpl * impl , PyThreadState * tstate ,
359+ int generation , _PyGC_Reason reason );
360+
361+ // Free a collector
362+ typedef void (* Ci_gc_finalize_t )(struct _Ci_PyGCImpl * impl );
363+
364+ // An implementation of cyclic garbage collection
365+ typedef struct _Ci_PyGCImpl {
366+ Ci_gc_collect_t collect ;
367+ Ci_gc_finalize_t finalize ;
368+ } _Ci_PyGCImpl ;
369+
370+ struct _gc_runtime_state ;
371+
372+ /*
373+ * Set the collection implementation.
374+ *
375+ * The callee takes ownership of impl.
376+ *
377+ * Returns a pointer to the previous impl, which the caller is responsible for freeing
378+ * using the returned impl's finalize().
379+ */
380+ PyAPI_FUNC (_Ci_PyGCImpl * ) _Ci_PyGC_SetImpl (struct _gc_runtime_state * gc_state , _Ci_PyGCImpl * impl );
381+
382+ /*
383+ * Returns a pointer to the current GC implementation but does not transfer
384+ * ownership to the caller.
385+ */
386+ PyAPI_FUNC (_Ci_PyGCImpl * ) _Ci_PyGC_GetImpl (struct _gc_runtime_state * gc_state );
387+
388+ /*
389+ * Clear free lists (e.g. frames, tuples, etc.) for the given interpreter.
390+ *
391+ * This should be called by GC implementations after collecting the highest
392+ * generation.
393+ */
394+ PyAPI_FUNC (void ) _Ci_PyGC_ClearFreeLists (PyInterpreterState * interp );
395+
347396#ifdef __cplusplus
348397}
349398#endif
0 commit comments