Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-99113: A Per-Interpreter GIL! #99114

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
318 commits
Select commit Hold shift + click to select a range
25fd52a
Revert "Remove unused refcounts in singletons within CPython/Objects"
eduardo-elizondo Mar 9, 2022
be86955
Include immortal interned strings
eduardo-elizondo Mar 9, 2022
38a14a9
Regen frozen main
eduardo-elizondo Mar 9, 2022
c828369
Properly clean up all immortal interned strings at runtime finalization
eduardo-elizondo Mar 9, 2022
ee41af6
Build and test fixes
eduardo-elizondo Mar 9, 2022
f835e6d
Temporarily disable single test_embed test
eduardo-elizondo Mar 9, 2022
8573af4
Fix structseq test
eduardo-elizondo Mar 9, 2022
ad19ff6
Move nonetype refcount to static refcnt
eduardo-elizondo Mar 18, 2022
66c625f
Remove unneeded reference counts in Cpython/Objects
eduardo-elizondo Mar 18, 2022
1379d50
Mark global instances as static globals
eduardo-elizondo Mar 18, 2022
1c9ee6d
Remove unneeded reference counts in Cpython/Python
eduardo-elizondo Mar 18, 2022
287b57c
Remove unneeded reference counts in gcmodule.c
eduardo-elizondo Mar 18, 2022
c736a7c
Cleanup bool and str usage
eduardo-elizondo Mar 18, 2022
60f0760
Merge branch 'main' into immortal-references
eduardo-elizondo Mar 18, 2022
1321ff6
Fix whitespaces
eduardo-elizondo Mar 18, 2022
a719b41
Remove static immortal bit in favor of unicode intern state
eduardo-elizondo Apr 17, 2022
9f3ed39
Merge remote-tracking branch 'upstream/main' into immortal-references
eduardo-elizondo Apr 17, 2022
8f72afe
Regen frozen
eduardo-elizondo Apr 17, 2022
52d6d78
Fix regrtest
eduardo-elizondo Apr 17, 2022
9fd8a98
Change immortal refcount for PY_SSIZE_T_MAX
eduardo-elizondo Apr 17, 2022
3478467
Introduce saturated adds for increfs
eduardo-elizondo Apr 17, 2022
eb5da8c
Add default and msvc intrinsic saturated add
eduardo-elizondo Apr 18, 2022
def8da3
Fix msvc saturated add
eduardo-elizondo Apr 18, 2022
fe6727e
Fix docs
eduardo-elizondo Apr 18, 2022
38df3ce
Move unicode_is_singleton to Py_DEBUG
eduardo-elizondo Apr 18, 2022
73f6dcd
Skip immortal checks in frame clear
eduardo-elizondo Apr 18, 2022
d68efa1
Make code objects immortal
eduardo-elizondo Apr 19, 2022
18cff33
Merge remote-tracking branch 'upstream/main' into immortal-references
eduardo-elizondo Apr 19, 2022
168a85c
Refcount fixes
eduardo-elizondo Apr 19, 2022
9ada9fd
Temporarily disable two code tests
eduardo-elizondo Apr 19, 2022
5d3beb9
Disable one more code test
eduardo-elizondo Apr 20, 2022
ea342e3
Cleanups
eduardo-elizondo Apr 21, 2022
d78a560
Simplify Implementation
eduardo-elizondo May 16, 2022
16d59e3
Merge remote-tracking branch 'upstream/main' into immortal-references
eduardo-elizondo May 16, 2022
f49c13c
Cleanups
eduardo-elizondo May 16, 2022
8262e56
More Cleanups
eduardo-elizondo May 16, 2022
96c7caa
Regen Frozen
eduardo-elizondo May 16, 2022
3493c85
Fix regrtest
eduardo-elizondo May 16, 2022
0f38657
Only immortal changes
eduardo-elizondo May 16, 2022
401a3c3
Fix C++ compilation issue
eduardo-elizondo May 16, 2022
6bd2d94
Fix regen files
eduardo-elizondo May 16, 2022
9df1447
Merge remote-tracking branch 'upstream/main' into immortal-references
eduardo-elizondo May 16, 2022
15f7365
Fix sat add
eduardo-elizondo May 16, 2022
ea9f01c
Merge remote-tracking branch 'upstream/main' into immortal-references
eduardo-elizondo May 22, 2022
c39b617
32 bit fixes
eduardo-elizondo May 22, 2022
3ae8374
Fix msvc build
eduardo-elizondo May 22, 2022
ba7cfe1
Add 32 compat
eduardo-elizondo May 22, 2022
7a29123
More fixes
eduardo-elizondo May 22, 2022
88ede67
Fix inlined refcounts
eduardo-elizondo May 22, 2022
34bdf3c
Change refcount strategy for 32bit systems
eduardo-elizondo May 22, 2022
ab1f6e4
Add guard for saturated add function
eduardo-elizondo May 22, 2022
c2c228e
Cleanup unneeded port values
eduardo-elizondo May 22, 2022
219ebdc
branchless saturated add
eduardo-elizondo May 23, 2022
cd42e16
Use PY32 bit integers
eduardo-elizondo May 23, 2022
99e7549
Cleanups
eduardo-elizondo May 23, 2022
d7df473
Remove branchless add as it's slower
eduardo-elizondo May 23, 2022
00238eb
Immortalize Interned Strings
eduardo-elizondo May 23, 2022
9355ca2
Fix structseq test
eduardo-elizondo May 23, 2022
eedd412
Bring back interned stats
eduardo-elizondo May 23, 2022
ccf8b61
Merge remote-tracking branch 'upstream/main' into immortal-references
eduardo-elizondo May 23, 2022
e57910d
Fix msvc ifdef
eduardo-elizondo May 23, 2022
6437df7
Only copy lower 32 bits to refcnt
eduardo-elizondo Oct 3, 2022
ba75726
Merge remote-tracking branch 'upstream/main' into immortal-references
eduardo-elizondo Nov 27, 2022
418b2ff
Merge cleanups
eduardo-elizondo Nov 27, 2022
1468f52
Fixing Test Failures
eduardo-elizondo Nov 28, 2022
e30fea4
Addressed static string issue
eduardo-elizondo Dec 17, 2022
5aa8c34
Addressed regrtest failures
eduardo-elizondo Dec 17, 2022
d74a4c5
Addressed CI failures
eduardo-elizondo Dec 17, 2022
9be58d4
Addressed CI failures second try
eduardo-elizondo Dec 19, 2022
f00f7f8
Merge remote-tracking branch 'upstream/main' into immortal-references
eduardo-elizondo Dec 20, 2022
747039d
Remove temporary fixes
eduardo-elizondo Dec 20, 2022
01017e1
Temporary windows fix
eduardo-elizondo Dec 20, 2022
6f0cf32
Remove duplicate immortal initialization
eduardo-elizondo Dec 20, 2022
7997d57
Windows fix
eduardo-elizondo Dec 21, 2022
749680e
Addressed CI failures third try
eduardo-elizondo Dec 21, 2022
c71c742
Merge remote-tracking branch 'upstream/main' into immortal-references
eduardo-elizondo Dec 21, 2022
bc28cb0
Merge remote-tracking branch 'upstream/main' into immortal-references
eduardo-elizondo Jan 9, 2023
c8b694f
Add tp_dealloc suggested changes by steering committee
eduardo-elizondo Jan 9, 2023
6abab4d
Fixed int leak
eduardo-elizondo Jan 9, 2023
1dfe27a
Merge remote-tracking branch 'upstream/main' into immortal-references
eduardo-elizondo Jan 9, 2023
7661541
Merge remote-tracking branch 'upstream/main' into immortal-references
eduardo-elizondo Jan 17, 2023
59513a7
Cleanup deallocation of immortal objects
eduardo-elizondo Jan 17, 2023
60329b5
Add DeepFreeze types for typle, long, and bytes
eduardo-elizondo Jan 17, 2023
a5e29d5
Fix regencode
eduardo-elizondo Jan 17, 2023
f88cbb6
Fix stable abi toml
eduardo-elizondo Jan 17, 2023
7efa760
Merge remote-tracking branch 'upstream/main' into immortal-references
eduardo-elizondo Jan 22, 2023
8ebb3db
Add DeepFreeze types for float, complex
eduardo-elizondo Jan 22, 2023
2c3d242
Add DeepFreeze types for code and update stable_abi
eduardo-elizondo Jan 22, 2023
5684be7
Remove PyDeepFreezeCode_Type from stable abi
eduardo-elizondo Jan 22, 2023
4529e23
Revert DeepFreeze changes
eduardo-elizondo Jan 29, 2023
cfb56b6
Merge remote-tracking branch 'upstream/main' into immortal-references
eduardo-elizondo Jan 29, 2023
a748e80
Replace incref memcpy with builtins
eduardo-elizondo Jan 29, 2023
07a09d4
Pass PyInterpreterState to pymalloc_*().
ericsnowcurrently Oct 6, 2022
ca75048
Move the object arenas to the interpreter state.
ericsnowcurrently Oct 7, 2022
4ee199b
Drop an errant #define.
ericsnowcurrently Feb 7, 2023
2768fa4
Leave dump_debug_stats in the global state.
ericsnowcurrently Feb 7, 2023
bf9425f
Dynamically initialize obmalloc for subinterpreters.
ericsnowcurrently Feb 9, 2023
83e16d5
Move types.next_version_tag to PyInterpreterState for non-core-static…
ericsnowcurrently Feb 28, 2023
c9281e4
Add NEXT_GLOBAL_VERSION_TAG.
ericsnowcurrently Mar 3, 2023
95ffcd1
Handle static types correctly in assign_version_tag().
ericsnowcurrently Mar 3, 2023
f3b707d
Verify that builtin types have builtin bases.
ericsnowcurrently Mar 3, 2023
c32b834
Add an assert.
ericsnowcurrently Mar 3, 2023
6362a36
Do not invalidate the method cache for static builtin types.
ericsnowcurrently Mar 3, 2023
d5da34b
Merge branch 'main' into per-interpreter-alloc
ericsnowcurrently Mar 9, 2023
6c3111c
Pass around struct _obmalloc_state* instead of PyInterpeterState*.
ericsnowcurrently Mar 8, 2023
4dc087d
Add _PyInterpreterConfig.use_main_obmalloc.
ericsnowcurrently Mar 9, 2023
1ae33a0
Add a comment about why per-interpreter obmalloc requires multi-phase…
ericsnowcurrently Mar 9, 2023
5b54d63
Add a TODO comment.
ericsnowcurrently Mar 9, 2023
9f4f8f3
Optionally use the main interpreter's obmalloc state.
ericsnowcurrently Mar 9, 2023
aa10204
Pass use_main_obmalloc to run_in_subinterp() in test_import.
ericsnowcurrently Mar 9, 2023
69d9a2d
_Py_GetAllocatedBlocks() -> _Py_GetGlobalAllocatedBlocks().
ericsnowcurrently Mar 10, 2023
25378f8
Errors from _Py_NewInterpreterFromConfig() are no longer fatal.
ericsnowcurrently Mar 10, 2023
1c5b109
Chain the exceptions.
ericsnowcurrently Mar 13, 2023
f36426b
Swap out the failed tstate.
ericsnowcurrently Mar 10, 2023
54b9f09
Remaining static builtin types must be fixed.
ericsnowcurrently Mar 13, 2023
2358a42
Add PyInterpreterState.sysdict_copy.
ericsnowcurrently Mar 13, 2023
b6502e1
Set m_copy to None for sys and builtins.
ericsnowcurrently Mar 13, 2023
678e67b
Add _PyIO_InitTypes().
ericsnowcurrently Mar 13, 2023
69a5829
Fix test_capi.
ericsnowcurrently Mar 13, 2023
3feb408
Avoid allocation for shared exceptions.
ericsnowcurrently Mar 13, 2023
05806fc
Fix the ChannelID tp_name.
ericsnowcurrently Mar 13, 2023
b1cd7bb
Merge branch 'main' into per-interpreter-alloc
ericsnowcurrently Mar 29, 2023
4feb2b7
Do not include the total from interpreters sharing with main.
ericsnowcurrently Mar 29, 2023
136ad2f
Add _PyRuntime.obmalloc.interpreter_leaks.
ericsnowcurrently Mar 29, 2023
e19bb37
Track leaked blocks across init/fini cycles.
ericsnowcurrently Mar 29, 2023
6c51997
Clean up assumptions around runtime fini.
ericsnowcurrently Mar 29, 2023
f0fcaf6
Merge branch 'main' into per-interpreter-alloc
ericsnowcurrently Mar 29, 2023
0ff65ff
Add stubs for when WITH_PYMALLOC isn't defined.
ericsnowcurrently Mar 30, 2023
7db8d4a
Decref the key in the right interpreter in _extensions_cache_set().
ericsnowcurrently Mar 31, 2023
38bee89
Don't test against sys (for now).
ericsnowcurrently Mar 31, 2023
375a8f2
Clean up SubinterpImportTests.
ericsnowcurrently Mar 31, 2023
b0a9e11
Ensure we are testing against the right type of extension.
ericsnowcurrently Mar 31, 2023
5e5d5d5
Add a test that uses an isolated interpreter.
ericsnowcurrently Mar 31, 2023
033c86d
Merge remote-tracking branch 'upstream/main' into immortal-references
eduardo-elizondo Apr 1, 2023
520fbc3
Rebase fixes
eduardo-elizondo Apr 1, 2023
90e0016
Debug build fixes
eduardo-elizondo Apr 1, 2023
bc726b0
Cleanups in prep for review
eduardo-elizondo Apr 3, 2023
5e0cd08
Merge remote-tracking branch 'upstream/main' into immortal-references
eduardo-elizondo Apr 3, 2023
f7fbf01
Correct whatsnew
eduardo-elizondo Apr 3, 2023
92fbf96
More cleanups
eduardo-elizondo Apr 3, 2023
1c390cc
Delete _PyType_FixCacheRefcounts
eduardo-elizondo Apr 3, 2023
25809ce
Fix is_core_module().
ericsnowcurrently Apr 4, 2023
616d3dd
Merge branch 'main' into per-interpreter-alloc
ericsnowcurrently Apr 4, 2023
43a836b
Ignore last_final_leaks.
ericsnowcurrently Apr 4, 2023
1841b55
Fix a typo.
ericsnowcurrently Apr 4, 2023
299527e
Merge branch 'main' into per-interpreter-alloc
ericsnowcurrently Apr 4, 2023
0091e48
Add a note about global state owned by the module.
ericsnowcurrently Apr 5, 2023
9f74f7b
Factor out GLOBAL_MALLOC() and GLOBAL_FREE().
ericsnowcurrently Apr 5, 2023
10c3589
Switch to the raw allocator.
ericsnowcurrently Apr 5, 2023
ff727ec
Merge branch 'channels-raw-allocator' into per-interpreter-alloc
ericsnowcurrently Apr 5, 2023
593430b
Use the raw allocator for _PyCrossInterpreterData_InitWithSize().
ericsnowcurrently Apr 5, 2023
f5ae710
atexit_callback -> atexit_py_callback.
ericsnowcurrently Apr 5, 2023
e6d4776
Add pycore_atexit.h.
ericsnowcurrently Apr 5, 2023
c719f02
Add _Py_AtExit().
ericsnowcurrently Apr 5, 2023
47c302d
Add a TODO comment.
ericsnowcurrently Apr 5, 2023
aaeaaa6
Move _Py_AtExit() to the public API.
ericsnowcurrently Apr 5, 2023
b5396e4
Test a constraint.
ericsnowcurrently Apr 5, 2023
448b48a
Add an atexit callback for _xxinterpchannels.
ericsnowcurrently Apr 5, 2023
c86f738
Implement the callback.
ericsnowcurrently Apr 5, 2023
1827feb
Drop the _PyCrossInterpreterData_Clear() call in _xxinterpchannels.
ericsnowcurrently Apr 5, 2023
82b395c
Drop the _PyCrossInterpreterData_Clear() call in _xxsubinterpreters.
ericsnowcurrently Apr 5, 2023
df77a64
Merge branch 'atexit-c-callback' into per-interpreter-alloc
ericsnowcurrently Apr 6, 2023
22758a3
Merge branch 'main' into per-interpreter-alloc
ericsnowcurrently Apr 6, 2023
030016a
Addressed First Round of Comments
eduardo-elizondo Apr 6, 2023
c4db85a
Add a thread_local macro.
ericsnowcurrently Jan 10, 2023
47a7094
tstate_current -> thread_local.
ericsnowcurrently Apr 6, 2023
cf22de1
Add _PyThraedState_GetCurrent().
ericsnowcurrently Apr 7, 2023
093c405
Address comments
eduardo-elizondo Apr 7, 2023
d4136d2
Add HAVE_THREAD_LOCAL.
ericsnowcurrently Apr 7, 2023
f8c6598
Support the faster approach, if available.
ericsnowcurrently Apr 7, 2023
6c0fdba
Return Py_DEBUG in unicode runtime shutdown
eduardo-elizondo Apr 7, 2023
9496df0
Do not fail if thread_local not supported.
ericsnowcurrently Apr 7, 2023
74b6e7b
Nits
eduardo-elizondo Apr 7, 2023
2c335a3
thread_local -> _Py_thread_local
ericsnowcurrently Apr 7, 2023
4af0ce7
Only define _Py_thread_local for the core runtime.
ericsnowcurrently Apr 7, 2023
3db4007
Fix pystate.c.
ericsnowcurrently Apr 7, 2023
d573053
Call _PyThreadState_GET() from _PyRuntimeState_GetThreadState().
ericsnowcurrently Apr 7, 2023
feb8ef5
Fix the error message.
ericsnowcurrently Apr 7, 2023
2332a2e
Add a NEWS entry.
ericsnowcurrently Apr 7, 2023
ed86e04
Add PyInterpreterState.ceval.gil.
ericsnowcurrently Nov 4, 2022
3885d43
Use PyInterpreterState.ceval.gil.
ericsnowcurrently Nov 4, 2022
c45e633
Add _PyInterpreterConfig.own_gil.
ericsnowcurrently Nov 3, 2022
a857530
Use PyInterpreterConfig.own_gil.
ericsnowcurrently Nov 4, 2022
04c023e
Actually make the GIL per-interpreter!
ericsnowcurrently Nov 5, 2022
a067e4a
Merge branch 'per-interpreter-alloc' into per-interpreter-gil-combined
ericsnowcurrently Apr 7, 2023
554e03a
Merge branch 'tstate_current-as-thread_local' into per-interpreter-gi…
ericsnowcurrently Apr 7, 2023
b2f8e8e
Skip blocking tests.
ericsnowcurrently Apr 7, 2023
433d1e3
Use Py_BUILD_CORE to set PyObject_HEAD_INIT as immortal
eduardo-elizondo Apr 8, 2023
069da16
Address Carl's comments
eduardo-elizondo Apr 8, 2023
d22a4bf
Use a union to refer to lower 32bits
eduardo-elizondo Apr 9, 2023
e04ef7e
Static declarations cleanups
eduardo-elizondo Apr 9, 2023
3b3b142
Only support split refcount in 64bit architectures
eduardo-elizondo Apr 9, 2023
ab3f951
Support incref in big-endian machines
eduardo-elizondo Apr 9, 2023
3e55a32
Cleanups and comments
eduardo-elizondo Apr 10, 2023
ff69be7
Fix bytes_method compiler error
eduardo-elizondo Apr 10, 2023
e6e459c
Merge remote-tracking branch 'upstream/main' into immortal-references
eduardo-elizondo Apr 10, 2023
e1e13df
Skip a blocking test.
ericsnowcurrently Apr 10, 2023
b659ca8
Fix a test.
ericsnowcurrently Apr 10, 2023
9a0d093
Add an assert.
ericsnowcurrently Apr 10, 2023
21984e4
Add _PyEval_AcquireLock().
ericsnowcurrently Apr 10, 2023
e19f50a
Add Py_ALWAYS_INLINE to Py_DECREF, Py_INCREF, and _Py_IsImmortal
eduardo-elizondo Apr 10, 2023
4ae3319
Add _PyThreadState_SwapNoGIL().
ericsnowcurrently Apr 10, 2023
34103b9
Acquire the GIL when not owned.
ericsnowcurrently Apr 10, 2023
e5b7aeb
Un-skip tests.
ericsnowcurrently Apr 10, 2023
d43bb5f
Fix tabs.
ericsnowcurrently Apr 10, 2023
02b681c
Add a granular lock for _PyRuntime.imports.extensions.
ericsnowcurrently Apr 6, 2023
1755379
Use the lock.
ericsnowcurrently Apr 6, 2023
9a65073
Merge branch 'extensions-lock' into per-interpreter-gil-new
ericsnowcurrently Apr 11, 2023
12dba6f
Merge remote-tracking branch 'eduardo-elizondo/immortal-references' i…
ericsnowcurrently Apr 12, 2023
63790f6
Immortalize tp_dict, tp_bases, and tp_mro for builtin static types.
ericsnowcurrently Apr 12, 2023
0edcfb5
Do the work in _PyStaticType_InitBuiltin().
ericsnowcurrently Apr 12, 2023
9cdb13a
Add _Py_EnsureImmortal() and _Py_ImmortalObjectsFini().
ericsnowcurrently Apr 12, 2023
a9a1f63
Fix an assert.
ericsnowcurrently Apr 12, 2023
42c6a9b
Immortalize in _PyStructSequence_InitBuiltinWithFlags().
ericsnowcurrently Apr 13, 2023
e1dde48
Recursively immortalize.
ericsnowcurrently Apr 13, 2023
5f8c3e4
Merge branch 'main' into isolate-types-next-version-tag
ericsnowcurrently Apr 24, 2023
0d78c1b
Only use deepfreeze in the main interpreter.
ericsnowcurrently Apr 24, 2023
4e1d627
Merge branch 'main' into per-interpreter-gil-new
ericsnowcurrently Apr 24, 2023
5496238
Merge branch 'main' into per-interpreter-gil-new
ericsnowcurrently Apr 24, 2023
fc6b906
Merge branch 'isolate-types-next-version-tag' into per-interpreter-gi…
ericsnowcurrently Apr 24, 2023
a93499c
Merge branch 'main' into per-interpreter-gil-new
ericsnowcurrently Apr 25, 2023
d1e4cf5
Make __mro__ a getter.
ericsnowcurrently Apr 27, 2023
d3db6bf
Add the fields to static_builtin_state.
ericsnowcurrently Apr 27, 2023
b5799d8
Isolate tp_bases.
ericsnowcurrently Apr 27, 2023
2e28be5
Isolate tp_mro.
ericsnowcurrently Apr 27, 2023
fb7a025
Add a note.
ericsnowcurrently Apr 27, 2023
2822f0d
Isolate tp_dict.
ericsnowcurrently Apr 27, 2023
68f0008
Fix type_get_bases() and type_get_mro().
ericsnowcurrently Apr 27, 2023
de2a3c1
Fix _PyStaticType_InitBuiltin() for subinterpreters.
ericsnowcurrently Apr 27, 2023
8bd3b67
Call _PyType_CheckConsistency() after setting the fields.
ericsnowcurrently Apr 27, 2023
071ef3f
Re-run most of type_ready() under each interpreter.
ericsnowcurrently Apr 28, 2023
850059a
Add some comments.
ericsnowcurrently May 2, 2023
cd1dd10
Drop an old workaround for previously shared objects.
ericsnowcurrently May 2, 2023
c328b27
Merge branch 'per-interpreter-static-types-fields' into per-interpret…
ericsnowcurrently May 2, 2023
2771f4e
Move Py_TPFLAGS_READYING to each interpreter for static builtin types.
ericsnowcurrently May 2, 2023
b9343f4
Merge branch 'per-interpreter-static-types-fields' into per-interpret…
ericsnowcurrently May 3, 2023
7afb005
Add the Py_mod_multiple_interpreters module def slot.
ericsnowcurrently May 2, 2023
d708985
Add constants for the Py_mod_multiple_interpreters value.
ericsnowcurrently May 3, 2023
8cb5a5a
Add a NEWS entry.
ericsnowcurrently May 3, 2023
b1d9ba4
Drop _Py_EnsureImmortal().
ericsnowcurrently May 4, 2023
07c54ef
Merge branch 'main' into per-interpreter-gil-new
ericsnowcurrently May 4, 2023
8f9d6a3
Merge branch 'module-def-slot-supports-interpreters' into per-interpr…
ericsnowcurrently May 4, 2023
9c8f1fd
Add Py_MOD_PER_INTERPRETER_GIL_SUPPORTED.
ericsnowcurrently May 4, 2023
340a469
Fix the flags.
ericsnowcurrently May 4, 2023
fcd539a
Merge branch 'module-def-slot-supports-interpreters' into per-interpr…
ericsnowcurrently May 4, 2023
6e875bc
Fix the flags.
ericsnowcurrently May 4, 2023
b1c928f
Merge branch 'module-def-slot-supports-interpreters' into per-interpr…
ericsnowcurrently May 4, 2023
31eb898
Fix all the modules.
ericsnowcurrently May 4, 2023
b3af284
Fix Python-ast.c.
ericsnowcurrently May 4, 2023
f3fd844
Fix PyModule_FromDefAndSpec2().
ericsnowcurrently May 4, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Include/cpython/initconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ typedef struct {
int allow_threads;
int allow_daemon_threads;
int check_multi_interp_extensions;
int own_gil;
} PyInterpreterConfig;

