]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Polish compat library xfree/xxfree
authorAmos Jeffries <squid3@treenet.co.nz>
Thu, 5 Jan 2012 14:12:04 +0000 (03:12 +1300)
committerAmos Jeffries <squid3@treenet.co.nz>
Thu, 5 Jan 2012 14:12:04 +0000 (03:12 +1300)
* remove xxfree() entirely it has been a useless wrapper for free_const()
  for some time now.

* update replace xfree() to a static inline function to permit better
  compiler optimization

compat/xalloc.cc
compat/xalloc.h
include/util.h
lib/malloc_trace.cc

index db13493c41a93c6fc87bf14919c67b7e6b41d875..bd84bef9e201e32313c91dc5bc40b0785b07cea8 100644 (file)
@@ -193,15 +193,6 @@ xrealloc(void *s, size_t sz)
     return (p);
 }
 
-void
-xfree(void *s)
-{
-    if (s == NULL)
-        return;
-
-    free_const(s);
-}
-
 void
 free_const(const void *s_const)
 {
index 1d86f404e240873374684da1845fcbc31e512296..1daff1504e577005ffff145dac7a92327d425d97 100644 (file)
@@ -30,27 +30,29 @@ extern "C" {
     void *xrealloc(void *s, size_t sz);
 
     /**
-     *  xfree() - same as free(3).  Used for portability.
-     *   Will not call free(3) if s == NULL.
+     * free_const() - Same as free(3).  Used for portability.
+     * Accepts pointers to dynamically allocated const data.
      *
      * Define failure_notify to receive error message.
      * otherwise perror() is used to display it.
      */
-    void xfree(void *s);
+    void free_const(const void *s);
 
     /**
-     * xxfree() / free_const() - Same as free(3).  Used for portability.
+     *  xfree() - same as free(3).  Used for portability.
      * Accepts pointers to dynamically allocated const data.
+     * Will not call free(3) if the pointer is NULL.
+     *
+     * Pointer is left with a value on completion.
+     * Use safe_free() if the pointer needs to be set to NULL afterward.
      *
      * Define failure_notify to receive error message.
      * otherwise perror() is used to display it.
      */
-    void free_const(const void *s);
-
-/// Backward compatibility alias for free_const(const void *s)
-#define xxfree(x)  free_const((x))
+    static inline void xfree(const void *p) { if (p) free_const(p); }
 
     /**
+     *  safe_free() - same as free(3).  Used for portability.
      * Accepts pointers to dynamically allocated const data.
      * Will not call free(3) if the pointer is NULL.
      * Sets the pointer to NULL on completion.
@@ -60,7 +62,7 @@ extern "C" {
      * Define failure_notify to receive error message.
      * otherwise perror() is used to display it.
      */
-#define safe_free(x)    while (x) { xxfree(x); (x) = NULL; }
+#define safe_free(x)    while ((x)) { free_const((x)); (x) = NULL; }
 
 #ifdef __cplusplus
 }
index 4bcd24e0b4e6316b45e5d23914b04df7334ba0f0..cb75b96889f3de61bafac6959403862236f1eba9 100644 (file)
@@ -69,7 +69,6 @@ SQUIDCEXTERN void Tolower(char *);
 #if XMALLOC_TRACE
 #define xmalloc(size) (xmalloc_func="xmalloc",xmalloc_line=__LINE__,xmalloc_file=__FILE__,xmalloc(size))
 #define xfree(ptr) (xmalloc_func="xfree",xmalloc_line=__LINE__,xmalloc_file=__FILE__,xfree(ptr))
-#define xxfree(ptr) (xmalloc_func="xxfree",xmalloc_line=__LINE__,xmalloc_file=__FILE__,xxfree(ptr))
 #define xrealloc(ptr,size) (xmalloc_func="xrealloc",xmalloc_line=__LINE__,xmalloc_file=__FILE__,xrealloc(ptr,size))
 #define xcalloc(n,size) (xmalloc_func="xcalloc",xmalloc_line=__LINE__,xmalloc_file=__FILE__,xcalloc(n,size))
 #define xstrdup(ptr) (xmalloc_func="xstrdup",xmalloc_line=__LINE__,xmalloc_file=__FILE__,xstrdup(ptr))
index fe1224a690f311a53a4740c6278aeb05fb08a65a..4d107b60d3308d0214fed81a247dac195dabf96e 100644 (file)
@@ -98,7 +98,6 @@ int xmalloc_trace = 0;                /* Enable with -m option */
 size_t xmalloc_total = 0;
 #undef xmalloc
 #undef xfree
-#undef xxfree
 #undef xrealloc
 #undef xcalloc
 #undef xstrdup