[vlc-devel] commit: xmalloc, xrealloc: traditional functions to allocate memory ( Rémi Denis-Courmont )

git version control git at videolan.org
Sun Dec 6 11:23:22 CET 2009


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Dec  6 10:46:29 2009 +0200| [95a993e5f486beda44c05e5fabf72a2c4bfb3bee] | committer: Rémi Denis-Courmont 

xmalloc, xrealloc: traditional functions to allocate memory

Those functions automatically abort if allocation fails (which is not
quite the same as calling assert()). Avoid these functions in new code.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=95a993e5f486beda44c05e5fabf72a2c4bfb3bee
---

 include/vlc_common.h |   19 +++++++++++++++++++
 1 files changed, 19 insertions(+), 0 deletions(-)

diff --git a/include/vlc_common.h b/include/vlc_common.h
index 82dad36..d8dd580 100644
--- a/include/vlc_common.h
+++ b/include/vlc_common.h
@@ -815,6 +815,25 @@ static inline const char *vlc_pgettext( const char *ctx, const char *id )
 }
 
 /*****************************************************************************
+ * 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
  *****************************************************************************/
 VLC_EXPORT( const char *, VLC_Version, ( void ) LIBVLC_USED );




More information about the vlc-devel mailing list