init_suboffsets(dest, src);
init_flags(mv);
- mv->mbuf = mbuf;
- Py_INCREF(mbuf);
+ mv->mbuf = (_PyManagedBufferObject*)Py_NewRef(mbuf);
mbuf->exports++;
return (PyObject *)mv;
dest = &mv->view;
init_shared_values(dest, src);
- mv->mbuf = mbuf;
- Py_INCREF(mbuf);
+ mv->mbuf = (_PyManagedBufferObject*)Py_NewRef(mbuf);
mbuf->exports++;
return (PyObject *)mv;
memory_enter(PyObject *self, PyObject *args)
{
CHECK_RELEASED(self);
- Py_INCREF(self);
- return self;
+ return Py_NewRef(self);
}
static PyObject *
}
- view->obj = (PyObject *)self;
- Py_INCREF(view->obj);
+ view->obj = Py_NewRef(self);
self->exports++;
return 0;
return NULL;
if (PyTuple_GET_SIZE(v) == 1) {
- PyObject *tmp = PyTuple_GET_ITEM(v, 0);
- Py_INCREF(tmp);
+ PyObject *res = Py_NewRef(PyTuple_GET_ITEM(v, 0));
Py_DECREF(v);
- return tmp;
+ return res;
}
return v;
return unpack_single(self, view->buf, fmt);
}
else if (key == Py_Ellipsis) {
- Py_INCREF(self);
- return (PyObject *)self;
+ return Py_NewRef(self);
}
else {
PyErr_SetString(PyExc_TypeError,
unpacker_free(unpack_v);
unpacker_free(unpack_w);
- Py_XINCREF(res);
- return res;
+ return Py_XNewRef(res);
}
/**************************************************************************/
if (view->obj == NULL) {
Py_RETURN_NONE;
}
- Py_INCREF(view->obj);
- return view->obj;
+ return Py_NewRef(view->obj);
}
static PyObject *
it->it_fmt = fmt;
it->it_length = memory_length(obj);
it->it_index = 0;
- Py_INCREF(seq);
- it->it_seq = obj;
+ it->it_seq = (PyMemoryViewObject*)Py_NewRef(obj);
_PyObject_GC_TRACK(it);
return (PyObject *)it;
}
if (om == NULL) {
return NULL;
}
- Py_INCREF(cls);
- om->mm_class = cls;
+ om->mm_class = (PyTypeObject*)Py_NewRef(cls);
op = (PyCFunctionObject *)om;
} else {
if (cls) {
op->m_weakreflist = NULL;
op->m_ml = ml;
- Py_XINCREF(self);
- op->m_self = self;
- Py_XINCREF(module);
- op->m_module = module;
+ op->m_self = Py_XNewRef(self);
+ op->m_module = Py_XNewRef(module);
op->vectorcall = vectorcall;
_PyObject_GC_TRACK(op);
return (PyObject *)op;
self = PyCFunction_GET_SELF(m);
if (self == NULL)
self = Py_None;
- Py_INCREF(self);
- return self;
+ return Py_NewRef(self);
}
static PyGetSetDef meth_getsets [] = {
res = eq ? Py_True : Py_False;
else
res = eq ? Py_False : Py_True;
- Py_INCREF(res);
- return res;
+ return Py_NewRef(res);
}
static Py_hash_t
if (PyDict_SetItem(md_dict, &_Py_ID(__spec__), Py_None) != 0)
return -1;
if (PyUnicode_CheckExact(name)) {
- Py_INCREF(name);
- Py_XSETREF(mod->md_name, name);
+ Py_XSETREF(mod->md_name, Py_NewRef(name));
}
return 0;
}
return NULL;
}
- Py_INCREF(name);
- return name;
+ return Py_NewRef(name);
}
const char *
}
return NULL;
}
- Py_INCREF(fileobj);
- return fileobj;
+ return Py_NewRef(fileobj);
}
const char *
if (PyUnicode_READY(v) < 0)
return NULL;
#endif
- Py_INCREF(v);
- return v;
+ return Py_NewRef(v);
}
if (Py_TYPE(v)->tp_str == NULL)
return PyObject_Repr(v);
return PyBytes_FromString("<NULL>");
if (PyBytes_CheckExact(v)) {
- Py_INCREF(v);
- return v;
+ return Py_NewRef(v);
}
func = _PyObject_LookupSpecial(v, &_Py_ID(__bytes__));
Py_TYPE(w)->tp_name);
return NULL;
}
- Py_INCREF(res);
- return res;
+ return Py_NewRef(res);
}
/* Perform a rich comparison with object result. This wraps do_richcompare()
PyObject *
PyObject_SelfIter(PyObject *obj)
{
- Py_INCREF(obj);
- return obj;
+ return Py_NewRef(obj);
}
/* Helper used when the __next__ method is removed from a type:
"not a '%.200s'", Py_TYPE(value)->tp_name);
return -1;
}
- Py_INCREF(value);
- Py_XSETREF(*dictptr, value);
+ Py_XSETREF(*dictptr, Py_NewRef(value));
return 0;
}
if (mutablemapping_update_arg(self, other) < 0) {
return NULL;
}
- Py_INCREF(self);
- return self;
+ return Py_NewRef(self);
}
/* tp_as_number */
return NULL;
assert(_odict_find_node(self, key) == NULL);
if (PyODict_SetItem((PyObject *)self, key, default_value) >= 0) {
- result = default_value;
- Py_INCREF(result);
+ result = Py_NewRef(default_value);
}
}
else {
result = PyObject_GetItem((PyObject *)self, key);
}
else if (PyObject_SetItem((PyObject *)self, key, default_value) >= 0) {
- result = default_value;
- Py_INCREF(result);
+ result = Py_NewRef(default_value);
}
}
else if (value == NULL && !PyErr_Occurred()) {
/* Apply the fallback value, if necessary. */
if (failobj) {
- value = failobj;
- Py_INCREF(failobj);
+ value = Py_NewRef(failobj);
}
else {
PyErr_SetObject(PyExc_KeyError, key);
return NULL;
res = (eq == (op == Py_EQ)) ? Py_True : Py_False;
- Py_INCREF(res);
- return res;
+ return Py_NewRef(res);
} else {
Py_RETURN_NOTIMPLEMENTED;
}
di->di_current = NULL;
}
else {
- di->di_current = _odictnode_KEY(node);
- Py_INCREF(di->di_current);
+ di->di_current = Py_NewRef(_odictnode_KEY(node));
}
return key;
di->kind = kind;
node = reversed ? _odict_LAST(od) : _odict_FIRST(od);
- di->di_current = node ? _odictnode_KEY(node) : NULL;
- Py_XINCREF(di->di_current);
+ di->di_current = node ? Py_NewRef(_odictnode_KEY(node)) : NULL;
di->di_size = PyODict_SIZE(od);
di->di_state = od->od_state;
- di->di_odict = od;
- Py_INCREF(od);
+ di->di_odict = (PyODictObject*)Py_NewRef(od);
_PyObject_GC_TRACK(di);
return (PyObject *)di;
key = other_entry->key;
if (key != NULL) {
assert(so_entry->key == NULL);
- Py_INCREF(key);
- so_entry->key = key;
+ so_entry->key = Py_NewRef(key);
so_entry->hash = other_entry->hash;
}
}
for (i = other->mask + 1; i > 0 ; i--, other_entry++) {
key = other_entry->key;
if (key != NULL && key != dummy) {
- Py_INCREF(key);
- set_insert_clean(newtable, newmask, key, other_entry->hash);
+ set_insert_clean(newtable, newmask, Py_NewRef(key),
+ other_entry->hash);
}
}
return 0;
goto fail;
si->len--;
key = entry[i].key;
- Py_INCREF(key);
- return key;
+ return Py_NewRef(key);
fail:
si->si_set = NULL;
setiterobject *si = PyObject_GC_New(setiterobject, &PySetIter_Type);
if (si == NULL)
return NULL;
- Py_INCREF(so);
- si->si_set = so;
+ si->si_set = (PySetObject*)Py_NewRef(so);
si->si_used = so->used;
si->si_pos = 0;
si->len = so->used;
if (iterable != NULL && PyFrozenSet_CheckExact(iterable)) {
/* frozenset(f) is idempotent */
- Py_INCREF(iterable);
- return iterable;
+ return Py_NewRef(iterable);
}
return make_new_set(type, iterable);
}
frozenset_copy(PySetObject *so, PyObject *Py_UNUSED(ignored))
{
if (PyFrozenSet_CheckExact(so)) {
- Py_INCREF(so);
- return (PyObject *)so;
+ return Py_NewRef(so);
}
return set_copy(so, NULL);
}
if (set_update_internal(so, other))
return NULL;
- Py_INCREF(so);
- return (PyObject *)so;
+ return Py_NewRef(so);
}
static PyObject *
set_intersection_multi(PySetObject *so, PyObject *args)
{
Py_ssize_t i;
- PyObject *result = (PyObject *)so;
if (PyTuple_GET_SIZE(args) == 0)
return set_copy(so, NULL);
- Py_INCREF(so);
+ PyObject *result = Py_NewRef(so);
for (i=0 ; i<PyTuple_GET_SIZE(args) ; i++) {
PyObject *other = PyTuple_GET_ITEM(args, i);
PyObject *newresult = set_intersection((PySetObject *)result, other);
if (result == NULL)
return NULL;
Py_DECREF(result);
- Py_INCREF(so);
- return (PyObject *)so;
+ return Py_NewRef(so);
}
static PyObject *
PyErr_SetString(PyExc_TypeError, "EllipsisType takes no arguments");
return NULL;
}
- Py_INCREF(Py_Ellipsis);
- return Py_Ellipsis;
+ return Py_NewRef(Py_Ellipsis);
}
static PyObject *
if (stop == NULL) {
stop = Py_None;
}
- Py_INCREF(start);
- Py_INCREF(stop);
- return (PyObject *) _PyBuildSlice_Consume2(start, stop, step);
+ return (PyObject *)_PyBuildSlice_Consume2(Py_NewRef(start),
+ Py_NewRef(stop), step);
}
PyObject *
/* Convert step to an integer; raise for zero step. */
if (self->step == Py_None) {
- step = _PyLong_GetOne();
- Py_INCREF(step);
+ step = Py_NewRef(_PyLong_GetOne());
step_is_negative = 0;
}
else {
goto error;
}
else {
- lower = _PyLong_GetZero();
- Py_INCREF(lower);
- upper = length;
- Py_INCREF(upper);
+ lower = Py_NewRef(_PyLong_GetZero());
+ upper = Py_NewRef(length);
}
/* Compute start. */
if (self->start == Py_None) {
- start = step_is_negative ? upper : lower;
- Py_INCREF(start);
+ start = Py_NewRef(step_is_negative ? upper : lower);
}
else {
start = evaluate_slice_index(self->start);
/* Compute stop. */
if (self->stop == Py_None) {
- stop = step_is_negative ? lower : upper;
- Py_INCREF(stop);
+ stop = Py_NewRef(step_is_negative ? lower : upper);
}
else {
stop = evaluate_slice_index(self->stop);
res = Py_False;
break;
}
- Py_INCREF(res);
- return res;
+ return Py_NewRef(res);
}
item = PySequence_Fast_GET_ITEM(seq, i);
if (PyBytes_CheckExact(item)) {
/* Fast path. */
- Py_INCREF(item);
- buffers[i].obj = item;
+ buffers[i].obj = Py_NewRef(item);
buffers[i].buf = PyBytes_AS_STRING(item);
buffers[i].len = PyBytes_GET_SIZE(item);
}
{
#if !STRINGLIB_MUTABLE
if (STRINGLIB_CHECK_EXACT(self)) {
- Py_INCREF(self);
- return self;
+ return Py_NewRef(self);
}
#endif
return STRINGLIB_NEW(STRINGLIB_STR(self), STRINGLIB_LEN(self));
otherwise create a one length string with the conversion
character */
if (conversion == '\0') {
- conversion_str = Py_None;
- Py_INCREF(conversion_str);
+ conversion_str = Py_NewRef(Py_None);
}
else
conversion_str = PyUnicode_FromKindAndData(PyUnicode_4BYTE_KIND,
return NULL;
/* take ownership, give the object to the iterator */
- Py_INCREF(self);
- it->str = self;
+ it->str = Py_NewRef(self);
/* initialize the contained MarkupIterator */
MarkupIterator_init(&it->it_markup, (PyObject*)self, 0, PyUnicode_GET_LENGTH(self));
/* take ownership, give the object to the iterator. this is
just to keep the field_name alive */
- Py_INCREF(self);
- it->str = self;
+ it->str = Py_NewRef(self);
/* Pass in auto_number = NULL. We'll return an empty string for
first_obj in that case. */
}
for (i = 0; i < len; ++i) {
PyObject *v = PySequence_Fast_GET_ITEM(arg, i);
- Py_INCREF(v);
- res->ob_item[i] = v;
+ res->ob_item[i] = Py_NewRef(v);
}
Py_DECREF(arg);
for (; i < max_len; ++i) {
ob = Py_None;
}
}
- Py_INCREF(ob);
- res->ob_item[i] = ob;
+ res->ob_item[i] = Py_NewRef(ob);
}
_PyObject_GC_TRACK(res);
}
for (; pos < size1; pos++) {
PyObject *a = items1[pos];
- Py_INCREF(a);
- PyTuple_SET_ITEM(tuple, pos, a);
+ PyTuple_SET_ITEM(tuple, pos, Py_NewRef(a));
}
}
- Py_INCREF(arg);
- PyTuple_SET_ITEM(tuple, pos, arg);
+ PyTuple_SET_ITEM(tuple, pos, Py_NewRef(arg));
pos++;
}
if (PyErr_Occurred()) {
return NULL;
}
- Py_INCREF(self);
- return self;
+ return Py_NewRef(self);
}
PyObject *new_union = make_union(tuple);
return NULL;
}
}
- Py_INCREF(alias->parameters);
- return alias->parameters;
+ return Py_NewRef(alias->parameters);
}
static PyGetSetDef union_properties[] = {
return NULL;
}
- Py_INCREF(args);
result->parameters = NULL;
- result->args = args;
+ result->args = Py_NewRef(args);
_PyObject_GC_TRACK(result);
return (PyObject*)result;
}
if (callback == NULL && type == &_PyWeakref_RefType) {
if (ref != NULL) {
/* We can re-use an existing reference. */
- Py_INCREF(ref);
- return (PyObject *)ref;
+ return Py_NewRef(ref);
}
}
/* We have to create a new reference. */
to avoid violating the invariants of the list
of weakrefs for ob. */
Py_DECREF(result);
- Py_INCREF(ref);
- result = ref;
+ result = (PyWeakReference*)Py_NewRef(ref);
}
}
else {
to avoid violating the invariants of the list
of weakrefs for ob. */
Py_DECREF(result);
- result = proxy;
- Py_INCREF(result);
+ result = (PyWeakReference*)Py_NewRef(proxy);
goto skip_insert;
}
prev = ref;
PyWeakReference *next = current->wr_next;
if (Py_REFCNT((PyObject *)current) > 0) {
- Py_INCREF(current);
- PyTuple_SET_ITEM(tuple, i * 2, (PyObject *) current);
+ PyTuple_SET_ITEM(tuple, i * 2, Py_NewRef(current));
PyTuple_SET_ITEM(tuple, i * 2 + 1, current->wr_callback);
}
else {