aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2011-03-24 23:20:43 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2011-03-25 01:53:22 +0200
commitca1e3b7fb228e66aaa5c9340b6bcd9f57ed12c64 (patch)
treecdf4ea02f41ba05e2b0dd3dc99343c32989431cc
parent240f7305641d1b8d87e2963c251a808f1aa28034 (diff)
downloadmailfromd-ca1e3b7fb228e66aaa5c9340b6bcd9f57ed12c64.tar.gz
mailfromd-ca1e3b7fb228e66aaa5c9340b6bcd9f57ed12c64.tar.bz2
Bugfixes (port of 02c6537e)
* mfd/mu_dbm.c (mf_dbm_insert): Add missing break. * src/prog.c (environ_locus): New struct. (eval_environ): Change type of locus to environ_locus. (ENV_LOC_FILE,ENV_LOC_LINE): New defines. (env_get_locus): Store locus in the struct locus supplied by the second argument. Register the file member as automatic variable, lest it gets clobbered by stack expansions. All callers updated. (instr_push,instr_stkalloc,instr_regmatch_mx) (instr_next): Fix trace formats. * src/prog.h (runtime_warning,runtime_error) (prog_trace): Mark as printflike. (env_get_locus): Change signature. * src/builtin/header.bi (header_add,header_insert) (header_delete,header_replace): Update calls to env_get_locus. * src/builtin/progress.bi (progress): Likewise. * src/builtin/qrnt.bi (quarantine): Likewise. * src/builtin/rcpt.bi (rcpt_add,rcpt_delete): Likewise. * mfd/builtin/mudebug.bi: Likewise. * mfd/builtin/poll.bi: Likewise.
-rw-r--r--mfd/builtin/header.bi26
-rw-r--r--mfd/builtin/mudebug.bi6
-rw-r--r--mfd/builtin/poll.bi23
-rw-r--r--mfd/builtin/progress.bi6
-rw-r--r--mfd/builtin/qrnt.bi6
-rw-r--r--mfd/builtin/rcpt.bi12
-rw-r--r--mfd/mu_dbm.c1
-rw-r--r--mfd/prog.c66
-rw-r--r--mfd/prog.h10
9 files changed, 104 insertions, 52 deletions
diff --git a/mfd/builtin/header.bi b/mfd/builtin/header.bi
index f387f0fc..2623368a 100644
--- a/mfd/builtin/header.bi
+++ b/mfd/builtin/header.bi
@@ -16,12 +16,14 @@
MF_DEFUN(header_add, VOID, STRING name, STRING value, OPTIONAL, NUMBER idx)
{
- const struct locus *locus = env_get_locus(env);
+ struct locus locus;
+
+ env_get_locus(env, &locus);
if (MF_DEFINED(idx)) {
trace("%s%s:%lu: %s %ld \"%s: %s\"",
mailfromd_msgid(env_get_context(env)),
- locus->file, locus->line,
+ locus.file, locus.line,
msgmod_opcode_str(header_insert),
idx,
name, value);
@@ -29,7 +31,7 @@ MF_DEFUN(header_add, VOID, STRING name, STRING value, OPTIONAL, NUMBER idx)
} else {
trace("%s%s:%lu: %s \"%s: %s\"",
mailfromd_msgid(env_get_context(env)),
- locus->file, locus->line,
+ locus.file, locus.line,
msgmod_opcode_str(header_add),
name, value);
env_msgmod(env, header_add, name, value, 1);
@@ -39,11 +41,13 @@ END
MF_DEFUN(header_insert, VOID, STRING name, STRING value, NUMBER idx)
{
- const struct locus *locus = env_get_locus(env);
+ struct locus locus;
+
+ env_get_locus(env, &locus);
trace("%s%s:%lu: %s %ld \"%s: %s\"",
mailfromd_msgid(env_get_context(env)),
- locus->file, locus->line,
+ locus.file, locus.line,
msgmod_opcode_str(header_insert),
idx,
name, value);
@@ -53,11 +57,13 @@ END
MF_DEFUN(header_delete, VOID, STRING name, OPTIONAL, NUMBER idx)
{
- const struct locus *locus = env_get_locus(env);
+ struct locus locus;
+
+ env_get_locus(env, &locus);
trace("%s%s:%lu: %s \"%s\" (%lu)",
mailfromd_msgid(env_get_context(env)),
- locus->file, locus->line,
+ locus.file, locus.line,
msgmod_opcode_str(header_delete),
name, MF_OPTVAL(idx, 1));
env_msgmod(env, header_delete, name, NULL, MF_OPTVAL(idx, 1));
@@ -66,11 +72,13 @@ END
MF_DEFUN(header_replace, VOID, STRING name, STRING value, OPTIONAL, NUMBER idx)
{
- const struct locus *locus = env_get_locus(env);
+ struct locus locus;
+
+ env_get_locus(env, &locus);
trace("%s%s:%lu: %s \"%s: %s\" (%lu)",
mailfromd_msgid(env_get_context(env)),
- locus->file, locus->line,
+ locus.file, locus.line,
msgmod_opcode_str(header_delete),
name, value, MF_OPTVAL(idx, 1));
env_msgmod(env, header_replace, name, value, MF_OPTVAL(idx, 1));
diff --git a/mfd/builtin/mudebug.bi b/mfd/builtin/mudebug.bi
index 649033f0..70f34806 100644
--- a/mfd/builtin/mudebug.bi
+++ b/mfd/builtin/mudebug.bi
@@ -16,9 +16,11 @@
MF_DEFUN(mailutils_set_debug_level, VOID, STRING str)
{
- const struct locus *loc = env_get_locus(env);
+ struct locus locus;
char *pfx;
- asprintf(&pfx, "%s:%lu", loc->file, (unsigned long)loc->line);
+
+ env_get_locus(env, &locus);
+ asprintf(&pfx, "%s:%lu", locus.file, (unsigned long)locus.line);
mu_global_debug_from_string(str, pfx);
free(pfx);
}
diff --git a/mfd/builtin/poll.bi b/mfd/builtin/poll.bi
index 35312dcf..226fd5e6 100644
--- a/mfd/builtin/poll.bi
+++ b/mfd/builtin/poll.bi
@@ -61,11 +61,12 @@ set_cache_used(eval_environ_t env, int value)
MF_DEFUN(stdpoll, NUMBER, STRING email, STRING ehlo, STRING mailfrom)
{
mf_status rc;
- const struct locus *locus = env_get_locus(env);
+ struct locus locus;
+ env_get_locus(env, &locus);
trace("%s%s:%lu: STANDARD POLL FOR %s FROM %s AS %s",
mailfromd_msgid(env_get_context(env)),
- locus->file, locus->line,
+ locus.file, locus.line,
email, ehlo, mailfrom);
rc = method_standard(env, email, ehlo, mailfrom);
MF_ASSERT(mf_resolved(rc), mf_status_to_exception(rc),
@@ -79,11 +80,13 @@ MF_DEFUN(strictpoll, NUMBER, STRING host, STRING email, STRING ehlo,
STRING mailfrom)
{
mf_status rc;
- const struct locus *locus = env_get_locus(env);
+ struct locus locus;
+
+ env_get_locus(env, &locus);
trace("%s%s:%lu: STRICT POLL FOR %s HOST %s FROM %s AS %s",
mailfromd_msgid(env_get_context(env)),
- locus->file, locus->line,
+ locus.file, locus.line,
email, host,
ehlo, mailfrom);
@@ -101,11 +104,13 @@ MF_DEFUN(_pollhost, NUMBER, STRING host, STRING email, STRING ehlo,
mf_status rc;
smtp_io_t io;
const char *id = mailfromd_msgid(env_get_context(env));
- const struct locus *locus = env_get_locus(env);
+ struct locus locus;
+
+ env_get_locus(env, &locus);
trace("%s%s:%lu: POLLHOST %s FOR %s FROM %s AS %s",
mailfromd_msgid(env_get_context(env)),
- locus->file, locus->line,
+ locus.file, locus.line,
email, host,
ehlo, mailfrom);
@@ -130,11 +135,13 @@ MF_DEFUN(_pollmx, NUMBER, STRING domain, STRING email, STRING ehlo,
mf_status rc;
smtp_io_t io;
const char *id = mailfromd_msgid(env_get_context(env));
- const struct locus *locus = env_get_locus(env);
+ struct locus locus;
+
+ env_get_locus(env, &locus);
trace("%s%s:%lu: POLLMX %s FOR %s FROM %s AS %s",
mailfromd_msgid(env_get_context(env)),
- locus->file, locus->line,
+ locus.file, locus.line,
domain, email, ehlo, mailfrom);
io = smtp_io_create(id ? id : "(none): ",
diff --git a/mfd/builtin/progress.bi b/mfd/builtin/progress.bi
index 3596e5f5..3de8af2b 100644
--- a/mfd/builtin/progress.bi
+++ b/mfd/builtin/progress.bi
@@ -17,11 +17,13 @@
MF_STATE(eom)
MF_DEFUN(progress, VOID)
{
- const struct locus *locus = env_get_locus(env);
+ struct locus locus;
+
+ env_get_locus(env, &locus);
trace("%s%s:%lu: %s",
mailfromd_msgid(env_get_context(env)),
- locus->file, locus->line,
+ locus.file, locus.line,
"PROGRESS");
gacopyz_progress(env_get_context(env));
}
diff --git a/mfd/builtin/qrnt.bi b/mfd/builtin/qrnt.bi
index b26b1f9b..ea393995 100644
--- a/mfd/builtin/qrnt.bi
+++ b/mfd/builtin/qrnt.bi
@@ -16,11 +16,13 @@
MF_DEFUN(quarantine, VOID, STRING reason)
{
- const struct locus *locus = env_get_locus(env);
+ struct locus locus;
+
+ env_get_locus(env, &locus);
trace("%s%s:%lu: %s %s",
mailfromd_msgid(env_get_context(env)),
- locus->file, locus->line,
+ locus.file, locus.line,
msgmod_opcode_str(quarantine),
reason);
env_msgmod(env, quarantine, reason, NULL, 0);
diff --git a/mfd/builtin/rcpt.bi b/mfd/builtin/rcpt.bi
index 6456a1af..1e3ff3c7 100644
--- a/mfd/builtin/rcpt.bi
+++ b/mfd/builtin/rcpt.bi
@@ -16,11 +16,13 @@
MF_DEFUN(rcpt_add, VOID, STRING addr)
{
- const struct locus *locus = env_get_locus(env);
+ struct locus locus;
+
+ env_get_locus(env, &locus);
trace("%s%s:%lu: %s %s",
mailfromd_msgid(env_get_context(env)),
- locus->file, locus->line,
+ locus.file, locus.line,
msgmod_opcode_str(rcpt_add),
addr);
env_msgmod(env, rcpt_add, addr, NULL, 0);
@@ -29,11 +31,13 @@ END
MF_DEFUN(rcpt_delete, VOID, STRING addr)
{
- const struct locus *locus = env_get_locus(env);
+ struct locus locus;
+
+ env_get_locus(env, &locus);
trace("%s%s:%lu: %s %s",
mailfromd_msgid(env_get_context(env)),
- locus->file, locus->line,
+ locus.file, locus.line,
msgmod_opcode_str(rcpt_delete),
addr);
env_msgmod(env, rcpt_delete, addr, NULL, 0);
diff --git a/mfd/mu_dbm.c b/mfd/mu_dbm.c
index 32324d6a..6284e0c0 100644
--- a/mfd/mu_dbm.c
+++ b/mfd/mu_dbm.c
@@ -555,6 +555,7 @@ mu_dbm_insert (DBM_FILE *dbm, DBM_DATUM key, DBM_DATUM contents, int replace)
case DB_KEYEXIST:
rc = MU_ERR_EXISTS;
+ break;
default:
rc = MU_ERR_FAILURE;
diff --git a/mfd/prog.c b/mfd/prog.c
index 09be2d41..35b45b05 100644
--- a/mfd/prog.c
+++ b/mfd/prog.c
@@ -232,6 +232,15 @@ struct exception_context {
#define TOS_INVARIANT(env,t) (datasize + (env)->stack_size - (t))
+struct environ_locus {
+ unsigned long file; /* File name */
+ unsigned long line; /* Line number */
+#if 0
+ unsigned long point; /* Offset in the input line */
+ unsigned long leng; /* Length of the input token */
+#endif
+};
+
struct eval_environ {
prog_counter_t pc; /* Program counter */
@@ -244,9 +253,10 @@ struct eval_environ {
STKVAL reg; /* General purpose register */
STKVAL *dataseg; /* Data space */
size_t stack_size; /* Size of allocated stack + heap */
-
- struct locus locus; /* Program locus corresponding to PC */
+ /* Program locus corresponding to PC */
+ struct environ_locus locus;
+
/* Temporary heap space */
size_t temp_start;
size_t temp_size;
@@ -290,6 +300,10 @@ struct eval_environ {
jmp_buf catch_jmp; /* Return point for throws */
};
+#define ENV_LOC_FILE(env) \
+ ((const char*)((env)->dataseg + (size_t) (env)->locus.file))
+#define ENV_LOC_LINE(env) ((env)->locus.line)
+
void
advance_pc(eval_environ_t env, long cnt)
{
@@ -364,12 +378,20 @@ void
env_var_inc(eval_environ_t env, size_t off)
{
++*env_data_ref(env, off);
-}
+}
-const struct locus *
-env_get_locus(eval_environ_t env)
+static void env_register_auto(eval_environ_t env, void *ptr);
+
+void
+env_get_locus(eval_environ_t env, struct locus *locus)
{
- return &env->locus;
+ locus->file = (char*)(env->dataseg + env->locus.file);
+ env_register_auto(env, (void*) locus->file);
+ locus->line = env->locus.line;
+#if 0
+ locus->point = env->locus.point;
+ locus->leng = env->locus.leng;
+#endif
}
const char *
@@ -408,7 +430,7 @@ env_reposition(eval_environ_t env)
The auto_ptr array is cleared (by calling env_unregister_autos) after
executing each instruction (see eval_environment).
*/
-void
+static void
env_register_auto(eval_environ_t env, void *ptr)
{
if (env->numautos == MAX_AUTO_PTR)
@@ -503,7 +525,7 @@ prog_trace(eval_environ_t env, const char *fmt, ...)
va_end(ap);
logmsg(LOG_DEBUG, "%4lu: %s:%lu: %s",
(unsigned long) env->pc,
- env->locus.file, (unsigned long) env->locus.line,
+ ENV_LOC_FILE(env), ENV_LOC_LINE(env),
buf);
}
@@ -564,7 +586,7 @@ runtime_warning(eval_environ_t env, const char *fmt, ...)
mu_diag_printf(MU_DIAG_WARNING,
_("RUNTIME WARNING near %s:%lu: "),
- env->locus.file, (unsigned long) env->locus.line);
+ ENV_LOC_FILE(env), ENV_LOC_LINE(env));
va_start(ap, fmt);
mu_diag_output(MU_DIAG_WARNING, fmt, ap);
va_end(ap);
@@ -578,7 +600,7 @@ runtime_error(eval_environ_t env, const char *fmt, ...)
char buf[512];
n = snprintf(buf, sizeof buf, _("RUNTIME ERROR near %s:%lu: "),
- env->locus.file, (unsigned long) env->locus.line);
+ ENV_LOC_FILE(env), ENV_LOC_LINE(env));
va_start(ap, fmt);
vsnprintf(buf + n, sizeof buf - n, fmt, ap);
va_end(ap);
@@ -595,7 +617,7 @@ get_immediate(eval_environ_t env, unsigned n)
return prog[env->pc + n + 1];
}
-void
+static void
get_literal(eval_environ_t env, unsigned n, const char **p)
{
*p = (char*)(env->dataseg + (size_t) get_immediate(env, n));
@@ -745,8 +767,8 @@ pushs(eval_environ_t env, const char *s)
void
instr_locus(eval_environ_t env)
{
- env->locus.line = (size_t) get_immediate(env, 1);
- get_literal(env, 0, &env->locus.file);
+ env->locus.file = (unsigned) get_immediate(env, 0);
+ env->locus.line = (unsigned) get_immediate(env, 1);
if (PROG_TRACE_ENGINE)
prog_trace(env, "LOCUS");
advance_pc(env, 2);
@@ -791,7 +813,7 @@ void
instr_push(eval_environ_t env)
{
if (PROG_TRACE_ENGINE)
- prog_trace(env, "PUSH %x", get_immediate(env, 0));
+ prog_trace(env, "PUSH %p", get_immediate(env, 0));
push(env, get_immediate(env, 0));
advance_pc(env, 1);
}
@@ -876,7 +898,7 @@ instr_stkalloc(eval_environ_t env)
{
unsigned n = (unsigned) get_immediate(env, 0);
if (PROG_TRACE_ENGINE)
- prog_trace(env, "STKALLOC %p", n);
+ prog_trace(env, "STKALLOC %x", n);
if (env->tos - n < env->toh) {
debug3(100, "tos=%lu, toh=%lu, delta=%u",
(unsigned long) env->tos,
@@ -1364,7 +1386,8 @@ instr_regmatch(eval_environ_t env)
if (PROG_TRACE_ENGINE)
prog_trace(env, "REGMATCH %s %s",
- env_data_ref(env, regtab[index].expr), string);
+ (char*)env_data_ref(env, regtab[index].expr),
+ string);
env->matchcount = re->re_nsub;
if (env->matchsize < env->matchcount + 1) {
@@ -1518,7 +1541,8 @@ instr_regmatch_mx(eval_environ_t env)
if (PROG_TRACE_ENGINE)
prog_trace(env, "REGMATCH,MX %s %s",
- regtab[index].expr, string);
+ (char*) env_data_ref(env, regtab[index].expr),
+ string);
rc = mx_match(env, string, regex_matcher, re);
@@ -1531,10 +1555,10 @@ void
instr_next(eval_environ_t env)
{
if (PROG_TRACE_ENGINE)
- prog_trace(env, "NEXT", env->locus.file, env->locus.line);
+ prog_trace(env, "NEXT");
trace("%s%s:%lu: next",
mailfromd_msgid(env->ctx),
- env->locus.file, env->locus.line);
+ ENV_LOC_FILE(env), ENV_LOC_LINE(env));
}
void
@@ -1557,7 +1581,7 @@ instr_result(eval_environ_t env)
trace("%s%s:%lu: %s %s %s %s",
mailfromd_msgid(env->ctx),
- env->locus.file, env->locus.line,
+ ENV_LOC_FILE(env), ENV_LOC_LINE(env),
sfsistat_str(status),
SP(code),
SP(xcode),
@@ -1601,7 +1625,7 @@ instr_header(eval_environ_t env)
trace("%s%s:%lu: %s %s %s",
mailfromd_msgid(env->ctx),
- env->locus.file, env->locus.line,
+ ENV_LOC_FILE(env), ENV_LOC_LINE(env),
msgmod_opcode_str(opcode),
name, SP(value));
diff --git a/mfd/prog.h b/mfd/prog.h
index 0214d07e..364d8fd0 100644
--- a/mfd/prog.h
+++ b/mfd/prog.h
@@ -27,9 +27,10 @@ struct eval_environ;
#define B2STACK(s) (s + sizeof(STKVAL) - 1) / sizeof(STKVAL)
-void runtime_warning(eval_environ_t env, const char *fmt, ...);
+void runtime_warning(eval_environ_t env, const char *fmt, ...)
+ MU_PRINTFLIKE(2, 3);
void runtime_error(eval_environ_t env, const char *fmt, ...)
- ATTRIBUTE_NORETURN;
+ MU_PRINTFLIKE(2, 3) ATTRIBUTE_NORETURN;
STKVAL get_arg(eval_environ_t env, unsigned n);
void get_pointer_arg(eval_environ_t env, unsigned n, void **p);
void get_string_arg(eval_environ_t env, unsigned n, char **ptr);
@@ -49,10 +50,11 @@ void pushs(eval_environ_t env, const char *s);
void advance_pc(eval_environ_t env, long cnt);
void adjust_stack(eval_environ_t env, unsigned cnt);
void unroll_stack(eval_environ_t env, unsigned cnt);
-void prog_trace(eval_environ_t env, const char *fmt, ...);
+void prog_trace(eval_environ_t env, const char *fmt, ...)
+ MU_PRINTFLIKE(2, 3);
void runtime_stack_trace(eval_environ_t env);
void env_var_inc(eval_environ_t env, size_t off);
-const struct locus *env_get_locus(eval_environ_t env);
+void env_get_locus(eval_environ_t env, struct locus *loc);
STKVAL env_get_reg(eval_environ_t env);
prog_counter_t env_register_read(eval_environ_t env, int what);
char *env_vaptr(eval_environ_t env, size_t off);

Return to:

Send suggestions and report system problems to the System administrator.