diff -r 15f82b64eee0 Include/objimpl.h --- a/Include/objimpl.h Thu Sep 22 17:11:53 2016 -0700 +++ b/Include/objimpl.h Fri Sep 23 02:15:21 2016 -0400 @@ -228,6 +228,10 @@ /* C equivalent of gc.collect() which ignores the state of gc.enabled. */ PyAPI_FUNC(Py_ssize_t) PyGC_Collect(void); + /* C API for checking and setting the state of the garbage collector */ +PyAPI_FUNC(void) PyGC_Enable(void); +PyAPI_FUNC(void) PyGC_Disable(void); +PyAPI_FUNC(int) PyGC_IsEnabled(void); #ifndef Py_LIMITED_API PyAPI_FUNC(Py_ssize_t) _PyGC_CollectNoFail(void); diff -r 15f82b64eee0 Modules/gcmodule.c --- a/Modules/gcmodule.c Thu Sep 22 17:11:53 2016 -0700 +++ b/Modules/gcmodule.c Fri Sep 23 02:15:21 2016 -0400 @@ -1596,6 +1596,25 @@ return n; } +/* C API for checking and setting the state of the garbage collector */ +void +PyGC_Enable(void) +{ + enabled = 1; +} + +void +PyGC_Disable(void) +{ + enabled = 0; +} + +int +PyGC_IsEnabled(void) +{ + return enabled; +} + Py_ssize_t _PyGC_CollectIfEnabled(void) {