@@ -419,6 +419,9 @@ class _contextvars.Context "PyContext *" "&PyContext_Type"
419
419
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=bdf87f8e0cb580e8]*/
420
420
421
421
422
+ #define _PyContext_CAST (op ) ((PyContext *)(op))
423
+
424
+
422
425
static inline PyContext *
423
426
_context_alloc (void )
424
427
{
@@ -513,37 +516,40 @@ context_tp_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
513
516
}
514
517
515
518
static int
516
- context_tp_clear (PyContext * self )
519
+ context_tp_clear (PyObject * op )
517
520
{
521
+ PyContext * self = _PyContext_CAST (op );
518
522
Py_CLEAR (self -> ctx_prev );
519
523
Py_CLEAR (self -> ctx_vars );
520
524
return 0 ;
521
525
}
522
526
523
527
static int
524
- context_tp_traverse (PyContext * self , visitproc visit , void * arg )
528
+ context_tp_traverse (PyObject * op , visitproc visit , void * arg )
525
529
{
530
+ PyContext * self = _PyContext_CAST (op );
526
531
Py_VISIT (self -> ctx_prev );
527
532
Py_VISIT (self -> ctx_vars );
528
533
return 0 ;
529
534
}
530
535
531
536
static void
532
- context_tp_dealloc (PyContext * self )
537
+ context_tp_dealloc (PyObject * self )
533
538
{
534
539
_PyObject_GC_UNTRACK (self );
535
-
536
- if (self -> ctx_weakreflist != NULL ) {
537
- PyObject_ClearWeakRefs (( PyObject * ) self );
540
+ PyContext * ctx = _PyContext_CAST ( self );
541
+ if (ctx -> ctx_weakreflist != NULL ) {
542
+ PyObject_ClearWeakRefs (self );
538
543
}
539
544
(void )context_tp_clear (self );
540
545
541
546
_Py_FREELIST_FREE (contexts , self , Py_TYPE (self )-> tp_free );
542
547
}
543
548
544
549
static PyObject *
545
- context_tp_iter (PyContext * self )
550
+ context_tp_iter (PyObject * op )
546
551
{
552
+ PyContext * self = _PyContext_CAST (op );
547
553
return _PyHamt_NewIterKeys (self -> ctx_vars );
548
554
}
549
555
@@ -575,18 +581,20 @@ context_tp_richcompare(PyObject *v, PyObject *w, int op)
575
581
}
576
582
577
583
static Py_ssize_t
578
- context_tp_len (PyContext * self )
584
+ context_tp_len (PyObject * op )
579
585
{
586
+ PyContext * self = _PyContext_CAST (op );
580
587
return _PyHamt_Len (self -> ctx_vars );
581
588
}
582
589
583
590
static PyObject *
584
- context_tp_subscript (PyContext * self , PyObject * key )
591
+ context_tp_subscript (PyObject * op , PyObject * key )
585
592
{
586
593
if (context_check_key_type (key )) {
587
594
return NULL ;
588
595
}
589
596
PyObject * val = NULL ;
597
+ PyContext * self = _PyContext_CAST (op );
590
598
int found = _PyHamt_Find (self -> ctx_vars , key , & val );
591
599
if (found < 0 ) {
592
600
return NULL ;
@@ -599,12 +607,13 @@ context_tp_subscript(PyContext *self, PyObject *key)
599
607
}
600
608
601
609
static int
602
- context_tp_contains (PyContext * self , PyObject * key )
610
+ context_tp_contains (PyObject * op , PyObject * key )
603
611
{
604
612
if (context_check_key_type (key )) {
605
613
return -1 ;
606
614
}
607
615
PyObject * val = NULL ;
616
+ PyContext * self = _PyContext_CAST (op );
608
617
return _PyHamt_Find (self -> ctx_vars , key , & val );
609
618
}
610
619
@@ -701,7 +710,7 @@ _contextvars_Context_copy_impl(PyContext *self)
701
710
702
711
703
712
static PyObject *
704
- context_run (PyContext * self , PyObject * const * args ,
713
+ context_run (PyObject * self , PyObject * const * args ,
705
714
Py_ssize_t nargs , PyObject * kwnames )
706
715
{
707
716
PyThreadState * ts = _PyThreadState_GET ();
@@ -712,14 +721,14 @@ context_run(PyContext *self, PyObject *const *args,
712
721
return NULL ;
713
722
}
714
723
715
- if (_PyContext_Enter (ts , ( PyObject * ) self )) {
724
+ if (_PyContext_Enter (ts , self )) {
716
725
return NULL ;
717
726
}
718
727
719
728
PyObject * call_result = _PyObject_VectorcallTstate (
720
729
ts , args [0 ], args + 1 , nargs - 1 , kwnames );
721
730
722
- if (_PyContext_Exit (ts , ( PyObject * ) self )) {
731
+ if (_PyContext_Exit (ts , self )) {
723
732
Py_XDECREF (call_result );
724
733
return NULL ;
725
734
}
@@ -739,21 +748,12 @@ static PyMethodDef PyContext_methods[] = {
739
748
};
740
749
741
750
static PySequenceMethods PyContext_as_sequence = {
742
- 0 , /* sq_length */
743
- 0 , /* sq_concat */
744
- 0 , /* sq_repeat */
745
- 0 , /* sq_item */
746
- 0 , /* sq_slice */
747
- 0 , /* sq_ass_item */
748
- 0 , /* sq_ass_slice */
749
- (objobjproc )context_tp_contains , /* sq_contains */
750
- 0 , /* sq_inplace_concat */
751
- 0 , /* sq_inplace_repeat */
751
+ .sq_contains = context_tp_contains
752
752
};
753
753
754
754
static PyMappingMethods PyContext_as_mapping = {
755
- ( lenfunc ) context_tp_len , /* mp_length */
756
- ( binaryfunc ) context_tp_subscript , /* mp_subscript */
755
+ . mp_length = context_tp_len ,
756
+ . mp_subscript = context_tp_subscript
757
757
};
758
758
759
759
PyTypeObject PyContext_Type = {
@@ -763,13 +763,13 @@ PyTypeObject PyContext_Type = {
763
763
.tp_methods = PyContext_methods ,
764
764
.tp_as_mapping = & PyContext_as_mapping ,
765
765
.tp_as_sequence = & PyContext_as_sequence ,
766
- .tp_iter = ( getiterfunc ) context_tp_iter ,
767
- .tp_dealloc = ( destructor ) context_tp_dealloc ,
766
+ .tp_iter = context_tp_iter ,
767
+ .tp_dealloc = context_tp_dealloc ,
768
768
.tp_getattro = PyObject_GenericGetAttr ,
769
769
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC ,
770
770
.tp_richcompare = context_tp_richcompare ,
771
- .tp_traverse = ( traverseproc ) context_tp_traverse ,
772
- .tp_clear = ( inquiry ) context_tp_clear ,
771
+ .tp_traverse = context_tp_traverse ,
772
+ .tp_clear = context_tp_clear ,
773
773
.tp_new = context_tp_new ,
774
774
.tp_weaklistoffset = offsetof(PyContext , ctx_weakreflist ),
775
775
.tp_hash = PyObject_HashNotImplemented ,
@@ -909,6 +909,9 @@ class _contextvars.ContextVar "PyContextVar *" "&PyContextVar_Type"
909
909
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=445da935fa8883c3]*/
910
910
911
911
912
+ #define _PyContextVar_CAST (op ) ((PyContextVar *)(op))
913
+
914
+
912
915
static PyObject *
913
916
contextvar_tp_new (PyTypeObject * type , PyObject * args , PyObject * kwds )
914
917
{
@@ -926,8 +929,9 @@ contextvar_tp_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
926
929
}
927
930
928
931
static int
929
- contextvar_tp_clear (PyContextVar * self )
932
+ contextvar_tp_clear (PyObject * op )
930
933
{
934
+ PyContextVar * self = _PyContextVar_CAST (op );
931
935
Py_CLEAR (self -> var_name );
932
936
Py_CLEAR (self -> var_default );
933
937
#ifndef Py_GIL_DISABLED
@@ -939,30 +943,33 @@ contextvar_tp_clear(PyContextVar *self)
939
943
}
940
944
941
945
static int
942
- contextvar_tp_traverse (PyContextVar * self , visitproc visit , void * arg )
946
+ contextvar_tp_traverse (PyObject * op , visitproc visit , void * arg )
943
947
{
948
+ PyContextVar * self = _PyContextVar_CAST (op );
944
949
Py_VISIT (self -> var_name );
945
950
Py_VISIT (self -> var_default );
946
951
return 0 ;
947
952
}
948
953
949
954
static void
950
- contextvar_tp_dealloc (PyContextVar * self )
955
+ contextvar_tp_dealloc (PyObject * self )
951
956
{
952
957
PyObject_GC_UnTrack (self );
953
958
(void )contextvar_tp_clear (self );
954
959
Py_TYPE (self )-> tp_free (self );
955
960
}
956
961
957
962
static Py_hash_t
958
- contextvar_tp_hash (PyContextVar * self )
963
+ contextvar_tp_hash (PyObject * op )
959
964
{
965
+ PyContextVar * self = _PyContextVar_CAST (op );
960
966
return self -> var_hash ;
961
967
}
962
968
963
969
static PyObject *
964
- contextvar_tp_repr (PyContextVar * self )
970
+ contextvar_tp_repr (PyObject * op )
965
971
{
972
+ PyContextVar * self = _PyContextVar_CAST (op );
966
973
// Estimation based on the shortest name and default value,
967
974
// but maximize the pointer size.
968
975
// "<ContextVar name='a' at 0x1234567812345678>"
@@ -1106,15 +1113,15 @@ PyTypeObject PyContextVar_Type = {
1106
1113
sizeof (PyContextVar ),
1107
1114
.tp_methods = PyContextVar_methods ,
1108
1115
.tp_members = PyContextVar_members ,
1109
- .tp_dealloc = ( destructor ) contextvar_tp_dealloc ,
1116
+ .tp_dealloc = contextvar_tp_dealloc ,
1110
1117
.tp_getattro = PyObject_GenericGetAttr ,
1111
1118
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC ,
1112
- .tp_traverse = ( traverseproc ) contextvar_tp_traverse ,
1113
- .tp_clear = ( inquiry ) contextvar_tp_clear ,
1119
+ .tp_traverse = contextvar_tp_traverse ,
1120
+ .tp_clear = contextvar_tp_clear ,
1114
1121
.tp_new = contextvar_tp_new ,
1115
1122
.tp_free = PyObject_GC_Del ,
1116
- .tp_hash = ( hashfunc ) contextvar_tp_hash ,
1117
- .tp_repr = ( reprfunc ) contextvar_tp_repr ,
1123
+ .tp_hash = contextvar_tp_hash ,
1124
+ .tp_repr = contextvar_tp_repr ,
1118
1125
};
1119
1126
1120
1127
@@ -1129,6 +1136,9 @@ class _contextvars.Token "PyContextToken *" "&PyContextToken_Type"
1129
1136
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=338a5e2db13d3f5b]*/
1130
1137
1131
1138
1139
+ #define _PyContextToken_CAST (op ) ((PyContextToken *)(op))
1140
+
1141
+
1132
1142
static PyObject *
1133
1143
token_tp_new (PyTypeObject * type , PyObject * args , PyObject * kwds )
1134
1144
{
@@ -1138,34 +1148,37 @@ token_tp_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
1138
1148
}
1139
1149
1140
1150
static int
1141
- token_tp_clear (PyContextToken * self )
1151
+ token_tp_clear (PyObject * op )
1142
1152
{
1153
+ PyContextToken * self = _PyContextToken_CAST (op );
1143
1154
Py_CLEAR (self -> tok_ctx );
1144
1155
Py_CLEAR (self -> tok_var );
1145
1156
Py_CLEAR (self -> tok_oldval );
1146
1157
return 0 ;
1147
1158
}
1148
1159
1149
1160
static int
1150
- token_tp_traverse (PyContextToken * self , visitproc visit , void * arg )
1161
+ token_tp_traverse (PyObject * op , visitproc visit , void * arg )
1151
1162
{
1163
+ PyContextToken * self = _PyContextToken_CAST (op );
1152
1164
Py_VISIT (self -> tok_ctx );
1153
1165
Py_VISIT (self -> tok_var );
1154
1166
Py_VISIT (self -> tok_oldval );
1155
1167
return 0 ;
1156
1168
}
1157
1169
1158
1170
static void
1159
- token_tp_dealloc (PyContextToken * self )
1171
+ token_tp_dealloc (PyObject * self )
1160
1172
{
1161
1173
PyObject_GC_UnTrack (self );
1162
1174
(void )token_tp_clear (self );
1163
1175
Py_TYPE (self )-> tp_free (self );
1164
1176
}
1165
1177
1166
1178
static PyObject *
1167
- token_tp_repr (PyContextToken * self )
1179
+ token_tp_repr (PyObject * op )
1168
1180
{
1181
+ PyContextToken * self = _PyContextToken_CAST (op );
1169
1182
PyUnicodeWriter * writer = PyUnicodeWriter_Create (0 );
1170
1183
if (writer == NULL ) {
1171
1184
return NULL ;
@@ -1195,14 +1208,16 @@ token_tp_repr(PyContextToken *self)
1195
1208
}
1196
1209
1197
1210
static PyObject *
1198
- token_get_var (PyContextToken * self , void * Py_UNUSED (ignored ))
1211
+ token_get_var (PyObject * op , void * Py_UNUSED (ignored ))
1199
1212
{
1213
+ PyContextToken * self = _PyContextToken_CAST (op );
1200
1214
return Py_NewRef (self -> tok_var );;
1201
1215
}
1202
1216
1203
1217
static PyObject *
1204
- token_get_old_value (PyContextToken * self , void * Py_UNUSED (ignored ))
1218
+ token_get_old_value (PyObject * op , void * Py_UNUSED (ignored ))
1205
1219
{
1220
+ PyContextToken * self = _PyContextToken_CAST (op );
1206
1221
if (self -> tok_oldval == NULL ) {
1207
1222
return get_token_missing ();
1208
1223
}
@@ -1211,8 +1226,8 @@ token_get_old_value(PyContextToken *self, void *Py_UNUSED(ignored))
1211
1226
}
1212
1227
1213
1228
static PyGetSetDef PyContextTokenType_getsetlist [] = {
1214
- {"var" , ( getter ) token_get_var , NULL , NULL },
1215
- {"old_value" , ( getter ) token_get_old_value , NULL , NULL },
1229
+ {"var" , token_get_var , NULL , NULL },
1230
+ {"old_value" , token_get_old_value , NULL , NULL },
1216
1231
{NULL }
1217
1232
};
1218
1233
@@ -1228,15 +1243,15 @@ PyTypeObject PyContextToken_Type = {
1228
1243
sizeof (PyContextToken ),
1229
1244
.tp_methods = PyContextTokenType_methods ,
1230
1245
.tp_getset = PyContextTokenType_getsetlist ,
1231
- .tp_dealloc = ( destructor ) token_tp_dealloc ,
1246
+ .tp_dealloc = token_tp_dealloc ,
1232
1247
.tp_getattro = PyObject_GenericGetAttr ,
1233
1248
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC ,
1234
- .tp_traverse = ( traverseproc ) token_tp_traverse ,
1235
- .tp_clear = ( inquiry ) token_tp_clear ,
1249
+ .tp_traverse = token_tp_traverse ,
1250
+ .tp_clear = token_tp_clear ,
1236
1251
.tp_new = token_tp_new ,
1237
1252
.tp_free = PyObject_GC_Del ,
1238
1253
.tp_hash = PyObject_HashNotImplemented ,
1239
- .tp_repr = ( reprfunc ) token_tp_repr ,
1254
+ .tp_repr = token_tp_repr ,
1240
1255
};
1241
1256
1242
1257
static PyContextToken *
@@ -1270,7 +1285,7 @@ context_token_missing_tp_repr(PyObject *self)
1270
1285
}
1271
1286
1272
1287
static void
1273
- context_token_missing_tp_dealloc (_PyContextTokenMissing * Py_UNUSED (self ))
1288
+ context_token_missing_tp_dealloc (PyObject * Py_UNUSED (self ))
1274
1289
{
1275
1290
#ifdef Py_DEBUG
1276
1291
/* The singleton is statically allocated. */
@@ -1285,7 +1300,7 @@ PyTypeObject _PyContextTokenMissing_Type = {
1285
1300
PyVarObject_HEAD_INIT (& PyType_Type , 0 )
1286
1301
"Token.MISSING" ,
1287
1302
sizeof (_PyContextTokenMissing ),
1288
- .tp_dealloc = ( destructor ) context_token_missing_tp_dealloc ,
1303
+ .tp_dealloc = context_token_missing_tp_dealloc ,
1289
1304
.tp_getattro = PyObject_GenericGetAttr ,
1290
1305
.tp_flags = Py_TPFLAGS_DEFAULT ,
1291
1306
.tp_repr = context_token_missing_tp_repr ,
0 commit comments