mirror of
https://github.com/python/cpython.git
synced 2025-10-09 16:34:44 +00:00
gh-99300: Use Py_NewRef() in Objects/ directory (#99335)
Replace Py_INCREF() and Py_XINCREF() with Py_NewRef() and Py_XNewRef() in C files of the Objects/ directory.
This commit is contained in:
parent
2f4af2d99c
commit
584e55bd34
8 changed files with 120 additions and 244 deletions
|
@ -194,8 +194,7 @@ gen_send_ex2(PyGenObject *gen, PyObject *arg, PyObject **presult,
|
|||
else if (arg && !exc) {
|
||||
/* `gen` is an exhausted generator:
|
||||
only return value if called from send(). */
|
||||
*presult = Py_None;
|
||||
Py_INCREF(*presult);
|
||||
*presult = Py_NewRef(Py_None);
|
||||
return PYGEN_RETURN;
|
||||
}
|
||||
return PYGEN_ERROR;
|
||||
|
@ -204,8 +203,7 @@ gen_send_ex2(PyGenObject *gen, PyObject *arg, PyObject **presult,
|
|||
assert(gen->gi_frame_state < FRAME_EXECUTING);
|
||||
/* Push arg onto the frame's value stack */
|
||||
result = arg ? arg : Py_None;
|
||||
Py_INCREF(result);
|
||||
_PyFrame_StackPush(frame, result);
|
||||
_PyFrame_StackPush(frame, Py_NewRef(result));
|
||||
|
||||
_PyErr_StackItem *prev_exc_info = tstate->exc_info;
|
||||
gen->gi_exc_state.previous_item = prev_exc_info;
|
||||
|
@ -625,8 +623,7 @@ _PyGen_FetchStopIterationValue(PyObject **pvalue)
|
|||
if (ev) {
|
||||
/* exception will usually be normalised already */
|
||||
if (PyObject_TypeCheck(ev, (PyTypeObject *) et)) {
|
||||
value = ((PyStopIterationObject *)ev)->value;
|
||||
Py_INCREF(value);
|
||||
value = Py_NewRef(((PyStopIterationObject *)ev)->value);
|
||||
Py_DECREF(ev);
|
||||
} else if (et == PyExc_StopIteration && !PyTuple_Check(ev)) {
|
||||
/* Avoid normalisation and take ev as value.
|
||||
|
@ -645,8 +642,7 @@ _PyGen_FetchStopIterationValue(PyObject **pvalue)
|
|||
PyErr_Restore(et, ev, tb);
|
||||
return -1;
|
||||
}
|
||||
value = ((PyStopIterationObject *)ev)->value;
|
||||
Py_INCREF(value);
|
||||
value = Py_NewRef(((PyStopIterationObject *)ev)->value);
|
||||
Py_DECREF(ev);
|
||||
}
|
||||
}
|
||||
|
@ -656,8 +652,7 @@ _PyGen_FetchStopIterationValue(PyObject **pvalue)
|
|||
return -1;
|
||||
}
|
||||
if (value == NULL) {
|
||||
value = Py_None;
|
||||
Py_INCREF(value);
|
||||
value = Py_NewRef(Py_None);
|
||||
}
|
||||
*pvalue = value;
|
||||
return 0;
|
||||
|
@ -673,8 +668,7 @@ gen_repr(PyGenObject *gen)
|
|||
static PyObject *
|
||||
gen_get_name(PyGenObject *op, void *Py_UNUSED(ignored))
|
||||
{
|
||||
Py_INCREF(op->gi_name);
|
||||
return op->gi_name;
|
||||
return Py_NewRef(op->gi_name);
|
||||
}
|
||||
|
||||
static int
|
||||
|
@ -687,16 +681,14 @@ gen_set_name(PyGenObject *op, PyObject *value, void *Py_UNUSED(ignored))
|
|||
"__name__ must be set to a string object");
|
||||
return -1;
|
||||
}
|
||||
Py_INCREF(value);
|
||||
Py_XSETREF(op->gi_name, value);
|
||||
Py_XSETREF(op->gi_name, Py_NewRef(value));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
gen_get_qualname(PyGenObject *op, void *Py_UNUSED(ignored))
|
||||
{
|
||||
Py_INCREF(op->gi_qualname);
|
||||
return op->gi_qualname;
|
||||
return Py_NewRef(op->gi_qualname);
|
||||
}
|
||||
|
||||
static int
|
||||
|
@ -709,8 +701,7 @@ gen_set_qualname(PyGenObject *op, PyObject *value, void *Py_UNUSED(ignored))
|
|||
"__qualname__ must be set to a string object");
|
||||
return -1;
|
||||
}
|
||||
Py_INCREF(value);
|
||||
Py_XSETREF(op->gi_qualname, value);
|
||||
Py_XSETREF(op->gi_qualname, Py_NewRef(value));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -868,8 +859,7 @@ make_gen(PyTypeObject *type, PyFunctionObject *func)
|
|||
return NULL;
|
||||
}
|
||||
gen->gi_frame_state = FRAME_CLEARED;
|
||||
gen->gi_code = (PyCodeObject *)func->func_code;
|
||||
Py_INCREF(gen->gi_code);
|
||||
gen->gi_code = (PyCodeObject *)Py_NewRef(func->func_code);
|
||||
gen->gi_weakreflist = NULL;
|
||||
gen->gi_exc_state.exc_value = NULL;
|
||||
gen->gi_exc_state.previous_item = NULL;
|
||||
|
@ -955,15 +945,13 @@ gen_new_with_qualname(PyTypeObject *type, PyFrameObject *f,
|
|||
gen->gi_exc_state.exc_value = NULL;
|
||||
gen->gi_exc_state.previous_item = NULL;
|
||||
if (name != NULL)
|
||||
gen->gi_name = name;
|
||||
gen->gi_name = Py_NewRef(name);
|
||||
else
|
||||
gen->gi_name = gen->gi_code->co_name;
|
||||
Py_INCREF(gen->gi_name);
|
||||
gen->gi_name = Py_NewRef(gen->gi_code->co_name);
|
||||
if (qualname != NULL)
|
||||
gen->gi_qualname = qualname;
|
||||
gen->gi_qualname = Py_NewRef(qualname);
|
||||
else
|
||||
gen->gi_qualname = gen->gi_code->co_qualname;
|
||||
Py_INCREF(gen->gi_qualname);
|
||||
gen->gi_qualname = Py_NewRef(gen->gi_code->co_qualname);
|
||||
_PyObject_GC_TRACK(gen);
|
||||
return (PyObject *)gen;
|
||||
}
|
||||
|
@ -1015,8 +1003,7 @@ _PyCoro_GetAwaitableIter(PyObject *o)
|
|||
|
||||
if (PyCoro_CheckExact(o) || gen_is_coroutine(o)) {
|
||||
/* 'o' is a coroutine. */
|
||||
Py_INCREF(o);
|
||||
return o;
|
||||
return Py_NewRef(o);
|
||||
}
|
||||
|
||||
ot = Py_TYPE(o);
|
||||
|
@ -1063,8 +1050,7 @@ coro_await(PyCoroObject *coro)
|
|||
if (cw == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
Py_INCREF(coro);
|
||||
cw->cw_coroutine = coro;
|
||||
cw->cw_coroutine = (PyCoroObject*)Py_NewRef(coro);
|
||||
_PyObject_GC_TRACK(cw);
|
||||
return (PyObject *)cw;
|
||||
}
|
||||
|
@ -1434,8 +1420,7 @@ async_gen_init_hooks(PyAsyncGenObject *o)
|
|||
|
||||
finalizer = tstate->async_gen_finalizer;
|
||||
if (finalizer) {
|
||||
Py_INCREF(finalizer);
|
||||
o->ag_origin_or_finalizer = finalizer;
|
||||
o->ag_origin_or_finalizer = Py_NewRef(finalizer);
|
||||
}
|
||||
|
||||
firstiter = tstate->async_gen_firstiter;
|
||||
|
@ -1897,11 +1882,9 @@ async_gen_asend_new(PyAsyncGenObject *gen, PyObject *sendval)
|
|||
}
|
||||
}
|
||||
|
||||
Py_INCREF(gen);
|
||||
o->ags_gen = gen;
|
||||
o->ags_gen = (PyAsyncGenObject*)Py_NewRef(gen);
|
||||
|
||||
Py_XINCREF(sendval);
|
||||
o->ags_sendval = sendval;
|
||||
o->ags_sendval = Py_XNewRef(sendval);
|
||||
|
||||
o->ags_state = AWAITABLE_STATE_INIT;
|
||||
|
||||
|
@ -2017,8 +2000,7 @@ _PyAsyncGenValueWrapperNew(PyObject *val)
|
|||
return NULL;
|
||||
}
|
||||
}
|
||||
o->agw_val = val;
|
||||
Py_INCREF(val);
|
||||
o->agw_val = Py_NewRef(val);
|
||||
_PyObject_GC_TRACK((PyObject*)o);
|
||||
return (PyObject*)o;
|
||||
}
|
||||
|
@ -2301,11 +2283,9 @@ async_gen_athrow_new(PyAsyncGenObject *gen, PyObject *args)
|
|||
if (o == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
o->agt_gen = gen;
|
||||
o->agt_args = args;
|
||||
o->agt_gen = (PyAsyncGenObject*)Py_NewRef(gen);
|
||||
o->agt_args = Py_XNewRef(args);
|
||||
o->agt_state = AWAITABLE_STATE_INIT;
|
||||
Py_INCREF(gen);
|
||||
Py_XINCREF(args);
|
||||
_PyObject_GC_TRACK((PyObject*)o);
|
||||
return (PyObject*)o;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue