Skip to content

Commit f13f466

Browse files
authored
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.
1 parent ee821dc commit f13f466

File tree

2 files changed

+78
-144
lines changed

2 files changed

+78
-144
lines changed

Parser/asdl_c.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -675,8 +675,7 @@ def visitField(self, field, name, sum=None, prod=None, depth=0):
675675
self.emit("if (%s == NULL) goto failed;" % field.name, depth+1)
676676
self.emit("for (i = 0; i < len; i++) {", depth+1)
677677
self.emit("%s val;" % ctype, depth+2)
678-
self.emit("PyObject *tmp2 = PyList_GET_ITEM(tmp, i);", depth+2)
679-
self.emit("Py_INCREF(tmp2);", depth+2)
678+
self.emit("PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));", depth+2)
680679
with self.recursive_call(name, depth+2):
681680
self.emit("res = obj2ast_%s(state, tmp2, &val, arena);" %
682681
field.type, depth+2, reflow=False)
@@ -1021,9 +1020,11 @@ def visitModule(self, mod):
10211020
*out = NULL;
10221021
return -1;
10231022
}
1024-
Py_INCREF(obj);
1023+
*out = Py_NewRef(obj);
1024+
}
1025+
else {
1026+
*out = NULL;
10251027
}
1026-
*out = obj;
10271028
return 0;
10281029
}
10291030

0 commit comments

Comments
 (0)