use stringshare in eina_error
authordiscomfitor <discomfitor@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Fri, 18 Mar 2011 22:02:03 +0000 (22:02 +0000)
committerdiscomfitor <discomfitor@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Fri, 18 Mar 2011 22:02:03 +0000 (22:02 +0000)
the only restriction here is that eina_error_msg_register cannot be used internally by eina prior to stringshare init, but since this does not happen currently there is no problem :)

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

ChangeLog
src/lib/eina_error.c

index aea60fd..831d360 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -32,3 +32,7 @@
 
        * Fix stat failure when file size in bytes or the number of blocks
        allocated to the file or the file serial number didn't fit in 32bits.
+
+2011-03-18  Mike Blumenkrantz
+
+        * Use stringshare for eina_error messages
index f273ca5..ff47405 100644 (file)
@@ -41,7 +41,7 @@
  * or a lib should manage. Then, when an error can occur, use
  * eina_error_set(), and when errors are managed, use
  * eina_error_get(). If eina_error_set() is used to set an error, do
- * not forget to call before eina_error_set0), to remove previous set
+ * not forget to call before eina_error_set(), to remove previous set
  * errors.
  *
  * Here is an example of use:
 /* undefs EINA_ARG_NONULL() so NULL checks are not compiled out! */
 #include "eina_safety_checks.h"
 #include "eina_error.h"
+#include "eina_stringshare.h"
 
 /* TODO
  * + add a wrapper for assert?
@@ -269,7 +270,7 @@ eina_error_shutdown(void)
 
    for (; eem < eem_end; eem++)
       if (eem->string_allocated)
-         free((char *)eem->string);
+         eina_stringshare_del(eem->string);
 
          free(_eina_errors);
    _eina_errors = NULL;
@@ -303,7 +304,7 @@ eina_error_shutdown(void)
  * @brief Register a new error type.
  *
  * @param msg The description of the error. It will be duplicated using
- *        strdup().
+ *        eina_stringshare_add().
  * @return The unique number identifier for this error.
  *
  * This function stores in a list the error message described by
@@ -325,7 +326,7 @@ eina_error_msg_register(const char *msg)
       return 0;
 
    eem->string_allocated = EINA_TRUE;
-   eem->string = strdup(msg);
+   eem->string = eina_stringshare_add(msg);
    if (!eem->string)
      {
         _eina_errors_count--;
@@ -378,7 +379,7 @@ eina_error_msg_static_register(const char *msg)
  * This function modifies the message associated with @p error and changes
  * it to @p msg.  If the error was previously registered by @ref eina_error_msg_static_register
  * then the string will not be duplicated, otherwise the previous message
- * will be freed and @p msg copied.
+ * will be unrefed and @p msg copied.
  *
  * @see eina_error_msg_register()
  */
@@ -396,10 +397,10 @@ eina_error_msg_modify(Eina_Error error, const char *msg)
      {
         const char *tmp;
 
-        if (!(tmp = strdup(msg)))
+        if (!(tmp = eina_stringshare_add(msg)))
            return EINA_FALSE;
 
-        free((void *)_eina_errors[error - 1].string);
+        eina_stringshare_del(_eina_errors[error - 1].string);
         _eina_errors[error - 1].string = tmp;
         return EINA_TRUE;
      }