bpo-1635741: _ast uses PyModule_AddObjectRef() (GH-23146)

Replace PyModule_AddObject() with PyModule_AddObjectRef() in the _ast
module (Python-ast.c).
This commit is contained in:
Victor Stinner 2020-11-04 16:37:07 +01:00 committed by GitHub
parent 988f1ec8d2
commit 18ce7f1d0a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 209 additions and 312 deletions

View file

@ -1115,10 +1115,9 @@ class ASTModuleVisitor(PickleVisitor):
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)
@ -1166,11 +1165,10 @@ PyInit__ast(void)
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):