Skip to content

Commit 585f565

Browse files
committed
Stop avoiding _PyThreadState_GET
1 parent d63dc4f commit 585f565

File tree

7 files changed

+44
-49
lines changed

7 files changed

+44
-49
lines changed

graalpython/com.oracle.graal.python.cext/include/internal/pycore_call.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ extern "C" {
1313
# error "this header requires Py_BUILD_CORE define"
1414
#endif
1515

16-
#if 0 // GraalPy change
1716
#include "pycore_pystate.h" // _PyThreadState_GET()
18-
#endif // GraalPy change
1917

2018
PyAPI_FUNC(PyObject *) _PyObject_Call_Prepend(
2119
PyThreadState *tstate,
@@ -110,7 +108,7 @@ _PyObject_CallNoArgsTstate(PyThreadState *tstate, PyObject *func) {
110108
// Private static inline function variant of public PyObject_CallNoArgs()
111109
static inline PyObject *
112110
_PyObject_CallNoArgs(PyObject *func) {
113-
PyThreadState *tstate = NULL; // GraalPy change: don't get thread state
111+
PyThreadState *tstate = _PyThreadState_GET();
114112
return _PyObject_VectorcallTstate(tstate, func, NULL, 0, NULL);
115113
}
116114

graalpython/com.oracle.graal.python.cext/include/internal/pycore_ceval.h

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,17 @@ struct _ceval_runtime_state;
2828
# endif
2929
#endif
3030

31-
// #include "pycore_interp.h" // PyInterpreterState.eval_frame
32-
// #include "pycore_pystate.h" // _PyThreadState_GET()
31+
#if 0 // GraalPy change
32+
#include "pycore_interp.h" // PyInterpreterState.eval_frame
33+
#endif // GraalPy change
34+
#include "pycore_pystate.h" // _PyThreadState_GET()
3335

3436

37+
#if 0 // GraalPy change
3538
extern void _Py_FinishPendingCalls(PyThreadState *tstate);
3639
extern void _PyEval_InitRuntimeState(struct _ceval_runtime_state *);
37-
// extern void _PyEval_InitState(struct _ceval_state *, PyThread_type_lock);
38-
// extern void _PyEval_FiniState(struct _ceval_state *ceval);
40+
extern void _PyEval_InitState(struct _ceval_state *, PyThread_type_lock);
41+
extern void _PyEval_FiniState(struct _ceval_state *ceval);
3942
PyAPI_FUNC(void) _PyEval_SignalReceived(PyInterpreterState *interp);
4043
PyAPI_FUNC(int) _PyEval_AddPendingCall(
4144
PyInterpreterState *interp,
@@ -71,7 +74,6 @@ extern PyObject* _PyEval_BuiltinsFromGlobals(
7174
PyObject *globals);
7275

7376

74-
/* GraalVM change
7577
static inline PyObject*
7678
_PyEval_EvalFrame(PyThreadState *tstate, struct _PyInterpreterFrame *frame, int throwflag)
7779
{
@@ -80,7 +82,6 @@ _PyEval_EvalFrame(PyThreadState *tstate, struct _PyInterpreterFrame *frame, int
8082
}
8183
return tstate->interp->eval_frame(tstate, frame, throwflag);
8284
}
83-
*/
8485

8586
extern PyObject*
8687
_PyEval_Vector(PyThreadState *tstate,
@@ -95,6 +96,7 @@ extern void _PyEval_FiniGIL(PyInterpreterState *interp);
9596
extern void _PyEval_ReleaseLock(PyThreadState *tstate);
9697

9798
extern void _PyEval_DeactivateOpCache(void);
99+
#endif // GraalPy change
98100

99101

100102
/* --- _Py_EnterRecursiveCall() ----------------------------------------- */
@@ -122,10 +124,7 @@ static inline int _Py_EnterRecursiveCallTstate(PyThreadState *tstate,
122124
}
123125

124126
static inline int _Py_EnterRecursiveCall(const char *where) {
125-
/* GraalVM change
126127
PyThreadState *tstate = _PyThreadState_GET();
127-
*/
128-
PyThreadState *tstate = PyThreadState_GET();
129128
return _Py_EnterRecursiveCallTstate(tstate, where);
130129
}
131130

@@ -134,16 +133,15 @@ static inline void _Py_LeaveRecursiveCallTstate(PyThreadState *tstate) {
134133
}
135134

136135
static inline void _Py_LeaveRecursiveCall(void) {
137-
/* GraalVM change
138136
PyThreadState *tstate = _PyThreadState_GET();
139-
*/
140-
PyThreadState *tstate = PyThreadState_GET();
141137
_Py_LeaveRecursiveCallTstate(tstate);
142138
}
143139

140+
#if 0 // GraalPy change
144141
extern struct _PyInterpreterFrame* _PyEval_GetFrame(void);
145142

146143
extern PyObject* _Py_MakeCoro(PyFunctionObject *func);
144+
#endif // GraalPy change
147145

148146
#ifdef __cplusplus
149147
}

graalpython/com.oracle.graal.python.cext/include/internal/pycore_pystate.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ extern "C" {
1313
# error "this header requires Py_BUILD_CORE define"
1414
#endif
1515

16-
// #include "pycore_runtime.h" /* PyRuntimeState */
16+
#if 0 // GraalPy change
17+
#include "pycore_runtime.h" /* PyRuntimeState */
1718

1819

1920
/* Check if the current thread is the main thread.
@@ -80,6 +81,7 @@ _PyRuntimeState_GetThreadState(_PyRuntimeState *runtime)
8081
{
8182
return (PyThreadState*)_Py_atomic_load_relaxed(&runtime->gilstate.tstate_current);
8283
}
84+
#endif // GraalPy change
8385

8486
/* Get the current Python thread state.
8587
@@ -97,6 +99,7 @@ _PyThreadState_GET(void)
9799
return PyThreadState_Get();
98100
}
99101

102+
#if 0 // GraalPy change
100103
PyAPI_FUNC(void) _Py_NO_RETURN _Py_FatalError_TstateNULL(const char *func);
101104

102105
static inline void
@@ -172,6 +175,7 @@ PyAPI_FUNC(int) _PyState_AddModule(
172175

173176

174177
PyAPI_FUNC(int) _PyOS_InterruptOccurred(PyThreadState *tstate);
178+
#endif // GraalPy change
175179

176180
#ifdef __cplusplus
177181
}

graalpython/com.oracle.graal.python.cext/src/abstract.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
#include "pycore_object.h" // _Py_CheckSlotResult()
1515
#endif // GraalPy change
1616
#include "pycore_pyerrors.h" // _PyErr_Occurred()
17-
#if 0 // GraalPy change
1817
#include "pycore_pystate.h" // _PyThreadState_GET()
18+
#if 0 // GraalPy change
1919
#include "pycore_unionobject.h" // _PyUnion_Check()
2020
#endif // GraalPy change
2121
#include <ctype.h>
@@ -66,7 +66,7 @@ type_error(const char *msg, PyObject *obj)
6666
static PyObject *
6767
null_error(void)
6868
{
69-
PyThreadState *tstate = NULL; // GraalPy change: don't get thread state
69+
PyThreadState *tstate = _PyThreadState_GET();
7070
if (!_PyErr_Occurred(tstate)) {
7171
_PyErr_SetString(tstate, PyExc_SystemError,
7272
"null argument to internal routine");
@@ -1117,7 +1117,6 @@ BINARY_FUNC(PyNumber_Subtract, nb_subtract, "-")
11171117
BINARY_FUNC(PyNumber_Divmod, nb_divmod, "divmod()")
11181118
#endif // GraalPy change
11191119

1120-
11211120
PyObject *
11221121
PyNumber_Add(PyObject *v, PyObject *w)
11231122
{
@@ -1449,7 +1448,7 @@ PyNumber_AsSsize_t(PyObject *item, PyObject *err)
14491448
if (result != -1)
14501449
goto finish;
14511450

1452-
PyThreadState *tstate = NULL; // GraalPy change: don't get thread state
1451+
PyThreadState *tstate = _PyThreadState_GET();
14531452
runerr = _PyErr_Occurred(tstate);
14541453
if (!runerr) {
14551454
goto finish;

graalpython/com.oracle.graal.python.cext/src/call.c

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111
#endif // GraalPy change
1212
#include "pycore_object.h" // _PyObject_GC_TRACK()
1313
#include "pycore_pyerrors.h" // _PyErr_Occurred()
14-
#if 0 // GraalPy change
1514
#include "pycore_pystate.h" // _PyThreadState_GET()
16-
#endif // GraalPy change
1715
#include "pycore_tuple.h" // _PyTuple_ITEMS()
1816
#include "frameobject.h" // _PyFrame_New_NoTrack()
1917

@@ -199,7 +197,7 @@ PyObject *
199197
PyObject_VectorcallDict(PyObject *callable, PyObject *const *args,
200198
size_t nargsf, PyObject *kwargs)
201199
{
202-
PyThreadState *tstate = NULL; // GraalPy change: don't get thread state
200+
PyThreadState *tstate = _PyThreadState_GET();
203201
return _PyObject_FastCallDictTstate(tstate, callable, args, nargsf, kwargs);
204202
}
205203

@@ -305,8 +303,7 @@ _PyVectorcall_Call(PyThreadState *tstate, vectorcallfunc func,
305303
PyObject *
306304
PyVectorcall_Call(PyObject *callable, PyObject *tuple, PyObject *kwargs)
307305
{
308-
// GraalPy change: don't get thread state
309-
PyThreadState *tstate = NULL;
306+
PyThreadState *tstate = _PyThreadState_GET();
310307

311308
/* get vectorcallfunc as in _PyVectorcall_Function, but without
312309
* the Py_TPFLAGS_HAVE_VECTORCALL check */
@@ -336,7 +333,7 @@ PyObject *
336333
PyObject_Vectorcall(PyObject *callable, PyObject *const *args,
337334
size_t nargsf, PyObject *kwnames)
338335
{
339-
PyThreadState *tstate = NULL; // GraalPy change: don't get thread state
336+
PyThreadState *tstate = _PyThreadState_GET();
340337
return _PyObject_VectorcallTstate(tstate, callable,
341338
args, nargsf, kwnames);
342339
}
@@ -345,7 +342,7 @@ PyObject_Vectorcall(PyObject *callable, PyObject *const *args,
345342
PyObject *
346343
_PyObject_FastCall(PyObject *func, PyObject *const *args, Py_ssize_t nargs)
347344
{
348-
PyThreadState *tstate = NULL; // GraalPy change: don't get thread state
345+
PyThreadState *tstate = _PyThreadState_GET();
349346
return _PyObject_FastCallTstate(tstate, func, args, nargs);
350347
}
351348

@@ -416,7 +413,7 @@ PyObject_CallOneArg(PyObject *func, PyObject *arg)
416413
PyObject *_args[2];
417414
PyObject **args = _args + 1; // For PY_VECTORCALL_ARGUMENTS_OFFSET
418415
args[0] = arg;
419-
PyThreadState *tstate = NULL; // GraalPy change: don't get thread state
416+
PyThreadState *tstate = _PyThreadState_GET();
420417
size_t nargsf = 1 | PY_VECTORCALL_ARGUMENTS_OFFSET;
421418
return _PyObject_VectorcallTstate(tstate, func, args, nargsf, NULL);
422419
}
@@ -875,8 +872,7 @@ PyObject_VectorcallMethod(PyObject *name, PyObject *const *args,
875872
assert(args != NULL);
876873
assert(PyVectorcall_NARGS(nargsf) >= 1);
877874

878-
// GraalPy change: don't get thread state
879-
PyThreadState *tstate = NULL;
875+
PyThreadState *tstate = _PyThreadState_GET();
880876
PyObject *callable = NULL;
881877
/* Use args[0] as "self" argument */
882878
int unbound = _PyObject_GetMethod(args[0], name, &callable);

graalpython/com.oracle.graal.python.cext/src/errors.c

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
#include "pycore_initconfig.h" // _PyStatus_ERR()
1414
#endif // GraalPy change
1515
#include "pycore_pyerrors.h" // _PyErr_Format()
16-
#if 0 // GraalPy change
1716
#include "pycore_pystate.h" // _PyThreadState_GET()
17+
#if 0 // GraalPy change
1818
#include "pycore_structseq.h" // _PyStructSequence_FiniType()
1919
#include "pycore_sysmodule.h" // _PySys_Audit()
2020
#include "pycore_traceback.h" // _PyTraceBack_FromFrame()
@@ -106,7 +106,7 @@ _PyErr_SetObject(PyThreadState *tstate, PyObject *exception, PyObject *value)
106106
void
107107
PyErr_SetObject(PyObject *exception, PyObject *value)
108108
{
109-
PyThreadState *tstate = NULL; // GraalPy change: don't get thread state
109+
PyThreadState *tstate = _PyThreadState_GET();
110110
_PyErr_SetObject(tstate, exception, value);
111111
}
112112

@@ -138,7 +138,7 @@ _PyErr_SetNone(PyThreadState *tstate, PyObject *exception)
138138
void
139139
PyErr_SetNone(PyObject *exception)
140140
{
141-
PyThreadState *tstate = NULL; // GraalPy change: don't get thread state
141+
PyThreadState *tstate = _PyThreadState_GET();
142142
_PyErr_SetNone(tstate, exception);
143143
}
144144

@@ -157,7 +157,7 @@ _PyErr_SetString(PyThreadState *tstate, PyObject *exception,
157157
void
158158
PyErr_SetString(PyObject *exception, const char *string)
159159
{
160-
PyThreadState *tstate = NULL; // GraalPy change: don't get thread state
160+
PyThreadState *tstate = _PyThreadState_GET();
161161
_PyErr_SetString(tstate, exception, string);
162162
}
163163

@@ -217,7 +217,7 @@ _PyErr_ExceptionMatches(PyThreadState *tstate, PyObject *exc)
217217
int
218218
PyErr_ExceptionMatches(PyObject *exc)
219219
{
220-
PyThreadState *tstate = NULL; // GraalPy change: don't get thread state
220+
PyThreadState *tstate = _PyThreadState_GET();
221221
return _PyErr_ExceptionMatches(tstate, exc);
222222
}
223223

@@ -245,7 +245,7 @@ _PyErr_NormalizeException(PyThreadState *tstate, PyObject **exc,
245245
void
246246
PyErr_NormalizeException(PyObject **exc, PyObject **val, PyObject **tb)
247247
{
248-
PyThreadState *tstate = NULL; // GraalPy change: don't get thread state
248+
PyThreadState *tstate = _PyThreadState_GET();
249249
_PyErr_NormalizeException(tstate, exc, val, tb);
250250
}
251251

@@ -275,7 +275,7 @@ _PyErr_Fetch(PyThreadState *tstate, PyObject **p_type, PyObject **p_value,
275275
void
276276
PyErr_Fetch(PyObject **p_type, PyObject **p_value, PyObject **p_traceback)
277277
{
278-
PyThreadState *tstate = NULL; // GraalPy change: don't get thread state
278+
PyThreadState *tstate = _PyThreadState_GET();
279279
_PyErr_Fetch(tstate, p_type, p_value, p_traceback);
280280
}
281281

@@ -290,7 +290,7 @@ _PyErr_Clear(PyThreadState *tstate)
290290
void
291291
PyErr_Clear(void)
292292
{
293-
PyThreadState *tstate = NULL; // GraalPy change: don't get thread state
293+
PyThreadState *tstate = _PyThreadState_GET();
294294
_PyErr_Clear(tstate);
295295
}
296296

@@ -370,7 +370,7 @@ PyErr_SetHandledException(PyObject *exc)
370370
void
371371
PyErr_GetExcInfo(PyObject **p_type, PyObject **p_value, PyObject **p_traceback)
372372
{
373-
PyThreadState *tstate = NULL; // GraalPy change: don't get thread state
373+
PyThreadState *tstate = _PyThreadState_GET();
374374
_PyErr_GetExcInfo(tstate, p_type, p_value, p_traceback);
375375
}
376376

@@ -542,7 +542,7 @@ NO_INLINE // GraalPy change: disallow bitcode inlining
542542
PyObject *
543543
_PyErr_FormatFromCause(PyObject *exception, const char *format, ...)
544544
{
545-
PyThreadState *tstate = NULL; // GraalPy change: don't get thread state
545+
PyThreadState *tstate = _PyThreadState_GET();
546546
va_list vargs;
547547
#ifdef HAVE_STDARG_PROTOTYPES
548548
va_start(vargs, format);
@@ -559,7 +559,7 @@ _PyErr_FormatFromCause(PyObject *exception, const char *format, ...)
559559
int
560560
PyErr_BadArgument(void)
561561
{
562-
PyThreadState *tstate = NULL; // GraalPy change: don't get thread state
562+
PyThreadState *tstate = _PyThreadState_GET();
563563
_PyErr_SetString(tstate, PyExc_TypeError,
564564
"bad argument type for built-in operation");
565565
return 0;
@@ -583,7 +583,7 @@ _PyErr_NoMemory(PyThreadState *tstate)
583583
PyObject *
584584
PyErr_NoMemory(void)
585585
{
586-
PyThreadState *tstate = NULL; // GraalPy change: don't get thread state
586+
PyThreadState *tstate = _PyThreadState_GET();
587587
return _PyErr_NoMemory(tstate);
588588
}
589589

@@ -596,7 +596,7 @@ PyErr_SetFromErrnoWithFilenameObject(PyObject *exc, PyObject *filenameObject)
596596
PyObject *
597597
PyErr_SetFromErrnoWithFilenameObjects(PyObject *exc, PyObject *filenameObject, PyObject *filenameObject2)
598598
{
599-
PyThreadState *tstate = NULL; // GraalPy change: don't get thread state
599+
PyThreadState *tstate = _PyThreadState_GET();
600600
PyObject *message;
601601
PyObject *v, *args;
602602
int i = errno;
@@ -865,7 +865,7 @@ PyErr_SetImportError(PyObject *msg, PyObject *name, PyObject *path)
865865
void
866866
_PyErr_BadInternalCall(const char *filename, int lineno)
867867
{
868-
PyThreadState *tstate = NULL; // GraalPy change: don't get thread state
868+
PyThreadState *tstate = _PyThreadState_GET();
869869
_PyErr_Format(tstate, PyExc_SystemError,
870870
"%s:%d: bad argument to internal function",
871871
filename, lineno);
@@ -878,7 +878,7 @@ void
878878
PyErr_BadInternalCall(void)
879879
{
880880
assert(0 && "bad argument to internal function");
881-
PyThreadState *tstate = NULL; // GraalPy change: don't get thread state
881+
PyThreadState *tstate = _PyThreadState_GET();
882882
_PyErr_SetString(tstate, PyExc_SystemError,
883883
"bad argument to internal function");
884884
}
@@ -907,7 +907,7 @@ _PyErr_FormatV(PyThreadState *tstate, PyObject *exception,
907907
PyObject *
908908
PyErr_FormatV(PyObject *exception, const char *format, va_list vargs)
909909
{
910-
PyThreadState *tstate = NULL; // GraalPy change: don't get thread state
910+
PyThreadState *tstate = _PyThreadState_GET();
911911
return _PyErr_FormatV(tstate, exception, format, vargs);
912912
}
913913

@@ -933,7 +933,7 @@ NO_INLINE // GraalPy change: disallow bitcode inlining
933933
PyObject *
934934
PyErr_Format(PyObject *exception, const char *format, ...)
935935
{
936-
PyThreadState *tstate = NULL; // GrallPy change: don't get thread state
936+
PyThreadState *tstate = _PyThreadState_GET();
937937
va_list vargs;
938938
#ifdef HAVE_STDARG_PROTOTYPES
939939
va_start(vargs, format);

0 commit comments

Comments
 (0)