Skip to content

Commit

Permalink
Align signature of HPyFunc_VARARGS to HPyFunc_KEYWORDS
Browse files Browse the repository at this point in the history
  • Loading branch information
fangerer committed Mar 22, 2023
1 parent a69ff3c commit b7feda8
Show file tree
Hide file tree
Showing 27 changed files with 82 additions and 82 deletions.
2 changes: 1 addition & 1 deletion hpy/debug/src/_debugmod.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ static UHPy get_open_handles_impl(HPyContext *uctx, UHPy u_self, UHPy u_gen)

HPyDef_METH(get_closed_handles, "get_closed_handles", HPyFunc_VARARGS,
.doc="Return a list of all the closed handle in the cache")
static UHPy get_closed_handles_impl(HPyContext *uctx, UHPy u_self, HPy *args, HPy_ssize_t nargs)
static UHPy get_closed_handles_impl(HPyContext *uctx, UHPy u_self, const HPy *args, size_t nargs)
{
HPyContext *dctx = hpy_debug_get_ctx(uctx);
if (dctx == NULL)
Expand Down
4 changes: 2 additions & 2 deletions hpy/devel/include/hpy/autogen_hpyfunc_declare.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion hpy/devel/include/hpy/cpython/hpyfunc_trampolines.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef HPY_CPYTHON_HPYFUNC_TRAMPOLINES_H
#define HPY_CPYTHON_HPYFUNC_TRAMPOLINES_H

typedef HPy (*_HPyCFunction_VARARGS)(HPyContext*, HPy, const HPy *, HPy_ssize_t);
typedef HPy (*_HPyCFunction_VARARGS)(HPyContext*, HPy, const HPy *, size_t);
#define _HPyFunc_TRAMPOLINE_HPyFunc_VARARGS(SYM, IMPL) \
static PyObject* \
SYM(PyObject *self, PyObject *const *args, Py_ssize_t nargs) \
Expand Down
2 changes: 1 addition & 1 deletion hpy/devel/include/hpy/runtime/argparse.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ extern "C" {

HPyAPI_HELPER int
HPyArg_Parse(HPyContext *ctx, HPyTracker *ht, const HPy *args,
HPy_ssize_t nargs, const char *fmt, ...);
size_t nargs, const char *fmt, ...);

HPyAPI_HELPER int
HPyArg_ParseKeywords(HPyContext *ctx, HPyTracker *ht, const HPy *args,
Expand Down
4 changes: 2 additions & 2 deletions hpy/devel/src/runtime/argparse.c
Original file line number Diff line number Diff line change
Expand Up @@ -463,14 +463,14 @@ parse_item(HPyContext *ctx, HPyTracker *ht, HPy current_arg, int current_arg_tmp
* future format string codes (e.g. for character strings).
*/
HPyAPI_HELPER int
HPyArg_Parse(HPyContext *ctx, HPyTracker *ht, const HPy *args, HPy_ssize_t nargs, const char *fmt, ...)
HPyArg_Parse(HPyContext *ctx, HPyTracker *ht, const HPy *args, size_t nargs, const char *fmt, ...)
{
const char *fmt1 = fmt;
const char *err_fmt = NULL;
const char *fmt_end = NULL;

int optional = 0;
HPy_ssize_t i = 0;
size_t i = 0;
HPy current_arg;

fmt_end = parse_err_fmt(fmt, &err_fmt);
Expand Down
2 changes: 1 addition & 1 deletion hpy/tools/autogen/public_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -1066,7 +1066,7 @@ int HPy_SetCallFunction(HPyContext *ctx, HPy h, HPyCallFunction *func);
*/
typedef HPy (*HPyFunc_noargs)(HPyContext *ctx, HPy self);
typedef HPy (*HPyFunc_o)(HPyContext *ctx, HPy self, HPy arg);
typedef HPy (*HPyFunc_varargs)(HPyContext *ctx, HPy self, HPy *args, HPy_ssize_t nargs);
typedef HPy (*HPyFunc_varargs)(HPyContext *ctx, HPy self, const HPy *args, size_t nargs);
typedef HPy (*HPyFunc_keywords)(HPyContext *ctx, HPy self, const HPy *args,
size_t nargs, HPy kwnames);

Expand Down
6 changes: 3 additions & 3 deletions microbench/src/hpy_simple.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ static HPy onearg_impl(HPyContext *ctx, HPy self, HPy arg)
}

HPyDef_METH(varargs, "varargs", HPyFunc_VARARGS)
static HPy varargs_impl(HPyContext *ctx, HPy self, HPy *args, HPy_ssize_t nargs)
static HPy varargs_impl(HPyContext *ctx, HPy self, const HPy *args, size_t nargs)
{
return HPy_Dup(ctx, ctx->h_None);
}

HPyDef_METH(call_with_tuple, "call_with_tuple", HPyFunc_VARARGS)
static HPy call_with_tuple_impl(HPyContext *ctx, HPy self, HPy *args, HPy_ssize_t nargs)
static HPy call_with_tuple_impl(HPyContext *ctx, HPy self, const HPy *args, size_t nargs)
{
HPy f, f_args;
if (nargs != 2) {
Expand All @@ -34,7 +34,7 @@ static HPy call_with_tuple_impl(HPyContext *ctx, HPy self, HPy *args, HPy_ssize_
}

HPyDef_METH(call_with_tuple_and_dict, "call_with_tuple_and_dict", HPyFunc_VARARGS)
static HPy call_with_tuple_and_dict_impl(HPyContext *ctx, HPy self, HPy *args, HPy_ssize_t nargs)
static HPy call_with_tuple_and_dict_impl(HPyContext *ctx, HPy self, const HPy *args, size_t nargs)
{
HPy f, f_args, f_kw;
if (nargs != 3) {
Expand Down
4 changes: 2 additions & 2 deletions proof-of-concept/pof.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ static HPy double_obj_impl(HPyContext *ctx, HPy self, HPy obj)
}

HPyDef_METH(add_ints, "add_ints", HPyFunc_VARARGS)
static HPy add_ints_impl(HPyContext *ctx, HPy self, HPy *args, HPy_ssize_t nargs)
static HPy add_ints_impl(HPyContext *ctx, HPy self, const HPy *args, size_t nargs)
{
long a, b;
if (!HPyArg_Parse(ctx, NULL, args, nargs, "ll", &a, &b))
Expand Down Expand Up @@ -106,4 +106,4 @@ static HPyModuleDef moduledef = {
.defines = module_defines
};

HPy_MODINIT(pof, moduledef)
HPy_MODINIT(pof, moduledef)
2 changes: 1 addition & 1 deletion proof-of-concept/pofcpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ static HPy double_obj_impl(HPyContext *ctx, HPy self, HPy obj)
}

HPyDef_METH(add_ints, "add_ints", HPyFunc_VARARGS)
static HPy add_ints_impl(HPyContext *ctx, HPy self, HPy *args, HPy_ssize_t nargs)
static HPy add_ints_impl(HPyContext *ctx, HPy self, const HPy *args, size_t nargs)
{
long a, b;
if (!HPyArg_Parse(ctx, NULL, args, nargs, "ll", &a, &b))
Expand Down
32 changes: 16 additions & 16 deletions test/debug/test_builder_invalid.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ def test_correct_usage(compiler, hpy_debug_capture):
# Basic sanity check that valid code does not trigger any error reports
mod = compiler.make_module("""
HPyDef_METH(build, "build", HPyFunc_VARARGS)
static HPy build_impl(HPyContext *ctx, HPy h_self, HPy *args, HPy_ssize_t nargs)
static HPy build_impl(HPyContext *ctx, HPy h_self, const HPy *args, size_t nargs)
{
HPyTupleBuilder tbuilder = HPyTupleBuilder_New(ctx, nargs);
HPyListBuilder lbuilder = HPyListBuilder_New(ctx, nargs);
for (int i=0; i < nargs; i++) {
for (size_t i=0; i < nargs; i++) {
HPyTupleBuilder_Set(ctx, tbuilder, i, args[i]);
HPyListBuilder_Set(ctx, lbuilder, i, args[i]);
}
Expand All @@ -28,11 +28,11 @@ def test_correct_usage(compiler, hpy_debug_capture):
}
HPyDef_METH(cancel, "cancel", HPyFunc_VARARGS)
static HPy cancel_impl(HPyContext *ctx, HPy h_self, HPy *args, HPy_ssize_t nargs)
static HPy cancel_impl(HPyContext *ctx, HPy h_self, const HPy *args, size_t nargs)
{
HPyTupleBuilder tbuilder = HPyTupleBuilder_New(ctx, nargs);
HPyListBuilder lbuilder = HPyListBuilder_New(ctx, nargs);
for (int i=0; i < nargs; i++) {
for (size_t i=0; i < nargs; i++) {
HPyTupleBuilder_Set(ctx, tbuilder, i, args[i]);
HPyListBuilder_Set(ctx, lbuilder, i, args[i]);
}
Expand All @@ -52,20 +52,20 @@ def test_correct_usage(compiler, hpy_debug_capture):
def test_build_twice(compiler, hpy_debug_capture):
mod = compiler.make_module("""
HPyDef_METH(f, "f", HPyFunc_VARARGS)
static HPy f_impl(HPyContext *ctx, HPy h_self, HPy *args, HPy_ssize_t nargs)
static HPy f_impl(HPyContext *ctx, HPy h_self, const HPy *args, size_t nargs)
{
HPyTupleBuilder builder = HPyTupleBuilder_New(ctx, nargs);
for (int i=0; i < nargs; i++)
for (size_t i=0; i < nargs; i++)
HPyTupleBuilder_Set(ctx, builder, i, args[i]);
HPy h_result = HPyTupleBuilder_Build(ctx, builder);
HPy_Close(ctx, h_result);
return HPyTupleBuilder_Build(ctx, builder);
}
HPyDef_METH(g, "g", HPyFunc_VARARGS)
static HPy g_impl(HPyContext *ctx, HPy h_self, HPy *args, HPy_ssize_t nargs)
static HPy g_impl(HPyContext *ctx, HPy h_self, const HPy *args, size_t nargs)
{
HPyListBuilder builder = HPyListBuilder_New(ctx, nargs);
for (int i=0; i < nargs; i++)
for (size_t i=0; i < nargs; i++)
HPyListBuilder_Set(ctx, builder, i, args[i]);
HPy h_result = HPyListBuilder_Build(ctx, builder);
HPy_Close(ctx, h_result);
Expand All @@ -86,19 +86,19 @@ def test_build_twice(compiler, hpy_debug_capture):
def test_build_after_cancel(compiler, hpy_debug_capture):
mod = compiler.make_module("""
HPyDef_METH(f, "f", HPyFunc_VARARGS)
static HPy f_impl(HPyContext *ctx, HPy h_self, HPy *args, HPy_ssize_t nargs)
static HPy f_impl(HPyContext *ctx, HPy h_self, const HPy *args, size_t nargs)
{
HPyTupleBuilder builder = HPyTupleBuilder_New(ctx, nargs);
for (int i=0; i < nargs; i++)
for (size_t i=0; i < nargs; i++)
HPyTupleBuilder_Set(ctx, builder, i, args[i]);
HPyTupleBuilder_Cancel(ctx, builder);
return HPyTupleBuilder_Build(ctx, builder);
}
HPyDef_METH(g, "g", HPyFunc_VARARGS)
static HPy g_impl(HPyContext *ctx, HPy h_self, HPy *args, HPy_ssize_t nargs)
static HPy g_impl(HPyContext *ctx, HPy h_self, const HPy *args, size_t nargs)
{
HPyListBuilder builder = HPyListBuilder_New(ctx, nargs);
for (int i=0; i < nargs; i++)
for (size_t i=0; i < nargs; i++)
HPyListBuilder_Set(ctx, builder, i, args[i]);
HPyListBuilder_Cancel(ctx, builder);
return HPyListBuilder_Build(ctx, builder);
Expand All @@ -118,21 +118,21 @@ def test_build_after_cancel(compiler, hpy_debug_capture):
def test_build_cancel_after_build(compiler, hpy_debug_capture):
mod = compiler.make_module("""
HPyDef_METH(f, "f", HPyFunc_VARARGS)
static HPy f_impl(HPyContext *ctx, HPy h_self, HPy *args, HPy_ssize_t nargs)
static HPy f_impl(HPyContext *ctx, HPy h_self, const HPy *args, size_t nargs)
{
HPyTupleBuilder builder = HPyTupleBuilder_New(ctx, nargs);
for (int i=0; i < nargs; i++)
for (size_t i=0; i < nargs; i++)
HPyTupleBuilder_Set(ctx, builder, i, args[i]);
HPy h_result = HPyTupleBuilder_Build(ctx, builder);
HPyTupleBuilder_Cancel(ctx, builder);
HPy_Close(ctx, h_result);
return HPy_Dup(ctx, ctx->h_None);
}
HPyDef_METH(g, "g", HPyFunc_VARARGS)
static HPy g_impl(HPyContext *ctx, HPy h_self, HPy *args, HPy_ssize_t nargs)
static HPy g_impl(HPyContext *ctx, HPy h_self, const HPy *args, size_t nargs)
{
HPyListBuilder builder = HPyListBuilder_New(ctx, nargs);
for (int i=0; i < nargs; i++)
for (size_t i=0; i < nargs; i++)
HPyListBuilder_Set(ctx, builder, i, args[i]);
HPy h_result = HPyListBuilder_Build(ctx, builder);
HPyListBuilder_Cancel(ctx, builder);
Expand Down
6 changes: 3 additions & 3 deletions test/debug/test_charptr.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def test_charptr_use_after_implicit_arg_handle_close(compiler, python_subprocess
const char *keep;
HPyDef_METH(f, "f", HPyFunc_VARARGS)
static HPy f_impl(HPyContext *ctx, HPy self, HPy *args, HPy_ssize_t n)
static HPy f_impl(HPyContext *ctx, HPy self, const HPy *args, size_t n)
{
if (n != 2) {
HPyErr_SetString(ctx, ctx->h_ValueError, "expected exactly two arguments");
Expand Down Expand Up @@ -74,7 +74,7 @@ def test_charptr_use_after_implicit_arg_handle_close(compiler, python_subprocess
def test_charptr_use_after_handle_close(compiler, python_subprocess):
mod = compiler.compile_module("""
HPyDef_METH(f, "f", HPyFunc_VARARGS)
static HPy f_impl(HPyContext *ctx, HPy self, HPy *args, HPy_ssize_t n)
static HPy f_impl(HPyContext *ctx, HPy self, const HPy *args, size_t n)
{
if (n != 2) {
HPyErr_SetString(ctx, ctx->h_ValueError, "expected exactly two arguments");
Expand Down Expand Up @@ -127,7 +127,7 @@ def test_charptr_use_after_handle_close(compiler, python_subprocess):
def test_charptr_write_ptr(compiler, python_subprocess):
mod = compiler.compile_module("""
HPyDef_METH(f, "f", HPyFunc_VARARGS)
static HPy f_impl(HPyContext *ctx, HPy self, HPy *args, HPy_ssize_t n)
static HPy f_impl(HPyContext *ctx, HPy self, const HPy *args, size_t n)
{
if (n != 2) {
HPyErr_SetString(ctx, ctx->h_ValueError, "expected exactly two arguments");
Expand Down
2 changes: 1 addition & 1 deletion test/debug/test_handles_invalid.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def test_cant_use_closed_handle(compiler, hpy_debug_capture):
}
HPyDef_METH(f_varargs, "f_varargs", HPyFunc_VARARGS, .doc="returns arg w/o dupping it")
static HPy f_varargs_impl(HPyContext *ctx, HPy self, HPy *args, HPy_ssize_t nargs)
static HPy f_varargs_impl(HPyContext *ctx, HPy self, const HPy *args, size_t nargs)
{
// should be: return HPy_Dup(ctx, args[0]);
return args[0];
Expand Down
8 changes: 4 additions & 4 deletions test/debug/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def test_use_invalid_as_struct(compiler, python_subprocess):
def test_typecheck(compiler, python_subprocess):
mod = compiler.compile_module("""
HPyDef_METH(f, "f", HPyFunc_VARARGS)
static HPy f_impl(HPyContext *ctx, HPy self, HPy *args, HPy_ssize_t nargs)
static HPy f_impl(HPyContext *ctx, HPy self, const HPy *args, size_t nargs)
{
if (nargs != 2) {
HPyErr_SetString(ctx, ctx->h_TypeError, "expected exactly 2 arguments");
Expand All @@ -68,7 +68,7 @@ def test_type_getname(compiler, python_subprocess):
#define MODE_READ_ONLY 0
#define MODE_USE_AFTER_FREE 1
HPyDef_METH(f, "f", HPyFunc_VARARGS)
static HPy f_impl(HPyContext *ctx, HPy self, HPy *args, HPy_ssize_t nargs)
static HPy f_impl(HPyContext *ctx, HPy self, const HPy *args, size_t nargs)
{
HPy type;
int mode;
Expand Down Expand Up @@ -123,7 +123,7 @@ def test_type_getname(compiler, python_subprocess):
def test_type_issubtype(compiler, python_subprocess):
mod = compiler.compile_module("""
HPyDef_METH(f, "f", HPyFunc_VARARGS)
static HPy f_impl(HPyContext *ctx, HPy self, HPy *args, HPy_ssize_t nargs)
static HPy f_impl(HPyContext *ctx, HPy self, const HPy *args, size_t nargs)
{
if (nargs != 2) {
HPyErr_SetString(ctx, ctx->h_TypeError, "expected exactly 2 arguments");
Expand All @@ -147,7 +147,7 @@ def test_type_issubtype(compiler, python_subprocess):
def test_unicode_substring(compiler, python_subprocess):
mod = compiler.compile_module("""
HPyDef_METH(f, "f", HPyFunc_VARARGS)
static HPy f_impl(HPyContext *ctx, HPy self, HPy *args, HPy_ssize_t nargs)
static HPy f_impl(HPyContext *ctx, HPy self, const HPy *args, size_t nargs)
{
HPy_ssize_t start, end;
if (nargs != 3) {
Expand Down
4 changes: 2 additions & 2 deletions test/test_00_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ def test_exception(self):
def test_varargs(self):
mod = self.make_module("""
HPyDef_METH(f, "f", HPyFunc_VARARGS)
static HPy f_impl(HPyContext *ctx, HPy self, HPy *args, HPy_ssize_t nargs)
static HPy f_impl(HPyContext *ctx, HPy self, const HPy *args, size_t nargs)
{
long a, b;
if (!HPyArg_Parse(ctx, NULL, args, nargs, "ll", &a, &b))
Expand Down Expand Up @@ -316,7 +316,7 @@ def test_extern_def(self):
return HPy_Dup(ctx, arg);
}
HPyDef_METH(h, "h", HPyFunc_VARARGS)
static HPy h_impl(HPyContext *ctx, HPy self, HPy *args, HPy_ssize_t nargs)
static HPy h_impl(HPyContext *ctx, HPy self, const HPy *args, size_t nargs)
{
long a, b;
if (!HPyArg_Parse(ctx, NULL, args, nargs, "ll", &a, &b))
Expand Down
10 changes: 5 additions & 5 deletions test/test_argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def make_parse_item(self, fmt, type, hpy_converter):
HPyDef_METH(f, "f", HPyFunc_VARARGS)
static HPy f_impl(HPyContext *ctx, HPy self,
HPy *args, HPy_ssize_t nargs)
const HPy *args, size_t nargs)
{{
{type} a;
if (!HPyArg_Parse(ctx, NULL, args, nargs, "{fmt}", &a))
Expand Down Expand Up @@ -300,7 +300,7 @@ def make_two_arg_add(self, fmt="OO"):
mod = self.make_module("""
HPyDef_METH(f, "f", HPyFunc_VARARGS)
static HPy f_impl(HPyContext *ctx, HPy self,
HPy *args, HPy_ssize_t nargs)
const HPy *args, size_t nargs)
{{
HPy a;
HPy b = HPy_NULL;
Expand All @@ -325,7 +325,7 @@ def test_many_int_arguments(self):
mod = self.make_module("""
HPyDef_METH(f, "f", HPyFunc_VARARGS)
static HPy f_impl(HPyContext *ctx, HPy self,
HPy *args, HPy_ssize_t nargs)
const HPy *args, size_t nargs)
{
long a, b, c, d, e;
if (!HPyArg_Parse(ctx, NULL, args, nargs, "lllll",
Expand All @@ -343,7 +343,7 @@ def test_many_handle_arguments(self):
mod = self.make_module("""
HPyDef_METH(f, "f", HPyFunc_VARARGS)
static HPy f_impl(HPyContext *ctx, HPy self,
HPy *args, HPy_ssize_t nargs)
const HPy *args, size_t nargs)
{
HPy a, b;
if (!HPyArg_Parse(ctx, NULL, args, nargs, "OO", &a, &b))
Expand All @@ -359,7 +359,7 @@ def test_supplying_hpy_tracker(self):
mod = self.make_module("""
HPyDef_METH(f, "f", HPyFunc_VARARGS)
static HPy f_impl(HPyContext *ctx, HPy self,
HPy *args, HPy_ssize_t nargs)
const HPy *args, size_t nargs)
{
HPy a, b, result;
HPyTracker ht;
Expand Down
Loading

0 comments on commit b7feda8

Please sign in to comment.