Skip to content

Commit f9d2f28

Browse files
cleanup
1 parent 4cd1ebc commit f9d2f28

File tree

2 files changed

+23
-20
lines changed

2 files changed

+23
-20
lines changed

Objects/call.c

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -871,19 +871,22 @@ PyObject_CallMethodObjArgs(PyObject *obj, PyObject *name, ...)
871871
return null_error(tstate);
872872
}
873873

874-
PyObject *callable = NULL;
875-
int is_method = _PyObject_GetMethod(obj, name, &callable);
876-
if (callable == NULL) {
874+
_PyCStackRef method;
875+
_PyThreadState_PushCStackRef(tstate, &method);
876+
int is_method = _PyObject_GetMethodStackRef(tstate, obj, name, &method.ref);
877+
if (PyStackRef_IsNull(method.ref)) {
878+
_PyThreadState_PopCStackRef(tstate, &method);
877879
return NULL;
878880
}
881+
PyObject *callable = PyStackRef_AsPyObjectBorrow(method.ref);
879882
obj = is_method ? obj : NULL;
880883

881884
va_list vargs;
882885
va_start(vargs, name);
883886
PyObject *result = object_vacall(tstate, obj, callable, vargs);
884887
va_end(vargs);
885888

886-
Py_DECREF(callable);
889+
_PyThreadState_PopCStackRef(tstate, &method);
887890
return result;
888891
}
889892

@@ -900,20 +903,23 @@ _PyObject_CallMethodIdObjArgs(PyObject *obj, _Py_Identifier *name, ...)
900903
if (!oname) {
901904
return NULL;
902905
}
903-
904-
PyObject *callable = NULL;
905-
int is_method = _PyObject_GetMethod(obj, oname, &callable);
906-
if (callable == NULL) {
906+
_PyCStackRef method;
907+
_PyThreadState_PushCStackRef(tstate, &method);
908+
int is_method = _PyObject_GetMethodStackRef(tstate, obj, oname, &method.ref);
909+
if (PyStackRef_IsNull(method.ref)) {
910+
_PyThreadState_PopCStackRef(tstate, &method);
907911
return NULL;
908912
}
913+
PyObject *callable = PyStackRef_AsPyObjectBorrow(method.ref);
914+
909915
obj = is_method ? obj : NULL;
910916

911917
va_list vargs;
912918
va_start(vargs, name);
913919
PyObject *result = object_vacall(tstate, obj, callable, vargs);
914920
va_end(vargs);
915921

916-
Py_DECREF(callable);
922+
_PyThreadState_PopCStackRef(tstate, &method);
917923
return result;
918924
}
919925

Objects/object.c

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1670,7 +1670,6 @@ _PyObject_GetMethodStackRef(PyThreadState *ts, PyObject *obj,
16701670
{
16711671
int meth_found = 0;
16721672

1673-
int ret = 0;
16741673
assert(PyStackRef_IsNull(*method));
16751674

16761675
PyTypeObject *tp = Py_TYPE(obj);
@@ -1703,7 +1702,7 @@ _PyObject_GetMethodStackRef(PyThreadState *ts, PyObject *obj,
17031702
if (value != NULL) {
17041703
*method = PyStackRef_FromPyObjectSteal(value);
17051704
}
1706-
goto exit;
1705+
return 0;
17071706
}
17081707
}
17091708
}
@@ -1713,7 +1712,7 @@ _PyObject_GetMethodStackRef(PyThreadState *ts, PyObject *obj,
17131712
if (attr != NULL) {
17141713
PyStackRef_CLEAR(*method);
17151714
*method = PyStackRef_FromPyObjectSteal(attr);
1716-
goto exit;
1715+
return 0;
17171716
}
17181717
dict = NULL;
17191718
}
@@ -1740,16 +1739,15 @@ _PyObject_GetMethodStackRef(PyThreadState *ts, PyObject *obj,
17401739
if (value != NULL) {
17411740
*method = PyStackRef_FromPyObjectSteal(value);
17421741
}
1743-
goto exit;
1742+
return 0;
17441743
}
17451744
// not found
17461745
Py_DECREF(dict);
17471746
}
17481747

17491748
if (meth_found) {
1750-
ret = 1;
17511749
assert(!PyStackRef_IsNull(*method));
1752-
goto exit;
1750+
return 1;
17531751
}
17541752

17551753
if (f != NULL) {
@@ -1758,22 +1756,21 @@ _PyObject_GetMethodStackRef(PyThreadState *ts, PyObject *obj,
17581756
if (value) {
17591757
*method = PyStackRef_FromPyObjectSteal(value);
17601758
}
1761-
goto exit;
1759+
return 0;
17621760
}
17631761

17641762
if (descr != NULL) {
17651763
assert(!PyStackRef_IsNull(*method));
1766-
goto exit;
1764+
return 0;
17671765
}
17681766

17691767
PyErr_Format(PyExc_AttributeError,
17701768
"'%.100s' object has no attribute '%U'",
17711769
tp->tp_name, name);
17721770

17731771
_PyObject_SetAttributeErrorContext(obj, name);
1774-
PyStackRef_CLEAR(*method);
1775-
exit:
1776-
return ret;
1772+
assert(PyStackRef_IsNull(*method));
1773+
return 0;
17771774
}
17781775

17791776

0 commit comments

Comments
 (0)