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 a0458fd
Show file tree
Hide file tree
Showing 31 changed files with 87 additions and 87 deletions.
2 changes: 1 addition & 1 deletion docs/examples/mixed-example/mixed.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

/* a HPy style function */
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
2 changes: 1 addition & 1 deletion docs/examples/snippets/hpyvarargs.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ static HPy myabs_impl(HPyContext *ctx, HPy self, HPy arg)

// BEGIN: add_ints
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
4 changes: 2 additions & 2 deletions docs/examples/snippets/snippets.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ int is_same_object(HPyContext *ctx, HPy x, HPy y)
// dummy entry point so that we can test the snippets:
HPyDef_METH(test_foo_and_is_same_object, "test_foo_and_is_same_object", HPyFunc_VARARGS)
static HPy test_foo_and_is_same_object_impl(HPyContext *ctx, HPy self,
HPy *args, HPy_ssize_t nargs)
const HPy *args, size_t nargs)
{
foo(ctx); // not much we can test here
return HPyLong_FromLong(ctx, is_same_object(ctx, args[0], args[1]));
Expand All @@ -52,7 +52,7 @@ static HPy test_leak_stacktrace_impl(HPyContext *ctx, HPy self)

// BEGIN: add
HPyDef_METH(add, "add", HPyFunc_VARARGS)
static HPy add_impl(HPyContext *ctx, HPy self, HPy *args, HPy_ssize_t nargs)
static HPy add_impl(HPyContext *ctx, HPy self, const HPy *args, size_t nargs)
{
if (nargs != 2) {
HPyErr_SetString(ctx, ctx->h_TypeError, "expected exactly two args");
Expand Down
2 changes: 1 addition & 1 deletion docs/porting-example/steps/step_03_hpy_final.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ HPy Point_norm_impl(HPyContext *ctx, HPy self)

// this is an HPy function that uses Point
HPyDef_METH(dot, "dot", HPyFunc_VARARGS, .doc="Dot product.")
HPy dot_impl(HPyContext *ctx, HPy self, HPy *args, HPy_ssize_t nargs)
HPy dot_impl(HPyContext *ctx, HPy self, const HPy *args, size_t nargs)
{
HPy point1, point2;
if (!HPyArg_Parse(ctx, NULL, args, nargs, "OO", &point1, &point2))
Expand Down
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
Loading

0 comments on commit a0458fd

Please sign in to comment.