@@ -110,6 +110,15 @@ def check_dont_replace(self, source):
110110 source = reformat (source )
111111 self .assertEqual (patch (source ), source )
112112
113+ def test_expr_regex (self ):
114+ # Test EXPR_REGEX
115+ self .check_replace ("a->b->ob_type" , "Py_TYPE(a->b)" )
116+ self .check_replace ("a.b->ob_type" , "Py_TYPE(a.b)" )
117+ self .check_replace ("array[2]->ob_type" , "Py_TYPE(array[2])" )
118+
119+ # Don't match function calls
120+ self .check_dont_replace ("func()->ob_type" )
121+
113122 def test_pythoncapi_compat (self ):
114123 # If pythoncapi_compat.h is included, avoid compatibility includes
115124 # and macros.
@@ -531,27 +540,33 @@ def test_py_is(self):
531540 """ )
532541
533542 self .check_replace ("""
534- void test_expr(struct MyStruct *obj)
543+ void test_expr(struct MyStruct *obj, PyObject **obj2 )
535544 {
536545 if (obj->attr1 == Py_None) {
537546 return 1;
538547 }
539548 if (obj->attr2.name == Py_None) {
540549 return 1;
541550 }
551+ if (*obj2 == Py_None) {
552+ return 1;
553+ }
542554 return 0;
543555 }
544556 """ , """
545557 #include "pythoncapi_compat.h"
546558
547- void test_expr(struct MyStruct *obj)
559+ void test_expr(struct MyStruct *obj, PyObject **obj2 )
548560 {
549561 if (Py_IsNone(obj->attr1)) {
550562 return 1;
551563 }
552564 if (Py_IsNone(obj->attr2.name)) {
553565 return 1;
554566 }
567+ if (Py_IsNone(*obj2)) {
568+ return 1;
569+ }
555570 return 0;
556571 }
557572 """ )
0 commit comments