summaryrefslogtreecommitdiffstats
path: root/Parser
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2022-11-10 10:23:36 (GMT)
committerGitHub <noreply@github.com>2022-11-10 10:23:36 (GMT)
commit231d83b72435d61e929d6d62f2be7305e7b5b62b (patch)
tree17768fa10f1ade6bae9022d26e1470fd0b931366 /Parser
parentd8f239d86eb70c31aa4c4ac46a1d0a27bdb14b20 (diff)
downloadcpython-231d83b72435d61e929d6d62f2be7305e7b5b62b.zip
cpython-231d83b72435d61e929d6d62f2be7305e7b5b62b.tar.gz
cpython-231d83b72435d61e929d6d62f2be7305e7b5b62b.tar.bz2
gh-99300: Use Py_NewRef() in Python/ directory (#99317)
Replace Py_INCREF() and Py_XINCREF() with Py_NewRef() and Py_XNewRef() in C files of the Python/ directory. Update Parser/asdl_c.py to regenerate Python/Python-ast.c.
Diffstat (limited to 'Parser')
-rwxr-xr-xParser/asdl_c.py15
1 files changed, 7 insertions, 8 deletions
diff --git a/Parser/asdl_c.py b/Parser/asdl_c.py
index 6bd2e66..972d896 100755
--- a/Parser/asdl_c.py
+++ b/Parser/asdl_c.py
@@ -995,10 +995,11 @@ static PyObject* ast2obj_list(struct ast_state *state, asdl_seq *seq, PyObject*
static PyObject* ast2obj_object(struct ast_state *Py_UNUSED(state), void *o)
{
- if (!o)
- o = Py_None;
- Py_INCREF((PyObject*)o);
- return (PyObject*)o;
+ PyObject *op = (PyObject*)o;
+ if (!op) {
+ op = Py_None;
+ }
+ return Py_NewRef(op);
}
#define ast2obj_constant ast2obj_object
#define ast2obj_identifier ast2obj_object
@@ -1032,8 +1033,7 @@ static int obj2ast_constant(struct ast_state *Py_UNUSED(state), PyObject* obj, P
*out = NULL;
return -1;
}
- Py_INCREF(obj);
- *out = obj;
+ *out = Py_NewRef(obj);
return 0;
}
@@ -1301,8 +1301,7 @@ class ObjVisitor(PickleVisitor):
self.emit("switch(o) {", 1)
for t in sum.types:
self.emit("case %s:" % t.name, 2)
- self.emit("Py_INCREF(state->%s_singleton);" % t.name, 3)
- self.emit("return state->%s_singleton;" % t.name, 3)
+ self.emit("return Py_NewRef(state->%s_singleton);" % t.name, 3)
self.emit("}", 1)
self.emit("Py_UNREACHABLE();", 1);
self.emit("}", 0)