@@ -998,17 +998,25 @@ def visitModule(self, mod):
998998 self .emit ("if (!init_types()) return NULL;" , 1 )
999999 self .emit ('m = PyState_FindModule(&_astmodule);' , 1 )
10001000 self .emit ("if (!m) return NULL;" , 1 )
1001+ self .emit ('if (PyModule_AddObject(m, "AST", astmodulestate_global->AST_type) < 0) {' , 1 )
1002+ self .emit ('goto error;' , 2 )
1003+ self .emit ('}' , 1 )
10011004 self .emit ('Py_INCREF(astmodulestate(m)->AST_type);' , 1 )
1002- self .emit ('if (PyModule_AddObject(m, "AST", astmodulestate_global->AST_type) < 0) return NULL;' , 1 )
1003- self .emit ('if (PyModule_AddIntMacro(m, PyCF_ALLOW_TOP_LEVEL_AWAIT) < 0)' , 1 )
1004- self .emit ("return NULL;" , 2 )
1005- self .emit ('if (PyModule_AddIntMacro(m, PyCF_ONLY_AST) < 0)' , 1 )
1006- self .emit ("return NULL;" , 2 )
1007- self .emit ('if (PyModule_AddIntMacro(m, PyCF_TYPE_COMMENTS) < 0)' , 1 )
1008- self .emit ("return NULL;" , 2 )
1005+ self .emit ('if (PyModule_AddIntMacro(m, PyCF_ALLOW_TOP_LEVEL_AWAIT) < 0) {' , 1 )
1006+ self .emit ("goto error;" , 2 )
1007+ self .emit ('}' , 1 )
1008+ self .emit ('if (PyModule_AddIntMacro(m, PyCF_ONLY_AST) < 0) {' , 1 )
1009+ self .emit ("goto error;" , 2 )
1010+ self .emit ('}' , 1 )
1011+ self .emit ('if (PyModule_AddIntMacro(m, PyCF_TYPE_COMMENTS) < 0) {' , 1 )
1012+ self .emit ("goto error;" , 2 )
1013+ self .emit ('}' , 1 )
10091014 for dfn in mod .dfns :
10101015 self .visit (dfn )
10111016 self .emit ("return m;" , 1 )
1017+ self .emit ("error:" , 0 )
1018+ self .emit ("Py_DECREF(m);" , 1 )
1019+ self .emit ("return NULL;" , 1 )
10121020 self .emit ("}" , 0 )
10131021
10141022 def visitProduct (self , prod , name ):
@@ -1024,7 +1032,9 @@ def visitConstructor(self, cons, name):
10241032
10251033 def addObj (self , name ):
10261034 self .emit ("if (PyModule_AddObject(m, \" %s\" , "
1027- "astmodulestate_global->%s_type) < 0) return NULL;" % (name , name ), 1 )
1035+ "astmodulestate_global->%s_type) < 0) {" % (name , name ), 1 )
1036+ self .emit ("goto error;" , 2 )
1037+ self .emit ('}' , 1 )
10281038 self .emit ("Py_INCREF(astmodulestate(m)->%s_type);" % name , 1 )
10291039
10301040
0 commit comments