00001
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef VL_GENERIC_H
00014 #define VL_GENERIC_H
00015
00016 #include <stddef.h>
00017 #include <time.h>
00018 #include <assert.h>
00019
00020 #include "host.h"
00021
00023 #define VL_VERSION_STRING "0.9.4"
00024
00051 #define VL_STRINGIFY(x) # x
00052
00070 #define VL_XSTRINGIFY(x) VL_STRINGIFY(x)
00071
00085 #define VL_CAT(x,y) x ## y
00086
00097 #define VL_XCAT(x,y) VL_CAT(x,y)
00098
00110 #define VL_YESNO(x) ((x)?"yes":"no")
00111
00116 VL_EXPORT
00117 void vl_set_alloc_func (void *(*malloc_func) (size_t),
00118 void *(*realloc_func) (void*,size_t),
00119 void *(*calloc_func) (size_t, size_t),
00120 void (*free_func) (void*)) ;
00121 VL_INLINE void *vl_malloc (size_t n) ;
00122 VL_INLINE void *vl_realloc (void *ptr, size_t n) ;
00123 VL_INLINE void *vl_calloc (size_t n, size_t size) ;
00124 VL_INLINE void vl_free (void* ptr) ;
00125
00134 typedef int(*printf_func_t) (char const *format, ...) ;
00135
00140 VL_EXPORT void vl_set_printf_func (printf_func_t printf_func) ;
00141
00147 #define VL_PRINTF (*vl_printf_func)
00148
00152 #define VL_PRINT (*vl_printf_func)
00153
00161 extern VL_EXPORT int vl_err_no ;
00162
00164 #define VL_ERR_MSG_LEN 1024
00165
00167 extern VL_EXPORT char vl_err_msg [VL_ERR_MSG_LEN + 1] ;
00168
00169 #define VL_ERR_OK 0
00170 #define VL_ERR_OVERFLOW 1
00171 #define VL_ERR_ALLOC 2
00172 #define VL_ERR_BAD_ARG 3
00173 #define VL_ERR_IO 4
00174 #define VL_ERR_EOF 5
00175 #define VL_ERR_NO_MORE 5
00188 #define VL_MIN(x,y) (((x)<(y))?(x):(y))
00189
00195 #define VL_MAX(x,y) (((x)>(y))?(x):(y))
00196
00206 #define VL_SHIFT_LEFT(x,n) (((n)>=0)?((x)<<(n)):((x)>>-(n)))
00207
00208
00210 VL_EXPORT
00211 char const * vl_get_version_string () ;
00212
00213 VL_EXPORT
00214 void vl_print_info () ;
00215
00220 VL_EXPORT void vl_tic() ;
00221 VL_EXPORT double vl_toc() ;
00224 extern VL_EXPORT int (*vl_printf_func) (char const * format, ...) ;
00225 extern VL_EXPORT void *(*vl_malloc_func) (size_t) ;
00226 extern VL_EXPORT void *(*vl_realloc_func) (void*,size_t) ;
00227 extern VL_EXPORT void *(*vl_calloc_func) (size_t, size_t) ;
00228 extern VL_EXPORT void (*vl_free_func) (void*) ;
00229
00230 VL_INLINE
00231 void* vl_malloc (size_t n)
00232 {
00233 return (*vl_malloc_func)(n) ;
00234 }
00235
00236 VL_INLINE
00237 void* vl_realloc (void* ptr, size_t n)
00238 {
00239 return (*vl_realloc_func)(ptr, n) ;
00240 }
00241
00242 VL_INLINE
00243 void* vl_calloc (size_t n, size_t size)
00244 {
00245 return (*vl_calloc_func)(n, size) ;
00246 }
00247
00248 VL_INLINE
00249 void vl_free (void *ptr)
00250 {
00251 (*vl_free_func)(ptr) ;
00252 }
00253
00254
00255 #endif