* This file defines functions, structures and macros for handling arrays in vlc
*/
+/* realloc() that never fails *if* downsizing */
+static inline void *realloc_down( void *ptr, size_t size )
+{
+ void *ret = realloc( ptr, size );
+ return ret ? ret : ptr;
+}
+
/**
* Simple dynamic array handling. Array is realloced at each insert/removal
*/
{ \
if( !i_oldsize ) (p_ar) = NULL; \
(p_ar) = VLCCVP realloc( p_ar, ((i_oldsize) + 1) * sizeof(*(p_ar)) ); \
+ if( !(p_ar) ) abort(); \
if( (i_oldsize) - (i_pos) ) \
{ \
memmove( (p_ar) + (i_pos) + 1, (p_ar) + (i_pos), \
} \
while( 0 )
-#define REMOVE_ELEM( p_ar, i_oldsize, i_pos ) \
+#define REMOVE_ELEM( p_ar, i_size, i_pos ) \
do \
{ \
- if( (i_oldsize) - (i_pos) - 1 ) \
+ if( (i_size) - (i_pos) - 1 ) \
{ \
memmove( (p_ar) + (i_pos), \
(p_ar) + (i_pos) + 1, \
- ((i_oldsize) - (i_pos) - 1) * sizeof( *(p_ar) ) ); \
- } \
- if( i_oldsize > 1 ) \
- { \
- (p_ar) = realloc( p_ar, ((i_oldsize) - 1) * sizeof( *(p_ar) ) ); \
+ ((i_size) - (i_pos) - 1) * sizeof( *(p_ar) ) ); \
} \
+ if( i_size > 1 ) \
+ (p_ar) = realloc_down( p_ar, ((i_size) - 1) * sizeof( *(p_ar) ) );\
else \
{ \
free( p_ar ); \
(p_ar) = NULL; \
} \
- (i_oldsize)--; \
+ (i_size)--; \
} \
while( 0 )
(tab) = cast realloc( tab, sizeof( void ** ) * ( (count) + 1 ) ); \
else \
(tab) = cast malloc( sizeof( void ** ) ); \
+ if( !(tab) ) abort(); \
(tab)[count] = (p); \
(count)++; \
} while(0)
(tab) = cast realloc( tab, sizeof( void ** ) * ( (count) + 1 ) ); \
else \
(tab) = cast malloc( sizeof( void ** ) ); \
+ if( !(tab) ) abort(); \
if( (count) - (index) > 0 ) \
memmove( (void**)(tab) + (index) + 1, \
(void**)(tab) + (index), \
(array).i_alloc = newsize; \
(array).p_elems = VLCCVP realloc( (array).p_elems, (array).i_alloc * \
sizeof(*(array).p_elems) ); \
+ if( !(array).p_elems ) abort(); \
}
#define _ARRAY_GROW1(array) { \