@@ -998,17 +998,25 @@ def visitModule(self, mod):
998
998
self .emit ("if (!init_types()) return NULL;" , 1 )
999
999
self .emit ('m = PyState_FindModule(&_astmodule);' , 1 )
1000
1000
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 )
1001
1004
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 )
1009
1014
for dfn in mod .dfns :
1010
1015
self .visit (dfn )
1011
1016
self .emit ("return m;" , 1 )
1017
+ self .emit ("error:" , 0 )
1018
+ self .emit ("Py_DECREF(m);" , 1 )
1019
+ self .emit ("return NULL;" , 1 )
1012
1020
self .emit ("}" , 0 )
1013
1021
1014
1022
def visitProduct (self , prod , name ):
@@ -1024,7 +1032,9 @@ def visitConstructor(self, cons, name):
1024
1032
1025
1033
def addObj (self , name ):
1026
1034
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 )
1028
1038
self .emit ("Py_INCREF(astmodulestate(m)->%s_type);" % name , 1 )
1029
1039
1030
1040
0 commit comments