cedric pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=b23f65291f9624827e40ebf32d5133cb1074aeb6

commit b23f65291f9624827e40ebf32d5133cb1074aeb6
Author: Cedric BAIL <[email protected]>
Date:   Mon Feb 11 16:31:52 2019 -0800

    eo: make reflection setter able to return an error code in case of failure.
    
    Reviewed-by: Marcel Hollerbach <[email protected]>
    Differential Revision: https://phab.enlightenment.org/D7935
---
 src/bin/eolian/sources.c                  | 11 +++++++++--
 src/lib/eo/Eo.h                           |  4 ++--
 src/lib/eo/eo.c                           | 19 ++++++++++++-------
 src/tests/eo/suite/eo_test_class_simple.c |  4 +++-
 src/tests/eo/suite/eo_test_reflection.c   |  4 ++++
 src/tests/eolian/data/class_simple_ref.c  | 12 +++++++++---
 6 files changed, 39 insertions(+), 15 deletions(-)

diff --git a/src/bin/eolian/sources.c b/src/bin/eolian/sources.c
index 2bcda4c382..e7a461255d 100644
--- a/src/bin/eolian/sources.c
+++ b/src/bin/eolian/sources.c
@@ -408,23 +408,30 @@ _gen_reflect_set(Eina_Strbuf *buf, const char *cnamel, 
const Eolian_Type *valt,
    else
      eina_hash_set(refh, &fid, (void *)EOLIAN_PROP_SET);
 
-   eina_strbuf_append(buf, "\nstatic void\n");
+   eina_strbuf_append(buf, "\nstatic Eina_Error\n");
    eina_strbuf_append_printf(buf, "__eolian_%s_%s_set_reflect(Eo *obj, 
Eina_Value val)\n",
      cnamel, eolian_function_name_get(fid));
    eina_strbuf_append(buf, "{\n");
+   eina_strbuf_append(buf, "   Eina_Error r = 0;");
 
    Eina_Stringshare *ct = eolian_type_c_type_get(valt, EOLIAN_C_TYPE_PARAM);
    const char *starsp = (ct[strlen(ct) - 1] != '*') ? " " : "";
    eina_strbuf_append_printf(buf, "   %s%scval;\n", ct, starsp);
    eina_stringshare_del(ct);
 
-   eina_strbuf_append_printf(buf, "   eina_value_%s_convert(&val, &cval);\n", 
initf);
+   eina_strbuf_append_printf(buf, "   if (!eina_value_%s_convert(&val, 
&cval))\n", initf);
+   eina_strbuf_append(buf, "      {\n");
+   eina_strbuf_append(buf, "         r = EINA_ERROR_VALUE_FAILED;\n");
+   eina_strbuf_append(buf, "         goto end;\n");
+   eina_strbuf_append(buf, "      }\n");
 
    Eina_Stringshare *fcn = eolian_function_full_c_name_get(fid, 
EOLIAN_PROP_SET, EINA_FALSE);
    eina_strbuf_append_printf(buf, "   %s(obj, cval);\n", fcn);
    eina_stringshare_del(fcn);
 
+   eina_strbuf_append(buf, " end:\n");
    eina_strbuf_append(buf, "   eina_value_flush(&val);\n");
+   eina_strbuf_append(buf, "   return r;\n");
 
    eina_strbuf_append(buf, "}\n\n");
 }
diff --git a/src/lib/eo/Eo.h b/src/lib/eo/Eo.h
index 323a1a97b5..52b75134ac 100644
--- a/src/lib/eo/Eo.h
+++ b/src/lib/eo/Eo.h
@@ -827,7 +827,7 @@ struct _Efl_Class_Description
 /**
  * Setter type which is used to set an #Eina_Value, this function should 
access one particular property field
  */
-typedef void (*Efl_Object_Property_Reflection_Setter)(Eo *obj, Eina_Value 
value);
+typedef Eina_Error (*Efl_Object_Property_Reflection_Setter)(Eo *obj, 
Eina_Value value);
 
 /**
  * Getter type which is used to get an #Eina_Value, this function should 
access one particular property field
@@ -1985,7 +1985,7 @@ EAPI Eina_Bool efl_destructed_is(const Eo *obj);
  * @param value The value to set, the value passed here will be flushed by the 
function
  *
  */
