diff --git a/legacy/ecore/src/lib/ecore/Ecore_Data.h b/legacy/ecore/src/lib/ecore/Ecore_Data.h index 25350837b0..dd5284c66a 100644 --- a/legacy/ecore/src/lib/ecore/Ecore_Data.h +++ b/legacy/ecore/src/lib/ecore/Ecore_Data.h @@ -419,6 +419,8 @@ extern "C" { int references; }; + int ecore_string_init(void); + void ecore_string_shutdown(void); char *ecore_string_instance(char *string); void ecore_string_release(char *string); diff --git a/legacy/ecore/src/lib/ecore/ecore_strings.c b/legacy/ecore/src/lib/ecore/ecore_strings.c index f1eddffea7..c68f835e3c 100644 --- a/legacy/ecore/src/lib/ecore/ecore_strings.c +++ b/legacy/ecore/src/lib/ecore/ecore_strings.c @@ -1,7 +1,10 @@ #include "ecore_private.h" #include "Ecore_Data.h" +static void ecore_string_free_cb(void *data); + static Ecore_Hash *ecore_strings = NULL; +static int ecore_string_init_count = 0; /** * @defgroup Ecore_String_Group String Instance Functions @@ -10,6 +13,27 @@ static Ecore_Hash *ecore_strings = NULL; * throughout your program. */ +/** + * Initialize the ecore string internal structure. + * @return Zero on failure, non-zero on successful initialization. + */ +int ecore_string_init() +{ + /* + * No strings have been loaded at this point, so create the hash + * table for storing string info for later. + */ + if (!ecore_string_init_count) { + ecore_strings = ecore_hash_new(ecore_str_hash, ecore_str_compare); + if (!ecore_strings) + return 0; + ecore_hash_set_free_value(ecore_strings, ecore_string_free_cb); + } + ecore_string_init_count++; + + return 1; +} + /** * Retrieves an instance of a string for use in an ecore program. * @param string The string to retrieve an instance of. @@ -23,13 +47,6 @@ char *ecore_string_instance(char *string) CHECK_PARAM_POINTER_RETURN("string", string, NULL); - /* - * No strings have been loaded at this point, so create the hash - * table for storing string info for later. - */ - if (!ecore_strings) - ecore_strings = ecore_hash_new(ecore_str_hash, ecore_str_compare); - /* * Check for a previous instance of the string, if not found, create * it. @@ -78,3 +95,24 @@ void ecore_string_release(char *string) FREE(str); } } + +/** + * Shutdown the ecore string internal structures + */ +void ecore_string_shutdown() +{ + --ecore_string_init_count; + if (!ecore_string_init_count) { + ecore_hash_destroy(ecore_strings); + ecore_strings = NULL; + } +} + +static void ecore_string_free_cb(void *data) +{ + Ecore_String *str; + + str = data; + FREE(str->string); + FREE(str); +}