aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog2
-rw-r--r--extension/ChangeLog3
-rw-r--r--extension/filefuncs.c1
-rw-r--r--extension/fork.c1
-rw-r--r--extension/ordchr.c1
-rw-r--r--extension/readfile.c1
-rw-r--r--extension/rwarray.c1
-rw-r--r--extension/testext.c1
-rw-r--r--extension/time.c1
-rw-r--r--gawkapi.h26
10 files changed, 37 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 2429bd8b..83057189 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -12,6 +12,8 @@
(make_const_string): New macro, renamed from dup_string.
(make_malloced_string): New macro, renamed from make_string.
(make_null_string): New inline function.
+ (dl_load_func): Add call to init routine through pointer if
+ not NULL.
* gawkapi.c (awk_value_to_node): Assume that string values came
from malloc.
diff --git a/extension/ChangeLog b/extension/ChangeLog
index be315619..2ea13e36 100644
--- a/extension/ChangeLog
+++ b/extension/ChangeLog
@@ -9,6 +9,9 @@
(test_array_elem): Duplicate strings coming from gawk before passing
them back in.
+ All files: Add null 'init_func' file pointer for dl_load_func
+ to work.
+
2012-07-09 Arnold D. Robbins <arnold@skeeve.com>
* filefuncs.c (do_readfile): Return "" and set ERRNO on error
diff --git a/extension/filefuncs.c b/extension/filefuncs.c
index 74af8b1b..71387cb3 100644
--- a/extension/filefuncs.c
+++ b/extension/filefuncs.c
@@ -44,6 +44,7 @@
static const gawk_api_t *api; /* for convenience macros to work */
static awk_ext_id_t *ext_id;
+static awk_bool_t (*init_func)(void) = NULL;
int plugin_is_GPL_compatible;
diff --git a/extension/fork.c b/extension/fork.c
index 84232663..02b6b6f2 100644
--- a/extension/fork.c
+++ b/extension/fork.c
@@ -41,6 +41,7 @@
static const gawk_api_t *api; /* for convenience macros to work */
static awk_ext_id_t *ext_id;
+static awk_bool_t (*init_func)(void) = NULL;
int plugin_is_GPL_compatible;
diff --git a/extension/ordchr.c b/extension/ordchr.c
index 3ab0f872..7773f1b9 100644
--- a/extension/ordchr.c
+++ b/extension/ordchr.c
@@ -43,6 +43,7 @@
static const gawk_api_t *api; /* for convenience macros to work */
static awk_ext_id_t *ext_id;
+static awk_bool_t (*init_func)(void) = NULL;
int plugin_is_GPL_compatible;
diff --git a/extension/readfile.c b/extension/readfile.c
index 1b6772fe..f9a364fb 100644
--- a/extension/readfile.c
+++ b/extension/readfile.c
@@ -50,6 +50,7 @@
static const gawk_api_t *api; /* for convenience macros to work */
static awk_ext_id_t *ext_id;
+static awk_bool_t (*init_func)(void) = NULL;
int plugin_is_GPL_compatible;
diff --git a/extension/rwarray.c b/extension/rwarray.c
index 64c501dd..8a749498 100644
--- a/extension/rwarray.c
+++ b/extension/rwarray.c
@@ -47,6 +47,7 @@
static const gawk_api_t *api; /* for convenience macros to work */
static awk_ext_id_t *ext_id;
+static awk_bool_t (*init_func)(void) = NULL;
int plugin_is_GPL_compatible;
diff --git a/extension/testext.c b/extension/testext.c
index 8dac1c2b..d446fb8e 100644
--- a/extension/testext.c
+++ b/extension/testext.c
@@ -39,6 +39,7 @@
static const gawk_api_t *api; /* for convenience macros to work */
static awk_ext_id_t *ext_id;
+static awk_bool_t (*init_func)(void) = NULL;
int plugin_is_GPL_compatible;
diff --git a/extension/time.c b/extension/time.c
index 2024510c..eb42eee2 100644
--- a/extension/time.c
+++ b/extension/time.c
@@ -39,6 +39,7 @@
static const gawk_api_t *api; /* for convenience macros to work */
static awk_ext_id_t *ext_id;
+static awk_bool_t (*init_func)(void) = NULL;
int plugin_is_GPL_compatible;
diff --git a/gawkapi.h b/gawkapi.h
index 2bef258e..9f541cfc 100644
--- a/gawkapi.h
+++ b/gawkapi.h
@@ -533,9 +533,13 @@ make_number(double num, awk_value_t *result)
*
* int dl_load(gawk_api_t *api_p, awk_ext_id_t id)
*
+ * The return value should be zero on failure and non-zero on success.
+ *
* For the macros to work, the function should save api_p in a global
* variable named 'api' and save id in a global variable named 'ext_id'.
- * The return value should be zero on failure and non-zero on success.
+ * In addition, a global function pointer named 'init_func' should be
+ * defined and set to either NULL or an initialization function that
+ * returns non-zero on success and zero upon failure.
*/
extern int dl_load(const gawk_api_t *const api_p, awk_ext_id_t id);
@@ -549,6 +553,19 @@ static awk_ext_func_t func_table[] = {
/* ... */
};
+/* EITHER: */
+
+static awk_bool_t (*init_func)(void) = NULL;
+
+/* OR: */
+
+static awk_bool_t init_my_module(void)
+{
+ ...
+}
+
+static awk_bool_t (*init_func)(void) = init_my_module;
+
dl_load_func(func_table, some_name, "name_space_in_quotes")
#endif
@@ -579,6 +596,13 @@ int dl_load(const gawk_api_t *const api_p, awk_ext_id_t id) \
} \
} \
\
+ if (init_func != NULL) { \
+ if (! init_func()) { \
+ warning(ext_id, #module ": initialization function failed\n"); \
+ errors++; \
+ } \
+ } \
+\
return (errors == 0); \
}