Skip to content

Commit

Permalink
bpo-1635741: _ast uses PyModule_AddObjectRef() (pythonGH-23146)
Browse files Browse the repository at this point in the history
Replace PyModule_AddObject() with PyModule_AddObjectRef() in the _ast
module (Python-ast.c).
  • Loading branch information
vstinner authored and adorilson committed Mar 11, 2021
1 parent 6c41dfc commit d804003
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 220 deletions.
6 changes: 2 additions & 4 deletions Parser/asdl_c.py
Original file line number Diff line number Diff line change
Expand Up @@ -1115,10 +1115,9 @@ def visitModule(self, mod):
self.emit('if (state == NULL) {', 1)
self.emit('return -1;', 2)
self.emit('}', 1)
self.emit('if (PyModule_AddObject(m, "AST", state->AST_type) < 0) {', 1)
self.emit('if (PyModule_AddObjectRef(m, "AST", state->AST_type) < 0) {', 1)
self.emit('return -1;', 2)
self.emit('}', 1)
self.emit('Py_INCREF(state->AST_type);', 1)
self.emit('if (PyModule_AddIntMacro(m, PyCF_ALLOW_TOP_LEVEL_AWAIT) < 0) {', 1)
self.emit("return -1;", 2)
self.emit('}', 1)
Expand Down Expand Up @@ -1166,11 +1165,10 @@ def visitConstructor(self, cons, name):
self.addObj(cons.name)

def addObj(self, name):
self.emit("if (PyModule_AddObject(m, \"%s\", "
self.emit("if (PyModule_AddObjectRef(m, \"%s\", "
"state->%s_type) < 0) {" % (name, name), 1)
self.emit("return -1;", 2)
self.emit('}', 1)
self.emit("Py_INCREF(state->%s_type);" % name, 1)


class StaticVisitor(PickleVisitor):
Expand Down
Loading

0 comments on commit d804003

Please sign in to comment.