Skip to content

Commit

Permalink
pythongh-99300: Use Py_NewRef() in Python/Python-ast.c (python#99499)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
vstinner committed Nov 15, 2022
1 parent ee821dc commit f13f466
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 144 deletions.
9 changes: 5 additions & 4 deletions Parser/asdl_c.py
Original file line number Diff line number Diff line change
Expand Up @@ -675,8 +675,7 @@ def visitField(self, field, name, sum=None, prod=None, depth=0):
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)
Expand Down Expand Up @@ -1021,9 +1020,11 @@ def visitModule(self, mod):
*out = NULL;
return -1;
}
Py_INCREF(obj);
*out = Py_NewRef(obj);
}
else {
*out = NULL;
}
*out = obj;
return 0;
}
Expand Down
Loading

0 comments on commit f13f466

Please sign in to comment.