summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCedric BAIL <cedric.bail@free.fr>2019-02-23 08:57:10 -0500
committerMike Blumenkrantz <zmike@samsung.com>2019-02-23 08:57:10 -0500
commit790fc1b8c5ce819dc7e17063baad52968b0c6706 (patch)
treee139ec0b27e6f46e703240c6fe4c3f10e49544b0 /src
parent7943a69b0df744183450a48eca0f818d748c2875 (diff)
ecore: enforce proper lifecycle for all Efl.Composite_Model children.
Summary: This make sure that the object returned by children_slice_get are properly destroyed when the refcount drop to only the parent holding a reference on it. This make it clear that the user of the api can rely on efl_ref/efl_unref to actually manage its use of the returned object. Reviewers: felipealmeida, segfaultxavi, SanghyeonLee, zmike, bu5hm4n Reviewed By: segfaultxavi, zmike Subscribers: #reviewers, #committers Tags: #efl Maniphest Tasks: T7528 Differential Revision: https://phab.enlightenment.org/D7864
Diffstat (limited to 'src')
-rw-r--r--src/lib/ecore/efl_composite_model.c9
-rw-r--r--src/lib/ecore/efl_select_model.c35
2 files changed, 32 insertions, 12 deletions
diff --git a/src/lib/ecore/efl_composite_model.c b/src/lib/ecore/efl_composite_model.c
index 1eea0cbd28..8c511c651e 100644
--- a/src/lib/ecore/efl_composite_model.c
+++ b/src/lib/ecore/efl_composite_model.c
@@ -193,11 +193,14 @@ _efl_composite_model_then(Eo *o EINA_UNUSED, void *data, const Eina_Value v)
193 193
194 // First set the Model to be used as a source so that we the newly object 194 // First set the Model to be used as a source so that we the newly object
195 // can know if it needs to retain the information regarding its index. 195 // can know if it needs to retain the information regarding its index.
196 composite = efl_add(req->self, req->parent, 196 composite = efl_add_ref(req->self, req->parent,
197 efl_ui_view_model_set(efl_added, target), 197 efl_ui_view_model_set(efl_added, target),
198 efl_composite_model_index_set(efl_added, req->start + i)); 198 efl_composite_model_index_set(efl_added, req->start + i),
199 efl_loop_model_volatile_make(efl_added));
199 200
200 eina_value_array_append(&r, composite); 201 eina_value_array_append(&r, composite);
202 // Dropping this scope reference
203 efl_unref(composite);
201 } 204 }
202 205
203 return r; 206 return r;
diff --git a/src/lib/ecore/efl_select_model.c b/src/lib/ecore/efl_select_model.c
index 75b11bde4d..52100e681c 100644
--- a/src/lib/ecore/efl_select_model.c
+++ b/src/lib/ecore/efl_select_model.c
@@ -88,7 +88,7 @@ _clear_child(Eo *child,
88 void *data EINA_UNUSED, 88 void *data EINA_UNUSED,
89 const Eina_Future *dead_future EINA_UNUSED) 89 const Eina_Future *dead_future EINA_UNUSED)
90{ 90{
91 efl_del(child); 91 efl_unref(child);
92} 92}
93 93
94static Efl_Model * 94static Efl_Model *
@@ -125,7 +125,9 @@ _check_child_change(Efl_Model *child, Eina_Bool value)
125 else 125 else
126 { 126 {
127 r = efl_model_property_set(child, "selected", eina_value_bool_new(!!value)); 127 r = efl_model_property_set(child, "selected", eina_value_bool_new(!!value));
128 r = efl_future_then(child, r, .success = _commit_change, .free = _clear_child); 128 r = efl_future_then(efl_ref(child), r,
129 .success = _commit_change,
130 .free = _clear_child);
129 } 131 }
130 132
131 return r; 133 return r;
@@ -229,6 +231,15 @@ _untangle_error(void *data, Eina_Error err)
229 return eina_future_as_value(f); 231 return eina_future_as_value(f);
230} 232}
231 233
234static void
235_untangle_free(void *data,
236 const Eina_Future *dead_future EINA_UNUSED)
237{
238 Eo *obj = data;
239
240 efl_unref(obj);
241}
242
232static Eina_Iterator * 243static Eina_Iterator *
233_efl_select_model_efl_model_properties_get(const Eo *obj, 244_efl_select_model_efl_model_properties_get(const Eo *obj,
234 Efl_Select_Model_Data *pd EINA_UNUSED) 245 Efl_Select_Model_Data *pd EINA_UNUSED)
@@ -271,9 +282,10 @@ _efl_select_model_efl_model_property_set(Eo *obj,
271 if (!eina_value_ulong_convert(value, &l)) 282 if (!eina_value_ulong_convert(value, &l))
272 return efl_loop_future_rejected(obj, EFL_MODEL_ERROR_INCORRECT_VALUE); 283 return efl_loop_future_rejected(obj, EFL_MODEL_ERROR_INCORRECT_VALUE);
273 284
274 return efl_future_then(obj, efl_model_children_slice_get(obj, l, 1), 285 return efl_future_then(efl_ref(obj), efl_model_children_slice_get(obj, l, 1),
275 .success = _select_slice_then, 286 .success = _select_slice_then,
276 .success_type = EINA_VALUE_TYPE_ARRAY); 287 .success_type = EINA_VALUE_TYPE_ARRAY,
288 .free = _clear_child);
277 } 289 }
278 290
279 if (pd->parent && !strcmp("self.selected", property)) 291 if (pd->parent && !strcmp("self.selected", property))
@@ -326,18 +338,23 @@ _efl_select_model_efl_model_property_set(Eo *obj,
326 // There was, need to unselect the previous one along setting the new value 338 // There was, need to unselect the previous one along setting the new value
327 parent = efl_parent_get(obj); 339 parent = efl_parent_get(obj);
328 chain = eina_future_all(chain, 340 chain = eina_future_all(chain,
329 efl_future_then(parent, efl_model_children_slice_get(parent, selected, 1), 341 efl_future_then(efl_ref(parent),
342 efl_model_children_slice_get(parent, selected, 1),
330 .success = _unselect_slice_then, 343 .success = _unselect_slice_then,
331 .success_type = EINA_VALUE_TYPE_ARRAY)); 344 .success_type = EINA_VALUE_TYPE_ARRAY,
345 .free = _clear_child));
332 chain = eina_future_then_easy(chain, 346 chain = eina_future_then_easy(chain,
333 .success_type = EINA_VALUE_TYPE_ARRAY, 347 .success_type = EINA_VALUE_TYPE_ARRAY,
334 .success = _untangle_array, 348 .success = _untangle_array,
335 .data = obj, 349 .data = efl_ref(obj),
336 .error = _untangle_error); 350 .error = _untangle_error,
351 .free = _untangle_free);
337 } 352 }
338 } 353 }
339 354
340 return efl_future_then(obj, chain, .success = _commit_change); 355 return efl_future_then(efl_ref(obj), chain,
356 .success = _commit_change,
357 .free = _clear_child);
341 } 358 }
342 359
343 return efl_model_property_set(efl_super(obj, EFL_SELECT_MODEL_CLASS), 360 return efl_model_property_set(efl_super(obj, EFL_SELECT_MODEL_CLASS),