Enlightenment CVS committal Author : ningerso Project : e17 Module : libs/ewl
Dir : e17/libs/ewl/src/lib Modified Files: ewl_attach.c ewl_private.h ewl_text.c ewl_theme.c ewl_theme.h ewl_widget.c ewl_widget.h Log Message: Pass const pointers when possible and provide functions that can copy appearances to arbitrary buffers to reduce allocations. Convert existing code to API change. API breakage if using ewl_theme API directly. =================================================================== RCS file: /cvs/e/e17/libs/ewl/src/lib/ewl_attach.c,v retrieving revision 1.38 retrieving revision 1.39 diff -u -3 -r1.38 -r1.39 --- ewl_attach.c 4 Jan 2007 05:09:46 -0000 1.38 +++ ewl_attach.c 10 Jan 2007 11:34:25 -0000 1.39 @@ -593,7 +593,7 @@ { Ewl_Attach *attach; Ewl_Event_Mouse_Move *e; - char *delay_str; + const char *delay_str; double delay = 1.0; DENTER_FUNCTION(DLEVEL_STABLE); @@ -621,7 +621,6 @@ if (delay_str) { delay = atof(delay_str); - FREE(delay_str) } ewl_attach_tooltip->timer = ecore_timer_add(delay, =================================================================== RCS file: /cvs/e/e17/libs/ewl/src/lib/ewl_private.h,v retrieving revision 1.15 retrieving revision 1.16 diff -u -3 -r1.15 -r1.16 --- ewl_private.h 4 Jan 2007 05:09:47 -0000 1.15 +++ ewl_private.h 10 Jan 2007 11:34:25 -0000 1.16 @@ -3,6 +3,7 @@ #define _EWL_PRIVATE_H #include <Edje.h> +#include <Ecore_Str.h> #include <Ecore_File.h> #include <Ecore_Desktop.h> =================================================================== RCS file: /cvs/e/e17/libs/ewl/src/lib/ewl_text.c,v retrieving revision 1.153 retrieving revision 1.154 diff -u -3 -r1.153 -r1.154 --- ewl_text.c 10 Jan 2007 02:38:43 -0000 1.153 +++ ewl_text.c 10 Jan 2007 11:34:25 -0000 1.154 @@ -1224,8 +1224,10 @@ if (source) change->font_source = strdup(source); /* null font will go back to the theme default */ - if (!font) change->font = ewl_theme_data_str_get(EWL_WIDGET(t), "font"); - else change->font = strdup(font); + if (!font) font = ewl_theme_data_str_get(EWL_WIDGET(t), "font"); + + /* Duplicate a local copy of the font */ + if (font) change->font = strdup(font); ewl_text_current_fmt_set(t, EWL_TEXT_CONTEXT_MASK_FONT, change); ewl_text_context_release(change); @@ -1261,8 +1263,10 @@ if (source) tx->font_source = strdup(source); /* null font will go back to the theme default */ - if (!font) tx->font = ewl_theme_data_str_get(EWL_WIDGET(t), "font"); - else tx->font = strdup(font); + if (!font) font = ewl_theme_data_str_get(EWL_WIDGET(t), "font"); + + /* Duplicate a local copy of the font */ + if (font) tx->font = strdup(font); ewl_text_fmt_apply(t, EWL_TEXT_CONTEXT_MASK_FONT, tx, t->cursor_position, char_len); @@ -5289,6 +5293,7 @@ Ewl_Text_Context * ewl_text_context_default_create(Ewl_Text *t) { + const char *font; Ewl_Text_Context *tx = NULL, *tmp; int i; @@ -5305,7 +5310,8 @@ tmp = ewl_text_context_new(); /* handle default values */ - tmp->font = ewl_theme_data_str_get(EWL_WIDGET(t), "font"); + font = ewl_theme_data_str_get(EWL_WIDGET(t), "font"); + if (font) tmp->font = strdup(font); tmp->font_source = NULL; tmp->size = ewl_theme_data_int_get(EWL_WIDGET(t), "font_size"); =================================================================== RCS file: /cvs/e/e17/libs/ewl/src/lib/ewl_theme.c,v retrieving revision 1.33 retrieving revision 1.34 diff -u -3 -r1.33 -r1.34 --- ewl_theme.c 6 Jan 2007 00:03:47 -0000 1.33 +++ ewl_theme.c 10 Jan 2007 11:34:25 -0000 1.34 @@ -213,7 +213,7 @@ char * ewl_theme_image_get(Ewl_Widget *w, char *k) { - char *data; + const char *data; DENTER_FUNCTION(DLEVEL_STABLE); DCHECK_PARAM_PTR_RET("w", w, NULL); @@ -228,7 +228,7 @@ DRETURN_PTR(NULL, DLEVEL_STABLE); } else - data = strdup(ewl_theme_path); + data = ewl_theme_path; } /* @@ -238,10 +238,10 @@ char path[PATH_MAX]; snprintf(path, PATH_MAX, "%s/%s", ewl_theme_path, data); - - FREE(data); data = strdup(path); } + else + data = strdup(data); DRETURN_PTR(data, DLEVEL_STABLE); } @@ -252,7 +252,7 @@ * @return Returns the string associated with @a k on success, NULL on failure. * @brief Retrieve an string value from a widgets theme */ -char * +const char * ewl_theme_data_str_get(Ewl_Widget *w, char *k) { char *ret = NULL; @@ -266,14 +266,29 @@ * Use the widget's appearance string to build a relative theme key. */ if (w) { + int len; char *tmp; - tmp = ewl_widget_appearance_path_get(w); + len = ewl_widget_appearance_path_size_get(w); + tmp = alloca(len); if (tmp) { - snprintf(key, PATH_MAX, "%s/%s", tmp, k); - FREE(tmp); - } else - snprintf(key, PATH_MAX, "%s", k); + int used; + + used = ewl_widget_appearance_path_copy(w, tmp, len); + if (used == (len - 1)) { + used = ecore_strlcpy(key, tmp, PATH_MAX); + if (used < PATH_MAX) { + *(key + used) = '/'; + used++; + } + + ecore_strlcpy(key + used, k, PATH_MAX - used); + } + } + else { + len += strlen(k) + 1; + ecore_strlcpy(key, k, len); + } } else snprintf(key, PATH_MAX, "%s", k); @@ -296,11 +311,8 @@ if (w && w->theme) ret = ecore_hash_get(w->theme, temp); - if (ret) { - if (ret != EWL_THEME_KEY_NOMATCH) - ret = strdup(ret); + if (ret) break; - } temp++; temp = strchr(temp, '/'); @@ -317,23 +329,18 @@ temp = key; while (temp && !ret) { ret = ecore_hash_get(ewl_theme_def_data, temp); - if (ret) { - if (ret != EWL_THEME_KEY_NOMATCH) - ret = strdup(ret); + if (ret) break; - } /* * Resort to looking in the edje. */ - if (!ret) { - ret = edje_file_data_get(ewl_theme_path, temp); - if (ret) { - ecore_hash_set(ewl_theme_def_data, - strdup(temp), - strdup(ret)); - break; - } + ret = edje_file_data_get(ewl_theme_path, temp); + if (ret) { + ecore_hash_set(ewl_theme_def_data, + strdup(temp), + strdup(ret)); + break; } temp++; temp = strchr(temp, '/'); @@ -343,7 +350,7 @@ /* * Mark unmatched keys in the cache. */ - if (!ret) { + if (!ret && ret != EWL_THEME_KEY_NOMATCH) { ecore_hash_set(ewl_theme_def_data, strdup(key), EWL_THEME_KEY_NOMATCH); } @@ -366,17 +373,14 @@ int ewl_theme_data_int_get(Ewl_Widget *w, char *k) { - char *temp; + const char *temp; int ret = 0; DENTER_FUNCTION(DLEVEL_STABLE); DCHECK_PARAM_PTR_RET("k", k, FALSE); temp = ewl_theme_data_str_get(w, k); - if (temp) { - ret = atoi(temp); - FREE(temp); - } + if (temp) ret = atoi(temp); DRETURN_INT(ret, DLEVEL_STABLE); } @@ -520,7 +524,7 @@ static void ewl_theme_font_path_init(void) { - char *font_path; + const char *font_path; char key[PATH_MAX]; DENTER_FUNCTION(DLEVEL_STABLE); @@ -538,7 +542,7 @@ DRETURN(DLEVEL_STABLE); if (*font_path == '/') - ecore_list_append(ewl_theme_font_paths, font_path); + ecore_list_append(ewl_theme_font_paths, strdup(font_path)); else { int len; char *tmp; @@ -553,7 +557,6 @@ snprintf(key, PATH_MAX, "%s", ewl_theme_path); ecore_list_append(ewl_theme_font_paths, strdup(key)); - FREE(font_path); } DLEAVE_FUNCTION(DLEVEL_STABLE); =================================================================== RCS file: /cvs/e/e17/libs/ewl/src/lib/ewl_theme.h,v retrieving revision 1.13 retrieving revision 1.14 diff -u -3 -r1.13 -r1.14 --- ewl_theme.h 4 Jan 2007 05:09:48 -0000 1.13 +++ ewl_theme.h 10 Jan 2007 11:34:25 -0000 1.14 @@ -41,7 +41,7 @@ char *ewl_theme_image_get(Ewl_Widget *w, char *k); -char *ewl_theme_data_str_get(Ewl_Widget *w, char *k); +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); int ewl_theme_data_int_get(Ewl_Widget *w, char *k); =================================================================== RCS file: /cvs/e/e17/libs/ewl/src/lib/ewl_widget.c,v retrieving revision 1.120 retrieving revision 1.121 diff -u -3 -r1.120 -r1.121 --- ewl_widget.c 6 Jan 2007 00:04:34 -0000 1.120 +++ ewl_widget.c 10 Jan 2007 11:34:25 -0000 1.121 @@ -693,37 +693,57 @@ } /** + * @internal * @param w: the widget to retrieve the full appearance key * @param size: pointer to an int indicating the string length * @return Returns a pointer to the full appearance path string on success, NULL on * failure. * @brief Retrieve the appearance path key of the widget */ -static char * -ewl_widget_appearance_path_size_get(Ewl_Widget *w, int *size) +int +ewl_widget_appearance_path_size_get(Ewl_Widget *w) { - char *ret = NULL; + int size; DENTER_FUNCTION(DLEVEL_STABLE); - DCHECK_PARAM_PTR_RET("w", w, NULL); - DCHECK_TYPE_RET("w", w, EWL_WIDGET_TYPE, NULL); + DCHECK_PARAM_PTR_RET("w", w, 0); + DCHECK_TYPE_RET("w", w, EWL_WIDGET_TYPE, 0); /* * Allocate enough for the appearance plus a leading "/" */ - *size += (w->appearance ? strlen(w->appearance) : 0) + 1; - if (w->parent) { - ret = ewl_widget_appearance_path_size_get(w->parent, size); + size = 0; + while (w) { + size += (w->appearance ? strlen(w->appearance) : 0) + 1; + w = w->parent; } - else { - ret = NEW(char, *size + 1); + size++; + + DRETURN_INT(size, DLEVEL_STABLE); +} + +/** + */ +int +ewl_widget_appearance_path_copy(Ewl_Widget *w, char *buf, int size) +{ + int len, used; + + used = 0; + len = (w->appearance ? strlen(w->appearance) : 0); + + if (w->parent) { + used += ewl_widget_appearance_path_copy(w->parent, buf, + size - len); } - strcat(ret, "/"); - if (w->appearance) - strcat(ret, w->appearance); + *(buf + used) = '/'; + used++; + used += ecore_strlcpy(buf + used, + (w->appearance ? w->appearance : ""), + size - used); - DRETURN_PTR(ret, DLEVEL_STABLE); + DRETURN_INT(used, DLEVEL_STABLE); } /** @@ -742,7 +762,9 @@ DCHECK_PARAM_PTR_RET("w", w, NULL); DCHECK_TYPE_RET("w", w, EWL_WIDGET_TYPE, NULL); - ret = ewl_widget_appearance_path_size_get(w, &len); + len = ewl_widget_appearance_path_size_get(w); + ret = NEW(char *, len); + ewl_widget_appearance_path_copy(w, ret, len); DRETURN_PTR(ret, DLEVEL_STABLE); } @@ -876,7 +898,6 @@ ewl_widget_appearance_part_text_apply(Ewl_Widget *w, const char *part, const char *text) { Evas_Coord nw, nh; - char *cleanup = NULL; DENTER_FUNCTION(DLEVEL_STABLE); DCHECK_PARAM_PTR("w", w); @@ -890,15 +911,13 @@ * Fill in the default part to use when the key is NULL. */ if (!part || !*part) - part = cleanup = ewl_theme_data_str_get(w, "textpart"); + part = ewl_theme_data_str_get(w, "textpart"); edje_object_part_text_set(w->theme_object, part, text); edje_object_size_min_calc(w->theme_object, &nw, &nh); ewl_object_preferred_inner_size_set(EWL_OBJECT(w), (int)nw, (int)nh); - IF_FREE(cleanup); - DLEAVE_FUNCTION(DLEVEL_STABLE); } @@ -1078,7 +1097,7 @@ char * ewl_widget_appearance_text_get(Ewl_Widget *w) { - char *part; + const char *part; char *match = NULL; DENTER_FUNCTION(DLEVEL_STABLE); @@ -1086,10 +1105,7 @@ DCHECK_TYPE_RET("w", w, EWL_WIDGET_TYPE, NULL); part = ewl_theme_data_str_get(w, "textpart"); - if (part) { - match = ewl_widget_appearance_part_text_get(w, part); - FREE(part); - } + if (part) match = ewl_widget_appearance_part_text_get(w, part); if (!match) match = ewl_widget_appearance_part_text_get(w, NULL); @@ -1624,7 +1640,7 @@ void ewl_widget_inherit(Ewl_Widget *widget, const char *inherit) { - int len; + size_t len; char *tmp = NULL; const char *tmp2 = NULL; @@ -1636,14 +1652,36 @@ * set the inheritence */ len = strlen(inherit) + 3; + tmp2 = widget->inheritance; - if (tmp2) - len += strlen(tmp2); - else - tmp2 = ""; + if (tmp2) len += strlen(tmp2); + + tmp = alloca(sizeof(char) * len); + if (tmp) { + size_t used = 0; + + /* Copy the existing inherited types */ + if (tmp2) used = ecore_strlcpy(tmp, tmp2, len); + + /* Insert the leading colon */ + if (used < len - 1) { + *(tmp + used) = ':'; + used++; + } - tmp = malloc(sizeof(char) * len); - sprintf(tmp, "%s:%s:", tmp2, inherit); + /* Copy newly inherited type */ + if (used < len) + used += ecore_strlcpy(tmp + used, inherit, len - used); + + /* Insert trailing colon */ + if (used < len - 1) { + *(tmp + used) = ':'; + used++; + } + + /* Terminate the string */ + *(tmp + used) = '\0'; + } /* * Intentionally lose a reference to the ecore string to keep a @@ -1651,8 +1689,6 @@ */ widget->inheritance = ecore_string_instance(tmp); - FREE(tmp); - DLEAVE_FUNCTION(DLEVEL_STABLE); } @@ -2535,7 +2571,7 @@ int i_l = 0, i_r = 0, i_t = 0, i_b = 0; int p_l = 0, p_r = 0, p_t = 0, p_b = 0; char *i = NULL; - char *group = NULL; + const char *group = NULL; Evas_Coord width, height; Ewl_Embed *emb = NULL; @@ -2584,7 +2620,6 @@ } IF_FREE(i); - IF_FREE(group); /* * Reveal is done in this part of the callback to avoid duplicate code =================================================================== RCS file: /cvs/e/e17/libs/ewl/src/lib/ewl_widget.h,v retrieving revision 1.54 retrieving revision 1.55 diff -u -3 -r1.54 -r1.55 --- ewl_widget.h 5 Jan 2007 08:12:48 -0000 1.54 +++ ewl_widget.h 10 Jan 2007 11:34:25 -0000 1.55 @@ -181,6 +181,9 @@ void ewl_widget_appearance_set(Ewl_Widget *w, const char *appearance); char *ewl_widget_appearance_get(Ewl_Widget *w); char *ewl_widget_appearance_path_get(Ewl_Widget *w); +int ewl_widget_appearance_path_size_get(Ewl_Widget *w); +int ewl_widget_appearance_path_copy(Ewl_Widget *w, char *buf, + int size); void ewl_widget_appearance_part_text_set(Ewl_Widget *w, const char *part, const char *text); char *ewl_widget_appearance_part_text_get(Ewl_Widget *w, const char *part); ------------------------------------------------------------------------- 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