Hi,

I'm trying to bring epsilon into the 21st century with some
eina_stringshare love. The attached patch should convert all epsilon
strings to consts that use eina_stringshare_*. Please review it.
Index: src/include/Epsilon_Request.h
===================================================================
--- src/include/Epsilon_Request.h	(revision 38120)
+++ src/include/Epsilon_Request.h	(working copy)
@@ -20,8 +20,8 @@
 	unsigned int   size;     /**< Thumbnail size to be generated */
 	unsigned int   format;   /**< Thumbnail format to be generated */
 	unsigned int   status;   /**< Status code of the thumbnail generation */
-	char          *path;     /**< Path to file requiring thumbnail */
-	char          *dest;     /**< Path to generated file, NULL on error */
+	const char    *path;     /**< Path to file requiring thumbnail */
+	const char    *dest;     /**< Path to generated file, NULL on error */
 	void          *data;     /**< Data associated with this thumbnail. */
 	void          *_event;   /**< private, Pointer to Ecore_Event if it existent. */
 };
Index: src/lib/Epsilon.h
===================================================================
--- src/lib/Epsilon.h	(revision 38120)
+++ src/lib/Epsilon.h	(working copy)
@@ -36,10 +36,10 @@
 
 struct _Epsilon
 {
-  char *hash;
-  char *src;
-  char *thumb;
-  char *key;
+  const char *hash;
+  const char *src;
+  const char *thumb;
+  const char *key;
   int w, h;
   int tw, th;
   int tsize;
@@ -49,10 +49,10 @@
 
 struct _Epsilon_Info
 {
-  char *uri;
+  const char *uri;
   unsigned long long int mtime;
   int w, h;
-  char *mimetype;
+  const char *mimetype;
   Epsilon_Exif_Info *eei;
 };
 typedef struct _Epsilon_Info Epsilon_Info;
Index: src/lib/epsilon_thumb.c
===================================================================
--- src/lib/epsilon_thumb.c	(revision 38120)
+++ src/lib/epsilon_thumb.c	(working copy)
@@ -43,6 +43,7 @@
 	/*
 	 * Init required subsystems.
 	 */
+        if (!eina_stringshare_init()) goto init_error;
 	if (!ecore_init()) goto init_error;
 	if (!ecore_ipc_init()) goto con_init_error;
 	if (!epsilon_init()) goto init_error;
@@ -145,9 +146,9 @@
 static void
 epsilon_request_free(Epsilon_Request *thumb)
 {
-	free(thumb->path);
+	eina_stringshare_del(thumb->path);
 	if (thumb->dest)
-		free(thumb->dest);
+          eina_stringshare_del(thumb->dest);
 	free(thumb);
 }
 
@@ -194,7 +195,7 @@
 
 		dest = epsilon_thumb_file_get(tb);
 		if (dest)
-			thumb->dest = strdup(dest);
+			thumb->dest = eina_stringshare_add(dest);
 	}
 	epsilon_free(tb);
 
@@ -326,13 +327,13 @@
 
 	thumb = calloc(1, sizeof(Epsilon_Request));
 	if (!thumb)
-		return NULL;
+          return NULL;
 
