From f2b6d100d8958a9c811c950f113a0ce38a25d484 Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Tue, 6 Dec 2016 22:06:26 +0200 Subject: Add min_required and max_expected arg counts to API. --- gawkapi.h | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'gawkapi.h') diff --git a/gawkapi.h b/gawkapi.h index 1c884741..af362bd2 100644 --- a/gawkapi.h +++ b/gawkapi.h @@ -376,15 +376,22 @@ typedef struct awk_flat_array { * Each extension function may decide what to do if the number of * arguments isn't what it expected. Following awk functions, it * is likely OK to ignore extra arguments. - - * Note that the 'max_expected_args' value should be used by the - * extension function itself only to trigger a lint warning if more - * arguments are passed to the function. + * + * 'min_required_args' indicates how many arguments MUST be passed. + * The API will throw a fatal error if not enough are passed. + * + * 'max_expected_args' is more benign; if more than that are passed, + * the API prints a lint message (IFF lint is enabled, of course). + * + * In any case, the extension function itself need not compare the + * actual number of arguments passed to those two values if it does + * not want to. */ typedef struct awk_ext_func { const char *name; awk_value_t *(*function)(int num_actual_args, awk_value_t *result); - size_t max_expected_args; + unsigned short min_required_args; + unsigned short max_expected_args; } awk_ext_func_t; typedef void *awk_ext_id_t; /* opaque type for extension id */ -- cgit v1.2.3 From 539de0a854fb94fd6ba47e91cee55f22fcd851a3 Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Mon, 12 Dec 2016 21:54:57 +0200 Subject: Improve handling of min and max args for extension functions. --- gawkapi.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'gawkapi.h') diff --git a/gawkapi.h b/gawkapi.h index af362bd2..d1ad9a2c 100644 --- a/gawkapi.h +++ b/gawkapi.h @@ -390,8 +390,8 @@ typedef struct awk_flat_array { typedef struct awk_ext_func { const char *name; awk_value_t *(*function)(int num_actual_args, awk_value_t *result); - unsigned short min_required_args; - unsigned short max_expected_args; + size_t max_expected_args; + size_t min_required_args; } awk_ext_func_t; typedef void *awk_ext_id_t; /* opaque type for extension id */ -- cgit v1.2.3 From 0855ef4db6d8e0d1d57776eb273c9de321bfd6cf Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Wed, 14 Dec 2016 21:25:20 +0200 Subject: Fix lint stuff, arg checking. Add a data pointer. Pass finfo to functions. --- gawkapi.h | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'gawkapi.h') diff --git a/gawkapi.h b/gawkapi.h index d1ad9a2c..8998d07f 100644 --- a/gawkapi.h +++ b/gawkapi.h @@ -260,8 +260,8 @@ typedef struct awk_two_way_processor { awk_const struct awk_two_way_processor *awk_const next; /* for use by gawk */ } awk_two_way_processor_t; -#define gawk_api_major_version 1 -#define gawk_api_minor_version 2 +#define gawk_api_major_version 2 +#define gawk_api_minor_version 0 /* Current version of the API. */ enum { @@ -389,9 +389,13 @@ typedef struct awk_flat_array { */ typedef struct awk_ext_func { const char *name; - awk_value_t *(*function)(int num_actual_args, awk_value_t *result); - size_t max_expected_args; - size_t min_required_args; + awk_value_t *(*const function)(int num_actual_args, + awk_value_t *result, + struct awk_ext_func *finfo); + const size_t min_required_args; + const size_t max_expected_args; + awk_bool_t suppress_lint; + void *data; /* opaque pointer to any extra state */ } awk_ext_func_t; typedef void *awk_ext_id_t; /* opaque type for extension id */ @@ -426,7 +430,7 @@ typedef struct gawk_api { /* Add a function to the interpreter, returns true upon success */ awk_bool_t (*api_add_ext_func)(awk_ext_id_t id, const char *namespace, - const awk_ext_func_t *func); + awk_ext_func_t *func); /* Register an input parser; for opening files read-only */ void (*api_register_input_parser)(awk_ext_id_t id, -- cgit v1.2.3 From 570758ee453fb42451f52a451e75d0a51c732cde Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Fri, 16 Dec 2016 14:02:26 +0200 Subject: Further improvements to min/max args code and doc. --- gawkapi.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gawkapi.h') diff --git a/gawkapi.h b/gawkapi.h index 8998d07f..337fef8a 100644 --- a/gawkapi.h +++ b/gawkapi.h @@ -392,8 +392,8 @@ typedef struct awk_ext_func { awk_value_t *(*const function)(int num_actual_args, awk_value_t *result, struct awk_ext_func *finfo); - const size_t min_required_args; const size_t max_expected_args; + const size_t min_required_args; awk_bool_t suppress_lint; void *data; /* opaque pointer to any extra state */ } awk_ext_func_t; -- cgit v1.2.3 From b76409d4d7fe75c018a80c685668cb65769a613c Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Sat, 17 Dec 2016 20:43:40 +0200 Subject: Further api doc updates. Simplify lint checking for max args. --- gawkapi.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'gawkapi.h') diff --git a/gawkapi.h b/gawkapi.h index 337fef8a..aae3ac0a 100644 --- a/gawkapi.h +++ b/gawkapi.h @@ -428,7 +428,12 @@ typedef struct gawk_api { /* Next, registration functions: */ - /* Add a function to the interpreter, returns true upon success */ + /* + * Add a function to the interpreter, returns true upon success. + * Gawk does not modify what func points to, but the extension + * function itself receives this pointer and can modify what it + * points to, thus it's not const. + */ awk_bool_t (*api_add_ext_func)(awk_ext_id_t id, const char *namespace, awk_ext_func_t *func); -- cgit v1.2.3