From: Adam Dickmeiss Date: Wed, 9 Sep 2009 12:02:43 +0000 (+0200) Subject: Ref count pp2_charset_t X-Git-Tag: v1.2.0~10 X-Git-Url: http://lists.indexdata.com/cgi-bin?a=commitdiff_plain;h=e8680d3e8a8900797c7bac415e20b127a7a077b9;p=pazpar2-moved-to-github.git Ref count pp2_charset_t --- diff --git a/src/charsets.c b/src/charsets.c index 39ede26..d2c79bd 100644 --- a/src/charsets.c +++ b/src/charsets.c @@ -43,6 +43,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA struct pp2_charset_s { const char *(*token_next_handler)(pp2_relevance_token_t prt); const char *(*get_sort_handler)(pp2_relevance_token_t prt, int skip); + int ref_count; #if YAZ_HAVE_ICU struct icu_chain * icu_chn; UErrorCode icu_sts; @@ -99,6 +100,10 @@ pp2_charset_t pp2_charset_create_xml(xmlNode *xml_node) #endif // YAZ_HAVE_ICU } +void pp2_charset_incref(pp2_charset_t pct) +{ + (pct->ref_count)++; +} pp2_charset_t pp2_charset_create(struct icu_chain * icu_chn) { @@ -106,6 +111,7 @@ pp2_charset_t pp2_charset_create(struct icu_chain * icu_chn) pct->token_next_handler = pp2_relevance_token_a_to_z; pct->get_sort_handler = pp2_get_sort_ascii; + pct->ref_count = 1; #if YAZ_HAVE_ICU pct->icu_chn = 0; if (icu_chn) @@ -121,7 +127,13 @@ pp2_charset_t pp2_charset_create(struct icu_chain * icu_chn) void pp2_charset_destroy(pp2_charset_t pct) { - xfree(pct); + if (pct) + { + assert(pct->ref_count >= 1); + --(pct->ref_count); + if (pct->ref_count == 0) + xfree(pct); + } } pp2_relevance_token_t pp2_relevance_tokenize(pp2_charset_t pct, diff --git a/src/charsets.h b/src/charsets.h index ef7e333..cb41404 100644 --- a/src/charsets.h +++ b/src/charsets.h @@ -35,6 +35,7 @@ typedef struct pp2_relevance_token_s *pp2_relevance_token_t; pp2_charset_t pp2_charset_create_xml(xmlNode *xml_node); pp2_charset_t pp2_charset_create(struct icu_chain * icu_chn); void pp2_charset_destroy(pp2_charset_t pct); +void pp2_charset_incref(pp2_charset_t pct); pp2_relevance_token_t pp2_relevance_tokenize(pp2_charset_t pct, const char *buf);