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.
* 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
}
#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))