From 366f4ee4da4420842eac26b3fa00c2b01d4515a6 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Thu, 1 Dec 2016 14:43:22 +0100 Subject: Replace PyObject_CallFunctionObjArgs() with fastcall * PyObject_CallFunctionObjArgs(func, NULL) => _PyObject_CallNoArg(func) * PyObject_CallFunctionObjArgs(func, arg, NULL) => _PyObject_CallArg1(func, arg) PyObject_CallFunctionObjArgs() allocates 40 bytes on the C stack and requires extra work to "parse" C arguments to build a C array of PyObject*. _PyObject_CallNoArg() and _PyObject_CallArg1() are simpler and don't allocate memory on the C stack. This change is part of the fastcall project. The change on listsort() is related to the issue #23507. --- Objects/genobject.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Objects/genobject.c') diff --git a/Objects/genobject.c b/Objects/genobject.c index 2680ab0e12..1db83c9d64 100644 --- a/Objects/genobject.c +++ b/Objects/genobject.c @@ -43,7 +43,7 @@ _PyGen_Finalize(PyObject *self) /* Save the current exception, if any. */ PyErr_Fetch(&error_type, &error_value, &error_traceback); - res = PyObject_CallFunctionObjArgs(finalizer, self, NULL); + res = _PyObject_CallArg1(finalizer, self); if (res == NULL) { PyErr_WriteUnraisable(self); @@ -591,7 +591,7 @@ _PyGen_SetStopIterationValue(PyObject *value) * * (See PyErr_SetObject/_PyErr_CreateException code for details.) */ - e = PyObject_CallFunctionObjArgs(PyExc_StopIteration, value, NULL); + e = _PyObject_CallArg1(PyExc_StopIteration, value); if (e == NULL) { return -1; } -- cgit v1.2.1 From 3f6ef1e99f7c517a21d4f53c63b0aeef7e5b5b2c Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Thu, 1 Dec 2016 14:51:04 +0100 Subject: Replace PyObject_CallFunction() with fastcall Replace PyObject_CallFunction(func, "O", arg) and PyObject_CallFunction(func, "O", arg, NULL) with _PyObject_CallArg1(func, arg) Replace PyObject_CallFunction(func, NULL) with _PyObject_CallNoArg(func) _PyObject_CallNoArg() and _PyObject_CallArg1() are simpler and don't allocate memory on the C stack. --- Objects/genobject.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Objects/genobject.c') diff --git a/Objects/genobject.c b/Objects/genobject.c index 1db83c9d64..0484b1c677 100644 --- a/Objects/genobject.c +++ b/Objects/genobject.c @@ -1341,7 +1341,7 @@ async_gen_init_hooks(PyAsyncGenObject *o) PyObject *res; Py_INCREF(firstiter); - res = PyObject_CallFunction(firstiter, "O", o); + res = _PyObject_CallArg1(firstiter, o); Py_DECREF(firstiter); if (res == NULL) { return 1; -- cgit v1.2.1 From 39ae5bedd90f9caf9a78efa82f4d11e838933b3a Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Sun, 4 Dec 2016 22:59:09 +0100 Subject: Backed out changeset b9c9691c72c5 Issue #28858: The change b9c9691c72c5 introduced a regression. It seems like _PyObject_CallArg1() uses more stack memory than PyObject_CallFunctionObjArgs(). --- Objects/genobject.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Objects/genobject.c') diff --git a/Objects/genobject.c b/Objects/genobject.c index 0484b1c677..bd7873bceb 100644 --- a/Objects/genobject.c +++ b/Objects/genobject.c @@ -43,7 +43,7 @@ _PyGen_Finalize(PyObject *self) /* Save the current exception, if any. */ PyErr_Fetch(&error_type, &error_value, &error_traceback); - res = _PyObject_CallArg1(finalizer, self); + res = PyObject_CallFunctionObjArgs(finalizer, self, NULL); if (res == NULL) { PyErr_WriteUnraisable(self); @@ -591,7 +591,7 @@ _PyGen_SetStopIterationValue(PyObject *value) * * (See PyErr_SetObject/_PyErr_CreateException code for details.) */ - e = _PyObject_CallArg1(PyExc_StopIteration, value); + e = PyObject_CallFunctionObjArgs(PyExc_StopIteration, value, NULL); if (e == NULL) { return -1; } -- cgit v1.2.1 From 40273ec4f37c65c13a09d0ac23b08c99ebe2f1a3 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 5 Dec 2016 17:04:32 +0100 Subject: Issue #28858: Remove _PyObject_CallArg1() macro Replace _PyObject_CallArg1(func, arg) with PyObject_CallFunctionObjArgs(func, arg, NULL) Using the _PyObject_CallArg1() macro increases the usage of the C stack, which was unexpected and unwanted. PyObject_CallFunctionObjArgs() doesn't have this issue. --- Objects/genobject.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Objects/genobject.c') diff --git a/Objects/genobject.c b/Objects/genobject.c index bd7873bceb..59f53cefcb 100644 --- a/Objects/genobject.c +++ b/Objects/genobject.c @@ -1341,7 +1341,7 @@ async_gen_init_hooks(PyAsyncGenObject *o) PyObject *res; Py_INCREF(firstiter); - res = _PyObject_CallArg1(firstiter, o); + res = PyObject_CallFunctionObjArgs(firstiter, o, NULL); Py_DECREF(firstiter); if (res == NULL) { return 1; -- cgit v1.2.1 From 0a023be4188e0fae813a3a468528452c02f553bb Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Fri, 9 Dec 2016 17:12:17 +0100 Subject: Inline PyEval_EvalFrameEx() in callers The PEP 523 modified PyEval_EvalFrameEx(): it's now an indirection to interp->eval_frame(). Inline the call in performance critical code. Leave PyEval_EvalFrame() unchanged, this function is only kept for backward compatibility. --- Objects/genobject.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Objects/genobject.c') diff --git a/Objects/genobject.c b/Objects/genobject.c index 59f53cefcb..9d93a761d7 100644 --- a/Objects/genobject.c +++ b/Objects/genobject.c @@ -186,7 +186,7 @@ gen_send_ex(PyGenObject *gen, PyObject *arg, int exc, int closing) f->f_back = tstate->frame; gen->gi_running = 1; - result = PyEval_EvalFrameEx(f, exc); + result = tstate->interp->eval_frame(f, exc); gen->gi_running = 0; /* Don't keep the reference to f_back any longer than necessary. It -- cgit v1.2.1 From 52f6d966c7b6f06c6b140163799cb809373a53c8 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Fri, 9 Dec 2016 18:51:13 +0100 Subject: Backed out changeset 99c34e47348b The change broke test_gdb. --- Objects/genobject.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Objects/genobject.c') diff --git a/Objects/genobject.c b/Objects/genobject.c index 9d93a761d7..59f53cefcb 100644 --- a/Objects/genobject.c +++ b/Objects/genobject.c @@ -186,7 +186,7 @@ gen_send_ex(PyGenObject *gen, PyObject *arg, int exc, int closing) f->f_back = tstate->frame; gen->gi_running = 1; - result = tstate->interp->eval_frame(f, exc); + result = PyEval_EvalFrameEx(f, exc); gen->gi_running = 0; /* Don't keep the reference to f_back any longer than necessary. It -- cgit v1.2.1 From bfeec6d871e3db2e0ddfdef01387913bc19cadd4 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Mon, 23 Jan 2017 09:47:21 +0200 Subject: Issue #28999: Use Py_RETURN_NONE, Py_RETURN_TRUE and Py_RETURN_FALSE wherever possible. Patch is writen with Coccinelle. --- Objects/genobject.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'Objects/genobject.c') diff --git a/Objects/genobject.c b/Objects/genobject.c index 59f53cefcb..24a1da6f3e 100644 --- a/Objects/genobject.c +++ b/Objects/genobject.c @@ -402,8 +402,7 @@ gen_close(PyGenObject *gen, PyObject *args) if (PyErr_ExceptionMatches(PyExc_StopIteration) || PyErr_ExceptionMatches(PyExc_GeneratorExit)) { PyErr_Clear(); /* ignore these errors */ - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } return NULL; } -- cgit v1.2.1