Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
gh-99300: Use Py_NewRef() in Doc/ directory
Replace Py_INCREF() and Py_XINCREF() with Py_NewRef() and
Py_XNewRef() in test C files of the Doc/ directory.
  • Loading branch information
vstinner committed Nov 14, 2022
commit 40f41097de2bc8d589ab685c17cbbbca1b738e74
6 changes: 2 additions & 4 deletions Doc/includes/custom2.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,12 @@ Custom_init(CustomObject *self, PyObject *args, PyObject *kwds)

if (first) {
tmp = self->first;
Py_INCREF(first);
self->first = first;
self->first = Py_NewRef(first);
Py_XDECREF(tmp);
}
if (last) {
tmp = self->last;
Py_INCREF(last);
self->last = last;
self->last = Py_NewRef(last);
Py_XDECREF(tmp);
}
return 0;
Expand Down
18 changes: 6 additions & 12 deletions Doc/includes/custom3.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,12 @@ Custom_init(CustomObject *self, PyObject *args, PyObject *kwds)

if (first) {
tmp = self->first;
Py_INCREF(first);
self->first = first;
self->first = Py_NewRef(first);
Py_DECREF(tmp);
}
if (last) {
tmp = self->last;
Py_INCREF(last);
self->last = last;
self->last = Py_NewRef(last);
Py_DECREF(tmp);
}
return 0;
Expand All @@ -73,8 +71,7 @@ static PyMemberDef Custom_members[] = {
static PyObject *
Custom_getfirst(CustomObject *self, void *closure)
{
Py_INCREF(self->first);
return self->first;
return Py_NewRef(self->first);
}

static int
Expand All @@ -91,17 +88,15 @@ Custom_setfirst(CustomObject *self, PyObject *value, void *closure)
return -1;
}
tmp = self->first;
Py_INCREF(value);
self->first = value;
self->first = Py_NewRef(value);
Py_DECREF(tmp);
return 0;
}

static PyObject *
Custom_getlast(CustomObject *self, void *closure)
{
Py_INCREF(self->last);
return self->last;
return Py_NewRef(self->last);
}

static int
Expand All @@ -118,8 +113,7 @@ Custom_setlast(CustomObject *self, PyObject *value, void *closure)
return -1;
}
tmp = self->last;
Py_INCREF(value);
self->last = value;
self->last = Py_NewRef(value);
Py_DECREF(tmp);
return 0;
}
Expand Down
12 changes: 4 additions & 8 deletions Doc/includes/custom4.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,12 @@ Custom_init(CustomObject *self, PyObject *args, PyObject *kwds)

if (first) {
tmp = self->first;
Py_INCREF(first);
self->first = first;
self->first = Py_NewRef(first);
Py_DECREF(tmp);
}
if (last) {
tmp = self->last;
Py_INCREF(last);
self->last = last;
self->last = Py_NewRef(last);
Py_DECREF(tmp);
}
return 0;
Expand All @@ -89,8 +87,7 @@ static PyMemberDef Custom_members[] = {
static PyObject *
Custom_getfirst(CustomObject *self, void *closure)
{
Py_INCREF(self->first);
return self->first;
return Py_NewRef(self->first);
}

static int
Expand All @@ -114,8 +111,7 @@ Custom_setfirst(CustomObject *self, PyObject *value, void *closure)
static PyObject *
Custom_getlast(CustomObject *self, void *closure)
{
Py_INCREF(self->last);
return self->last;
return Py_NewRef(self->last);
}

static int
Expand Down