mirror of https://github.com/python/cpython
gh-99300: Use Py_NewRef() in Objects/ directory (#99354)
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
1960eb005e
commit
3a1dde8f29
|
@ -682,8 +682,7 @@ mbuf_add_view(_PyManagedBufferObject *mbuf, const Py_buffer *src)
|
||||||
init_suboffsets(dest, src);
|
init_suboffsets(dest, src);
|
||||||
init_flags(mv);
|
init_flags(mv);
|
||||||
|
|
||||||
mv->mbuf = mbuf;
|
mv->mbuf = (_PyManagedBufferObject*)Py_NewRef(mbuf);
|
||||||
Py_INCREF(mbuf);
|
|
||||||
mbuf->exports++;
|
mbuf->exports++;
|
||||||
|
|
||||||
return (PyObject *)mv;
|
return (PyObject *)mv;
|
||||||
|
@ -713,8 +712,7 @@ mbuf_add_incomplete_view(_PyManagedBufferObject *mbuf, const Py_buffer *src,
|
||||||
dest = &mv->view;
|
dest = &mv->view;
|
||||||
init_shared_values(dest, src);
|
init_shared_values(dest, src);
|
||||||
|
|
||||||
mv->mbuf = mbuf;
|
mv->mbuf = (_PyManagedBufferObject*)Py_NewRef(mbuf);
|
||||||
Py_INCREF(mbuf);
|
|
||||||
mbuf->exports++;
|
mbuf->exports++;
|
||||||
|
|
||||||
return (PyObject *)mv;
|
return (PyObject *)mv;
|
||||||
|
@ -1102,8 +1100,7 @@ static PyObject *
|
||||||
memory_enter(PyObject *self, PyObject *args)
|
memory_enter(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
CHECK_RELEASED(self);
|
CHECK_RELEASED(self);
|
||||||
Py_INCREF(self);
|
return Py_NewRef(self);
|
||||||
return self;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
@ -1515,8 +1512,7 @@ memory_getbuf(PyMemoryViewObject *self, Py_buffer *view, int flags)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
view->obj = (PyObject *)self;
|
view->obj = Py_NewRef(self);
|
||||||
Py_INCREF(view->obj);
|
|
||||||
self->exports++;
|
self->exports++;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -2047,10 +2043,9 @@ struct_unpack_single(const char *ptr, struct unpacker *x)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (PyTuple_GET_SIZE(v) == 1) {
|
if (PyTuple_GET_SIZE(v) == 1) {
|
||||||
PyObject *tmp = PyTuple_GET_ITEM(v, 0);
|
PyObject *res = Py_NewRef(PyTuple_GET_ITEM(v, 0));
|
||||||
Py_INCREF(tmp);
|
|
||||||
Py_DECREF(v);
|
Py_DECREF(v);
|
||||||
return tmp;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
return v;
|
return v;
|
||||||
|
@ -2496,8 +2491,7 @@ memory_subscript(PyMemoryViewObject *self, PyObject *key)
|
||||||
return unpack_single(self, view->buf, fmt);
|
return unpack_single(self, view->buf, fmt);
|
||||||
}
|
}
|
||||||
else if (key == Py_Ellipsis) {
|
else if (key == Py_Ellipsis) {
|
||||||
Py_INCREF(self);
|
return Py_NewRef(self);
|
||||||
return (PyObject *)self;
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
PyErr_SetString(PyExc_TypeError,
|
PyErr_SetString(PyExc_TypeError,
|
||||||
|
@ -2957,8 +2951,7 @@ result:
|
||||||
unpacker_free(unpack_v);
|
unpacker_free(unpack_v);
|
||||||
unpacker_free(unpack_w);
|
unpacker_free(unpack_w);
|
||||||
|
|
||||||
Py_XINCREF(res);
|
return Py_XNewRef(res);
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
@ -3052,8 +3045,7 @@ memory_obj_get(PyMemoryViewObject *self, void *Py_UNUSED(ignored))
|
||||||
if (view->obj == NULL) {
|
if (view->obj == NULL) {
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
}
|
}
|
||||||
Py_INCREF(view->obj);
|
return Py_NewRef(view->obj);
|
||||||
return view->obj;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
@ -3281,8 +3273,7 @@ memory_iter(PyObject *seq)
|
||||||
it->it_fmt = fmt;
|
it->it_fmt = fmt;
|
||||||
it->it_length = memory_length(obj);
|
it->it_length = memory_length(obj);
|
||||||
it->it_index = 0;
|
it->it_index = 0;
|
||||||
Py_INCREF(seq);
|
it->it_seq = (PyMemoryViewObject*)Py_NewRef(obj);
|
||||||
it->it_seq = obj;
|
|
||||||
_PyObject_GC_TRACK(it);
|
_PyObject_GC_TRACK(it);
|
||||||
return (PyObject *)it;
|
return (PyObject *)it;
|
||||||
}
|
}
|
||||||
|
|
|
@ -88,8 +88,7 @@ PyCMethod_New(PyMethodDef *ml, PyObject *self, PyObject *module, PyTypeObject *c
|
||||||
if (om == NULL) {
|
if (om == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
Py_INCREF(cls);
|
om->mm_class = (PyTypeObject*)Py_NewRef(cls);
|
||||||
om->mm_class = cls;
|
|
||||||
op = (PyCFunctionObject *)om;
|
op = (PyCFunctionObject *)om;
|
||||||
} else {
|
} else {
|
||||||
if (cls) {
|
if (cls) {
|
||||||
|
@ -106,10 +105,8 @@ PyCMethod_New(PyMethodDef *ml, PyObject *self, PyObject *module, PyTypeObject *c
|
||||||
|
|
||||||
op->m_weakreflist = NULL;
|
op->m_weakreflist = NULL;
|
||||||
op->m_ml = ml;
|
op->m_ml = ml;
|
||||||
Py_XINCREF(self);
|
op->m_self = Py_XNewRef(self);
|
||||||
op->m_self = self;
|
op->m_module = Py_XNewRef(module);
|
||||||
Py_XINCREF(module);
|
|
||||||
op->m_module = module;
|
|
||||||
op->vectorcall = vectorcall;
|
op->vectorcall = vectorcall;
|
||||||
_PyObject_GC_TRACK(op);
|
_PyObject_GC_TRACK(op);
|
||||||
return (PyObject *)op;
|
return (PyObject *)op;
|
||||||
|
@ -260,8 +257,7 @@ meth_get__self__(PyCFunctionObject *m, void *closure)
|
||||||
self = PyCFunction_GET_SELF(m);
|
self = PyCFunction_GET_SELF(m);
|
||||||
if (self == NULL)
|
if (self == NULL)
|
||||||
self = Py_None;
|
self = Py_None;
|
||||||
Py_INCREF(self);
|
return Py_NewRef(self);
|
||||||
return self;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyGetSetDef meth_getsets [] = {
|
static PyGetSetDef meth_getsets [] = {
|
||||||
|
@ -314,8 +310,7 @@ meth_richcompare(PyObject *self, PyObject *other, int op)
|
||||||
res = eq ? Py_True : Py_False;
|
res = eq ? Py_True : Py_False;
|
||||||
else
|
else
|
||||||
res = eq ? Py_False : Py_True;
|
res = eq ? Py_False : Py_True;
|
||||||
Py_INCREF(res);
|
return Py_NewRef(res);
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static Py_hash_t
|
static Py_hash_t
|
||||||
|
|
|
@ -70,8 +70,7 @@ module_init_dict(PyModuleObject *mod, PyObject *md_dict,
|
||||||
if (PyDict_SetItem(md_dict, &_Py_ID(__spec__), Py_None) != 0)
|
if (PyDict_SetItem(md_dict, &_Py_ID(__spec__), Py_None) != 0)
|
||||||
return -1;
|
return -1;
|
||||||
if (PyUnicode_CheckExact(name)) {
|
if (PyUnicode_CheckExact(name)) {
|
||||||
Py_INCREF(name);
|
Py_XSETREF(mod->md_name, Py_NewRef(name));
|
||||||
Py_XSETREF(mod->md_name, name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -506,8 +505,7 @@ PyModule_GetNameObject(PyObject *m)
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
Py_INCREF(name);
|
return Py_NewRef(name);
|
||||||
return name;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
|
@ -541,8 +539,7 @@ PyModule_GetFilenameObject(PyObject *m)
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
Py_INCREF(fileobj);
|
return Py_NewRef(fileobj);
|
||||||
return fileobj;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
|
|
|
@ -455,8 +455,7 @@ PyObject_Str(PyObject *v)
|
||||||
if (PyUnicode_READY(v) < 0)
|
if (PyUnicode_READY(v) < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
#endif
|
#endif
|
||||||
Py_INCREF(v);
|
return Py_NewRef(v);
|
||||||
return v;
|
|
||||||
}
|
}
|
||||||
if (Py_TYPE(v)->tp_str == NULL)
|
if (Py_TYPE(v)->tp_str == NULL)
|
||||||
return PyObject_Repr(v);
|
return PyObject_Repr(v);
|
||||||
|
@ -532,8 +531,7 @@ PyObject_Bytes(PyObject *v)
|
||||||
return PyBytes_FromString("<NULL>");
|
return PyBytes_FromString("<NULL>");
|
||||||
|
|
||||||
if (PyBytes_CheckExact(v)) {
|
if (PyBytes_CheckExact(v)) {
|
||||||
Py_INCREF(v);
|
return Py_NewRef(v);
|
||||||
return v;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func = _PyObject_LookupSpecial(v, &_Py_ID(__bytes__));
|
func = _PyObject_LookupSpecial(v, &_Py_ID(__bytes__));
|
||||||
|
@ -689,8 +687,7 @@ do_richcompare(PyThreadState *tstate, PyObject *v, PyObject *w, int op)
|
||||||
Py_TYPE(w)->tp_name);
|
Py_TYPE(w)->tp_name);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
Py_INCREF(res);
|
return Py_NewRef(res);
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Perform a rich comparison with object result. This wraps do_richcompare()
|
/* Perform a rich comparison with object result. This wraps do_richcompare()
|
||||||
|
@ -1096,8 +1093,7 @@ _PyObject_GetDictPtr(PyObject *obj)
|
||||||
PyObject *
|
PyObject *
|
||||||
PyObject_SelfIter(PyObject *obj)
|
PyObject_SelfIter(PyObject *obj)
|
||||||
{
|
{
|
||||||
Py_INCREF(obj);
|
return Py_NewRef(obj);
|
||||||
return obj;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Helper used when the __next__ method is removed from a type:
|
/* Helper used when the __next__ method is removed from a type:
|
||||||
|
@ -1481,8 +1477,7 @@ PyObject_GenericSetDict(PyObject *obj, PyObject *value, void *context)
|
||||||
"not a '%.200s'", Py_TYPE(value)->tp_name);
|
"not a '%.200s'", Py_TYPE(value)->tp_name);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
Py_INCREF(value);
|
Py_XSETREF(*dictptr, Py_NewRef(value));
|
||||||
Py_XSETREF(*dictptr, value);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -889,8 +889,7 @@ odict_inplace_or(PyObject *self, PyObject *other)
|
||||||
if (mutablemapping_update_arg(self, other) < 0) {
|
if (mutablemapping_update_arg(self, other) < 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
Py_INCREF(self);
|
return Py_NewRef(self);
|
||||||
return self;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* tp_as_number */
|
/* tp_as_number */
|
||||||
|
@ -1007,8 +1006,7 @@ OrderedDict_setdefault_impl(PyODictObject *self, PyObject *key,
|
||||||
return NULL;
|
return NULL;
|
||||||
assert(_odict_find_node(self, key) == NULL);
|
assert(_odict_find_node(self, key) == NULL);
|
||||||
if (PyODict_SetItem((PyObject *)self, key, default_value) >= 0) {
|
if (PyODict_SetItem((PyObject *)self, key, default_value) >= 0) {
|
||||||
result = default_value;
|
result = Py_NewRef(default_value);
|
||||||
Py_INCREF(result);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -1024,8 +1022,7 @@ OrderedDict_setdefault_impl(PyODictObject *self, PyObject *key,
|
||||||
result = PyObject_GetItem((PyObject *)self, key);
|
result = PyObject_GetItem((PyObject *)self, key);
|
||||||
}
|
}
|
||||||
else if (PyObject_SetItem((PyObject *)self, key, default_value) >= 0) {
|
else if (PyObject_SetItem((PyObject *)self, key, default_value) >= 0) {
|
||||||
result = default_value;
|
result = Py_NewRef(default_value);
|
||||||
Py_INCREF(result);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1055,8 +1052,7 @@ _odict_popkey_hash(PyObject *od, PyObject *key, PyObject *failobj,
|
||||||
else if (value == NULL && !PyErr_Occurred()) {
|
else if (value == NULL && !PyErr_Occurred()) {
|
||||||
/* Apply the fallback value, if necessary. */
|
/* Apply the fallback value, if necessary. */
|
||||||
if (failobj) {
|
if (failobj) {
|
||||||
value = failobj;
|
value = Py_NewRef(failobj);
|
||||||
Py_INCREF(failobj);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
PyErr_SetObject(PyExc_KeyError, key);
|
PyErr_SetObject(PyExc_KeyError, key);
|
||||||
|
@ -1497,8 +1493,7 @@ odict_richcompare(PyObject *v, PyObject *w, int op)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
res = (eq == (op == Py_EQ)) ? Py_True : Py_False;
|
res = (eq == (op == Py_EQ)) ? Py_True : Py_False;
|
||||||
Py_INCREF(res);
|
return Py_NewRef(res);
|
||||||
return res;
|
|
||||||
} else {
|
} else {
|
||||||
Py_RETURN_NOTIMPLEMENTED;
|
Py_RETURN_NOTIMPLEMENTED;
|
||||||
}
|
}
|
||||||
|
@ -1714,8 +1709,7 @@ odictiter_nextkey(odictiterobject *di)
|
||||||
di->di_current = NULL;
|
di->di_current = NULL;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
di->di_current = _odictnode_KEY(node);
|
di->di_current = Py_NewRef(_odictnode_KEY(node));
|
||||||
Py_INCREF(di->di_current);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return key;
|
return key;
|
||||||
|
@ -1872,12 +1866,10 @@ odictiter_new(PyODictObject *od, int kind)
|
||||||
|
|
||||||
di->kind = kind;
|
di->kind = kind;
|
||||||
node = reversed ? _odict_LAST(od) : _odict_FIRST(od);
|
node = reversed ? _odict_LAST(od) : _odict_FIRST(od);
|
||||||
di->di_current = node ? _odictnode_KEY(node) : NULL;
|
di->di_current = node ? Py_NewRef(_odictnode_KEY(node)) : NULL;
|
||||||
Py_XINCREF(di->di_current);
|
|
||||||
di->di_size = PyODict_SIZE(od);
|
di->di_size = PyODict_SIZE(od);
|
||||||
di->di_state = od->od_state;
|
di->di_state = od->od_state;
|
||||||
di->di_odict = od;
|
di->di_odict = (PyODictObject*)Py_NewRef(od);
|
||||||
Py_INCREF(od);
|
|
||||||
|
|
||||||
_PyObject_GC_TRACK(di);
|
_PyObject_GC_TRACK(di);
|
||||||
return (PyObject *)di;
|
return (PyObject *)di;
|
||||||
|
|
|
@ -588,8 +588,7 @@ set_merge(PySetObject *so, PyObject *otherset)
|
||||||
key = other_entry->key;
|
key = other_entry->key;
|
||||||
if (key != NULL) {
|
if (key != NULL) {
|
||||||
assert(so_entry->key == NULL);
|
assert(so_entry->key == NULL);
|
||||||
Py_INCREF(key);
|
so_entry->key = Py_NewRef(key);
|
||||||
so_entry->key = key;
|
|
||||||
so_entry->hash = other_entry->hash;
|
so_entry->hash = other_entry->hash;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -607,8 +606,8 @@ set_merge(PySetObject *so, PyObject *otherset)
|
||||||
for (i = other->mask + 1; i > 0 ; i--, other_entry++) {
|
for (i = other->mask + 1; i > 0 ; i--, other_entry++) {
|
||||||
key = other_entry->key;
|
key = other_entry->key;
|
||||||
if (key != NULL && key != dummy) {
|
if (key != NULL && key != dummy) {
|
||||||
Py_INCREF(key);
|
set_insert_clean(newtable, newmask, Py_NewRef(key),
|
||||||
set_insert_clean(newtable, newmask, key, other_entry->hash);
|
other_entry->hash);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -820,8 +819,7 @@ static PyObject *setiter_iternext(setiterobject *si)
|
||||||
goto fail;
|
goto fail;
|
||||||
si->len--;
|
si->len--;
|
||||||
key = entry[i].key;
|
key = entry[i].key;
|
||||||
Py_INCREF(key);
|
return Py_NewRef(key);
|
||||||
return key;
|
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
si->si_set = NULL;
|
si->si_set = NULL;
|
||||||
|
@ -868,8 +866,7 @@ set_iter(PySetObject *so)
|
||||||
setiterobject *si = PyObject_GC_New(setiterobject, &PySetIter_Type);
|
setiterobject *si = PyObject_GC_New(setiterobject, &PySetIter_Type);
|
||||||
if (si == NULL)
|
if (si == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
Py_INCREF(so);
|
si->si_set = (PySetObject*)Py_NewRef(so);
|
||||||
si->si_set = so;
|
|
||||||
si->si_used = so->used;
|
si->si_used = so->used;
|
||||||
si->si_pos = 0;
|
si->si_pos = 0;
|
||||||
si->len = so->used;
|
si->len = so->used;
|
||||||
|
@ -997,8 +994,7 @@ make_new_frozenset(PyTypeObject *type, PyObject *iterable)
|
||||||
|
|
||||||
if (iterable != NULL && PyFrozenSet_CheckExact(iterable)) {
|
if (iterable != NULL && PyFrozenSet_CheckExact(iterable)) {
|
||||||
/* frozenset(f) is idempotent */
|
/* frozenset(f) is idempotent */
|
||||||
Py_INCREF(iterable);
|
return Py_NewRef(iterable);
|
||||||
return iterable;
|
|
||||||
}
|
}
|
||||||
return make_new_set(type, iterable);
|
return make_new_set(type, iterable);
|
||||||
}
|
}
|
||||||
|
@ -1100,8 +1096,7 @@ static PyObject *
|
||||||
frozenset_copy(PySetObject *so, PyObject *Py_UNUSED(ignored))
|
frozenset_copy(PySetObject *so, PyObject *Py_UNUSED(ignored))
|
||||||
{
|
{
|
||||||
if (PyFrozenSet_CheckExact(so)) {
|
if (PyFrozenSet_CheckExact(so)) {
|
||||||
Py_INCREF(so);
|
return Py_NewRef(so);
|
||||||
return (PyObject *)so;
|
|
||||||
}
|
}
|
||||||
return set_copy(so, NULL);
|
return set_copy(so, NULL);
|
||||||
}
|
}
|
||||||
|
@ -1173,8 +1168,7 @@ set_ior(PySetObject *so, PyObject *other)
|
||||||
|
|
||||||
if (set_update_internal(so, other))
|
if (set_update_internal(so, other))
|
||||||
return NULL;
|
return NULL;
|
||||||
Py_INCREF(so);
|
return Py_NewRef(so);
|
||||||
return (PyObject *)so;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
@ -1264,12 +1258,11 @@ static PyObject *
|
||||||
set_intersection_multi(PySetObject *so, PyObject *args)
|
set_intersection_multi(PySetObject *so, PyObject *args)
|
||||||
{
|
{
|
||||||
Py_ssize_t i;
|
Py_ssize_t i;
|
||||||
PyObject *result = (PyObject *)so;
|
|
||||||
|
|
||||||
if (PyTuple_GET_SIZE(args) == 0)
|
if (PyTuple_GET_SIZE(args) == 0)
|
||||||
return set_copy(so, NULL);
|
return set_copy(so, NULL);
|
||||||
|
|
||||||
Py_INCREF(so);
|
PyObject *result = Py_NewRef(so);
|
||||||
for (i=0 ; i<PyTuple_GET_SIZE(args) ; i++) {
|
for (i=0 ; i<PyTuple_GET_SIZE(args) ; i++) {
|
||||||
PyObject *other = PyTuple_GET_ITEM(args, i);
|
PyObject *other = PyTuple_GET_ITEM(args, i);
|
||||||
PyObject *newresult = set_intersection((PySetObject *)result, other);
|
PyObject *newresult = set_intersection((PySetObject *)result, other);
|
||||||
|
@ -1336,8 +1329,7 @@ set_iand(PySetObject *so, PyObject *other)
|
||||||
if (result == NULL)
|
if (result == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
Py_DECREF(result);
|
Py_DECREF(result);
|
||||||
Py_INCREF(so);
|
return Py_NewRef(so);
|
||||||
return (PyObject *)so;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
|
|
@ -26,8 +26,7 @@ ellipsis_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
|
||||||
PyErr_SetString(PyExc_TypeError, "EllipsisType takes no arguments");
|
PyErr_SetString(PyExc_TypeError, "EllipsisType takes no arguments");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
Py_INCREF(Py_Ellipsis);
|
return Py_NewRef(Py_Ellipsis);
|
||||||
return Py_Ellipsis;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
@ -153,9 +152,8 @@ PySlice_New(PyObject *start, PyObject *stop, PyObject *step)
|
||||||
if (stop == NULL) {
|
if (stop == NULL) {
|
||||||
stop = Py_None;
|
stop = Py_None;
|
||||||
}
|
}
|
||||||
Py_INCREF(start);
|
return (PyObject *)_PyBuildSlice_Consume2(Py_NewRef(start),
|
||||||
Py_INCREF(stop);
|
Py_NewRef(stop), step);
|
||||||
return (PyObject *) _PyBuildSlice_Consume2(start, stop, step);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PyObject *
|
PyObject *
|
||||||
|
@ -406,8 +404,7 @@ _PySlice_GetLongIndices(PySliceObject *self, PyObject *length,
|
||||||
|
|
||||||
/* Convert step to an integer; raise for zero step. */
|
/* Convert step to an integer; raise for zero step. */
|
||||||
if (self->step == Py_None) {
|
if (self->step == Py_None) {
|
||||||
step = _PyLong_GetOne();
|
step = Py_NewRef(_PyLong_GetOne());
|
||||||
Py_INCREF(step);
|
|
||||||
step_is_negative = 0;
|
step_is_negative = 0;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -435,16 +432,13 @@ _PySlice_GetLongIndices(PySliceObject *self, PyObject *length,
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
lower = _PyLong_GetZero();
|
lower = Py_NewRef(_PyLong_GetZero());
|
||||||
Py_INCREF(lower);
|
upper = Py_NewRef(length);
|
||||||
upper = length;
|
|
||||||
Py_INCREF(upper);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Compute start. */
|
/* Compute start. */
|
||||||
if (self->start == Py_None) {
|
if (self->start == Py_None) {
|
||||||
start = step_is_negative ? upper : lower;
|
start = Py_NewRef(step_is_negative ? upper : lower);
|
||||||
Py_INCREF(start);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
start = evaluate_slice_index(self->start);
|
start = evaluate_slice_index(self->start);
|
||||||
|
@ -482,8 +476,7 @@ _PySlice_GetLongIndices(PySliceObject *self, PyObject *length,
|
||||||
|
|
||||||
/* Compute stop. */
|
/* Compute stop. */
|
||||||
if (self->stop == Py_None) {
|
if (self->stop == Py_None) {
|
||||||
stop = step_is_negative ? lower : upper;
|
stop = Py_NewRef(step_is_negative ? lower : upper);
|
||||||
Py_INCREF(stop);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
stop = evaluate_slice_index(self->stop);
|
stop = evaluate_slice_index(self->stop);
|
||||||
|
@ -609,8 +602,7 @@ slice_richcompare(PyObject *v, PyObject *w, int op)
|
||||||
res = Py_False;
|
res = Py_False;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Py_INCREF(res);
|
return Py_NewRef(res);
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -63,8 +63,7 @@ STRINGLIB(bytes_join)(PyObject *sep, PyObject *iterable)
|
||||||
item = PySequence_Fast_GET_ITEM(seq, i);
|
item = PySequence_Fast_GET_ITEM(seq, i);
|
||||||
if (PyBytes_CheckExact(item)) {
|
if (PyBytes_CheckExact(item)) {
|
||||||
/* Fast path. */
|
/* Fast path. */
|
||||||
Py_INCREF(item);
|
buffers[i].obj = Py_NewRef(item);
|
||||||
buffers[i].obj = item;
|
|
||||||
buffers[i].buf = PyBytes_AS_STRING(item);
|
buffers[i].buf = PyBytes_AS_STRING(item);
|
||||||
buffers[i].len = PyBytes_GET_SIZE(item);
|
buffers[i].len = PyBytes_GET_SIZE(item);
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,8 +17,7 @@ return_self(PyObject *self)
|
||||||
{
|
{
|
||||||
#if !STRINGLIB_MUTABLE
|
#if !STRINGLIB_MUTABLE
|
||||||
if (STRINGLIB_CHECK_EXACT(self)) {
|
if (STRINGLIB_CHECK_EXACT(self)) {
|
||||||
Py_INCREF(self);
|
return Py_NewRef(self);
|
||||||
return self;
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return STRINGLIB_NEW(STRINGLIB_STR(self), STRINGLIB_LEN(self));
|
return STRINGLIB_NEW(STRINGLIB_STR(self), STRINGLIB_LEN(self));
|
||||||
|
|
|
@ -1042,8 +1042,7 @@ formatteriter_next(formatteriterobject *it)
|
||||||
otherwise create a one length string with the conversion
|
otherwise create a one length string with the conversion
|
||||||
character */
|
character */
|
||||||
if (conversion == '\0') {
|
if (conversion == '\0') {
|
||||||
conversion_str = Py_None;
|
conversion_str = Py_NewRef(Py_None);
|
||||||
Py_INCREF(conversion_str);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
conversion_str = PyUnicode_FromKindAndData(PyUnicode_4BYTE_KIND,
|
conversion_str = PyUnicode_FromKindAndData(PyUnicode_4BYTE_KIND,
|
||||||
|
@ -1121,8 +1120,7 @@ formatter_parser(PyObject *ignored, PyObject *self)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
/* take ownership, give the object to the iterator */
|
/* take ownership, give the object to the iterator */
|
||||||
Py_INCREF(self);
|
it->str = Py_NewRef(self);
|
||||||
it->str = self;
|
|
||||||
|
|
||||||
/* initialize the contained MarkupIterator */
|
/* initialize the contained MarkupIterator */
|
||||||
MarkupIterator_init(&it->it_markup, (PyObject*)self, 0, PyUnicode_GET_LENGTH(self));
|
MarkupIterator_init(&it->it_markup, (PyObject*)self, 0, PyUnicode_GET_LENGTH(self));
|
||||||
|
@ -1265,8 +1263,7 @@ formatter_field_name_split(PyObject *ignored, PyObject *self)
|
||||||
|
|
||||||
/* take ownership, give the object to the iterator. this is
|
/* take ownership, give the object to the iterator. this is
|
||||||
just to keep the field_name alive */
|
just to keep the field_name alive */
|
||||||
Py_INCREF(self);
|
it->str = Py_NewRef(self);
|
||||||
it->str = self;
|
|
||||||
|
|
||||||
/* Pass in auto_number = NULL. We'll return an empty string for
|
/* Pass in auto_number = NULL. We'll return an empty string for
|
||||||
first_obj in that case. */
|
first_obj in that case. */
|
||||||
|
|
|
@ -200,8 +200,7 @@ structseq_new_impl(PyTypeObject *type, PyObject *arg, PyObject *dict)
|
||||||
}
|
}
|
||||||
for (i = 0; i < len; ++i) {
|
for (i = 0; i < len; ++i) {
|
||||||
PyObject *v = PySequence_Fast_GET_ITEM(arg, i);
|
PyObject *v = PySequence_Fast_GET_ITEM(arg, i);
|
||||||
Py_INCREF(v);
|
res->ob_item[i] = Py_NewRef(v);
|
||||||
res->ob_item[i] = v;
|
|
||||||
}
|
}
|
||||||
Py_DECREF(arg);
|
Py_DECREF(arg);
|
||||||
for (; i < max_len; ++i) {
|
for (; i < max_len; ++i) {
|
||||||
|
@ -219,8 +218,7 @@ structseq_new_impl(PyTypeObject *type, PyObject *arg, PyObject *dict)
|
||||||
ob = Py_None;
|
ob = Py_None;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Py_INCREF(ob);
|
res->ob_item[i] = Py_NewRef(ob);
|
||||||
res->ob_item[i] = ob;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_PyObject_GC_TRACK(res);
|
_PyObject_GC_TRACK(res);
|
||||||
|
|
|
@ -114,12 +114,10 @@ merge(PyObject **items1, Py_ssize_t size1,
|
||||||
}
|
}
|
||||||
for (; pos < size1; pos++) {
|
for (; pos < size1; pos++) {
|
||||||
PyObject *a = items1[pos];
|
PyObject *a = items1[pos];
|
||||||
Py_INCREF(a);
|
PyTuple_SET_ITEM(tuple, pos, Py_NewRef(a));
|
||||||
PyTuple_SET_ITEM(tuple, pos, a);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Py_INCREF(arg);
|
PyTuple_SET_ITEM(tuple, pos, Py_NewRef(arg));
|
||||||
PyTuple_SET_ITEM(tuple, pos, arg);
|
|
||||||
pos++;
|
pos++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -170,8 +168,7 @@ _Py_union_type_or(PyObject* self, PyObject* other)
|
||||||
if (PyErr_Occurred()) {
|
if (PyErr_Occurred()) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
Py_INCREF(self);
|
return Py_NewRef(self);
|
||||||
return self;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PyObject *new_union = make_union(tuple);
|
PyObject *new_union = make_union(tuple);
|
||||||
|
@ -326,8 +323,7 @@ union_parameters(PyObject *self, void *Py_UNUSED(unused))
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Py_INCREF(alias->parameters);
|
return Py_NewRef(alias->parameters);
|
||||||
return alias->parameters;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyGetSetDef union_properties[] = {
|
static PyGetSetDef union_properties[] = {
|
||||||
|
@ -400,9 +396,8 @@ make_union(PyObject *args)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
Py_INCREF(args);
|
|
||||||
result->parameters = NULL;
|
result->parameters = NULL;
|
||||||
result->args = args;
|
result->args = Py_NewRef(args);
|
||||||
_PyObject_GC_TRACK(result);
|
_PyObject_GC_TRACK(result);
|
||||||
return (PyObject*)result;
|
return (PyObject*)result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -311,8 +311,7 @@ weakref___new__(PyTypeObject *type, PyObject *args, PyObject *kwargs)
|
||||||
if (callback == NULL && type == &_PyWeakref_RefType) {
|
if (callback == NULL && type == &_PyWeakref_RefType) {
|
||||||
if (ref != NULL) {
|
if (ref != NULL) {
|
||||||
/* We can re-use an existing reference. */
|
/* We can re-use an existing reference. */
|
||||||
Py_INCREF(ref);
|
return Py_NewRef(ref);
|
||||||
return (PyObject *)ref;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* We have to create a new reference. */
|
/* We have to create a new reference. */
|
||||||
|
@ -826,8 +825,7 @@ PyWeakref_NewRef(PyObject *ob, PyObject *callback)
|
||||||
to avoid violating the invariants of the list
|
to avoid violating the invariants of the list
|
||||||
of weakrefs for ob. */
|
of weakrefs for ob. */
|
||||||
Py_DECREF(result);
|
Py_DECREF(result);
|
||||||
Py_INCREF(ref);
|
result = (PyWeakReference*)Py_NewRef(ref);
|
||||||
result = ref;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -891,8 +889,7 @@ PyWeakref_NewProxy(PyObject *ob, PyObject *callback)
|
||||||
to avoid violating the invariants of the list
|
to avoid violating the invariants of the list
|
||||||
of weakrefs for ob. */
|
of weakrefs for ob. */
|
||||||
Py_DECREF(result);
|
Py_DECREF(result);
|
||||||
result = proxy;
|
result = (PyWeakReference*)Py_NewRef(proxy);
|
||||||
Py_INCREF(result);
|
|
||||||
goto skip_insert;
|
goto skip_insert;
|
||||||
}
|
}
|
||||||
prev = ref;
|
prev = ref;
|
||||||
|
@ -993,8 +990,7 @@ PyObject_ClearWeakRefs(PyObject *object)
|
||||||
PyWeakReference *next = current->wr_next;
|
PyWeakReference *next = current->wr_next;
|
||||||
|
|
||||||
if (Py_REFCNT((PyObject *)current) > 0) {
|
if (Py_REFCNT((PyObject *)current) > 0) {
|
||||||
Py_INCREF(current);
|
PyTuple_SET_ITEM(tuple, i * 2, Py_NewRef(current));
|
||||||
PyTuple_SET_ITEM(tuple, i * 2, (PyObject *) current);
|
|
||||||
PyTuple_SET_ITEM(tuple, i * 2 + 1, current->wr_callback);
|
PyTuple_SET_ITEM(tuple, i * 2 + 1, current->wr_callback);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
Loading…
Reference in New Issue