File tree Expand file tree Collapse file tree 3 files changed +21
-11
lines changed
com.oracle.graal.python.cext
com.oracle.graal.python.jni/src Expand file tree Collapse file tree 3 files changed +21
-11
lines changed Original file line number Diff line number Diff line change 1
- /* Copyright (c) 2018, 2022 , Oracle and/or its affiliates.
1
+ /* Copyright (c) 2018, 2023 , Oracle and/or its affiliates.
2
2
* Copyright (C) 1996-2020 Python Software Foundation
3
3
*
4
4
* Licensed under the PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
@@ -97,9 +97,8 @@ PyAPI_FUNC(PyFrameObject*) PyThreadState_GetFrame(PyThreadState *tstate);
97
97
PyAPI_FUNC (uint64_t ) PyThreadState_GetID (PyThreadState * tstate );
98
98
#endif
99
99
100
- typedef
101
- enum {PyGILState_LOCKED , PyGILState_UNLOCKED }
102
- PyGILState_STATE ;
100
+ /* GraalVM change: we need more state bits */
101
+ typedef int PyGILState_STATE ;
103
102
104
103
105
104
/* Ensure that the current thread is ready to call the Python
Original file line number Diff line number Diff line change @@ -118,13 +118,12 @@ int PyState_RemoveModule(struct PyModuleDef* def) {
118
118
119
119
// This function has a different implementation on NFI in capi_native.c
120
120
PyAPI_FUNC (PyGILState_STATE ) PyGILState_Ensure () {
121
- int res = GraalPyTruffleGILState_Ensure ();
122
- return res ? PyGILState_LOCKED : PyGILState_UNLOCKED ;
121
+ return GraalPyTruffleGILState_Ensure ();
123
122
}
124
123
125
124
// This function has a different implementation on NFI in capi_native.c
126
125
PyAPI_FUNC (void ) PyGILState_Release (PyGILState_STATE state ) {
127
- if (state == PyGILState_LOCKED ) {
126
+ if (state ) {
128
127
GraalPyTruffleGILState_Release ();
129
128
}
130
129
}
Original file line number Diff line number Diff line change @@ -465,15 +465,27 @@ void finalizeCAPI() {
465
465
GraalPy_set_PyObject_ob_refcnt = nop_GraalPy_set_PyObject_ob_refcnt ;
466
466
}
467
467
468
+ #define _PYGILSTATE_LOCKED 0x1
469
+ #define _PYGILSTATE_ATTACHED 0x2
470
+
468
471
PyAPI_FUNC (PyGILState_STATE ) PyGILState_Ensure () {
469
- (* TRUFFLE_CONTEXT )-> attachCurrentThread (TRUFFLE_CONTEXT );
470
- int res = PyTruffleGILState_Ensure ();
471
- return res ? PyGILState_LOCKED : PyGILState_UNLOCKED ;
472
+ int result = 0 ;
473
+ if ((* TRUFFLE_CONTEXT )-> getTruffleEnv (TRUFFLE_CONTEXT ) == NULL ) {
474
+ (* TRUFFLE_CONTEXT )-> attachCurrentThread (TRUFFLE_CONTEXT );
475
+ result |= _PYGILSTATE_ATTACHED ;
476
+ }
477
+ int locked = PyTruffleGILState_Ensure ();
478
+ if (locked ) {
479
+ result |= _PYGILSTATE_LOCKED ;
480
+ }
481
+ return result ;
472
482
}
473
483
474
484
PyAPI_FUNC (void ) PyGILState_Release (PyGILState_STATE state ) {
475
- if (state == PyGILState_LOCKED ) {
485
+ if (state & _PYGILSTATE_LOCKED ) {
476
486
PyTruffleGILState_Release ();
487
+ }
488
+ if (state & _PYGILSTATE_ATTACHED ) {
477
489
(* TRUFFLE_CONTEXT )-> detachCurrentThread (TRUFFLE_CONTEXT );
478
490
}
479
491
}
You can’t perform that action at this time.
0 commit comments