diff options
author | Jean-Philippe Andre <jp.andre@samsung.com> | 2017-09-06 21:26:57 +0900 |
---|---|---|
committer | Jean-Philippe Andre <jp.andre@samsung.com> | 2017-09-13 09:57:05 +0900 |
commit | d971ca2fb83faf5d6ddcbbb1f64a0ebaf69e8007 (patch) | |
tree | e08713b4953019fc63c67485d6407cb73d95c8a4 /src/lib/emotion/emotion_smart.c | |
parent | 820b8a0e6f65642c2cfd4196f8d08fe444bce310 (diff) |
emotion: Fix refcounts related to eio use
Inside emotion, if Eio is compiled, some asynchronous functions are used
and a refcounted struct was used to ensure safety of the code.
Unfortunately the logic didn't make much sense as emotion's private data
is used. The refcount becomes useless, the lifecycle of the data being
bound to the object itself.
Note that an actual crash is almost impossible because:
- eio is actually quite fast
- evas objects are kept alive for 2 frames
- eina_freeq is used to keep eo objects' data alive for some more time
But this in theory fixes the events, as they were sent on the wrong
object. "obj" is the image object, "smartobj" was the emotion object.
This is fixed with a weak ref.
I don't think it is necessary to backport this.
Diffstat (limited to 'src/lib/emotion/emotion_smart.c')
-rw-r--r-- | src/lib/emotion/emotion_smart.c | 189 |
1 files changed, 78 insertions, 111 deletions
diff --git a/src/lib/emotion/emotion_smart.c b/src/lib/emotion/emotion_smart.c index b2a7370..064ca23 100644 --- a/src/lib/emotion/emotion_smart.c +++ b/src/lib/emotion/emotion_smart.c | |||
@@ -56,29 +56,24 @@ | |||
56 | #define MY_CLASS EFL_CANVAS_VIDEO_CLASS | 56 | #define MY_CLASS EFL_CANVAS_VIDEO_CLASS |
57 | 57 | ||
58 | typedef struct _Efl_Canvas_Video_Data Efl_Canvas_Video_Data; | 58 | typedef struct _Efl_Canvas_Video_Data Efl_Canvas_Video_Data; |
59 | typedef struct _Emotion_Xattr_Data Emotion_Xattr_Data; | ||
59 | 60 | ||
60 | struct _Efl_Canvas_Video_Data | 61 | struct _Efl_Canvas_Video_Data |
61 | { | 62 | { |
62 | EINA_REFCOUNT; | ||
63 | Emotion_Engine_Instance *engine_instance; | 63 | Emotion_Engine_Instance *engine_instance; |
64 | 64 | ||
65 | const char *engine; | 65 | const char *engine; |
66 | const char *file; | 66 | const char *file; |
67 | Evas_Object *smartobj; | ||
68 | Evas_Object *obj; | 67 | Evas_Object *obj; |
69 | Evas_Object *bg; | 68 | Evas_Object *bg; |
70 | 69 | ||
71 | Ecore_Job *job; | 70 | Ecore_Job *job; |
72 | 71 | ||
73 | Efl_Vpath_File *file_obj; | 72 | Efl_Vpath_File *file_obj; |
73 | Emotion_Xattr_Data *xattr; | ||
74 | 74 | ||
75 | const char *title; | 75 | const char *title; |
76 | 76 | ||
77 | #ifdef HAVE_EIO | ||
78 | Eio_File *load_xattr; | ||
79 | Eio_File *save_xattr; | ||
80 | #endif | ||
81 | |||
82 | struct { | 77 | struct { |
83 | const char *info; | 78 | const char *info; |
84 | double stat; | 79 | double stat; |
@@ -126,6 +121,16 @@ struct _Efl_Canvas_Video_Data | |||
126 | Eina_Bool seeking : 1; | 121 | Eina_Bool seeking : 1; |
127 | }; | 122 | }; |
128 | 123 | ||
124 | struct _Emotion_Xattr_Data | ||
125 | { | ||
126 | EINA_REFCOUNT; | ||
127 | Eo *obj_wref; | ||
128 | #ifdef HAVE_EIO | ||
129 | Eio_File *load; | ||
130 | Eio_File *save; | ||
131 | #endif | ||
132 | }; | ||
133 | |||
129 | static void _mouse_move(void *data, Evas *ev, Evas_Object *obj, void *event_info); | 134 | static void _mouse_move(void *data, Evas *ev, Evas_Object *obj, void *event_info); |
130 | static void _mouse_down(void *data, Evas *ev, Evas_Object *obj, void *event_info); | 135 | static void _mouse_down(void *data, Evas *ev, Evas_Object *obj, void *event_info); |
131 | static void _pos_set_job(void *data); | 136 | static void _pos_set_job(void *data); |
@@ -163,48 +168,26 @@ _emotion_image_data_zero(Evas_Object *img) | |||
163 | } | 168 | } |
164 | 169 | ||
165 | static void | 170 | static void |
166 | _smart_data_free(Efl_Canvas_Video_Data *sd) | 171 | _xattr_data_cancel(Emotion_Xattr_Data *xattr) |
167 | { | 172 | { |
173 | (void) xattr; | ||
168 | #ifdef HAVE_EIO | 174 | #ifdef HAVE_EIO |
169 | /* Only cancel the load_xattr or we will loose ref to time_seek stringshare */ | 175 | /* Only cancel the load_xattr or we will loose ref to time_seek stringshare */ |
170 | if (sd->load_xattr) eio_file_cancel(sd->load_xattr); | 176 | if (xattr->load) eio_file_cancel(xattr->load); |
171 | sd->load_xattr = NULL; | 177 | xattr->load = NULL; |
172 | if (sd->save_xattr) eio_file_cancel(sd->save_xattr); | 178 | if (xattr->save) eio_file_cancel(xattr->save); |
173 | sd->save_xattr = NULL; | 179 | xattr->save = NULL; |
174 | #endif | 180 | #endif |
181 | } | ||
175 | 182 | ||
176 | if (sd->file_obj) | 183 | static void |
177 | { | 184 | _xattr_data_unref(Emotion_Xattr_Data *xattr) |
178 | efl_del(sd->file_obj); | 185 | { |
179 | sd->file_obj = NULL; | 186 | EINA_REFCOUNT_UNREF(xattr) {} else return; |
180 | } | ||
181 | if (sd->engine_instance) | ||
182 | { | ||
183 | emotion_engine_instance_file_close(sd->engine_instance); | ||
184 | emotion_engine_instance_del(sd->engine_instance); | ||
185 | sd->engine_instance = NULL; | ||
186 | } | ||
187 | if (sd->obj) evas_object_del(sd->obj); | ||
188 | sd->obj = NULL; | ||
189 | if (sd->crop.clipper) evas_object_del(sd->crop.clipper); | ||
190 | sd->crop.clipper = NULL; | ||
191 | if (sd->bg) evas_object_del(sd->bg); | ||
192 | sd->bg = NULL; | ||
193 | if (sd->file) eina_stringshare_del(sd->file); | ||
194 | sd->file = NULL; | ||
195 | if (sd->job) ecore_job_del(sd->job); | ||
196 | sd->job = NULL; | ||
197 | if (sd->anim) ecore_animator_del(sd->anim); | ||
198 | sd->anim = NULL; | ||
199 | eina_stringshare_del(sd->progress.info); | ||
200 | sd->progress.info = NULL; | ||
201 | eina_stringshare_del(sd->ref.file); | ||
202 | sd->ref.file = NULL; | ||
203 | if (sd->engine) eina_stringshare_del(sd->engine); | ||
204 | sd->engine = NULL; | ||
205 | 187 | ||
206 | /* TODO: remove legacy: emotion used to have no shutdown, call automatically */ | 188 | _xattr_data_cancel(xattr); |
207 | emotion_shutdown(); | 189 | efl_wref_del_safe(&xattr->obj_wref); |
190 | free(xattr); | ||
208 | } | 191 | } |
209 | 192 | ||
210 | static void | 193 | static void |
@@ -264,9 +247,7 @@ _efl_canvas_video_efl_object_constructor(Eo *obj, Efl_Canvas_Video_Data *pd EINA | |||
264 | EAPI Evas_Object * | 247 | EAPI Evas_Object * |
265 | emotion_object_image_get(const Evas_Object *obj) | 248 | emotion_object_image_get(const Evas_Object *obj) |
266 | { | 249 | { |
267 | Efl_Canvas_Video_Data *sd; | 250 | Efl_Canvas_Video_Data *sd = efl_data_scope_safe_get(obj, MY_CLASS); |
268 | |||
269 | sd = evas_object_smart_data_get(obj); | ||
270 | if (!sd) return NULL; | 251 | if (!sd) return NULL; |
271 | return sd->obj; | 252 | return sd->obj; |
272 | } | 253 | } |
@@ -436,13 +417,7 @@ _efl_canvas_video_efl_file_file_set(Eo *obj EINA_UNUSED, Efl_Canvas_Video_Data * | |||
436 | if (sd->anim) ecore_animator_del(sd->anim); | 417 | if (sd->anim) ecore_animator_del(sd->anim); |
437 | sd->anim = NULL; | 418 | sd->anim = NULL; |
438 | 419 | ||
439 | #ifdef HAVE_EIO | 420 | _xattr_data_cancel(sd->xattr); |
440 | /* Only cancel the load_xattr or we will loose ref to time_seek stringshare */ | ||
441 | if (sd->load_xattr) eio_file_cancel(sd->load_xattr); | ||
442 | sd->load_xattr = NULL; | ||
443 | if (sd->save_xattr) eio_file_cancel(sd->save_xattr); | ||
444 | sd->save_xattr = NULL; | ||
445 | #endif | ||
446 | 421 | ||
447 | return EINA_TRUE; | 422 | return EINA_TRUE; |
448 | } | 423 | } |
@@ -1359,37 +1334,31 @@ emotion_object_priority_get(const Evas_Object *obj) | |||
1359 | 1334 | ||
1360 | #ifdef HAVE_EIO | 1335 | #ifdef HAVE_EIO |
1361 | static void | 1336 | static void |
1362 | _eio_load_xattr_cleanup(Efl_Canvas_Video_Data *sd, Eio_File *handler) | 1337 | _eio_load_xattr_cleanup(Emotion_Xattr_Data *xattr, Eio_File *handler) |
1363 | { | 1338 | { |
1364 | if (handler == sd->load_xattr) sd->load_xattr = NULL; | 1339 | if (handler == xattr->load) xattr->load = NULL; |
1365 | 1340 | _xattr_data_unref(xattr); | |
1366 | EINA_REFCOUNT_UNREF(sd) | ||
1367 | { | ||
1368 | if (sd->smartobj) evas_object_smart_data_set(sd->smartobj, NULL); | ||
1369 | sd->smartobj = NULL; | ||
1370 | _smart_data_free(sd); | ||
1371 | } | ||
1372 | } | 1341 | } |
1373 | 1342 | ||
1374 | static void | 1343 | static void |
1375 | _eio_load_xattr_done(void *data, Eio_File *handler, double xattr_double) | 1344 | _eio_load_xattr_done(void *data, Eio_File *handler, double xattr_double) |
1376 | { | 1345 | { |
1377 | Efl_Canvas_Video_Data *sd = data; | 1346 | Emotion_Xattr_Data *xattr = data; |
1378 | 1347 | ||
1379 | emotion_object_position_set(evas_object_smart_parent_get(sd->obj), xattr_double); | 1348 | emotion_object_position_set(evas_object_smart_parent_get(xattr->obj_wref), xattr_double); |
1380 | efl_event_callback_call(evas_object_smart_parent_get(sd->obj), EFL_CANVAS_VIDEO_EVENT_POSITION_LOAD_DONE, NULL); | 1349 | efl_event_callback_call(evas_object_smart_parent_get(xattr->obj_wref), EFL_CANVAS_VIDEO_EVENT_POSITION_LOAD_DONE, NULL); |
1381 | evas_object_smart_callback_call(evas_object_smart_parent_get(sd->obj), "position_load,succeed", NULL); | 1350 | evas_object_smart_callback_call(evas_object_smart_parent_get(xattr->obj_wref), "position_load,succeed", NULL); |
1382 | _eio_load_xattr_cleanup(sd, handler); | 1351 | _eio_load_xattr_cleanup(xattr, handler); |
1383 | } | 1352 | } |
1384 | 1353 | ||
1385 | static void | 1354 | static void |
1386 | _eio_load_xattr_error(void *data, Eio_File *handler, int err EINA_UNUSED) | 1355 | _eio_load_xattr_error(void *data, Eio_File *handler, int err EINA_UNUSED) |
1387 | { | 1356 | { |
1388 | Efl_Canvas_Video_Data *sd = data; | 1357 | Emotion_Xattr_Data *xattr = data; |
1389 | 1358 | ||
1390 | efl_event_callback_call(evas_object_smart_parent_get(sd->obj), EFL_CANVAS_VIDEO_EVENT_POSITION_LOAD_FAIL, NULL); | 1359 | efl_event_callback_call(evas_object_smart_parent_get(xattr->obj_wref), EFL_CANVAS_VIDEO_EVENT_POSITION_LOAD_FAIL, NULL); |
1391 | evas_object_smart_callback_call(evas_object_smart_parent_get(sd->obj), "position_load,failed", NULL); | 1360 | evas_object_smart_callback_call(evas_object_smart_parent_get(xattr->obj_wref), "position_load,failed", NULL); |
1392 | _eio_load_xattr_cleanup(sd, handler); | 1361 | _eio_load_xattr_cleanup(xattr, handler); |
1393 | } | 1362 | } |
1394 | #endif | 1363 | #endif |
1395 | 1364 | ||
@@ -1410,15 +1379,16 @@ emotion_object_last_position_load(Evas_Object *obj) | |||
1410 | else return; | 1379 | else return; |
1411 | 1380 | ||
1412 | #ifdef HAVE_EIO | 1381 | #ifdef HAVE_EIO |
1413 | if (sd->load_xattr) return; | 1382 | Emotion_Xattr_Data *xattr = sd->xattr; |
1414 | 1383 | ||
1415 | EINA_REFCOUNT_REF(sd); | 1384 | if (xattr->load) return; |
1385 | EINA_REFCOUNT_REF(xattr); | ||
1416 | 1386 | ||
1417 | sd->load_xattr = eio_file_xattr_double_get(tmp, | 1387 | xattr->load = eio_file_xattr_double_get(tmp, |
1418 | "user.e.time_seek", | 1388 | "user.e.time_seek", |
1419 | _eio_load_xattr_done, | 1389 | _eio_load_xattr_done, |
1420 | _eio_load_xattr_error, | 1390 | _eio_load_xattr_error, |
1421 | sd); | 1391 | xattr); |
1422 | #else | 1392 | #else |
1423 | if (eina_xattr_double_get(tmp, "user.e.time_seek", &xattr)) | 1393 | if (eina_xattr_double_get(tmp, "user.e.time_seek", &xattr)) |
1424 | { | 1394 | { |
@@ -1436,36 +1406,30 @@ emotion_object_last_position_load(Evas_Object *obj) | |||
1436 | 1406 | ||
1437 | #ifdef HAVE_EIO | 1407 | #ifdef HAVE_EIO |
1438 | static void | 1408 | static void |
1439 | _eio_save_xattr_cleanup(Efl_Canvas_Video_Data *sd, Eio_File *handler) | 1409 | _eio_save_xattr_cleanup(Emotion_Xattr_Data *xattr, Eio_File *handler) |
1440 | { | 1410 | { |
1441 | if (handler == sd->save_xattr) sd->save_xattr = NULL; | 1411 | if (handler == xattr->save) xattr->save = NULL; |
1442 | 1412 | _xattr_data_unref(xattr); | |
1443 | EINA_REFCOUNT_UNREF(sd) | ||
1444 | { | ||
1445 | if (sd->smartobj) evas_object_smart_data_set(sd->smartobj, NULL); | ||
1446 | sd->smartobj = NULL; | ||
1447 | _smart_data_free(sd); | ||
1448 | } | ||
1449 | } | 1413 | } |
1450 | 1414 | ||
1451 | static void | 1415 | static void |
1452 | _eio_save_xattr_done(void *data, Eio_File *handler) | 1416 | _eio_save_xattr_done(void *data, Eio_File *handler) |
1453 | { | 1417 | { |
1454 | Efl_Canvas_Video_Data *sd = data; | 1418 | Emotion_Xattr_Data *xattr = data; |
1455 | 1419 | ||
1456 | efl_event_callback_call(sd->obj, EFL_CANVAS_VIDEO_EVENT_POSITION_SAVE_DONE, NULL); | 1420 | efl_event_callback_call(xattr->obj_wref, EFL_CANVAS_VIDEO_EVENT_POSITION_SAVE_DONE, NULL); |
1457 | evas_object_smart_callback_call(sd->obj, "position_save,succeed", NULL); | 1421 | evas_object_smart_callback_call(xattr->obj_wref, "position_save,succeed", NULL); |
1458 | _eio_save_xattr_cleanup(sd, handler); | 1422 | _eio_save_xattr_cleanup(xattr, handler); |
1459 | } | 1423 | } |
1460 | 1424 | ||
1461 | static void | 1425 | static void |
1462 | _eio_save_xattr_error(void *data, Eio_File *handler, int err EINA_UNUSED) | 1426 | _eio_save_xattr_error(void *data, Eio_File *handler, int err EINA_UNUSED) |
1463 | { | 1427 | { |
1464 | Efl_Canvas_Video_Data *sd = data; | 1428 | Emotion_Xattr_Data *xattr = data; |
1465 | 1429 | ||
1466 | efl_event_callback_call(sd->obj, EFL_CANVAS_VIDEO_EVENT_POSITION_SAVE_FAIL, NULL); | 1430 | efl_event_callback_call(xattr->obj_wref, EFL_CANVAS_VIDEO_EVENT_POSITION_SAVE_FAIL, NULL); |
1467 | evas_object_smart_callback_call(sd->obj, "position_save,failed", NULL); | 1431 | evas_object_smart_callback_call(xattr->obj_wref, "position_save,failed", NULL); |
1468 | _eio_save_xattr_cleanup(sd, handler); | 1432 | _eio_save_xattr_cleanup(xattr, handler); |
1469 | } | 1433 | } |
1470 | #endif | 1434 | #endif |
1471 | 1435 | ||
@@ -1482,16 +1446,18 @@ emotion_object_last_position_save(Evas_Object *obj) | |||
1482 | else if (!strstr(sd->file, "://")) tmp = sd->file; | 1446 | else if (!strstr(sd->file, "://")) tmp = sd->file; |
1483 | else return; | 1447 | else return; |
1484 | #ifdef HAVE_EIO | 1448 | #ifdef HAVE_EIO |
1485 | if (sd->save_xattr) return; | 1449 | Emotion_Xattr_Data *xattr = sd->xattr; |
1486 | 1450 | ||
1487 | EINA_REFCOUNT_REF(sd); | 1451 | if (xattr->save) return; |
1488 | sd->save_xattr = eio_file_xattr_double_set(tmp, | 1452 | EINA_REFCOUNT_REF(xattr); |
1489 | "user.e.time_seek", | 1453 | |
1490 | emotion_object_position_get(obj), | 1454 | xattr->save = eio_file_xattr_double_set(tmp, |
1491 | 0, | 1455 | "user.e.time_seek", |
1492 | _eio_save_xattr_done, | 1456 | emotion_object_position_get(obj), |
1493 | _eio_save_xattr_error, | 1457 | 0, |
1494 | sd); | 1458 | _eio_save_xattr_done, |
1459 | _eio_save_xattr_error, | ||
1460 | xattr); | ||
1495 | #else | 1461 | #else |
1496 | if (eina_xattr_double_set(tmp, "user.e.time_seek", emotion_object_position_get(obj), 0)) | 1462 | if (eina_xattr_double_set(tmp, "user.e.time_seek", emotion_object_position_get(obj), 0)) |
1497 | { | 1463 | { |
@@ -1933,14 +1899,13 @@ _pixels_get(void *data, Evas_Object *obj) | |||
1933 | EOLIAN static void | 1899 | EOLIAN static void |
1934 | _efl_canvas_video_efl_canvas_group_group_add(Evas_Object *obj, Efl_Canvas_Video_Data *sd) | 1900 | _efl_canvas_video_efl_canvas_group_group_add(Evas_Object *obj, Efl_Canvas_Video_Data *sd) |
1935 | { | 1901 | { |
1902 | Emotion_Xattr_Data *xattr; | ||
1936 | unsigned int *pixel; | 1903 | unsigned int *pixel; |
1937 | 1904 | ||
1938 | /* TODO: remove legacy: emotion used to have no init, call automatically */ | 1905 | /* TODO: remove legacy: emotion used to have no init, call automatically */ |
1939 | emotion_init(); | 1906 | emotion_init(); |
1940 | 1907 | ||
1941 | EINA_REFCOUNT_INIT(sd); | ||
1942 | sd->state = EMOTION_WAKEUP; | 1908 | sd->state = EMOTION_WAKEUP; |
1943 | sd->smartobj = obj; | ||
1944 | sd->obj = evas_object_image_add(evas_object_evas_get(obj)); | 1909 | sd->obj = evas_object_image_add(evas_object_evas_get(obj)); |
1945 | sd->bg = evas_object_rectangle_add(evas_object_evas_get(obj)); | 1910 | sd->bg = evas_object_rectangle_add(evas_object_evas_get(obj)); |
1946 | sd->engine = eina_stringshare_add("gstreamer1"); | 1911 | sd->engine = eina_stringshare_add("gstreamer1"); |
@@ -1962,7 +1927,11 @@ _efl_canvas_video_efl_canvas_group_group_add(Evas_Object *obj, Efl_Canvas_Video_ | |||
1962 | *pixel = 0xff000000; | 1927 | *pixel = 0xff000000; |
1963 | evas_object_image_data_set(obj, pixel); | 1928 | evas_object_image_data_set(obj, pixel); |
1964 | } | 1929 | } |
1965 | evas_object_smart_data_set(obj, sd); | 1930 | |
1931 | xattr = calloc(1, sizeof(*xattr)); | ||
1932 | EINA_REFCOUNT_INIT(xattr); | ||
1933 | efl_wref_add(obj, &xattr->obj_wref); | ||
1934 | sd->xattr = xattr; | ||
1966 | } | 1935 | } |
1967 | 1936 | ||
1968 | EOLIAN static void | 1937 | EOLIAN static void |
@@ -1990,9 +1959,7 @@ _efl_canvas_video_efl_canvas_group_group_del(Evas_Object *obj EINA_UNUSED, Efl_C | |||
1990 | sd->progress.info = NULL; | 1959 | sd->progress.info = NULL; |
1991 | eina_stringshare_del(sd->ref.file); | 1960 | eina_stringshare_del(sd->ref.file); |
1992 | sd->ref.file = NULL; | 1961 | sd->ref.file = NULL; |
1993 | if (sd->smartobj) evas_object_smart_data_set(sd->smartobj, NULL); | 1962 | _xattr_data_unref(sd->xattr); |
1994 | sd->smartobj = NULL; | ||
1995 | EINA_REFCOUNT_UNREF(sd) _smart_data_free(sd); | ||
1996 | efl_canvas_group_del(efl_super(obj, MY_CLASS)); | 1963 | efl_canvas_group_del(efl_super(obj, MY_CLASS)); |
1997 | } | 1964 | } |
1998 | 1965 | ||