@@ -395,6 +395,11 @@ static struct PyModuleDef sremodule;
395
395
static PyObject * pattern_new_match (_sremodulestate * , PatternObject * , SRE_STATE * , Py_ssize_t );
396
396
static PyObject * pattern_scanner (_sremodulestate * , PatternObject * , PyObject * , Py_ssize_t , Py_ssize_t );
397
397
398
+ #define _PatternObject_CAST (op ) ((PatternObject *)(op))
399
+ #define _MatchObject_CAST (op ) ((MatchObject *)(op))
400
+ #define _TemplateObject_CAST (op ) ((TemplateObject *)(op))
401
+ #define _ScannerObject_CAST (op ) ((ScannerObject *)(op))
402
+
398
403
/*[clinic input]
399
404
module _sre
400
405
class _sre.SRE_Pattern "PatternObject *" "get_sre_module_state_by_class(tp)->Pattern_Type"
@@ -699,8 +704,9 @@ pattern_error(Py_ssize_t status)
699
704
}
700
705
701
706
static int
702
- pattern_traverse (PatternObject * self , visitproc visit , void * arg )
707
+ pattern_traverse (PyObject * op , visitproc visit , void * arg )
703
708
{
709
+ PatternObject * self = _PatternObject_CAST (op );
704
710
Py_VISIT (Py_TYPE (self ));
705
711
Py_VISIT (self -> groupindex );
706
712
Py_VISIT (self -> indexgroup );
@@ -712,8 +718,9 @@ pattern_traverse(PatternObject *self, visitproc visit, void *arg)
712
718
}
713
719
714
720
static int
715
- pattern_clear (PatternObject * self )
721
+ pattern_clear (PyObject * op )
716
722
{
723
+ PatternObject * self = _PatternObject_CAST (op );
717
724
Py_CLEAR (self -> groupindex );
718
725
Py_CLEAR (self -> indexgroup );
719
726
Py_CLEAR (self -> pattern );
@@ -724,13 +731,13 @@ pattern_clear(PatternObject *self)
724
731
}
725
732
726
733
static void
727
- pattern_dealloc (PatternObject * self )
734
+ pattern_dealloc (PyObject * self )
728
735
{
729
736
PyTypeObject * tp = Py_TYPE (self );
730
-
731
737
PyObject_GC_UnTrack (self );
732
- if (self -> weakreflist != NULL ) {
733
- PyObject_ClearWeakRefs ((PyObject * ) self );
738
+ PatternObject * obj = _PatternObject_CAST (self );
739
+ if (obj -> weakreflist != NULL ) {
740
+ PyObject_ClearWeakRefs (self );
734
741
}
735
742
(void )pattern_clear (self );
736
743
tp -> tp_free (self );
@@ -1497,7 +1504,7 @@ _sre_SRE_Pattern__fail_after_impl(PatternObject *self, int count,
1497
1504
#endif /* Py_DEBUG */
1498
1505
1499
1506
static PyObject *
1500
- pattern_repr (PatternObject * obj )
1507
+ pattern_repr (PyObject * self )
1501
1508
{
1502
1509
static const struct {
1503
1510
const char * name ;
@@ -1512,6 +1519,8 @@ pattern_repr(PatternObject *obj)
1512
1519
{"re.DEBUG" , SRE_FLAG_DEBUG },
1513
1520
{"re.ASCII" , SRE_FLAG_ASCII },
1514
1521
};
1522
+
1523
+ PatternObject * obj = _PatternObject_CAST (self );
1515
1524
PyObject * result = NULL ;
1516
1525
PyObject * flag_items ;
1517
1526
size_t i ;
@@ -1579,8 +1588,9 @@ PyDoc_STRVAR(pattern_doc, "Compiled regular expression object.");
1579
1588
1580
1589
/* PatternObject's 'groupindex' method. */
1581
1590
static PyObject *
1582
- pattern_groupindex (PatternObject * self , void * Py_UNUSED (ignored ))
1591
+ pattern_groupindex (PyObject * op , void * Py_UNUSED (ignored ))
1583
1592
{
1593
+ PatternObject * self = _PatternObject_CAST (op );
1584
1594
if (self -> groupindex == NULL )
1585
1595
return PyDict_New ();
1586
1596
return PyDictProxy_New (self -> groupindex );
@@ -2245,8 +2255,9 @@ _validate(PatternObject *self)
2245
2255
/* match methods */
2246
2256
2247
2257
static int
2248
- match_traverse (MatchObject * self , visitproc visit , void * arg )
2258
+ match_traverse (PyObject * op , visitproc visit , void * arg )
2249
2259
{
2260
+ MatchObject * self = _MatchObject_CAST (op );
2250
2261
Py_VISIT (Py_TYPE (self ));
2251
2262
Py_VISIT (self -> string );
2252
2263
Py_VISIT (self -> regs );
@@ -2255,19 +2266,19 @@ match_traverse(MatchObject *self, visitproc visit, void *arg)
2255
2266
}
2256
2267
2257
2268
static int
2258
- match_clear (MatchObject * self )
2269
+ match_clear (PyObject * op )
2259
2270
{
2271
+ MatchObject * self = _MatchObject_CAST (op );
2260
2272
Py_CLEAR (self -> string );
2261
2273
Py_CLEAR (self -> regs );
2262
2274
Py_CLEAR (self -> pattern );
2263
2275
return 0 ;
2264
2276
}
2265
2277
2266
2278
static void
2267
- match_dealloc (MatchObject * self )
2279
+ match_dealloc (PyObject * self )
2268
2280
{
2269
2281
PyTypeObject * tp = Py_TYPE (self );
2270
-
2271
2282
PyObject_GC_UnTrack (self );
2272
2283
(void )match_clear (self );
2273
2284
tp -> tp_free (self );
@@ -2376,8 +2387,9 @@ _sre_SRE_Match_expand_impl(MatchObject *self, PyObject *template)
2376
2387
}
2377
2388
2378
2389
static PyObject *
2379
- match_group (MatchObject * self , PyObject * args )
2390
+ match_group (PyObject * op , PyObject * args )
2380
2391
{
2392
+ MatchObject * self = _MatchObject_CAST (op );
2381
2393
PyObject * result ;
2382
2394
Py_ssize_t i , size ;
2383
2395
@@ -2411,8 +2423,9 @@ match_group(MatchObject* self, PyObject* args)
2411
2423
}
2412
2424
2413
2425
static PyObject *
2414
- match_getitem (MatchObject * self , PyObject * name )
2426
+ match_getitem (PyObject * op , PyObject * name )
2415
2427
{
2428
+ MatchObject * self = _MatchObject_CAST (op );
2416
2429
return match_getslice (self , name , Py_None );
2417
2430
}
2418
2431
@@ -2654,16 +2667,18 @@ PyDoc_STRVAR(match_group_doc,
2654
2667
For 0 returns the entire match." );
2655
2668
2656
2669
static PyObject *
2657
- match_lastindex_get (MatchObject * self , void * Py_UNUSED (ignored ))
2670
+ match_lastindex_get (PyObject * op , void * Py_UNUSED (ignored ))
2658
2671
{
2672
+ MatchObject * self = _MatchObject_CAST (op );
2659
2673
if (self -> lastindex >= 0 )
2660
2674
return PyLong_FromSsize_t (self -> lastindex );
2661
2675
Py_RETURN_NONE ;
2662
2676
}
2663
2677
2664
2678
static PyObject *
2665
- match_lastgroup_get (MatchObject * self , void * Py_UNUSED (ignored ))
2679
+ match_lastgroup_get (PyObject * op , void * Py_UNUSED (ignored ))
2666
2680
{
2681
+ MatchObject * self = _MatchObject_CAST (op );
2667
2682
if (self -> pattern -> indexgroup &&
2668
2683
self -> lastindex >= 0 &&
2669
2684
self -> lastindex < PyTuple_GET_SIZE (self -> pattern -> indexgroup ))
@@ -2676,8 +2691,9 @@ match_lastgroup_get(MatchObject *self, void *Py_UNUSED(ignored))
2676
2691
}
2677
2692
2678
2693
static PyObject *
2679
- match_regs_get (MatchObject * self , void * Py_UNUSED (ignored ))
2694
+ match_regs_get (PyObject * op , void * Py_UNUSED (ignored ))
2680
2695
{
2696
+ MatchObject * self = _MatchObject_CAST (op );
2681
2697
if (self -> regs ) {
2682
2698
return Py_NewRef (self -> regs );
2683
2699
} else
@@ -2780,27 +2796,29 @@ pattern_new_match(_sremodulestate* module_state,
2780
2796
/* scanner methods (experimental) */
2781
2797
2782
2798
static int
2783
- scanner_traverse (ScannerObject * self , visitproc visit , void * arg )
2799
+ scanner_traverse (PyObject * op , visitproc visit , void * arg )
2784
2800
{
2801
+ ScannerObject * self = _ScannerObject_CAST (op );
2785
2802
Py_VISIT (Py_TYPE (self ));
2786
2803
Py_VISIT (self -> pattern );
2787
2804
return 0 ;
2788
2805
}
2789
2806
2790
2807
static int
2791
- scanner_clear (ScannerObject * self )
2808
+ scanner_clear (PyObject * op )
2792
2809
{
2810
+ ScannerObject * self = _ScannerObject_CAST (op );
2793
2811
Py_CLEAR (self -> pattern );
2794
2812
return 0 ;
2795
2813
}
2796
2814
2797
2815
static void
2798
- scanner_dealloc (ScannerObject * self )
2816
+ scanner_dealloc (PyObject * self )
2799
2817
{
2800
2818
PyTypeObject * tp = Py_TYPE (self );
2801
-
2802
2819
PyObject_GC_UnTrack (self );
2803
- state_fini (& self -> state );
2820
+ ScannerObject * scanner = _ScannerObject_CAST (self );
2821
+ state_fini (& scanner -> state );
2804
2822
(void )scanner_clear (self );
2805
2823
tp -> tp_free (self );
2806
2824
Py_DECREF (tp );
@@ -2957,8 +2975,9 @@ pattern_scanner(_sremodulestate *module_state,
2957
2975
/* template methods */
2958
2976
2959
2977
static int
2960
- template_traverse (TemplateObject * self , visitproc visit , void * arg )
2978
+ template_traverse (PyObject * op , visitproc visit , void * arg )
2961
2979
{
2980
+ TemplateObject * self = _TemplateObject_CAST (op );
2962
2981
Py_VISIT (Py_TYPE (self ));
2963
2982
Py_VISIT (self -> literal );
2964
2983
for (Py_ssize_t i = 0 , n = Py_SIZE (self ); i < n ; i ++ ) {
@@ -2968,8 +2987,9 @@ template_traverse(TemplateObject *self, visitproc visit, void *arg)
2968
2987
}
2969
2988
2970
2989
static int
2971
- template_clear (TemplateObject * self )
2990
+ template_clear (PyObject * op )
2972
2991
{
2992
+ TemplateObject * self = _TemplateObject_CAST (op );
2973
2993
Py_CLEAR (self -> literal );
2974
2994
for (Py_ssize_t i = 0 , n = Py_SIZE (self ); i < n ; i ++ ) {
2975
2995
Py_CLEAR (self -> items [i ].literal );
@@ -2978,10 +2998,9 @@ template_clear(TemplateObject *self)
2978
2998
}
2979
2999
2980
3000
static void
2981
- template_dealloc (TemplateObject * self )
3001
+ template_dealloc (PyObject * self )
2982
3002
{
2983
3003
PyTypeObject * tp = Py_TYPE (self );
2984
-
2985
3004
PyObject_GC_UnTrack (self );
2986
3005
(void )template_clear (self );
2987
3006
tp -> tp_free (self );
@@ -3056,8 +3075,10 @@ expand_template(TemplateObject *self, MatchObject *match)
3056
3075
3057
3076
3058
3077
static Py_hash_t
3059
- pattern_hash (PatternObject * self )
3078
+ pattern_hash (PyObject * op )
3060
3079
{
3080
+ PatternObject * self = _PatternObject_CAST (op );
3081
+
3061
3082
Py_hash_t hash , hash2 ;
3062
3083
3063
3084
hash = PyObject_Hash (self -> pattern );
@@ -3148,7 +3169,7 @@ static PyMethodDef pattern_methods[] = {
3148
3169
};
3149
3170
3150
3171
static PyGetSetDef pattern_getset [] = {
3151
- {"groupindex" , ( getter ) pattern_groupindex , ( setter ) NULL ,
3172
+ {"groupindex" , pattern_groupindex , NULL ,
3152
3173
"A dictionary mapping group names to group numbers." },
3153
3174
{NULL } /* Sentinel */
3154
3175
};
@@ -3166,9 +3187,9 @@ static PyMemberDef pattern_members[] = {
3166
3187
};
3167
3188
3168
3189
static PyType_Slot pattern_slots [] = {
3169
- {Py_tp_dealloc , ( destructor ) pattern_dealloc },
3170
- {Py_tp_repr , ( reprfunc ) pattern_repr },
3171
- {Py_tp_hash , ( hashfunc ) pattern_hash },
3190
+ {Py_tp_dealloc , pattern_dealloc },
3191
+ {Py_tp_repr , pattern_repr },
3192
+ {Py_tp_hash , pattern_hash },
3172
3193
{Py_tp_doc , (void * )pattern_doc },
3173
3194
{Py_tp_richcompare , pattern_richcompare },
3174
3195
{Py_tp_methods , pattern_methods },
@@ -3189,7 +3210,7 @@ static PyType_Spec pattern_spec = {
3189
3210
};
3190
3211
3191
3212
static PyMethodDef match_methods [] = {
3192
- {"group" , ( PyCFunction ) match_group , METH_VARARGS , match_group_doc },
3213
+ {"group" , match_group , METH_VARARGS , match_group_doc },
3193
3214
_SRE_SRE_MATCH_START_METHODDEF
3194
3215
_SRE_SRE_MATCH_END_METHODDEF
3195
3216
_SRE_SRE_MATCH_SPAN_METHODDEF
@@ -3204,11 +3225,11 @@ static PyMethodDef match_methods[] = {
3204
3225
};
3205
3226
3206
3227
static PyGetSetDef match_getset [] = {
3207
- {"lastindex" , ( getter ) match_lastindex_get , ( setter ) NULL ,
3228
+ {"lastindex" , match_lastindex_get , NULL ,
3208
3229
"The integer index of the last matched capturing group." },
3209
- {"lastgroup" , ( getter ) match_lastgroup_get , ( setter ) NULL ,
3230
+ {"lastgroup" , match_lastgroup_get , NULL ,
3210
3231
"The name of the last matched capturing group." },
3211
- {"regs" , ( getter ) match_regs_get , ( setter ) NULL },
3232
+ {"regs" , match_regs_get , NULL , NULL },
3212
3233
{NULL }
3213
3234
};
3214
3235
0 commit comments