From c352bd7ff6a87ddc1079e81392185f94820a5072 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Tue, 6 Oct 2015 16:02:32 +0100 Subject: [PATCH] Add pool token dup utility. --- src/libutil/mem_pool.c | 16 ++++++++++++++-- src/libutil/mem_pool.h | 13 ++++++++++++- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/libutil/mem_pool.c b/src/libutil/mem_pool.c index 6d8c37223..849e70c03 100644 --- a/src/libutil/mem_pool.c +++ b/src/libutil/mem_pool.c @@ -26,8 +26,6 @@ #include "mem_pool.h" #include "fstring.h" #include "logger.h" -#include "util.h" -#include "rspamd.h" #include "utlist.h" #include "ottery.h" @@ -429,6 +427,20 @@ rspamd_mempool_fstrdup (rspamd_mempool_t * pool, const struct f_str_s *src) return newstr; } +gchar * +rspamd_mempool_ftokdup (rspamd_mempool_t *pool, const rspamd_ftok_t *src) +{ + gchar *newstr; + + if (src == NULL) { + return NULL; + } + + newstr = rspamd_mempool_alloc (pool, src->len + 1); + memcpy (newstr, src->begin, src->len); + newstr[src->len] = '\0'; + return newstr; +} gchar * rspamd_mempool_strdup_shared (rspamd_mempool_t * pool, const gchar *src) diff --git a/src/libutil/mem_pool.h b/src/libutil/mem_pool.h index 3b0e97666..21ddc9d90 100644 --- a/src/libutil/mem_pool.h +++ b/src/libutil/mem_pool.h @@ -179,6 +179,17 @@ gchar * rspamd_mempool_strdup (rspamd_mempool_t * pool, const gchar *src); gchar * rspamd_mempool_fstrdup (rspamd_mempool_t * pool, const struct f_str_s *src); +struct f_str_tok; + +/** + * Make a copy of fixed string token in pool as null terminated string + * @param pool memory pool object + * @param src source string + * @return pointer to newly created string that is copy of src + */ +gchar * rspamd_mempool_ftokdup (rspamd_mempool_t *pool, + const struct f_str_tok *src); + /** * Allocate piece of shared memory * @param pool memory pool object @@ -201,7 +212,7 @@ void rspamd_mempool_lock_shared (rspamd_mempool_t *pool, void *pointer); * @param pool memory pool object * @param pointer pointer of shared memory object that is to be unlocked (the whole page that contains that object is locked) */ -void rspamd_mempool_lock_shared (rspamd_mempool_t *pool, void *pointer); +void rspamd_mempool_unlock_shared (rspamd_mempool_t *pool, void *pointer); /** * Add destructor callback to pool -- 2.39.5