Revert "Revert "Eo: Move eo_add_ref logic inside the library.""
authorTom Hacohen <tom@stosb.com>
Fri, 10 Oct 2014 08:30:52 +0000 (09:30 +0100)
committerTom Hacohen <tom@stosb.com>
Fri, 10 Oct 2014 08:30:52 +0000 (09:30 +0100)
This reverts commit 11da9421842c439474ea08b346cdb1ee986db361.

Can't reproduce with the non-existent bug report, thus have no choice
but consider it as working.

src/lib/eo/Eo.h
src/lib/eo/eo.c

index b280797..8c26d6e 100644 (file)
@@ -636,7 +636,7 @@ EAPI void eo_error_set_internal(const Eo *obj, const char *file, int line);
 #define eo_add(klass, parent, ...) \
    ({ \
     const Eo_Class *_tmp_klass = klass; \
-    Eo *_tmp_obj = _eo_add_internal_start(__FILE__, __LINE__, _tmp_klass, parent); \
+    Eo *_tmp_obj = _eo_add_internal_start(__FILE__, __LINE__, _tmp_klass, parent, EINA_FALSE); \
     eo_do(_tmp_obj, \
            eo_constructor(); \
            __VA_ARGS__; \
@@ -659,12 +659,17 @@ EAPI void eo_error_set_internal(const Eo *obj, const char *file, int line);
  */
 #define eo_add_ref(klass, parent, ...) \
    ({ \
-    Eo *_tmp_obj_ref = eo_add(klass, parent, __VA_ARGS__); \
-    if (eo_do(_tmp_obj_ref, eo_parent_get())) eo_ref(_tmp_obj_ref); \
-    _tmp_obj_ref; \
+    const Eo_Class *_tmp_klass = klass; \
+    Eo *_tmp_obj = _eo_add_internal_start(__FILE__, __LINE__, _tmp_klass, parent, EINA_TRUE); \
+    eo_do(_tmp_obj, \
+           eo_constructor(); \
+           __VA_ARGS__; \
+           _tmp_obj = eo_finalize(); \
+          ); \
+    _tmp_obj; \
     })
 
-EAPI Eo * _eo_add_internal_start(const char *file, int line, const Eo_Class *klass_id, Eo *parent);
+EAPI Eo * _eo_add_internal_start(const char *file, int line, const Eo_Class *klass_id, Eo *parent, Eina_Bool ref);
 
 /**
  * @brief Get a pointer to the data of an object for a specific class.
index e78b6f0..6e3ed73 100644 (file)
@@ -868,7 +868,7 @@ _eo_class_funcs_set(_Eo_Class *klass)
 }
 
 EAPI Eo *
-_eo_add_internal_start(const char *file, int line, const Eo_Class *klass_id, Eo *parent_id)
+_eo_add_internal_start(const char *file, int line, const Eo_Class *klass_id, Eo *parent_id, Eina_Bool ref)
 {
    _Eo_Object *obj;
 
@@ -915,7 +915,7 @@ _eo_add_internal_start(const char *file, int line, const Eo_Class *klass_id, Eo
 
    /* If there's a parent. Unref. Eo_add should return an object with either a
     * parent ref, or with the lack of, just a ref. */
-   if (eo_do(eo_id, eo_parent_get()))
+   if (!ref && eo_do(eo_id, eo_parent_get()))
      {
         _eo_unref(obj);
      }