-	thumb->path = strdup(path);
-	if (!thumb->path) {
-		free(thumb);
-		return NULL;
+	if (!path) {
+             free(thumb);
+             return NULL;
 	}
+	thumb->path = eina_stringshare_add(path);
 	thumb->size = size;
 	thumb->data = data;
 	thumb->format = format;
Index: src/lib/Epsilon.c
===================================================================
--- src/lib/Epsilon.c	(revision 38120)
+++ src/lib/Epsilon.c	(working copy)
@@ -37,10 +37,10 @@
 #include <Edje.h>
 #include <dlfcn.h>
 
-static char *PATH_DIR_LARGE = NULL;
-static char *PATH_DIR_NORMAL = NULL;
-static char *PATH_DIR_CUSTOM = NULL;
-static char *PATH_DIR_FAIL = NULL;
+static const char *PATH_DIR_LARGE = NULL;
+static const char *PATH_DIR_NORMAL = NULL;
+static const char *PATH_DIR_CUSTOM = NULL;
+static const char *PATH_DIR_FAIL = NULL;
 static unsigned LEN_DIR_LARGE = 0;
 static unsigned LEN_DIR_NORMAL = 0;
 static unsigned LEN_DIR_CUSTOM = 0;
@@ -60,7 +60,7 @@
 extern Epsilon_Exif_Info *epsilon_exif_info_get (Epsilon * e);
 
 static int _epsilon_exists_ext(Epsilon *e, const char *ext, char *path, int path_size, time_t *mtime);
-static char *epsilon_hash (const char *file);
+static const char *epsilon_hash (const char *file);
 #ifdef HAVE_PNG_H
 static FILE *_epsilon_open_png_file_reading (const char *filename);
 static int _epsilon_png_write (const char *file, unsigned int * ptr,
@@ -78,8 +78,8 @@
     {
       if (file[0] == '/')
 	{
-	  result = calloc (1, sizeof (Epsilon));
-	  result->src = strdup (file);
+	  result = calloc(1, sizeof(Epsilon));
+	  result->src = eina_stringshare_add(file);
 	  result->tw = THUMB_SIZE_LARGE;
 	  result->th = THUMB_SIZE_LARGE;
 	  result->format = EPSILON_THUMB_FDO;
@@ -99,13 +99,13 @@
   if (e)
     {
       if (e->key)
-	free (e->key);
+	eina_stringshare_del(e->key);
       if (e->hash)
-	free (e->hash);
+	eina_stringshare_del(e->hash);
       if (e->src)
-	free (e->src);
+	eina_stringshare_del(e->src);
       if (e->thumb)
-	free (e->thumb);
+	eina_stringshare_del(e->thumb);
       free (e);
     }
 }
@@ -133,6 +133,8 @@
 }
 
 static int epsilon_init_count = 0;
+
+/* XXX: no epsilon_shutdown? */
 int
 epsilon_init (void)
 {
@@ -146,22 +148,23 @@
   char plugin_path[PATH_MAX];
 
   if (epsilon_init_count) return ++epsilon_init_count;
+  eina_stringshare_init();
 
   home = getenv("HOME");
   base_len = snprintf(buf, sizeof(buf), "%s/.thumbnails", home);
   if (!PATH_DIR_LARGE) {
      strncpy(buf + base_len, "/large", PATH_MAX - base_len);
-     PATH_DIR_LARGE = strdup(buf);
+     PATH_DIR_LARGE = eina_stringshare_add(buf);
      LEN_DIR_LARGE = strlen(buf);
   }
   if (!PATH_DIR_NORMAL) {
      strncpy(buf + base_len, "/normal", PATH_MAX - base_len);
-     PATH_DIR_NORMAL = strdup(buf);
+     PATH_DIR_NORMAL = eina_stringshare_add(buf);
      LEN_DIR_NORMAL = strlen(buf);
   }
   if (!PATH_DIR_FAIL) {
      strncpy(buf + base_len, "/fail/epsilon", PATH_MAX - base_len);
-     PATH_DIR_FAIL = strdup(buf);
+     PATH_DIR_FAIL = eina_stringshare_add(buf);
      LEN_DIR_FAIL = strlen(buf);
   }
 
@@ -202,9 +205,9 @@
   if (e)
     {
       if (e->key)
-	free (e->key);
+	eina_stringshare_del(e->key);
       if (key)
-	e->key = strdup (key);
+	e->key = eina_stringshare_add(key);
       else
 	e->key = NULL;
     }
@@ -230,10 +233,10 @@
 const char *
 epsilon_file_get (Epsilon * e)
 {
-  char *result = NULL;
+  const char *result = NULL;
   if (e)
     result = e->src;
-  return (result);
+  return result;
 }
 
 const char *
@@ -243,26 +246,26 @@
   char buf[PATH_MAX];
 
   if (!e)
-    return (NULL);
+    return NULL;
   if (e->thumb)
-    return (e->thumb);
+    return e->thumb;
 
   if (_epsilon_exists_ext(e, "jpg", buf, sizeof(buf), &mtime))
     {
-       e->thumb = strdup(buf);
-       return (e->thumb);
+       e->thumb = eina_stringshare_add(buf);
+       return e->thumb;
     }
 #ifdef HAVE_PNG_H
   if (_epsilon_exists_ext(e, "png", buf, sizeof(buf), &mtime))
     {
-       e->thumb = strdup (buf);
-       return (e->thumb);
+       e->thumb = eina_stringshare_add(buf);
+       return e->thumb;
     }
 #endif
-  return (NULL);
+  return NULL;
 }
 
-static char *
+static const char *
 epsilon_hash (const char *file)
 {
   int n;
@@ -287,7 +290,7 @@
       md5out[2 * n + 1] = hex[hash[n] & 0x0f];
     }
   md5out[2 * n] = '\0';
-  return (strdup (md5out));
+  return eina_stringshare_add(md5out);
 }
 
 static Epsilon_Info *
@@ -305,12 +308,12 @@
   if (info)
     {
       if (info->uri)
-	free (info->uri);
+	eina_stringshare_del(info->uri);
       if (info->mimetype)
-	free (info->mimetype);
+	eina_stringshare_del(info->mimetype);
       if (info->eei)
-	epsilon_exif_info_free (info->eei);
-      free (info);
+	epsilon_exif_info_free(info->eei);
+      free(info);
     }
 }
 
