summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCedric BAIL <cedric.bail@free.fr>2019-02-11 16:31:52 -0800
committerCedric BAIL <cedric.bail@free.fr>2019-02-21 11:54:09 -0800
commitb23f65291f9624827e40ebf32d5133cb1074aeb6 (patch)
tree34f7287c424413a2bf5debb2ff8601e6c7d1e00a /src
parent56a91961ce07337fb9e73f46298415426175d25a (diff)
eo: make reflection setter able to return an error code in case of failure.
Reviewed-by: Marcel Hollerbach <marcel-hollerbach@t-online.de> Differential Revision: https://phab.enlightenment.org/D7935
Diffstat (limited to 'src')
-rw-r--r--src/bin/eolian/sources.c11
-rw-r--r--src/lib/eo/Eo.h4
-rw-r--r--src/lib/eo/eo.c19
-rw-r--r--src/tests/eo/suite/eo_test_class_simple.c4
-rw-r--r--src/tests/eo/suite/eo_test_reflection.c4
-rw-r--r--src/tests/eolian/data/class_simple_ref.c12
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,
408 else 408 else
409 eina_hash_set(refh, &fid, (void *)EOLIAN_PROP_SET); 409 eina_hash_set(refh, &fid, (void *)EOLIAN_PROP_SET);
410 410
411 eina_strbuf_append(buf, "\nstatic void\n"); 411 eina_strbuf_append(buf, "\nstatic Eina_Error\n");
412 eina_strbuf_append_printf(buf, "__eolian_%s_%s_set_reflect(Eo *obj, Eina_Value val)\n", 412 eina_strbuf_append_printf(buf, "__eolian_%s_%s_set_reflect(Eo *obj, Eina_Value val)\n",
413 cnamel, eolian_function_name_get(fid)); 413 cnamel, eolian_function_name_get(fid));
414 eina_strbuf_append(buf, "{\n"); 414 eina_strbuf_append(buf, "{\n");
415 eina_strbuf_append(buf, " Eina_Error r = 0;");
415 416
416 Eina_Stringshare *ct = eolian_type_c_type_get(valt, EOLIAN_C_TYPE_PARAM); 417 Eina_Stringshare *ct = eolian_type_c_type_get(valt, EOLIAN_C_TYPE_PARAM);
417 const char *starsp = (ct[strlen(ct) - 1] != '*') ? " " : ""; 418 const char *starsp = (ct[strlen(ct) - 1] != '*') ? " " : "";
418 eina_strbuf_append_printf(buf, " %s%scval;\n", ct, starsp); 419 eina_strbuf_append_printf(buf, " %s%scval;\n", ct, starsp);
419 eina_stringshare_del(ct); 420 eina_stringshare_del(ct);
420 421
421 eina_strbuf_append_printf(buf, " eina_value_%s_convert(&val, &cval);\n", initf); 422 eina_strbuf_append_printf(buf, " if (!eina_value_%s_convert(&val, &cval))\n", initf);
423 eina_strbuf_append(buf, " {\n");
424 eina_strbuf_append(buf, " r = EINA_ERROR_VALUE_FAILED;\n");
425 eina_strbuf_append(buf, " goto end;\n");
426 eina_strbuf_append(buf, " }\n");
422 427
423 Eina_Stringshare *fcn = eolian_function_full_c_name_get(fid, EOLIAN_PROP_SET, EINA_FALSE); 428 Eina_Stringshare *fcn = eolian_function_full_c_name_get(fid, EOLIAN_PROP_SET, EINA_FALSE);
424 eina_strbuf_append_printf(buf, " %s(obj, cval);\n", fcn); 429 eina_strbuf_append_printf(buf, " %s(obj, cval);\n", fcn);
425 eina_stringshare_del(fcn); 430 eina_stringshare_del(fcn);
426 431
432 eina_strbuf_append(buf, " end:\n");
427 eina_strbuf_append(buf, " eina_value_flush(&val);\n"); 433 eina_strbuf_append(buf, " eina_value_flush(&val);\n");
434 eina_strbuf_append(buf, " return r;\n");
428 435
429 eina_strbuf_append(buf, "}\n\n"); 436 eina_strbuf_append(buf, "}\n\n");
430} 437}
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
827/** 827/**
828 * Setter type which is used to set an #Eina_Value, this function should access one particular property field 828 * Setter type which is used to set an #Eina_Value, this function should access one particular property field
829 */ 829 */
830typedef void (*Efl_Object_Property_Reflection_Setter)(Eo *obj, Eina_Value value); 830typedef Eina_Error (*Efl_Object_Property_Reflection_Setter)(Eo *obj, Eina_Value value);
831 831
832/** 832/**
833 * Getter type which is used to get an #Eina_Value, this function should access one particular property field 833 * 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);
1985 * @param value The value to set, the value passed here will be flushed by the function 1985 * @param value The value to set, the value passed here will be flushed by the function
1986 * 1986 *
1987 */ 1987 */
1988EAPI void efl_property_reflection_set(Eo *obj, const char *property_name, Eina_Value value); 1988EAPI Eina_Error efl_property_reflection_set(Eo *obj, const char *property_name, Eina_Value value);
1989 1989
1990/** 1990/**
1991 * @brief Retrieve an #Eina_Value containing the current value of the property specified with \c property_name. 1991 * @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)
3636 return NULL; 3636 return NULL;
3637} 3637}
3638 3638
3639EAPI void 3639EAPI Eina_Error
3640efl_property_reflection_set(Eo *obj_id, const char *property_name, Eina_Value value) 3640efl_property_reflection_set(Eo *obj_id, const char *property_name, Eina_Value value)
3641{ 3641{
3642 Eina_Error r = EINA_ERROR_NOT_IMPLEMENTED;
3643 Eina_Bool freed = EINA_FALSE;
3644
3642 EO_OBJ_POINTER_GOTO(obj_id, obj, end); 3645 EO_OBJ_POINTER_GOTO(obj_id, obj, end);
3643 const Efl_Object_Property_Reflection *reflection = _efl_class_reflection_find(obj->klass, property_name); 3646 const Efl_Object_Property_Reflection *reflection = _efl_class_reflection_find(obj->klass, property_name);
3644 3647
3645 if (!reflection || !reflection->set) goto end; 3648 if (reflection && reflection->set)
3649 {
3650 r = reflection->set(obj_id, value);
3651 freed = EINA_TRUE;
3652 }
3646 3653
3647 reflection->set(obj_id, value); 3654 end:
3648 EO_OBJ_DONE(obj_id); 3655 if (!freed) eina_value_flush(&value);
3649 return;
3650end:
3651 eina_value_flush(&value);
3652 EO_OBJ_DONE(obj_id); 3656 EO_OBJ_DONE(obj_id);
3657 return r;
3653} 3658}
3654 3659
3655EAPI Eina_Value 3660EAPI 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)
23 efl_event_callback_legacy_call(obj, EV_A_CHANGED, &pd->a); 23 efl_event_callback_legacy_call(obj, EV_A_CHANGED, &pd->a);
24} 24}
25 25
26static void 26static Eina_Error
27_a_set_reflect(Eo *obj, Eina_Value value) 27_a_set_reflect(Eo *obj, Eina_Value value)
28{ 28{
29 int a; 29 int a;
@@ -31,6 +31,8 @@ _a_set_reflect(Eo *obj, Eina_Value value)
31 eina_value_int_convert(&value, &a); 31 eina_value_int_convert(&value, &a);
32 simple_a_set(obj, a); 32 simple_a_set(obj, a);
33 eina_value_flush(&value); 33 eina_value_flush(&value);
34
35 return 0;
34} 36}
35 37
36static int 38static 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)
45 const int numb = 42; 45 const int numb = 42;
46 int number_ref; 46 int number_ref;
47 Eina_Value numb_val = eina_value_int_init(numb); 47 Eina_Value numb_val = eina_value_int_init(numb);
48 Eina_Value useless_val = eina_value_int_init(7);
48 Eo *simple = efl_new(SIMPLE_CLASS); 49 Eo *simple = efl_new(SIMPLE_CLASS);
49 50
50 simple_a_set(simple, 22); 51 simple_a_set(simple, 22);
51 efl_property_reflection_set(simple, "simple_a", numb_val); 52 efl_property_reflection_set(simple, "simple_a", numb_val);
52 ck_assert_int_eq(simple_a_get(simple), numb); 53 ck_assert_int_eq(simple_a_get(simple), numb);
53 54
55 ck_assert_int_eq(efl_property_reflection_set(simple, "should_fail", useless_val),
56 EINA_ERROR_NOT_IMPLEMENTED);
57
54 simple_a_set(simple, 22); 58 simple_a_set(simple, 22);
55 Eina_Value res = efl_property_reflection_get(simple, "simple_a"); 59 Eina_Value res = efl_property_reflection_get(simple, "simple_a");
56 eina_value_int_convert(&res, &number_ref); 60 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;
3Eina_Bool _class_simple_a_set(Eo *obj, Evas_Simple_Data *pd, int value); 3Eina_Bool _class_simple_a_set(Eo *obj, Evas_Simple_Data *pd, int value);
4 4
5 5
6static void 6static Eina_Error
7__eolian_class_simple_a_set_reflect(Eo *obj, Eina_Value val) 7__eolian_class_simple_a_set_reflect(Eo *obj, Eina_Value val)
8{ 8{
9 int cval; 9 Eina_Error r = 0; int cval;
10 eina_value_int_convert(&val, &cval); 10 if (!eina_value_int_convert(&val, &cval))
11 {
12 r = EINA_ERROR_VALUE_FAILED;
13 goto end;
14 }
11 efl_canvas_object_simple_a_set(obj, cval); 15 efl_canvas_object_simple_a_set(obj, cval);
16 end:
12 eina_value_flush(&val); 17 eina_value_flush(&val);
18 return r;
13} 19}
14 20
15EOAPI EFL_FUNC_BODYV(efl_canvas_object_simple_a_set, Eina_Bool, EINA_TRUE /* true */, EFL_FUNC_CALL(value), int value); 21EOAPI EFL_FUNC_BODYV(efl_canvas_object_simple_a_set, Eina_Bool, EINA_TRUE /* true */, EFL_FUNC_CALL(value), int value);