@@ -203,13 +203,15 @@ PyContextVar_Get(PyObject *ovar, PyObject *def, PyObject **val)
203
203
goto not_found ;
204
204
}
205
205
206
+ #ifndef Py_GIL_DISABLED
206
207
if (var -> var_cached != NULL &&
207
208
var -> var_cached_tsid == ts -> id &&
208
209
var -> var_cached_tsver == ts -> context_ver )
209
210
{
210
211
* val = var -> var_cached ;
211
212
goto found ;
212
213
}
214
+ #endif
213
215
214
216
assert (PyContext_CheckExact (ts -> context ));
215
217
PyHamtObject * vars = ((PyContext * )ts -> context )-> ctx_vars ;
@@ -221,9 +223,11 @@ PyContextVar_Get(PyObject *ovar, PyObject *def, PyObject **val)
221
223
}
222
224
if (res == 1 ) {
223
225
assert (found != NULL );
226
+ #ifndef Py_GIL_DISABLED
224
227
var -> var_cached = found ; /* borrow */
225
228
var -> var_cached_tsid = ts -> id ;
226
229
var -> var_cached_tsver = ts -> context_ver ;
230
+ #endif
227
231
228
232
* val = found ;
229
233
goto found ;
@@ -723,8 +727,10 @@ PyTypeObject PyContext_Type = {
723
727
static int
724
728
contextvar_set (PyContextVar * var , PyObject * val )
725
729
{
730
+ #ifndef Py_GIL_DISABLED
726
731
var -> var_cached = NULL ;
727
732
PyThreadState * ts = _PyThreadState_GET ();
733
+ #endif
728
734
729
735
PyContext * ctx = context_get ();
730
736
if (ctx == NULL ) {
@@ -739,16 +745,20 @@ contextvar_set(PyContextVar *var, PyObject *val)
739
745
740
746
Py_SETREF (ctx -> ctx_vars , new_vars );
741
747
748
+ #ifndef Py_GIL_DISABLED
742
749
var -> var_cached = val ; /* borrow */
743
750
var -> var_cached_tsid = ts -> id ;
744
751
var -> var_cached_tsver = ts -> context_ver ;
752
+ #endif
745
753
return 0 ;
746
754
}
747
755
748
756
static int
749
757
contextvar_del (PyContextVar * var )
750
758
{
759
+ #ifndef Py_GIL_DISABLED
751
760
var -> var_cached = NULL ;
761
+ #endif
752
762
753
763
PyContext * ctx = context_get ();
754
764
if (ctx == NULL ) {
@@ -823,9 +833,11 @@ contextvar_new(PyObject *name, PyObject *def)
823
833
824
834
var -> var_default = Py_XNewRef (def );
825
835
836
+ #ifndef Py_GIL_DISABLED
826
837
var -> var_cached = NULL ;
827
838
var -> var_cached_tsid = 0 ;
828
839
var -> var_cached_tsver = 0 ;
840
+ #endif
829
841
830
842
if (_PyObject_GC_MAY_BE_TRACKED (name ) ||
831
843
(def != NULL && _PyObject_GC_MAY_BE_TRACKED (def )))
@@ -863,9 +875,11 @@ contextvar_tp_clear(PyContextVar *self)
863
875
{
864
876
Py_CLEAR (self -> var_name );
865
877
Py_CLEAR (self -> var_default );
878
+ #ifndef Py_GIL_DISABLED
866
879
self -> var_cached = NULL ;
867
880
self -> var_cached_tsid = 0 ;
868
881
self -> var_cached_tsver = 0 ;
882
+ #endif
869
883
return 0 ;
870
884
}
871
885
0 commit comments