Skip to content

Commit

Permalink
Use _PyObject_Vectorcall on Python 3.8
Browse files Browse the repository at this point in the history
  • Loading branch information
fangerer committed Apr 3, 2023
1 parent 6588d87 commit 1037774
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
8 changes: 8 additions & 0 deletions hpy/devel/include/hpy/cpython/misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 *)) {
Expand All @@ -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
Expand Down
15 changes: 9 additions & 6 deletions hpy/devel/src/runtime/ctx_call.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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)
Expand Down

0 comments on commit 1037774

Please sign in to comment.