◐ Shell
reader mode source ↗
Skip to content

gh-71587: Isolate _datetime#102995

Closed
erlend-aasland wants to merge 33 commits into
python:mainfrom
erlend-aasland:isolate-datetime/poc
Closed

gh-71587: Isolate _datetime#102995
erlend-aasland wants to merge 33 commits into
python:mainfrom
erlend-aasland:isolate-datetime/poc

Conversation

@erlend-aasland

@erlend-aasland erlend-aasland commented Mar 24, 2023

Copy link
Copy Markdown
Contributor

@erlend-aasland

erlend-aasland commented Mar 24, 2023

Copy link
Copy Markdown
Contributor Author

Observations:

  • the (fishy) time and datetime memory optimisations may need to go; for now, I tore them out
  • it may be beneficial to store state in object context instead of passing it around
  • the exposed C API is still using a global variable; this is unfortunate

@erlend-aasland

Copy link
Copy Markdown
Contributor Author

@ericsnowcurrently, regarding the datetime C API:

Currently, the encapsulated datetime C API is exposed as a global variable:

cpython/Include/datetime.h

Lines 196 to 197 in e375bff

/* 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;
}

@vstinner vstinner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hide comment

Would it be possible to split the PR into multiple parts? Example:

  • PR 1: Add a module state, refer a few static types there, and pass the state to the easy places to retrieve the type
  • PR 2: Slowly, convert static types, one by one
  • PR 3: Dirty changes
  • PR 4: The final beautiful change which just remove the old code

@erlend-aasland

Copy link
Copy Markdown
Contributor Author

Would it be possible to split the PR into multiple parts? Example:

  • PR 1: Add a module state, refer a few static types there, and pass the state to the easy places to retrieve the type
  • PR 2: Slowly, convert static types, one by one
  • PR 3: Dirty changes
  • PR 4: The final beautiful change which just remove the old code

Definitely!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants