eina share log refactor.
authorbarbieri <barbieri@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Sat, 21 Jan 2012 07:21:23 +0000 (07:21 +0000)
committerbarbieri <barbieri@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Sat, 21 Jan 2012 07:21:23 +0000 (07:21 +0000)
Don't print messages from share common, that way we have no way to
know where it happens, moreover the binshare values may lack trailing
'\0'.

Also makes no sense to share the log domain. With separate domains we
can be more selective in what we log/debug.

git-svn-id: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/eina@67418 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33

src/lib/eina_binshare.c
src/lib/eina_share_common.c
src/lib/eina_share_common.h
src/lib/eina_stringshare.c
src/lib/eina_ustringshare.c

index 68a82fc..01e8046 100644 (file)
 
  */
 
-#include "eina_share_common.h"
-#include "eina_unicode.h"
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include "eina_config.h"
 #include "eina_private.h"
+#include "eina_unicode.h"
+#include "eina_log.h"
+#include "eina_share_common.h"
+
+/* undefs EINA_ARG_NONULL() so NULL checks are not compiled out! */
+#include "eina_safety_checks.h"
 #include "eina_binshare.h"
 
 /*============================================================================*
  * @cond LOCAL
  */
 
+#ifdef CRITICAL
+#undef CRITICAL
+#endif
+#define CRITICAL(...) EINA_LOG_DOM_CRIT(_eina_share_binshare_log_dom, __VA_ARGS__)
+
+#ifdef ERR
+#undef ERR
+#endif
+#define ERR(...) EINA_LOG_DOM_ERR(_eina_share_binshare_log_dom, __VA_ARGS__)
+
+#ifdef DBG
+#undef DBG
+#endif
+#define DBG(...) EINA_LOG_DOM_DBG(_eina_share_binshare_log_dom, __VA_ARGS__)
+
+static int _eina_share_binshare_log_dom = -1;
+
 /* The actual share */
 static Eina_Share *binshare_share;
 static const char EINA_MAGIC_BINSHARE_NODE_STR[] = "Eina Binshare Node";
@@ -42,7 +68,6 @@ static const char EINA_MAGIC_BINSHARE_NODE_STR[] = "Eina Binshare Node";
  * @endcond
  */
 
-
 /*============================================================================*
 *                                 Global                                     *
 *============================================================================*/
@@ -61,9 +86,31 @@ static const char EINA_MAGIC_BINSHARE_NODE_STR[] = "Eina Binshare Node";
 EAPI Eina_Bool
 eina_binshare_init(void)
 {
-   return eina_share_common_init(&binshare_share,
-                                 EINA_MAGIC_BINSHARE_NODE,
-                                 EINA_MAGIC_BINSHARE_NODE_STR);
+   Eina_Bool ret;
+
+   if (_eina_share_binshare_log_dom < 0)
+     {
+        _eina_share_binshare_log_dom = eina_log_domain_register
+          ("eina_binshare", EINA_LOG_COLOR_DEFAULT);
+
+        if (_eina_share_binshare_log_dom < 0)
+          {
+             EINA_LOG_ERR("Could not register log domain: eina_binshare");
+             return EINA_FALSE;
+          }
+     }
+
+   ret = eina_share_common_init(&binshare_share,
+                                EINA_MAGIC_BINSHARE_NODE,
+                                EINA_MAGIC_BINSHARE_NODE_STR);
+
+   if (!ret)
+     {
+        eina_log_domain_unregister(_eina_share_binshare_log_dom);
+        _eina_share_binshare_log_dom = -1;
+     }
+
+   return ret;
 }
 
 /**
@@ -82,6 +129,13 @@ eina_binshare_shutdown(void)
 {
    Eina_Bool ret;
    ret = eina_share_common_shutdown(&binshare_share);
+
+   if (_eina_share_binshare_log_dom > 0)
+     {
+        eina_log_domain_unregister(_eina_share_binshare_log_dom);
+        _eina_share_binshare_log_dom = -1;
+     }
+
    return ret;
 }
 
@@ -96,7 +150,8 @@ eina_binshare_del(const void *obj)
    if (!obj)
       return;
 
-   eina_share_common_del(binshare_share, obj);
+   if (!eina_share_common_del(binshare_share, obj))
+     CRITICAL("EEEK trying to del non-shared binshare %p", obj);
 }
 
 EAPI const void *
index 90e1868..776e429 100644 (file)
@@ -76,7 +76,6 @@
 #include "eina_hash.h"
 #include "eina_rbtree.h"
 #include "eina_error.h"
-#include "eina_log.h"
 #include "eina_lock.h"
 
 /* undefs EINA_ARG_NONULL() so NULL checks are not compiled out! */
