diff options
Diffstat (limited to 'Objects')
| -rw-r--r-- | Objects/dictobject.c | 9 | ||||
| -rw-r--r-- | Objects/funcobject.c | 10 | ||||
| -rw-r--r-- | Objects/genobject.c | 6 | ||||
| -rw-r--r-- | Objects/namespaceobject.c | 5 | ||||
| -rw-r--r-- | Objects/odictobject.c | 3 | ||||
| -rw-r--r-- | Objects/rangeobject.c | 4 | ||||
| -rw-r--r-- | Objects/typeobject.c | 12 | ||||
| -rw-r--r-- | Objects/unionobject.c | 3 |
8 files changed, 17 insertions, 35 deletions
diff --git a/Objects/dictobject.c b/Objects/dictobject.c index fc48720386..51903ab271 100644 --- a/Objects/dictobject.c +++ b/Objects/dictobject.c @@ -1883,13 +1883,11 @@ _PyDict_SetItem_KnownHash(PyObject *op, PyObject *key, PyObject *value, assert(hash != -1); mp = (PyDictObject *)op; - Py_INCREF(key); - Py_INCREF(value); if (mp->ma_keys == Py_EMPTY_KEYS) { - return insert_to_emptydict(mp, key, hash, value); + return insert_to_emptydict(mp, Py_NewRef(key), hash, Py_NewRef(value)); } /* insertdict() handles any resizing that might be necessary */ - return insertdict(mp, key, hash, value); + return insertdict(mp, Py_NewRef(key), hash, Py_NewRef(value)); } static void @@ -2197,9 +2195,8 @@ _PyDict_Pop_KnownHash(PyObject *dict, PyObject *key, Py_hash_t hash, PyObject *d return NULL; } assert(old_value != NULL); - Py_INCREF(old_value); uint64_t new_version = _PyDict_NotifyEvent(PyDict_EVENT_DELETED, mp, key, NULL); - delitem_common(mp, hash, ix, old_value, new_version); + delitem_common(mp, hash, ix, Py_NewRef(old_value), new_version); ASSERT_CONSISTENT(mp); return old_value; diff --git a/Objects/funcobject.c b/Objects/funcobject.c index 80117bfb20..d60e4eb848 100644 --- a/Objects/funcobject.c +++ b/Objects/funcobject.c @@ -47,9 +47,8 @@ PyFunction_NewWithQualName(PyObject *code, PyObject *globals, PyObject *qualname PyCodeObject *code_obj = (PyCodeObject *)Py_NewRef(code); - PyObject *name = code_obj->co_name; - assert(name != NULL); - Py_INCREF(name); + assert(code_obj->co_name != NULL); + PyObject *name = Py_NewRef(code_obj->co_name); if (!qualname) { qualname = code_obj->co_qualname; @@ -525,10 +524,7 @@ func_get_annotations(PyFunctionObject *op, void *Py_UNUSED(ignored)) return NULL; } PyObject *d = func_get_annotation_dict(op); - if (d) { - Py_INCREF(d); - } - return d; + return Py_XNewRef(d); } static int diff --git a/Objects/genobject.c b/Objects/genobject.c index 3e0e075097..6661e3fb94 100644 --- a/Objects/genobject.c +++ b/Objects/genobject.c @@ -341,8 +341,7 @@ _PyGen_yf(PyGenObject *gen) /* Not in a yield from */ return NULL; } - yf = _PyFrame_StackPeek(frame); - Py_INCREF(yf); + yf = Py_NewRef(_PyFrame_StackPeek(frame)); } return yf; @@ -494,8 +493,7 @@ throw_here: /* Normalize to raise <class>, <instance> */ Py_XDECREF(val); val = typ; - typ = PyExceptionInstance_Class(typ); - Py_INCREF(typ); + typ = Py_NewRef(PyExceptionInstance_Class(typ)); if (tb == NULL) /* Returns NULL if there's no traceback */ diff --git a/Objects/namespaceobject.c b/Objects/namespaceobject.c index 7875e7cafe..2cc4ddd3c9 100644 --- a/Objects/namespaceobject.c +++ b/Objects/namespaceobject.c @@ -85,9 +85,8 @@ namespace_repr(PyObject *ns) if (pairs == NULL) goto error; - d = ((_PyNamespaceObject *)ns)->ns_dict; - assert(d != NULL); - Py_INCREF(d); + assert(((_PyNamespaceObject *)ns)->ns_dict != NULL); + d = Py_NewRef(((_PyNamespaceObject *)ns)->ns_dict); keys = PyDict_Keys(d); if (keys == NULL) diff --git a/Objects/odictobject.c b/Objects/odictobject.c index 33af1d1d52..4976b70b5d 100644 --- a/Objects/odictobject.c +++ b/Objects/odictobject.c @@ -1114,8 +1114,7 @@ OrderedDict_popitem_impl(PyODictObject *self, int last) } node = last ? _odict_LAST(self) : _odict_FIRST(self); - key = _odictnode_KEY(node); - Py_INCREF(key); + key = Py_NewRef(_odictnode_KEY(node)); value = _odict_popkey_hash((PyObject *)self, key, NULL, _odictnode_HASH(node)); if (value == NULL) return NULL; diff --git a/Objects/rangeobject.c b/Objects/rangeobject.c index 8e3083e5b8..a889aa04db 100644 --- a/Objects/rangeobject.c +++ b/Objects/rangeobject.c @@ -936,10 +936,8 @@ longrangeiter_reduce(longrangeiterobject *r, PyObject *Py_UNUSED(ignored)) Py_DECREF(product); if (stop == NULL) return NULL; - Py_INCREF(r->start); - Py_INCREF(r->step); range = (PyObject*)make_range_object(&PyRange_Type, - r->start, stop, r->step); + Py_NewRef(r->start), stop, Py_NewRef(r->step)); if (range == NULL) { Py_DECREF(r->start); Py_DECREF(stop); diff --git a/Objects/typeobject.c b/Objects/typeobject.c index 675d6d874d..1e58d32f49 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -5437,8 +5437,7 @@ object_getstate_default(PyObject *obj, int required) for (i = 0; i < slotnames_size; i++) { PyObject *name, *value; - name = PyList_GET_ITEM(slotnames, i); - Py_INCREF(name); + name = Py_NewRef(PyList_GET_ITEM(slotnames, i)); if (_PyObject_LookupAttr(obj, name, &value) < 0) { Py_DECREF(name); goto error; @@ -5570,10 +5569,8 @@ _PyObject_GetNewArguments(PyObject *obj, PyObject **args, PyObject **kwargs) Py_DECREF(newargs); return -1; } - *args = PyTuple_GET_ITEM(newargs, 0); - Py_INCREF(*args); - *kwargs = PyTuple_GET_ITEM(newargs, 1); - Py_INCREF(*kwargs); + *args = Py_NewRef(PyTuple_GET_ITEM(newargs, 0)); + *kwargs = Py_NewRef(PyTuple_GET_ITEM(newargs, 1)); Py_DECREF(newargs); /* XXX We should perhaps allow None to be passed here. */ @@ -9601,8 +9598,7 @@ super_init_impl(PyObject *self, PyTypeObject *type, PyObject *obj) { return -1; Py_INCREF(obj); } - Py_INCREF(type); - Py_XSETREF(su->type, type); + Py_XSETREF(su->type, Py_NewRef(type)); Py_XSETREF(su->obj, obj); Py_XSETREF(su->obj_type, obj_type); return 0; diff --git a/Objects/unionobject.c b/Objects/unionobject.c index b2ac3509ce..f273f7d15e 100644 --- a/Objects/unionobject.c +++ b/Objects/unionobject.c @@ -295,8 +295,7 @@ union_getitem(PyObject *self, PyObject *item) res = make_union(newargs); } else { - res = PyTuple_GET_ITEM(newargs, 0); - Py_INCREF(res); + res = Py_NewRef(PyTuple_GET_ITEM(newargs, 0)); for (Py_ssize_t iarg = 1; iarg < nargs; iarg++) { PyObject *arg = PyTuple_GET_ITEM(newargs, iarg); Py_SETREF(res, PyNumber_Or(res, arg)); |
