summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Kolesa <d.kolesa@samsung.com>2019-01-29 20:37:11 +0100
committerDaniel Kolesa <d.kolesa@samsung.com>2019-02-28 01:09:02 +0100
commit4cbc010d8fefe25a390a4d4cfe5bdcbe77e9ff73 (patch)
tree9797f1c79e580e78b9890c5967f32977d210100f
parent6609a0d17ee6995fc07cd4ce7cea94f6aae5d9da (diff)
eolian_gen: better freeing for inarray
This one will only loop the inarray if it contains a struct with owned fields, however it will not do iterative free for container fields in that kind of struct. That may be added later, or Eolian might be restricted further.
-rw-r--r--src/bin/eolian/sources.c63
1 files changed, 57 insertions, 6 deletions
diff --git a/src/bin/eolian/sources.c b/src/bin/eolian/sources.c
index 352bbc60be..e9da5b294d 100644
--- a/src/bin/eolian/sources.c
+++ b/src/bin/eolian/sources.c
@@ -242,6 +242,53 @@ _generate_loop_content(Eina_Strbuf **buf, const Eolian_Type *inner_type, const E
242 eina_strbuf_append(*buf, " }\n"); 242 eina_strbuf_append(*buf, " }\n");
243} 243}
244 244
245static const Eolian_Typedecl *
246_have_struct_owned_fields(const Eolian_Type *tp)
247{
248 const Eolian_Type *btp = eolian_type_aliased_base_get(tp);
249 const Eolian_Typedecl *tdecl = eolian_type_typedecl_get(btp);
250 if (!tdecl || eolian_typedecl_type_get(tdecl) != EOLIAN_TYPEDECL_STRUCT)
251 return NULL;
252
253 Eina_Iterator *itr = eolian_typedecl_struct_fields_get(tdecl);
254 const Eolian_Struct_Type_Field *sf;
255 EINA_ITERATOR_FOREACH(itr, sf)
256 {
257 const Eolian_Type *ftp = eolian_typedecl_struct_field_type_get(sf);
258 if (eolian_type_is_owned(ftp))
259 {
260 eina_iterator_free(itr);
261 return tdecl;
262 }
263 }
264 eina_iterator_free(itr);
265 return NULL;
266}
267
268static void
269_generate_inarray_loop(Eina_Strbuf **buf, const Eolian_Typedecl *tdecl,
270 const Eina_Strbuf *iter_param)
271{
272 eina_strbuf_append(*buf, " {\n");
273 Eina_Iterator *itr = eolian_typedecl_struct_fields_get(tdecl);
274 const Eolian_Struct_Type_Field *sf;
275 Eina_Strbuf *fldbuf = eina_strbuf_new();
276 EINA_ITERATOR_FOREACH(itr, sf)
277 {
278 const Eolian_Type *ftp = eolian_typedecl_struct_field_type_get(sf);
279 if (!eolian_type_is_owned(ftp))
280 continue;
281 eina_strbuf_reset(fldbuf);
282 eina_strbuf_append_buffer(fldbuf, iter_param);
283 eina_strbuf_append(fldbuf, "->");
284 eina_strbuf_append(fldbuf, eolian_typedecl_struct_field_name_get(sf));
285 _generate_normal_free(buf, ftp, fldbuf, " ");
286 }
287 eina_strbuf_free(fldbuf);
288 eina_iterator_free(itr);
289 eina_strbuf_append(*buf, " }\n");
290}
291
245static void 292static void
246_generate_iterative_free(Eina_Strbuf **buf, const Eolian_Type *type, const Eolian_Type *inner_type, Eolian_Function_Parameter *parameter, Eina_Strbuf *param) 293_generate_iterative_free(Eina_Strbuf **buf, const Eolian_Type *type, const Eolian_Type *inner_type, Eolian_Function_Parameter *parameter, Eina_Strbuf *param)
247{ 294{
@@ -276,12 +323,16 @@ _generate_iterative_free(Eina_Strbuf **buf, const Eolian_Type *type, const Eolia
276 } 323 }
277 else if (t == EOLIAN_TYPE_BUILTIN_INARRAY) 324 else if (t == EOLIAN_TYPE_BUILTIN_INARRAY)
278 { 325 {
279 eina_strbuf_append_printf(*buf, " EINA_INARRAY_FOREACH("); 326 const Eolian_Typedecl *ts = _have_struct_owned_fields(inner_type);
280 eina_strbuf_append_buffer(*buf, param); 327 if (ts)
281 eina_strbuf_append_char(*buf, ','); 328 {
282 eina_strbuf_append_buffer(*buf, iter_param); 329 eina_strbuf_append_printf(*buf, " EINA_INARRAY_FOREACH(");
283 eina_strbuf_append(*buf, ")\n"); 330 eina_strbuf_append_buffer(*buf, param);
284 _generate_loop_content(buf, inner_type, iter_param); 331 eina_strbuf_append_char(*buf, ',');
332 eina_strbuf_append_buffer(*buf, iter_param);
333 eina_strbuf_append(*buf, ")\n");
334 _generate_inarray_loop(buf, ts, iter_param);
335 }
285 _write_free_call(*buf, "eina_inarray_free", param, ""); 336 _write_free_call(*buf, "eina_inarray_free", param, "");
286 } 337 }
287 else if (t == EOLIAN_TYPE_BUILTIN_INLIST) 338 else if (t == EOLIAN_TYPE_BUILTIN_INLIST)