10 #ifdef CXR_DEBUG_ALLOCATORS
11 #define CXR_STR_PRE(x) #x
12 #define CXR_STR(x) CXR_STR_PRE(x)
13 #define cxr_ab_ptr(b,i) __cxr_ab_ptr(b,i, __FILE__ ":L" CXR_STR(__LINE__) )
15 #define cxr_ab_ptr(b,i) __cxr_ab_ptr(b,i)
18 static void *__cxr_ab_ptr( struct cxr_auto_buffer
*buffer
, u32 index
20 #ifdef CXR_DEBUG_ALLOCATORS
21 ,const char *debug_str
27 #ifdef CXR_DEBUG_ALLOCATORS
28 if( index
>= buffer
->capacity
|| index
< 0 )
30 printf( "index out of capactity (%d /: [0->%d (cap)]) (%s)\n", index
, buffer
->capacity
, debug_str
);
35 return buffer
->arr
+ buffer
->esize
*index
;
38 static void cxr_ab_reserve( struct cxr_auto_buffer
*buffer
, u32 count
)
40 if( buffer
->count
+ count
> buffer
->capacity
)
42 buffer
->capacity
= cxr_max(buffer
->capacity
*2, buffer
->capacity
+count
);
43 buffer
->arr
= realloc( buffer
->arr
, buffer
->capacity
*buffer
->esize
);
47 static void *cxr_ab_empty( struct cxr_auto_buffer
*buffer
)
49 cxr_ab_reserve( buffer
, 1 );
50 return cxr_ab_ptr( buffer
, buffer
->count
++ );
53 static void *cxr_ab_empty_at( struct cxr_auto_buffer
*buffer
, int at
)
55 cxr_ab_reserve( buffer
, 1 );
57 if( at
== buffer
->count
)
60 return cxr_ab_ptr( buffer
, at
);
66 cxr_ab_ptr( buffer
, at
+1 ),
67 cxr_ab_ptr( buffer
, at
),
68 (buffer
->count
-at
)*buffer
->esize
72 return cxr_ab_ptr( buffer
, at
);
75 static void cxr_ab_push( struct cxr_auto_buffer
*buffer
, void *em
)
77 cxr_ab_reserve( buffer
, 1 );
79 memcpy( buffer
->arr
+buffer
->count
*buffer
->esize
, em
, buffer
->esize
);
83 static void cxr_ab_init( struct cxr_auto_buffer
*buffer
, u32 esize
, u32 cap
)
85 buffer
->esize
= esize
;
86 buffer
->capacity
= cxr_max(1,cap
);
89 buffer
->arr
= malloc( buffer
->esize
*buffer
->capacity
);
92 static void cxr_ab_clear( struct cxr_auto_buffer
*buffer
)
97 static void cxr_ab_free( struct cxr_auto_buffer
*buffer
)