[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gawk-diffs] [SCM] gawk branch, feature/namespaces, updated. gawk-4.1.0-
From: |
Arnold Robbins |
Subject: |
[gawk-diffs] [SCM] gawk branch, feature/namespaces, updated. gawk-4.1.0-2627-g112e041 |
Date: |
Tue, 11 Jul 2017 01:25:50 -0400 (EDT) |
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, feature/namespaces has been updated
via 112e04137a4d519f9cf1bedf372f7271bedfdf4e (commit)
from 8f532881651b96d1cbe21cbf1e97e6726bf663d2 (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=112e04137a4d519f9cf1bedf372f7271bedfdf4e
commit 112e04137a4d519f9cf1bedf372f7271bedfdf4e
Author: Arnold D. Robbins <address@hidden>
Date: Tue Jul 11 08:25:33 2017 +0300
Continue adding namespace support to the extension API.
diff --git a/ChangeLog b/ChangeLog
index 030b02c..05a6ca0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,18 @@
2017-07-11 Arnold D. Robbins <address@hidden>
+ Continue adding namespace support to the extension API.
+
+ * awk.h (make_builtin): Add leading name_space parameter.
+ * ext.c (make_builtin): Add leading name_space parameter.
+ Do the appropriate checking and building of a name before
+ installing in the symbol table.
+ * gawkapi.c (add_ext_func): Use name_space, not namespace.
+ Check that the parameter isn't NULL.
+ (api_sym_lookup, api_sym_update): Use name_space, not namespace.
+ * gawkapi.h: Use name_space, not namespace, everywhere.
+
+2017-07-11 Arnold D. Robbins <address@hidden>
+
* awk.h (is_letter): Add declaration.
* ext.c (is_valid_identifier): New function.
(make_builtin): Use is_valid_identifier instead of inline code.
diff --git a/awk.h b/awk.h
index db5c8be..d0786f0 100644
--- a/awk.h
+++ b/awk.h
@@ -1517,7 +1517,7 @@ extern NODE *do_ext(int nargs);
void load_ext(const char *lib_name); /* temporary */
extern void close_extensions(void);
#ifdef DYNAMIC
-extern awk_bool_t make_builtin(const awk_ext_func_t *);
+extern awk_bool_t make_builtin(const char *name_space, const awk_ext_func_t *);
extern NODE *get_argument(int);
extern NODE *get_actual_argument(NODE *, int, bool);
#define get_scalar_argument(n, i) get_actual_argument((n), (i), false)
diff --git a/ext.c b/ext.c
index 6640f02..99bc159 100644
--- a/ext.c
+++ b/ext.c
@@ -99,12 +99,13 @@ is_valid_identifier(const char *name)
/* make_builtin --- register name to be called as func with a builtin body */
awk_bool_t
-make_builtin(const awk_ext_func_t *funcinfo)
+make_builtin(const char *name_space, const awk_ext_func_t *funcinfo)
{
NODE *symbol, *f;
INSTRUCTION *b;
const char *name = funcinfo->name;
int count = funcinfo->max_expected_args;
+ const char *install_name;
if (name == NULL || *name == '\0')
fatal(_("make_builtin: missing function name"));
@@ -112,8 +113,22 @@ make_builtin(const awk_ext_func_t *funcinfo)
if (! is_valid_identifier(name))
return awk_false;
- // FIXME: Handle namespaces here
- f = lookup(name, false);
+ assert(name_space != NULL);
+ if (name_space[0] == '\0' || strcmp(name_space, awk_namespace) == 0) {
+ f = lookup(name, false);
+ install_name = estrdup(name, strlen(name));
+ } else {
+ if (! is_valid_identifier(name_space))
+ return awk_false;
+
+ size_t len = strlen(name_space) + 2 + strlen(name) + 1;
+ char *buf;
+ emalloc(buf, char *, len, "make_builtin");
+ sprintf(buf, "%s::%s", name_space, name);
+ install_name = buf;
+
+ f = lookup(install_name, false);
+ }
if (f != NULL) {
if (f->type == Node_func) {
@@ -129,6 +144,8 @@ make_builtin(const awk_ext_func_t *funcinfo)
fatal(_("make_builtin: function name `%s' previously
defined"), name);
} else if (check_special(name) >= 0)
fatal(_("make_builtin: can't use gawk built-in `%s' as function
name"), name);
+ // else
+ // what to do if f == NULL?
if (count < 0)
fatal(_("make_builtin: negative argument count for function
`%s'"),
@@ -140,7 +157,7 @@ make_builtin(const awk_ext_func_t *funcinfo)
/* NB: extension sub must return something */
- symbol = install_symbol(estrdup(name, strlen(name)),
Node_ext_func);
+ symbol = install_symbol(install_name, Node_ext_func);
symbol->code_ptr = b;
track_ext_func(name);
return awk_true;
diff --git a/gawkapi.c b/gawkapi.c
index 5b1e635..015a046 100644
--- a/gawkapi.c
+++ b/gawkapi.c
@@ -335,17 +335,19 @@ 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 char *name_space,
awk_ext_func_t *func)
{
(void) id;
- (void) namespace;
if (func == NULL)
return awk_false;
+ if (name_space == NULL)
+ fatal(_("add_ext_func: received NULL name_space parameter"));
+
#ifdef DYNAMIC
- return make_builtin(func);
+ return make_builtin(name_space, func);
#else
return awk_false;
#endif
@@ -675,7 +677,7 @@ node_to_awk_value(NODE *node, awk_value_t *val,
awk_valtype_t wanted)
static awk_bool_t
api_sym_lookup(awk_ext_id_t id,
- const char *namespace,
+ const char *name_space,
const char *name,
awk_valtype_t wanted,
awk_value_t *result)
@@ -721,7 +723,7 @@ api_sym_lookup_scalar(awk_ext_id_t id,
static awk_bool_t
api_sym_update(awk_ext_id_t id,
- const char *namespace,
+ const char *name_space,
const char *name,
awk_value_t *value)
{
diff --git a/gawkapi.h b/gawkapi.h
index 627b721..102520b 100644
--- a/gawkapi.h
+++ b/gawkapi.h
@@ -475,7 +475,7 @@ typedef struct gawk_api {
* 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_bool_t (*api_add_ext_func)(awk_ext_id_t id, const char *name_space,
awk_ext_func_t *func);
/* Register an input parser; for opening files read-only */
@@ -603,7 +603,7 @@ typedef struct gawk_api {
* }
*/
awk_bool_t (*api_sym_lookup)(awk_ext_id_t id,
- const char *namespace,
+ const char *name_space,
const char *name,
awk_valtype_t wanted,
awk_value_t *result);
@@ -615,7 +615,7 @@ typedef struct gawk_api {
* Such an attempt returns false.
*/
awk_bool_t (*api_sym_update)(awk_ext_id_t id,
- const char *namespace,
+ const char *name_space,
const char *name,
awk_value_t *value);
@@ -840,10 +840,10 @@ typedef struct gawk_api {
#define sym_update(name, value) \
sym_update_ns("", name, value)
-#define sym_lookup_ns(namespace, name, wanted, result) \
- (api->api_sym_lookup(ext_id, namespace, name, wanted, result))
-#define sym_update_ns(namespace, name, value) \
- (api->api_sym_update(ext_id, namespace, name, value))
+#define sym_lookup_ns(name_space, name, wanted, result) \
+ (api->api_sym_lookup(ext_id, name_space, name, wanted, result))
+#define sym_update_ns(name_space, name, value) \
+ (api->api_sym_update(ext_id, name_space, name, value))
#define sym_lookup_scalar(scalar_cookie, wanted, result) \
(api->api_sym_lookup_scalar(ext_id, scalar_cookie, wanted, result))
-----------------------------------------------------------------------
Summary of changes:
ChangeLog | 13 +++++++++++++
awk.h | 2 +-
ext.c | 25 +++++++++++++++++++++----
gawkapi.c | 12 +++++++-----
gawkapi.h | 14 +++++++-------
5 files changed, 49 insertions(+), 17 deletions(-)
hooks/post-receive
--
gawk
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gawk-diffs] [SCM] gawk branch, feature/namespaces, updated. gawk-4.1.0-2627-g112e041,
Arnold Robbins <=