summaryrefslogtreecommitdiff
path: root/src/shared/util.h
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2014-04-10 09:48:59 -0400
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2014-04-12 10:20:55 -0400
commitca2d37841476e6272c9957c3f5a0cbe869a531ca (patch)
treeab1dea346bd6342248858be26e9638437141a0d1 /src/shared/util.h
parent7cc832b91e8f5883b505c42f9f403e03dfc83c89 (diff)
Unify GREEDY_REALLOC and GREEDY_REALLOC_T
greedy_realloc() and greedy_realloc0() now store the allocated size as the count, not bytes. Replace GREEDY_REALLOC uses with GREEDY_REALLOC_T everywhere, and then rename GREEDY_REALLOC_T to GREEDY_REALLOC. It is just too error-prone to have two slightly different macros which do the same thing.
Diffstat (limited to 'src/shared/util.h')
-rw-r--r--src/shared/util.h22
1 files changed, 7 insertions, 15 deletions
diff --git a/src/shared/util.h b/src/shared/util.h
index 90464c940..900f1cf54 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -730,21 +730,13 @@ void *unhexmem(const char *p, size_t l);
char *strextend(char **x, ...) _sentinel_;
char *strrep(const char *s, unsigned n);
-void* greedy_realloc(void **p, size_t *allocated, size_t need);
-void* greedy_realloc0(void **p, size_t *allocated, size_t need);
-#define GREEDY_REALLOC(array, allocated, need) \
- greedy_realloc((void**) &(array), &(allocated), sizeof((array)[0]) * (need))
-#define GREEDY_REALLOC0(array, allocated, need) \
- greedy_realloc0((void**) &(array), &(allocated), sizeof((array)[0]) * (need))
-
-#define GREEDY_REALLOC0_T(array, count, need) \
- ({ \
- size_t _size = (count) * sizeof((array)[0]); \
- void *_ptr = GREEDY_REALLOC0((array), _size, (need)); \
- if (_ptr) \
- (count) = _size / sizeof((array)[0]); \
- _ptr; \
- })
+void* greedy_realloc(void **p, size_t *allocated, size_t need, size_t size);
+void* greedy_realloc0(void **p, size_t *allocated, size_t need, size_t size);
+#define GREEDY_REALLOC(array, allocated, need) \
+ greedy_realloc((void**) &(array), &(allocated), (need), sizeof((array)[0]))
+
+#define GREEDY_REALLOC0(array, allocated, need) \
+ greedy_realloc0((void**) &(array), &(allocated), (need), sizeof((array)[0]))
static inline void _reset_errno_(int *saved_errno) {
errno = *saved_errno;