From d7a4362203dbd80afd88e89b46e649d7c3095821 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Fri, 19 Aug 2016 16:11:43 +0200 Subject: Add _PyObject_FastCall() Issue #27128: Add _PyObject_FastCall(), a new calling convention avoiding a temporary tuple to pass positional parameters in most cases, but create a temporary tuple if needed (ex: for the tp_call slot). The API is prepared to support keyword parameters, but the full implementation will come later (_PyFunction_FastCall() doesn't support keyword parameters yet). Add also: * _PyStack_AsTuple() helper function: convert a "stack" of parameters to a tuple. * _PyCFunction_FastCall(): fast call implementation for C functions * _PyFunction_FastCall(): fast call implementation for Python functions --- Include/methodobject.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'Include/methodobject.h') diff --git a/Include/methodobject.h b/Include/methodobject.h index e2ad80440b..8dec00a8f5 100644 --- a/Include/methodobject.h +++ b/Include/methodobject.h @@ -37,6 +37,12 @@ PyAPI_FUNC(int) PyCFunction_GetFlags(PyObject *); #endif PyAPI_FUNC(PyObject *) PyCFunction_Call(PyObject *, PyObject *, PyObject *); +#ifndef Py_LIMITED_API +PyAPI_FUNC(PyObject *) _PyCFunction_FastCall(PyObject *func, + PyObject **args, int nargs, + PyObject *kwargs); +#endif + struct PyMethodDef { const char *ml_name; /* The name of the built-in function/method */ PyCFunction ml_meth; /* The C function that implements it */ -- cgit v1.2.1 From 9dae6156b5e3127cb8bfaa1bd36cecadaad5d60b Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 22 Aug 2016 23:15:44 +0200 Subject: _PyFunction_FastCallDict() supports keyword args Issue #27809: * Rename _PyFunction_FastCall() to _PyFunction_FastCallDict() * Rename _PyCFunction_FastCall() to _PyCFunction_FastCallDict() * _PyFunction_FastCallDict() now supports keyword arguments --- Include/methodobject.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Include/methodobject.h') diff --git a/Include/methodobject.h b/Include/methodobject.h index 8dec00a8f5..107a650257 100644 --- a/Include/methodobject.h +++ b/Include/methodobject.h @@ -38,7 +38,7 @@ PyAPI_FUNC(int) PyCFunction_GetFlags(PyObject *); PyAPI_FUNC(PyObject *) PyCFunction_Call(PyObject *, PyObject *, PyObject *); #ifndef Py_LIMITED_API -PyAPI_FUNC(PyObject *) _PyCFunction_FastCall(PyObject *func, +PyAPI_FUNC(PyObject *) _PyCFunction_FastCallDict(PyObject *func, PyObject **args, int nargs, PyObject *kwargs); #endif -- cgit v1.2.1 From c79e5123bcf2d1e514a0420e89c62fa334d57ba9 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Thu, 25 Aug 2016 00:04:09 +0200 Subject: Use Py_ssize_t type for number of arguments Issue #27848: use Py_ssize_t rather than C int for the number of function positional and keyword arguments. --- Include/methodobject.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'Include/methodobject.h') diff --git a/Include/methodobject.h b/Include/methodobject.h index 107a650257..84a14978e1 100644 --- a/Include/methodobject.h +++ b/Include/methodobject.h @@ -39,7 +39,8 @@ PyAPI_FUNC(PyObject *) PyCFunction_Call(PyObject *, PyObject *, PyObject *); #ifndef Py_LIMITED_API PyAPI_FUNC(PyObject *) _PyCFunction_FastCallDict(PyObject *func, - PyObject **args, int nargs, + PyObject **args, + Py_ssize_t nargs, PyObject *kwargs); #endif -- cgit v1.2.1 From 2615f24fb54cece9f22c5e2b1d206e8dd559631a Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Fri, 9 Sep 2016 14:07:44 -0700 Subject: Issue #27810: Add _PyCFunction_FastCallKeywords() Use _PyCFunction_FastCallKeywords() in ceval.c: it allows to remove a lot of code from ceval.c which was only used to call C functions. --- Include/methodobject.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'Include/methodobject.h') diff --git a/Include/methodobject.h b/Include/methodobject.h index 84a14978e1..1f4f06cff8 100644 --- a/Include/methodobject.h +++ b/Include/methodobject.h @@ -42,6 +42,11 @@ PyAPI_FUNC(PyObject *) _PyCFunction_FastCallDict(PyObject *func, PyObject **args, Py_ssize_t nargs, PyObject *kwargs); + +PyAPI_FUNC(PyObject *) _PyCFunction_FastCallKeywords(PyObject *func, + PyObject **stack, + Py_ssize_t nargs, + PyObject *kwnames); #endif struct PyMethodDef { -- cgit v1.2.1 From 14e79902895c8f92b5cf80483619fac1e3832425 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Fri, 9 Sep 2016 17:40:22 -0700 Subject: Add METH_FASTCALL calling convention Issue #27810: Add a new calling convention for C functions: PyObject* func(PyObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames); Where args is a C array of positional arguments followed by values of keyword arguments. nargs is the number of positional arguments, kwnames are keys of keyword arguments. kwnames can be NULL. --- Include/methodobject.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'Include/methodobject.h') diff --git a/Include/methodobject.h b/Include/methodobject.h index 1f4f06cff8..9dba58f2c5 100644 --- a/Include/methodobject.h +++ b/Include/methodobject.h @@ -16,6 +16,8 @@ PyAPI_DATA(PyTypeObject) PyCFunction_Type; #define PyCFunction_Check(op) (Py_TYPE(op) == &PyCFunction_Type) typedef PyObject *(*PyCFunction)(PyObject *, PyObject *); +typedef PyObject *(*_PyCFunctionFast) (PyObject *self, PyObject **args, + Py_ssize_t nargs, PyObject *kwnames); typedef PyObject *(*PyCFunctionWithKeywords)(PyObject *, PyObject *, PyObject *); typedef PyObject *(*PyNoArgsFunction)(PyObject *); @@ -83,6 +85,8 @@ PyAPI_FUNC(PyObject *) PyCFunction_NewEx(PyMethodDef *, PyObject *, #define METH_COEXIST 0x0040 +#define METH_FASTCALL 0x0080 + #ifndef Py_LIMITED_API typedef struct { PyObject_HEAD -- cgit v1.2.1 From bfe9bfdefae31d0e71c011dc5d7410660d4ab378 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 12 Sep 2016 15:55:21 +0200 Subject: Issue #27810: Exclude METH_FASTCALL from the stable API --- Include/methodobject.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Include/methodobject.h') diff --git a/Include/methodobject.h b/Include/methodobject.h index 9dba58f2c5..79fad8235c 100644 --- a/Include/methodobject.h +++ b/Include/methodobject.h @@ -85,9 +85,9 @@ PyAPI_FUNC(PyObject *) PyCFunction_NewEx(PyMethodDef *, PyObject *, #define METH_COEXIST 0x0040 +#ifndef Py_LIMITED_API #define METH_FASTCALL 0x0080 -#ifndef Py_LIMITED_API typedef struct { PyObject_HEAD PyMethodDef *m_ml; /* Description of the C function to call */ -- cgit v1.2.1