#endif
#endif
-#ifdef __cplusplus
- #define RSPAMD_CONSTRUCTOR(f) \
- static void f(void); \
- struct f##_t_ { f##_t_(void) { f(); } }; static f##_t_ f##_; \
- static void f(void)
-#elif defined(_MSC_VER)
- #pragma section(".CRT$XCU",read)
- #define INITIALIZER2_(f,p) \
- static void f(void); \
- __declspec(allocate(".CRT$XCU")) void (*f##_)(void) = f; \
- __pragma(comment(linker,"/include:" p #f "_")) \
- static void f(void)
- #ifdef _WIN64
- #define RSPAMD_CONSTRUCTOR(f) INITIALIZER2_(f,"")
- #else
- #define RSPAMD_CONSTRUCTOR(f) INITIALIZER2_(f,"_")
- #endif
+#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)
+ #define RSPAMD_CONSTRUCTOR(f) \
+ static void f(void) __attribute__((constructor)); \
+ static void f(void)
+ #define RSPAMD_DESTRUCTOR(f) \
+ static void f(void) __attribute__((destructor)); \
+ static void f(void)
#else
- #define RSPAMD_CONSTRUCTOR(f) \
- static void f(void) __attribute__((constructor)); \
- static void f(void)
+ /* In fact, everything else is not supported ¯\_(ツ)_/¯ */
+ #error incompatible compiler found, need gcc > 2.7 or clang
#endif
#endif
}
if (ctx->config.client_key_rotate_time > 0) {
- /* Event is removed on base event loop termination */
- /* event_del (&ctx->client_rotate_ev); */
+ ev_timer_stop (ctx->event_loop, &ctx->client_rotate_ev);
if (ctx->client_kp) {
rspamd_keypair_unref (ctx->client_kp);
return entry;
}
+RSPAMD_CONSTRUCTOR (rspamd_mempool_entries_ctor)
+{
+ mempool_entries = kh_init (mempool_entry);
+}
+
+RSPAMD_DESTRUCTOR (rspamd_mempool_entries_dtor)
+{
+ struct rspamd_mempool_entry_point *elt;
+
+ kh_foreach_value (mempool_entries, elt, {
+ g_free (elt);
+ });
+
+ kh_destroy (mempool_entry, mempool_entries);
+}
+
static inline struct rspamd_mempool_entry_point *
rspamd_mempool_get_entry (const gchar *loc)
{
khiter_t k;
struct rspamd_mempool_entry_point *elt;
- if (mempool_entries == NULL) {
- mempool_entries = kh_init (mempool_entry);
- }
- else {
- k = kh_get (mempool_entry, mempool_entries, loc);
+ k = kh_get (mempool_entry, mempool_entries, loc);
- if (k != kh_end (mempool_entries)) {
- elt = kh_value (mempool_entries, k);
+ if (k != kh_end (mempool_entries)) {
+ elt = kh_value (mempool_entries, k);
- return elt;
- }
+ return elt;
}
return rspamd_mempool_entry_new (loc);
res = rspamd_regexp_new (pattern, flags, err);
if (res) {
- REF_RETAIN (res);
+ /* REF_RETAIN (res); */
g_hash_table_insert (cache->tbl, res->id, res);
}
}
}
+RSPAMD_CONSTRUCTOR (rspamd_re_static_pool_ctor)
+{
+ global_re_cache = rspamd_regexp_cache_new ();
+#ifdef WITH_PCRE2
+ pcre2_ctx = pcre2_compile_context_create (NULL);
+ pcre2_set_newline (pcre2_ctx, PCRE_FLAG(NEWLINE_ANY));
+#endif
+}
+
+RSPAMD_DESTRUCTOR (rspamd_re_static_pool_dtor)
+{
+ rspamd_regexp_cache_destroy (global_re_cache);
+#ifdef WITH_PCRE2
+ pcre2_compile_context_free (pcre2_ctx);
+#endif
+}
+
+
void
rspamd_regexp_library_init (struct rspamd_config *cfg)
{
can_jit = FALSE;
check_jit = FALSE;
}
+ else if (!can_jit) {
+ check_jit = TRUE;
+ }
}
- if (global_re_cache == NULL) {
- global_re_cache = rspamd_regexp_cache_new ();
+ if (check_jit) {
#ifdef HAVE_PCRE_JIT
gint jit, rc;
gchar *str;
- if (check_jit) {
-#ifdef WITH_PCRE2
- pcre2_ctx = pcre2_compile_context_create (NULL);
- pcre2_set_newline (pcre2_ctx, PCRE_FLAG(NEWLINE_ANY));
-#endif
#ifndef WITH_PCRE2
rc = pcre_config (PCRE_CONFIG_JIT, &jit);
#else
" are impossible");
can_jit = FALSE;
}
- }
#else
msg_info ("pcre is too old and has no JIT support, so many optimizations"
- " are impossible");
+ " are impossible");
can_jit = FALSE;
#endif
- }
-}
-
-void
-rspamd_regexp_library_finalize (void)
-{
- if (global_re_cache != NULL) {
- rspamd_regexp_cache_destroy (global_re_cache);
-#ifdef WITH_PCRE2
- pcre2_compile_context_free (pcre2_ctx);
-#endif
+ check_jit = FALSE;
}
}
*/
void rspamd_regexp_library_init (struct rspamd_config *cfg);
-/**
- * Cleanup internal library structures
- */
-void rspamd_regexp_library_finalize (void);
-
/**
* Create regexp from glob
* @param gl
KHASH_INIT (lua_class_set, const gchar *, bool, 0, rspamd_str_hash, rspamd_str_equal);
khash_t (lua_class_set) *lua_classes = NULL;
+RSPAMD_CONSTRUCTOR (lua_classes_ctor)
+{
+ lua_classes = kh_init (lua_class_set);
+}
+
+RSPAMD_DESTRUCTOR (lua_classes_dtor)
+{
+ kh_destroy (lua_class_set, lua_classes);
+}
+
/* Util functions */
/**
* Create new class and store metatable on top of the stack (must be popped if not needed)
khiter_t k;
gint r, nmethods = 0;
- if (lua_classes == NULL) {
- lua_classes = kh_init (lua_class_set);
- }
-
k = kh_put (lua_class_set, lua_classes, classname, &r);
class_ptr = RSPAMD_LIGHTUSERDATA_MASK (kh_key (lua_classes, k));
rspamd_lua_new_class (L, "rspamd{regexp}", regexplib_m);
lua_pop (L, 1);
rspamd_lua_add_preload (L, "rspamd_regexp", lua_load_regexp);
+}
- if (regexp_static_pool == NULL) {
- regexp_static_pool = rspamd_mempool_new (rspamd_mempool_suggest_size (),
- "regexp_lua_pool");
- }
+RSPAMD_CONSTRUCTOR (lua_re_static_pool_ctor) {
+ regexp_static_pool = rspamd_mempool_new (rspamd_mempool_suggest_size (),
+ "regexp_lua_pool");
}
+
+RSPAMD_DESTRUCTOR (lua_re_static_pool_dtor) {
+ rspamd_mempool_delete (regexp_static_pool);
+}
\ No newline at end of file
g_test_add_func ("/rspamd/aio", rspamd_async_test_func);
#endif
g_test_run ();
- rspamd_regexp_library_finalize ();
return 0;
}