summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Kolesa <d.kolesa@samsung.com>2019-03-21 15:55:43 +0100
committerDaniel Kolesa <d.kolesa@samsung.com>2019-03-21 16:00:18 +0100
commit3f083b3ccba9cdc0f9cfe875fec030e228be69d0 (patch)
treed9fc3d0275130dddb620fd578a15c42b13276c77
parent1066e5be60eb135700f3ec41c6b184ecbe142f6e (diff)
eolian: add event type call convention checks for non-beta classes
-rw-r--r--src/lib/eolian/database_validate.c60
-rw-r--r--src/tests/eolian_cxx/callback.eo2
-rw-r--r--src/tests/eolian_cxx/eolian_cxx_test_binding.cc2
-rw-r--r--src/tests/eolian_cxx/generic.c6
-rw-r--r--src/tests/eolian_cxx/generic.eo2
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)
524 if (!_validate_type(vals, event->type)) 524 if (!_validate_type(vals, event->type))
525 return _reset_stable(vals, was_stable, EINA_FALSE); 525 return _reset_stable(vals, was_stable, EINA_FALSE);
526 526
527 /* if this is an alias we need the lowest type in the stack, this is
528 * after validation so all the necessary fields are properly filled in
529 */
530 const Eolian_Type *tp = eolian_type_aliased_base_get(event->type);
531
532 /* event types are specially restricted
533 * but stuff like pointer-to-pointer is alrady handled by _validate_type
534 */
535 if (tp->type == EOLIAN_TYPE_REGULAR && vals->stable)
536 {
537 /* explicit pointers never allowed */
538 if (tp->is_ptr)
539 {
540 _eo_parser_log(&tp->base, "pointers not allowed in events");
541 return _reset_stable(vals, was_stable, EINA_FALSE);
542 }
543 /* require containers to be const for now...
544 *
545 * this is FIXME, and decision wasn't reached before 1.22
546 * it is a simple search-replace anyway
547 */
548 if (database_type_is_ownable(tp->base.unit, tp, EINA_FALSE))
549 {
550 if (!tp->is_const)
551 {
552 _eo_parser_log(&tp->base, "event container types must be const");
553 return _reset_stable(vals, was_stable, EINA_FALSE);
554 }
555 }
556 else if (tp->is_const)
557 {
558 _eo_parser_log(&tp->base, "event value types cannot be const");
559 return _reset_stable(vals, was_stable, EINA_FALSE);
560 }
561 int kwid = eo_lexer_keyword_str_to_id(tp->base.name);
562 /* containers are allowed but not iterators/lists */
563 if (kwid == KW_iterator || kwid == KW_list)
564 {
565 _eo_parser_log(&tp->base, "sequence containers not allowed in events");
566 return _reset_stable(vals, was_stable, EINA_FALSE);
567 }
568 /* rw slices are not allowed as regular types are always immutable */
569 if (kwid == KW_rw_slice)
570 {
571 _eo_parser_log(&tp->base, "mutable slices not allowed in events");
572 return _reset_stable(vals, was_stable, EINA_FALSE);
573 }
574 /* any type past builtin value types and containers is not allowed,
575 * any_value is allowed but passed as const reference, any_value_ptr
576 * is not; string is allowed, but mutable strings or stringshares are
577 * not and neither are string buffers, the type is never owned by the
578 * callee, so all strings passed in are unowned and read-only
579 */
580 if (kwid >= KW_any_value_ptr && kwid != KW_string)
581 {
582 _eo_parser_log(&tp->base, "forbidden event type");
583 return _reset_stable(vals, was_stable, EINA_FALSE);
584 }
585 }
586
527 if (!_validate_doc(event->doc)) 587 if (!_validate_doc(event->doc))
528 return _reset_stable(vals, was_stable, EINA_FALSE); 588 return _reset_stable(vals, was_stable, EINA_FALSE);
529 589
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
11 prefix,event1: void; 11 prefix,event1: void;
12 prefix,event2: Callback; 12 prefix,event2: Callback;
13 prefix,event3: int; 13 prefix,event3: int;
14 prefix,event4: list<int*>; 14 prefix,event4: const(array<ptr(int)>);
15 prefix,event5: Callback_Event; 15 prefix,event5: Callback_Event;
16 } 16 }
17} 17}
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)
203 event3 = true; 203 event3 = true;
204 ck_assert(v == 42); 204 ck_assert(v == 42);
205 }); 205 });
206 efl::eolian::event_add(g.prefix_event4_event, g, [&] (nonamespace::Generic, efl::eina::range_list<const int &> e) 206 efl::eolian::event_add(g.prefix_event4_event, g, [&] (nonamespace::Generic, efl::eina::range_array<const int &> e)
207 { 207 {
208 event4 = true; 208 event4 = true;
209 ck_assert(e.size() == 1); 209 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)
115static void _generic_call_event4(Eo *obj, Generic_Data* pd EINA_UNUSED) 115static void _generic_call_event4(Eo *obj, Generic_Data* pd EINA_UNUSED)
116{ 116{
117 int i = 42; 117 int i = 42;
118 Eina_List* p = eina_list_append(NULL, &i); 118 Eina_Array* p = eina_array_new(1);
119 ck_assert(p != NULL); 119 ck_assert(eina_array_push(p, &i));
120 efl_event_callback_call(obj, GENERIC_EVENT_PREFIX_EVENT4, p); 120 efl_event_callback_call(obj, GENERIC_EVENT_PREFIX_EVENT4, p);
121 eina_list_free(p); 121 eina_array_free(p);
122} 122}
123static void _generic_call_event5(Eo *obj, Generic_Data* pd EINA_UNUSED) 123static void _generic_call_event5(Eo *obj, Generic_Data* pd EINA_UNUSED)
124{ 124{
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
108 prefix,event1: void; 108 prefix,event1: void;
109 prefix,event2: Generic; 109 prefix,event2: Generic;
110 prefix,event3: int; 110 prefix,event3: int;
111 prefix,event4: list<ptr(int)>; 111 prefix,event4: const(array<ptr(int)>);
112 prefix,event5: Generic.Event; 112 prefix,event5: Generic.Event;
113 protected,event1 @protected: void; 113 protected,event1 @protected: void;
114 beta,event1 @beta: void; 114 beta,event1 @beta: void;