X-Git-Url: http://jsfdemo.indexdata.com/?a=blobdiff_plain;f=src%2Fcharsets.c;h=d2c79bd0adb8de3c1fbafaf095794ad73f5e0948;hb=5b4ea0cf66dd82c871ed7d69a5801d78789087b2;hp=0d63c1187b1553c9b94a9c675b6fc785452e9be0;hpb=57b393132b1e795da47e50c13260a1346c8029e9;p=pazpar2-moved-to-github.git diff --git a/src/charsets.c b/src/charsets.c index 0d63c11..d2c79bd 100644 --- a/src/charsets.c +++ b/src/charsets.c @@ -1,5 +1,5 @@ /* This file is part of Pazpar2. - Copyright (C) 2006-2008 Index Data + Copyright (C) 2006-2009 Index Data Pazpar2 is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free @@ -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, @@ -248,7 +260,9 @@ static const char *pp2_get_sort_icu(pp2_relevance_token_t prt, /* * Local variables: * c-basic-offset: 4 + * c-file-style: "Stroustrup" * indent-tabs-mode: nil * End: * vim: shiftwidth=4 tabstop=8 expandtab */ +