gh-71587: Isolate `_datetime` by erlend-aasland · Pull Request #102995 · python/cpython
@ericsnowcurrently, regarding the datetime C API:
Currently, the encapsulated datetime C API is exposed as a global variable:
| /* Define global variable for the C API and a macro for setting it. */ | |
| static PyDateTime_CAPI *PyDateTimeAPI = NULL; |
I guess we could move this to the interpreter state instead. Thoughts?
FTR, if we run the ref leak bots on this PR, they fail because of the datetime C API tests in testcapi:
| static PyObject * | |
| test_datetime_capi(PyObject *self, PyObject *args) | |
| { | |
| if (PyDateTimeAPI) { | |
| if (test_run_counter) { | |
| /* Probably regrtest.py -R */ | |
| Py_RETURN_NONE; | |
| } | |
| else { | |
| PyErr_SetString(PyExc_AssertionError, | |
| "PyDateTime_CAPI somehow initialized"); | |
| return NULL; | |
| } | |
| } | |
| test_run_counter++; | |
| PyDateTime_IMPORT; | |
| if (PyDateTimeAPI) { | |
| Py_RETURN_NONE; | |
| } | |
| return NULL; | |
| } |