Enlightenment CVS committal Author : ningerso Project : e17 Module : libs/ewl
Dir : e17/libs/ewl/src/lib Modified Files: ewl_theme.c ewl_theme.h Log Message: Make theme key lookup return values consistent to prevent memory leaks and improve cache performance. Add theme reset to clear cached values on specified widgets. Update theme test to cache API change. =================================================================== RCS file: /cvs/e/e17/libs/ewl/src/lib/ewl_theme.c,v retrieving revision 1.38 retrieving revision 1.39 diff -u -3 -r1.38 -r1.39 --- ewl_theme.c 6 Feb 2007 13:42:17 -0000 1.38 +++ ewl_theme.c 28 Feb 2007 12:24:46 -0000 1.39 @@ -253,27 +253,19 @@ DCHECK_PARAM_PTR("cache", cache); DCHECK_PARAM_PTR("k", k); - if (v != EWL_THEME_KEY_NOMATCH) { - if (v) { - ecore_hash_set(cache, (void *)ecore_string_instance(k), - (void *)ecore_string_instance(v)); - } - /* - * Mark unmatched keys in the cache. - */ - else { - ecore_hash_set(cache, (void *)ecore_string_instance(k), - EWL_THEME_KEY_NOMATCH); - } - } + /* + * The v value should already be a string instance at this point so we + * can set the value directly whether its a match or no match. + */ + ecore_hash_set(cache, (void *)ecore_string_instance(k), (void *)v); DLEAVE_FUNCTION(DLEVEL_STABLE); } -static char * +static const char * ewl_theme_lookup_key(Ecore_Hash *cache, const char *path, const char *k) { - char *ret; + const char *ret; DENTER_FUNCTION(DLEVEL_STABLE); DCHECK_PARAM_PTR_RET("cache", cache, NULL); @@ -281,18 +273,50 @@ ret = ecore_hash_get(cache, k); if (!ret) { + char *tmp = NULL; /* * Resort to looking in the edje. */ if (path) - ret = edje_file_data_get(path, k); + tmp = edje_file_data_get(path, k); + + /* + * Get a string instance for the value so we can treat the + * return type consistently and not leak memory. + */ + if (tmp) { + ret = ecore_string_instance(tmp); + FREE(tmp); + } } + else + ret = ecore_string_instance(ret); DRETURN_PTR(ret, DLEVEL_STABLE); } /** + * @param w: the widget to reset theme settings + * @return Returns no value. + * @brief Reset the theme settings for the widget @a w. + */ +void +ewl_theme_data_reset(Ewl_Widget *w) +{ + DENTER_FUNCTION(DLEVEL_STABLE); + DCHECK_PARAM_PTR("w", w); + DCHECK_TYPE("w", w, EWL_WIDGET_TYPE); + + if (w->theme) { + ecore_hash_destroy(w->theme); + w->theme = NULL; + } + + DLEAVE_FUNCTION(DLEVEL_STABLE); +} + +/** * @param w: the widget to search * @param k: the key to search for * @return Returns the string associated with @a k on success, NULL on failure. @@ -301,7 +325,8 @@ const char * ewl_theme_data_str_get(Ewl_Widget *w, char *k) { - char *ret = NULL; + Ecore_Hash *cache = NULL; + const char *ret = NULL; char *temp = NULL; char key[PATH_MAX]; @@ -357,8 +382,10 @@ if (w && w->theme) ret = ewl_theme_lookup_key(w->theme, w->theme_path, temp); - if (ret) + if (ret) { + cache = w->theme; break; + } temp++; temp = strchr(temp, '/'); @@ -376,18 +403,24 @@ while (temp && !ret) { ret = ewl_theme_lookup_key(ewl_theme_def_data, ewl_theme_path, temp); - if (ret) + if (ret) { + cache = ewl_theme_def_data; break; + } temp++; temp = strchr(temp, '/'); } - /* - * Mark unmatched keys in the cache. - */ - ewl_theme_lookup_cache(ewl_theme_def_data, key, ret); } + + if (!cache) + cache = ewl_theme_def_data; + + /* + * Mark all keys matched and unmatched in the cache. + */ + ewl_theme_lookup_cache(cache, key, ret); /* * Fixup unmatched keys in the cache. =================================================================== RCS file: /cvs/e/e17/libs/ewl/src/lib/ewl_theme.h,v retrieving revision 1.14 retrieving revision 1.15 diff -u -3 -r1.14 -r1.15 --- ewl_theme.h 10 Jan 2007 11:34:25 -0000 1.14 +++ ewl_theme.h 28 Feb 2007 12:24:46 -0000 1.15 @@ -41,6 +41,8 @@ char *ewl_theme_image_get(Ewl_Widget *w, char *k); +void ewl_theme_data_reset(Ewl_Widget *w); + const char *ewl_theme_data_str_get(Ewl_Widget *w, char *k); void ewl_theme_data_str_set(Ewl_Widget *w, char *k, char *v); ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys-and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV _______________________________________________ enlightenment-cvs mailing list enlightenment-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs