diff options
| author | Mattias Andrée <maandree@kth.se> | 2016-03-05 22:27:04 +0100 |
|---|---|---|
| committer | Mattias Andrée <maandree@kth.se> | 2016-03-05 22:28:33 +0100 |
| commit | c1f4d263ec1004512cdd6b38b351eb2fe2321c22 (patch) | |
| tree | ff884393424694c79eb87d16f13b151ba0233ec7 /src/internals.h | |
| parent | zinit is now an inline function (diff) | |
| download | libzahl-c1f4d263ec1004512cdd6b38b351eb2fe2321c22.tar.gz libzahl-c1f4d263ec1004512cdd6b38b351eb2fe2321c22.tar.bz2 libzahl-c1f4d263ec1004512cdd6b38b351eb2fe2321c22.tar.xz | |
Add memory pool, also let the user know that libzahl is not designed for cryptography
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'src/internals.h')
| -rw-r--r-- | src/internals.h | 17 |
1 files changed, 5 insertions, 12 deletions
diff --git a/src/internals.h b/src/internals.h index 5c0ac32..8a9c379 100644 --- a/src/internals.h +++ b/src/internals.h @@ -56,6 +56,9 @@ extern z_t libzahl_tmp_divmod_ds[BITS_PER_CHAR]; extern jmp_buf libzahl_jmp_buf; extern int libzahl_set_up; extern int libzahl_error; +extern zahl_char_t **libzahl_pool[sizeof(size_t) * 8]; +extern size_t libzahl_pool_n[sizeof(size_t) * 8]; +extern size_t libzahl_pool_alloc[sizeof(size_t) * 8]; #define FAILURE(error) (libzahl_error = (error), longjmp(libzahl_jmp_buf, 1)) #define zmemcpy(d, s, n) memcpy(d, s, (n) * sizeof(zahl_char_t)) @@ -65,19 +68,9 @@ extern int libzahl_error; #define SET_SIGNUM(a, signum) ((a)->sign = (signum)) #define SET(a, b) do { if ((a) != (b)) zset(a, b); } while (0) -#define ENSURE_SIZE(a, n) do { if ((a)->alloced < (n)) zahl_realloc(a, (n)); } while (0) +#define ENSURE_SIZE(a, n) do { if ((a)->alloced < (n)) libzahl_realloc(a, (n)); } while (0) #define MIN(a, b) ((a) < (b) ? (a) : (b)) #define MAX(a, b) ((a) > (b) ? (a) : (b)) -static inline void -zahl_realloc(z_t p, size_t n) -{ - p->chars = realloc(p->chars, n * sizeof(zahl_char_t)); - if (!p->chars) { - if (!errno) /* sigh... */ - errno = ENOMEM; - FAILURE(errno); - } - p->alloced = n; -} +void libzahl_realloc(z_t a, size_t need); |
