summaryrefslogtreecommitdiffstats
path: root/Objects/classobject.c
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2022-11-10 15:27:32 (GMT)
committerGitHub <noreply@github.com>2022-11-10 15:27:32 (GMT)
commitc0feb99187f449f844621b378273776d70a50f57 (patch)
tree23251e00cd73fab30b9ae2df063ce8bc6edef3e9 /Objects/classobject.c
parent4ce2a202c7b573edaa0ee4a2315d5578f66737c5 (diff)
downloadcpython-c0feb99187f449f844621b378273776d70a50f57.zip
cpython-c0feb99187f449f844621b378273776d70a50f57.tar.gz
cpython-c0feb99187f449f844621b378273776d70a50f57.tar.bz2
gh-99300: Use Py_NewRef() in Objects/ directory (#99332)
Replace Py_INCREF() and Py_XINCREF() with Py_NewRef() and Py_XNewRef() in C files of the Objects/ directory.
Diffstat (limited to 'Objects/classobject.c')
-rw-r--r--Objects/classobject.c24
1 files changed, 8 insertions, 16 deletions
diff --git a/Objects/classobject.c b/Objects/classobject.c
index b9708ba..eedf8f0 100644
--- a/Objects/classobject.c
+++ b/Objects/classobject.c
@@ -113,10 +113,8 @@ PyMethod_New(PyObject *func, PyObject *self)
return NULL;
}
im->im_weakreflist = NULL;
- Py_INCREF(func);
- im->im_func = func;
- Py_INCREF(self);
- im->im_self = self;
+ im->im_func = Py_NewRef(func);
+ im->im_self = Py_NewRef(self);
im->vectorcall = method_vectorcall;
_PyObject_GC_TRACK(im);
return (PyObject *)im;
@@ -195,8 +193,7 @@ method_getattro(PyObject *obj, PyObject *name)
if (f != NULL)
return f(descr, obj, (PyObject *)Py_TYPE(obj));
else {
- Py_INCREF(descr);
- return descr;
+ return Py_NewRef(descr);
}
}
@@ -267,8 +264,7 @@ method_richcompare(PyObject *self, PyObject *other, int op)
res = eq ? Py_True : Py_False;
else
res = eq ? Py_False : Py_True;
- Py_INCREF(res);
- return res;
+ return Py_NewRef(res);
}
static PyObject *
@@ -359,8 +355,7 @@ PyInstanceMethod_New(PyObject *func) {
method = PyObject_GC_New(PyInstanceMethodObject,
&PyInstanceMethod_Type);
if (method == NULL) return NULL;
- Py_INCREF(func);
- method->func = func;
+ method->func = Py_NewRef(func);
_PyObject_GC_TRACK(method);
return (PyObject *)method;
}
@@ -412,8 +407,7 @@ instancemethod_getattro(PyObject *self, PyObject *name)
if (f != NULL)
return f(descr, self, (PyObject *)Py_TYPE(self));
else {
- Py_INCREF(descr);
- return descr;
+ return Py_NewRef(descr);
}
}
@@ -443,8 +437,7 @@ static PyObject *
instancemethod_descr_get(PyObject *descr, PyObject *obj, PyObject *type) {
PyObject *func = PyInstanceMethod_GET_FUNCTION(descr);
if (obj == NULL) {
- Py_INCREF(func);
- return func;
+ return Py_NewRef(func);
}
else
return PyMethod_New(func, obj);
@@ -472,8 +465,7 @@ instancemethod_richcompare(PyObject *self, PyObject *other, int op)
res = eq ? Py_True : Py_False;
else
res = eq ? Py_False : Py_True;
- Py_INCREF(res);
- return res;
+ return Py_NewRef(res);
}
static PyObject *