summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Kolesa <d.kolesa@samsung.com>2020-05-31 02:28:22 +0200
committerDaniel Kolesa <d.kolesa@samsung.com>2020-05-31 02:32:35 +0200
commit38bf0be7d002c578392039b57f518ae5eb112ad9 (patch)
tree76aad20e5bc8d83a00cdddb5aad7e8df2ae13a12
parent1ba91f37fb155763423d3e2e9f3d1892c4c185f6 (diff)
bindings/lua: use new _fill api variants for expr values
The previous behavior was also invalid, since it was casting a GC-managed pointer, which doesn't provide any guarantee that it will stay valid. Fix that too, by using manually allocated memory and assigning a finalizer at the end.
-rw-r--r--src/bindings/lua/eolian.lua31
1 files changed, 23 insertions, 8 deletions
diff --git a/src/bindings/lua/eolian.lua b/src/bindings/lua/eolian.lua
index b847a69835..eebe44486f 100644
--- a/src/bindings/lua/eolian.lua
+++ b/src/bindings/lua/eolian.lua
@@ -278,6 +278,9 @@ ffi.cdef [[
278 const char *text_end; 278 const char *text_end;
279 } Eolian_Doc_Token; 279 } Eolian_Doc_Token;
280 280
281 void *malloc(size_t sz);
282 void free(void *ptr);
283
281 int eolian_init(void); 284 int eolian_init(void);
282 int eolian_shutdown(void); 285 int eolian_shutdown(void);
283 unsigned short eolian_file_format_version_get(void); 286 unsigned short eolian_file_format_version_get(void);
@@ -443,7 +446,7 @@ ffi.cdef [[
443 446
444 const Eolian_Function *eolian_typedecl_function_pointer_get(const Eolian_Typedecl *tp); 447 const Eolian_Function *eolian_typedecl_function_pointer_get(const Eolian_Typedecl *tp);
445 448
446 Eolian_Value_t eolian_expression_eval(const Eolian_Expression *expr, Eolian_Expression_Mask m); 449 Eina_Bool eolian_expression_eval_fill(const Eolian_Expression *expr, Eolian_Expression_Mask m, Eolian_Value_t *val);
447 const char *eolian_expression_value_to_literal(const Eolian_Value *v); 450 const char *eolian_expression_value_to_literal(const Eolian_Value *v);
448 const char *eolian_expression_serialize(const Eolian_Expression *expr); 451 const char *eolian_expression_serialize(const Eolian_Expression *expr);
449 Eolian_Expression_Type eolian_expression_type_get(const Eolian_Expression *expr); 452 Eolian_Expression_Type eolian_expression_type_get(const Eolian_Expression *expr);
@@ -452,7 +455,7 @@ ffi.cdef [[
452 const Eolian_Expression *eolian_expression_binary_rhs_get(const Eolian_Expression *expr); 455 const Eolian_Expression *eolian_expression_binary_rhs_get(const Eolian_Expression *expr);
453 Eolian_Unary_Operator eolian_expression_unary_operator_get(const Eolian_Expression *expr); 456 Eolian_Unary_Operator eolian_expression_unary_operator_get(const Eolian_Expression *expr);
454 const Eolian_Expression *eolian_expression_unary_expression_get(const Eolian_Expression *expr); 457 const Eolian_Expression *eolian_expression_unary_expression_get(const Eolian_Expression *expr);
455 Eolian_Value_t eolian_expression_value_get(const Eolian_Expression *expr); 458 Eina_Bool eolian_expression_value_get_fill(const Eolian_Expression *expr, Eolian_Value_t *val);
456 const Eolian_Documentation *eolian_constant_documentation_get(const Eolian_Constant *var); 459 const Eolian_Documentation *eolian_constant_documentation_get(const Eolian_Constant *var);
457 const Eolian_Type *eolian_constant_type_get(const Eolian_Constant *var); 460 const Eolian_Type *eolian_constant_type_get(const Eolian_Constant *var);
458 const Eolian_Expression *eolian_constant_value_get(const Eolian_Constant *var); 461 const Eolian_Expression *eolian_constant_value_get(const Eolian_Constant *var);
@@ -1656,9 +1659,15 @@ M.Expression = ffi.metatype("Eolian_Expression", {
1656 __index = wrap_object { 1659 __index = wrap_object {
1657 eval = function(self, mask) 1660 eval = function(self, mask)
1658 mask = mask or emask.ALL 1661 mask = mask or emask.ALL
1659 local v = eolian.eolian_expression_eval(self, mask) 1662 local vsz = ffi.sizeof("Eolian_Value_t")
1660 if v == ffi.nullptr then return nil end 1663 local p = ffi.cast("Eolian_Value_t *", ffi.C.malloc(vsz))
1661 return ffi.cast("Eolian_Value*", v) 1664 if p == ffi.nullptr then return nil end
1665 local v = eolian.eolian_expression_eval_fill(self, mask, p)
1666 if v == 0 then
1667 ffi.C.free(p)
1668 return nil
1669 end
1670 return ffi.gc(ffi.cast("Eolian_Value *", p), ffi.C.free)
1662 end, 1671 end,
1663 1672
1664 serialize = function(self) 1673 serialize = function(self)
@@ -1698,9 +1707,15 @@ M.Expression = ffi.metatype("Eolian_Expression", {
1698 end, 1707 end,
1699 1708
1700 value_get = function(self) 1709 value_get = function(self)
1701 local v = eolian.eolian_expression_value_get(self) 1710 local vsz = ffi.sizeof("Eolian_Value_t")
1702 if v == ffi.nullptr then return nil end 1711 local p = ffi.cast("Eolian_Value_t *", ffi.C.malloc(vsz))
1703 return ffi.cast("Eolian_Value*", v) 1712 if p == ffi.nullptr then return nil end
1713 local v = eolian.eolian_expression_value_get_fill(self, p)
1714 if v == 0 then
1715 ffi.C.free(p)
1716 return nil
1717 end
1718 return ffi.gc(ffi.cast("Eolian_Value *", p), ffi.C.free)
1704 end 1719 end
1705 } 1720 }
1706}) 1721})