* 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");
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
/*
* 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
/*
* Free any resources used by the unlang interpreter.
*/
- unlang_free();
+ unlang_free_global();
/*
* And now nothing should be left anywhere except the
#include "unlang_priv.h"
+static uint32_t instance_count;
+
/** Return whether a section has unlang data associated with it
*
* @param[in] cs to check.
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();
void unlang_free(void)
{
+ if (--instance_count > 0) return;
+
unlang_foreach_free();
unlang_subrequest_op_free();
+ xlat_free();
}
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
}