blob: c7127deb747bcc102289f4dfede0516694cafa99 [file] [log] [blame]
Harald Welte898ffef2017-05-15 21:37:34 +02001#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 */
11extern void *pseudotalloc_malloc(size_t size);
12extern void pseudotalloc_free(void *ptr);
13
14typedef 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__)
23void *_talloc_zero(const void *ctx, size_t size, const char *name);
24
25#define talloc_free(ctx) _talloc_free(ctx, __location__)
26int _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__)
31void *talloc_named_const(const void *context, size_t size, const char *name);
32void talloc_set_name_const(const void *ptr, const char *name);
33char *talloc_strdup(const void *t, const char *p);
34void *talloc_pool(const void *context, size_t size);
35#define talloc_array(ctx, type, count) (type *)_talloc_array(ctx, sizeof(type), count, #type)
36void *_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)
38void *_talloc_zero_array(const void *ctx,
39 size_t el_size,
40 unsigned count,
41 const char *name);
42