Skip to content

Commit a4a9f2e

Browse files
authored
GH-96177: Move GIL and eval breaker code out of ceval.c into ceval_gil.c. (GH-96204)
1 parent 4de06e3 commit a4a9f2e

12 files changed

+1005
-985
lines changed

Include/internal/pycore_ceval.h

+3
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ extern struct _PyInterpreterFrame* _PyEval_GetFrame(void);
133133

134134
extern PyObject* _Py_MakeCoro(PyFunctionObject *func);
135135

136+
extern int _Py_HandlePending(PyThreadState *tstate);
137+
138+
136139
#ifdef __cplusplus
137140
}
138141
#endif

Include/internal/pycore_pystate.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,14 @@ _PyThreadState_GET(void)
8585
return _PyRuntimeState_GetThreadState(&_PyRuntime);
8686
}
8787

88-
PyAPI_FUNC(void) _Py_NO_RETURN _Py_FatalError_TstateNULL(const char *func);
89-
9088
static inline void
9189
_Py_EnsureFuncTstateNotNULL(const char *func, PyThreadState *tstate)
9290
{
9391
if (tstate == NULL) {
94-
_Py_FatalError_TstateNULL(func);
92+
_Py_FatalErrorFunc(func,
93+
"the function must be called with the GIL held, "
94+
"after Python initialization and before Python finalization, "
95+
"but the GIL is released (the current Python thread state is NULL)");
9596
}
9697
}
9798

Makefile.pre.in

+2-2
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,7 @@ PYTHON_OBJS= \
388388
Python/getcopyright.o \
389389
Python/getplatform.o \
390390
Python/getversion.o \
391+
Python/ceval_gil.o \
391392
Python/hamt.o \
392393
Python/hashtable.o \
393394
Python/import.o \
@@ -1419,8 +1420,7 @@ regen-opcode-targets:
14191420
$(srcdir)/Python/opcode_targets.h.new
14201421
$(UPDATE_FILE) $(srcdir)/Python/opcode_targets.h $(srcdir)/Python/opcode_targets.h.new
14211422

1422-
Python/ceval.o: $(srcdir)/Python/opcode_targets.h $(srcdir)/Python/ceval_gil.h \
1423-
$(srcdir)/Python/condvar.h
1423+
Python/ceval.o: $(srcdir)/Python/opcode_targets.h $(srcdir)/Python/condvar.h
14241424

14251425
Python/frozen.o: $(FROZEN_FILES_OUT)
14261426

PCbuild/_freeze_module.vcxproj

+1
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@
199199
<ClCompile Include="..\Python\getopt.c" />
200200
<ClCompile Include="..\Python\getplatform.c" />
201201
<ClCompile Include="..\Python\getversion.c" />
202+
<ClCompile Include="..\Python\ceval_gil.c" />
202203
<ClCompile Include="..\Python\hamt.c" />
203204
<ClCompile Include="..\Python\hashtable.c" />
204205
<ClCompile Include="..\Python\import.c" />

PCbuild/_freeze_module.vcxproj.filters

+3
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,9 @@
184184
<ClCompile Include="..\Python\getversion.c">
185185
<Filter>Source Files</Filter>
186186
</ClCompile>
187+
<ClCompile Include="..\Python\ceval_gil.c">
188+
<Filter>Source Files</Filter>
189+
</ClCompile>
187190
<ClCompile Include="..\Python\hamt.c">
188191
<Filter>Source Files</Filter>
189192
</ClCompile>

PCbuild/pythoncore.vcxproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,6 @@
327327
<ClInclude Include="..\Parser\pegen.h" />
328328
<ClInclude Include="..\PC\errmap.h" />
329329
<ClInclude Include="..\PC\pyconfig.h" />
330-
<ClInclude Include="..\Python\ceval_gil.h" />
331330
<ClInclude Include="..\Python\condvar.h" />
332331
<ClInclude Include="..\Python\importdl.h" />
333332
<ClInclude Include="..\Python\stdlib_module_names.h" />
@@ -502,6 +501,7 @@
502501
<ClCompile Include="..\Python\getopt.c" />
503502
<ClCompile Include="..\Python\getplatform.c" />
504503
<ClCompile Include="..\Python\getversion.c" />
504+
<ClCompile Include="..\Python\ceval_gil.c" />
505505
<ClCompile Include="..\Python\hamt.c" />
506506
<ClCompile Include="..\Python\hashtable.c" />
507507
<ClCompile Include="..\Python\import.c" />

PCbuild/pythoncore.vcxproj.filters

+3-3
Original file line numberDiff line numberDiff line change
@@ -312,9 +312,6 @@
312312
<ClInclude Include="..\Python\condvar.h">
313313
<Filter>Python</Filter>
314314
</ClInclude>
315-
<ClInclude Include="..\Python\ceval_gil.h">
316-
<Filter>Python</Filter>
317-
</ClInclude>
318315
<ClInclude Include="..\Include\pyhash.h">
319316
<Filter>Include</Filter>
320317
</ClInclude>
@@ -1097,6 +1094,9 @@
10971094
<ClCompile Include="..\Python\getversion.c">
10981095
<Filter>Python</Filter>
10991096
</ClCompile>
1097+
<ClCompile Include="..\Python\ceval_gil.c">
1098+
<Filter>Python</Filter>
1099+
</ClCompile>
11001100
<ClCompile Include="..\Python\hashtable.c">
11011101
<Filter>Modules</Filter>
11021102
</ClCompile>

0 commit comments

Comments
 (0)