diff options
author | Daniel Kolesa <d.kolesa@samsung.com> | 2019-03-21 15:55:43 +0100 |
---|---|---|
committer | Daniel Kolesa <d.kolesa@samsung.com> | 2019-03-21 16:00:18 +0100 |
commit | 3f083b3ccba9cdc0f9cfe875fec030e228be69d0 (patch) | |
tree | d9fc3d0275130dddb620fd578a15c42b13276c77 | |
parent | 1066e5be60eb135700f3ec41c6b184ecbe142f6e (diff) | |
download | efl-3f083b3ccba9cdc0f9cfe875fec030e228be69d0.tar.gz |
eolian: add event type call convention checks for non-beta classes
-rw-r--r-- | src/lib/eolian/database_validate.c | 60 | ||||
-rw-r--r-- | src/tests/eolian_cxx/callback.eo | 2 | ||||
-rw-r--r-- | src/tests/eolian_cxx/eolian_cxx_test_binding.cc | 2 | ||||
-rw-r--r-- | src/tests/eolian_cxx/generic.c | 6 | ||||
-rw-r--r-- | src/tests/eolian_cxx/generic.eo | 2 |
5 files changed, 66 insertions, 6 deletions
diff --git a/src/lib/eolian/database_validate.c b/src/lib/eolian/database_validate.c index a0aa0af45c..d9ca18a755 100644 --- a/src/lib/eolian/database_validate.c +++ b/src/lib/eolian/database_validate.c @@ -524,6 +524,66 @@ _validate_event(Validate_State *vals, Eolian_Event *event, Eina_Hash *nhash) if (!_validate_type(vals, event->type)) return _reset_stable(vals, was_stable, EINA_FALSE); + /* if this is an alias we need the lowest type in the stack, this is + * after validation so all the necessary fields are properly filled in + */ + const Eolian_Type *tp = eolian_type_aliased_base_get(event->type); + + /* event types are specially restricted + * but stuff like pointer-to-pointer is alrady handled by _validate_type + */ + if (tp->type == EOLIAN_TYPE_REGULAR && vals->stable) + { + /* explicit pointers never allowed */ + if (tp->is_ptr) + { + _eo_parser_log(&tp->base, "pointers not allowed in events"); + return _reset_stable(vals, was_stable, EINA_FALSE); + } + /* require containers to be const for now... + * + * this is FIXME, and decision wasn't reached before 1.22 + * it is a simple search-replace anyway + */ + if (database_type_is_ownable(tp->base.unit, tp, EINA_FALSE)) + { + if (!tp->is_const) + { + _eo_parser_log(&tp->base, "event container types must be const"); + return _reset_stable(vals, was_stable, EINA_FALSE); + } + } + else if (tp->is_const) + { + _eo_parser_log(&tp->base, "event value types cannot be const"); + return _reset_stable(vals, was_stable, EINA_FALSE); + } + int kwid = eo_lexer_keyword_str_to_id(tp->base.name); + /* containers are allowed but not iterators/lists */ + if (kwid == KW_iterator || kwid == KW_list) + { + _eo_parser_log(&tp->base, "sequence containers not allowed in events"); + return _reset_stable(vals, was_stable, EINA_FALSE); + } + /* rw slices are not allowed as regular types are always immutable */ + if (kwid == KW_rw_slice) + { + _eo_parser_log(&tp->base, "mutable slices not allowed in events"); + return _reset_stable(vals, was_stable, EINA_FALSE); + } + /* any type past builtin value types and containers is not allowed, + * any_value is allowed but passed as const reference, any_value_ptr + * is not; string is allowed, but mutable strings or stringshares are + * not and neither are string buffers, the type is never owned by the + * callee, so all strings passed in are unowned and read-only + */ + if (kwid >= KW_any_value_ptr && kwid != KW_string) + { + _eo_parser_log(&tp->base, "forbidden event type"); + return _reset_stable(vals, was_stable, EINA_FALSE); + } + } + if (!_validate_doc(event->doc)) return _reset_stable(vals, was_stable, EINA_FALSE); diff --git a/src/tests/eolian_cxx/callback.eo b/src/tests/eolian_cxx/callback.eo index 3f4cd9effe..a62ec0031b 100644 --- a/src/tests/eolian_cxx/callback.eo +++ b/src/tests/eolian_cxx/callback.eo @@ -11,7 +11,7 @@ class Callback extends Efl.Object prefix,event1: void; prefix,event2: Callback; prefix,event3: int; - prefix,event4: list<int*>; + prefix,event4: const(array<ptr(int)>); prefix,event5: Callback_Event; } } diff --git a/src/tests/eolian_cxx/eolian_cxx_test_binding.cc b/src/tests/eolian_cxx/eolian_cxx_test_binding.cc index 9d1734c94d..069e876ba5 100644 --- a/src/tests/eolian_cxx/eolian_cxx_test_binding.cc +++ b/src/tests/eolian_cxx/eolian_cxx_test_binding.cc @@ -203,7 +203,7 @@ EFL_START_TEST(eolian_cxx_test_type_callback) event3 = true; ck_assert(v == 42); }); - efl::eolian::event_add(g.prefix_event4_event, g, [&] (nonamespace::Generic, efl::eina::range_list<const int &> e) + efl::eolian::event_add(g.prefix_event4_event, g, [&] (nonamespace::Generic, efl::eina::range_array<const int &> e) { event4 = true; ck_assert(e.size() == 1); diff --git a/src/tests/eolian_cxx/generic.c b/src/tests/eolian_cxx/generic.c index ee3a0c3e87..65f8025b57 100644 --- a/src/tests/eolian_cxx/generic.c +++ b/src/tests/eolian_cxx/generic.c @@ -115,10 +115,10 @@ static void _generic_call_event3(Eo *obj, Generic_Data* pd EINA_UNUSED) static void _generic_call_event4(Eo *obj, Generic_Data* pd EINA_UNUSED) { int i = 42; - Eina_List* p = eina_list_append(NULL, &i); - ck_assert(p != NULL); + Eina_Array* p = eina_array_new(1); + ck_assert(eina_array_push(p, &i)); efl_event_callback_call(obj, GENERIC_EVENT_PREFIX_EVENT4, p); - eina_list_free(p); + eina_array_free(p); } static void _generic_call_event5(Eo *obj, Generic_Data* pd EINA_UNUSED) { diff --git a/src/tests/eolian_cxx/generic.eo b/src/tests/eolian_cxx/generic.eo index 7f367a975b..192765d7df 100644 --- a/src/tests/eolian_cxx/generic.eo +++ b/src/tests/eolian_cxx/generic.eo @@ -108,7 +108,7 @@ class Generic extends Efl.Object implements Generic_Interface prefix,event1: void; prefix,event2: Generic; prefix,event3: int; - prefix,event4: list<ptr(int)>; + prefix,event4: const(array<ptr(int)>); prefix,event5: Generic.Event; protected,event1 @protected: void; beta,event1 @beta: void; |