+static int64_t GCD( int64_t a, int64_t b )
+{
+ if( b ) return GCD( b, a % b );
+ else return a;
+}
+
+/* Malloc with automatic error */
+#define MALLOC_VOID( var, type ) { var = (type*)malloc( sizeof( type) ); \
+ if( !var ) return; }
+#define MALLOC_NULL( var, type ) { var = (type*)malloc( sizeof( type) ); \
+ if( !var ) return NULL; }
+#define MALLOC_ERR( var, type ) { var = (type*)malloc( sizeof( type) ); \
+ if( !var ) return VLC_ENOMEM; }
+#define MALLOC_GOTOERR( var, type ) { var = (type*)malloc( sizeof( type) ); \
+ if( !var ) goto error; }
+#define DECMALLOC_VOID( var, type ) type* var = (type*)malloc( sizeof(type) );\
+ if( !var ) return;
+#define DECMALLOC_ERR( var, type ) type* var = (type*)malloc( sizeof(type) );\
+ if( !var ) return VLC_ENOMEM;
+#define DECMALLOC_NULL( var, type ) type* var = (type*)malloc( sizeof(type) );\
+ if( !var ) return NULL;
+
+#define FREENULL(a) if( a ) { free( a ); a = NULL; }
+#define FREE(a) if( a ) { free( a ); }
+
+/* Dynamic array handling: realloc array, move data, increment position */
+#if defined( _MSC_VER ) && _MSC_VER < 1300 && !defined( UNDER_CE )
+# define VLCCVP (void**) /* Work-around for broken compiler */
+#else
+# define VLCCVP
+#endif
+#define INSERT_ELEM( p_ar, i_oldsize, i_pos, elem ) \
+ do \
+ { \
+ if( !i_oldsize ) (p_ar) = NULL; \
+ (p_ar) = VLCCVP realloc( p_ar, ((i_oldsize) + 1) * sizeof(*(p_ar)) ); \
+ if( (i_oldsize) - (i_pos) ) \
+ { \
+ memmove( (p_ar) + (i_pos) + 1, (p_ar) + (i_pos), \
+ ((i_oldsize) - (i_pos)) * sizeof( *(p_ar) ) ); \
+ } \
+ (p_ar)[i_pos] = elem; \
+ (i_oldsize)++; \
+ } \
+ while( 0 )
+
+#define REMOVE_ELEM( p_ar, i_oldsize, i_pos ) \
+ do \
+ { \
+ if( (i_oldsize) - (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) ) ); \
+ } \
+ else \
+ { \
+ free( p_ar ); \
+ (p_ar) = NULL; \
+ } \
+ (i_oldsize)--; \
+ } \
+ while( 0 )
+
+
+#define TAB_APPEND( count, tab, p ) \
+ if( (count) > 0 ) \
+ { \
+ (tab) = realloc( tab, sizeof( void ** ) * ( (count) + 1 ) ); \
+ } \
+ else \
+ { \
+ (tab) = malloc( sizeof( void ** ) ); \
+ } \
+ (tab)[count] = (p); \
+ (count)++
+
+#define TAB_FIND( count, tab, p, index ) \
+ { \
+ int _i_; \
+ (index) = -1; \
+ for( _i_ = 0; _i_ < (count); _i_++ ) \
+ { \
+ if( (tab)[_i_] == (p) ) \
+ { \
+ (index) = _i_; \
+ break; \
+ } \
+ } \
+ }
+
+#define TAB_REMOVE( count, tab, p ) \
+ { \
+ int _i_index_; \
+ TAB_FIND( count, tab, p, _i_index_ ); \
+ if( _i_index_ >= 0 ) \
+ { \
+ if( (count) > 1 ) \
+ { \
+ memmove( ((void**)(tab) + _i_index_), \
+ ((void**)(tab) + _i_index_+1), \
+ ( (count) - _i_index_ - 1 ) * sizeof( void* ) );\
+ } \
+ (count)--; \
+ if( (count) == 0 ) \
+ { \
+ free( tab ); \
+ (tab) = NULL; \
+ } \
+ } \
+ }
+
+/* Hash tables handling */
+struct hashtable_entry_t
+{
+ int i_id;
+ char *psz_name;
+ uint64_t i_hash;
+ void *p_data;
+};
+
+VLC_EXPORT( void, vlc_HashInsert, (hashtable_entry_t **, int *, int, const char *, void *));
+VLC_EXPORT( void*, vlc_HashRetrieve, (hashtable_entry_t*, int, int, const char *) );
+VLC_EXPORT( int, vlc_HashLookup, (hashtable_entry_t *, int, int, const char *) );
+
+