@@ -341,9 +344,9 @@
 	  p->w = info.w;
 	  p->h = info.h;
 	  if (info.uri)
-	    p->uri = strdup (info.uri);
+	    p->uri = eina_stringshare_add(info.uri);
 	  if (info.mimetype)
-	    p->mimetype = strdup (info.mimetype);
+	    p->mimetype = eina_stringshare_add(info.mimetype);
 	}
       epeg_close (im);
     }
@@ -388,9 +391,9 @@
 	  if (!strcmp (text.key, "Thumb::Image::Height"))
 	    p->h = atoi (text.text);
 	  if (!strcmp (text.key, "Thumb::URI"))
-	    p->uri = strdup (text.text);
+	    p->uri = eina_stringshare_add(text.text);
 	  if (!strcmp (text.key, "Thumb::Mimetype"))
-	    p->mimetype = strdup (text.text);
+	    p->mimetype = eina_stringshare_add(text.text);
 	}
       /* png_read_end(png_ptr,info_ptr); */
       png_destroy_read_struct (&png_ptr, &info_ptr, (png_infopp) NULL);
@@ -446,7 +449,7 @@
 static void
 _epsilon_file_name(unsigned thumb_size, const char *hash, const char *ext, char *path, int path_size)
 {
-   char *dir;
+   const char *dir;
    int dir_len;
 
    if (thumb_size == THUMB_SIZE_LARGE)
@@ -769,9 +772,9 @@
       strncpy(buf + base_len, dir, PATH_MAX - base_len);
 
       if (PATH_DIR_CUSTOM)
-        free(PATH_DIR_CUSTOM);
+        eina_stringshare_del(PATH_DIR_CUSTOM);
 
-      PATH_DIR_CUSTOM = strdup(buf);
+      PATH_DIR_CUSTOM = eina_stringshare_add(buf);
       LEN_DIR_CUSTOM = strlen(buf);
       ecore_file_mkpath(PATH_DIR_CUSTOM);
     }
Index: configure.ac
===================================================================
--- configure.ac	(revision 38120)
+++ configure.ac	(working copy)
@@ -23,6 +23,8 @@
 version_info=`expr $VMAJ + $VMIN`":$VMIC:$VMIN"
 AC_SUBST(version_info)
 
+PKG_CHECK_MODULES(EINA, [eina-0])
+
 PKG_CHECK_MODULES(EVAS, [evas >= 0.9.9])
 
 PKG_CHECK_MODULES(ECORE, [
------------------------------------------------------------------------------
SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada.
The future of the web can't happen without you.  Join us at MIX09 to help
pave the way to the Next Web now. Learn more and register at
http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/
_______________________________________________
enlightenment-devel mailing list
enlightenment-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel

Reply via email to