From 103777449fc8348c6f171dcf2fcad1f462e84da4 Mon Sep 17 00:00:00 2001 From: Florian Angerer Date: Mon, 3 Apr 2023 16:14:12 +0200 Subject: [PATCH] Use _PyObject_Vectorcall on Python 3.8 --- hpy/devel/include/hpy/cpython/misc.h | 8 ++++++++ hpy/devel/src/runtime/ctx_call.c | 15 +++++++++------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/hpy/devel/include/hpy/cpython/misc.h b/hpy/devel/include/hpy/cpython/misc.h index 632af72fa..3d46b9d3d 100644 --- a/hpy/devel/include/hpy/cpython/misc.h +++ b/hpy/devel/include/hpy/cpython/misc.h @@ -276,6 +276,10 @@ HPyAPI_FUNC HPy HPy_CallTupleDict(HPyContext *ctx, HPy callable, HPy args, HPy k return ctx_CallTupleDict(ctx, callable, args, kw); } +#if PY_VERSION_HEX < 0x03090000 +#define PyObject_Vectorcall _PyObject_Vectorcall +#endif + HPyAPI_FUNC HPy HPy_Call(HPyContext *ctx, HPy callable, const HPy *args, size_t nargs, HPy kwnames) { if (sizeof(HPy) == sizeof(PyObject *)) { @@ -284,6 +288,10 @@ HPyAPI_FUNC HPy HPy_Call(HPyContext *ctx, HPy callable, const HPy *args, size_t return ctx_Call(ctx, callable, args, nargs, kwnames); } +#if PY_VERSION_HEX < 0x03090000 +#undef PyObject_Vectorcall +#endif + HPyAPI_FUNC HPy HPy_CallMethod(HPyContext *ctx, HPy name, const HPy *args, size_t nargs, HPy kwnames) { #if PY_VERSION_HEX >= 0x03090000 diff --git a/hpy/devel/src/runtime/ctx_call.c b/hpy/devel/src/runtime/ctx_call.c index 5be097a03..2e929f5fd 100644 --- a/hpy/devel/src/runtime/ctx_call.c +++ b/hpy/devel/src/runtime/ctx_call.c @@ -40,10 +40,14 @@ ctx_CallTupleDict(HPyContext *ctx, HPy callable, HPy args, HPy kw) return _py2h(obj); } +#if PY_VERSION_HEX < 0x03090000 +#define PyObject_Vectorcall _PyObject_Vectorcall +#endif + _HPy_HIDDEN HPy ctx_Call(HPyContext *ctx, HPy h_callable, const HPy *h_args, size_t nargs, HPy h_kwnames) { - PyObject *result, *kwnames; + PyObject *kwnames; size_t n_all_args; if (HPy_IsNull(h_kwnames)) { @@ -62,13 +66,12 @@ ctx_Call(HPyContext *ctx, HPy h_callable, const HPy *h_args, size_t nargs, HPy h args[i] = _h2py(h_args[i]); } + return _py2h(PyObject_Vectorcall(_h2py(h_callable), args, nargs, kwnames)); +} + #if PY_VERSION_HEX < 0x03090000 - result = _PyObject_Vectorcall(_h2py(callable), args, nargs, kwnames); -#else - result = PyObject_Vectorcall(_h2py(h_callable), args, nargs, kwnames); +#undef PyObject_Vectorcall #endif - return _py2h(result); -} _HPy_HIDDEN HPy ctx_CallMethod(HPyContext *ctx, HPy h_name, const HPy *h_args, size_t nargs, HPy h_kwnames)