diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2016-08-19 14:11:43 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2016-08-19 14:11:43 (GMT) |
commit | 9be7e7b52fa4b48012e956167a344df691195a04 (patch) | |
tree | b556a431bb06664b814b206dee3790eb2ac00464 /Include | |
parent | fa46aa78996cbeb30ccbeb9c405a54459d5d55de (diff) | |
download | cpython-9be7e7b52fa4b48012e956167a344df691195a04.zip cpython-9be7e7b52fa4b48012e956167a344df691195a04.tar.gz cpython-9be7e7b52fa4b48012e956167a344df691195a04.tar.bz2 |
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
Diffstat (limited to 'Include')
-rw-r--r-- | Include/abstract.h | 18 | ||||
-rw-r--r-- | Include/funcobject.h | 7 | ||||
-rw-r--r-- | Include/methodobject.h | 6 |
3 files changed, 30 insertions, 1 deletions
diff --git a/Include/abstract.h b/Include/abstract.h index 4ff79f2..280402c 100644 --- a/Include/abstract.h +++ b/Include/abstract.h @@ -267,10 +267,26 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/ PyObject *args, PyObject *kw); #ifndef Py_LIMITED_API + PyAPI_FUNC(PyObject*) _PyStack_AsTuple(PyObject **stack, + Py_ssize_t nargs); + + /* Call the callable object func with the "fast call" calling convention: + args is a C array for positional parameters (nargs is the number of + positional paramater), kwargs is a dictionary for keyword parameters. + + If nargs is equal to zero, args can be NULL. kwargs can be NULL. + nargs must be greater or equal to zero. + + Return the result on success. Raise an exception on return NULL on + error. */ + PyAPI_FUNC(PyObject *) _PyObject_FastCall(PyObject *func, + PyObject **args, int nargs, + PyObject *kwargs); + PyAPI_FUNC(PyObject *) _Py_CheckFunctionResult(PyObject *func, PyObject *result, const char *where); -#endif +#endif /* Py_LIMITED_API */ /* Call a callable Python object, callable_object, with diff --git a/Include/funcobject.h b/Include/funcobject.h index cc1426c..908944d 100644 --- a/Include/funcobject.h +++ b/Include/funcobject.h @@ -58,6 +58,13 @@ PyAPI_FUNC(int) PyFunction_SetClosure(PyObject *, PyObject *); PyAPI_FUNC(PyObject *) PyFunction_GetAnnotations(PyObject *); PyAPI_FUNC(int) PyFunction_SetAnnotations(PyObject *, PyObject *); +#ifndef Py_LIMITED_API +PyAPI_FUNC(PyObject *) _PyFunction_FastCall( + PyObject *func, + PyObject **args, int nargs, + PyObject *kwargs); +#endif + /* Macros for direct access to these values. Type checks are *not* done, so use with care. */ #define PyFunction_GET_CODE(func) \ diff --git a/Include/methodobject.h b/Include/methodobject.h index e2ad804..8dec00a 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 */ |