]> git.sesse.net Git - vlc/commitdiff
xmalloc, xrealloc: traditional functions to allocate memory
authorRémi Denis-Courmont <remi@remlab.net>
Sun, 6 Dec 2009 08:46:29 +0000 (10:46 +0200)
committerRémi Denis-Courmont <remi@remlab.net>
Sun, 6 Dec 2009 08:48:43 +0000 (10:48 +0200)
Those functions automatically abort if allocation fails (which is not
quite the same as calling assert()). Avoid these functions in new code.

include/vlc_common.h

index 82dad3670f8926ff09dc817c24ee164467678c02..d8dd5807a06619639439ea612f9466f2b156077e 100644 (file)
@@ -814,6 +814,25 @@ static inline const char *vlc_pgettext( const char *ctx, const char *id )
     return (tr == ctx) ? id : tr;
 }
 
+/*****************************************************************************
+ * Loosy memory allocation functions. Do not use in new code.
+ *****************************************************************************/
+static inline void *xmalloc (size_t len)
+{
+    void *ptr = malloc (len);
+    if (unlikely (ptr == NULL))
+        abort ();
+    return ptr;
+}
+
+static inline void *xrealloc (void *ptr, size_t len)
+{
+    void *nptr = realloc (ptr, len);
+    if (unlikely (nptr == NULL))
+        abort ();
+    return nptr;
+}
+
 /*****************************************************************************
  * libvlc features
  *****************************************************************************/