summaryrefslogtreecommitdiff
path: root/libmu_sieve/mem.c
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2016-12-04 11:23:43 +0200
committerSergey Poznyakoff <gray@gnu.org>2016-12-04 11:45:37 +0200
commite2bd3a059eb8268d156baf59e41909cae1e28297 (patch)
tree2bb388b447716624c6afb7b157cfa1faddc2f497 /libmu_sieve/mem.c
parentfdf02db320d6bd88920cdcd15db3c45f71d2fb74 (diff)
downloadmailutils-e2bd3a059eb8268d156baf59e41909cae1e28297.tar.gz
mailutils-e2bd3a059eb8268d156baf59e41909cae1e28297.tar.bz2
sieve: redo symbol registry support.
The purpose is to simplify the machine structure and to ensure its clones are completely independent of the master instance. * include/mailutils/sieve.h (mu_sieve_command): New struct. (mu_sieve_record): New enum (mu_sieve_registry_t): Generalize for storing various types of objects. (mu_sieve_test_lookup,mu_sieve_action_lookup) (mu_sieve_require_action,mu_sieve_require_test) (mu_sieve_require_comparator): Remove. (mu_sieve_register_test_ext,mu_sieve_register_test) (mu_sieve_register_action_ext,mu_sieve_register_action) (mu_sieve_register_comparator) (mu_sieve_load_ext): Change return type. (mu_sieve_registry_require,mu_sieve_unload_ext): New functions. (mu_sieve_machine_inherit): Rename to mu_sieve_machine_clone. * libmu_sieve/sieve-priv.h (mu_sieve_machine): Remove source_list, test_list, action_list, and comp_list. Add a single registry list instead. Add space for file and command (action and test) names: idspace, idcount, idmax. Remove unused field "stack"; (mu_i_sv_lex_finish): Change prototype. (_mu_i_sv_instr_push,_mu_i_sv_instr_pop): Remove protos. (mu_i_sv_id_canon,mu_i_sv_id_num) (mu_i_sv_id_str,mu_i_sv_free_idspace): New protos. * libmu_sieve/register.c: Rename to registry.c * libmu_sieve/registry.c (mu_sieve_test_lookup) (mu_sieve_action_lookup): Remove. (mu_sieve_require_test,mu_sieve_require_action): Remove. (mu_sieve_registry_require): New function. (mu_sieve_registry_add,mu_sieve_registry_lookup): New functions. * libmu_sieve/Makefile.am: Update. * libmu_sieve/comparator.c: Rewrite using new registry functions. * libmu_sieve/load.c (mu_sieve_load_ext): Return module handle. (mu_sieve_unload_ext): New function. * libmu_sieve/mem.c (mu_sieve_free): Gracefully handle NULL argument. (mu_i_sv_id_canon,mu_i_sv_id_num,mu_i_sv_id_str): New functions. * libmu_sieve/prog.c (mu_i_sv_locus): Store index of the file name in the id space, instead of pointer to the name itself. * libmu_sieve/require.c (mu_sieve_require): Rewrite. * libmu_sieve/runtime.c (_mu_i_sv_instr_source): Expect ID index as argument. (_mu_i_sv_instr_push) (_mu_i_sv_instr_pop): Remove unused instructions. * libmu_sieve/sieve.l (file_names): Remove. Use mu_sieve_machine idspace instead. * libmu_sieve/sieve.y (mu_sieve_machine_clone) (mu_sieve_machine_dup): Rewrite. (mu_sieve_machine_destroy): Free idspace and registry * examples/numaddr.c: Reflect changes. * libmu_sieve/extensions/editheader.c: Likewise. * libmu_sieve/extensions/list.c: Likewise. * libmu_sieve/extensions/moderator.c: Likewise. * libmu_sieve/extensions/pipe.c: Likewise. * libmu_sieve/extensions/spamd.c: Likewise. * libmu_sieve/extensions/timestamp.c: Likewise. * libmu_sieve/extensions/vacation.c: Likewise.
Diffstat (limited to 'libmu_sieve/mem.c')
-rw-r--r--libmu_sieve/mem.c65
1 files changed, 65 insertions, 0 deletions
diff --git a/libmu_sieve/mem.c b/libmu_sieve/mem.c
index 3c39a3d10..565ba3228 100644
--- a/libmu_sieve/mem.c
+++ b/libmu_sieve/mem.c
@@ -83,6 +83,9 @@ mu_sieve_free (mu_sieve_machine_t mach, void *ptr)
int rc;
struct memory_cell mcell;
+ if (!ptr)
+ return;
+
mcell.ptr = ptr;
rc = mu_list_remove (mach->memory_pool, &mcell);
if (rc)
@@ -228,3 +231,65 @@ mu_i_sv_2nrealloc (mu_sieve_machine_t mach, void **pptr, size_t *pnmemb,
*pptr = ptr;
*pnmemb = nmemb;
}
+
+char *
+mu_i_sv_id_canon (mu_sieve_machine_t mach, char const *name)
+{
+ size_t i;
+ char *p;
+
+ if (!name)
+ return NULL;
+
+ for (i = 0; i < mach->idcount; i++)
+ {
+ if (strcmp (mach->idspace[i], name) == 0)
+ return mach->idspace[i];
+ }
+
+ if (mach->idcount == mach->idmax)
+ {
+ mu_i_sv_2nrealloc (mach,
+ (void **) &mach->idspace,
+ &mach->idmax,
+ sizeof mach->idspace[0]);
+ }
+
+ p = mu_sieve_strdup (mach, name);
+ mach->idspace[mach->idcount++] = p;
+
+ return p;
+}
+
+size_t
+mu_i_sv_id_num (mu_sieve_machine_t mach, char const *name)
+{
+ size_t i;
+
+ for (i = 0; i < mach->idcount; i++)
+ {
+ if (mach->idspace[i] == name || strcmp (mach->idspace[i], name) == 0)
+ return i;
+ }
+ abort ();
+}
+
+char *
+mu_i_sv_id_str (mu_sieve_machine_t mach, size_t n)
+{
+ if (n >= mach->idcount)
+ abort ();
+ return mach->idspace[n];
+}
+
+void
+mu_i_sv_free_idspace (mu_sieve_machine_t mach)
+{
+ size_t i;
+
+ for (i = 0; i < mach->idcount; i++)
+ mu_sieve_free (mach, mach->idspace[i]);
+ mach->idcount = 0;
+}
+
+

Return to:

Send suggestions and report system problems to the System administrator.