@@ -126,8 +125,6 @@ typedef struct _Eina_Share_Common Eina_Share_Common;
 typedef struct _Eina_Share_Common_Node Eina_Share_Common_Node;
 typedef struct _Eina_Share_Common_Head Eina_Share_Common_Head;
 
-int _eina_share_common_log_dom = -1;
-
 struct _Eina_Share
 {
    Eina_Share_Common *share;
@@ -600,28 +597,8 @@ eina_share_common_init(Eina_Share **_share,
    share = *_share = calloc(sizeof(Eina_Share), 1);
    if (!share) goto on_error;
 
-   if (_eina_share_common_log_dom < 0) /*Only register if not already */
-      _eina_share_common_log_dom = eina_log_domain_register(
-            "eina_share",
-            EINA_LOG_COLOR_DEFAULT);
-
-   if (_eina_share_common_log_dom < 0)
-     {
-        EINA_LOG_ERR("Could not register log domain: eina_share_common");
-        goto on_error;
-     }
-
    share->share = calloc(1, sizeof(Eina_Share_Common));
-   if (!share->share)
-     {
-        if (_eina_share_common_log_dom > 0)
-          {
-             eina_log_domain_unregister(_eina_share_common_log_dom);
-             _eina_share_common_log_dom = -1;
-          }
-
-        goto on_error;
-     }
+   if (!share->share) goto on_error;
 
    share->node_magic = node_magic;
 #define EMS(n) eina_magic_string_static_set(n, n ## _STR)
@@ -678,11 +655,6 @@ eina_share_common_shutdown(Eina_Share **_share)
    MAGIC_FREE(share->share);
 
    _eina_share_common_population_shutdown(share);
-   if (_eina_share_common_log_dom > 0) /* Only free if necessary */
-     {
-        eina_log_domain_unregister(_eina_share_common_log_dom);
-        _eina_share_common_log_dom = -1;
-     }
 
    eina_lock_release(&_mutex_big);
 
@@ -833,7 +805,7 @@ eina_share_common_ref(Eina_Share *share, const char *str)
 }
 
 
-void
+Eina_Bool
 eina_share_common_del(Eina_Share *share, const char *str)
 {
    unsigned int slen;
@@ -843,7 +815,7 @@ eina_share_common_del(Eina_Share *share, const char *str)
    int hash_num, hash;
 
    if (!str)
-      return;
+      return EINA_TRUE;
 
    eina_lock_take(&_mutex_big);
 
@@ -857,7 +829,7 @@ eina_share_common_del(Eina_Share *share, const char *str)
      {
         node->references--;
         eina_lock_release(&_mutex_big);
-        return;
+        return EINA_TRUE;
      }
 
    node->references = 0;
@@ -871,7 +843,7 @@ eina_share_common_del(Eina_Share *share, const char *str)
    if (!ed)
       goto on_error;
 
-   EINA_MAGIC_CHECK_SHARE_COMMON_HEAD(ed, eina_lock_release(&_mutex_big));
+   EINA_MAGIC_CHECK_SHARE_COMMON_HEAD(ed, eina_lock_release(&_mutex_big), EINA_FALSE);
 
    if (!_eina_share_common_head_remove_node(ed, node))
       goto on_error;
@@ -886,12 +858,12 @@ eina_share_common_del(Eina_Share *share, const char *str)
 
    eina_lock_release(&_mutex_big);
 
-   return;
+   return EINA_TRUE;
 
 on_error:
    eina_lock_release(&_mutex_big);
    /* possible segfault happened before here, but... */
-   CRITICAL("EEEK trying to del non-shared share_common \"%s\"", str);
+   return EINA_FALSE;
 }
 
 int
index 002c652..6bc11ef 100644 (file)
@@ -71,7 +71,7 @@ const char *eina_share_common_add_length(Eina_Share *share,
                                          unsigned int null_size)
 EINA_WARN_UNUSED_RESULT;
 const char *eina_share_common_ref(Eina_Share *share, const char *str);
-void        eina_share_common_del(Eina_Share *share, const char *str);
+Eina_Bool   eina_share_common_del(Eina_Share *share, const char *str) EINA_WARN_UNUSED_RESULT;
 int         eina_share_common_length(Eina_Share *share,
                                      const char *str) EINA_CONST
 EINA_WARN_UNUSED_RESULT;
@@ -83,21 +83,4 @@ void        eina_share_common_dump(Eina_Share *share, void (*additional_dump)(
 void        eina_share_common_population_add(Eina_Share *share, int slen);
 void        eina_share_common_population_del(Eina_Share *share, int slen);
 
-/* Share logging */
-#ifdef CRITICAL
-#undef CRITICAL
-#endif
-#define CRITICAL(...) EINA_LOG_DOM_CRIT(_eina_share_common_log_dom, __VA_ARGS__)
-
-#ifdef ERR
-#undef ERR
-#endif
-#define ERR(...) EINA_LOG_DOM_ERR(_eina_share_common_log_dom, __VA_ARGS__)
-
-#ifdef DBG
-#undef DBG
-#endif
-#define DBG(...) EINA_LOG_DOM_DBG(_eina_share_common_log_dom, __VA_ARGS__)
-extern int _eina_share_common_log_dom;
-
-#endif /* EINA_STRINGSHARE_H_ */
+#endif /* EINA_SHARE_COMMON_H_ */
index 478b300..2f909b6 100644 (file)
@@ -55,12 +55,30 @@ void *alloca (size_t);
 #include "eina_private.h"
 #include "eina_error.h"
 #include "eina_log.h"
-#include "eina_stringshare.h"
 #include "eina_lock.h"
+#include "eina_share_common.h"
 
 /* undefs EINA_ARG_NONULL() so NULL checks are not compiled out! */
 #include "eina_safety_checks.h"
-#include "eina_share_common.h"
+#include "eina_stringshare.h"
+
+
+#ifdef CRITICAL
+#undef CRITICAL
+#endif
+#define CRITICAL(...) EINA_LOG_DOM_CRIT(_eina_share_stringshare_log_dom, __VA_ARGS__)
+
+#ifdef ERR
+#undef ERR
+#endif
+#define ERR(...) EINA_LOG_DOM_ERR(_eina_share_stringshare_log_dom, __VA_ARGS__)
+
+#ifdef DBG
+#undef DBG
+#endif
+#define DBG(...) EINA_LOG_DOM_DBG(_eina_share_stringshare_log_dom, __VA_ARGS__)
+
+static int _eina_share_stringshare_log_dom = -1;
 
 /* The actual share */
 static Eina_Share *stringshare_share;
@@ -500,11 +518,29 @@ Eina_Bool
 eina_stringshare_init(void)
 {
    Eina_Bool ret;
+
+   if (_eina_share_stringshare_log_dom < 0)
+     {
+        _eina_share_stringshare_log_dom = eina_log_domain_register
+          ("eina_stringshare", EINA_LOG_COLOR_DEFAULT);
+
+        if (_eina_share_stringshare_log_dom < 0)
+          {
+             EINA_LOG_ERR("Could not register log domain: eina_stringshare");
+             return EINA_FALSE;
+          }
+     }
+
    ret = eina_share_common_init(&stringshare_share,
                                 EINA_MAGIC_STRINGSHARE_NODE,
                                 EINA_MAGIC_STRINGSHARE_NODE_STR);
    if (ret)
       _eina_stringshare_small_init();
+   else
+     {
+        eina_log_domain_unregister(_eina_share_stringshare_log_dom);
+        _eina_share_stringshare_log_dom = -1;
+     }
 
    return ret;
 }
@@ -526,6 +562,13 @@ eina_stringshare_shutdown(void)
    Eina_Bool ret;
    _eina_stringshare_small_shutdown();
    ret = eina_share_common_shutdown(&stringshare_share);
+
+   if (_eina_share_stringshare_log_dom >= 0)
+     {
+        eina_log_domain_unregister(_eina_share_stringshare_log_dom);
+        _eina_share_stringshare_log_dom = -1;
+     }
+
    return ret;
 }
 
@@ -564,7 +607,8 @@ eina_stringshare_del(const char *str)
         return;
      }
 
-   eina_share_common_del(stringshare_share, str);
+   if (!eina_share_common_del(stringshare_share, str))
+     CRITICAL("EEEK trying to del non-shared stringshare \"%s\"", str);
 }
 
 EAPI const char *
