diff options
author | Victor Stinner <vstinner@python.org> | 2022-11-15 09:29:56 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-15 09:29:56 (GMT) |
commit | f13f466474ed53529acd3f209070431fbae14323 (patch) | |
tree | 37b0aa7f90435ec2c910d5def19fc4311082894d /Parser/asdl_c.py | |
parent | ee821dcd3961efc47262322848267fe398faa4e4 (diff) | |
download | cpython-f13f466474ed53529acd3f209070431fbae14323.zip cpython-f13f466474ed53529acd3f209070431fbae14323.tar.gz cpython-f13f466474ed53529acd3f209070431fbae14323.tar.bz2 |
gh-99300: Use Py_NewRef() in Python/Python-ast.c (#99499)
Replace Py_INCREF() and Py_XINCREF() with Py_NewRef() and
Py_XNewRef() in Python/Python-ast.c.
Update Parser/asdl_c.py to regenerate code.
Diffstat (limited to 'Parser/asdl_c.py')
-rwxr-xr-x | Parser/asdl_c.py | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/Parser/asdl_c.py b/Parser/asdl_c.py index 8bdd253..3e30761 100755 --- a/Parser/asdl_c.py +++ b/Parser/asdl_c.py @@ -675,8 +675,7 @@ class Obj2ModVisitor(PickleVisitor): self.emit("if (%s == NULL) goto failed;" % field.name, depth+1) self.emit("for (i = 0; i < len; i++) {", depth+1) self.emit("%s val;" % ctype, depth+2) - self.emit("PyObject *tmp2 = PyList_GET_ITEM(tmp, i);", depth+2) - self.emit("Py_INCREF(tmp2);", depth+2) + self.emit("PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));", depth+2) with self.recursive_call(name, depth+2): self.emit("res = obj2ast_%s(state, tmp2, &val, arena);" % field.type, depth+2, reflow=False) @@ -1021,9 +1020,11 @@ static int obj2ast_object(struct ast_state *Py_UNUSED(state), PyObject* obj, PyO *out = NULL; return -1; } - Py_INCREF(obj); + *out = Py_NewRef(obj); + } + else { + *out = NULL; } - *out = obj; return 0; } |