-EAPI void efl_property_reflection_set(Eo *obj, const char *property_name, 
Eina_Value value);
+EAPI Eina_Error efl_property_reflection_set(Eo *obj, const char 
*property_name, Eina_Value value);
 
 /**
  * @brief Retrieve an #Eina_Value containing the current value of the property 
specified with \c property_name.
diff --git a/src/lib/eo/eo.c b/src/lib/eo/eo.c
index c2b5f85b60..efd68055dc 100644
--- a/src/lib/eo/eo.c
+++ b/src/lib/eo/eo.c
@@ -3636,20 +3636,25 @@ _efl_class_reflection_find(const _Efl_Class *klass, 
const char *property_name)
    return NULL;
 }
 
-EAPI void
+EAPI Eina_Error
 efl_property_reflection_set(Eo *obj_id, const char *property_name, Eina_Value 
value)
 {
+   Eina_Error r = EINA_ERROR_NOT_IMPLEMENTED;
+   Eina_Bool freed = EINA_FALSE;
+
    EO_OBJ_POINTER_GOTO(obj_id, obj, end);
    const Efl_Object_Property_Reflection *reflection = 
_efl_class_reflection_find(obj->klass, property_name);
 
-   if (!reflection || !reflection->set) goto end;
+   if (reflection && reflection->set)
+     {
+        r = reflection->set(obj_id, value);
+        freed = EINA_TRUE;
+     }
 
-   reflection->set(obj_id, value);
-   EO_OBJ_DONE(obj_id);
-   return;
-end:
-   eina_value_flush(&value);
+ end:
+   if (!freed) eina_value_flush(&value);
    EO_OBJ_DONE(obj_id);
+   return r;
 }
 
 EAPI Eina_Value
diff --git a/src/tests/eo/suite/eo_test_class_simple.c 
b/src/tests/eo/suite/eo_test_class_simple.c
index fef3dd3ae5..f374575ee4 100644
--- a/src/tests/eo/suite/eo_test_class_simple.c
+++ b/src/tests/eo/suite/eo_test_class_simple.c
@@ -23,7 +23,7 @@ _a_set(Eo *obj EINA_UNUSED, void *class_data, int a)
    efl_event_callback_legacy_call(obj, EV_A_CHANGED, &pd->a);
 }
 
-static void
+static Eina_Error
 _a_set_reflect(Eo *obj, Eina_Value value)
 {
    int a;
@@ -31,6 +31,8 @@ _a_set_reflect(Eo *obj, Eina_Value value)
    eina_value_int_convert(&value, &a);
    simple_a_set(obj, a);
    eina_value_flush(&value);
+
+   return 0;
 }
 
 static int
diff --git a/src/tests/eo/suite/eo_test_reflection.c 
b/src/tests/eo/suite/eo_test_reflection.c
index ae1e11b214..b517f61ad5 100644
--- a/src/tests/eo/suite/eo_test_reflection.c
+++ b/src/tests/eo/suite/eo_test_reflection.c
@@ -45,12 +45,16 @@ EFL_START_TEST(eo_test_reflection_simple)
    const int numb = 42;
    int number_ref;
    Eina_Value numb_val = eina_value_int_init(numb);
+   Eina_Value useless_val = eina_value_int_init(7);
    Eo *simple = efl_new(SIMPLE_CLASS);
 
    simple_a_set(simple, 22);
    efl_property_reflection_set(simple, "simple_a", numb_val);
    ck_assert_int_eq(simple_a_get(simple), numb);
 
+   ck_assert_int_eq(efl_property_reflection_set(simple, "should_fail", 
useless_val),
+                    EINA_ERROR_NOT_IMPLEMENTED);
+
    simple_a_set(simple, 22);
    Eina_Value res = efl_property_reflection_get(simple, "simple_a");
    eina_value_int_convert(&res, &number_ref);
diff --git a/src/tests/eolian/data/class_simple_ref.c 
b/src/tests/eolian/data/class_simple_ref.c
index 0ce99ca6d1..5d1af350e6 100644
--- a/src/tests/eolian/data/class_simple_ref.c
+++ b/src/tests/eolian/data/class_simple_ref.c
@@ -3,13 +3,19 @@ EWAPI float BAR = 10.300000f;
 Eina_Bool _class_simple_a_set(Eo *obj, Evas_Simple_Data *pd, int value);
 
 
-static void
+static Eina_Error
 __eolian_class_simple_a_set_reflect(Eo *obj, Eina_Value val)
 {
-   int cval;
-   eina_value_int_convert(&val, &cval);
+   Eina_Error r = 0;   int cval;
+   if (!eina_value_int_convert(&val, &cval))
+      {
+         r = EINA_ERROR_VALUE_FAILED;
+         goto end;
+      }
    efl_canvas_object_simple_a_set(obj, cval);
+ end:
    eina_value_flush(&val);
+   return r;
 }
 
 EOAPI EFL_FUNC_BODYV(efl_canvas_object_simple_a_set, Eina_Bool, EINA_TRUE /* 
true */, EFL_FUNC_CALL(value), int value);

-- 


Reply via email to