index 3992dc6..33be242 100644 (file)
  *
  */
 
-#include "eina_share_common.h"
-#include "eina_unicode.h"
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include "eina_config.h"
 #include "eina_private.h"
+#include "eina_unicode.h"
+#include "eina_log.h"
+#include "eina_share_common.h"
+
+/* undefs EINA_ARG_NONULL() so NULL checks are not compiled out! */
+#include "eina_safety_checks.h"
 #include "eina_ustringshare.h"
 
+
+#ifdef CRITICAL
+#undef CRITICAL
+#endif
+#define CRITICAL(...) EINA_LOG_DOM_CRIT(_eina_share_ustringshare_log_dom, __VA_ARGS__)
+
+#ifdef ERR
+#undef ERR
+#endif
+#define ERR(...) EINA_LOG_DOM_ERR(_eina_share_ustringshare_log_dom, __VA_ARGS__)
+
+#ifdef DBG
+#undef DBG
+#endif
+#define DBG(...) EINA_LOG_DOM_DBG(_eina_share_ustringshare_log_dom, __VA_ARGS__)
+
+static int _eina_share_ustringshare_log_dom = -1;
+
 /* The actual share */
 static Eina_Share *ustringshare_share;
 static const char EINA_MAGIC_USTRINGSHARE_NODE_STR[] = "Eina UStringshare Node";
