Harald Welte | 898ffef | 2017-05-15 21:37:34 +0200 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | /* overly simplistic talloc replacement for deeply embedded |
| 4 | * microcontrollers. Obviously this has none of the properties of real |
| 5 | * talloc, it is particualrly not hierarchical at all */ |
| 6 | |
| 7 | #include <stdlib.h> |
| 8 | #include <stdarg.h> |
| 9 | |
| 10 | /* those two functions have to be provided by the user/environment */ |
| 11 | extern void *pseudotalloc_malloc(size_t size); |
| 12 | extern void pseudotalloc_free(void *ptr); |
| 13 | |
| 14 | typedef void TALLOC_CTX; |
| 15 | |
| 16 | #define __TALLOC_STRING_LINE1__(s) #s |
| 17 | #define __TALLOC_STRING_LINE2__(s) __TALLOC_STRING_LINE1__(s) |
| 18 | #define __TALLOC_STRING_LINE3__ __TALLOC_STRING_LINE2__(__LINE__) |
| 19 | #define __location__ __FILE__ ":" __TALLOC_STRING_LINE3__ |
| 20 | |
| 21 | #define talloc_zero(ctx, type) (type *)_talloc_zero(ctx, sizeof(type), #type) |
| 22 | #define talloc_zero_size(ctx, size) _talloc_zero(ctx, size, __location__) |
| 23 | void *_talloc_zero(const void *ctx, size_t size, const char *name); |
| 24 | |
| 25 | #define talloc_free(ctx) _talloc_free(ctx, __location__) |
| 26 | int _talloc_free(void *ptr, const char *location); |
| 27 | |
| 28 | /* Unsupported! */ |
| 29 | #define talloc(ctx, type) (type *)talloc_named_const(ctx, sizeof(type), #type) |
| 30 | #define talloc_size(ctx, size) talloc_named_const(ctx, size, __location__) |
| 31 | void *talloc_named_const(const void *context, size_t size, const char *name); |
| 32 | void talloc_set_name_const(const void *ptr, const char *name); |
| 33 | char *talloc_strdup(const void *t, const char *p); |
| 34 | void *talloc_pool(const void *context, size_t size); |
| 35 | #define talloc_array(ctx, type, count) (type *)_talloc_array(ctx, sizeof(type), count, #type) |
| 36 | void *_talloc_array(const void *ctx, size_t el_size, unsigned count, const char *name); |
| 37 | #define talloc_zero_array(ctx, type, count) (type *)_talloc_zero_array(ctx, sizeof(type), count, #type) |
| 38 | void *_talloc_zero_array(const void *ctx, |
| 39 | size_t el_size, |
| 40 | unsigned count, |
| 41 | const char *name); |
| 42 | |