summaryrefslogtreecommitdiff
path: root/src/lib/eolian
diff options
context:
space:
mode:
authorDaniel Kolesa <d.kolesa@samsung.com>2019-08-31 01:30:00 +0200
committerDaniel Kolesa <d.kolesa@samsung.com>2019-08-31 01:58:19 +0200
commitb1d147abf4ff235e6acb32c53bd695cb533a4a97 (patch)
treefb556f5fc6d8fe4263cdc89147a74454b2dec3b3 /src/lib/eolian
parentb6648b748bdef45293bc220cc84c21c9d60d36c1 (diff)
eolian: validate @by_ref correctness
The @by_ref qualifier can only be used with value types, to guarantee exactly one level of pointers.
Diffstat (limited to 'src/lib/eolian')
-rw-r--r--src/lib/eolian/database_validate.c31
1 files changed, 27 insertions, 4 deletions
diff --git a/src/lib/eolian/database_validate.c b/src/lib/eolian/database_validate.c
index ee55e6cfe3..0d118ceb4a 100644
--- a/src/lib/eolian/database_validate.c
+++ b/src/lib/eolian/database_validate.c
@@ -105,6 +105,8 @@ _validate_doc(Eolian_Documentation *doc)
105} 105}
106 106
107static Eina_Bool _validate_type(Validate_State *vals, Eolian_Type *tp); 107static Eina_Bool _validate_type(Validate_State *vals, Eolian_Type *tp);
108static Eina_Bool _validate_type_by_ref(Validate_State *vals, Eolian_Type *tp,
109 Eina_Bool by_ref);
108static Eina_Bool _validate_expr(Eolian_Expression *expr, 110static Eina_Bool _validate_expr(Eolian_Expression *expr,
109 const Eolian_Type *tp, 111 const Eolian_Type *tp,
110 Eolian_Expression_Mask msk); 112 Eolian_Expression_Mask msk);
@@ -122,7 +124,7 @@ static Eina_Bool
122_sf_map_cb(const Eina_Hash *hash EINA_UNUSED, const void *key EINA_UNUSED, 124_sf_map_cb(const Eina_Hash *hash EINA_UNUSED, const void *key EINA_UNUSED,
123 const Eolian_Struct_Type_Field *sf, Cb_Ret *sc) 125 const Eolian_Struct_Type_Field *sf, Cb_Ret *sc)
124{ 126{
125 sc->succ = _validate_type(sc->vals, sf->type); 127 sc->succ = _validate_type_by_ref(sc->vals, sf->type, sf->by_ref);
126 128
127 if (!sc->succ) 129 if (!sc->succ)
128 return EINA_FALSE; 130 return EINA_FALSE;
@@ -223,6 +225,25 @@ _validate_ownable(Eolian_Type *tp)
223} 225}
224 226
225static Eina_Bool 227static Eina_Bool
228_validate_by_ref(Eolian_Type *tp, Eina_Bool by_ref)
229{
230 /* when not @by_ref, allow any type */
231 if (!by_ref)
232 return EINA_TRUE;
233 /* else only allow value types */
234 return !database_type_is_ownable(tp->base.unit, tp, EINA_FALSE);
235}
236
237static Eina_Bool
238_validate_type_by_ref(Validate_State *vals, Eolian_Type *tp, Eina_Bool by_ref)
239{
240 if (!_validate_type(vals, tp))
241 return EINA_FALSE;
242
243 return _validate_by_ref(tp, by_ref);
244}
245
246static Eina_Bool
226_validate_type(Validate_State *vals, Eolian_Type *tp) 247_validate_type(Validate_State *vals, Eolian_Type *tp)
227{ 248{
228 const Eolian_Unit *src = tp->base.unit; 249 const Eolian_Unit *src = tp->base.unit;
@@ -392,7 +413,7 @@ _validate_expr(Eolian_Expression *expr, const Eolian_Type *tp,
392static Eina_Bool 413static Eina_Bool
393_validate_param(Validate_State *vals, Eolian_Function_Parameter *param) 414_validate_param(Validate_State *vals, Eolian_Function_Parameter *param)
394{ 415{
395 if (!_validate_type(vals, param->type)) 416 if (!_validate_type_by_ref(vals, param->type, param->by_ref))
396 return EINA_FALSE; 417 return EINA_FALSE;
397 418
398 if (param->value && !_validate_expr(param->value, param->type, 0)) 419 if (param->value && !_validate_expr(param->value, param->type, 0))
@@ -434,10 +455,12 @@ _validate_function(Validate_State *vals, Eolian_Function *func, Eina_Hash *nhash
434 /* need to preserve stable flag set from the class */ 455 /* need to preserve stable flag set from the class */
435 Eina_Bool was_stable = _set_stable(vals, !func->base.is_beta && vals->stable); 456 Eina_Bool was_stable = _set_stable(vals, !func->base.is_beta && vals->stable);
436 457
437 if (func->get_ret_type && !_validate_type(vals, func->get_ret_type)) 458 if (func->get_ret_type && !_validate_type_by_ref(vals, func->get_ret_type,
459 func->get_return_by_ref))
438 return _reset_stable(vals, was_stable, EINA_FALSE); 460 return _reset_stable(vals, was_stable, EINA_FALSE);
439 461
440 if (func->set_ret_type && !_validate_type(vals, func->set_ret_type)) 462 if (func->set_ret_type && !_validate_type_by_ref(vals, func->set_ret_type,
463 func->set_return_by_ref))
441 return _reset_stable(vals, was_stable, EINA_FALSE); 464 return _reset_stable(vals, was_stable, EINA_FALSE);
442 465
443 if (func->get_ret_val && !_validate_expr(func->get_ret_val, 466 if (func->get_ret_val && !_validate_expr(func->get_ret_val,