cedric pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=04090f3e7acef5ca47b7b44033dbf3312ae8b6d1

commit 04090f3e7acef5ca47b7b44033dbf3312ae8b6d1
Author: Cedric BAIL <cedric.b...@free.fr>
Date:   Fri Jan 4 16:01:40 2019 -0800

    eio: remove use of eina_promise_data_set.
    
    eina_promise_data_set is a misleading API and result in conflicted use by
    multiple independent piece of code leading to bug and crash. It is also not
    necessary and we can avoid using it completely.
    
    Reviewed-by: Mike Blumenkrantz <michael.blumenkra...@gmail.com>
    Differential Revision: https://phab.enlightenment.org/D7572
---
 src/lib/eio/efl_io_manager.c | 46 +++++++++++++++++---------------------------
 src/lib/eio/eio_model.c      | 23 ++++++++++++----------
 src/lib/eio/eio_private.h    | 16 ++++++++++++---
 3 files changed, 44 insertions(+), 41 deletions(-)

diff --git a/src/lib/eio/efl_io_manager.c b/src/lib/eio/efl_io_manager.c
index 9dcdfeeedf..110f01c87b 100644
--- a/src/lib/eio/efl_io_manager.c
+++ b/src/lib/eio/efl_io_manager.c
@@ -119,7 +119,7 @@ _efl_io_manager_direct_ls(const Eo *obj,
    Eina_Future *future;
    Eio_File *h;
 
-   p = eina_promise_new(efl_loop_future_scheduler_get(obj), 
_efl_io_manager_future_cancel, NULL);
+   p = efl_loop_promise_new(obj, NULL, NULL, NULL);
    if (!p) return NULL;
    future = eina_future_new(p);
 
@@ -143,9 +143,8 @@ _efl_io_manager_direct_ls(const Eo *obj,
 
    ecore_thread_local_data_add(h->thread, ".info", info, NULL, EINA_TRUE);
    ecore_thread_local_data_add(h->thread, ".info_data", info_data, 
info_free_cb, EINA_TRUE);
-   eina_promise_data_set(p, h);
 
-   return efl_future_then(obj, future);
+   return _efl_io_manager_future(obj, future, h);
 
  end:
    return future;
@@ -162,7 +161,7 @@ _efl_io_manager_stat_ls(const Eo *obj,
    Eina_Future *future;
    Eio_File *h;
 
-   p = eina_promise_new(efl_loop_future_scheduler_get(obj), 
_efl_io_manager_future_cancel, NULL);
+   p = efl_loop_promise_new(obj, NULL, NULL, NULL);
    if (!p) return NULL;
    future = eina_future_new(p);
 
@@ -186,9 +185,8 @@ _efl_io_manager_stat_ls(const Eo *obj,
 
    ecore_thread_local_data_add(h->thread, ".info", info, NULL, EINA_TRUE);
    ecore_thread_local_data_add(h->thread, ".info_data", info_data, 
info_free_cb, EINA_TRUE);
-   eina_promise_data_set(p, h);
 
-   return efl_future_then(obj, future);
+   return _efl_io_manager_future(obj, future, h);
 
  end:
    return future;
@@ -204,7 +202,7 @@ _efl_io_manager_ls(const Eo *obj,
    Eina_Future *future;
    Eio_File *h;
 
-   p = eina_promise_new(efl_loop_future_scheduler_get(obj), 
_efl_io_manager_future_cancel, NULL);
+   p = efl_loop_promise_new(obj, NULL, NULL, NULL);
    if (!p) return NULL;
    future = eina_future_new(p);
 
@@ -217,9 +215,8 @@ _efl_io_manager_ls(const Eo *obj,
 
    ecore_thread_local_data_add(h->thread, ".paths", paths, NULL, EINA_TRUE);
    ecore_thread_local_data_add(h->thread, ".paths_data", paths_data, 
paths_free_cb, EINA_TRUE);
-   eina_promise_data_set(p, h);
 
-   return efl_future_then(obj, future);
+   return _efl_io_manager_future(obj, future, h);
 
  end:
    return future;
@@ -256,7 +253,7 @@ _efl_io_manager_stat(const Eo *obj,
    Eina_Future *future;
    Eio_File *h;
 
-   p = eina_promise_new(efl_loop_future_scheduler_get(obj), 
_efl_io_manager_future_cancel, NULL);
+   p = efl_loop_promise_new(obj, NULL, NULL, NULL);
    if (!p) return NULL;
    future = eina_future_new(p);
 
@@ -265,9 +262,8 @@ _efl_io_manager_stat(const Eo *obj,
                             _future_file_error_cb,
                             p);
    if (!h) goto end;
-   eina_promise_data_set(p, h);
 
-   return efl_future_then(obj, future);
+   return _efl_io_manager_future(obj, future, h);
 
  end:
    return future;
@@ -285,7 +281,7 @@ _efl_io_manager_xattr_ls(const Eo *obj,
    Eina_Future *future;
    Eio_File *h;
 
-   p = eina_promise_new(efl_loop_future_scheduler_get(obj), 
_efl_io_manager_future_cancel, NULL);
+   p = efl_loop_promise_new(obj, NULL, NULL, NULL);
    if (!p) return NULL;
    future = eina_future_new(p);
 
@@ -299,9 +295,8 @@ _efl_io_manager_xattr_ls(const Eo *obj,
    // There is no race condition here as all the callback are called in the 
main loop after this
    ecore_thread_local_data_add(h->thread, ".paths", paths, NULL, EINA_TRUE);
    ecore_thread_local_data_add(h->thread, ".paths_data", paths_data, 
paths_free_cb, EINA_TRUE);
-   eina_promise_data_set(p, h);
 
-   return efl_future_then(obj, future);
+   return _efl_io_manager_future(obj, future, h);
 
  end:
    return efl_future_then(obj, future);;
@@ -336,7 +331,7 @@ _efl_io_manager_xattr_set(Eo *obj,
    Eina_Future *future;
    Eio_File *h;
 
-   p = eina_promise_new(efl_loop_future_scheduler_get(obj), 
_efl_io_manager_future_cancel, NULL);
+   p = efl_loop_promise_new(obj, NULL, NULL, NULL);
    if (!p) return NULL;
    future = eina_future_new(p);
 
@@ -348,9 +343,8 @@ _efl_io_manager_xattr_set(Eo *obj,
                           _future_file_error_cb,
                           p);
    if (!h) goto end;
-   eina_promise_data_set(p, h);
 
-   return efl_future_then(obj, future);
+   return _efl_io_manager_future(obj, future, h);
 
  end:
    return future;
@@ -366,7 +360,7 @@ _efl_io_manager_xattr_get(const Eo *obj,
    Eina_Future *future;
    Eio_File *h;
 
-   p = eina_promise_new(efl_loop_future_scheduler_get(obj), 
_efl_io_manager_future_cancel, NULL);
+   p = efl_loop_promise_new(obj, NULL, NULL, NULL);
    if (!p) return NULL;
    future = eina_future_new(p);
 
@@ -375,10 +369,8 @@ _efl_io_manager_xattr_get(const Eo *obj,
                           _future_file_error_cb,
                           p);
    if (!h) goto end;
-   eina_promise_data_set(p, h);
 
-   /* XXX const */
-   return efl_future_then((Eo *)obj, future);
+   return _efl_io_manager_future(obj, future, h);
 
  end:
    return future;
@@ -405,7 +397,7 @@ _efl_io_manager_open(const Eo *obj,
    Eina_Future *future;
    Eio_File *h;
 
-   p = eina_promise_new(efl_loop_future_scheduler_get(obj), 
_efl_io_manager_future_cancel, NULL);
+   p = efl_loop_promise_new(obj, NULL, NULL, NULL);
    if (!p) return NULL;
    future = eina_future_new(p);
 
@@ -414,9 +406,8 @@ _efl_io_manager_open(const Eo *obj,
                      _future_file_error_cb,
                      p);
    if (!h) goto end;
-   eina_promise_data_set(p, h);
 
-   return efl_future_then(obj, future);
+   return _efl_io_manager_future(obj, future, h);
 
  end:
    return future;
@@ -431,7 +422,7 @@ _efl_io_manager_close(const Eo *obj,
    Eina_Future *future;
    Eio_File *h;
 
-   p = eina_promise_new(efl_loop_future_scheduler_get(obj), 
_efl_io_manager_future_cancel, NULL);
+   p = efl_loop_promise_new(obj, NULL, NULL, NULL);
    if (!p) return NULL;
    future = eina_future_new(p);
 
@@ -440,9 +431,8 @@ _efl_io_manager_close(const Eo *obj,
                       _future_file_error_cb,
                       p);
    if (!h) goto end;
-   eina_promise_data_set(p, h);
 
-   return efl_future_then(obj, future);
+   return _efl_io_manager_future(obj, future, h);
 
  end:
    return future;
diff --git a/src/lib/eio/eio_model.c b/src/lib/eio/eio_model.c
index c6e03e663b..d080830ab6 100644
--- a/src/lib/eio/eio_model.c
+++ b/src/lib/eio/eio_model.c
@@ -406,10 +406,12 @@ _delayed_flush(void *data EINA_UNUSED, const Efl_Event 
*ev)
    efl_event_callback_del(ev->object, EFL_LOOP_EVENT_IDLE, _delayed_flush, 
NULL);
 }
 
-static void
-_cancel_request(void *data, const Eina_Promise *dead_ptr EINA_UNUSED)
+static Eina_Value
+_cancel_request(Efl_Loop *loop EINA_UNUSED, void *data, Eina_Error error)
 {
    delayed_queue = eina_list_remove_list(delayed_queue, data);
+
+   return eina_value_error_init(error);
 }
 
 static Eina_Future *
@@ -417,7 +419,7 @@ _build_delay(Efl_Loop *loop)
 {
    Eina_Promise *p;
 
-   p = eina_promise_new(efl_loop_future_scheduler_get(loop), _cancel_request, 
NULL);
+   p = eina_promise_new(efl_loop_future_scheduler_get(loop), NULL, NULL);
 
    if (!delayed_queue)
      {
@@ -428,9 +430,10 @@ _build_delay(Efl_Loop *loop)
      }
 
    delayed_queue = eina_list_append(delayed_queue, p);
-   eina_promise_data_set(p, eina_list_last(delayed_queue));
 
-   return eina_future_new(p);
+   return efl_future_then(loop, eina_future_new(p),
+                          .error = _cancel_request,
+                          .data = eina_list_last(delayed_queue));
 }
 
 static void
@@ -682,7 +685,7 @@ _eio_model_efl_model_property_set(Eo *obj,
 
    if (finalized)
      {
-        Eina_Promise *p = eina_promise_new(efl_loop_future_scheduler_get(obj), 
_efl_io_manager_future_cancel, NULL);
+        Eina_Promise *p = efl_loop_promise_new(obj, NULL, NULL, NULL);
         f = eina_future_new(p);
 
         pd->request.move = eio_file_move(pd->path, path,
@@ -690,17 +693,17 @@ _eio_model_efl_model_property_set(Eo *obj,
                                          _eio_move_done_cb, 
_eio_file_error_cb, p);
 
         ecore_thread_local_data_add(pd->request.move->thread, ".pd", pd, NULL, 
EINA_TRUE);
-        eina_promise_data_set(p, pd->request.move);
+
+        f = _efl_io_manager_future(obj, f, pd->request.move);
 
         // FIXME: turn on monitor in the finalize stage or after move
      }
    else
      {
-        f = efl_loop_future_resolved(obj,
-                                 eina_value_string_init(pd->path));
+        f = efl_loop_future_resolved(obj, eina_value_string_init(pd->path));
      }
 
-   return efl_future_then(obj, f);
+   return f;
 
  on_error:
    return efl_loop_future_rejected(obj, err);
diff --git a/src/lib/eio/eio_private.h b/src/lib/eio/eio_private.h
index 7e8656609a..a6cd4ccab5 100644
--- a/src/lib/eio/eio_private.h
+++ b/src/lib/eio/eio_private.h
@@ -545,10 +545,20 @@ Eio_File * _eio_file_xattr(const char *path,
 void _eio_string_notify(void *data, Ecore_Thread *thread EINA_UNUSED, void 
*msg_data);
 void _eio_direct_notify(void *data, Ecore_Thread *thread EINA_UNUSED, void 
*msg_data);
 
-static inline void
-_efl_io_manager_future_cancel(void *data, const Eina_Promise *dead_ptr 
EINA_UNUSED)
+static inline Eina_Value
+_efl_io_manager_future_cancel(Eo *o EINA_UNUSED, void *data, Eina_Error error)
 {
-   eio_file_cancel(data);
+   if (error == ECANCELED) eio_file_cancel(data);
+
+   return eina_value_error_init(error);
+}
+
+static inline Eina_Future *
+_efl_io_manager_future(const Eo *o, Eina_Future *f, Eio_File *h)
+{
+   return efl_future_then(o, f,
+                          .error = _efl_io_manager_future_cancel,
+                          .data = h);
 }
 
 EINA_VALUE_STRUCT_DESC_DEFINE(_eina_stat_desc,

-- 


Reply via email to