aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog14
-rw-r--r--awk.h62
-rw-r--r--eval.c1
-rw-r--r--main.c4
-rw-r--r--node.c15
5 files changed, 45 insertions, 51 deletions
diff --git a/ChangeLog b/ChangeLog
index 17f53df6..352d9da1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2012-01-30 Andrew J. Schorr <aschorr@telemetry-investments.com>
+
+ Further cleanups of macros in awk.h
+
+ * awk.h (_r, _t): Remove declarations.
+ (unref, m_force_string): Remove macros.
+ (r_unref): Move declaration.
+ (r_force_string): Remove declaration.
+ (DEREF, force_string, force_number, unref): Now inline functions.
+ (POP_STRING, TOP_STRING): Back to macros.
+ * eval.c (_t): Remove definition.
+ * main.c (_r): Remove definition.
+ * node.c (r_force_string): Remove.
+
2012-11-27 Arnold D. Robbins <arnold@skeeve.com>
* builtin.c (do_fflush): Make fflush() and fflush("") both
diff --git a/awk.h b/awk.h
index 557e0360..a35484f0 100644
--- a/awk.h
+++ b/awk.h
@@ -1034,9 +1034,6 @@ extern int (*cmp_numbers)(const NODE *, const NODE *);
typedef int (*Func_pre_exec)(INSTRUCTION **);
typedef void (*Func_post_exec)(INSTRUCTION *);
-extern NODE *_t; /* used as temporary in macros */
-extern NODE *_r; /* used as temporary in macros */
-
extern BLOCK nextfree[];
extern bool field0_valid;
@@ -1157,7 +1154,14 @@ extern STACK_ITEM *stack_top;
#define UPREF(r) (void) ((r)->valref++)
-#define DEREF(r) ( _r = (r), (--_r->valref == 0) ? r_unref(_r) : (void)0 )
+extern void r_unref(NODE *tmp);
+
+static inline void
+DEREF(NODE *r)
+{
+ if (--r->valref == 0)
+ r_unref(r);
+}
#define POP_NUMBER() force_number(POP_SCALAR())
#define TOP_NUMBER() force_number(TOP_SCALAR())
@@ -1238,24 +1242,33 @@ extern STACK_ITEM *stack_top;
#define efree(p) free(p)
-#define force_string(s) (_t = (s), m_force_string(_t))
+static inline NODE *
+force_string(NODE *s)
+{
+ if ((s->flags & STRCUR) != 0
+ && (s->stfmt == -1 || s->stfmt == CONVFMTidx)
+ )
+ return s;
+ return format_val(CONVFMT, CONVFMTidx, s);
+}
#ifdef GAWKDEBUG
#define unref r_unref
-#define m_force_string r_force_string
-extern NODE *r_force_string(NODE *s);
#define force_number str2number
#else /* not GAWKDEBUG */
-#define unref(r) ( _r = (r), (_r == NULL || --_r->valref > 0) ? \
- (void)0 : r_unref(_r) )
-
-#define m_force_string(_ts) (((_ts->flags & STRCUR) && \
- (_ts->stfmt == -1 || _ts->stfmt == CONVFMTidx)) ? \
- _ts : format_val(CONVFMT, CONVFMTidx, _ts))
+static inline void
+unref(NODE *r)
+{
+ if (r != NULL && --r->valref <= 0)
+ r_unref(r);
+}
-#define force_number(n) (_t = (n), \
- (_t->flags & NUMCUR) ? _t : str2number(_t))
+static inline NODE *
+force_number(NODE *n)
+{
+ return (n->flags & NUMCUR) ? n : str2number(n);
+}
#endif /* GAWKDEBUG */
@@ -1549,7 +1562,6 @@ extern NODE *r_format_val(const char *format, int index, NODE *s);
extern NODE *r_dupnode(NODE *n);
extern NODE *make_str_node(const char *s, size_t len, int flags);
extern void *more_blocks(int id);
-extern void r_unref(NODE *tmp);
extern int parse_escape(const char **string_ptr);
#if MBS_SUPPORT
extern NODE *str2wstr(NODE *n, size_t **ptr);
@@ -1711,24 +1723,10 @@ TOP_SCALAR()
}
/* POP_STRING --- pop the string at the top of the stack */
-
-static inline NODE *
-POP_STRING()
-{
- NODE *s = POP_SCALAR();
-
- return m_force_string(s);
-}
+#define POP_STRING() force_string(POP_SCALAR())
/* TOP_STRING --- get the string at the top of the stack */
-
-static inline NODE *
-TOP_STRING()
-{
- NODE *s = TOP_SCALAR();
-
- return m_force_string(s);
-}
+#define TOP_STRING() force_string(TOP_SCALAR())
/* in_array --- return pointer to element in array if there */
diff --git a/eval.c b/eval.c
index 69b830af..2db2a7dc 100644
--- a/eval.c
+++ b/eval.c
@@ -43,7 +43,6 @@ static Func_post_exec post_execute = NULL;
extern void frame_popped();
-NODE *_t; /* used as a temporary in macros */
int OFSlen;
int ORSlen;
int OFMTidx;
diff --git a/main.c b/main.c
index 5e84a3c7..6174dd93 100644
--- a/main.c
+++ b/main.c
@@ -71,8 +71,6 @@ NODE *RLENGTH_node, *RSTART_node, *RS_node, *RT_node, *SUBSEP_node;
NODE *PREC_node, *ROUNDMODE_node;
NODE *TEXTDOMAIN_node;
-NODE *_r; /* used as temporary in stack macros */
-
long NF;
long NR;
long FNR;
@@ -86,7 +84,7 @@ char *TEXTDOMAIN;
/*
* CONVFMT is a convenience pointer for the current number to string format.
* We must supply an initial value to avoid recursion problems of
- * set_CONVFMT -> fmt_index -> r_force_string: gets NULL CONVFMT
+ * set_CONVFMT -> fmt_index -> force_string: gets NULL CONVFMT
* Fun, fun, fun, fun.
*/
char *CONVFMT = "%.6g";
diff --git a/node.c b/node.c
index a857aa1d..8d9354f6 100644
--- a/node.c
+++ b/node.c
@@ -260,21 +260,6 @@ no_malloc:
return s;
}
-
-/* r_force_string --- force a value to be a string */
-
-#ifdef GAWKDEBUG
-NODE *
-r_force_string(NODE *s)
-{
- if ((s->flags & STRCUR) != 0
- && (s->stfmt == -1 || s->stfmt == CONVFMTidx)
- )
- return s;
- return format_val(CONVFMT, CONVFMTidx, s);
-}
-#endif
-
/* r_dupnode --- duplicate a node */
NODE *