aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2009-09-30 15:19:33 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2009-09-30 15:19:33 +0300
commitc1b69f5eae1bb4dfb32f5afe7cbcdb99c9c4693e (patch)
tree4fb7ec6a37ce77090f87fad07a72fb8267dfdf23
parentafa79161b65f810b8ad0ef37a8408d91061a1085 (diff)
downloadmailfromd-c1b69f5eae1bb4dfb32f5afe7cbcdb99c9c4693e.tar.gz
mailfromd-c1b69f5eae1bb4dfb32f5afe7cbcdb99c9c4693e.tar.bz2
Fix --dump-code and --dump-tree output.
* NEWS: Update. * configure.ac: Bump version number: 5.9.90 * lib/libmf.h (symtab_count_entries): New proto. * lib/symtab.c (symtab_count_entries): New function. * mfd/gram.y (function_enumerator): Process only functions from one module. (print_syntax_tree): Iterate over all modules. * mfd/mailfromd.h (collect_modules): New proto. * mfd/prog.c (function_counter): Change closure type. Process only functions from one module. (function_lister): Process only functions from one module. (print_code): Iterate over all modules. * mfd/symbols.c (collect_modules): New function. (free_module_entry): Pass file name to "top" module creation call. * mflib/safedb.mf4: Require status, not "#include" it.
-rw-r--r--NEWS4
-rw-r--r--configure.ac2
-rw-r--r--lib/libmf.h3
-rw-r--r--lib/symtab.c12
-rw-r--r--mfd/gram.y39
-rw-r--r--mfd/mailfromd.h1
-rw-r--r--mfd/prog.c51
-rw-r--r--mfd/symbols.c33
-rw-r--r--mflib/safedb.mf42
9 files changed, 107 insertions, 40 deletions
diff --git a/NEWS b/NEWS
index 2c314d5f..bd82b8e0 100644
--- a/NEWS
+++ b/NEWS
@@ -1,11 +1,11 @@
-Mailfromd NEWS -- history of user-visible changes. 2009-09-18
+Mailfromd NEWS -- history of user-visible changes. 2009-09-30
Copyright (C) 2005, 2006, 2007, 2008, 2009 Sergey Poznyakoff
See the end of file for copying conditions.
Please send Mailfromd bug reports to <bug-mailfromd@gnu.org.ua>
-Version 5.2.90, 2009-08-28
+Version 5.9.90 (Git)
* Incompatible changes
diff --git a/configure.ac b/configure.ac
index 5ed7a890..8c930578 100644
--- a/configure.ac
+++ b/configure.ac
@@ -16,7 +16,7 @@
AC_PREREQ(2.63)
m4_define([MF_VERSION_MAJOR], 5)
-m4_define([MF_VERSION_MINOR], 2)
+m4_define([MF_VERSION_MINOR], 9)
m4_define([MF_VERSION_PATCH], 90)
AC_INIT([mailfromd],
MF_VERSION_MAJOR.MF_VERSION_MINOR[]m4_ifdef([MF_VERSION_PATCH],.MF_VERSION_PATCH),
diff --git a/lib/libmf.h b/lib/libmf.h
index c0cf7596..58ae0993 100644
--- a/lib/libmf.h
+++ b/lib/libmf.h
@@ -110,6 +110,9 @@ int symtab_import(struct symtab *dst, struct symtab *src,
symtab_selfun selfun, symtab_errfun errfun,
symtab_confun confun, symtab_cpyfun cpyfun,
void *closure);
+
+size_t symtab_count_entries(struct symtab *st);
+
typedef struct transform *transform_t;
diff --git a/lib/symtab.c b/lib/symtab.c
index 3e69c4cf..55b01083 100644
--- a/lib/symtab.c
+++ b/lib/symtab.c
@@ -356,6 +356,18 @@ symtab_destroy(struct symtab **pst)
}
}
+size_t
+symtab_count_entries(struct symtab *st)
+{
+ unsigned i;
+ size_t count = 0;
+
+ for (i = 0; i < hash_size[st->hash_num]; i++)
+ if (st->tab[i])
+ count++;
+ return count;
+}
+
int
symtab_enumerate(struct symtab *st, symtab_enumerator_t fun, void *data)
{
diff --git a/mfd/gram.y b/mfd/gram.y
index 43e8757f..26ebc445 100644
--- a/mfd/gram.y
+++ b/mfd/gram.y
@@ -2479,7 +2479,10 @@ function_enumerator(void *sym, void *data)
struct function *fsym = sym;
struct function *f =
(struct function *)symbol_resolve_alias(&fsym->sym);
-
+ struct module *mod = data;
+
+ if (f->sym.module != mod)
+ return 0;
printf("function %s (", f->sym.name);
for (i = 0; i < f->parmcount; i++) {
printf("%s", type_to_string(f->parmtype[i]));
@@ -2498,8 +2501,9 @@ function_enumerator(void *sym, void *data)
void
print_syntax_tree()
{
- struct module_list *mp;
-
+ struct module **modv;
+ size_t i, modc;
+
enum smtp_state tag;
printf("State handlers:\n");
@@ -2513,22 +2517,21 @@ print_syntax_tree()
}
printf("User functions:\n");
printf("---------------\n");
- symtab_enumerate(TOP_MODULE_SYMTAB(namespace_function),
- function_enumerator, NULL);
- printf("Modules:\n");
- printf("--------\n");
-
- /* FIXME */
- for (mp = top_module->submodule_head; mp; mp = mp->next) {
- printf("Module %s (%s)\n", mp->module->name,
- mp->module->file);
- printf("Declared name: %s\n",
- mp->module->dclname ?
- mp->module->dclname : mp->module->name);
- symtab_enumerate(MODULE_SYMTAB(mp->module, namespace_function),
- function_enumerator, NULL);
- printf("--------\n");
+
+ collect_modules(&modv, &modc);
+ for (i = 0; i < modc; i++) {
+ size_t n;
+
+ n = printf("Module %s (%s)\n", modv[i]->name,
+ modv[i]->file);
+ while (n--)
+ putchar('-');
+ putchar('\n');
+ symtab_enumerate(MODULE_SYMTAB(modv[i], namespace_function),
+ function_enumerator, modv[i]);
+ putchar('\n');
}
+ free(modv);
}
diff --git a/mfd/mailfromd.h b/mfd/mailfromd.h
index 1a9a77fa..13273b2a 100644
--- a/mfd/mailfromd.h
+++ b/mfd/mailfromd.h
@@ -758,6 +758,7 @@ int set_top_module(const char *name, const char *file,
const struct locus *locus);
void pop_top_module(void);
void module_push(struct module *mod);
+void collect_modules(struct module ***pmodv, size_t *pmodc);
diff --git a/mfd/prog.c b/mfd/prog.c
index ae8b7af6..f06632e7 100644
--- a/mfd/prog.c
+++ b/mfd/prog.c
@@ -2467,16 +2467,6 @@ builtin_setup ()
-static int
-function_counter(void *sym, void *data)
-{
- struct function *fp = (struct function *)sym;
- size_t *p = data;
- if (fp->sym.alias == NULL)
- ++*p;
- return 0;
-}
-
struct entry_point {
int ishandler;
prog_counter_t pc;
@@ -2487,16 +2477,28 @@ struct entry_point {
};
struct enum_data {
- int i;
+ size_t i;
+ struct module *mod;
struct entry_point *base;
};
static int
+function_counter(void *sym, void *data)
+{
+ struct function *fp = (struct function *)sym;
+ struct enum_data *d = data;
+ if (fp->sym.module == d->mod && fp->sym.alias == NULL)
+ d->i++;
+ return 0;
+}
+
+static int
function_lister(void *sym, void *data)
{
struct function *f = sym;
struct enum_data *d = data;
- if (f->sym.alias == NULL) {
+
+ if (f->sym.module == d->mod && f->sym.alias == NULL) {
d->base[d->i].ishandler = 0;
d->base[d->i].v.name = f->sym.name;
d->base[d->i].pc = f->entry;
@@ -2544,14 +2546,23 @@ print_code()
size_t epcount = 0; /* Number of entry points */
size_t i;
struct enum_data d;
+ struct module **modv;
+ size_t modc;
+ /* Get all modules */
+ collect_modules(&modv, &modc);
+
/* Count all available entry points: */
+ d.i = 0;
+ for (i = 0; i < modc; i++) {
+ d.mod = modv[i];
+ symtab_enumerate(MODULE_SYMTAB(modv[i], namespace_function),
+ function_counter, &d);
+ }
+ epcount = d.i;
for (tag = smtp_state_first; tag < smtp_state_count; tag++)
if (entry_point[tag])
epcount++;
- symtab_enumerate(TOP_MODULE_SYMTAB(namespace_function),
- function_counter,
- &epcount);
ep = xmalloc((epcount+1)*sizeof *ep);
@@ -2567,8 +2578,14 @@ print_code()
d.base = ep;
d.i = i;
- symtab_enumerate(TOP_MODULE_SYMTAB(namespace_function),
- function_lister, &d);
+ for (i = 0; i < modc; i++) {
+ d.mod = modv[i];
+ symtab_enumerate(MODULE_SYMTAB(modv[i], namespace_function),
+ function_lister, &d);
+ }
+
+ /* Dispose of module vector */
+ free (modv);
/* Sort the array */
qsort(ep, epcount, sizeof ep[0], comp_pc);
diff --git a/mfd/symbols.c b/mfd/symbols.c
index 8f657490..dbbf38fe 100644
--- a/mfd/symbols.c
+++ b/mfd/symbols.c
@@ -572,6 +572,37 @@ pop_top_module()
}
}
+static int
+_collect_modules(void *ep, void *data)
+{
+ struct module ***pmod = data;
+ *(*pmod)++ = ep;
+ return 0;
+}
+
+static int
+_module_comp(const void *a, const void *b)
+{
+ const struct module *am = a;
+ const struct module *bm = b;
+ return strcmp(am->name, bm->name);
+}
+
+void
+collect_modules(struct module ***pmodv, size_t *pmodc)
+{
+ size_t modc = symtab_count_entries(stab_module);
+ struct module **modv = xcalloc(modc + 1, sizeof(*modv));
+ struct module **tmp = modv + 1;
+
+ modv[0] = top_module;
+ symtab_enumerate(stab_module, _collect_modules, &tmp);
+ qsort(modv + 1, modc, sizeof(modv[0]), _module_comp);
+ modc++;
+ *pmodv = modv;
+ *pmodc = modc;
+}
+
void
free_module_entry(void *ptr)
@@ -592,7 +623,7 @@ init_symbols()
SYMTAB_COPY_KEY, NULL);
stab_literal = xsymtab_create(sizeof(struct literal),
SYMTAB_COPY_KEY, NULL);
- top_module = module_create("top", NULL); /*FIXME: file name*/
+ top_module = module_create("top", script_file);
}
void
diff --git a/mflib/safedb.mf4 b/mflib/safedb.mf4
index d51e00ca..808f4860 100644
--- a/mflib/safedb.mf4
+++ b/mflib/safedb.mf4
@@ -14,7 +14,7 @@
You should have received a copy of the GNU General Public License
along with this program . If not, see <http://www.gnu.org/licenses/>. */
-#include_once <status.mfh>
+require status
number safedb_verbose

Return to:

Send suggestions and report system problems to the System administrator.