}
int result = PyObject_IsSubclass(subclass, self);
if (result > 0) {
- Py_INCREF(subclass);
- return subclass; /* Already a subclass. */
+ return Py_NewRef(subclass); /* Already a subclass. */
}
if (result < 0) {
return NULL;
set_collection_flag_recursive((PyTypeObject *)subclass, collection_flag);
}
}
- Py_INCREF(subclass);
- return subclass;
+ return Py_NewRef(subclass);
}
goto end;
}
if (incache > 0) {
- result = Py_True;
- Py_INCREF(result);
+ result = Py_NewRef(Py_True);
goto end;
}
subtype = (PyObject *)Py_TYPE(instance);
goto end;
}
if (incache > 0) {
- result = Py_False;
- Py_INCREF(result);
+ result = Py_NewRef(Py_False);
goto end;
}
}
end:
Py_DECREF(impl);
Py_XDECREF(subclasses);
- Py_XINCREF(result);
- return result;
+ return Py_XNewRef(result);
}
Py_ssize_t i = 0;
while (_PySet_NextEntry(impl->_abc_registry, &pos, &key, &hash)) {
- Py_INCREF(key);
- copy[i++] = key;
+ copy[i++] = Py_NewRef(key);
}
assert(i == registry_size);
static PyObject *
deque_append(dequeobject *deque, PyObject *item)
{
- Py_INCREF(item);
- if (deque_append_internal(deque, item, deque->maxlen) < 0)
+ if (deque_append_internal(deque, Py_NewRef(item), deque->maxlen) < 0)
return NULL;
Py_RETURN_NONE;
}
static PyObject *
deque_appendleft(dequeobject *deque, PyObject *item)
{
- Py_INCREF(item);
- if (deque_appendleft_internal(deque, item, deque->maxlen) < 0)
+ if (deque_appendleft_internal(deque, Py_NewRef(item), deque->maxlen) < 0)
return NULL;
Py_RETURN_NONE;
}
size = Py_SIZE(deque);
if (size == 0 || n == 1) {
- Py_INCREF(deque);
- return (PyObject *)deque;
+ return Py_NewRef(deque);
}
if (n <= 0) {
deque_clear(deque);
- Py_INCREF(deque);
- return (PyObject *)deque;
+ return Py_NewRef(deque);
}
if (size == 1) {
i += m;
while (m--) {
deque->rightindex++;
- Py_INCREF(item);
- deque->rightblock->data[deque->rightindex] = item;
+ deque->rightblock->data[deque->rightindex] = Py_NewRef(item);
}
}
Py_SET_SIZE(deque, Py_SIZE(deque) + i);
- Py_INCREF(deque);
- return (PyObject *)deque;
+ return Py_NewRef(deque);
}
if ((size_t)size > PY_SSIZE_T_MAX / (size_t)n) {
while (--n >= 0) {
CHECK_NOT_END(b);
- item = b->data[index];
- Py_INCREF(item);
+ item = Py_NewRef(b->data[index]);
cmp = PyObject_RichCompareBool(item, v, Py_EQ);
Py_DECREF(item);
if (cmp < 0)
while (--n >= 0) {
CHECK_NOT_END(b);
- item = b->data[index];
- Py_INCREF(item);
+ item = Py_NewRef(b->data[index]);
cmp = PyObject_RichCompareBool(item, v, Py_EQ);
Py_DECREF(item);
if (cmp) {
}
}
item = b->data[i];
- Py_INCREF(item);
- return item;
+ return Py_NewRef(item);
}
static int
int cmp, rv;
for (i = 0 ; i < n; i++) {
- item = b->data[index];
- Py_INCREF(item);
+ item = Py_NewRef(b->data[index]);
cmp = PyObject_RichCompareBool(item, value, Py_EQ);
Py_DECREF(item);
if (cmp < 0) {
while (--n >= 0)
b = b->leftlink;
}
- Py_INCREF(v);
old_value = b->data[i];
- b->data[i] = v;
+ b->data[i] = Py_NewRef(v);
Py_DECREF(old_value);
return 0;
}
return NULL;
it->b = deque->leftblock;
it->index = deque->leftindex;
- Py_INCREF(deque);
- it->deque = deque;
+ it->deque = (dequeobject*)Py_NewRef(deque);
it->state = deque->state;
it->counter = Py_SIZE(deque);
PyObject_GC_Track(it);
it->b = it->b->rightlink;
it->index = 0;
}
- Py_INCREF(item);
- return item;
+ return Py_NewRef(item);
}
static PyObject *
return NULL;
it->b = deque->rightblock;
it->index = deque->rightindex;
- Py_INCREF(deque);
- it->deque = deque;
+ it->deque = (dequeobject*)Py_NewRef(deque);
it->state = deque->state;
it->counter = Py_SIZE(deque);
PyObject_GC_Track(it);
it->b = it->b->leftlink;
it->index = BLOCKLEN - 1;
}
- Py_INCREF(item);
- return item;
+ return Py_NewRef(item);
}
static PyObject *
}
if (newargs == NULL)
return -1;
- Py_XINCREF(newdefault);
- dd->default_factory = newdefault;
+ dd->default_factory = Py_XNewRef(newdefault);
result = PyDict_Type.tp_init(self, newargs, kwds);
Py_DECREF(newargs);
Py_XDECREF(olddefault);
return NULL;
}
self->index = index;
- Py_INCREF(doc);
- self->doc = doc;
+ self->doc = Py_NewRef(doc);
return (PyObject *)self;
}
PyObject *result;
if (obj == NULL) {
- Py_INCREF(self);
- return self;
+ return Py_NewRef(self);
}
if (!PyTuple_Check(obj)) {
if (obj == Py_None) {
- Py_INCREF(self);
- return self;
+ return Py_NewRef(self);
}
PyErr_Format(PyExc_TypeError,
"descriptor for index '%zd' for tuple subclasses "
}
result = PyTuple_GET_ITEM(obj, index);
- Py_INCREF(result);
- return result;
+ return Py_NewRef(result);
}
static int
static PyObject *
Dialect_get_lineterminator(DialectObj *self, void *Py_UNUSED(ignored))
{
- Py_XINCREF(self->lineterminator);
- return self->lineterminator;
+ return Py_XNewRef(self->lineterminator);
}
static PyObject *
else {
if (PyUnicode_READY(src) == -1)
return -1;
- Py_INCREF(src);
- Py_XSETREF(*target, src);
+ Py_XSETREF(*target, Py_NewRef(src));
}
}
return 0;
goto err;
}
- ret = (PyObject *)self;
- Py_INCREF(self);
+ ret = Py_NewRef(self);
err:
Py_CLEAR(self);
Py_CLEAR(dialect);
Py_DECREF(po);
return NULL;
}
- po->wo = wo;
- Py_INCREF(wo);
+ po->wo = (PyCursesWindowObject*)Py_NewRef(wo);
return (PyObject *)po;
}
"panel_above: can't find Panel Object");
return NULL;
}
- Py_INCREF(po);
- return (PyObject *)po;
+ return Py_NewRef(po);
}
/* panel_below(NULL) returns the top panel in the stack. To get
"panel_below: can't find Panel Object");
return NULL;
}
- Py_INCREF(po);
- return (PyObject *)po;
+ return Py_NewRef(po);
}
/*[clinic input]
_curses_panel_panel_window_impl(PyCursesPanelObject *self)
/*[clinic end generated code: output=5f05940d4106b4cb input=6067353d2c307901]*/
{
- Py_INCREF(self->wo);
- return (PyObject *)self->wo;
+ return Py_NewRef(self->wo);
}
/*[clinic input]
PyErr_SetString(state->PyCursesError, "replace_panel() returned ERR");
return NULL;
}
- Py_INCREF(win);
- Py_SETREF(po->wo, win);
+ Py_SETREF(po->wo, Py_NewRef(win));
Py_RETURN_NONE;
}
return NULL;
}
- Py_INCREF(obj);
- return obj;
+ return Py_NewRef(obj);
}
"panel_above: can't find Panel Object");
return NULL;
}
- Py_INCREF(po);
- return (PyObject *)po;
+ return Py_NewRef(po);
}
/*[clinic input]
"panel_below: can't find Panel Object");
return NULL;
}
- Py_INCREF(po);
- return (PyObject *)po;
+ return Py_NewRef(po);
}
/*[clinic input]
state->PyCursesError = PyErr_NewException(
"_curses_panel.error", NULL, NULL);
- Py_INCREF(state->PyCursesError);
- if (PyModule_AddObject(mod, "error", state->PyCursesError) < 0) {
+ if (PyModule_AddObject(mod, "error", Py_NewRef(state->PyCursesError)) < 0) {
Py_DECREF(state->PyCursesError);
return -1;
}
#endif
}
else if (PyBytes_Check(obj)) {
- Py_INCREF(obj);
- *bytes = obj;
+ *bytes = Py_NewRef(obj);
/* check for embedded null bytes */
if (PyBytes_AsStringAndSize(*bytes, &str, NULL) < 0) {
Py_DECREF(obj);
return PyBytes_FromStringAndSize(val.dptr, val.dsize);
}
- Py_INCREF(default_value);
- return default_value;
+ return Py_NewRef(default_value);
}
/*[clinic input]
static PyObject *
dbm__enter__(PyObject *self, PyObject *args)
{
- Py_INCREF(self);
- return self;
+ return Py_NewRef(self);
}
static PyObject *
Py_LOCAL_INLINE(PyObject *)
incr_true(void)
{
- Py_INCREF(Py_True);
- return Py_True;
+ return Py_NewRef(Py_True);
}
Py_LOCAL_INLINE(PyObject *)
incr_false(void)
{
- Py_INCREF(Py_False);
- return Py_False;
+ return Py_NewRef(Py_False);
}
}
}
- Py_INCREF(res);
- return res;
+ return Py_NewRef(res);
}
static PyObject *
{
int i = mpd_getround(CTX(self));
- Py_INCREF(round_map[i]);
- return round_map[i];
+ return Py_NewRef(round_map[i]);
}
static PyObject *
if (PyUnicode_Check(name)) {
if (PyUnicode_CompareWithASCIIString(name, "traps") == 0) {
retval = ((PyDecContextObject *)self)->traps;
- Py_INCREF(retval);
- return retval;
+ return Py_NewRef(retval);
}
if (PyUnicode_CompareWithASCIIString(name, "flags") == 0) {
retval = ((PyDecContextObject *)self)->flags;
- Py_INCREF(retval);
- return retval;
+ return Py_NewRef(retval);
}
}
return NULL;
}
- Py_INCREF(context);
- return context;
+ return Py_NewRef(context);
}
/* Set the thread local context to a new context, decrement old reference */
Py_DECREF(self);
return NULL;
}
- self->global = global;
- Py_INCREF(self->global);
+ self->global = Py_NewRef(global);
int ret = context_setattrs(
self->local, prec, rounding,
}
Py_DECREF(ret);
- Py_INCREF(self->local);
- return self->local;
+ return Py_NewRef(self->local);
}
static PyObject *
uint32_t status = 0;
if (type == &PyDec_Type && PyDec_CheckExact(v)) {
- Py_INCREF(v);
- return v;
+ return Py_NewRef(v);
}
dec = PyDecType_New(type);
sequence_as_tuple(PyObject *v, PyObject *ex, const char *mesg)
{
if (PyTuple_Check(v)) {
- Py_INCREF(v);
- return v;
+ return Py_NewRef(v);
}
if (PyList_Check(v)) {
return PyList_AsTuple(v);
{
if (PyDec_Check(v)) {
- *conv = v;
- Py_INCREF(v);
+ *conv = Py_NewRef(v);
return 1;
}
if (PyLong_Check(v)) {
Py_TYPE(v)->tp_name);
}
else {
- Py_INCREF(Py_NotImplemented);
- *conv = Py_NotImplemented;
+ *conv = Py_NewRef(Py_NotImplemented);
}
return 0;
}
*vcmp = v;
if (PyDec_Check(w)) {
- Py_INCREF(w);
- *wcmp = w;
+ *wcmp = Py_NewRef(w);
}
else if (PyLong_Check(w)) {
*wcmp = PyDec_FromLongExact(w, context);
}
}
else {
- Py_INCREF(Py_NotImplemented);
- *wcmp = Py_NotImplemented;
+ *wcmp = Py_NewRef(Py_NotImplemented);
}
}
else {
}
}
else {
- Py_INCREF(Py_NotImplemented);
- *wcmp = Py_NotImplemented;
+ *wcmp = Py_NewRef(Py_NotImplemented);
}
}
static PyObject *
dec_canonical(PyObject *self, PyObject *dummy UNUSED)
{
- Py_INCREF(self);
- return self;
+ return Py_NewRef(self);
}
static PyObject *
dec_conjugate(PyObject *self, PyObject *dummy UNUSED)
{
- Py_INCREF(self);
- return self;
+ return Py_NewRef(self);
}
static PyObject *
static PyObject *
dec_copy(PyObject *self, PyObject *dummy UNUSED)
{
- Py_INCREF(self);
- return self;
+ return Py_NewRef(self);
}
/* __floor__ */
static PyObject *
dec_real(PyObject *self, void *closure UNUSED)
{
- Py_INCREF(self);
- return self;
+ return Py_NewRef(self);
}
static PyObject *
return NULL;
}
- Py_INCREF(v);
- return v;
+ return Py_NewRef(v);
}
static PyObject *
/* Create the module */
ASSIGN_PTR(m, PyModule_Create(&_decimal_module));
-
/* Add types to the module */
- Py_INCREF(&PyDec_Type);
- CHECK_INT(PyModule_AddObject(m, "Decimal", (PyObject *)&PyDec_Type));
- Py_INCREF(&PyDecContext_Type);
+ CHECK_INT(PyModule_AddObject(m, "Decimal", Py_NewRef(&PyDec_Type)));
CHECK_INT(PyModule_AddObject(m, "Context",
- (PyObject *)&PyDecContext_Type));
- Py_INCREF(DecimalTuple);
- CHECK_INT(PyModule_AddObject(m, "DecimalTuple", (PyObject *)DecimalTuple));
-
+ Py_NewRef(&PyDecContext_Type)));
+ CHECK_INT(PyModule_AddObject(m, "DecimalTuple", Py_NewRef(DecimalTuple)));
/* Create top level exception */
ASSIGN_PTR(DecimalException, PyErr_NewException(
"decimal.DecimalException",
PyExc_ArithmeticError, NULL));
- Py_INCREF(DecimalException);
- CHECK_INT(PyModule_AddObject(m, "DecimalException", DecimalException));
+ CHECK_INT(PyModule_AddObject(m, "DecimalException", Py_NewRef(DecimalException)));
/* Create signal tuple */
ASSIGN_PTR(SignalTuple, PyTuple_New(SIGNAL_MAP_LEN));
Py_DECREF(base);
/* add to module */
- Py_INCREF(cm->ex);
- CHECK_INT(PyModule_AddObject(m, cm->name, cm->ex));
+ CHECK_INT(PyModule_AddObject(m, cm->name, Py_NewRef(cm->ex)));
/* add to signal tuple */
- Py_INCREF(cm->ex);
- PyTuple_SET_ITEM(SignalTuple, i, cm->ex);
+ PyTuple_SET_ITEM(SignalTuple, i, Py_NewRef(cm->ex));
}
/*
ASSIGN_PTR(cm->ex, PyErr_NewException(cm->fqname, base, NULL));
Py_DECREF(base);
- Py_INCREF(cm->ex);
- CHECK_INT(PyModule_AddObject(m, cm->name, cm->ex));
+ CHECK_INT(PyModule_AddObject(m, cm->name, Py_NewRef(cm->ex)));
}
/* Init default context template first */
ASSIGN_PTR(default_context_template,
PyObject_CallObject((PyObject *)&PyDecContext_Type, NULL));
- Py_INCREF(default_context_template);
CHECK_INT(PyModule_AddObject(m, "DefaultContext",
- default_context_template));
+ Py_NewRef(default_context_template)));
#ifndef WITH_DECIMAL_CONTEXTVAR
ASSIGN_PTR(tls_context_key, PyUnicode_FromString("___DECIMAL_CTX__"));
- Py_INCREF(Py_False);
- CHECK_INT(PyModule_AddObject(m, "HAVE_CONTEXTVAR", Py_False));
+ CHECK_INT(PyModule_AddObject(m, "HAVE_CONTEXTVAR", Py_NewRef(Py_False)));
#else
ASSIGN_PTR(current_context_var, PyContextVar_New("decimal_context", NULL));
- Py_INCREF(Py_True);
- CHECK_INT(PyModule_AddObject(m, "HAVE_CONTEXTVAR", Py_True));
+ CHECK_INT(PyModule_AddObject(m, "HAVE_CONTEXTVAR", Py_NewRef(Py_True)));
#endif
- Py_INCREF(Py_True);
- CHECK_INT(PyModule_AddObject(m, "HAVE_THREADS", Py_True));
+ CHECK_INT(PyModule_AddObject(m, "HAVE_THREADS", Py_NewRef(Py_True)));
/* Init basic context template */
ASSIGN_PTR(basic_context_template,
PyObject_CallObject((PyObject *)&PyDecContext_Type, NULL));
init_basic_context(basic_context_template);
- Py_INCREF(basic_context_template);
CHECK_INT(PyModule_AddObject(m, "BasicContext",
- basic_context_template));
+ Py_NewRef(basic_context_template)));
/* Init extended context template */
ASSIGN_PTR(extended_context_template,
PyObject_CallObject((PyObject *)&PyDecContext_Type, NULL));
init_extended_context(extended_context_template);
- Py_INCREF(extended_context_template);
CHECK_INT(PyModule_AddObject(m, "ExtendedContext",
- extended_context_template));
+ Py_NewRef(extended_context_template)));
/* Init mpd_ssize_t constants */
/* Init string constants */
for (i = 0; i < _PY_DEC_ROUND_GUARD; i++) {
ASSIGN_PTR(round_map[i], PyUnicode_InternFromString(mpd_round_string[i]));
- Py_INCREF(round_map[i]);
- CHECK_INT(PyModule_AddObject(m, mpd_round_string[i], round_map[i]));
+ CHECK_INT(PyModule_AddObject(m, mpd_round_string[i], Py_NewRef(round_map[i])));
}
/* Add specification version number */
if (pto == NULL)
return NULL;
- pto->fn = func;
- Py_INCREF(func);
+ pto->fn = Py_NewRef(func);
nargs = PyTuple_GetSlice(args, 1, PY_SSIZE_T_MAX);
if (nargs == NULL) {
pto->kw = PyDict_New();
}
else if (Py_REFCNT(kw) == 1) {
- Py_INCREF(kw);
- pto->kw = kw;
+ pto->kw = Py_NewRef(kw);
}
else {
pto->kw = PyDict_Copy(kw);
PyObject *kwargs2;
if (PyDict_GET_SIZE(pto->kw) == 0) {
/* kwargs can be NULL */
- kwargs2 = kwargs;
- Py_XINCREF(kwargs2);
+ kwargs2 = Py_XNewRef(kwargs);
}
else {
/* bpo-27840, bpo-29318: dictionary of keyword parameters must be
else
Py_INCREF(dict);
- Py_INCREF(fn);
- Py_SETREF(pto->fn, fn);
+ Py_SETREF(pto->fn, Py_NewRef(fn));
Py_SETREF(pto->args, fnargs);
Py_SETREF(pto->kw, kw);
Py_XSETREF(pto->dict, dict);
if (result == NULL) {
return NULL;
}
- Py_INCREF(ko->cmp);
- result->cmp = ko->cmp;
- Py_INCREF(object);
- result->object = object;
+ result->cmp = Py_NewRef(ko->cmp);
+ result->object = Py_NewRef(object);
PyObject_GC_Track(result);
return (PyObject *)result;
}
object = PyObject_GC_New(keyobject, state->keyobject_type);
if (!object)
return NULL;
- Py_INCREF(mycmp);
- object->cmp = mycmp;
+ object->cmp = Py_NewRef(mycmp);
object->object = NULL;
PyObject_GC_Track(object);
return (PyObject *)object;
if (PyUnicode_CheckExact(key) || PyLong_CheckExact(key)) {
/* For common scalar keys, save space by
dropping the enclosing args tuple */
- Py_INCREF(key);
- return key;
+ return Py_NewRef(key);
}
}
- Py_INCREF(args);
- return args;
+ return Py_NewRef(args);
}
key_size = PyTuple_GET_SIZE(args);
key_pos = 0;
for (pos = 0; pos < PyTuple_GET_SIZE(args); ++pos) {
PyObject *item = PyTuple_GET_ITEM(args, pos);
- Py_INCREF(item);
- PyTuple_SET_ITEM(key, key_pos++, item);
+ PyTuple_SET_ITEM(key, key_pos++, Py_NewRef(item));
}
if (kwds_size) {
- Py_INCREF(kwd_mark);
- PyTuple_SET_ITEM(key, key_pos++, kwd_mark);
+ PyTuple_SET_ITEM(key, key_pos++, Py_NewRef(kwd_mark));
for (pos = 0; PyDict_Next(kwds, &pos, &keyword, &value);) {
- Py_INCREF(keyword);
- PyTuple_SET_ITEM(key, key_pos++, keyword);
- Py_INCREF(value);
- PyTuple_SET_ITEM(key, key_pos++, value);
+ PyTuple_SET_ITEM(key, key_pos++, Py_NewRef(keyword));
+ PyTuple_SET_ITEM(key, key_pos++, Py_NewRef(value));
}
assert(key_pos == PyTuple_GET_SIZE(args) + kwds_size * 2 + 1);
}
if (typed) {
for (pos = 0; pos < PyTuple_GET_SIZE(args); ++pos) {
PyObject *item = (PyObject *)Py_TYPE(PyTuple_GET_ITEM(args, pos));
- Py_INCREF(item);
- PyTuple_SET_ITEM(key, key_pos++, item);
+ PyTuple_SET_ITEM(key, key_pos++, Py_NewRef(item));
}
if (kwds_size) {
for (pos = 0; PyDict_Next(kwds, &pos, &keyword, &value);) {
PyObject *item = (PyObject *)Py_TYPE(value);
- Py_INCREF(item);
- PyTuple_SET_ITEM(key, key_pos++, item);
+ PyTuple_SET_ITEM(key, key_pos++, Py_NewRef(item));
}
}
}
return NULL;
}
lru_cache_append_link(self, link);
- Py_INCREF(result); /* for return */
- return result;
+ return Py_NewRef(result);
}
/* Since the cache is full, we need to evict an old key and add
a new key. Rather than free the old link and allocate a new
obj->wrapper = wrapper;
obj->typed = typed;
obj->cache = cachedict;
- Py_INCREF(func);
- obj->func = func;
+ obj->func = Py_NewRef(func);
obj->misses = obj->hits = 0;
obj->maxsize = maxsize;
- Py_INCREF(state->kwd_mark);
- obj->kwd_mark = state->kwd_mark;
- Py_INCREF(state->lru_list_elem_type);
- obj->lru_list_elem_type = state->lru_list_elem_type;
- Py_INCREF(cache_info_type);
- obj->cache_info_type = cache_info_type;
+ obj->kwd_mark = Py_NewRef(state->kwd_mark);
+ obj->lru_list_elem_type = (PyTypeObject*)Py_NewRef(state->lru_list_elem_type);
+ obj->cache_info_type = Py_NewRef(cache_info_type);
obj->dict = NULL;
obj->weakreflist = NULL;
return (PyObject *)obj;
lru_cache_descr_get(PyObject *self, PyObject *obj, PyObject *type)
{
if (obj == Py_None || obj == NULL) {
- Py_INCREF(self);
- return self;
+ return Py_NewRef(self);
}
return PyMethod_New(self, obj);
}
static PyObject *
lru_cache_copy(PyObject *self, PyObject *unused)
{
- Py_INCREF(self);
- return self;
+ return Py_NewRef(self);
}
static PyObject *
lru_cache_deepcopy(PyObject *self, PyObject *unused)
{
- Py_INCREF(self);
- return self;
+ return Py_NewRef(self);
}
static int
res = gdbm_subscript(self, key);
if (res == NULL && PyErr_ExceptionMatches(PyExc_KeyError)) {
PyErr_Clear();
- Py_INCREF(default_value);
- return default_value;
+ return Py_NewRef(default_value);
}
return res;
}
static PyObject *
gdbm__enter__(PyObject *self, PyObject *args)
{
- Py_INCREF(self);
- return self;
+ return Py_NewRef(self);
}
static PyObject *
}
returnitem = PyList_GET_ITEM(heap, 0);
- Py_INCREF(item);
- PyList_SET_ITEM(heap, 0, item);
+ PyList_SET_ITEM(heap, 0, Py_NewRef(item));
if (siftup_func((PyListObject *)heap, 0)) {
Py_DECREF(returnitem);
return NULL;
int cmp;
if (PyList_GET_SIZE(heap) == 0) {
- Py_INCREF(item);
- return item;
+ return Py_NewRef(item);
}
PyObject* top = PyList_GET_ITEM(heap, 0);
if (cmp < 0)
return NULL;
if (cmp == 0) {
- Py_INCREF(item);
- return item;
+ return Py_NewRef(item);
}
if (PyList_GET_SIZE(heap) == 0) {
}
returnitem = PyList_GET_ITEM(heap, 0);
- Py_INCREF(item);
- PyList_SET_ITEM(heap, 0, item);
+ PyList_SET_ITEM(heap, 0, Py_NewRef(item));
if (siftup((PyListObject *)heap, 0)) {
Py_DECREF(returnitem);
return NULL;
newitem = arr[pos];
while (pos > startpos) {
parentpos = (pos - 1) >> 1;
- parent = arr[parentpos];
- Py_INCREF(parent);
+ parent = Py_NewRef(arr[parentpos]);
Py_INCREF(newitem);
cmp = PyObject_RichCompareBool(parent, newitem, Py_LT);
Py_DECREF(parent);