Skip to content

Commit 405efd2

Browse files
[mypyc] Use PyObject_CallNoArgs and PyObject_CallOneArg (#12862)
Use PyObject_CallNoArgs and PyObject_CallOneArg to replace PyObject_CallFunctionObjArgs in lib-rt, since the new API costs less memory according to python/cpython#13890 (comment) Also remove the macro in pythonsupport.h since the two API are already covered by pythoncapi_compat.h.
1 parent 24ef8d0 commit 405efd2

File tree

3 files changed

+5
-9
lines changed

3 files changed

+5
-9
lines changed

mypyc/lib-rt/exc_ops.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
void CPy_Raise(PyObject *exc) {
99
if (PyObject_IsInstance(exc, (PyObject *)&PyType_Type)) {
10-
PyObject *obj = PyObject_CallFunctionObjArgs(exc, NULL);
10+
PyObject *obj = PyObject_CallNoArgs(exc);
1111
if (!obj)
1212
return;
1313
PyErr_SetObject(exc, obj);

mypyc/lib-rt/misc_ops.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ int CPy_YieldFromErrorHandle(PyObject *iter, PyObject **outp)
5454
if (PyErr_GivenExceptionMatches(exc_type, PyExc_GeneratorExit)) {
5555
_m = _PyObject_GetAttrId(iter, &PyId_close);
5656
if (_m) {
57-
res = PyObject_CallFunctionObjArgs(_m, NULL);
57+
res = PyObject_CallNoArgs(_m);
5858
Py_DECREF(_m);
5959
if (!res)
6060
return 2;
@@ -360,7 +360,7 @@ CPyDataclass_SleightOfHand(PyObject *dataclass_dec, PyObject *tp,
360360
}
361361

362362
/* Run the @dataclass descriptor */
363-
res = PyObject_CallFunctionObjArgs(dataclass_dec, tp, NULL);
363+
res = PyObject_CallOneArg(dataclass_dec, tp);
364364
if (!res) {
365365
goto fail;
366366
}

mypyc/lib-rt/pythonsupport.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -350,15 +350,15 @@ CPyGen_SetStopIterationValue(PyObject *value)
350350
return 0;
351351
}
352352
/* Construct an exception instance manually with
353-
* PyObject_CallFunctionObjArgs and pass it to PyErr_SetObject.
353+
* PyObject_CallOneArg and pass it to PyErr_SetObject.
354354
*
355355
* We do this to handle a situation when "value" is a tuple, in which
356356
* case PyErr_SetObject would set the value of StopIteration to
357357
* the first element of the tuple.
358358
*
359359
* (See PyErr_SetObject/_PyErr_CreateException code for details.)
360360
*/
361-
e = PyObject_CallFunctionObjArgs(PyExc_StopIteration, value, NULL);
361+
e = PyObject_CallOneArg(PyExc_StopIteration, value);
362362
if (e == NULL) {
363363
return -1;
364364
}
@@ -410,10 +410,6 @@ _CPyObject_HasAttrId(PyObject *v, _Py_Identifier *name) {
410410
_PyObject_CallMethodIdObjArgs((self), (name), NULL)
411411
#define _PyObject_CallMethodIdOneArg(self, name, arg) \
412412
_PyObject_CallMethodIdObjArgs((self), (name), (arg), NULL)
413-
#define PyObject_CallNoArgs(callable) \
414-
PyObject_CallFunctionObjArgs((callable), NULL)
415-
#define PyObject_CallOneArg(callable, arg) \
416-
PyObject_CallFunctionObjArgs((callable), (arg), NULL)
417413
#endif
418414

419415
#endif

0 commit comments

Comments
 (0)