summaryrefslogtreecommitdiffstats
path: root/Objects/codeobject.c
diff options
context:
space:
mode:
Diffstat (limited to 'Objects/codeobject.c')
-rw-r--r--Objects/codeobject.c51
1 files changed, 17 insertions, 34 deletions
diff --git a/Objects/codeobject.c b/Objects/codeobject.c
index 3824fc0..fc1db72 100644
--- a/Objects/codeobject.c
+++ b/Objects/codeobject.c
@@ -175,8 +175,7 @@ void
_Py_set_localsplus_info(int offset, PyObject *name, _PyLocals_Kind kind,
PyObject *names, PyObject *kinds)
{
- Py_INCREF(name);
- PyTuple_SET_ITEM(names, offset, name);
+ PyTuple_SET_ITEM(names, offset, Py_NewRef(name));
_PyLocals_SetKind(kinds, offset, kind);
}
@@ -235,8 +234,7 @@ get_localsplus_names(PyCodeObject *co, _PyLocals_Kind kind, int num)
}
assert(index < num);
PyObject *name = PyTuple_GET_ITEM(co->co_localsplusnames, offset);
- Py_INCREF(name);
- PyTuple_SET_ITEM(names, index, name);
+ PyTuple_SET_ITEM(names, index, Py_NewRef(name));
index += 1;
}
assert(index == num);
@@ -311,27 +309,19 @@ init_code(PyCodeObject *co, struct _PyCodeConstructor *con)
get_localsplus_counts(con->localsplusnames, con->localspluskinds,
&nlocals, &nplaincellvars, &ncellvars, &nfreevars);
- Py_INCREF(con->filename);
- co->co_filename = con->filename;
- Py_INCREF(con->name);
- co->co_name = con->name;
- Py_INCREF(con->qualname);
- co->co_qualname = con->qualname;
+ co->co_filename = Py_NewRef(con->filename);
+ co->co_name = Py_NewRef(con->name);
+ co->co_qualname = Py_NewRef(con->qualname);
co->co_flags = con->flags;
co->co_firstlineno = con->firstlineno;
- Py_INCREF(con->linetable);
- co->co_linetable = con->linetable;
+ co->co_linetable = Py_NewRef(con->linetable);
- Py_INCREF(con->consts);
- co->co_consts = con->consts;
- Py_INCREF(con->names);
- co->co_names = con->names;
+ co->co_consts = Py_NewRef(con->consts);
+ co->co_names = Py_NewRef(con->names);
- Py_INCREF(con->localsplusnames);
- co->co_localsplusnames = con->localsplusnames;
- Py_INCREF(con->localspluskinds);
- co->co_localspluskinds = con->localspluskinds;
+ co->co_localsplusnames = Py_NewRef(con->localsplusnames);
+ co->co_localspluskinds = Py_NewRef(con->localspluskinds);
co->co_argcount = con->argcount;
co->co_posonlyargcount = con->posonlyargcount;
@@ -339,8 +329,7 @@ init_code(PyCodeObject *co, struct _PyCodeConstructor *con)
co->co_stacksize = con->stacksize;
- Py_INCREF(con->exceptiontable);
- co->co_exceptiontable = con->exceptiontable;
+ co->co_exceptiontable = Py_NewRef(con->exceptiontable);
/* derived values */
co->co_nlocalsplus = nlocalsplus;
@@ -1144,8 +1133,7 @@ lineiter_next(lineiterator *li)
start = PyLong_FromLong(bounds->ar_start);
end = PyLong_FromLong(bounds->ar_end);
if (bounds->ar_line < 0) {
- Py_INCREF(Py_None);
- line = Py_None;
+ line = Py_NewRef(Py_None);
}
else {
line = PyLong_FromLong(bounds->ar_line);
@@ -1215,8 +1203,7 @@ new_linesiterator(PyCodeObject *code)
if (li == NULL) {
return NULL;
}
- Py_INCREF(code);
- li->li_code = code;
+ li->li_code = (PyCodeObject*)Py_NewRef(code);
_PyCode_InitAddressRange(code, &li->li_line);
return li;
}
@@ -1315,8 +1302,7 @@ code_positionsiterator(PyCodeObject* code, PyObject* Py_UNUSED(args))
if (pi == NULL) {
return NULL;
}
- Py_INCREF(code);
- pi->pi_code = code;
+ pi->pi_code = (PyCodeObject*)Py_NewRef(code);
_PyCode_InitAddressRange(code, &pi->pi_range);
pi->pi_offset = pi->pi_range.ar_end;
return (PyObject*)pi;
@@ -1777,8 +1763,7 @@ code_richcompare(PyObject *self, PyObject *other, int op)
res = Py_False;
done:
- Py_INCREF(res);
- return res;
+ return Py_NewRef(res);
}
static Py_hash_t
@@ -2030,8 +2015,7 @@ code__varname_from_oparg_impl(PyCodeObject *self, int oparg)
if (name == NULL) {
return NULL;
}
- Py_INCREF(name);
- return name;
+ return Py_NewRef(name);
}
/* XXX code objects need to participate in GC? */
@@ -2106,8 +2090,7 @@ _PyCode_ConstantKey(PyObject *op)
{
/* Objects of these types are always different from object of other
* type and from tuples. */
- Py_INCREF(op);
- key = op;
+ key = Py_NewRef(op);
}
else if (PyBool_Check(op) || PyBytes_CheckExact(op)) {
/* Make booleans different from integers 0 and 1.