diff options
author | Arnold D. Robbins <arnold@skeeve.com> | 2016-12-14 21:25:20 +0200 |
---|---|---|
committer | Arnold D. Robbins <arnold@skeeve.com> | 2016-12-14 21:25:20 +0200 |
commit | 0855ef4db6d8e0d1d57776eb273c9de321bfd6cf (patch) | |
tree | 360dc72f0eecdeed3cb15154c55f767fa0508caa | |
parent | 539de0a854fb94fd6ba47e91cee55f22fcd851a3 (diff) | |
download | egawk-0855ef4db6d8e0d1d57776eb273c9de321bfd6cf.tar.gz egawk-0855ef4db6d8e0d1d57776eb273c9de321bfd6cf.tar.bz2 egawk-0855ef4db6d8e0d1d57776eb273c9de321bfd6cf.zip |
Fix lint stuff, arg checking. Add a data pointer. Pass finfo to functions.
-rw-r--r-- | ChangeLog | 14 | ||||
-rw-r--r-- | NEWS | 6 | ||||
-rw-r--r-- | awk.h | 4 | ||||
-rw-r--r-- | doc/ChangeLog | 4 | ||||
-rw-r--r-- | doc/gawk.info | 310 | ||||
-rw-r--r-- | doc/gawk.texi | 49 | ||||
-rw-r--r-- | doc/gawktexi.in | 49 | ||||
-rw-r--r-- | extension/ChangeLog | 17 | ||||
-rw-r--r-- | extension/filefuncs.c | 18 | ||||
-rw-r--r-- | extension/fnmatch.c | 4 | ||||
-rw-r--r-- | extension/fork.c | 12 | ||||
-rw-r--r-- | extension/inplace.c | 8 | ||||
-rw-r--r-- | extension/ordchr.c | 8 | ||||
-rw-r--r-- | extension/readdir.c | 2 | ||||
-rw-r--r-- | extension/readfile.c | 4 | ||||
-rw-r--r-- | extension/revoutput.c | 2 | ||||
-rw-r--r-- | extension/revtwoway.c | 2 | ||||
-rw-r--r-- | extension/rwarray.c | 8 | ||||
-rw-r--r-- | extension/rwarray0.c | 8 | ||||
-rw-r--r-- | extension/testext.c | 56 | ||||
-rw-r--r-- | extension/time.c | 8 | ||||
-rw-r--r-- | gawkapi.c | 2 | ||||
-rw-r--r-- | gawkapi.h | 16 | ||||
-rw-r--r-- | interpret.h | 8 |
24 files changed, 367 insertions, 252 deletions
@@ -1,3 +1,17 @@ +2016-12-14 Arnold D. Robbins <arnold@skeeve.com> + + MAJOR BREAKING API CHANGE. + + * awk.h (INSTRUCTION): Update extension function pointer to + take 3rd argument of pointer to struct awk_ext_func. + * gawkapi.c (api_add_ext_func): Update third arg to not be const. + * gawkapi.h (awk_ext_func_t): Put min before max. Add suppress_lint + and data pointer. + [gawk_api_major_version]: Update to 2. + [gawk_api_minor_version]: Reset to 0. + (api_add_ext_func): Update third arg to not be const. + * interpret.h (Op_ext_symbol): Revise lint check. + 2016-12-12 Arnold D. Robbins <arnold@skeeve.com> * awk.h (INSTRUCTION): Replace min_required and max_expected @@ -90,6 +90,12 @@ Changes from 4.1.x to 4.2.0 22. Passing negative operands to any of the bitwise functions now produces a fatal error. +23. The C API has undergone changes that break both binary and source + code compatibility with the previous version. Thus the API version + is now at 2.0. YOU WILL NEED TO REVISE YOUR EXTENSIONS to work + with this version of gawk. Fortunately, the changes are fairly + minor and straightforward. + Changes from 4.1.3 to 4.1.4 --------------------------- @@ -767,7 +767,9 @@ typedef struct exp_instruction { NODE *dn; struct exp_instruction *di; NODE *(*fptr)(int); - awk_value_t *(*efptr)(int, awk_value_t *); + awk_value_t *(*efptr)(int num_actual_args, + awk_value_t *result, + struct awk_ext_func *finfo); long dl; char *name; } d; diff --git a/doc/ChangeLog b/doc/ChangeLog index c948bcda..61c4f942 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,3 +1,7 @@ +2016-12-14 Arnold D. Robbins <arnold@skeeve.com> + + * gawktexi.in: Update description of awk_ext_func_t structure. + 2016-11-21 Arnold D. Robbins <arnold@skeeve.com> * gawktexi.in: Finish off discussion of strongly typed regexp diff --git a/doc/gawk.info b/doc/gawk.info index 3bb2f352..c197aa14 100644 --- a/doc/gawk.info +++ b/doc/gawk.info @@ -23859,8 +23859,13 @@ Extension functions are described by the following record: 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; + 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; The fields are: @@ -23874,7 +23879,7 @@ Extension functions are described by the following record: which may be followed by any number of letters, digits, and underscores. Letter case in function names is significant. -'awk_value_t *(*function)(int num_actual_args, awk_value_t *result);' +'awk_value_t *(*const function)(int num_actual_args, awk_value_t *result, struct awk_ext_func *finfo);' This is a pointer to the C function that provides the extension's functionality. The function must fill in '*result' with either a number or a string. 'gawk' takes ownership of any string memory. @@ -23884,20 +23889,39 @@ Extension functions are described by the following record: The 'num_actual_args' argument tells the C function how many actual parameters were passed from the calling 'awk' code. + The 'finfo' parameter is a pointer to the 'awk_ext_func_t' for this + function. The called function may access data within it as + desired, or not. + The function must return the value of 'result'. This is for the convenience of the calling code inside 'gawk'. -'size_t max_expected_args;' - This is the maximum number of arguments the function expects to - receive. Each extension function may decide what to do if the - number of arguments isn't what it expected. As with real 'awk' - functions, it is likely OK to ignore extra arguments. This value - does not affect actual program execution. +'const size_t min_required_args;' + This is the minimum number of arguments the function expects to + receive. If called with fewer arguments, 'gawk' prints a fatal + error message and exits. - Extension functions should compare this value to the number of - actual arguments passed and possibly issue a lint warning if there - is an undesirable mismatch. Of course, if '--lint=fatal' is used, - this would cause the program to exit. +'const size_t max_expected_args;' + This is the maximum number of arguments the function expects to + receive. If called with more arguments than this, and if lint + checking has been enabled, then 'gawk' prints a warning message. + For more information, see the next item in this list. + +'awk_bool_t suppress_lint;' + This flag tells 'gawk' not to print a lint message if lint checking + has been enabled and if more arguments were supplied in the call + than expected. An extension function can tell if 'gawk' already + printed at least one such message by checking if 'num_actual_args > + finfo->max_expected_args'. If so, and the function does not want + more lint messages to be printed, it should set + 'finfo->suppress_lint' to 'awk_true'. + +'void *data;' + This is an opaque pointer to any data that an extension function + may wish to have available when called. Passing the + 'awk_ext_funct_t' structure to the extension function, and having + this pointer available in it enables writing a single C or C++ + function that implements multiple 'awk'-level extension functions. Once you have a record representing your extension function, you register it with 'gawk' using this API function: @@ -35758,135 +35782,135 @@ Ref: Memory Allocation Functions-Footnote-1966474 Node: Constructor Functions966573 Node: Registration Functions968318 Node: Extension Functions969003 -Node: Exit Callback Functions971626 -Node: Extension Version String972876 -Node: Input Parsers973539 -Node: Output Wrappers983421 -Node: Two-way processors987933 -Node: Printing Messages990198 -Ref: Printing Messages-Footnote-1991369 -Node: Updating ERRNO991522 -Node: Requesting Values992261 -Ref: table-value-types-returned992998 -Node: Accessing Parameters993881 -Node: Symbol Table Access995116 -Node: Symbol table by name995628 -Node: Symbol table by cookie997649 -Ref: Symbol table by cookie-Footnote-11001801 -Node: Cached values1001865 -Ref: Cached values-Footnote-11005372 -Node: Array Manipulation1005463 -Ref: Array Manipulation-Footnote-11006554 -Node: Array Data Types1006591 -Ref: Array Data Types-Footnote-11009249 -Node: Array Functions1009341 -Node: Flattening Arrays1013199 -Node: Creating Arrays1020107 -Node: Redirection API1024876 -Node: Extension API Variables1027707 -Node: Extension Versioning1028340 -Ref: gawk-api-version1028777 -Node: Extension API Informational Variables1030533 -Node: Extension API Boilerplate1031597 -Node: Finding Extensions1035411 -Node: Extension Example1035970 -Node: Internal File Description1036768 -Node: Internal File Ops1040848 -Ref: Internal File Ops-Footnote-11052610 -Node: Using Internal File Ops1052750 -Ref: Using Internal File Ops-Footnote-11055133 -Node: Extension Samples1055407 -Node: Extension Sample File Functions1056936 -Node: Extension Sample Fnmatch1064585 -Node: Extension Sample Fork1066072 -Node: Extension Sample Inplace1067290 -Node: Extension Sample Ord1070500 -Node: Extension Sample Readdir1071336 -Ref: table-readdir-file-types1072225 -Node: Extension Sample Revout1073030 -Node: Extension Sample Rev2way1073619 -Node: Extension Sample Read write array1074359 -Node: Extension Sample Readfile1076301 -Node: Extension Sample Time1077396 -Node: Extension Sample API Tests1078744 -Node: gawkextlib1079236 -Node: Extension summary1081683 -Node: Extension Exercises1085385 -Node: Language History1086883 -Node: V7/SVR3.11088539 -Node: SVR41090691 -Node: POSIX1092125 -Node: BTL1093504 -Node: POSIX/GNU1094233 -Node: Feature History1100095 -Node: Common Extensions1114465 -Node: Ranges and Locales1115748 -Ref: Ranges and Locales-Footnote-11120364 -Ref: Ranges and Locales-Footnote-21120391 -Ref: Ranges and Locales-Footnote-31120626 -Node: Contributors1120847 -Node: History summary1126407 -Node: Installation1127787 -Node: Gawk Distribution1128731 -Node: Getting1129215 -Node: Extracting1130176 -Node: Distribution contents1131814 -Node: Unix Installation1137899 -Node: Quick Installation1138581 -Node: Shell Startup Files1140995 -Node: Additional Configuration Options1142073 -Node: Configuration Philosophy1143878 -Node: Non-Unix Installation1146247 -Node: PC Installation1146707 -Node: PC Binary Installation1147545 -Node: PC Compiling1147980 -Node: PC Using1149097 -Node: Cygwin1152142 -Node: MSYS1152912 -Node: VMS Installation1153413 -Node: VMS Compilation1154204 -Ref: VMS Compilation-Footnote-11155433 -Node: VMS Dynamic Extensions1155491 -Node: VMS Installation Details1157176 -Node: VMS Running1159429 -Node: VMS GNV1163708 -Node: VMS Old Gawk1164443 -Node: Bugs1164914 -Node: Bug address1165577 -Node: Usenet1167974 -Node: Maintainers1168749 -Node: Other Versions1170125 -Node: Installation summary1176709 -Node: Notes1177744 -Node: Compatibility Mode1178609 -Node: Additions1179391 -Node: Accessing The Source1180316 -Node: Adding Code1181751 -Node: New Ports1187970 -Node: Derived Files1192458 -Ref: Derived Files-Footnote-11197943 -Ref: Derived Files-Footnote-21197978 -Ref: Derived Files-Footnote-31198576 -Node: Future Extensions1198690 -Node: Implementation Limitations1199348 -Node: Extension Design1200531 -Node: Old Extension Problems1201685 -Ref: Old Extension Problems-Footnote-11203203 -Node: Extension New Mechanism Goals1203260 -Ref: Extension New Mechanism Goals-Footnote-11206624 -Node: Extension Other Design Decisions1206813 -Node: Extension Future Growth1208926 -Node: Old Extension Mechanism1209762 -Node: Notes summary1211525 -Node: Basic Concepts1212707 -Node: Basic High Level1213388 -Ref: figure-general-flow1213670 -Ref: figure-process-flow1214355 -Ref: Basic High Level-Footnote-11217656 -Node: Basic Data Typing1217841 -Node: Glossary1221169 -Node: Copying1253116 -Node: GNU Free Documentation License1290655 -Node: Index1315773 +Node: Exit Callback Functions972816 +Node: Extension Version String974066 +Node: Input Parsers974729 +Node: Output Wrappers984611 +Node: Two-way processors989123 +Node: Printing Messages991388 +Ref: Printing Messages-Footnote-1992559 +Node: Updating ERRNO992712 +Node: Requesting Values993451 +Ref: table-value-types-returned994188 +Node: Accessing Parameters995071 +Node: Symbol Table Access996306 +Node: Symbol table by name996818 +Node: Symbol table by cookie998839 +Ref: Symbol table by cookie-Footnote-11002991 +Node: Cached values1003055 +Ref: Cached values-Footnote-11006562 +Node: Array Manipulation1006653 +Ref: Array Manipulation-Footnote-11007744 +Node: Array Data Types1007781 +Ref: Array Data Types-Footnote-11010439 +Node: Array Functions1010531 +Node: Flattening Arrays1014389 +Node: Creating Arrays1021297 +Node: Redirection API1026066 +Node: Extension API Variables1028897 +Node: Extension Versioning1029530 +Ref: gawk-api-version1029967 +Node: Extension API Informational Variables1031723 +Node: Extension API Boilerplate1032787 +Node: Finding Extensions1036601 +Node: Extension Example1037160 +Node: Internal File Description1037958 +Node: Internal File Ops1042038 +Ref: Internal File Ops-Footnote-11053800 +Node: Using Internal File Ops1053940 +Ref: Using Internal File Ops-Footnote-11056323 +Node: Extension Samples1056597 +Node: Extension Sample File Functions1058126 +Node: Extension Sample Fnmatch1065775 +Node: Extension Sample Fork1067262 +Node: Extension Sample Inplace1068480 +Node: Extension Sample Ord1071690 +Node: Extension Sample Readdir1072526 +Ref: table-readdir-file-types1073415 +Node: Extension Sample Revout1074220 +Node: Extension Sample Rev2way1074809 +Node: Extension Sample Read write array1075549 +Node: Extension Sample Readfile1077491 +Node: Extension Sample Time1078586 +Node: Extension Sample API Tests1079934 +Node: gawkextlib1080426 +Node: Extension summary1082873 +Node: Extension Exercises1086575 +Node: Language History1088073 +Node: V7/SVR3.11089729 +Node: SVR41091881 +Node: POSIX1093315 +Node: BTL1094694 +Node: POSIX/GNU1095423 +Node: Feature History1101285 +Node: Common Extensions1115655 +Node: Ranges and Locales1116938 +Ref: Ranges and Locales-Footnote-11121554 +Ref: Ranges and Locales-Footnote-21121581 +Ref: Ranges and Locales-Footnote-31121816 +Node: Contributors1122037 +Node: History summary1127597 +Node: Installation1128977 +Node: Gawk Distribution1129921 +Node: Getting1130405 +Node: Extracting1131366 +Node: Distribution contents1133004 +Node: Unix Installation1139089 +Node: Quick Installation1139771 +Node: Shell Startup Files1142185 +Node: Additional Configuration Options1143263 +Node: Configuration Philosophy1145068 +Node: Non-Unix Installation1147437 +Node: PC Installation1147897 +Node: PC Binary Installation1148735 +Node: PC Compiling1149170 +Node: PC Using1150287 +Node: Cygwin1153332 +Node: MSYS1154102 +Node: VMS Installation1154603 +Node: VMS Compilation1155394 +Ref: VMS Compilation-Footnote-11156623 +Node: VMS Dynamic Extensions1156681 +Node: VMS Installation Details1158366 +Node: VMS Running1160619 +Node: VMS GNV1164898 +Node: VMS Old Gawk1165633 +Node: Bugs1166104 +Node: Bug address1166767 +Node: Usenet1169164 +Node: Maintainers1169939 +Node: Other Versions1171315 +Node: Installation summary1177899 +Node: Notes1178934 +Node: Compatibility Mode1179799 +Node: Additions1180581 +Node: Accessing The Source1181506 +Node: Adding Code1182941 +Node: New Ports1189160 +Node: Derived Files1193648 +Ref: Derived Files-Footnote-11199133 +Ref: Derived Files-Footnote-21199168 +Ref: Derived Files-Footnote-31199766 +Node: Future Extensions1199880 +Node: Implementation Limitations1200538 +Node: Extension Design1201721 +Node: Old Extension Problems1202875 +Ref: Old Extension Problems-Footnote-11204393 +Node: Extension New Mechanism Goals1204450 +Ref: Extension New Mechanism Goals-Footnote-11207814 +Node: Extension Other Design Decisions1208003 +Node: Extension Future Growth1210116 +Node: Old Extension Mechanism1210952 +Node: Notes summary1212715 +Node: Basic Concepts1213897 +Node: Basic High Level1214578 +Ref: figure-general-flow1214860 +Ref: figure-process-flow1215545 +Ref: Basic High Level-Footnote-11218846 +Node: Basic Data Typing1219031 +Node: Glossary1222359 +Node: Copying1254306 +Node: GNU Free Documentation License1291845 +Node: Index1316963 End Tag Table diff --git a/doc/gawk.texi b/doc/gawk.texi index 5f3d6efa..c482f8d2 100644 --- a/doc/gawk.texi +++ b/doc/gawk.texi @@ -32799,8 +32799,13 @@ Extension functions are described by the following record: @example 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; +@ @ @ @ 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; @end example @@ -32818,7 +32823,7 @@ or an underscore, which may be followed by any number of letters, digits, and underscores. Letter case in function names is significant. -@item awk_value_t *(*function)(int num_actual_args, awk_value_t *result); +@item awk_value_t *(*const function)(int num_actual_args, awk_value_t *result, struct awk_ext_func *finfo); This is a pointer to the C function that provides the extension's functionality. The function must fill in @code{*result} with either a number @@ -32829,20 +32834,38 @@ As mentioned earlier, string memory @emph{must} come from one of The @code{num_actual_args} argument tells the C function how many actual parameters were passed from the calling @command{awk} code. +The @code{finfo} parameter is a pointer to the @code{awk_ext_func_t} for +this function. The called function may access data within it as desired, or not. + The function must return the value of @code{result}. This is for the convenience of the calling code inside @command{gawk}. -@item size_t max_expected_args; +@item const size_t min_required_args; +This is the minimum number of arguments the function expects to receive. +If called with fewer arguments, @command{gawk} prints a fatal error +message and exits. + +@item const size_t max_expected_args; This is the maximum number of arguments the function expects to receive. -Each extension function may decide what to do if the number of -arguments isn't what it expected. As with real @command{awk} functions, it -is likely OK to ignore extra arguments. This value does not affect -actual program execution. - -Extension functions should compare this value to the number of actual -arguments passed and possibly issue a lint warning if there is an -undesirable mismatch. Of course, if -@samp{--lint=fatal} is used, this would cause the program to exit. +If called with more arguments than this, and if lint checking has +been enabled, then @command{gawk} prints a warning message. For more +information, see the next item in this list. + +@item awk_bool_t suppress_lint; +This flag tells @command{gawk} not to print a lint message if lint +checking has been enabled and if more arguments were supplied in the call +than expected. An extension function can tell if @command{gawk} already +printed at least one such message by checking if @samp{num_actual_args > +finfo->max_expected_args}. If so, and the function does not want more +lint messages to be printed, it should set @code{finfo->suppress_lint} +to @code{awk_true}. + +@item void *data; +This is an opaque pointer to any data that an extension function may +wish to have available when called. Passing the @code{awk_ext_funct_t} +structure to the extension function, and having this pointer available +in it enables writing a single C or C++ function that implements multiple +@command{awk}-level extension functions. @end table Once you have a record representing your extension function, you register diff --git a/doc/gawktexi.in b/doc/gawktexi.in index 857be3ab..7f7a7b26 100644 --- a/doc/gawktexi.in +++ b/doc/gawktexi.in @@ -31813,8 +31813,13 @@ Extension functions are described by the following record: @example 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; +@ @ @ @ 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; @end example @@ -31832,7 +31837,7 @@ or an underscore, which may be followed by any number of letters, digits, and underscores. Letter case in function names is significant. -@item awk_value_t *(*function)(int num_actual_args, awk_value_t *result); +@item awk_value_t *(*const function)(int num_actual_args, awk_value_t *result, struct awk_ext_func *finfo); This is a pointer to the C function that provides the extension's functionality. The function must fill in @code{*result} with either a number @@ -31843,20 +31848,38 @@ As mentioned earlier, string memory @emph{must} come from one of The @code{num_actual_args} argument tells the C function how many actual parameters were passed from the calling @command{awk} code. +The @code{finfo} parameter is a pointer to the @code{awk_ext_func_t} for +this function. The called function may access data within it as desired, or not. + The function must return the value of @code{result}. This is for the convenience of the calling code inside @command{gawk}. -@item size_t max_expected_args; +@item const size_t min_required_args; +This is the minimum number of arguments the function expects to receive. +If called with fewer arguments, @command{gawk} prints a fatal error +message and exits. + +@item const size_t max_expected_args; This is the maximum number of arguments the function expects to receive. -Each extension function may decide what to do if the number of -arguments isn't what it expected. As with real @command{awk} functions, it -is likely OK to ignore extra arguments. This value does not affect -actual program execution. - -Extension functions should compare this value to the number of actual -arguments passed and possibly issue a lint warning if there is an -undesirable mismatch. Of course, if -@samp{--lint=fatal} is used, this would cause the program to exit. +If called with more arguments than this, and if lint checking has +been enabled, then @command{gawk} prints a warning message. For more +information, see the next item in this list. + +@item awk_bool_t suppress_lint; +This flag tells @command{gawk} not to print a lint message if lint +checking has been enabled and if more arguments were supplied in the call +than expected. An extension function can tell if @command{gawk} already +printed at least one such message by checking if @samp{num_actual_args > +finfo->max_expected_args}. If so, and the function does not want more +lint messages to be printed, it should set @code{finfo->suppress_lint} +to @code{awk_true}. + +@item void *data; +This is an opaque pointer to any data that an extension function may +wish to have available when called. Passing the @code{awk_ext_funct_t} +structure to the extension function, and having this pointer available +in it enables writing a single C or C++ function that implements multiple +@command{awk}-level extension functions. @end table Once you have a record representing your extension function, you register diff --git a/extension/ChangeLog b/extension/ChangeLog index edacc2f4..831a15f9 100644 --- a/extension/ChangeLog +++ b/extension/ChangeLog @@ -1,3 +1,19 @@ +2016-12-14 Arnold D. Robbins <arnold@skeeve.com> + + * filefuncs.c: Update do_xxx to match new API. Update func_table. + * fnmatch.c: Ditto. + * fork.c: Ditto. + * inplace.c: Ditto. + * ordchr.c: Ditto. + * readdir.c: Ditto. + * readfile.c: Ditto. + * revoutput.c: Ditto. + * revtwoway.c: Ditto. + * rwarray.c: Ditto. + * rwarray0.c: Ditto. + * testext.c: Ditto. + * time.c: Ditto. + 2016-12-12 Arnold D. Robbins <arnold@skeeve.com> * filefuncs.c (func_table): Adjust ordering of min and max @@ -14,6 +30,7 @@ * fork.c: Ditto. * inplace.c: Ditto. * ordchr.c: Ditto. + * readdir.c: Ditto. * readfile.c: Ditto. * rwarray.c: Ditto. * rwarray0.c: Ditto. diff --git a/extension/filefuncs.c b/extension/filefuncs.c index de293bee..696a8599 100644 --- a/extension/filefuncs.c +++ b/extension/filefuncs.c @@ -153,7 +153,7 @@ int plugin_is_GPL_compatible; /* do_chdir --- provide dynamically loaded chdir() function for gawk */ static awk_value_t * -do_chdir(int nargs, awk_value_t *result) +do_chdir(int nargs, awk_value_t *result, struct awk_ext_func *unused) { awk_value_t newdir; int ret = -1; @@ -458,7 +458,7 @@ fill_stat_array(const char *name, awk_array_t array, struct stat *sbuf) /* do_stat --- provide a stat() function for gawk */ static awk_value_t * -do_stat(int nargs, awk_value_t *result) +do_stat(int nargs, awk_value_t *result, struct awk_ext_func *unused) { awk_value_t file_param, array_param; char *name; @@ -503,7 +503,7 @@ do_stat(int nargs, awk_value_t *result) /* do_statvfs --- provide a statvfs() function for gawk */ static awk_value_t * -do_statvfs(int nargs, awk_value_t *result) +do_statvfs(int nargs, awk_value_t *result, struct awk_ext_func *unused) { awk_value_t file_param, array_param; char *name; @@ -599,7 +599,7 @@ init_filefuncs(void) */ static awk_value_t * -do_fts(int nargs, awk_value_t *result) +do_fts(int nargs, awk_value_t *result, struct awk_ext_func *unused) { fatal(ext_id, _("fts is not supported on this system")); @@ -814,7 +814,7 @@ process(FTS *heirarchy, awk_array_t destarray, int seedot) */ static awk_value_t * -do_fts(int nargs, awk_value_t *result) +do_fts(int nargs, awk_value_t *result, struct awk_ext_func *unused) { awk_value_t pathlist, flagval, dest; awk_flat_array_t *path_array = NULL; @@ -913,13 +913,13 @@ out: #endif /* ! __MINGW32__ */ static awk_ext_func_t func_table[] = { - { "chdir", do_chdir, 1, 1 }, - { "stat", do_stat, 3, 2 }, + { "chdir", do_chdir, 1, 1, awk_false, NULL }, + { "stat", do_stat, 2, 3, awk_false, NULL }, #ifndef __MINGW32__ - { "fts", do_fts, 3, 3 }, + { "fts", do_fts, 3, 3, awk_false, NULL }, #endif #if defined(HAVE_SYS_STATVFS_H) && defined(HAVE_STATVFS) - { "statvfs", do_statvfs, 2, 2 }, + { "statvfs", do_statvfs, 2, 2, awk_false, NULL }, #endif }; diff --git a/extension/fnmatch.c b/extension/fnmatch.c index caf64a7b..5382e4bc 100644 --- a/extension/fnmatch.c +++ b/extension/fnmatch.c @@ -95,7 +95,7 @@ int plugin_is_GPL_compatible; /* do_fnmatch --- implement the fnmatch interface */ static awk_value_t * -do_fnmatch(int nargs, awk_value_t *result) +do_fnmatch(int nargs, awk_value_t *result, struct awk_ext_func *unused) { #ifdef HAVE_FNMATCH_H static int flags_mask = @@ -194,7 +194,7 @@ init_fnmatch(void) } static awk_ext_func_t func_table[] = { - { "fnmatch", do_fnmatch, 3, 3 }, + { "fnmatch", do_fnmatch, 3, 3, awk_false, NULL }, }; /* define the dl_load function using the boilerplate macro */ diff --git a/extension/fork.c b/extension/fork.c index 064a2a8c..823506dd 100644 --- a/extension/fork.c +++ b/extension/fork.c @@ -71,7 +71,7 @@ array_set_numeric(awk_array_t array, const char *sub, double num) /* do_fork --- provide dynamically loaded fork() builtin for gawk */ static awk_value_t * -do_fork(int nargs, awk_value_t *result) +do_fork(int nargs, awk_value_t *result, struct awk_ext_func *unused) { int ret = -1; @@ -103,7 +103,7 @@ do_fork(int nargs, awk_value_t *result) /* do_waitpid --- provide dynamically loaded waitpid() builtin for gawk */ static awk_value_t * -do_waitpid(int nargs, awk_value_t *result) +do_waitpid(int nargs, awk_value_t *result, struct awk_ext_func *unused) { awk_value_t pid; int ret = -1; @@ -126,7 +126,7 @@ do_waitpid(int nargs, awk_value_t *result) /* do_wait --- provide dynamically loaded wait() builtin for gawk */ static awk_value_t * -do_wait(int nargs, awk_value_t *result) +do_wait(int nargs, awk_value_t *result, struct awk_ext_func *unused) { int ret; @@ -141,9 +141,9 @@ do_wait(int nargs, awk_value_t *result) } static awk_ext_func_t func_table[] = { - { "fork", do_fork, 0, 0 }, - { "waitpid", do_waitpid, 1, 1 }, - { "wait", do_wait, 0, 0 }, + { "fork", do_fork, 0, 0, awk_false, NULL }, + { "waitpid", do_waitpid, 1, 1, awk_false, NULL }, + { "wait", do_wait, 0, 0, awk_false, NULL }, }; /* define the dl_load function using the boilerplate macro */ diff --git a/extension/inplace.c b/extension/inplace.c index 19ee5605..5457287f 100644 --- a/extension/inplace.c +++ b/extension/inplace.c @@ -118,7 +118,7 @@ invalid_filename(const awk_string_t *filename) /* do_inplace_begin --- start in-place editing */ static awk_value_t * -do_inplace_begin(int nargs, awk_value_t *result) +do_inplace_begin(int nargs, awk_value_t *result, struct awk_ext_func *unused) { awk_value_t filename; struct stat sbuf; @@ -201,7 +201,7 @@ do_inplace_begin(int nargs, awk_value_t *result) /* do_inplace_end --- finish in-place editing */ static awk_value_t * -do_inplace_end(int nargs, awk_value_t *result) +do_inplace_end(int nargs, awk_value_t *result, struct awk_ext_func *unused) { awk_value_t filename, suffix; @@ -262,8 +262,8 @@ do_inplace_end(int nargs, awk_value_t *result) } static awk_ext_func_t func_table[] = { - { "inplace_begin", do_inplace_begin, 2, 2 }, - { "inplace_end", do_inplace_end, 2, 2 }, + { "inplace_begin", do_inplace_begin, 2, 2, awk_false, NULL }, + { "inplace_end", do_inplace_end, 2, 2, awk_false, NULL }, }; static awk_bool_t init_inplace(void) diff --git a/extension/ordchr.c b/extension/ordchr.c index 3722ced8..c7451f6d 100644 --- a/extension/ordchr.c +++ b/extension/ordchr.c @@ -58,7 +58,7 @@ int plugin_is_GPL_compatible; /* do_ord --- return numeric value of first char of string */ static awk_value_t * -do_ord(int nargs, awk_value_t *result) +do_ord(int nargs, awk_value_t *result, struct awk_ext_func *unused) { awk_value_t str; double ret = -1; @@ -77,7 +77,7 @@ do_ord(int nargs, awk_value_t *result) /* do_chr --- turn numeric value into a string */ static awk_value_t * -do_chr(int nargs, awk_value_t *result) +do_chr(int nargs, awk_value_t *result, struct awk_ext_func *unused) { awk_value_t num; unsigned int ret = 0; @@ -102,8 +102,8 @@ do_chr(int nargs, awk_value_t *result) } static awk_ext_func_t func_table[] = { - { "ord", do_ord, 1, 1 }, - { "chr", do_chr, 1, 1 }, + { "ord", do_ord, 1, 1, awk_false, NULL }, + { "chr", do_chr, 1, 1, awk_false, NULL }, }; /* define the dl_load function using the boilerplate macro */ diff --git a/extension/readdir.c b/extension/readdir.c index 6106a44b..39acba68 100644 --- a/extension/readdir.c +++ b/extension/readdir.c @@ -316,7 +316,7 @@ init_readdir() } static awk_ext_func_t func_table[] = { - { NULL, NULL, 0 } + { NULL, NULL, 0, 0, awk_false, NULL } }; /* define the dl_load function using the boilerplate macro */ diff --git a/extension/readfile.c b/extension/readfile.c index cc9a4c14..b453da21 100644 --- a/extension/readfile.c +++ b/extension/readfile.c @@ -98,7 +98,7 @@ done: /* do_readfile --- read a file into memory */ static awk_value_t * -do_readfile(int nargs, awk_value_t *result) +do_readfile(int nargs, awk_value_t *result, struct awk_ext_func *unused) { awk_value_t filename; int ret; @@ -238,7 +238,7 @@ init_readfile() } static awk_ext_func_t func_table[] = { - { "readfile", do_readfile, 1, 1 }, + { "readfile", do_readfile, 1, 1, awk_false, NULL }, }; /* define the dl_load function using the boilerplate macro */ diff --git a/extension/revoutput.c b/extension/revoutput.c index 84d0aaa5..5862ed6e 100644 --- a/extension/revoutput.c +++ b/extension/revoutput.c @@ -134,7 +134,7 @@ init_revoutput() } static awk_ext_func_t func_table[] = { - { NULL, NULL, 0 } + { NULL, NULL, 0, 0, awk_false, NULL } }; /* define the dl_load function using the boilerplate macro */ diff --git a/extension/revtwoway.c b/extension/revtwoway.c index 82fabb2b..ac4e22cf 100644 --- a/extension/revtwoway.c +++ b/extension/revtwoway.c @@ -336,7 +336,7 @@ init_revtwoway() } static awk_ext_func_t func_table[] = { - { NULL, NULL, 0 } + { NULL, NULL, 0, 0, awk_false, NULL } }; /* define the dl_load function using the boilerplate macro */ diff --git a/extension/rwarray.c b/extension/rwarray.c index 8c3200ea..00ded7bf 100644 --- a/extension/rwarray.c +++ b/extension/rwarray.c @@ -99,7 +99,7 @@ static awk_bool_t read_value(FILE *fp, awk_value_t *value); /* do_writea --- write an array */ static awk_value_t * -do_writea(int nargs, awk_value_t *result) +do_writea(int nargs, awk_value_t *result, struct awk_ext_func *unused) { awk_value_t filename, array; FILE *fp = NULL; @@ -251,7 +251,7 @@ write_value(FILE *fp, awk_value_t *val) /* do_reada --- read an array */ static awk_value_t * -do_reada(int nargs, awk_value_t *result) +do_reada(int nargs, awk_value_t *result, struct awk_ext_func *unused) { awk_value_t filename, array; FILE *fp = NULL; @@ -464,8 +464,8 @@ read_value(FILE *fp, awk_value_t *value) } static awk_ext_func_t func_table[] = { - { "writea", do_writea, 2, 2 }, - { "reada", do_reada, 2, 2 }, + { "writea", do_writea, 2, 2, awk_false, NULL }, + { "reada", do_reada, 2, 2, awk_false, NULL }, }; diff --git a/extension/rwarray0.c b/extension/rwarray0.c index 35e0a702..faa73783 100644 --- a/extension/rwarray0.c +++ b/extension/rwarray0.c @@ -95,7 +95,7 @@ static awk_bool_t read_value(int fd, awk_value_t *value); /* do_writea --- write an array */ static awk_value_t * -do_writea(int nargs, awk_value_t *result) +do_writea(int nargs, awk_value_t *result, struct awk_ext_func *unused) { awk_value_t filename, array; int fd = -1; @@ -247,7 +247,7 @@ write_value(int fd, awk_value_t *val) /* do_reada --- read an array */ static awk_value_t * -do_reada(int nargs, awk_value_t *result) +do_reada(int nargs, awk_value_t *result, struct awk_ext_func *unused) { awk_value_t filename, array; int fd = -1; @@ -459,8 +459,8 @@ read_value(int fd, awk_value_t *value) } static awk_ext_func_t func_table[] = { - { "writea", do_writea, 2, 2 }, - { "reada", do_reada, 2, 2 }, + { "writea", do_writea, 2, 2, awk_false, NULL }, + { "reada", do_reada, 2, 2, awk_false, NULL }, }; diff --git a/extension/testext.c b/extension/testext.c index 227714e1..bf342182 100644 --- a/extension/testext.c +++ b/extension/testext.c @@ -107,7 +107,7 @@ BEGIN { } */ static awk_value_t * -dump_array_and_delete(int nargs, awk_value_t *result) +dump_array_and_delete(int nargs, awk_value_t *result, struct awk_ext_func *unused) { awk_value_t value, value2, value3; awk_flat_array_t *flat_array; @@ -201,7 +201,7 @@ BEGIN { */ static awk_value_t * -try_modify_environ(int nargs, awk_value_t *result) +try_modify_environ(int nargs, awk_value_t *result, struct awk_ext_func *unused) { awk_value_t value, index, newvalue; awk_flat_array_t *flat_array; @@ -290,7 +290,7 @@ BEGIN { */ static awk_value_t * -var_test(int nargs, awk_value_t *result) +var_test(int nargs, awk_value_t *result, struct awk_ext_func *unused) { awk_value_t value, value2; awk_value_t *valp; @@ -357,7 +357,7 @@ BEGIN { } */ static awk_value_t * -test_errno(int nargs, awk_value_t *result) +test_errno(int nargs, awk_value_t *result, struct awk_ext_func *unused) { assert(result != NULL); make_number(0.0, result); @@ -386,7 +386,7 @@ BEGIN { } */ static awk_value_t * -test_deferred(int nargs, awk_value_t *result) +test_deferred(int nargs, awk_value_t *result, struct awk_ext_func *unused) { awk_value_t arr; awk_value_t index, value; @@ -465,7 +465,7 @@ BEGIN { */ static awk_value_t * -test_array_size(int nargs, awk_value_t *result) +test_array_size(int nargs, awk_value_t *result, struct awk_ext_func *unused) { awk_value_t value; size_t count = 0; @@ -529,7 +529,7 @@ BEGIN { } */ static awk_value_t * -test_array_elem(int nargs, awk_value_t *result) +test_array_elem(int nargs, awk_value_t *result, struct awk_ext_func *unused) { awk_value_t array, index, index2, value; @@ -617,7 +617,7 @@ BEGIN { */ static awk_value_t * -test_array_param(int nargs, awk_value_t *result) +test_array_param(int nargs, awk_value_t *result, struct awk_ext_func *unused) { awk_value_t new_array; awk_value_t arg0; @@ -660,7 +660,7 @@ BEGIN { } */ static awk_value_t * -print_do_lint(int nargs, awk_value_t *result) +print_do_lint(int nargs, awk_value_t *result, struct awk_ext_func *unused) { assert(result != NULL); make_number(0.0, result); @@ -696,7 +696,7 @@ BEGIN { /* test_scalar --- test scalar cookie */ static awk_value_t * -test_scalar(int nargs, awk_value_t *result) +test_scalar(int nargs, awk_value_t *result, struct awk_ext_func *unused) { awk_value_t new_value, new_value2; awk_value_t the_scalar; @@ -743,7 +743,7 @@ BEGIN { /* test_scalar_reserved --- test scalar cookie on special variable */ static awk_value_t * -test_scalar_reserved(int nargs, awk_value_t *result) +test_scalar_reserved(int nargs, awk_value_t *result, struct awk_ext_func *unused) { awk_value_t new_value; awk_value_t the_scalar; @@ -796,7 +796,7 @@ BEGIN { /* test_indirect_vars --- test that access to NR, NF, get correct vales */ static awk_value_t * -test_indirect_vars(int nargs, awk_value_t *result) +test_indirect_vars(int nargs, awk_value_t *result, struct awk_ext_func *unused) { awk_value_t value; char *name = "NR"; @@ -844,7 +844,7 @@ BEGIN { /* test_get_file --- test that we can create a file */ static awk_value_t * -test_get_file(int nargs, awk_value_t *result) +test_get_file(int nargs, awk_value_t *result, struct awk_ext_func *unused) { awk_value_t filename, alias; int fd; @@ -882,7 +882,7 @@ test_get_file(int nargs, awk_value_t *result) /* do_get_file --- provide access to get_file API */ static awk_value_t * -do_get_file(int nargs, awk_value_t *result) +do_get_file(int nargs, awk_value_t *result, struct awk_ext_func *unused) { awk_value_t filename, filetype, fd, res; const awk_input_buf_t *ibuf; @@ -1024,20 +1024,20 @@ static void at_exit2(void *data, int exit_status) } static awk_ext_func_t func_table[] = { - { "dump_array_and_delete", dump_array_and_delete, 2, 2 }, - { "try_modify_environ", try_modify_environ, 0, 0 }, - { "var_test", var_test, 1, 1 }, - { "test_deferred", test_deferred, 0, 0 }, - { "test_errno", test_errno, 0, 0 }, - { "test_array_size", test_array_size, 1, 1 }, - { "test_array_elem", test_array_elem, 2, 2 }, - { "test_array_param", test_array_param, 1, 1 }, - { "print_do_lint", print_do_lint, 0, 0 }, - { "test_scalar", test_scalar, 1, 1 }, - { "test_scalar_reserved", test_scalar_reserved, 0, 0 }, - { "test_indirect_vars", test_indirect_vars, 0, 0 }, - { "test_get_file", test_get_file, 2, 2 }, - { "get_file", do_get_file, 4, 4 }, + { "dump_array_and_delete", dump_array_and_delete, 2, 2, awk_false, NULL }, + { "try_modify_environ", try_modify_environ, 0, 0, awk_false, NULL }, + { "var_test", var_test, 1, 1, awk_false, NULL }, + { "test_deferred", test_deferred, 0, 0, awk_false, NULL }, + { "test_errno", test_errno, 0, 0, awk_false, NULL }, + { "test_array_size", test_array_size, 1, 1, awk_false, NULL }, + { "test_array_elem", test_array_elem, 2, 2, awk_false, NULL }, + { "test_array_param", test_array_param, 1, 1, awk_false, NULL }, + { "print_do_lint", print_do_lint, 0, 0, awk_false, NULL }, + { "test_scalar", test_scalar, 1, 1, awk_false, NULL }, + { "test_scalar_reserved", test_scalar_reserved, 0, 0, awk_false, NULL }, + { "test_indirect_vars", test_indirect_vars, 0, 0, awk_false, NULL }, + { "test_get_file", test_get_file, 2, 2, awk_false, NULL }, + { "get_file", do_get_file, 4, 4, awk_false, NULL }, }; /* init_testext --- additional initialization function */ diff --git a/extension/time.c b/extension/time.c index 67002752..01be7784 100644 --- a/extension/time.c +++ b/extension/time.c @@ -103,7 +103,7 @@ int plugin_is_GPL_compatible; * on the platform */ static awk_value_t * -do_gettimeofday(int nargs, awk_value_t *result) +do_gettimeofday(int nargs, awk_value_t *result, struct awk_ext_func *unused) { double curtime; @@ -150,7 +150,7 @@ do_gettimeofday(int nargs, awk_value_t *result) * did not complete successfully (perhaps interrupted) */ static awk_value_t * -do_sleep(int nargs, awk_value_t *result) +do_sleep(int nargs, awk_value_t *result, struct awk_ext_func *unused) { awk_value_t num; double secs; @@ -206,8 +206,8 @@ do_sleep(int nargs, awk_value_t *result) } static awk_ext_func_t func_table[] = { - { "gettimeofday", do_gettimeofday, 0, 0 }, - { "sleep", do_sleep, 1, 1 }, + { "gettimeofday", do_gettimeofday, 0, 0, awk_false, NULL }, + { "sleep", do_sleep, 1, 1, awk_false, NULL }, }; /* define the dl_load function using the boilerplate macro */ @@ -326,7 +326,7 @@ api_unset_ERRNO(awk_ext_id_t id) static 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) { (void) id; (void) namespace; @@ -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, diff --git a/interpret.h b/interpret.h index db4bd325..79e7228e 100644 --- a/interpret.h +++ b/interpret.h @@ -965,14 +965,12 @@ arrayfor: fatal(_("%s: called with %d arguments, expecting at least %d"), pc[1].func_name, arg_count, min_req); - if (do_lint && max_expect > 0 && arg_count > max_expect) { - lintwarn(_("%s: called with %d arguments, expecting no more than %d; check all calls"), + if (do_lint && ! f->suppress_lint && arg_count > max_expect) + lintwarn(_("%s: called with %d arguments, expecting no more than %d"), pc[1].func_name, arg_count, max_expect); - f->max_expected_args = 0; // avoid multiple lint messages - } PUSH_CODE(pc); - r = awk_value_to_node(pc->extfunc(arg_count, & result)); + r = awk_value_to_node(pc->extfunc(arg_count, & result, f)); (void) POP_CODE(); while (arg_count-- > 0) { t1 = POP(); |