cpython/Python
Eric Snow dcd6f226d6
gh-100227: Make the Global PyModuleDef Cache Safe for Isolated Interpreters (gh-103084)
Sharing mutable (or non-immortal) objects between interpreters is generally not safe.  We can work around that but not easily. 
 There are two restrictions that are critical for objects that break interpreter isolation.

The first is that the object's state be guarded by a global lock.  For now the GIL meets this requirement, but a granular global lock is needed once we have a per-interpreter GIL.

The second restriction is that the object (and, for a container, its items) be deallocated/resized only when the interpreter in which it was allocated is the current one.  This is because every interpreter has (or will have, see gh-101660) its own object allocator.  Deallocating an object with a different allocator can cause crashes.

The dict for the cache of module defs is completely internal, which simplifies what we have to do to meet those requirements.  To do so, we do the following:

* add a mechanism for re-using a temporary thread state tied to the main interpreter in an arbitrary thread
   * add _PyRuntime.imports.extensions.main_tstate` 
   * add _PyThreadState_InitDetached() and _PyThreadState_ClearDetached() (pystate.c)
   * add _PyThreadState_BindDetached() and _PyThreadState_UnbindDetached() (pystate.c)
* make sure the cache dict (_PyRuntime.imports.extensions.dict) and its items are all owned by the main interpreter)
* add a placeholder using for a granular global lock

Note that the cache is only used for legacy extension modules and not for multi-phase init modules.

https://github.com/python/cpython/issues/100227
2023-03-29 17:15:43 -06:00
..
clinic
deepfreeze
frozen_modules
_warnings.c
adaptive.md
asdl.c
asm_trampoline.S
ast.c
ast_opt.c GH-101291: Rearrange the size bits in PyLongObject (GH-102464) 2023-03-22 14:49:51 +00:00
ast_unparse.c
bltinmodule.c gh-102939: Fix "conversion from Py_ssize_t to long" warning in builtins (GH-102940) 2023-03-23 10:37:04 +00:00
bootstrap_hash.c
bytecodes.c GH-89987: Shrink the BINARY_SUBSCR caches (GH-103022) 2023-03-29 15:53:30 -07:00
ceval.c GH-100987: Don't cache references to the names and consts array in _PyEval_EvalFrameDefault. (#102640) 2023-03-13 18:35:37 +00:00
ceval_gil.c
ceval_macros.h gh-101975: Fixed a potential SegFault on garbage collection (GH-102803) 2023-03-18 10:59:21 +00:00
codecs.c gh-102406: replace exception chaining by PEP-678 notes in codecs (#102407) 2023-03-21 21:36:31 +00:00
compile.c GH-100982: Break up COMPARE_AND_BRANCH (GH-102801) 2023-03-23 15:25:09 -07:00
condvar.h
context.c
dtoa.c
dup2.c
dynamic_annotations.c
dynload_hpux.c
dynload_shlib.c
dynload_stub.c
dynload_win.c gh-102255: Improve build support for Windows API partitions (GH-102256) 2023-03-09 21:09:12 +00:00
emscripten_signal.c
errors.c gh-102192: Replace PyErr_Fetch/Restore etc by more efficient alternatives (#102769) 2023-03-18 13:44:47 +00:00
fileutils.c gh-99726: Improves correctness of stat results for Windows, and uses faster API when available (GH-102149) 2023-03-16 17:27:21 +00:00
formatter_unicode.c
frame.c
frozen.c
frozenmain.c
future.c
generated_cases.c.h GH-89987: Shrink the BINARY_SUBSCR caches (GH-103022) 2023-03-29 15:53:30 -07:00
getargs.c
getcompiler.c
getcopyright.c
getopt.c
getplatform.c
getversion.c
hamt.c
hashtable.c
import.c gh-100227: Make the Global PyModuleDef Cache Safe for Isolated Interpreters (gh-103084) 2023-03-29 17:15:43 -06:00
importdl.c
importdl.h
importlib.h
initconfig.c
intrinsics.c gh-90110: Fix the c-analyzer Tool (#102483) 2023-03-06 19:40:09 -07:00
makeopcodetargets.py
marshal.c GH-101291: Rearrange the size bits in PyLongObject (GH-102464) 2023-03-22 14:49:51 +00:00
modsupport.c
mysnprintf.c
mystrtoul.c
opcode_metadata.h GH-89987: Shrink the BINARY_SUBSCR caches (GH-103022) 2023-03-29 15:53:30 -07:00
opcode_targets.h GH-100982: Break up COMPARE_AND_BRANCH (GH-102801) 2023-03-23 15:25:09 -07:00
pathconfig.c
perf_trampoline.c
preconfig.c
pyarena.c
pyctype.c
pyfpe.c
pyhash.c
pylifecycle.c gh-100227: Revert gh-102925 "gh-100227: Make the Global Interned Dict Safe for Isolated Interpreters" (gh-103063) 2023-03-27 16:53:05 -06:00
pymath.c
pystate.c gh-100227: Make the Global PyModuleDef Cache Safe for Isolated Interpreters (gh-103084) 2023-03-29 17:15:43 -06:00
pystrcmp.c
pystrhex.c
pystrtod.c
Python-ast.c
Python-tokenize.c
pythonrun.c gh-102192: Replace PyErr_Fetch/Restore etc by more efficient alternatives (#102816) 2023-03-19 15:17:59 +00:00
pytime.c
README
specialize.c GH-89987: Shrink the BINARY_SUBSCR caches (GH-103022) 2023-03-29 15:53:30 -07:00
stdlib_module_names.h
structmember.c
suggestions.c
symtable.c
sysmodule.c gh-102304: Move the Total Refcount to PyInterpreterState (gh-102545) 2023-03-21 11:46:09 -06:00
thread.c
thread_nt.h
thread_pthread.h
thread_pthread_stubs.h
traceback.c gh-102192: Replace PyErr_Fetch/Restore etc by more efficient alternatives (#102760) 2023-03-16 19:03:52 +00:00

Miscellaneous source files for the main Python shared library