summaryrefslogtreecommitdiffstats
path: root/contrib/tools/python3/src/Objects/classobject.c
diff options
context:
space:
mode:
authorAlexSm <[email protected]>2024-02-16 11:51:30 +0100
committerGitHub <[email protected]>2024-02-16 11:51:30 +0100
commit506ecaee93b52cc12c2e2f97c3d42e3ca2a7f59e (patch)
treed096fb9eb988fbb0ca1ba970041773207ce3aa70 /contrib/tools/python3/src/Objects/classobject.c
parent4749b9e5d260714490997e6f5ee1ee8c1c8fc46c (diff)
parentf200f72c9d7a89c1018e3dc6b46c49fe2ecf84fb (diff)
Merge pull request #1940 from dcherednik/importlib
Library import 14
Diffstat (limited to 'contrib/tools/python3/src/Objects/classobject.c')
-rw-r--r--contrib/tools/python3/src/Objects/classobject.c36
1 files changed, 14 insertions, 22 deletions
diff --git a/contrib/tools/python3/src/Objects/classobject.c b/contrib/tools/python3/src/Objects/classobject.c
index b9708ba0e41..12dc276f289 100644
--- a/contrib/tools/python3/src/Objects/classobject.c
+++ b/contrib/tools/python3/src/Objects/classobject.c
@@ -48,6 +48,7 @@ method_vectorcall(PyObject *method, PyObject *const *args,
PyObject *self = PyMethod_GET_SELF(method);
PyObject *func = PyMethod_GET_FUNCTION(method);
Py_ssize_t nargs = PyVectorcall_NARGS(nargsf);
+ assert(nargs == 0 || args[nargs-1]);
PyObject *result;
if (nargsf & PY_VECTORCALL_ARGUMENTS_OFFSET) {
@@ -56,6 +57,7 @@ method_vectorcall(PyObject *method, PyObject *const *args,
nargs += 1;
PyObject *tmp = newargs[0];
newargs[0] = self;
+ assert(newargs[nargs-1]);
result = _PyObject_VectorcallTstate(tstate, func, newargs,
nargs, kwnames);
newargs[0] = tmp;
@@ -113,10 +115,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;
@@ -183,7 +183,7 @@ method_getattro(PyObject *obj, PyObject *name)
PyObject *descr = NULL;
{
- if (tp->tp_dict == NULL) {
+ if (!_PyType_IsReady(tp)) {
if (PyType_Ready(tp) < 0)
return NULL;
}
@@ -195,8 +195,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 +266,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 *
@@ -287,8 +285,7 @@ method_repr(PyMethodObject *a)
}
if (funcname != NULL && !PyUnicode_Check(funcname)) {
- Py_DECREF(funcname);
- funcname = NULL;
+ Py_SETREF(funcname, NULL);
}
/* XXX Shouldn't use repr()/%R here! */
@@ -359,8 +356,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;
}
@@ -401,7 +397,7 @@ instancemethod_getattro(PyObject *self, PyObject *name)
PyTypeObject *tp = Py_TYPE(self);
PyObject *descr = NULL;
- if (tp->tp_dict == NULL) {
+ if (!_PyType_IsReady(tp)) {
if (PyType_Ready(tp) < 0)
return NULL;
}
@@ -412,8 +408,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 +438,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 +466,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 *
@@ -492,8 +485,7 @@ instancemethod_repr(PyObject *self)
return NULL;
}
if (funcname != NULL && !PyUnicode_Check(funcname)) {
- Py_DECREF(funcname);
- funcname = NULL;
+ Py_SETREF(funcname, NULL);
}
result = PyUnicode_FromFormat("<instancemethod %V at %p>",