aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2015-04-25 15:56:53 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2015-04-27 10:56:46 +0300
commitb6173eeaf3311d9de26d530d5ff07fdf6ddddcad (patch)
tree43e02edb931587b91f5f84300e2ace32ef1abad9 /src
parent06509efd56988c83af61dd132ff080725c42ae2e (diff)
downloadmailfromd-b6173eeaf3311d9de26d530d5ff07fdf6ddddcad.tar.gz
mailfromd-b6173eeaf3311d9de26d530d5ff07fdf6ddddcad.tar.bz2
Avoid casts between pointers and integers (prog & runtime).
* src/prog.h (mf_stkval): New data type. (STKVAL): Redefine as union mf_stkval. (mft_ptr,mft_str,mft_int) (mft_uint,mft_long,mft_ulong) (mft_size,mft_string,mft_number): New data types. (mf_cat,mf_c_val): New macros. (instr_t): Moved from mailfromd.h (mf_code_cell): New union (mf_code_cell_t): New typedef. (mf_cell_instr,mf_cell_value) (mf_cell_c_value): New macros (code_peek): Moved from mailfromd.h. Change return type; (code_immediate,code_put): Moved from mailfromd.h. Change signature. (code_op,code_instr,code_exmask) (code_get_counter,dump_code,fixup_code): Moved from mailfromd.h. (prog): Change type. * src/prog.c: Use mf_c_val to extract C values from STKVAL. (get_immediate): Return STKVAL. (prog): Change type (code_cell): New function. (code_instr): Rewrite using code_cell (code_immediate): Likewise. Change argument type. (code_exmask): Use proper typecast. (code_put): Change argument type. (code_peek): Change return type. (runtime_stack_trace): Use mf_cell_instr to access instruction pointer. * src/mailfromd.h (yyerror): Change signature. (instr_t): Move to prog.h (code_put,code_peek,code_reserve) (code_immediate,code_op,code_instr) (code_exmask,code_get_counter) (dump_code,fixup_code): Move to prog.h * src/exclist.c: Use mf_c_val * src/gram.y (yyerror): Change signature. (mailfromd_run): Use mf_c_val to extract actual value. * doc/functions.texi (body_has_nulls): Fix return type. * src/builtin/snarf.m4 (__mf_defun): Define __MF_RETTYPE__ (MF_RETURN): Take optional second argument (return type). Decide what push function to use and what type to cast the value to depending on its value and that of __MF_RETTYPE__. (MF_RETURN_STRING): Remove. (MF_RETURN_OBSTACK): Explicitly declare return type as STKVAL. (MF_VAR_REF): Take two or three arguments (second one declaring value type). (MF_ALLOC_HEAP_TEMP): (MF_VAR_STRING): Update. (END): Popdef __MF_RETTYPE__. * src/builtin/body.bi: Use MF_RETURN. (body_has_nulls): Fix return type. * src/builtin/burst.bi: Use MF_RETURN. * src/builtin/callout.bi: Likewise. * src/builtin/ctype.bi: Likewise. * src/builtin/curhdr.bi: Likewise. * src/builtin/db.bi: Likewise. * src/builtin/debug.bi: Likewise. * src/builtin/dns.bi: Likewise. * src/builtin/email.bi: Likewise. * src/builtin/geoip.bi: Likewise. * src/builtin/getopt.bi: Likewise. * src/builtin/gettext.bi: Likewise. * src/builtin/io.bi: Likewise. * src/builtin/ipaddr.bi: Likewise. * src/builtin/macro.bi: Likewise. * src/builtin/msg.bi: Likewise. * src/builtin/sa.bi: Likewise. * src/builtin/spf.bi: Likewise. * src/builtin/string.bi: Likewise. * src/builtin/system.bi: Likewise. * src/builtin/vars.bi: Likewise. * src/drivers.c: Use proper typecasts when calling code_* functions. * src/optab.opc (scan_code): Use mf_cell_c_value to inspect prog[].
Diffstat (limited to 'src')
-rw-r--r--src/builtin/body.bi4
-rw-r--r--src/builtin/burst.bi2
-rw-r--r--src/builtin/callout.bi4
-rw-r--r--src/builtin/ctype.bi2
-rw-r--r--src/builtin/curhdr.bi6
-rw-r--r--src/builtin/db.bi24
-rw-r--r--src/builtin/debug.bi2
-rw-r--r--src/builtin/dns.bi8
-rw-r--r--src/builtin/email.bi10
-rw-r--r--src/builtin/geoip.bi2
-rw-r--r--src/builtin/getopt.bi16
-rw-r--r--src/builtin/gettext.bi6
-rw-r--r--src/builtin/io.bi8
-rw-r--r--src/builtin/ipaddr.bi2
-rw-r--r--src/builtin/macro.bi2
-rw-r--r--src/builtin/msg.bi10
-rw-r--r--src/builtin/sa.bi6
-rw-r--r--src/builtin/snarf.m440
-rw-r--r--src/builtin/spf.bi4
-rw-r--r--src/builtin/string.bi22
-rw-r--r--src/builtin/system.bi4
-rw-r--r--src/builtin/vars.bi16
-rw-r--r--src/drivers.c154
-rw-r--r--src/exclist.c2
-rw-r--r--src/gram.y10
-rw-r--r--src/mailfromd.h17
-rw-r--r--src/optab.opc4
-rw-r--r--src/prog.c376
-rw-r--r--src/prog.h53
29 files changed, 432 insertions, 384 deletions
diff --git a/src/builtin/body.bi b/src/builtin/body.bi
index 42c8fd62..dfbcc913 100644
--- a/src/builtin/body.bi
+++ b/src/builtin/body.bi
@@ -23,12 +23,12 @@ MF_DEFUN(body_string, STRING, POINTER text, NUMBER length)
char *s = MF_ALLOC_HEAP(off, length + 1);
memcpy(s, text, length);
s[length] = 0;
- MF_RETURN(off);
+ MF_RETURN(off, size);
}
END
MF_STATE(body)
-MF_DEFUN(body_has_nulls, STRING, POINTER text, NUMBER length)
+MF_DEFUN(body_has_nulls, NUMBER, POINTER text, NUMBER length)
{
MF_RETURN(memchr(text, 0, length) != NULL);
}
diff --git a/src/builtin/burst.bi b/src/builtin/burst.bi
index 15c47244..72b94871 100644
--- a/src/builtin/burst.bi
+++ b/src/builtin/burst.bi
@@ -384,7 +384,7 @@ burst_digest(eval_environ_t env, mu_mime_t mime, mu_message_t msg,
struct burst_stream *bs;
int result = 0;
- int eb_min_length = (int) MF_VAR_REF(burst_eb_min_length);
+ int eb_min_length = MF_VAR_REF(burst_eb_min_length, int);
if (eb_min_length <= 0)
eb_min_length = DEFAULT_EB_LEN;
diff --git a/src/builtin/callout.bi b/src/builtin/callout.bi
index 5b36edc5..de5f93b6 100644
--- a/src/builtin/callout.bi
+++ b/src/builtin/callout.bi
@@ -31,8 +31,8 @@ MF_PRAGMA(provide-callout, 1, 1)
MF_DEFUN(default_callout_server_url, STRING)
{
- MF_RETURN_STRING(callout_server_url ?
- callout_server_url : DEFAULT_CALLOUT_SOCKET);
+ MF_RETURN(callout_server_url ?
+ callout_server_url : DEFAULT_CALLOUT_SOCKET);
}
END
diff --git a/src/builtin/ctype.bi b/src/builtin/ctype.bi
index 06556788..f0b8f05a 100644
--- a/src/builtin/ctype.bi
+++ b/src/builtin/ctype.bi
@@ -22,7 +22,7 @@ MF_DEFUN($1, NUMBER, STRING str)
int i;
for (i = 0; str[i]; i++)
if (!mu_$1(str[i])) {
- MF_VAR_REF(ctype_mismatch, i);
+ MF_VAR_REF(ctype_mismatch, int, i);
MF_RETURN(0);
}
MF_RETURN(1);
diff --git a/src/builtin/curhdr.bi b/src/builtin/curhdr.bi
index 01192bdb..59acace1 100644
--- a/src/builtin/curhdr.bi
+++ b/src/builtin/curhdr.bi
@@ -82,7 +82,7 @@ MF_DEFUN(current_header_nth_name, STRING, NUMBER index)
MF_THROW(mfe_failure,
"mu_header_sget_field_name: %s",
mu_strerror(rc));
- MF_RETURN_STRING(sptr);
+ MF_RETURN(sptr);
}
END
@@ -113,7 +113,7 @@ MF_DEFUN(current_header_nth_value, STRING, NUMBER index)
MF_THROW(mfe_failure,
"mu_header_sget_field_name: %s",
mu_strerror(rc));
- MF_RETURN_STRING(sptr);
+ MF_RETURN(sptr);
}
END
@@ -144,7 +144,7 @@ MF_DEFUN(current_header, STRING, STRING name, OPTIONAL, NUMBER index)
MF_THROW(mfe_failure,
"mu_header_sget_field_name: %s",
mu_strerror(rc));
- MF_RETURN_STRING(sptr);
+ MF_RETURN(sptr);
}
END
diff --git a/src/builtin/db.bi b/src/builtin/db.bi
index ffb1db67..e1226c4e 100644
--- a/src/builtin/db.bi
+++ b/src/builtin/db.bi
@@ -248,9 +248,9 @@ dbmap_lookup(eval_environ_t env, char *dbname, const char *keystr,
else {
if (rc) {
if (defval)
- pushs(env, (STKVAL)defval);
+ pushs(env, defval);
else
- push(env, 0);
+ push(env, (STKVAL) 0L);
} else if (((char*)contents.mu_dptr)[contents.mu_dsize-1]) {
size_t off;
size_t len = contents.mu_dsize;
@@ -547,7 +547,7 @@ MF_DEFUN(dbkey, STRING, NUMBER dn)
s = MF_ALLOC_HEAP(off, len + 1);
memcpy(s, dbt->key.mu_dptr, len);
s[len] = 0;
- MF_RETURN(off);
+ MF_RETURN(off, size);
}
END
@@ -576,7 +576,7 @@ MF_DEFUN(dbvalue, STRING, NUMBER dn)
memcpy(s, contents.mu_dptr, len);
s[len] = 0;
mu_dbm_datum_free(&contents);
- MF_RETURN(off);
+ MF_RETURN(off, size);
}
END
@@ -672,7 +672,7 @@ do_greylist_traditional(eval_environ_t env, char *email, long interval)
if (diff < interval) {
diff = interval - diff;
- MF_VAR_REF(greylist_seconds_left, diff);
+ MF_VAR_REF(greylist_seconds_left, ulong, diff);//FIXME
MF_DEBUG(MU_DEBUG_TRACE6,
("%s still greylisted (for %lu sec.)",
@@ -682,7 +682,7 @@ do_greylist_traditional(eval_environ_t env, char *email, long interval)
} else if (diff > greylist_format->expire_interval) {
MF_DEBUG(MU_DEBUG_TRACE6,
("greylist record for %s expired", email));
- MF_VAR_REF(greylist_seconds_left, interval);
+ MF_VAR_REF(greylist_seconds_left, long, interval);
if (!readonly) {
memcpy(contents.mu_dptr, &now, sizeof now);
rc = mu_dbm_store(db, &key, &contents, 1);
@@ -708,7 +708,7 @@ do_greylist_traditional(eval_environ_t env, char *email, long interval)
mu_dbm_datum_free(&contents);
} else if (!readonly) {
MF_DEBUG(MU_DEBUG_TRACE6, ("greylisting %s", email));
- MF_VAR_REF(greylist_seconds_left, interval);
+ MF_VAR_REF(greylist_seconds_left, long, interval);
contents.mu_dptr = (void*)&now;
contents.mu_dsize = sizeof now;
rc = mu_dbm_store(db, &key, &contents, 1);
@@ -786,7 +786,7 @@ do_greylist_ct(eval_environ_t env, char *email, long interval)
if (now < timestamp) {
time_t diff = timestamp - now;
- MF_VAR_REF(greylist_seconds_left, diff);
+ MF_VAR_REF(greylist_seconds_left, long, diff);
MF_DEBUG(MU_DEBUG_TRACE6,
("%s still greylisted (for %lu sec.)",
@@ -797,7 +797,7 @@ do_greylist_ct(eval_environ_t env, char *email, long interval)
greylist_format->expire_interval) {
MF_DEBUG(MU_DEBUG_TRACE6,
("greylist record for %s expired", email));
- MF_VAR_REF(greylist_seconds_left, interval);
+ MF_VAR_REF(greylist_seconds_left, long, interval);
if (!readonly) {
now += interval;
memcpy(contents.mu_dptr, &now, sizeof now);
@@ -825,7 +825,7 @@ do_greylist_ct(eval_environ_t env, char *email, long interval)
mu_dbm_datum_free(&contents);
} else if (!readonly) {
MF_DEBUG(MU_DEBUG_TRACE6, ("greylisting %s", email));
- MF_VAR_REF(greylist_seconds_left, interval);
+ MF_VAR_REF(greylist_seconds_left, long, interval);
now += interval;
contents.mu_dptr = (void*)&now;
contents.mu_dsize = sizeof now;
@@ -883,7 +883,7 @@ is_greylisted_ct(eval_environ_t env, char *email)
rc = timestamp > now;
if (rc)
- MF_VAR_REF(greylist_seconds_left, timestamp - now);
+ MF_VAR_REF(greylist_seconds_left, long, timestamp - now);
mu_dbm_datum_free(&contents);
} else
@@ -933,7 +933,7 @@ MF_DEFUN(db_name, STRING, STRING fmtid)
MF_ASSERT(fmt != NULL,
mfe_not_found,
_("no such db format: %s"), fmtid);
- MF_RETURN_STRING(fmt->dbname);
+ MF_RETURN(fmt->dbname);
}
END
diff --git a/src/builtin/debug.bi b/src/builtin/debug.bi
index 5d3b7d6c..d386997c 100644
--- a/src/builtin/debug.bi
+++ b/src/builtin/debug.bi
@@ -60,7 +60,7 @@ MF_DEFUN(debug_spec, STRING, OPTIONAL, STRING modnames, NUMBER showunset)
MF_ASSERT(rc == 0,
mfe_failure,
"%s", mu_strerror(rc));
- MF_RETURN(off);
+ MF_RETURN(off, size);
}
END
diff --git a/src/builtin/dns.bi b/src/builtin/dns.bi
index 926139ae..45e4d0d9 100644
--- a/src/builtin/dns.bi
+++ b/src/builtin/dns.bi
@@ -114,7 +114,7 @@ MF_DEFUN(dns_getaddr, STRING, STRING string)
}
case dns_not_found:
free(ipbuf);
- MF_RETURN_STRING("");
+ MF_RETURN("");
default:
free(ipbuf);
MF_THROW(dns_to_mf_status(dnstat),
@@ -167,7 +167,7 @@ MF_DEFUN(dns_getname, STRING, STRING ipstr)
}
case dns_not_found:
free(names);
- MF_RETURN_STRING("");
+ MF_RETURN("");
default:
free(names);
MF_THROW(dns_to_mf_status(dnstat),
@@ -213,7 +213,7 @@ MF_DEFUN(getmx, STRING, STRING domain, OPTIONAL, NUMBER no_resolve)
}
if (mxstat == mf_not_found) {
free(ipbuf);
- MF_RETURN_STRING("");
+ MF_RETURN("");
} else {
int i;
@@ -243,7 +243,7 @@ MF_DEFUN(getmx, STRING, STRING domain, OPTIONAL, NUMBER no_resolve)
}
if (mxstat == mf_not_found) {
mxbuf_free(&mxbuf);
- MF_RETURN_STRING("");
+ MF_RETURN("");
} else {
int i;
diff --git a/src/builtin/email.bi b/src/builtin/email.bi
index 75025dd2..7c01b87b 100644
--- a/src/builtin/email.bi
+++ b/src/builtin/email.bi
@@ -19,7 +19,7 @@
MF_DEFUN(domainpart, STRING, STRING str)
{
char *p = strchr(str, '@');
- MF_RETURN_STRING(p ? p+1 : str);
+ MF_RETURN(p ? p+1 : str);
}
END
@@ -33,9 +33,9 @@ MF_DEFUN(localpart, STRING, STRING str)
char *string_space = MF_ALLOC_HEAP(off, size + 1);
memcpy(string_space, str, size);
string_space[size] = 0;
- MF_RETURN(off);
+ MF_RETURN(off, size);
} else
- MF_RETURN_STRING(str);
+ MF_RETURN(str);
}
END
@@ -47,9 +47,9 @@ MF_DEFUN(dequote, STRING, STRING str)
char *string_space = MF_ALLOC_HEAP(off, len - 1);
memcpy(string_space, str + 1, len - 2);
string_space[len - 2] = 0;
- MF_RETURN(off);
+ MF_RETURN(off, size);
} else
- MF_RETURN_STRING(str);
+ MF_RETURN(str);
}
END
diff --git a/src/builtin/geoip.bi b/src/builtin/geoip.bi
index 4bbf7720..3bd7a0a6 100644
--- a/src/builtin/geoip.bi
+++ b/src/builtin/geoip.bi
@@ -51,7 +51,7 @@ MF_DEFUN(geoip_country_code_by_name, STRING, STRING name,
MF_ASSERT(ret != NULL && strcmp(ret, "N/A") != 0,
mfe_not_found,
_("country code not found"));
- MF_RETURN_STRING(ret);
+ MF_RETURN(ret);
}
END
diff --git a/src/builtin/getopt.bi b/src/builtin/getopt.bi
index e758af34..dda4215d 100644
--- a/src/builtin/getopt.bi
+++ b/src/builtin/getopt.bi
@@ -123,24 +123,24 @@ MF_DEFUN_VARARGS(getopt, STRING, NUMBER argc, NUMBER argoff)
}
if (xargc == 0 || optstr == NULL || option == 0)
- MF_RETURN_STRING("");
+ MF_RETURN("");
- optind = (int) MF_VAR_REF(optind);
- opterr = (int) MF_VAR_REF(opterr);
+ optind = MF_VAR_REF(optind, int);
+ opterr = MF_VAR_REF(opterr, int);
rc = getopt_long(xargc, xargv, optstr, option, &long_idx);
- MF_VAR_REF(optind, optind);
- MF_VAR_REF(opterr, opterr);
+ MF_VAR_REF(optind, int, optind);
+ MF_VAR_REF(opterr, int, opterr);
s[0] = optopt;
MF_VAR_SET_STRING(optopt, s);
MF_VAR_SET_STRING(optarg, optarg);
if (rc == EOF)
- MF_RETURN_STRING("");
+ MF_RETURN("");
if (rc < 256) {
s[0] = rc;
- MF_RETURN_STRING(s);
+ MF_RETURN(s);
}
- MF_RETURN_STRING(option[long_idx].name);
+ MF_RETURN(option[long_idx].name);
}
END
diff --git a/src/builtin/gettext.bi b/src/builtin/gettext.bi
index 9fb8e5bf..35d17ecf 100644
--- a/src/builtin/gettext.bi
+++ b/src/builtin/gettext.bi
@@ -20,20 +20,20 @@ MF_DEFUN(bindtextdomain, STRING, STRING domain, STRING dirname)
MF_ASSERT(s != NULL,
mfe_failure,
"bindtextdomain failed: %s", mu_strerror(errno));
- MF_RETURN_STRING(s);
+ MF_RETURN(s);
}
END
MF_DEFUN(dgettext, STRING, STRING domain, STRING msgid)
{
- MF_RETURN_STRING(dgettext(domain, msgid));
+ MF_RETURN(dgettext(domain, msgid));
}
END
MF_DEFUN(dngettext, STRING, STRING domain,
STRING msgid, STRING msgid_plural, NUMBER n)
{
- MF_RETURN_STRING(dngettext(domain, msgid, msgid_plural, n));
+ MF_RETURN(dngettext(domain, msgid, msgid_plural, n));
}
END
diff --git a/src/builtin/io.bi b/src/builtin/io.bi
index 18cb52dd..35e9f48e 100644
--- a/src/builtin/io.bi
+++ b/src/builtin/io.bi
@@ -954,7 +954,7 @@ MF_DEFUN(read, STRING, NUMBER fd, NUMBER size)
_("read error on %s: %s"),
iotab[fd].name, mu_strerror(errno));
s[size] = 0;
- MF_RETURN(off);
+ MF_RETURN(off, size);
}
END
@@ -1055,7 +1055,7 @@ MF_DEFUN(getdelim, STRING, NUMBER fd, STRING delim)
mfe_io,
_("read error on %s: %s"),
ioptr->name, mu_strerror(errno));
- MF_RETURN_STRING(ioptr->buf);
+ MF_RETURN(ioptr->buf);
}
END
@@ -1077,7 +1077,7 @@ MF_DEFUN(getline, STRING, NUMBER fd)
mfe_io,
_("read error on %s: %s"),
ioptr->name, mu_strerror(errno));
- MF_RETURN_STRING(ioptr->buf);
+ MF_RETURN(ioptr->buf);
}
END
@@ -1104,7 +1104,7 @@ MF_DEFUN(fd_delimiter, STRING, NUMBER fd, STRING delim)
mfe_range,
_("invalid file descriptor"));
ioptr = &iotab[fd];
- MF_RETURN_STRING(ioptr->delim ? ioptr->delim : "\n");
+ MF_RETURN(ioptr->delim ? ioptr->delim : "\n");
}
END
diff --git a/src/builtin/ipaddr.bi b/src/builtin/ipaddr.bi
index 0aefa29a..99694b19 100644
--- a/src/builtin/ipaddr.bi
+++ b/src/builtin/ipaddr.bi
@@ -63,7 +63,7 @@ MF_DEFUN(inet_ntoa, STRING, NUMBER ip)
struct in_addr addr;
addr.s_addr = htonl(ip);
- MF_RETURN_STRING(inet_ntoa(addr));
+ MF_RETURN(inet_ntoa(addr));
}
END
diff --git a/src/builtin/macro.bi b/src/builtin/macro.bi
index 9099fb7c..3b706c10 100644
--- a/src/builtin/macro.bi
+++ b/src/builtin/macro.bi
@@ -35,7 +35,7 @@ MF_DEFUN(getmacro, STRING, STRING name)
MF_ASSERT(s,
mfe_macroundef, _("macro not defined: %s"),
name);
- MF_RETURN_STRING(s);
+ MF_RETURN(s);
}
END
diff --git a/src/builtin/msg.bi b/src/builtin/msg.bi
index 3feafd9c..0b9761b5 100644
--- a/src/builtin/msg.bi
+++ b/src/builtin/msg.bi
@@ -399,7 +399,7 @@ MF_DEFUN(message_find_header, STRING, NUMBER nmsg, STRING header,
MF_THROW(mfe_not_found, _("header not found"));
else if (rc)
MF_THROW(mfe_failure, "%s", mu_strerror(rc));
- MF_RETURN_STRING(val);
+ MF_RETURN(val);
}
END
@@ -415,7 +415,7 @@ MF_DEFUN(message_nth_header_name, STRING, NUMBER nmsg, NUMBER idx)
MF_THROW(mfe_range, "header index out of range");
else if (rc)
MF_THROW(mfe_failure, "%s", mu_strerror(rc));
- MF_RETURN_STRING(val);
+ MF_RETURN(val);
}
END
@@ -431,7 +431,7 @@ MF_DEFUN(message_nth_header_value, STRING, NUMBER nmsg, NUMBER idx)
MF_THROW(mfe_range, "header index out of range");
else if (rc)
MF_THROW(mfe_failure, "%s", mu_strerror(rc));
- MF_RETURN_STRING(val);
+ MF_RETURN(val);
}
END
@@ -522,7 +522,7 @@ MF_DEFUN(message_read_line, STRING, NUMBER nmsg)
mfe_eof,
"mu_stream_getline: %s",
_("end of input"));
- MF_RETURN_STRING(mp->buf);
+ MF_RETURN(mp->buf);
}
END
@@ -557,7 +557,7 @@ MF_DEFUN(message_read_body_line, STRING, NUMBER nmsg)
mfe_eof,
"mu_stream_getline: %s",
_("end of input"));
- MF_RETURN_STRING(mp->buf);
+ MF_RETURN(mp->buf);
}
END
diff --git a/src/builtin/sa.bi b/src/builtin/sa.bi
index 0fd16f61..98326b86 100644
--- a/src/builtin/sa.bi
+++ b/src/builtin/sa.bi
@@ -440,8 +440,8 @@ MF_DEFUN(spamc, NUMBER, NUMBER nmsg, STRING urlstr, NUMBER prec, NUMBER command)
decode_float(&score, score_str, prec);
decode_float(&threshold, threshold_str, prec);
- MF_VAR_REF(sa_score, score);
- MF_VAR_REF(sa_threshold, threshold);
+ MF_VAR_REF(sa_score, long, score);
+ MF_VAR_REF(sa_threshold, long, threshold);
/* Skip newline */
spamd_get_line(ostr, &buffer, &bufsize);
@@ -464,7 +464,7 @@ MF_DEFUN(spamc, NUMBER, NUMBER nmsg, STRING urlstr, NUMBER prec, NUMBER command)
&& n > 0)
MF_OBSTACK_GROW(buffer, n);
MF_OBSTACK_1GROW(0);
- MF_VAR_REF(sa_keywords, MF_OBSTACK_FINISH);
+ MF_VAR_REF(sa_keywords, ptr, mf_c_val(MF_OBSTACK_FINISH, ptr));//FIXME
break;
case SA_SYMBOLS:
diff --git a/src/builtin/snarf.m4 b/src/builtin/snarf.m4
index 2c64a755..9decf7c6 100644
--- a/src/builtin/snarf.m4
+++ b/src/builtin/snarf.m4
@@ -390,6 +390,7 @@ m4_define([<__mf_defun>],m4_dnl
void
bi_$2(eval_environ_t env)
m4_pushdef([<__MF_FUNCTION__>], $2)m4_dnl
+m4_pushdef([<__MF_RETTYPE__>], $3)m4_dnl
m4_pushdef([<__MF_ARGLIST__>], [<m4_shift(m4_shift(m4_shift($*)))>])
m4_ifelse($3,STRING,[<MF_DSEXP>])
m4_divert(1)m4_dnl
@@ -440,7 +441,7 @@ m4_errprint(m4___file__:m4___line__: [<return used in MF_DEFUN>]
)
m4_define([<__mf_error_code>],1)>],[<[<return>]>])>])
-/* MF_RETURN(value) - Return a numeric value
+/* MF_RETURN(value[,type]) - Return a value
*/
m4_define([<MF_RETURN>],[<
m4_ifdef([<__MF_VA_START_USED__>],[<m4_dnl
@@ -448,23 +449,19 @@ m4_errprint(m4___file__:m4___line__: [<MF_RETURN>] used before [<MF_VA_END>]
)
m4_define([<__mf_error_code>],1)>],[<m4_dnl
do {
- push(env, (STKVAL) ($1));
+m4_pushdef([<__type>],[<m4_ifelse($2,,__MF_RETTYPE__,$2)>])m4_dnl
+ m4_ifelse(__type,[<NUMBER>],[<push(env, (STKVAL)(mft_number)($1))>],m4_dnl
+__type,[<STRING>],[<pushs(env, $1)>],m4_dnl
+__type,[<string>],[<pushs(env, $1)>],m4_dnl
+__type,[<STKVAL>],[<push(env, (STKVAL) ($1))>],m4_dnl
+__type,,[<m4_errprint(m4___file__:m4___line__: return type undefined
+)>],m4_dnl
+[<push(env, (STKVAL) ([<mft_>]$2) ($1))>]);
+m4_popdef([<__type>])m4_dnl
goto endlab;
m4_define([<__MF_ENDLAB__>])m4_dnl
} while (0)>])>])
-/* MF_RETURN_STRING(value) - Return a string value
- */
-m4_define([<MF_RETURN_STRING>],[<m4_dnl
-m4_ifdef([<__MF_VA_START_USED__>],[<m4_dnl
-m4_errprint(m4___file__:m4___line__: [<MF_RETURN_STRING>] used before [<MF_VA_END>]
-)
-m4_define([<__mf_error_code>],1)>],[<do {m4_dnl
-pushs(env, $1);
-goto endlab;
-m4_define([<__MF_ENDLAB__>])m4_dnl
-} while (0)>])>])
-
/* MF_ALLOC_HEAP(off, len) - Allocate LEN bytes from the heap
*/
m4_define([<MF_ALLOC_HEAP>],[<m4_dnl
@@ -474,7 +471,7 @@ __MF_DSEXP_REQ()m4_dnl
/* MF_ALLOC_HEAP_TEMP(len) - Temporarly allocate LEN bytes from the heap.
*/
m4_define([<MF_ALLOC_HEAP_TEMP>],[<__MF_DSEXP_REQ()m4_dnl
-heap_tempspace(env, $1)>])
+mf_c_val(heap_tempspace(env, $1), ptr)>])
/* MF_COPY_STRING(off, string) - Copy STRING to the heap. Return the
* pointer to the copy.
@@ -511,7 +508,7 @@ m4_define([<MF_OBSTACK_BASE>],[<heap_obstack_base(env)>])
/* MF_RETURN_OBSTACK() - Relocate and return temporary space
*/
-m4_define([<MF_RETURN_OBSTACK>],[<MF_RETURN(heap_obstack_finish(env))>])
+m4_define([<MF_RETURN_OBSTACK>],[<MF_RETURN(heap_obstack_finish(env),[<STKVAL>])>])
/* MF_OBSTACK_FINISH() - Relocate temporary space and return its starting
offset.
@@ -574,15 +571,15 @@ m4_divert(1)m4_dnl
m4_divert(2)m4_dnl
>])
-/* MF_VAR_REF(name[, value]) - Reference global variable NAME
- * In one-argument form, return its value. In two-arguments form, assign
+/* MF_VAR_REF(name, type[, value]) - Reference global variable NAME
+ * In two-argument form, return its value. In three-arguments form, assign
* the VALUE to it.
*/
m4_define([<MF_VAR_REF>],[<m4_dnl
-*env_data_ref(env, $1_loc) m4_ifelse($2,,,= (STKVAL) ($2))>])
+mf_c_val(*env_data_ref(env, $1_loc),$2) m4_ifelse($3,,,= ($3))>])
m4_define([<MF_VAR_STRING>],[<m4_dnl
-(char*)env_data_ref(env, (size_t)MF_VAR_REF($1))>])
+(char*)env_data_ref(env, MF_VAR_REF($1, size))>])
/* MF_VAR_SET_STRING(name, value) - Set variable NAME to the string VALUE */
m4_define([<MF_VAR_SET_STRING>],[<
@@ -592,7 +589,7 @@ m4_define([<MF_VAR_SET_STRING>],[<
MF_COPY_STRING(__off, __s);
else
__off = 0;
- MF_VAR_REF($1, __off); }
+ MF_VAR_REF($1, size, __off); }
>])
/* MF_VAR_INC(name) - Increment the value of the global variable NAME
@@ -670,6 +667,7 @@ m4_errprint(>]__MF_VA_START_USED__[<: This is the location of [<MF_VA_START>]
m4_define([<__mf_error_code>],1)m4_dnl
m4_undefine([<__MF_VA_START_USED__>])>])m4_dnl
m4_popdef([<__MF_FUNCTION__>])m4_dnl
+m4_popdef([<__MF_RETTYPE__>])m4_dnl
m4_popdef([<__MF_ARGLIST__>])m4_dnl
m4_popdef([<__MF_VARARGS__>])m4_dnl
m4_undefine([<__MF_CAPTURE__>])m4_dnl
diff --git a/src/builtin/spf.bi b/src/builtin/spf.bi
index e3f44ce1..1effd412 100644
--- a/src/builtin/spf.bi
+++ b/src/builtin/spf.bi
@@ -27,9 +27,9 @@ update_spf_vars(eval_environ_t env, spf_answer_t *ans)
{
MF_VAR_SET_STRING(spf_explanation, ans->exp_text);
MF_VAR_SET_STRING(spf_mechanism, ans->mech);
- MF_VAR_REF(spf_ttl, ans->ttl);
+ MF_VAR_REF(spf_ttl, ulong, ans->ttl);
}
- >])
+>])
MF_DSEXP
MF_DEFUN(spf_check_host, NUMBER, STRING ip, STRING domain, STRING sender,
diff --git a/src/builtin/string.bi b/src/builtin/string.bi
index 5d84263e..1e81bfbd 100644
--- a/src/builtin/string.bi
+++ b/src/builtin/string.bi
@@ -21,7 +21,7 @@ MF_DEFUN(toupper, STRING, STRING string)
char *p;
for (p = s; *p; p++)
*p = toupper(*p);
- MF_RETURN(off);
+ MF_RETURN(off, size);
}
END
@@ -32,7 +32,7 @@ MF_DEFUN(tolower, STRING, STRING string)
char *p;
for (p = s; *p; p++)
*p = tolower(*p);
- MF_RETURN(off);
+ MF_RETURN(off, size);
}
END
@@ -64,7 +64,7 @@ MF_DEFUN(substring, STRING, STRING string, NUMBER start, NUMBER end)
memcpy(s, string + start, len);
s[len] = 0;
- MF_RETURN(off);
+ MF_RETURN(off, size);
}
END
@@ -85,7 +85,7 @@ MF_DEFUN(substr, STRING, STRING string, NUMBER start, OPTIONAL, NUMBER nbytes)
memcpy(s, string + start, nbytes);
s[nbytes] = 0;
- MF_RETURN(off);
+ MF_RETURN(off, size);
}
END
@@ -153,7 +153,7 @@ MF_DEFUN(revstr, STRING, STRING str)
s[len] = 0;
for (p = s + len - 1; p >= s; p--, str++)
*p = *str;
- MF_RETURN(off);
+ MF_RETURN(off, size);
}
END
@@ -166,7 +166,7 @@ MF_DEFUN(replstr, STRING, STRING text, NUMBER count)
MF_ASSERT(count >= 0, mfe_range,
_("argument out of range: count=%ld"), count);
if (count == 0)
- MF_RETURN_STRING("");
+ MF_RETURN("");
len = strlen(text);
size = len * count;
@@ -174,7 +174,7 @@ MF_DEFUN(replstr, STRING, STRING text, NUMBER count)
for (i = 0; i < count; i++, s += len)
memcpy(s, text, len);
*s = 0;
- MF_RETURN(off);
+ MF_RETURN(off, size);
}
END
@@ -212,7 +212,7 @@ MF_DEFUN(unfold, STRING, STRING text)
size_t off;
char *s = MF_COPY_STRING(off, text);
mu_string_unfold(s, NULL);
- MF_RETURN(off);
+ MF_RETURN(off, size);
}
END
@@ -221,7 +221,7 @@ MF_DEFUN(escape, STRING, STRING text, OPTIONAL, STRING chars)
char *charmap = MF_OPTVAL(chars, "\\\"");
if (text[strcspn(text, charmap)] == 0)
- MF_RETURN_STRING(text);
+ MF_RETURN(text);
MF_OBSTACK_BEGIN();
for (;;) {
@@ -265,7 +265,7 @@ MF_DEFUN(ltrim, STRING, STRING input, OPTIONAL, STRING cset)
{
char *p = MF_OPTVAL(cset, " \t\r\n\f");
for (; *input && strchr(p, *input); input++);
- MF_RETURN_STRING(input);
+ MF_RETURN(input);
}
END
@@ -279,7 +279,7 @@ MF_DEFUN(rtrim, STRING, STRING input, OPTIONAL, STRING cset)
p = MF_ALLOC_HEAP(off, len+1);
memcpy(p, input, len);
p[len] = 0;
- MF_RETURN(off);
+ MF_RETURN(off, size);
}
END
diff --git a/src/builtin/system.bi b/src/builtin/system.bi
index e583c34b..aceb41db 100644
--- a/src/builtin/system.bi
+++ b/src/builtin/system.bi
@@ -50,7 +50,7 @@ MF_DEFUN(strftime, STRING, STRING fmt, NUMBER timestamp, OPTIONAL, NUMBER gmt)
size_t off;
char *s = MF_ALLOC_HEAP(off, size + 1);
strcpy(s, buf);
- MF_RETURN(off);
+ MF_RETURN(off, size);
}
END
@@ -145,7 +145,7 @@ MF_DEFUN(getenv, STRING, STRING name)
mfe_not_found,
"%s: environment variable not defined",
name);
- MF_RETURN_STRING(p);
+ MF_RETURN(p);
}
END
diff --git a/src/builtin/vars.bi b/src/builtin/vars.bi
index 60b3e12b..a13083c4 100644
--- a/src/builtin/vars.bi
+++ b/src/builtin/vars.bi
@@ -27,13 +27,13 @@ MF_VAR(sendmail_header_count, NUMBER, SYM_PRECIOUS);
unsigned long
get_rcpt_count(eval_environ_t env)
{
- return (long) MF_VAR_REF(rcpt_count);
+ return MF_VAR_REF(rcpt_count, long);
}
void
clear_rcpt_count(eval_environ_t env)
{
- MF_VAR_REF(rcpt_count, 0);
+ MF_VAR_REF(rcpt_count, long, 0);
}
void
@@ -46,