From: Arran Cudbard-Bell Date: Thu, 18 Mar 2021 20:57:29 +0000 (+0000) Subject: Rename unlang init functions X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=fe2b13ff0eeba75903cd7879f480c4b94e2f5a38;p=thirdparty%2Ffreeradius-server.git Rename unlang init functions --- diff --git a/src/bin/unit_test_attribute.c b/src/bin/unit_test_attribute.c index 3a599578b1c..cfe8599cb7e 100644 --- a/src/bin/unit_test_attribute.c +++ b/src/bin/unit_test_attribute.c @@ -3121,7 +3121,10 @@ int main(int argc, char *argv[]) * Initialise the interpreter, registering operations. * Needed because some keywords also register xlats. */ - if (unlang_init() < 0) return -1; + if (unlang_init_global() < 0) { + fr_perror("unit_test_attribute"); + EXIT_WITH_FAILURE; + } if (!xlat_register_legacy(inst, "test", xlat_test, NULL, NULL, 0, XLAT_DEFAULT_BUF_LEN)) { ERROR("Failed registering xlat"); @@ -3204,8 +3207,7 @@ cleanup: fr_perror("unit_test_attribute - dl_loader - "); /* Print free order issues */ } fr_dict_free(&config.dict); - unlang_free(); - xlat_free(); + unlang_free_global(); /* * Dictionaries get freed towards the end diff --git a/src/bin/unit_test_module.c b/src/bin/unit_test_module.c index df2d0e926fe..2edadc0a9e7 100644 --- a/src/bin/unit_test_module.c +++ b/src/bin/unit_test_module.c @@ -800,8 +800,12 @@ int main(int argc, char *argv[]) /* * Initialise the interpreter, registering operations. + * This initialises */ - if (unlang_init() < 0) return -1; + if (unlang_init_global() < 0) { + fr_perror("%s", config->name); + EXIT_WITH_FAILURE; + } /* * Ensure that we load the correct virtual server for the @@ -1033,7 +1037,7 @@ cleanup: /* * Free any resources used by the unlang interpreter. */ - unlang_free(); + unlang_free_global(); /* * And now nothing should be left anywhere except the diff --git a/src/lib/unlang/base.c b/src/lib/unlang/base.c index 8ee7b23965f..fbcead89e2b 100644 --- a/src/lib/unlang/base.c +++ b/src/lib/unlang/base.c @@ -28,6 +28,8 @@ RCSID("$Id$") #include "unlang_priv.h" +static uint32_t instance_count; + /** Return whether a section has unlang data associated with it * * @param[in] cs to check. @@ -65,18 +67,19 @@ void unlang_register(int type, unlang_op_t *op) memcpy(&unlang_ops[type], op, sizeof(unlang_ops[type])); } -/** Initialize the unlang compiler / interpreter. - * - * For now, just register the magic xlat function. - */ -int unlang_init(void) +int unlang_init_global(void) { + if (instance_count > 0) { + instance_count++; + return 0; + } + /* * Explicitly initialise the xlat tree, and perform dictionary lookups. */ if (xlat_init() < 0) return -1; - unlang_interpret_init(); + unlang_interpret_init_global(); /* Register operations for the default keywords */ unlang_condition_init(); unlang_foreach_init(); @@ -98,6 +101,9 @@ int unlang_init(void) void unlang_free(void) { + if (--instance_count > 0) return; + unlang_foreach_free(); unlang_subrequest_op_free(); + xlat_free(); } diff --git a/src/lib/unlang/base.h b/src/lib/unlang/base.h index 8856bd67efb..d27180fad5d 100644 --- a/src/lib/unlang/base.h +++ b/src/lib/unlang/base.h @@ -33,11 +33,12 @@ extern "C" { #endif -bool unlang_section(CONF_SECTION *cs); +bool unlang_section(CONF_SECTION *cs); -int unlang_init(void); +int unlang_init_global(void); + +int unlang_free_global(void); -void unlang_free(void); #ifdef __cplusplus }