summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org.ua>2008-09-08 21:20:39 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2008-09-08 21:20:39 (GMT)
commit4cd3031ed36e207ce341c0854636c9047cd35d24 (patch) (side-by-side diff)
tree6e9274a96c5fdb0984a6822e351eb7230d3319ef
parentda3381a039b1ab4878baa9e5fc9be39284a154f2 (diff)
downloadmailfromd-release_4_4_patches.tar.gz
mailfromd-release_4_4_patches.tar.bz2
* src/snarf.m4, src/bi_sprintf.m4, src/prog.h, src/bi_sieve.m4,release_4_4_patches
Ported r1655 from trunk. * src/prog.c: Ported r1655 and r1660 from trunk. * NEWS: Update, set version number 4.4.1. * configure.ac: set version number 4.4.1. git-svn-id: file:///svnroot/mailfromd/branches/release_4_4_patches@1661 7a8a7f39-df28-0410-adc6-e0d955640f24
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--ChangeLog10
-rw-r--r--NEWS7
-rw-r--r--configure.ac2
-rw-r--r--src/bi_sieve.m42
-rw-r--r--src/bi_sprintf.m419
-rw-r--r--src/prog.c276
-rw-r--r--src/prog.h4
-rw-r--r--src/snarf.m470
8 files changed, 270 insertions, 120 deletions
diff --git a/ChangeLog b/ChangeLog
index 3602649..5ab7946 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2008-09-08 Sergey Poznyakoff <gray@gnu.org.ua>
+
+ * src/snarf.m4, src/bi_sprintf.m4, src/prog.h, src/bi_sieve.m4,
+ Ported r1655 from trunk.
+
+ * src/prog.c: Ported r1655 and r1660 from trunk.
+
+ * NEWS: Update, set version number 4.4.1.
+ * configure.ac: set version number 4.4.1.
+
2008-03-10 Sergey Poznyakoff <gray@gnu.org.ua>
* doc/mailfromd.texi: Spell check. Add missing acknowledgments.
diff --git a/NEWS b/NEWS
index 674dbae..a212fcc 100644
--- a/NEWS
+++ b/NEWS
@@ -1,10 +1,15 @@
-Mailfromd NEWS -- history of user-visible changes. 2008-03-10
+Mailfromd NEWS -- history of user-visible changes. 2008-09-09
Copyright (C) 2005, 2006, 2007, 2008 Sergey Poznyakoff
See the end of file for copying conditions.
Please send mailfromd bug reports to <bug-mailfromd@gnu.org.ua>
+Version 4.4.1
+
+* Fix stack reallocation.
+
+
Version 4.4, 2008-03-10
* The --domain option is withdrawn.
diff --git a/configure.ac b/configure.ac
index 5a14617..5a6e224 100644
--- a/configure.ac
+++ b/configure.ac
@@ -17,7 +17,7 @@
AC_PREREQ(2.59)
m4_define([MF_VERSION_MAJOR], 4)
m4_define([MF_VERSION_MINOR], 4)
-dnl m4_define([MF_VERSION_PATCH], 0)
+m4_define([MF_VERSION_PATCH], 1)
AC_INIT([mailfromd],
MF_VERSION_MAJOR.MF_VERSION_MINOR[]m4_ifdef([MF_VERSION_PATCH],.MF_VERSION_PATCH),
[bug-mailfromd@gnu.org.ua])
diff --git a/src/bi_sieve.m4 b/src/bi_sieve.m4
index 04ae8f9..0c5af27 100644
--- a/src/bi_sieve.m4
+++ b/src/bi_sieve.m4
@@ -151,7 +151,7 @@ MF_DEFUN(sieve, NUMBER, STRING script, OPTIONAL, NUMBER dbg)
mu_sieve_set_logger(mach, _sieve_action_log);
rc = mu_sieve_compile(mach, script);
- if (rc == 0){
+ if (rc == 0) {
mu_stream_t mstr = env_get_stream(env);
mu_attribute_t attr;
mu_message_t msg;
diff --git a/src/bi_sprintf.m4 b/src/bi_sprintf.m4
index afd63d3..051d2dc 100644
--- a/src/bi_sprintf.m4
+++ b/src/bi_sprintf.m4
@@ -150,8 +150,7 @@ MF_DEFUN_VARARGS(sprintf, STRING, STRING format)
if (isdigit(*p)) {
char *q = get_num(p, &n);
if (*q == '$') {
- num = (unsigned) MF_VA_ARG(n-1,
- NUMBER);
+ MF_VA_ARG(n-1, NUMBER, num);
p = q + 1;
if (num < 0) {
flags |= FMT_SPACEPFX;
@@ -161,7 +160,7 @@ MF_DEFUN_VARARGS(sprintf, STRING, STRING format)
break;
}
}
- num = MF_VA_ARG(i, NUMBER);
+ MF_VA_ARG(i, NUMBER, num);
i++;
if (num < 0) {
/* A negative field width is taken
@@ -193,14 +192,14 @@ MF_DEFUN_VARARGS(sprintf, STRING, STRING format)
if (isdigit(*p)) {
char *q = get_num(p, &n);
if (*q == '$') {
- num = MF_VA_ARG(n-1, NUMBER);
+ MF_VA_ARG(n-1, NUMBER, num);
if (num > 0)
prec = (unsigned) num;
p = q + 1;
break;
}
}
- num = MF_VA_ARG(i, NUMBER);
+ MF_VA_ARG(i, NUMBER, num);
i++;
if (num > 0)
prec = (unsigned) num;
@@ -211,7 +210,7 @@ MF_DEFUN_VARARGS(sprintf, STRING, STRING format)
argnum = i++;
switch (*p) {
case 's':
- str = MF_VA_ARG(argnum,STRING);
+ MF_VA_ARG(argnum, STRING, str);
n = strlen(str);
if (prec && prec < n)
n = prec;
@@ -235,7 +234,7 @@ MF_DEFUN_VARARGS(sprintf, STRING, STRING format)
case 'i':
case 'd':
- num = MF_VA_ARG(argnum,NUMBER);
+ MF_VA_ARG(argnum, NUMBER, num);
if (num < 0) {
negative = 1;
num = - num;
@@ -290,7 +289,7 @@ MF_DEFUN_VARARGS(sprintf, STRING, STRING format)
break;
case 'u':
- num = MF_VA_ARG(argnum,NUMBER);
+ MF_VA_ARG(argnum, NUMBER, num);
/* If a precision is given with a
numeric conversion, the 0 flag is ignored.
*/
@@ -323,7 +322,7 @@ MF_DEFUN_VARARGS(sprintf, STRING, STRING format)
case 'x':
case 'X':
- num = MF_VA_ARG(argnum,NUMBER);
+ MF_VA_ARG(argnum, NUMBER, num);
/* If a precision is given with a
numeric conversion, the 0 flag is ignored.
*/
@@ -369,7 +368,7 @@ MF_DEFUN_VARARGS(sprintf, STRING, STRING format)
break;
case 'o':
- num = MF_VA_ARG(argnum,NUMBER);
+ MF_VA_ARG(argnum, NUMBER, num);
/* If a precision is given with a
numeric conversion, the 0 flag is ignored.
*/
diff --git a/src/prog.c b/src/prog.c
index 2662110..9dc17da 100644
--- a/src/prog.c
+++ b/src/prog.c
@@ -235,6 +235,10 @@ disable_prog_trace(const char *modlist)
/* Run-time evaluation */
+/* Max. number of C locals to save in struct eval_environ for eventual fixups.
+ See comment to env_fixup_autos, below. */
+#define MAX_AUTO_PTR 128
+
struct eval_environ {
prog_counter_t pc; /* Program counter */
@@ -253,6 +257,10 @@ struct eval_environ {
/* Temporary heap space */
size_t temp_start;
size_t temp_size;
+
+ STKVAL *auto_ptr[MAX_AUTO_PTR]; /* Pointers to C automatic variables
+ referring to dataseg. */
+ size_t numautos; /* Number of entries in auto_ptr. */
/* Sendmail interaction data: */
SMFICTX *ctx; /* Milter Context */
@@ -328,12 +336,52 @@ env_get_stream(eval_environ_t env)
return env->stream;
}
+
+/* A call to expand_dataseg (see below) invalidates any C variables that
+ pointed to dataseg before the call. To avoid dereferencing invalid memory
+ pointers, the addresses of such C variables are stored in env->auto_ptr
+ using env_register_auto (it is done by get_string_arg). When
+ expand_dataseg is called, it calls env_fixup_autos and passes it the
+ offset of new dataseg from old one. env_fixup_autos adds this value to
+ every address in auto_ptr, thereby fixing them.
+
+ The auto_ptr array is cleared (by calling env_unregister_autos) after
+ executing each instruction (see eval_environment).
+ */
+void
+env_register_auto(eval_environ_t env, void *ptr)
+{
+ if (env->numautos == MAX_AUTO_PTR)
+ runtime_error(env, "INTERNAL ERROR at %s:%d, please report",
+ __FILE__, __LINE__);
+ env->auto_ptr[env->numautos++] = ptr;
+}
+
+void
+env_unregister_autos(eval_environ_t env)
+{
+ env->numautos = 0;
+}
+
+void
+env_fixup_autos(eval_environ_t env, ptrdiff_t offset)
+{
+ int i;
+ for (i = 0; i < env->numautos; i++) {
+ STKVAL *pptr = env->auto_ptr[i];
+ *pptr += offset;
+ }
+}
+
+
#define STACK_EXPAND_BLOCK 64
static int
expand_dataseg(eval_environ_t env, size_t count, const char *errtext)
{
STKVAL *newds;
+ ptrdiff_t offset;
+
count = ((count + STACK_EXPAND_BLOCK - 1) / STACK_EXPAND_BLOCK)
* STACK_EXPAND_BLOCK;
newds = realloc(env->dataseg,
@@ -346,6 +394,7 @@ expand_dataseg(eval_environ_t env, size_t count, const char *errtext)
return 1;
}
+ offset = (char*)newds - (char*)env->dataseg;
env->dataseg = newds;
env->stack_size += count;
env->tos += count;
@@ -353,6 +402,7 @@ expand_dataseg(eval_environ_t env, size_t count, const char *errtext)
memmove(newds + env->tos, newds + env->tos - count,
(datasize + env->stack_size - env->tos)
* sizeof newds[0]);
+ env_fixup_autos(env, offset);
mu_error(_("Warning: stack segment expanded, new size=%lu"),
(unsigned long) env->stack_size);
return 0;
@@ -462,10 +512,11 @@ get_immediate(eval_environ_t env, unsigned n)
return prog[env->pc + n + 1];
}
-const char *
-get_literal(eval_environ_t env, unsigned n)
+void
+get_literal(eval_environ_t env, unsigned n, const char **p)
{
- return (char*)(env->dataseg + (size_t) get_immediate(env, n));
+ *p = (char*)(env->dataseg + (size_t) get_immediate(env, n));
+ env_register_auto(env, p);
}
STKVAL
@@ -474,25 +525,31 @@ get_arg(eval_environ_t env, unsigned n)
return env->dataseg[env->tos + n + 1];
}
-char *
-get_string_arg(eval_environ_t env, unsigned n)
+void
+get_string_arg(eval_environ_t env, unsigned n, char **p)
{
- return (char*) (env->dataseg + (size_t) get_arg(env, n));
+ *p = (char*) (env->dataseg + (size_t) get_arg(env, n));
+ env_register_auto(env, p);
}
-size_t
-get_numeric_arg(eval_environ_t env, unsigned n)
+void
+get_numeric_arg(eval_environ_t env, unsigned n, long *np)
{
- return (size_t) get_arg(env, n);
+ *np = (long) get_arg(env, n);
+}
+
+void
+get_pointer_arg(eval_environ_t env, unsigned n, void **p)
+{
+ *p = (void*) get_arg(env, n);
}
void
push(eval_environ_t env, STKVAL val)
{
- if (env->tos < env->toh)
+ if (env->tos < env->toh)
runtime_error(env, "INTERNAL ERROR at %s:%d, please report",
__FILE__, __LINE__);
-
if (env->tos == env->toh) {
debug2(100, "tos=%lu, toh=%lu",
(unsigned long) env->tos,
@@ -591,8 +648,8 @@ pushs(eval_environ_t env, char *s)
void
instr_locus(eval_environ_t env)
{
- env->locus.file = get_literal(env, 0);
env->locus.line = (size_t) get_immediate(env, 1);
+ get_literal(env, 0, &env->locus.file);
if (PROG_TRACE_ENGINE)
prog_trace(env, "LOCUS");
advance_pc(env, 2);
@@ -687,6 +744,14 @@ instr_stkalloc(eval_environ_t env)
unsigned n = (unsigned) get_immediate(env, 0);
if (PROG_TRACE_ENGINE)
prog_trace(env, "STKALLOC %p", n);
+ if (env->tos - n < env->toh) {
+ debug3(100, "tos=%lu, toh=%lu, delta=%u",
+ (unsigned long) env->tos,
+ (unsigned long) env->toh,
+ n);
+ expand_dataseg(env, env->toh - (env->tos - n),
+ _("Out of stack space; increase #pragma stacksize"));
+ }
env->tos -= n;
advance_pc(env, 1);
}
@@ -743,10 +808,13 @@ dump_backref(prog_counter_t i)
void
instr_ston(eval_environ_t env)
{
- char *s = get_string_arg(env, 0);
+ char *s;
char *p;
- long v = strtol(s, &p, 0);
+ long v;
+ get_string_arg(env, 0, &s);
+ v = strtol(s, &p, 0);
+
adjust_stack(env, 1);
if (PROG_TRACE_ENGINE)
prog_trace(env, "STON %s", s);
@@ -761,7 +829,7 @@ instr_ston(eval_environ_t env)
void
instr_ntos(eval_environ_t env)
{
- long v = (long) get_numeric_arg(env, 0);
+ long v = (long) get_arg(env, 0);
char buf[NUMERIC_BUFSIZE_BOUND];
adjust_stack(env, 1);
@@ -776,8 +844,8 @@ instr_ntos(eval_environ_t env)
void
instr_cmp(eval_environ_t env)
{
- long l = (long) get_numeric_arg(env, 1);
- long r = (long) get_numeric_arg(env, 0);
+ long l = (long) get_arg(env, 1);
+ long r = (long) get_arg(env, 0);
adjust_stack(env, 2);
if (PROG_TRACE_ENGINE)
prog_trace(env, "CMP %ld %ld", l, r);
@@ -787,8 +855,10 @@ instr_cmp(eval_environ_t env)
void
instr_symbol(eval_environ_t env)
{
- char *symbol = (char *) get_literal(env, 0);
- char *s = env->getsym(env->data, symbol);
+ char *symbol, *s;
+
+ get_literal(env, 0, (const char **)&symbol);
+ s = env->getsym(env->data, symbol);
if (PROG_TRACE_ENGINE)
prog_trace(env, "SYMBOL %s", symbol);
@@ -815,8 +885,8 @@ dump_symbol(prog_counter_t i)
void
instr_eqn(eval_environ_t env)
{
- long a = (long) get_numeric_arg(env, 1);
- long b = (long) get_numeric_arg(env, 0);
+ long a = (long) get_arg(env, 1);
+ long b = (long) get_arg(env, 0);
if (PROG_TRACE_ENGINE)
prog_trace(env, "EQN %ld %ld", a, b);
adjust_stack(env, 2);
@@ -826,8 +896,9 @@ instr_eqn(eval_environ_t env)
void
instr_eqs(eval_environ_t env)
{
- char *a = get_string_arg(env, 1);
- char *b = get_string_arg(env, 0);
+ char *a, *b;
+ get_string_arg(env, 1, &a);
+ get_string_arg(env, 0, &b);
if (PROG_TRACE_ENGINE)
prog_trace(env, "EQS %s %s", a, b);
adjust_stack(env, 2);
@@ -837,8 +908,8 @@ instr_eqs(eval_environ_t env)
void
instr_nen(eval_environ_t env)
{
- long a = (long) get_numeric_arg(env, 1);
- long b = (long) get_numeric_arg(env, 0);
+ long a = (long) get_arg(env, 1);
+ long b = (long) get_arg(env, 0);
if (PROG_TRACE_ENGINE)
prog_trace(env, "NEN %ld %ld", a, b);
adjust_stack(env, 2);
@@ -848,8 +919,10 @@ instr_nen(eval_environ_t env)
void
instr_nes(eval_environ_t env)
{
- char *a = get_string_arg(env, 1);
- char *b = get_string_arg(env, 0);
+ char *a, *b;
+
+ get_string_arg(env, 1, &a);
+ get_string_arg(env, 0, &b);
if (PROG_TRACE_ENGINE)
prog_trace(env, "NES %s %s", a, b);
adjust_stack(env, 2);
@@ -859,8 +932,8 @@ instr_nes(eval_environ_t env)
void
instr_ltn(eval_environ_t env)
{
- long a = (long) get_numeric_arg(env, 1);
- long b = (long) get_numeric_arg(env, 0);
+ long a = (long) get_arg(env, 1);
+ long b = (long) get_arg(env, 0);
if (PROG_TRACE_ENGINE)
prog_trace(env, "LTN %ld %ld", a, b);
adjust_stack(env, 2);
@@ -870,8 +943,10 @@ instr_ltn(eval_environ_t env)
void
instr_lts(eval_environ_t env)
{
- char *a = get_string_arg(env, 1);
- char *b = get_string_arg(env, 0);
+ char *a, *b;
+
+ get_string_arg(env, 1, &a);
+ get_string_arg(env, 0, &b);
if (PROG_TRACE_ENGINE)
prog_trace(env, "LTS %s %s", a, b);
adjust_stack(env, 2);
@@ -881,8 +956,8 @@ instr_lts(eval_environ_t env)
void
instr_len(eval_environ_t env)
{
- long a = (long) get_numeric_arg(env, 1);
- long b = (long) get_numeric_arg(env, 0);
+ long a = (long) get_arg(env, 1);
+ long b = (long) get_arg(env, 0);
if (PROG_TRACE_ENGINE)
prog_trace(env, "LEN %ld %ld", a, b);
adjust_stack(env, 2);
@@ -892,8 +967,10 @@ instr_len(eval_environ_t env)
void
instr_les(eval_environ_t env)
{
- char *a = get_string_arg(env, 1);
- char *b = get_string_arg(env, 0);
+ char *a, *b;
+
+ get_string_arg(env, 1, &a);
+ get_string_arg(env, 0, &b);
if (PROG_TRACE_ENGINE)
prog_trace(env, "LES %s %s", a, b);
adjust_stack(env, 2);
@@ -903,8 +980,8 @@ instr_les(eval_environ_t env)
void
instr_gtn(eval_environ_t env)
{
- long a = (long) get_numeric_arg(env, 1);
- long b = (long) get_numeric_arg(env, 0);
+ long a = (long) get_arg(env, 1);
+ long b = (long) get_arg(env, 0);
if (PROG_TRACE_ENGINE)
prog_trace(env, "GTN %ld %ld", a, b);
adjust_stack(env, 2);
@@ -914,8 +991,10 @@ instr_gtn(eval_environ_t env)
void
instr_gts(eval_environ_t env)
{
- char *a = get_string_arg(env, 1);
- char *b = get_string_arg(env, 0);
+ char *a, *b;
+
+ get_string_arg(env, 1, &a);
+ get_string_arg(env, 0, &b);
if (PROG_TRACE_ENGINE)
prog_trace(env, "GTS %s %s", a, b);
adjust_stack(env, 2);
@@ -925,8 +1004,8 @@ instr_gts(eval_environ_t env)
void
instr_gen(eval_environ_t env)
{
- long a = (long) get_numeric_arg(env, 1);
- long b = (long) get_numeric_arg(env, 0);
+ long a = (long) get_arg(env, 1);
+ long b = (long) get_arg(env, 0);
if (PROG_TRACE_ENGINE)
prog_trace(env, "GEN %ld %ld", a, b);
adjust_stack(env, 2);
@@ -936,8 +1015,10 @@ instr_gen(eval_environ_t env)
void
instr_ges(eval_environ_t env)
{
- char *a = get_string_arg(env, 1);
- char *b = get_string_arg(env, 0);
+ char *a, *b;
+
+ get_string_arg(env, 1, &a);
+ get_string_arg(env, 0, &b);
if (PROG_TRACE_ENGINE)
prog_trace(env, "GES %s %s", a, b);
adjust_stack(env, 2);
@@ -948,7 +1029,7 @@ instr_ges(eval_environ_t env)
void
instr_bz(eval_environ_t env)
{
- long v = (long) get_numeric_arg(env, 0);
+ long v = (long) get_arg(env, 0);
long off = (long) get_immediate(env, 0);
if (PROG_TRACE_ENGINE)
@@ -968,7 +1049,7 @@ dump_branch (prog_counter_t i)
void
instr_bnz(eval_environ_t env)
{
- long v = (long) get_numeric_arg(env, 0);
+ long v = (long) get_arg(env, 0);
long off = (long) get_immediate(env, 0);
if (PROG_TRACE_ENGINE)
@@ -992,7 +1073,7 @@ instr_jmp(eval_environ_t env)
void
instr_not(eval_environ_t env)
{
- long v = (long) get_numeric_arg(env, 0);
+ long v = (long) get_arg(env, 0);
if (PROG_TRACE_ENGINE)
prog_trace(env, "NOT %ld", v);
adjust_stack(env, 1);
@@ -1003,8 +1084,8 @@ instr_not(eval_environ_t env)
void
instr_logand(eval_environ_t env)
{
- unsigned long a = (unsigned long) get_numeric_arg(env, 1);
- unsigned long b = (unsigned long) get_numeric_arg(env, 0);
+ unsigned long a = (unsigned long) get_arg(env, 1);
+ unsigned long b = (unsigned long) get_arg(env, 0);
adjust_stack(env, 2);
if (PROG_TRACE_ENGINE)
prog_trace(env, "LOGAND %lu %lu", a, b);
@@ -1014,8 +1095,8 @@ instr_logand(eval_environ_t env)
void
instr_logor(eval_environ_t env)
{
- unsigned long a = (unsigned long) get_numeric_arg(env, 1);
- unsigned long b = (unsigned long) get_numeric_arg(env, 0);
+ unsigned long a = (unsigned long) get_arg(env, 1);
+ unsigned long b = (unsigned long) get_arg(env, 0);
adjust_stack(env, 2);
if (PROG_TRACE_ENGINE)
prog_trace(env, "LOGOR %lu %lu", a, b);
@@ -1025,8 +1106,8 @@ instr_logor(eval_environ_t env)
void
instr_logxor(eval_environ_t env)
{
- unsigned long a = (unsigned long) get_numeric_arg(env, 1);
- unsigned long b = (unsigned long) get_numeric_arg(env, 0);
+ unsigned long a = (unsigned long) get_arg(env, 1);
+ unsigned long b = (unsigned long) get_arg(env, 0);
adjust_stack(env, 2);
if (PROG_TRACE_ENGINE)
prog_trace(env, "LOGXOR %lu %lu", a, b);
@@ -1036,7 +1117,7 @@ instr_logxor(eval_environ_t env)
void
instr_lognot(eval_environ_t env)
{
- unsigned long v = (unsigned long) get_numeric_arg(env, 0);
+ unsigned long v = (unsigned long) get_arg(env, 0);
if (PROG_TRACE_ENGINE)
prog_trace(env, "LOGNOT %ld", v);
adjust_stack(env, 1);
@@ -1047,8 +1128,8 @@ instr_lognot(eval_environ_t env)
void
instr_add(eval_environ_t env)
{
- long a = (long) get_numeric_arg(env, 1);
- long b = (long) get_numeric_arg(env, 0);
+ long a = (long) get_arg(env, 1);
+ long b = (long) get_arg(env, 0);
adjust_stack(env, 2);
if (PROG_TRACE_ENGINE)
prog_trace(env, "ADD %ld %ld", a, b);
@@ -1058,8 +1139,8 @@ instr_add(eval_environ_t env)
void
instr_sub(eval_environ_t env)
{
- long a = (long) get_numeric_arg(env, 1);
- long b = (long) get_numeric_arg(env, 0);
+ long a = (long) get_arg(env, 1);
+ long b = (long) get_arg(env, 0);
adjust_stack(env, 2);
if (PROG_TRACE_ENGINE)
prog_trace(env, "SUB %ld %ld", a, b);
@@ -1069,8 +1150,8 @@ instr_sub(eval_environ_t env)
void
instr_mul(eval_environ_t env)
{
- long a = (long) get_numeric_arg(env, 1);
- long b = (long) get_numeric_arg(env, 0);
+ long a = (long) get_arg(env, 1);
+ long b = (long) get_arg(env, 0);
adjust_stack(env, 2);
if (PROG_TRACE_ENGINE)
prog_trace(env, "MUL %ld %ld", a, b);
@@ -1080,8 +1161,8 @@ instr_mul(eval_environ_t env)
void
instr_div(eval_environ_t env)
{
- long a = (long) get_numeric_arg(env, 1);
- long b = (long) get_numeric_arg(env, 0);
+ long a = (long) get_arg(env, 1);
+ long b = (long) get_arg(env, 0);
adjust_stack(env, 2);
if (PROG_TRACE_ENGINE)
prog_trace(env, "DIV %ld %ld", a, b);
@@ -1094,7 +1175,7 @@ instr_div(eval_environ_t env)
void
instr_neg(eval_environ_t env)
{
- long v = (long) get_numeric_arg(env, 0);
+ long v = (long) get_arg(env, 0);
if (PROG_TRACE_ENGINE)
prog_trace(env, "NEG %ld", v);
adjust_stack(env, 1);
@@ -1135,9 +1216,11 @@ void
instr_regmatch(eval_environ_t env)
{
int v;
- size_t index = (size_t)get_numeric_arg(env, 0);
+ size_t index = (size_t)get_arg(env, 0);
regex_t *re = &regtab[index].re;
- char *string = get_string_arg(env, 1);
+ char *string;
+
+ get_string_arg(env, 1, &string);
adjust_stack(env, 2);
if (PROG_TRACE_ENGINE)
@@ -1167,9 +1250,11 @@ instr_regcomp(eval_environ_t env)
int v;
char buffer[REGEX_STRING_BUFSIZE];
size_t expr_off = (size_t)get_arg(env, 0);
- char *expr = get_string_arg(env, 0);
+ char *expr;
size_t index = (size_t) get_immediate(env, 0);
struct rt_regex *rtx = &regtab[index];
+
+ get_string_arg(env, 0, &expr);
advance_pc(env, 1);
adjust_stack(env, 1);
@@ -1211,8 +1296,10 @@ dump_regcomp(prog_counter_t i)
void
instr_fnmatch(eval_environ_t env)
{
- char *string = get_string_arg(env, 1);
- char *pattern = get_string_arg(env, 0);
+ char *string, *pattern;
+
+ get_string_arg(env, 1, &string);
+ get_string_arg(env, 0, &pattern);
adjust_stack(env, 2);
if (PROG_TRACE_ENGINE)
prog_trace(env, "FNMATCH %s %s", string, pattern);
@@ -1258,8 +1345,10 @@ fn_matcher(const char *string, void *data)
void
instr_fnmatch_mx(eval_environ_t env)
{
- char *string = get_string_arg(env, 1);
- char *pattern = get_string_arg(env, 0);
+ char *string, *pattern;
+
+ get_string_arg(env, 1, &string);
+ get_string_arg(env, 0, &pattern);
adjust_stack(env, 2);
if (PROG_TRACE_ENGINE)
@@ -1277,9 +1366,11 @@ void
instr_regmatch_mx(eval_environ_t env)
{
int rc;
- size_t index = (size_t)get_numeric_arg(env, 0);
+ size_t index = (size_t)get_arg(env, 0);
regex_t *re = &regtab[index].re;
- char *string = get_string_arg(env, 1);
+ char *string;
+
+ get_string_arg(env, 1, &string);
adjust_stack(env, 2);
if (PROG_TRACE_ENGINE)
@@ -1307,9 +1398,12 @@ void
instr_result(eval_environ_t env)
{
sfsistat status = (sfsistat) get_immediate(env, 0);
- char *code = (char *) get_literal(env, 1);
- char *xcode = (char *) get_literal(env, 2);
- char *message = get_string_arg(env, 0);
+ char *code, *xcode;
+ char *message;
+
+ get_string_arg(env, 0, &message);
+ get_literal(env, 1, (const char**)&code);
+ get_literal(env, 2, (const char**)&xcode);
if (PROG_TRACE_ENGINE)
prog_trace(env, "RESULT %d %s %s %s",
@@ -1350,11 +1444,13 @@ void
instr_header(eval_environ_t env)
{
struct old_header_node *hdr = xmalloc (sizeof(*hdr));
+ char *value;
hdr->opcode = (enum header_opcode) get_immediate(env, 0);
- hdr->name = get_literal(env, 1);
- hdr->value = strdup(get_string_arg(env, 0));
-
+ get_literal(env, 1, &hdr->name);
+ get_string_arg(env, 0, &value);
+ hdr->value = strdup(value);
+
advance_pc(env, 2);
adjust_stack(env, 1);
@@ -1382,9 +1478,10 @@ dump_header(prog_counter_t i)
void
instr_builtin(eval_environ_t env)
{
- const char *name = get_literal(env, 0);
+ const char *name;
void (*handler)(eval_environ_t) = get_immediate(env, 1);
+ get_literal(env, 0, &name);
if (PROG_TRACE_ENGINE)
prog_trace(env, "BUILTIN %s", name);
advance_pc(env, 2);
@@ -1400,10 +1497,14 @@ dump_builtin(prog_counter_t i)
void
instr_concat(eval_environ_t env)
{
- char *left = get_string_arg(env, 1);
- char *right = get_string_arg(env, 0);
- size_t off = heap_reserve(env, strlen(left) + strlen(right) + 1);
- char *res = (char*) env_data_ref(env, off);
+ char *left, *right;
+ size_t off;
+ char *res;
+
+ get_string_arg(env, 1, &left);
+ get_string_arg(env, 0, &right);
+ off = heap_reserve(env, strlen(left) + strlen(right) + 1);
+ res = (char*) env_data_ref(env, off);
strcat(strcpy(res, left), right);
adjust_stack(env, 2);
@@ -1422,7 +1523,7 @@ void
instr_asgn(eval_environ_t env)
{
STKVAL val = get_arg(env, 1);
- size_t dest = get_numeric_arg(env, 0);
+ size_t dest = (size_t) get_arg(env, 0);
adjust_stack(env, 2);
if (PROG_TRACE_ENGINE)
prog_trace(env, "ASGN %lu=%lu",
@@ -1576,8 +1677,9 @@ instr_pushreg(eval_environ_t env)
void
instr_funcall(eval_environ_t env)
{
- const char *name = get_literal(env, 0);
+ const char *name;
prog_counter_t pc = (prog_counter_t) get_immediate(env, 1);
+ get_literal(env, 0, &name);
advance_pc(env, 2);
if (PROG_TRACE_ENGINE)
prog_trace(env, "FUNCALL %s (%lu)", name, (unsigned long)pc);
@@ -1760,6 +1862,8 @@ env_init(eval_environ_t env)
env->matchcount = 0;
env->string = NULL;
+ env->numautos = 0;
+
/* Initialize catch functions */
memcpy (env->catch, env->defcatch, sizeof env->catch);
@@ -1806,8 +1910,10 @@ eval_environment(eval_environ_t env, prog_counter_t start)
runtime_error(env, _("pc out of range"));
if (!prog[env->pc])
break;
- if (setjmp(env->catch_jmp) == 0)
+ if (setjmp(env->catch_jmp) == 0) {
(*(prog[env->pc]))(env);
+ env_unregister_autos(env);
+ }
}
return 0;
}
diff --git a/src/prog.h b/src/prog.h
index c18ab87..ef97282 100644
--- a/src/prog.h
+++ b/src/prog.h
@@ -31,8 +31,8 @@ void runtime_warning(eval_environ_t env, const char *fmt, ...);
void runtime_error(eval_environ_t env, const char *fmt, ...)
ATTRIBUTE_NORETURN;
STKVAL get_arg(eval_environ_t env, unsigned n);
-char *get_string_arg(eval_environ_t env, unsigned n);
-size_t get_numeric_arg(eval_environ_t env, unsigned n);
+void get_string_arg(eval_environ_t env, unsigned n, char **ptr);
+void get_numeric_arg(eval_environ_t env, unsigned n, long *np);
void push(eval_environ_t env, STKVAL val);
STKVAL pop(eval_environ_t env);
STKVAL *env_data_ref(eval_environ_t env, size_t off);
diff --git a/src/snarf.m4 b/src/snarf.m4
index 6d41932..7ceb4af 100644
--- a/src/snarf.m4
+++ b/src/snarf.m4
@@ -79,25 +79,49 @@ m4_define([<__mf_c_getarg>],m4_dnl
[<m4_ifelse($1,STRING,get_string_arg,$1,NUMBER,get_numeric_arg, ERROR )>])
/* mf_c_argdcl(TYPE NAME) -- translate Mailfromd declaration "TYPE NAME"
- * into the corresponding C one, followed by an equals sign, a typecast,
- * and the name of corresponding get_.*_arg function
- * e.g.:
- * mf_c_argdcl(STRING str) => char *str = (char*) get_string_arg
+ * into the corresponding C one:
+ *
+ * mf_c_argdcl(STRING str) => char *str
*/
m4_define([<mf_c_argdcl>],m4_dnl
-[<m4_regexp([<$1>],[<\(\w+\)\W+\(\w+\)>],[<__mf_c_type(\1)>] \2 = ([<__mf_c_type(\1)>]) [<__mf_c_getarg(\1)>])>])
+[<m4_regexp([<$1>],[<\(\w+\)\W+\(\w+\)>],[<__mf_c_type(\1)>] \2)>])
+
+/* mf_c_arginit(TYPE NAME, NUM) -- translate Mailfromd declaration "TYPE NAME"
+ * into the corresponding C initialization:
+ *
+ * mf_c_argdcl(STRING str) => get_string_arg(env, NUM, &str)
+ */
+m4_define([<mf_c_arginit>],m4_dnl
+[<m4_regexp([<$1>],[<\(\w+\)\W+\(\w+\)>],[<__mf_c_getarg(\1)(env, $2, &\2)>])>])
+
+/* __mf_c_argdcl_list(NARG, LIST) -- translate Mailfromd declaration list
+ * into a set of corresponding C variable declarations.
+ * For more details, see mf_c_arglist below.
+ */
+m4_define([<__mf_c_argdcl_list>],m4_dnl
+[<m4_ifelse($2, , ,$2,[<OPTIONAL>],[<m4_dnl
+__mf_c_argdcl_list($1, m4_shift(m4_shift($@)))>],
+[<mf_c_argdcl($2);
+ __mf_c_argdcl_list(m4_incr($1), m4_shift(m4_shift($@)))>])>])
+
+/* __mf_c_arginit_list(NARG, LIST) -- translate Mailfromd declaration list
+ * into a set of corresponding C variable initializations.
+ * For more details, see mf_c_arglist below.
+ */
+m4_define([<__mf_c_arginit_list>],m4_dnl
+[<m4_ifelse($2, , ,$2,[<OPTIONAL>],[<m4_dnl
+__mf_c_arginit_list($1, m4_shift(m4_shift($@)))>],
+[<mf_c_arginit($2, m4_eval($1));
+ __mf_c_arginit_list(m4_incr($1), m4_shift(m4_shift($@)))>])>])
/* __mf_c_arglist(NARG, LIST) -- translate Mailfromd declaration list
- * into a set of corresponding C variable declarations with initializations.
+ * into a set of corresponding C variable declarations and initializations.
* Arguments:
* NARG -- ordinal number of the first variable in LIST
* LIST -- comma-separated list of Mailfromd declarations
*/
-m4_define([<__mf_c_arglist>],m4_dnl
-[<m4_ifelse($2, , ,$2,[<OPTIONAL>],[<m4_dnl
-__mf_c_arglist($1, m4_shift(m4_shift($@)))>],
-[<mf_c_argdcl($2)(env, m4_eval($1));
- __mf_c_arglist(m4_incr($1), m4_shift(m4_shift($@)))>])>])
+m4_define([<__mf_c_arglist>],[<__mf_c_argdcl_list($@)
+__mf_c_arginit_list($@)>])
/* mf_c_arglist(LIST) -- translate Mailfromd declaration list
* into a set of corresponding C variable declarations with initializations.
@@ -105,23 +129,29 @@ __mf_c_arglist($1, m4_shift(m4_shift($@)))>],
* variables.
* E.g.:
* mf_c_arglist(STRING a, NUMBER n) =>
- * char *a = (char*)get_string_arg(env, 0);
- * long n = (long)get_numeric_arg(env, 1);
+ * char *a;
+ * long n;
+ * get_string_arg(env, 0, &a);
+ * get_numeric_arg(env, 1, &n);
* adjust_stack(env, 2);
*
* Or, if the builtin takes optional parameters:
*
* mf_c_arglist(STRING a, NUMBER n) =>
- * long __bi_argcnt = (long)get_numeric_arg(env, 0);
- * char *a = (char*)get_string_arg(env, 1);
- * long n = (long)get_numeric_arg(env, 2);
+ * long __bi_argcnt;
+ * char *a;
+ * long n;
+ * get_string_arg(env, 1, &a);
+ * get_numeric_arg(env, 2, &n);
+ * get_numeric_arg(env, 0, &__bi_argcnt);
* adjust_stack(env, __bi_argcnt + 1);
*/
m4_define([<mf_c_arglist>],m4_dnl
[<
m4_pushdef([<__ARG1__>], m4_ifelse(__MF_VARARGS__,1,1,[<__mf_has_optarg($@)>]))
-m4_ifelse(__ARG1__,0,,[<long __bi_argcnt = (long)get_numeric_arg(env, 0);>])
+m4_ifelse(__ARG1__,0,,[<long __bi_argcnt;>])
__mf_c_arglist(__ARG1__, $@)
+m4_ifelse(__ARG1__,0,,[<get_numeric_arg(env, 0, &__bi_argcnt);>])
adjust_stack(env, m4_ifelse(__ARG1__,0,mf_argcount($@),__bi_argcnt + 1));
m4_popdef([<__ARG1__>])m4_dnl
>])
@@ -429,13 +459,13 @@ m4_ifelse(__MF_VARARGS__,1,[<__mf_va_count>],
)m4_dnl
m4_define([<__mf_error_code>],1)>])>])
-/* MF_VA_ARG(N, TYPE) -- Produce a code for returning Nth argument of the
- given TYPE in a vararg section. */
+/* MF_VA_ARG(N, TYPE, VAR) -- Produce a code for assigning to VAR the Nth
+ argument of the given TYPE in a vararg section. */
m4_define([<MF_VA_ARG>],[<m4_dnl
m4_ifdef([<__MF_VA_START_USED__>],m4_dnl
[<m4_pushdef([<__ARGN__>],[<$1+mf_argcount(__MF_ARGLIST__)>])
((__bi_argcnt > __ARGN__) ?m4_dnl
- __mf_c_getarg($2)(env, __ARGN__ + 1) :m4_dnl
+ __mf_c_getarg($2)(env, __ARGN__ + 1, &$3) :m4_dnl
(MF_THROW(mfe_range, "Argument %d is not supplied", __ARGN__),m4_dnl
(__mf_c_type($2)) 0))m4_dnl
m4_popdef([<__ARGN__>])>],

Return to:

Send suggestions and report system problems to the System administrator.