[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-2609-gd89203d |
Date: |
Sat, 1 Jul 2017 15:40:44 -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 d89203dbf1db050a5d39f488b0fc12b17b3d452f (commit)
from d4ec80371e61d6404b02541503b642ddb93c45cb (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=d89203dbf1db050a5d39f488b0fc12b17b3d452f
commit d89203dbf1db050a5d39f488b0fc12b17b3d452f
Author: Arnold D. Robbins <address@hidden>
Date: Sat Jul 1 22:40:09 2017 +0300
Fix install function params, improve pretty printing.
diff --git a/ChangeLog b/ChangeLog
index fdae359..c2e94fc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2017-07-01 Arnold D. Robbins <address@hidden>
+
+ * symbol.c (install): Don't call fix_up_namespace if
+ installing parameters.
+ * profile.c (remove_namespace): Renamed to
+ (adjust_namespace): Make smarter and add boolean parameter for
+ if return was mallc'ed. Adjust calls.
+
2017-06-30 Arnold D. Robbins <address@hidden>
Add namespace info into Op_Rule and Op_Func.
diff --git a/profile.c b/profile.c
index 80456a6..82006f3 100644
--- a/profile.c
+++ b/profile.c
@@ -42,7 +42,7 @@ static NODE *pp_pop(void);
static void print_comment(INSTRUCTION *pc, long in);
const char *redir2str(int redirtype);
static void pp_namespace(const char *name);
-static char *remove_namespace(char *name);
+static char *adjust_namespace(char *name, bool *malloced);
#define pp_str vname
#define pp_len sub.nodep.reserved
@@ -344,9 +344,12 @@ pprint(INSTRUCTION *startp, INSTRUCTION *endp, int flags)
case Node_var:
case Node_var_new:
case Node_var_array:
- if (m->vname != NULL)
- pp_push(pc->opcode,
remove_namespace(m->vname), DONT_FREE);
- else
+ if (m->vname != NULL) {
+ bool malloced = false;
+ char *name = adjust_namespace(m->vname,
& malloced);
+
+ pp_push(pc->opcode, name, malloced ?
CAN_FREE : DONT_FREE);
+ } else
fatal(_("internal error: %s with null
vname"),
nodetype2str(m->type));
break;
@@ -1752,7 +1755,12 @@ pp_func(INSTRUCTION *pc, void *data ATTRIBUTE_UNUSED)
}
indent(pc->nexti->exec_count);
- fprintf(prof_fp, "%s %s(", op2str(Op_K_function),
remove_namespace(func->vname));
+
+ bool malloced = false;
+ char *name = adjust_namespace(func->vname, & malloced);
+ fprintf(prof_fp, "%s %s(", op2str(Op_K_function), name);
+ if (malloced)
+ free(name);
pcount = func->param_cnt;
func_params = func->fparms;
for (j = 0; j < pcount; j++) {
@@ -1822,11 +1830,28 @@ pp_namespace(const char *name)
fprintf(prof_fp, "\"\n\n");
}
-/* remove_namespace --- remove leading namespace if that's the right thing to
do */
+/* adjust_namespace --- remove leading namespace or add leading awk:: */
static char *
-remove_namespace(char *name)
+adjust_namespace(char *name, bool *malloced)
{
+ *malloced = false;
+
+ // unadorned name from symbol table, add awk:: if not in awk:: n.s.
+ if (strchr(name, ':') == NULL &&
+ current_namespace != awk_namespace && // can be equal if
namespace never changed
+ strcmp(current_namespace, "awk::") != 0) {
+ char *buf;
+ size_t len = 5 + strlen(name) + 1;
+
+ emalloc(buf, char *, len, "adjust_namespace");
+ sprintf(buf, "awk::%s", name);
+ *malloced = true;
+
+ return buf;
+ }
+
+ // qualifed name, remove <ns>:: if in that n.s.
size_t len = strlen(current_namespace);
if (strncmp(current_namespace, name, len) == 0) {
diff --git a/symbol.c b/symbol.c
index 9ff6fd8..4d50214 100644
--- a/symbol.c
+++ b/symbol.c
@@ -312,12 +312,16 @@ install(const char *name, NODE *parm, NODETYPE type)
NODE *prev;
bool malloced = false;
- name = fix_up_namespace(name, & malloced);
-
- if (malloced)
- n_name = make_str_node(name, strlen(name), ALREADY_MALLOCED);
- else
+ if (type == Node_param_list) {
n_name = make_string(name, strlen(name));
+ } else {
+ name = fix_up_namespace(name, & malloced);
+
+ if (malloced)
+ n_name = make_str_node(name, strlen(name),
ALREADY_MALLOCED);
+ else
+ n_name = make_string(name, strlen(name));
+ }
table = symbol_table;
diff --git a/test/ChangeLog b/test/ChangeLog
index 047b3e0..6456fc1 100644
--- a/test/ChangeLog
+++ b/test/ChangeLog
@@ -1,3 +1,8 @@
+2017-07-01 Arnold D. Robbins <address@hidden>
+
+ * Makefile.am (nsprof2): New test.
+ * nsprof2.awk, nsprof2.ok: New files.
+
2017-06-30 Arnold D. Robbins <address@hidden>
* Makefile.am (nsprof1): New test.
diff --git a/test/Makefile.am b/test/Makefile.am
index 95c0bd0..d51323d 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -739,6 +739,8 @@ EXTRA_DIST = \
nors.ok \
nsprof1.awk \
nsprof1.ok \
+ nsprof2.awk \
+ nsprof2.ok \
nulinsrc.awk \
nulinsrc.ok \
nulrsend.awk \
@@ -1260,7 +1262,7 @@ GAWK_EXT_TESTS = \
muldimposix \
nastyparm negtime next nondec nondec2 \
nonfatal1 nonfatal2 nonfatal3 \
- nsprof1 \
+ nsprof1 nsprof2 \
patsplit posix printfbad1 printfbad2 printfbad3 printfbad4 printhuge
procinfs \
profile0 profile1 profile2 profile3 profile4 profile5 profile6 profile7
\
profile8 profile9 profile10 pty1 \
@@ -2429,6 +2431,11 @@ nsprof1:
@$(AWK) --pretty-print=_$@ -f "$(srcdir)"/address@hidden < /dev/null
@-$(CMP) "$(srcdir)"/address@hidden _$@ && rm -f _$@
+nsprof2:
+ @echo $@
+ @$(AWK) --pretty-print=_$@ -f "$(srcdir)"/address@hidden < /dev/null
+ @-$(CMP) "$(srcdir)"/address@hidden _$@ && rm -f _$@
+
# Targets generated for other tests:
include Maketests
diff --git a/test/Makefile.in b/test/Makefile.in
index 3d56dd2..4d81b85 100644
--- a/test/Makefile.in
+++ b/test/Makefile.in
@@ -997,6 +997,8 @@ EXTRA_DIST = \
nors.ok \
nsprof1.awk \
nsprof1.ok \
+ nsprof2.awk \
+ nsprof2.ok \
nulinsrc.awk \
nulinsrc.ok \
nulrsend.awk \
@@ -1517,7 +1519,7 @@ GAWK_EXT_TESTS = \
muldimposix \
nastyparm negtime next nondec nondec2 \
nonfatal1 nonfatal2 nonfatal3 \
- nsprof1 \
+ nsprof1 nsprof2 \
patsplit posix printfbad1 printfbad2 printfbad3 printfbad4 printhuge
procinfs \
profile0 profile1 profile2 profile3 profile4 profile5 profile6 profile7
\
profile8 profile9 profile10 pty1 \
@@ -2866,6 +2868,11 @@ nsprof1:
@echo $@
@$(AWK) --pretty-print=_$@ -f "$(srcdir)"/address@hidden < /dev/null
@-$(CMP) "$(srcdir)"/address@hidden _$@ && rm -f _$@
+
+nsprof2:
+ @echo $@
+ @$(AWK) --pretty-print=_$@ -f "$(srcdir)"/address@hidden < /dev/null
+ @-$(CMP) "$(srcdir)"/address@hidden _$@ && rm -f _$@
Gt-dummy:
# file Maketests, generated from Makefile.am by the Gentests program
addcomma:
diff --git a/test/nsprof2.awk b/test/nsprof2.awk
new file mode 100644
index 0000000..b862b9f
--- /dev/null
+++ b/test/nsprof2.awk
@@ -0,0 +1,70 @@
+# passwd.awk --- access password file information
+#
+# Arnold Robbins, address@hidden, Public Domain
+# May 1993
+# Revised October 2000
+# Revised December 2010
+# Revised July 2017
+
address@hidden "passwd"
+
+BEGIN {
+ # tailor this to suit your system
+ Awklib = "/usr/local/libexec/awk/"
+}
+
+function Init( oldfs, oldrs, olddol0, pwcat, using_fw, using_fpat)
+{
+ if (Inited)
+ return
+
+ oldfs = FS
+ oldrs = RS
+ olddol0 = $0
+ using_fw = (PROCINFO["FS"] == "FIELDWIDTHS")
+ using_fpat = (PROCINFO["FS"] == "FPAT")
+ FS = ":"
+ RS = "\n"
+
+ pwcat = Awklib "pwcat"
+ while ((pwcat | getline) > 0) {
+ Byname[$1] = $0
+ Byuid[$3] = $0
+ Bycount[++Total] = $0
+ }
+ close(pwcat)
+ Count = 0
+ Inited = 1
+ FS = oldfs
+ if (using_fw)
+ FIELDWIDTHS = FIELDWIDTHS
+ else if (using_fpat)
+ FPAT = FPAT
+ RS = oldrs
+ $0 = olddol0
+}
+
+function awk::getpwnam(name)
+{
+ Init()
+ return Byname[name]
+}
+
+function awk::getpwuid(uid)
+{
+ Init()
+ return Byuid[uid]
+}
+
+function awk::getpwent()
+{
+ Init()
+ if (Count < Total)
+ return Bycount[++Count]
+ return ""
+}
+
+function awk::endpwent()
+{
+ Count = 0
+}
diff --git a/test/nsprof2.ok b/test/nsprof2.ok
new file mode 100644
index 0000000..5fc805c
--- /dev/null
+++ b/test/nsprof2.ok
@@ -0,0 +1,71 @@
+# passwd.awk --- access password file information
+#
+# Arnold Robbins, address@hidden, Public Domain
+# May 1993
+# Revised October 2000
+# Revised December 2010
+# Revised July 2017
address@hidden "passwd"
+
+BEGIN {
+ # tailor this to suit your system
+ Awklib = "/usr/local/libexec/awk/"
+}
+
+
+function awk::endpwent()
+{
+ Count = 0
+}
+
+function awk::getpwent()
+{
+ Init()
+ if (Count < Total) {
+ return Bycount[++Count]
+ }
+ return ""
+}
+
+function awk::getpwnam(name)
+{
+ Init()
+ return Byname[name]
+}
+
+function awk::getpwuid(uid)
+{
+ Init()
+ return Byuid[uid]
+}
+
+function Init(oldfs, oldrs, olddol0, pwcat, using_fw, using_fpat)
+{
+ if (Inited) {
+ return
+ }
+ oldfs = awk::FS
+ oldrs = awk::RS
+ olddol0 = $0
+ using_fw = (awk::PROCINFO["FS"] == "FIELDWIDTHS")
+ using_fpat = (awk::PROCINFO["FS"] == "FPAT")
+ awk::FS = ":"
+ awk::RS = "\n"
+ pwcat = Awklib "pwcat"
+ while ((pwcat | getline) > 0) {
+ Byname[$1] = $0
+ Byuid[$3] = $0
+ Bycount[++Total] = $0
+ }
+ close(pwcat)
+ Count = 0
+ Inited = 1
+ awk::FS = oldfs
+ if (using_fw) {
+ awk::FIELDWIDTHS = awk::FIELDWIDTHS
+ } else if (using_fpat) {
+ awk::FPAT = awk::FPAT
+ }
+ awk::RS = oldrs
+ $0 = olddol0
+}
-----------------------------------------------------------------------
Summary of changes:
ChangeLog | 8 +++
profile.c | 39 +++++++++++---
symbol.c | 14 +++--
test/ChangeLog | 5 ++
test/Makefile.am | 9 +++-
test/Makefile.in | 9 +++-
awklib/eg/lib/passwdawk.in => test/nsprof2.awk | 49 ++++++++++--------
test/nsprof2.ok | 71 ++++++++++++++++++++++++++
8 files changed, 169 insertions(+), 35 deletions(-)
copy awklib/eg/lib/passwdawk.in => test/nsprof2.awk (52%)
create mode 100644 test/nsprof2.ok
hooks/post-receive
--
gawk
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gawk-diffs] [SCM] gawk branch, feature/namespaces, updated. gawk-4.1.0-2609-gd89203d,
Arnold Robbins <=