yakov pushed a commit to branch master.

http://git.enlightenment.org/tools/erigo.git/commit/?id=a92e6c355f16d28586caea7e88ab57f9c08e4a61

commit a92e6c355f16d28586caea7e88ab57f9c08e4a61
Author: Yakov Goldberg <[email protected]>
Date:   Thu Mar 19 16:05:49 2015 +0200

    Fix gui_value_string* API. Put strdup() inside, because free() is inside
---
 src/bin/egui_gui/cbview.c |  4 ++--
 src/bin/egui_gui/editor.c | 22 +++++++++++-----------
 src/lib/database.c        |  4 ++--
 src/lib/ffi_abstraction.c |  2 +-
 src/lib/gui_parser.c      | 12 ++++++------
 src/lib/gui_widget.c      | 14 ++++++++------
 6 files changed, 30 insertions(+), 28 deletions(-)

diff --git a/src/bin/egui_gui/cbview.c b/src/bin/egui_gui/cbview.c
index 50a92d8..e5816f6 100644
--- a/src/bin/egui_gui/cbview.c
+++ b/src/bin/egui_gui/cbview.c
@@ -324,7 +324,7 @@ _action_prop_update(void *data, Eo *obj, void *event_info)
                }
              else
                {
-                  gui_value_string_set(val, strdup(entry_data));
+                  gui_value_string_set(val, entry_data);
                }
           }
         else if (type == GUI_TYPE_SINT)
