bpo-36710: Add tstate parameter in ceval.c (GH-13547) · python/cpython@438a12d (original) (raw)

11 files changed

lines changed

Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@ PyAPI_FUNC(void) _PyEval_FiniThreads(
19 19 PyAPI_FUNC(void) _PyEval_SignalReceived(
20 20 struct _ceval_runtime_state *ceval);
21 21 PyAPI_FUNC(int) _PyEval_AddPendingCall(
22 +PyThreadState *tstate,
22 23 struct _ceval_runtime_state *ceval,
23 24 int (*func)(void *),
24 25 void *arg);
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
1 +#ifndef Py_INTERNAL_PYERRORS_H
2 +#define Py_INTERNAL_PYERRORS_H
3 +#ifdef __cplusplus
4 +extern "C" {
5 +#endif
6 +
7 +#ifndef Py_BUILD_CORE
8 +# error "this header requires Py_BUILD_CORE define"
9 +#endif
10 +
11 +static inline PyObject* _PyErr_Occurred(PyThreadState *tstate)
12 +{
13 +return tstate == NULL ? NULL : tstate->curexc_type;
14 +}
15 +
16 +
17 +PyAPI_FUNC(void) _PyErr_Fetch(
18 +PyThreadState *tstate,
19 +PyObject **type,
20 +PyObject **value,
21 +PyObject **traceback);
22 +
23 +PyAPI_FUNC(int) _PyErr_ExceptionMatches(
24 +PyThreadState *tstate,
25 +PyObject *exc);
26 +
27 +PyAPI_FUNC(void) _PyErr_Restore(
28 +PyThreadState *tstate,
29 +PyObject *type,
30 +PyObject *value,
31 +PyObject *traceback);
32 +
33 +PyAPI_FUNC(void) _PyErr_SetObject(
34 +PyThreadState *tstate,
35 +PyObject *type,
36 +PyObject *value);
37 +
38 +PyAPI_FUNC(void) _PyErr_Clear(PyThreadState *tstate);
39 +
40 +PyAPI_FUNC(void) _PyErr_SetNone(PyThreadState *tstate, PyObject *exception);
41 +
42 +PyAPI_FUNC(void) _PyErr_SetString(
43 +PyThreadState *tstate,
44 +PyObject *exception,
45 +const char *string);
46 +
47 +PyAPI_FUNC(PyObject *) _PyErr_Format(
48 +PyThreadState *tstate,
49 +PyObject *exception,
50 +const char *format,
51 + ...);
52 +
53 +PyAPI_FUNC(void) _PyErr_NormalizeException(
54 +PyThreadState *tstate,
55 +PyObject **exc,
56 +PyObject **val,
57 +PyObject **tb);
58 +
59 +#ifdef __cplusplus
60 +}
61 +#endif
62 +#endif /* !Py_INTERNAL_PYERRORS_H */
Original file line number Diff line number Diff line change
@@ -106,6 +106,8 @@ PyAPI_FUNC(int) _Py_HandleSystemExit(int *exitcode_p);
106 106
107 107 PyAPI_FUNC(PyObject*) _PyErr_WriteUnraisableDefaultHook(PyObject *unraisable);
108 108
109 +PyAPI_FUNC(void) _PyErr_Print(PyThreadState *tstate);
110 +
109 111 #ifdef __cplusplus
110 112 }
111 113 #endif
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
1 -#ifndef Py_INTERNAL_MEM_H
2 -#define Py_INTERNAL_MEM_H
1 +#ifndef Py_INTERNAL_PYMEM_H
2 +#define Py_INTERNAL_PYMEM_H
3 3 #ifdef __cplusplus
4 4 extern "C" {
5 5 #endif
@@ -191,4 +191,4 @@ PyAPI_FUNC(int) _PyMem_SetupAllocators(PyMemAllocatorName allocator);
191 191 #ifdef __cplusplus
192 192 }
193 193 #endif
194 -#endif /* !Py_INTERNAL_MEM_H */
194 +#endif /* !Py_INTERNAL_PYMEM_H */
Original file line number Diff line number Diff line change
@@ -1077,6 +1077,7 @@ PYTHON_HEADERS= \
1077 1077 $(srcdir)/Include/internal/pycore_hamt.h \
1078 1078 $(srcdir)/Include/internal/pycore_object.h \
1079 1079 $(srcdir)/Include/internal/pycore_pathconfig.h \
1080 + $(srcdir)/Include/internal/pycore_pyerrors.h \
1080 1081 $(srcdir)/Include/internal/pycore_pyhash.h \
1081 1082 $(srcdir)/Include/internal/pycore_pylifecycle.h \
1082 1083 $(srcdir)/Include/internal/pycore_pymem.h \
Original file line number Diff line number Diff line change
@@ -258,6 +258,7 @@ trip_signal(int sig_num)
258 258
259 259 /* Notify ceval.c */
260 260 _PyRuntimeState *runtime = &_PyRuntime;
261 +PyThreadState *tstate = _PyRuntimeState_GetThreadState(runtime);
261 262 _PyEval_SignalReceived(&runtime->ceval);
262 263
263 264 /* And then write to the wakeup fd *after* setting all the globals and
@@ -298,7 +299,7 @@ trip_signal(int sig_num)
298 299 {
299 300 /* Py_AddPendingCall() isn't signal-safe, but we
300 301 still use it for this exceptional case. */
301 -_PyEval_AddPendingCall(&runtime->ceval,
302 +_PyEval_AddPendingCall(tstate, &runtime->ceval,
302 303 report_wakeup_send_error,
303 304 (void *)(intptr_t) last_error);
304 305 }
@@ -317,7 +318,7 @@ trip_signal(int sig_num)
317 318 {
318 319 /* Py_AddPendingCall() isn't signal-safe, but we
319 320 still use it for this exceptional case. */
320 -_PyEval_AddPendingCall(&runtime->ceval,
321 +_PyEval_AddPendingCall(tstate, &runtime->ceval,
321 322 report_wakeup_write_error,
322 323 (void *)(intptr_t)errno);
323 324 }
Original file line number Diff line number Diff line change
@@ -168,6 +168,7 @@
168 168 <ClInclude Include="..\Include\internal\pycore_hamt.h" />
169 169 <ClInclude Include="..\Include\internal\pycore_object.h" />
170 170 <ClInclude Include="..\Include\internal\pycore_pathconfig.h" />
171 + <ClInclude Include="..\Include\internal\pycore_pyerrors.h" />
171 172 <ClInclude Include="..\Include\internal\pycore_pyhash.h" />
172 173 <ClInclude Include="..\Include\internal\pycore_pylifecycle.h" />
173 174 <ClInclude Include="..\Include\internal\pycore_pymem.h" />
Original file line number Diff line number Diff line change
@@ -207,6 +207,9 @@
207 207 <ClInclude Include="..\Include\internal\pycore_pathconfig.h">
208 208 <Filter>Include</Filter>
209 209 </ClInclude>
210 + <ClInclude Include="..\Include\internal\pycore_pyerrors.h">
211 + <Filter>Include</Filter>
212 + </ClInclude>
210 213 <ClInclude Include="..\Include\internal\pycore_pyhash.h">
211 214 <Filter>Include</Filter>
212 215 </ClInclude>