From: Enlightenment S. <no-...@en...> - 2009-04-08 18:25:11
|
Log: eina_stringshare_replace() gets in! I was replicating this code in many places, it should go into eina itself. It's the right way to change strings that you don't know are stringshared before, since it will first add a reference and then remove, making it impossible to have references to go 0 and string being released before adding new references, fixing the following possible problem: x = eina_stringshare_add("x"); replace(x, x); then: incorrect_replace(const char **b, const char *a) { eina_stringshare_del(*b); /* reference gets to 0 */ eina_stringshare_add(a); /* BUG!!! */ *b = a; } Author: barbieri Date: 2009-04-08 11:25:02 -0700 (Wed, 08 Apr 2009) New Revision: 39903 Added: trunk/eina/src/include/eina_inline_stringshare.x Modified: trunk/PROTO/eve/src/bin/eve_navigator.c trunk/PROTO/eve/src/bin/eve_scrolled_webview.c trunk/e/src/bin/e_fm.c trunk/e/src/bin/e_fm_op_registry.c trunk/e_dbus/src/lib/connman/e_connman_element.c trunk/eina/src/include/Makefile.am trunk/eina/src/include/eina_stringshare.h Modified: trunk/PROTO/eve/src/bin/eve_navigator.c =================================================================== --- trunk/PROTO/eve/src/bin/eve_navigator.c 2009-04-08 18:02:27 UTC (rev 39902) +++ trunk/PROTO/eve/src/bin/eve_navigator.c 2009-04-08 18:25:02 UTC (rev 39903) @@ -58,17 +58,6 @@ static const char EDJE_PART_CONTENT[] = "eve.swallow.content"; static const char EDJE_PART_LOCATION[] = "eve.text.location"; -static bool -_eina_stringshare_replace(const char **p, const char *new) -{ - new = eina_stringshare_add(new); - eina_stringshare_del(*p); - if (*p == new) - return 0; - *p = new; - return 1; -} - static void _eve_navigator_load_url(Eve_Navigator_Data *priv, const char *url) { @@ -86,7 +75,7 @@ url = buf; } - if (!_eina_stringshare_replace(&priv->url, url)) + if (!eina_stringshare_replace(&priv->url, url)) return; ewk_webview_object_load_url(priv->webview, priv->url); @@ -154,7 +143,7 @@ { Eve_Navigator_Data *priv = data; EWebKit_Event_Title_Changed *ev = event_info; - if (!_eina_stringshare_replace(&priv->title, ev->title)) + if (!eina_stringshare_replace(&priv->title, ev->title)) return; edje_object_part_text_set(priv->edje, "eve.text.title", priv->title); } @@ -164,7 +153,7 @@ { Eve_Navigator_Data *priv = data; EWebKit_Event_Url_Changed *ev = event_info; - if (!_eina_stringshare_replace(&priv->url, ev->url)) + if (!eina_stringshare_replace(&priv->url, ev->url)) return; edje_object_part_text_set(priv->edje, "eve.text.location", priv->url); } @@ -403,7 +392,7 @@ EVE_NAVIGATOR_DATA_GET_OR_RETURN_VAL(o, priv, 0); if (!eve_scrolled_webview_theme_file_set(priv->scrolled, file)) return 0; - _eina_stringshare_replace(&priv->file, file); + eina_stringshare_replace(&priv->file, file); return _eve_navigator_edje_reset(priv); } @@ -418,7 +407,7 @@ eve_navigator_theme_group_set(Evas_Object *o, const char *group) { EVE_NAVIGATOR_DATA_GET_OR_RETURN_VAL(o, priv, 0); - _eina_stringshare_replace(&priv->group, group); + eina_stringshare_replace(&priv->group, group); return _eve_navigator_edje_reset(priv); } Modified: trunk/PROTO/eve/src/bin/eve_scrolled_webview.c =================================================================== --- trunk/PROTO/eve/src/bin/eve_scrolled_webview.c 2009-04-08 18:02:27 UTC (rev 39902) +++ trunk/PROTO/eve/src/bin/eve_scrolled_webview.c 2009-04-08 18:25:02 UTC (rev 39903) @@ -64,17 +64,6 @@ static Evas_Smart_Class _parent_sc = {NULL}; static const char EDJE_PART_CONTENT[] = "eve.swallow.content"; -static bool -_eina_stringshare_replace(const char **p, const char *new) -{ - new = eina_stringshare_add(new); - eina_stringshare_del(*p); - if (*p == new) - return 0; - *p = new; - return 1; -} - static void _eve_scrolled_webview_scroll_by(Eve_Scrolled_Webview_Data *priv, int dx, int dy) { @@ -394,7 +383,7 @@ eve_scrolled_webview_theme_file_set(Evas_Object *o, const char *file) { EVE_SCROLLED_WEBVIEW_DATA_GET_OR_RETURN_VAL(o, priv, 0); - _eina_stringshare_replace(&priv->file, file); + eina_stringshare_replace(&priv->file, file); return _eve_scrolled_webview_edje_reset(priv); } @@ -409,7 +398,7 @@ eve_scrolled_webview_theme_group_set(Evas_Object *o, const char *group) { EVE_SCROLLED_WEBVIEW_DATA_GET_OR_RETURN_VAL(o, priv, 0); - _eina_stringshare_replace(&priv->group, group); + eina_stringshare_replace(&priv->group, group); return _eve_scrolled_webview_edje_reset(priv); } Modified: trunk/e/src/bin/e_fm.c =================================================================== --- trunk/e/src/bin/e_fm.c 2009-04-08 18:02:27 UTC (rev 39902) +++ trunk/e/src/bin/e_fm.c 2009-04-08 18:25:02 UTC (rev 39903) @@ -427,16 +427,6 @@ #include "e_fm_shared.h" #undef E_FM_SHARED_CODEC -static inline void -_eina_stringshare_replace(const char **p, const char *str) -{ - str = eina_stringshare_add(str); - eina_stringshare_del(*p); - if (*p == str) - return; - *p = str; -} - static inline Eina_Bool _e_fm2_icon_realpath(const E_Fm2_Icon *ic, char *buf, int buflen) { @@ -730,12 +720,12 @@ EAPI int e_fm2_shutdown(void) { - _eina_stringshare_replace(&_e_fm2_icon_desktop_str, NULL); - _eina_stringshare_replace(&_e_fm2_icon_thumb_str, NULL); - _eina_stringshare_replace(&_e_fm2_mime_inode_directory, NULL); - _eina_stringshare_replace(&_e_fm2_mime_app_desktop, NULL); - _eina_stringshare_replace(&_e_fm2_mime_app_edje, NULL); - _eina_stringshare_replace(&_e_fm2_mime_text_uri_list, NULL); + eina_stringshare_replace(&_e_fm2_icon_desktop_str, NULL); + eina_stringshare_replace(&_e_fm2_icon_thumb_str, NULL); + eina_stringshare_replace(&_e_fm2_mime_inode_directory, NULL); + eina_stringshare_replace(&_e_fm2_mime_app_desktop, NULL); + eina_stringshare_replace(&_e_fm2_mime_app_edje, NULL); + eina_stringshare_replace(&_e_fm2_mime_text_uri_list, NULL); /// DBG if (_e_fm2_op_registry_entry_add_handler) @@ -890,8 +880,8 @@ if (sd->realpath) _e_fm2_client_monitor_del(sd->id, sd->realpath); sd->listing = 0; - _eina_stringshare_replace(&sd->dev, dev); - _eina_stringshare_replace(&sd->path, path); + eina_stringshare_replace(&sd->dev, dev); + eina_stringshare_replace(&sd->path, path); eina_stringshare_del(sd->realpath); sd->realpath = realpath; _e_fm2_queue_free(obj); @@ -1001,7 +991,7 @@ if (!sd) return; // safety if (!evas_object_type_get(obj)) return; // safety if (strcmp(evas_object_type_get(obj), "e_fm")) return; // safety - _eina_stringshare_replace(&sd->custom_theme, path); + eina_stringshare_replace(&sd->custom_theme, path); _e_fm2_theme_edje_object_set(sd, sd->drop, "base/theme/fileman", "list/drop_between"); _e_fm2_theme_edje_object_set(sd, sd->drop_in, "base/theme/fileman", @@ -1021,7 +1011,7 @@ if (!sd) return; // safety if (!evas_object_type_get(obj)) return; // safety if (strcmp(evas_object_type_get(obj), "e_fm")) return; // safety - _eina_stringshare_replace(&sd->custom_theme_content, content); + eina_stringshare_replace(&sd->custom_theme_content, content); _e_fm2_theme_edje_object_set(sd, sd->drop, "base/theme/fileman", "list/drop_between"); _e_fm2_theme_edje_object_set(sd, sd->drop_in, "base/theme/fileman", @@ -1526,7 +1516,7 @@ { if (cf->icon.valid) { - _eina_stringshare_replace(&ic->info.icon, cf->icon.icon); + eina_stringshare_replace(&ic->info.icon, cf->icon.icon); ic->info.icon_type = cf->icon.type; } } @@ -4328,7 +4318,7 @@ { if (cf->icon.icon) { - _eina_stringshare_replace(&ic->info.icon, cf->icon.icon); + eina_stringshare_replace(&ic->info.icon, cf->icon.icon); } ic->info.icon_type = cf->icon.type; } Modified: trunk/e/src/bin/e_fm_op_registry.c =================================================================== --- trunk/e/src/bin/e_fm_op_registry.c 2009-04-08 18:02:27 UTC (rev 39902) +++ trunk/e/src/bin/e_fm_op_registry.c 2009-04-08 18:25:02 UTC (rev 39903) @@ -244,14 +244,8 @@ { if (!entry) return; - src = eina_stringshare_add(src); - dst = eina_stringshare_add(dst); - - eina_stringshare_del(entry->src); - eina_stringshare_del(entry->dst); - - entry->src = src; - entry->dst = dst; + eina_stringshare_replace(&entry->src, src); + eina_stringshare_replace(&entry->dst, dst); } /** Modified: trunk/e_dbus/src/lib/connman/e_connman_element.c =================================================================== --- trunk/e_dbus/src/lib/connman/e_connman_element.c 2009-04-08 18:02:27 UTC (rev 39902) +++ trunk/e_dbus/src/lib/connman/e_connman_element.c 2009-04-08 18:25:02 UTC (rev 39903) @@ -662,17 +662,6 @@ return element; } -static inline int -_stringshare_replace(const char **str, const char *new) -{ - new = eina_stringshare_add(new); - eina_stringshare_del(*str); - if (*str == new) - return 0; - *str = new; - return 1; -} - static void e_connman_element_extra_properties_free(E_Connman_Element *element) { Modified: trunk/eina/src/include/Makefile.am =================================================================== --- trunk/eina/src/include/Makefile.am 2009-04-08 18:02:27 UTC (rev 39902) +++ trunk/eina/src/include/Makefile.am 2009-04-08 18:25:02 UTC (rev 39903) @@ -19,6 +19,7 @@ eina_inline_array.x \ eina_magic.h \ eina_stringshare.h \ +eina_inline_stringshare.x \ eina_inline_list.x \ eina_accessor.h \ eina_convert.h \ Added: trunk/eina/src/include/eina_inline_stringshare.x Modified: trunk/eina/src/include/eina_stringshare.h =================================================================== --- trunk/eina/src/include/eina_stringshare.h 2009-04-08 18:02:27 UTC (rev 39902) +++ trunk/eina/src/include/eina_stringshare.h 2009-04-08 18:25:02 UTC (rev 39903) @@ -72,7 +72,10 @@ EAPI void eina_stringshare_del(const char *str); EAPI int eina_stringshare_strlen(const char *str) EINA_CONST EINA_WARN_UNUSED_RESULT; EAPI void eina_stringshare_dump(void); - + + +#include "eina_inline_stringshare.x" + /** * @} */ |