@@ -54,9 +81,31 @@ static const char EINA_MAGIC_USTRINGSHARE_NODE_STR[] = "Eina UStringshare Node";
 Eina_Bool
 eina_ustringshare_init(void)
 {
-   return eina_share_common_init(&ustringshare_share,
-                                 EINA_MAGIC_USTRINGSHARE_NODE,
-                                 EINA_MAGIC_USTRINGSHARE_NODE_STR);
+   Eina_Bool ret;
+
+   if (_eina_share_ustringshare_log_dom < 0)
+     {
+        _eina_share_ustringshare_log_dom = eina_log_domain_register
+          ("eina_ustringshare", EINA_LOG_COLOR_DEFAULT);
+
+        if (_eina_share_ustringshare_log_dom < 0)
+          {
+             EINA_LOG_ERR("Could not register log domain: eina_ustringshare");
+             return EINA_FALSE;
+          }
+     }
+
+   ret = eina_share_common_init(&ustringshare_share,
+                                EINA_MAGIC_USTRINGSHARE_NODE,
+                                EINA_MAGIC_USTRINGSHARE_NODE_STR);
+
+   if (!ret)
+     {
+        eina_log_domain_unregister(_eina_share_ustringshare_log_dom);
+        _eina_share_ustringshare_log_dom = -1;
+     }
+
+   return ret;
 }
 
 /**
@@ -75,6 +124,13 @@ eina_ustringshare_shutdown(void)
 {
    Eina_Bool ret;
    ret = eina_share_common_shutdown(&ustringshare_share);
+
+   if (_eina_share_ustringshare_log_dom >= 0)
+     {
+        eina_log_domain_unregister(_eina_share_ustringshare_log_dom);
+        _eina_share_ustringshare_log_dom = -1;
+     }
+
    return ret;
 }
 
@@ -88,7 +144,8 @@ eina_ustringshare_del(const Eina_Unicode *str)
    if (!str)
       return;
 
-   eina_share_common_del(ustringshare_share,(const char *)str);
+   if (!eina_share_common_del(ustringshare_share, (const char *)str))
+     CRITICAL("EEEK trying to del non-shared ustringshare \"%s\"", (const char *)str);
 }
 
 EAPI const Eina_Unicode *