gawk-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gawk-diffs] [SCM] gawk branch, extgawk, updated. 85458962f4ca247b4c263a


From: Arnold Robbins
Subject: [gawk-diffs] [SCM] gawk branch, extgawk, updated. 85458962f4ca247b4c263a5588150960ee6f3e42
Date: Wed, 16 May 2012 19:23:21 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "gawk".

The branch, extgawk has been updated
       via  85458962f4ca247b4c263a5588150960ee6f3e42 (commit)
      from  60a3183d9a228569eee98b19c67600e103ae1eac (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://git.sv.gnu.org/cgit/gawk.git/commit/?id=85458962f4ca247b4c263a5588150960ee6f3e42

commit 85458962f4ca247b4c263a5588150960ee6f3e42
Author: Arnold D. Robbins <address@hidden>
Date:   Wed May 16 22:22:57 2012 +0300

    More work on extension API.

diff --git a/extension/filefuncs2.c b/extension/filefuncs2.c
index 79fae61..73bea0c 100644
--- a/extension/filefuncs2.c
+++ b/extension/filefuncs2.c
@@ -37,7 +37,7 @@
 #include <sys/stat.h>
 #include "gawkapi.h"
 
-static gawk_api_t *api;                /* for convenience macros to work */
+static const gawk_api_t *api;  /* for convenience macros to work */
 static awk_ext_id_t *ext_id;
 
 int plugin_is_GPL_compatible;
@@ -220,10 +220,7 @@ array_set(awk_array_t array, const char *sub, awk_value_t 
*value)
 
        memset(& element, 0, sizeof(element));
 
-       emalloc(element.index.str, char *, strlen(sub), "array_set");
-
-       strcpy(element.index.str, sub);
-       element.index.len = strlen(sub);
+       element.index = dup_string(ext_id, sub, strlen(sub))->str_value;
        element.value = *value;
 
        set_array_element(ext_id, array, & element);
@@ -359,7 +356,7 @@ out:
 
 /* dl_load --- load new builtins in this library */
 
-int dl_load(gawk_api_t *api_p, awk_ext_id_t id)
+int dl_load(const gawk_api_t *const api_p, awk_ext_id_t id)
 {
        static awk_ext_func_t func_table[] = {
                { "chdir", do_chdir, 1 },
@@ -368,13 +365,23 @@ int dl_load(gawk_api_t *api_p, awk_ext_id_t id)
        size_t i, j;
        int errors = 0;
 
+       if (api->major_version != GAWK_API_MAJOR_VERSION
+           || api->minor_version < GAWK_API_MINOR_VERSION) {
+               fprintf(stderr, "filefuncs: version mismatch with gawk!\n");
+               fprintf(stderr, "\tmy version (%d, %d), gawk version (%d, 
%d)\n",
+                       GAWK_API_MAJOR_VERSION, GAWK_API_MINOR_VERSION,
+                       api->major_version, api->minor_version);
+               exit(1);
+       }
+
        api = api_p;
        ext_id = id;
 
        /* load functions */
        for (i = 0, j = sizeof(func_table) / sizeof(func_table[0]); i < j; i++) 
{
-               if (! add_ext_func(ext_id, & func_table[i])) {
-                       warning(ext_id, "filefuncs: could not add %s\n", 
func_table[i].name);
+               if (! add_ext_func(ext_id, & func_table[i], "")) {
+                       warning(ext_id, "filefuncs: could not add %s\n",
+                                       func_table[i].name);
                        errors++;
                }
        }
diff --git a/gawkapi.c b/gawkapi.c
index 059d49e..d4d6503 100644
--- a/gawkapi.c
+++ b/gawkapi.c
@@ -115,7 +115,9 @@ api_unset_ERRNO(awk_ext_id_t id)
 
 /* Add a function to the interpreter, returns true upon success */
 static awk_bool_t
-api_add_ext_func(awk_ext_id_t id, const awk_ext_func_t *func)
+api_add_ext_func(awk_ext_id_t id,
+               const awk_ext_func_t *func,
+               const char *namespace)
 {
        return true;    /* for now */
 }
@@ -277,14 +279,27 @@ api_release_flattened_array(awk_ext_id_t id,
 /* Constructor functions */
 static awk_value_t *
 api_make_string(awk_ext_id_t id,
-               const char *string, size_t length)
+               const char *string,
+               size_t length,
+               awk_bool_t duplicate)
 {
        static awk_value_t result;
+       char *cp = NULL;
 
        result.val_type = AWK_STRING;
-       result.str_value.str = (char *) string;
        result.str_value.len = length;
 
+       if (duplicate) {
+               emalloc(cp, char *, length + 1, "api_make_string");
+               memcpy(cp, string, length);
+               cp[length] = '\0';
+
+               result.str_value.str = cp;
+       } else {
+               result.str_value.str = (char *) string;
+       }
+
+
        return & result;
 }
 
diff --git a/gawkapi.h b/gawkapi.h
index 2a14d33..c3ddc38 100644
--- a/gawkapi.h
+++ b/gawkapi.h
@@ -210,7 +210,8 @@ typedef struct gawk_api {
        void (*unset_ERRNO)(awk_ext_id_t id);
 
        /* Add a function to the interpreter, returns true upon success */
-       awk_bool_t (*add_ext_func)(awk_ext_id_t id, const awk_ext_func_t *func);
+       awk_bool_t (*add_ext_func)(awk_ext_id_t id, const awk_ext_func_t *func,
+                       const char *namespace);
 
        /* Add an exit call back, returns true upon success */
        awk_bool_t (*awk_atexit)(awk_ext_id_t id,
@@ -287,9 +288,9 @@ typedef struct gawk_api {
                        awk_element_t *data);
 
        /* Constructor functions */
-       awk_value_t *(*make_string)(awk_ext_id_t id,
-                       const char *string, size_t length);
-       awk_value_t *(*make_number)(awk_ext_id_t id, double num);
+       awk_value_t *(*api_make_string)(awk_ext_id_t id,
+                       const char *string, size_t length, awk_bool_t 
duplicate);
+       awk_value_t *(*api_make_number)(awk_ext_id_t id, double num);
 
 } gawk_api_t;
 
@@ -335,8 +336,9 @@ typedef struct gawk_api {
 #define flatten_array          api->flatten_array
 #define release_flattened_array        api->release_flattened_array
 
-#define make_string    api->make_string
-#define make_number    api->make_number
+#define make_string(id, str, len)      api->api_make_string(id, str, len, 0)
+#define dup_string(id, str, len)       api->api_make_string(id, str, len, 1)
+#define make_number            api->api_make_number
 
 #define emalloc(pointer, type, size, message) \
        do { \
@@ -356,6 +358,50 @@ typedef struct gawk_api {
  * on failure and non-zero on success.
  */
 
+extern int dl_load(const gawk_api_t *const api_p, awk_ext_id_t id);
+
+
+/* TODO: Turn this into a macro... */
+#if 0
+/* Boiler plate code: */
+
+static gawk_api_t *const api;
+static awk_ext_id_t ext_id;
+
+int dl_load(const gawk_api_t *const api_p, awk_ext_id_t id);
+{
+       static awk_ext_func_t func_table[] = {
+               { "name", do_name, 1 },
+               /* ... */
+       };
+       size_t i, j;
+       int errors = 0;
+
+       if (api->major_version != GAWK_API_MAJOR_VERSION
+           || api->minor_version < GAWK_API_MINOR_VERSION) {
+               fprintf(stderr, "<NAME>: version mismatch with gawk!\n");
+               fprintf(stderr, "\tmy version (%d, %d), gawk version (%d, 
%d)\n",
+                       GAWK_API_MAJOR_VERSION, GAWK_API_MINOR_VERSION,
+                       api->major_version, api->minor_version);
+               exit(1);
+       }
+
+       api = api_p;
+       ext_id = id;
+
+       /* load functions */
+       for (i = 0, j = sizeof(func_table) / sizeof(func_table[0]); i < j; i++) 
{
+               if (! add_ext_func(ext_id, & func_table[i], "" /* "NAME" */)) {
+                       warning(ext_id, "<NAME>: could not add %s\n",
+                                       func_table[i].name);
+                       errors++;
+               }
+       }
+
+       return (errors == 0);
+}
+#endif
+
 #ifdef __cplusplus
 }
 #endif /* C++ */

-----------------------------------------------------------------------

Summary of changes:
 extension/filefuncs2.c |   23 ++++++++++++------
 gawkapi.c              |   21 +++++++++++++++--
 gawkapi.h              |   58 +++++++++++++++++++++++++++++++++++++++++++-----
 3 files changed, 85 insertions(+), 17 deletions(-)


hooks/post-receive
-- 
gawk



reply via email to

[Prev in Thread] Current Thread [Next in Thread]