mirror of https://github.com/python/cpython
39510dadde
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)
(cherry picked from commit
|
||
---|---|---|
.. | ||
cpython | ||
internal | ||
Python.h | ||
README.rst | ||
abstract.h | ||
bltinmodule.h | ||
boolobject.h | ||
bytearrayobject.h | ||
bytesobject.h | ||
ceval.h | ||
codecs.h | ||
compile.h | ||
complexobject.h | ||
datetime.h | ||
descrobject.h | ||
dictobject.h | ||
dynamic_annotations.h | ||
enumobject.h | ||
errcode.h | ||
exports.h | ||
fileobject.h | ||
fileutils.h | ||
floatobject.h | ||
frameobject.h | ||
genericaliasobject.h | ||
import.h | ||
intrcheck.h | ||
iterobject.h | ||
listobject.h | ||
longobject.h | ||
marshal.h | ||
memoryobject.h | ||
methodobject.h | ||
modsupport.h | ||
moduleobject.h | ||
monitoring.h | ||
object.h | ||
objimpl.h | ||
opcode.h | ||
opcode_ids.h | ||
osdefs.h | ||
osmodule.h | ||
patchlevel.h | ||
py_curses.h | ||
pyatomic.h | ||
pybuffer.h | ||
pycapsule.h | ||
pydtrace.d | ||
pydtrace.h | ||
pyerrors.h | ||
pyexpat.h | ||
pyframe.h | ||
pyhash.h | ||
pylifecycle.h | ||
pymacconfig.h | ||
pymacro.h | ||
pymath.h | ||
pymem.h | ||
pyport.h | ||
pystate.h | ||
pystats.h | ||
pystrcmp.h | ||
pystrtod.h | ||
pythonrun.h | ||
pythread.h | ||
pytypedefs.h | ||
rangeobject.h | ||
setobject.h | ||
sliceobject.h | ||
structmember.h | ||
structseq.h | ||
sysmodule.h | ||
traceback.h | ||
tupleobject.h | ||
typeslots.h | ||
unicodeobject.h | ||
warnings.h | ||
weakrefobject.h |
README.rst
The Python C API ================ The C API is divided into these sections: 1. ``Include/``: Limited API 2. ``Include/cpython/``: CPython implementation details 3. ``Include/cpython/``, names with the ``PyUnstable_`` prefix: API that can change between minor releases 4. ``Include/internal/``, and any name with ``_`` prefix: The internal API Information on changing the C API is available `in the developer guide`_ .. _in the developer guide: https://devguide.python.org/c-api/