]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
gh-117398: Add datetime Module State (gh-119810)
authorEric Snow <ericsnowcurrently@gmail.com>
Mon, 3 Jun 2024 21:56:00 +0000 (17:56 -0400)
committerGitHub <noreply@github.com>
Mon, 3 Jun 2024 21:56:00 +0000 (15:56 -0600)
commitd82a7ba041321e7b58a5a9bbc394670be6ceeb7c
tree5f3826f33fea97220aa64fb07a591d30d6d46662
parent47fb4327b5c405da6df066dcaa01b7c1aefab313
gh-117398: Add datetime Module State (gh-119810)

I was able to make use of the existing datetime_state struct, but there was one tricky thing I had to sort out.  We mostly aren't converting to heap types, so we can't use things like PyType_GetModuleByDef() to look up the module state.  The solution I came up with is somewhat novel, but I consider it straightforward.  Also, it shouldn't have much impact on performance.

In summary, this main changes here are:

* I've added some macros to help hide how various objects relate to module state
* as a solution to the module state lookup problem, I've stored the last loaded module on the current interpreter's internal dict (actually a weakref)
* if the static type method is used after the module has been deleted, it is reloaded
* to avoid extra work when loading the module, we directly copy the objects (new refs only) from the old module state into the new state if the old module hasn't been deleted yet
* during module init we set various objects on the static types' __dict__s; to simplify things, we only do that the first time; once those static types have a separate __dict__ per interpreter, we'll do it every time
* we now clear the module state when the module is destroyed (before, we were leaking everything in _datetime_global_state)
Include/internal/pycore_global_objects_fini_generated.h
Include/internal/pycore_global_strings.h
Include/internal/pycore_runtime_init_generated.h
Include/internal/pycore_unicodeobject_generated.h
Modules/_datetimemodule.c