#define _PyInterpreterConfig_INIT \
Expand All @@ -262,6 +263,7 @@ typedef struct {
.allow_threads = 1, \
.allow_daemon_threads = 0, \
.check_multi_interp_extensions = 1, \
.own_gil = 1, \
}

#define _PyInterpreterConfig_LEGACY_INIT \
Expand All @@ -272,6 +274,7 @@ typedef struct {
.allow_threads = 1, \
.allow_daemon_threads = 1, \
.check_multi_interp_extensions = 0, \
.own_gil = 0, \
}

/* --- Helper functions --------------------------------------- */
Expand Down
9 changes: 5 additions & 4 deletions Include/internal/pycore_ceval.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ struct _ceval_runtime_state;


extern void _Py_FinishPendingCalls(PyThreadState *tstate);
extern void _PyEval_InitRuntimeState(struct _ceval_runtime_state *);
extern void _PyEval_InitState(struct _ceval_state *, PyThread_type_lock);
extern void _PyEval_InitState(PyInterpreterState *, PyThread_type_lock);
extern void _PyEval_FiniState(struct _ceval_state *ceval);
PyAPI_FUNC(void) _PyEval_SignalReceived(PyInterpreterState *interp);
PyAPI_FUNC(int) _PyEval_AddPendingCall(
Expand Down Expand Up @@ -96,11 +95,13 @@ _PyEval_Vector(PyThreadState *tstate,
PyObject* const* args, size_t argcount,
PyObject *kwnames);

extern int _PyEval_ThreadsInitialized(struct pyruntimestate *runtime);
extern PyStatus _PyEval_InitGIL(PyThreadState *tstate);
extern int _PyEval_ThreadsInitialized(void);
extern PyStatus _PyEval_InitGIL(PyThreadState *tstate, int own_gil);
extern void _PyEval_FiniGIL(PyInterpreterState *interp);

extern void _PyEval_AcquireLock(PyThreadState *tstate);
extern void _PyEval_ReleaseLock(PyThreadState *tstate);
extern PyThreadState * _PyThreadState_SwapNoGIL(PyThreadState *);

extern void _PyEval_DeactivateOpCache(void);

Expand Down
3 changes: 2 additions & 1 deletion Include/internal/pycore_ceval_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ struct _ceval_runtime_state {
the main thread of the main interpreter can handle signals: see
_Py_ThreadCanHandleSignals(). */
_Py_atomic_int signals_pending;
struct _gil_runtime_state gil;
};

#ifdef PY_HAVE_PERF_TRAMPOLINE
Expand Down Expand Up @@ -83,6 +82,8 @@ struct _pending_calls {

struct _ceval_state {
int recursion_limit;
struct _gil_runtime_state *gil;
int own_gil;
/* This single variable consolidates all requests to break out of
the fast path in the eval loop. */
_Py_atomic_int eval_breaker;
Expand Down
3 changes: 3 additions & 0 deletions Include/internal/pycore_interp.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ struct _is {
basis. Also see _PyRuntimeState regarding the various mutex fields.
*/

/* The per-interpreter GIL, which might not be used. */
struct _gil_runtime_state _gil;

/* the initial PyInterpreterState.threads.head */
PyThreadState _initial_thread;
};
Expand Down
2 changes: 0 additions & 2 deletions Include/internal/pycore_runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ struct _getargs_runtime_state {
struct _PyArg_Parser *static_parsers;
};

/* ceval state */

/* GIL state */

struct _gilstate_runtime_state {
Expand Down
8 changes: 7 additions & 1 deletion Include/moduleobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,17 @@ struct PyModuleDef_Slot {

#define Py_mod_create 1
#define Py_mod_exec 2
#define Py_mod_multiple_interpreters 3

#ifndef Py_LIMITED_API
#define _Py_mod_LAST_SLOT 2
#define _Py_mod_LAST_SLOT 3
#endif

/* for Py_mod_multiple_interpreters: */
#define Py_MOD_MULTIPLE_INTERPRETERS_NOT_SUPPORTED ((void *)0)
#define Py_MOD_MULTIPLE_INTERPRETERS_SUPPORTED ((void *)1)
#define Py_MOD_PER_INTERPRETER_GIL_SUPPORTED ((void *)2)

#endif /* New in 3.5 */

struct PyModuleDef {
Expand Down
3 changes: 2 additions & 1 deletion Lib/test/test__xxsubinterpreters.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import _testcapi
from test import support
from test.support import import_helper
from test.support import os_helper
from test.support import script_helper


Expand Down Expand Up @@ -917,7 +918,7 @@ def f():
t = threading.Thread(target=f)
t.start()
""")
with support.temp_dir() as dirname:
with os_helper.temp_dir() as dirname:
filename = script_helper.make_script(dirname, 'interp', script)
with script_helper.spawn_python(filename) as proc:
retcode = proc.wait()
Expand Down
24 changes: 15 additions & 9 deletions Lib/test/test_capi/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1247,21 +1247,25 @@ def test_configured_settings(self):
EXEC = 1<<16

features = ['obmalloc', 'fork', 'exec', 'threads', 'daemon_threads',
'extensions']
'extensions', 'own_gil']
kwlist = [f'allow_{n}' for n in features]
kwlist[0] = 'use_main_obmalloc'
kwlist[-1] = 'check_multi_interp_extensions'

kwlist[-2] = 'check_multi_interp_extensions'
kwlist[-1] = 'own_gil'
# expected to work
for config, expected in {
(True, True, True, True, True, True):
OBMALLOC | FORK | EXEC | THREADS | DAEMON_THREADS | EXTENSIONS,
(True, False, False, False, False, False): OBMALLOC,
(False, False, False, True, False, True): THREADS | EXTENSIONS,
(True, True, True, True, True, True, True):
(OBMALLOC | FORK | EXEC | THREADS | DAEMON_THREADS | EXTENSIONS, True),
(True, False, False, False, False, False, False):
(OBMALLOC, False),
(False, False, False, True, False, True, False):
(THREADS | EXTENSIONS, False),
}.items():
kwargs = dict(zip(kwlist, config))
exp_flags, exp_gil = expected
expected = {
'feature_flags': expected,
'feature_flags': exp_flags,
'own_gil': exp_gil,
}
with self.subTest(config):
r, w = os.pipe()
Expand All @@ -1281,7 +1285,7 @@ def test_configured_settings(self):

# expected to fail
for config in [
(False, False, False, False, False, False),
(False, False, False, False, False, False, False),
]:
kwargs = dict(zip(kwlist, config))
with self.subTest(config):
Expand Down Expand Up @@ -1317,6 +1321,7 @@ def test_overridden_setting_extensions_subinterp_check(self):
'allow_exec': True,
'allow_threads': True,
'allow_daemon_threads': True,
'own_gil': False,
}

def check(enabled, override):
Expand All @@ -1327,6 +1332,7 @@ def check(enabled, override):
flags = BASE_FLAGS | EXTENSIONS if enabled else BASE_FLAGS
settings = {
'feature_flags': flags,
'own_gil': False,
}

expected = {
Expand Down
1 change: 1 addition & 0 deletions Lib/test/test_embed.py
Original file line number Diff line number Diff line change
Expand Up @@ -1666,6 +1666,7 @@ def test_init_main_interpreter_settings(self):
# All optional features should be enabled.
'feature_flags':
OBMALLOC | FORK | EXEC | THREADS | DAEMON_THREADS,
'own_gil': True,
}
out, err = self.run_embedded_interpreter(
'test_init_main_interpreter_settings',
Expand Down
1 change: 1 addition & 0 deletions Lib/test/test_import/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1639,6 +1639,7 @@ class SubinterpImportTests(unittest.TestCase):
# Isolation-related config values aren't included here.
)
ISOLATED = dict(
own_gil=True,
use_main_obmalloc=False,
)
NOT_ISOLATED = {k: not v for k, v in ISOLATED.items()}
Expand Down
1 change: 1 addition & 0 deletions Lib/test/test_threading.py
Original file line number Diff line number Diff line change
Expand Up @@ -1349,6 +1349,7 @@ def func():
allow_threads={allowed},
allow_daemon_threads={daemon_allowed},
check_multi_interp_extensions=False,
own_gil=False,
)
""")
with test.support.SuppressCrashReport():
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Multi-phase init extension modules may now indicate whether or not they
actually support multiple interpreters. By default such modules are
expected to support use in multiple interpreters. In the uncommon case that
one does not, it may use the new ``Py_mod_multiple_interpreters`` module def
slot. A value of ``0`` means the module does not support them. ``1`` means
it does. The default is ``1``.
1 change: 1 addition & 0 deletions Modules/_abc.c
Original file line number Diff line number Diff line change
Expand Up @@ -944,6 +944,7 @@ _abcmodule_free(void *module)

static PyModuleDef_Slot _abcmodule_slots[] = {
{Py_mod_exec, _abcmodule_exec},
{Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
{0, NULL}
};

Expand Down
2 changes: 2 additions & 0 deletions Modules/_asynciomodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -3805,6 +3805,8 @@ module_exec(PyObject *mod)

static struct PyModuleDef_Slot module_slots[] = {
{Py_mod_exec, module_exec},
// XXX gh-103092: fix isolation.
//{Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
{0, NULL},
};

Expand Down
1 change: 1 addition & 0 deletions Modules/_bisectmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,7 @@ bisect_modexec(PyObject *m)

static PyModuleDef_Slot bisect_slots[] = {
{Py_mod_exec, bisect_modexec},
{Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
{0, NULL}
};

Expand Down
3 changes: 2 additions & 1 deletion Modules/_blake2/blake2module.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ blake2_exec(PyObject *m)

static PyModuleDef_Slot _blake2_slots[] = {
{Py_mod_exec, blake2_exec},
{Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
{0, NULL}
};

Expand All @@ -146,4 +147,4 @@ PyMODINIT_FUNC
PyInit__blake2(void)
{
return PyModuleDef_Init(&blake2_module);
}
}
1 change: 1 addition & 0 deletions Modules/_bz2module.c
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,7 @@ _bz2_free(void *module)

static struct PyModuleDef_Slot _bz2_slots[] = {
{Py_mod_exec, _bz2_exec},
{Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
{0, NULL}
};

Expand Down
1 change: 1 addition & 0 deletions Modules/_codecsmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1049,6 +1049,7 @@ static PyMethodDef _codecs_functions[] = {
};

static PyModuleDef_Slot _codecs_slots[] = {
{Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
{0, NULL}
};

Expand Down
1 change: 1 addition & 0 deletions Modules/_collectionsmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -2571,6 +2571,7 @@ collections_exec(PyObject *module) {

static struct PyModuleDef_Slot collections_slots[] = {
{Py_mod_exec, collections_exec},
{Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
{0, NULL}
};

Expand Down
1 change: 1 addition & 0 deletions Modules/_contextvarsmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ _contextvars_exec(PyObject *m)

static struct PyModuleDef_Slot _contextvars_slots[] = {
{Py_mod_exec, _contextvars_exec},
{Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
{0, NULL}
};

Expand Down
1 change: 1 addition & 0 deletions Modules/_cryptmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ static PyMethodDef crypt_methods[] = {
};

static PyModuleDef_Slot _crypt_slots[] = {
{Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
{0, NULL}
};

Expand Down
1 change: 1 addition & 0 deletions Modules/_csv.c
Original file line number Diff line number Diff line change
Expand Up @@ -1798,6 +1798,7 @@ csv_exec(PyObject *module) {

static PyModuleDef_Slot csv_slots[] = {
{Py_mod_exec, csv_exec},
{Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
{0, NULL}
};

Expand Down
1 change: 1 addition & 0 deletions Modules/_ctypes/_ctypes_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -1054,6 +1054,7 @@ _testfunc_pylist_append(PyObject *list, PyObject *item)
}

static struct PyModuleDef_Slot _ctypes_test_slots[] = {
{Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
{0, NULL}
};

Expand Down
2 changes: 2 additions & 0 deletions Modules/_curses_panel.c
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,8 @@ _curses_panel_exec(PyObject *mod)

static PyModuleDef_Slot _curses_slots[] = {
{Py_mod_exec, _curses_panel_exec},
// XXX gh-103092: fix isolation.
//{Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
{0, NULL}
};

Expand Down
1 change: 1 addition & 0 deletions Modules/_dbmmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,7 @@ _dbm_module_free(void *module)

static PyModuleDef_Slot _dbmmodule_slots[] = {
{Py_mod_exec, _dbm_exec},
{Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
{0, NULL}
};

Expand Down
2 changes: 2 additions & 0 deletions Modules/_elementtree.c
Original file line number Diff line number Diff line change
Expand Up @@ -4419,6 +4419,8 @@ module_exec(PyObject *m)

static struct PyModuleDef_Slot elementtree_slots[] = {
{Py_mod_exec, module_exec},
// XXX gh-103092: fix isolation.
//{Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
{0, NULL},
};

Expand Down
1 change: 1 addition & 0 deletions Modules/_functoolsmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1520,6 +1520,7 @@ _functools_free(void *module)

static struct PyModuleDef_Slot _functools_slots[] = {
{Py_mod_exec, _functools_exec},
{Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
{0, NULL}
};

Expand Down
1 change: 1 addition & 0 deletions Modules/_gdbmmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,7 @@ _gdbm_module_free(void *module)

static PyModuleDef_Slot _gdbm_module_slots[] = {
{Py_mod_exec, _gdbm_exec},
{Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
{0, NULL}
};

Expand Down
1 change: 1 addition & 0 deletions Modules/_hashopenssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -2260,6 +2260,7 @@ static PyModuleDef_Slot hashlib_slots[] = {
{Py_mod_exec, hashlib_md_meth_names},
{Py_mod_exec, hashlib_init_constructors},
{Py_mod_exec, hashlib_exception},
{Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
{0, NULL}
};

Expand Down
1 change: 1 addition & 0 deletions Modules/_heapqmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,7 @@ heapq_exec(PyObject *m)

static struct PyModuleDef_Slot heapq_slots[] = {
{Py_mod_exec, heapq_exec},
{Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
{0, NULL}
};

Expand Down
1 change: 1 addition & 0 deletions Modules/_json.c
Original file line number Diff line number Diff line change
Expand Up @@ -1801,6 +1801,7 @@ _json_exec(PyObject *module)

static PyModuleDef_Slot _json_slots[] = {
{Py_mod_exec, _json_exec},
{Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
{0, NULL}
};

Expand Down
1 change: 1 addition & 0 deletions Modules/_localemodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,7 @@ _locale_exec(PyObject *module)

static struct PyModuleDef_Slot _locale_slots[] = {
{Py_mod_exec, _locale_exec},
{Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
{0, NULL}
};

Expand Down
2 changes: 2 additions & 0 deletions Modules/_lsprof.c
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,8 @@ _lsprof_exec(PyObject *module)

static PyModuleDef_Slot _lsprofslots[] = {
{Py_mod_exec, _lsprof_exec},
// XXX gh-103092: fix isolation.
//{Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
{0, NULL}
};

Expand Down
1 change: 1 addition & 0 deletions Modules/_lzmamodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1611,6 +1611,7 @@ static PyMethodDef lzma_methods[] = {

static PyModuleDef_Slot lzma_slots[] = {
{Py_mod_exec, lzma_exec},
{Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
{0, NULL}
};

Expand Down
Loading