@@ -353,7 +353,7 @@ _action_prop_update(void *data, Eo *obj, void *event_info)
         if (type == GUI_TYPE_ENUM)
           {
              gui_value_string_free(val);
-             gui_value_enum_set(val, strdup(new_enum_value));
+             gui_value_enum_set(val, new_enum_value);
           }
         else if (type == GUI_TYPE_OBJECT)
           {
diff --git a/src/bin/egui_gui/editor.c b/src/bin/egui_gui/editor.c
index 2b8bc93..61eb42e 100644
--- a/src/bin/egui_gui/editor.c
+++ b/src/bin/egui_gui/editor.c
@@ -1292,7 +1292,7 @@ _widget_prop_add(Gui_Session *session, const Gui_Widget 
*wdg, const Gui_Widget_P
                                       Op_Desc *op_desc = 
db_mro_op_desc_get(wdg_class_name_get(wdg), DB_DEF_CONTAINER_CLASS, 
CONTENT_SET);
                                       Gui_Widget_Property *new_prop = 
prop_create_for_op(op_desc);
                                       Gui_Value *val = 
prop_value_nth_get(new_prop, 0);
-                                      gui_value_string_set(val, 
strdup(part_name));
+                                      gui_value_string_set(val, part_name);
                                       val = prop_value_nth_get(new_prop, 1);
                                       gui_value_name_id_set(val, 
GUI_TYPE_OBJECT, DUMMY_ID);
                                       Object_Container_Item *ci = 
obj_container_item_new(new_prop, DUMMY_ID);
@@ -3136,13 +3136,13 @@ _editor_factory_wdg_create(const char *class_name, 
const Gui_Widget *focused_wdg
         val = prop_value_nth_get(prop, 0);
         gui_value_string_set(val, NULL);
         val = prop_value_nth_get(prop, 1);
-        gui_value_string_set(val, strdup("ELM_WIN_BASIC"));
+        gui_value_string_set(val, "ELM_WIN_BASIC");
         wdg_prop_add(wdg, prop);
 
         op = db_mro_op_desc_get(class_name, DB_DEF_WIN_CLASS, TITLE_SET);
         prop = prop_create_for_op(op);
         val = prop_value_nth_get(prop, 0);
-        gui_value_string_set(val, strdup(eid_name_get(wdg_eid_get(wdg))));
+        gui_value_string_set(val, eid_name_get(wdg_eid_get(wdg)));
         wdg_prop_add(wdg, prop);
      }
 
@@ -3285,7 +3285,7 @@ _prop_update_from_propview(void *data EINA_UNUSED, Eo 
*obj, const Eo_Event_Descr
              else
                {
                   gui_value_string_free(val);
-                  gui_value_string_set(val, strdup(entry_data));
+                  gui_value_string_set(val, entry_data);
                }
           }
         else if (type == GUI_TYPE_SINT)
@@ -3324,7 +3324,7 @@ _prop_update_from_propview(void *data EINA_UNUSED, Eo 
*obj, const Eo_Event_Descr
         if (type == GUI_TYPE_ENUM)
           {
              gui_value_string_free(val);
-             gui_value_enum_set(val, strdup(new_enum_value));
+             gui_value_enum_set(val, new_enum_value);
           }
         /* FIXME: there is problem with content_set; because prev content must 
be unset; or need to redraw from the beginning*/
         else if (type == GUI_TYPE_OBJECT)
@@ -3582,7 +3582,7 @@ _field_update_from_itemview(void *data EINA_UNUSED, Eo 
*obj, const Eo_Event_Desc
         if (type == GUI_TYPE_STRING)
           {
              gui_value_string_free(val);
-             gui_value_string_set(val, strdup(entry_data));
+             gui_value_string_set(val, entry_data);
 
              /* Reloading all window. */
              _wdg_parent_win_reload(wdg);
@@ -3726,19 +3726,19 @@ _itemview_item_do_(unsigned int type)
              gui_value_name_id_set(val, GUI_TYPE_OBJECT_ITEM, new_parent_eid);
 
              val = prop_value_nth_get(prop, 2);
-             gui_value_string_set(val, strdup(str));
+             gui_value_string_set(val, str);
           }
         else if (!strcmp(wdg_class_name_get(wdg), DB_DEF_DISKSELECTOR_CLASS) ||
                  !strcmp(wdg_class_name_get(wdg), DB_DEF_CTXPOPUP_CLASS) ||
                  !strcmp(wdg_class_name_get(wdg), DB_DEF_NAVIFRAME_CLASS))
           {
              val = prop_value_nth_get(prop, 0);
-             gui_value_string_set(val, strdup(str));
+             gui_value_string_set(val, str);
           }
         else if (!strcmp(wdg_class_name_get(wdg), DB_DEF_TOOLBAR_CLASS))
           {
              val = prop_value_nth_get(prop, 1);
-             gui_value_string_set(val, strdup(str));
+             gui_value_string_set(val, str);
           }
      }
    else if (type == ITEM_DELETE)
@@ -4035,7 +4035,7 @@ _content_change_from_propview(void *data EINA_UNUSED, Eo 
*obj, const Eo_Event_De
                   else
                     {
                        gui_value_string_free(val);
-                       gui_value_string_set(val, strdup(entry_data));
+                       gui_value_string_set(val, entry_data);
                     }
                   Eid *eid = obj_container_item_eid_get(ci);
                   wdg_obj_container_item_remove(wdg, ci);
@@ -4064,7 +4064,7 @@ _content_change_from_propview(void *data EINA_UNUSED, Eo 
*obj, const Eo_Event_De
         if (type == GUI_TYPE_ENUM)
           {
              gui_value_string_free(val);
-             gui_value_enum_set(val, strdup(new_value));
+             gui_value_enum_set(val, new_value);
           }
         if (type == GUI_TYPE_OBJECT)
           {
diff --git a/src/lib/database.c b/src/lib/database.c
index acfb599..2499ade 100644
--- a/src/lib/database.c
+++ b/src/lib/database.c
@@ -550,11 +550,11 @@ _json_arr_to_def_prop_values(Eina_Json_Value *jv, 
Gui_Widget_Property *prop)
                    const char *str = eina_json_string_get(v);
                    if (g_type == GUI_TYPE_STRING)
                      {
-                        gui_value_string_set(g_val, strdup(str));
+                        gui_value_string_set(g_val, str);
                      }
                    else if (g_type == GUI_TYPE_ENUM)
                      {
-                        gui_value_enum_set(g_val, strdup(str));
+                        gui_value_enum_set(g_val, str);
                      }
                    break;
                 }
diff --git a/src/lib/ffi_abstraction.c b/src/lib/ffi_abstraction.c
index 56b4374..66f8392 100644
--- a/src/lib/ffi_abstraction.c
+++ b/src/lib/ffi_abstraction.c
@@ -249,7 +249,7 @@ _ffi_eo_do_get(const Gui_Session *session, const Gui_Widget 
*wdg, const Gui_Widg
         if (gv_type == GUI_TYPE_ENUM)
           {
              const char *enum_str_value = db_op_desc_nth_par_enum_get(op_desc, 
i, INT_GET(gui_value));
-             gui_value_enum_set(gui_value, strdup(enum_str_value));
+             gui_value_enum_set(gui_value, enum_str_value);
           }
         i++;
      }
diff --git a/src/lib/gui_parser.c b/src/lib/gui_parser.c
index 6ad4066..51fc7e1 100644
--- a/src/lib/gui_parser.c
+++ b/src/lib/gui_parser.c
@@ -198,11 +198,11 @@ _json_arr_to_prop_values(const Gui_Context *gui_ctx, 
Eina_Json_Value *jv, Gui_Wi
                    const char *str = eina_json_string_get(v);
                    if (g_type == GUI_TYPE_STRING)
                      {
-                        gui_value_string_set(g_val, strdup(str));
+                        gui_value_string_set(g_val, str);
                      }
                    else if (g_type == GUI_TYPE_ENUM)
                      {
-                        gui_value_enum_set(g_val, strdup(str));
+                        gui_value_enum_set(g_val, str);
                      }
                    else if ((g_type == GUI_TYPE_FILE) ||
                             (g_type == GUI_TYPE_CB) ||
@@ -323,7 +323,7 @@ _read_items_section(const Gui_Context *gui_ctx, Gui_Widget 
*wdg, Item_Container_
                {
                   if (eina_json_type_get(tmp) == EINA_JSON_TYPE_STRING)
                     {
-                       gui_value_string_set(val_icon, 
strdup(eina_json_string_get(tmp)));
+                       gui_value_string_set(val_icon, 
eina_json_string_get(tmp));
                     }
                   else
                     {
@@ -350,7 +350,7 @@ _read_items_section(const Gui_Context *gui_ctx, Gui_Widget 
*wdg, Item_Container_
           {
              if (eina_json_type_get(tmp) == EINA_JSON_TYPE_STRING)
                {
-                  gui_value_string_set(val_label, 
strdup(eina_json_string_get(tmp)));
+                  gui_value_string_set(val_label, eina_json_string_get(tmp));
                }
              else
                {
@@ -405,7 +405,7 @@ _read_items_section(const Gui_Context *gui_ctx, Gui_Widget 
*wdg, Item_Container_
           {
              if (eina_json_type_get(tmp) == EINA_JSON_TYPE_STRING)
                {
-                  gui_value_string_set(val_style, 
strdup(eina_json_string_get(tmp)));
+                  gui_value_string_set(val_style, eina_json_string_get(tmp));
                }
              else
                {
@@ -661,7 +661,7 @@ _widget_parse(Gui_Context *gui_ctx, Eid *eid, 
Eina_Json_Value *widget_js, const
                     {
                        /* Part is the 1st parameter in content_set. */
                        val = prop_value_nth_get(prop, 0);
-                       gui_value_string_set(val, 
strdup(eina_json_string_get(arr_val)));
+                       gui_value_string_set(val, 
eina_json_string_get(arr_val));
                     }
                   Object_Container_Item *ci = obj_container_item_new(prop, 
_eid);
                   wdg_obj_container_item_add(wdg, ci, -1);
diff --git a/src/lib/gui_widget.c b/src/lib/gui_widget.c
index 480f900..153523f 100644
--- a/src/lib/gui_widget.c
+++ b/src/lib/gui_widget.c
@@ -191,8 +191,8 @@ struct _Gui_Value
    Gui_Type type;
    union
      {
-        const char *string;
-        const char *enum_str;
+        char *string;
+        char *enum_str;
         Eid *name_id;
         double value_double;
         int value_sint;
@@ -2591,14 +2591,16 @@ void
 gui_value_string_set(Gui_Value *val, const char *str)
 {
    val->type = GUI_TYPE_STRING;
-   val->string = str;
+   if (str)
+     val->string = strdup(str);
 }
 
 void
 gui_value_enum_set(Gui_Value *val, const char *str)
 {
    val->type = GUI_TYPE_ENUM;
-   val->enum_str = str;
+   if (str)
+     val->enum_str = strdup(str);
 }
 
 void
@@ -2648,12 +2650,12 @@ gui_value_del(Gui_Value *val)
            }
       case GUI_TYPE_ENUM:
            {
-              free((char *) val->enum_str);
+              free(val->enum_str);
               break;
            }
       case GUI_TYPE_STRING:
            {
-              free((char *) val->string);
+              free(val->string);
               break;
            }
       default:

-- 


Reply via email to