| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 559bb6a commit b900939
5 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -59,7 +59,7 @@ PyAPI_FUNC(PyObject *) PyFunction_GetAnnotations(PyObject *); | |||
| 59 | 59 | PyAPI_FUNC(int) PyFunction_SetAnnotations(PyObject *, PyObject *); | |
| 60 | 60 | ||
| 61 | 61 | #ifndef Py_LIMITED_API | |
| 62 | - PyAPI_FUNC(PyObject *) _PyFunction_FastCall( | ||
| 62 | + PyAPI_FUNC(PyObject *) _PyFunction_FastCallDict( | ||
| 63 | 63 | PyObject *func, | |
| 64 | 64 | PyObject **args, int nargs, | |
| 65 | 65 | PyObject *kwargs); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -38,7 +38,7 @@ PyAPI_FUNC(int) PyCFunction_GetFlags(PyObject *); | |||
| 38 | 38 | PyAPI_FUNC(PyObject *) PyCFunction_Call(PyObject *, PyObject *, PyObject *); | |
| 39 | 39 | ||
| 40 | 40 | #ifndef Py_LIMITED_API | |
| 41 | - PyAPI_FUNC(PyObject *) _PyCFunction_FastCall(PyObject *func, | ||
| 41 | + PyAPI_FUNC(PyObject *) _PyCFunction_FastCallDict(PyObject *func, | ||
| 42 | 42 | PyObject **args, int nargs, | |
| 43 | 43 | PyObject *kwargs); | |
| 44 | 44 | #endif | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2255,7 +2255,8 @@ _PyStack_AsTuple(PyObject **stack, Py_ssize_t nargs) | |||
| 2255 | 2255 | } | |
| 2256 | 2256 | ||
| 2257 | 2257 | PyObject * | |
| 2258 | - _PyObject_FastCallDict(PyObject *func, PyObject **args, int nargs, PyObject *kwargs) | ||
| 2258 | + _PyObject_FastCallDict(PyObject *func, PyObject **args, int nargs, | ||
| 2259 | + PyObject *kwargs) | ||
| 2259 | 2260 | { | |
| 2260 | 2261 | ternaryfunc call; | |
| 2261 | 2262 | PyObject *result = NULL; | |
@@ -2268,19 +2269,17 @@ _PyObject_FastCallDict(PyObject *func, PyObject **args, int nargs, PyObject *kwa | |||
| 2268 | 2269 | assert(func != NULL); | |
| 2269 | 2270 | assert(nargs >= 0); | |
| 2270 | 2271 | assert(nargs == 0 || args != NULL); | |
| 2271 | - /* issue #27128: support for keywords will come later: | ||
| 2272 | - _PyFunction_FastCall() doesn't support keyword arguments yet */ | ||
| 2273 | - assert(kwargs == NULL); | ||
| 2272 | + assert(kwargs == NULL || PyDict_Check(kwargs)); | ||
| 2274 | 2273 | ||
| 2275 | 2274 | if (Py_EnterRecursiveCall(" while calling a Python object")) { | |
| 2276 | 2275 | return NULL; | |
| 2277 | 2276 | } | |
| 2278 | 2277 | ||
| 2279 | 2278 | if (PyFunction_Check(func)) { | |
| 2280 | - result = _PyFunction_FastCall(func, args, nargs, kwargs); | ||
| 2279 | + result = _PyFunction_FastCallDict(func, args, nargs, kwargs); | ||
| 2281 | 2280 | } | |
| 2282 | 2281 | else if (PyCFunction_Check(func)) { | |
| 2283 | - result = _PyCFunction_FastCall(func, args, nargs, kwargs); | ||
| 2282 | + result = _PyCFunction_FastCallDict(func, args, nargs, kwargs); | ||
| 2284 | 2283 | } | |
| 2285 | 2284 | else { | |
| 2286 | 2285 | PyObject *tuple; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -146,16 +146,16 @@ PyCFunction_Call(PyObject *func, PyObject *args, PyObject *kwds) | |||
| 146 | 146 | } | |
| 147 | 147 | ||
| 148 | 148 | PyObject * | |
| 149 | - _PyCFunction_FastCall(PyObject *func_obj, PyObject **args, int nargs, | ||
| 150 | - PyObject *kwargs) | ||
| 149 | + _PyCFunction_FastCallDict(PyObject *func_obj, PyObject **args, int nargs, | ||
| 150 | + PyObject *kwargs) | ||
| 151 | 151 | { | |
| 152 | 152 | PyCFunctionObject* func = (PyCFunctionObject*)func_obj; | |
| 153 | 153 | PyCFunction meth = PyCFunction_GET_FUNCTION(func); | |
| 154 | 154 | PyObject *self = PyCFunction_GET_SELF(func); | |
| 155 | 155 | PyObject *result; | |
| 156 | 156 | int flags; | |
| 157 | 157 | ||
| 158 | - /* _PyCFunction_FastCall() must not be called with an exception set, | ||
| 158 | + /* _PyCFunction_FastCallDict() must not be called with an exception set, | ||
| 159 | 159 | because it may clear it (directly or indirectly) and so the | |
| 160 | 160 | caller loses its exception */ | |
| 161 | 161 | assert(!PyErr_Occurred()); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4889,24 +4889,29 @@ fast_function(PyObject *func, PyObject **stack, int n, int nargs, int nk) | |||
| 4889 | 4889 | } | |
| 4890 | 4890 | ||
| 4891 | 4891 | PyObject * | |
| 4892 | - _PyFunction_FastCall(PyObject *func, PyObject **args, int nargs, PyObject *kwargs) | ||
| 4892 | + _PyFunction_FastCallDict(PyObject *func, PyObject **args, int nargs, | ||
| 4893 | + PyObject *kwargs) | ||
| 4893 | 4894 | { | |
| 4894 | 4895 | PyCodeObject *co = (PyCodeObject *)PyFunction_GET_CODE(func); | |
| 4895 | 4896 | PyObject *globals = PyFunction_GET_GLOBALS(func); | |
| 4896 | 4897 | PyObject *argdefs = PyFunction_GET_DEFAULTS(func); | |
| 4897 | 4898 | PyObject *kwdefs, *closure, *name, *qualname; | |
| 4899 | + PyObject *kwtuple, **k; | ||
| 4898 | 4900 | PyObject **d; | |
| 4899 | 4901 | int nd; | |
| 4902 | + Py_ssize_t nk; | ||
| 4903 | + PyObject *result; | ||
| 4900 | 4904 | ||
| 4901 | 4905 | PCALL(PCALL_FUNCTION); | |
| 4902 | 4906 | PCALL(PCALL_FAST_FUNCTION); | |
| 4903 | 4907 | ||
| 4904 | - /* issue #27128: support for keywords will come later */ | ||
| 4905 | - assert(kwargs == NULL); | ||
| 4908 | + assert(kwargs == NULL || PyDict_Check(kwargs)); | ||
| 4906 | 4909 | ||
| 4907 | - if (co->co_kwonlyargcount == 0 && kwargs == NULL && | ||
| 4910 | + if (co->co_kwonlyargcount == 0 && | ||
| 4911 | + (kwargs == NULL || PyDict_Size(kwargs) == 0) && | ||
| 4908 | 4912 | co->co_flags == (CO_OPTIMIZED | CO_NEWLOCALS | CO_NOFREE)) | |
| 4909 | 4913 | { | |
| 4914 | + /* Fast paths */ | ||
| 4910 | 4915 | if (argdefs == NULL && co->co_argcount == nargs) { | |
| 4911 | 4916 | return _PyFunction_FastCallNoKw(co, args, nargs, globals); | |
| 4912 | 4917 | } | |
@@ -4920,6 +4925,30 @@ _PyFunction_FastCall(PyObject *func, PyObject **args, int nargs, PyObject *kwarg | |||
| 4920 | 4925 | } | |
| 4921 | 4926 | } | |
| 4922 | 4927 | ||
| 4928 | + if (kwargs != NULL) { | ||
| 4929 | + Py_ssize_t pos, i; | ||
| 4930 | + nk = PyDict_Size(kwargs); | ||
| 4931 | + | ||
| 4932 | + kwtuple = PyTuple_New(2 * nk); | ||
| 4933 | + if (kwtuple == NULL) { | ||
| 4934 | + return NULL; | ||
| 4935 | + } | ||
| 4936 | + | ||
| 4937 | + k = &PyTuple_GET_ITEM(kwtuple, 0); | ||
| 4938 | + pos = i = 0; | ||
| 4939 | + while (PyDict_Next(kwargs, &pos, &k[i], &k[i+1])) { | ||
| 4940 | + Py_INCREF(k[i]); | ||
| 4941 | + Py_INCREF(k[i+1]); | ||
| 4942 | + i += 2; | ||
| 4943 | + } | ||
| 4944 | + nk = i / 2; | ||
| 4945 | + } | ||
| 4946 | + else { | ||
| 4947 | + kwtuple = NULL; | ||
| 4948 | + k = NULL; | ||
| 4949 | + nk = 0; | ||
| 4950 | + } | ||
| 4951 | + | ||
| 4923 | 4952 | kwdefs = PyFunction_GET_KW_DEFAULTS(func); | |
| 4924 | 4953 | closure = PyFunction_GET_CLOSURE(func); | |
| 4925 | 4954 | name = ((PyFunctionObject *)func) -> func_name; | |
@@ -4933,11 +4962,14 @@ _PyFunction_FastCall(PyObject *func, PyObject **args, int nargs, PyObject *kwarg | |||
| 4933 | 4962 | d = NULL; | |
| 4934 | 4963 | nd = 0; | |
| 4935 | 4964 | } | |
| 4936 | - return _PyEval_EvalCodeWithName((PyObject*)co, globals, (PyObject *)NULL, | ||
| 4937 | - args, nargs, | ||
| 4938 | - NULL, 0, | ||
| 4939 | - d, nd, kwdefs, | ||
| 4940 | - closure, name, qualname); | ||
| 4965 | + | ||
| 4966 | + result = _PyEval_EvalCodeWithName((PyObject*)co, globals, (PyObject *)NULL, | ||
| 4967 | + args, nargs, | ||
| 4968 | + k, (int)nk, | ||
| 4969 | + d, nd, kwdefs, | ||
| 4970 | + closure, name, qualname); | ||
| 4971 | + Py_XDECREF(kwtuple); | ||
| 4972 | + return result; | ||
| 4941 | 4973 | } | |
| 4942 | 4974 | ||
| 4943 | 4975 | static PyObject * | |
| Back | FazBrowse Home | New Git URL |
0 commit comments