diff options
| author | Tyge Løvset <[email protected]> | 2023-01-31 13:26:04 +0100 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2023-01-31 13:41:33 +0100 |
| commit | a24ecd6bbfffc2e0b75b8ed48fcb5306d367ad3e (patch) | |
| tree | a9231182b09e139af14920dc6701dded80761793 | |
| parent | 5bbcae2a3add163ea3b7a91d65fda6836c18f410 (diff) | |
| download | STC-modified-a24ecd6bbfffc2e0b75b8ed48fcb5306d367ad3e.tar.gz STC-modified-a24ecd6bbfffc2e0b75b8ed48fcb5306d367ad3e.zip | |
Reverted c_MALLOC, c_CALLOC, c_REALLOC and c_FREE to lowercase.
| -rw-r--r-- | docs/ccommon_api.md | 12 | ||||
| -rw-r--r-- | include/stc/carc.h | 4 | ||||
| -rw-r--r-- | include/stc/cbits.h | 10 | ||||
| -rw-r--r-- | include/stc/cbox.h | 2 | ||||
| -rw-r--r-- | include/stc/ccommon.h | 55 | ||||
| -rw-r--r-- | include/stc/cdeq.h | 6 | ||||
| -rw-r--r-- | include/stc/clist.h | 2 | ||||
| -rw-r--r-- | include/stc/cmap.h | 14 | ||||
| -rw-r--r-- | include/stc/cpque.h | 4 | ||||
| -rw-r--r-- | include/stc/csmap.h | 4 | ||||
| -rw-r--r-- | include/stc/cstack.h | 10 | ||||
| -rw-r--r-- | include/stc/cstr.h | 12 | ||||
| -rw-r--r-- | include/stc/cvec.h | 4 | ||||
| -rw-r--r-- | include/stc/priv/altnames.h | 4 | ||||
| -rw-r--r-- | misc/archived/csmap.h | 4 | ||||
| -rw-r--r-- | misc/archived/cstr.h | 12 | ||||
| -rw-r--r-- | misc/examples/rawptr_elements.c | 2 | ||||
| -rw-r--r-- | misc/examples/shape.c | 2 | ||||
| -rw-r--r-- | src/cregex.c | 14 |
19 files changed, 83 insertions, 94 deletions
diff --git a/docs/ccommon_api.md b/docs/ccommon_api.md index 6f09a130..18edbeba 100644 --- a/docs/ccommon_api.md +++ b/docs/ccommon_api.md @@ -342,23 +342,23 @@ uint64_t crawstr_hash(const crawstr* x); | Usage | Meaning | |:----------------------------|:-------------------------------------------| | `c_NEW (type, value)` | Allocate and init a new object on the heap | -| `c_ALLOC (type)` | `(type *) c_MALLOC(sizeof(type))` | -| `c_ALLOC_N (type, N)` | `(type *) c_MALLOC((N)*sizeof(type))` | +| `c_ALLOC (type)` | `(type *) c_malloc(c_sizeof(type))` | +| `c_ALLOC_N (type, N)` | `(type *) c_malloc((N)*c_sizeof(type))` | ```c struct Pnt { double x, y, z; }; struct Pnt *pnt = c_NEW(struct Pnt, {1.2, 3.4, 5.6}); -c_FREE(pnt); +c_free(pnt); int* array = c_ALLOC_N(int, 100); -c_FREE(array); +c_free(array); ``` -### c_MALLOC, c_CALLOC, c_REALLOC, c_FREE: customizable allocators +### c_malloc, c_calloc, c_realloc, c_free: customizable allocators Memory allocator for the entire library. Macros can be overridden by the user. ### c_ARRAYLEN -- **c_ARRAYLEN(array)**: Return number of elements in an array. +- **c_ARRAYLEN(array)**: Return number of elements in an array. array must not be a pointer! ```c int array[] = {1, 2, 3, 4}; size_t n = c_ARRAYLEN(array); diff --git a/include/stc/carc.h b/include/stc/carc.h index 4f55aefb..5bf4ebc2 100644 --- a/include/stc/carc.h +++ b/include/stc/carc.h @@ -127,8 +127,8 @@ STC_INLINE void _cx_memb(_drop)(_cx_self* self) { if (self->use_count && _i_atomic_dec_and_test(self->use_count)) { i_keydrop(self->get); if ((char *)self->get != (char *)self->use_count + offsetof(struct _cx_memb(_rep_), value)) - c_FREE(self->get); - c_FREE((long*)self->use_count); + c_free(self->get); + c_free((long*)self->use_count); } } diff --git a/include/stc/cbits.h b/include/stc/cbits.h index 232be16b..41ee1713 100644 --- a/include/stc/cbits.h +++ b/include/stc/cbits.h @@ -125,7 +125,7 @@ struct { uint64_t *data64; size_t _size; } typedef i_type; STC_INLINE cbits cbits_init(void) { return c_LITERAL(cbits){NULL}; } STC_INLINE void cbits_create(cbits* self) { self->data64 = NULL; self->_size = 0; } -STC_INLINE void cbits_drop(cbits* self) { c_FREE(self->data64); } +STC_INLINE void cbits_drop(cbits* self) { c_free(self->data64); } STC_INLINE size_t cbits_size(const cbits* self) { return self->_size; } STC_INLINE cbits* cbits_take(cbits* self, cbits other) { @@ -138,7 +138,7 @@ STC_INLINE cbits* cbits_take(cbits* self, cbits other) { STC_INLINE cbits cbits_clone(cbits other) { const size_t bytes = _cbits_bytes(other._size); - cbits set = {(uint64_t *)memcpy(c_MALLOC(bytes), other.data64, bytes), other._size}; + cbits set = {(uint64_t *)memcpy(c_malloc(bytes), other.data64, bytes), other._size}; return set; } @@ -153,7 +153,7 @@ STC_INLINE cbits* cbits_copy(cbits* self, const cbits* other) { STC_INLINE void cbits_resize(cbits* self, const size_t size, const bool value) { const size_t new_n = _cbits_words(size), osize = self->_size, old_n = _cbits_words(osize); - self->data64 = (uint64_t *)c_REALLOC(self->data64, new_n*8); + self->data64 = (uint64_t *)c_realloc(self->data64, new_n*8); self->_size = size; if (new_n >= old_n) { memset(self->data64 + old_n, -(int)value, (new_n - old_n)*8); @@ -175,13 +175,13 @@ STC_INLINE cbits cbits_move(cbits* self) { } STC_INLINE cbits cbits_with_size(const size_t size, const bool value) { - cbits set = {(uint64_t *)c_MALLOC(_cbits_bytes(size)), size}; + cbits set = {(uint64_t *)c_malloc(_cbits_bytes(size)), size}; cbits_set_all(&set, value); return set; } STC_INLINE cbits cbits_with_pattern(const size_t size, const uint64_t pattern) { - cbits set = {(uint64_t *)c_MALLOC(_cbits_bytes(size)), size}; + cbits set = {(uint64_t *)c_malloc(_cbits_bytes(size)), size}; cbits_set_pattern(&set, pattern); return set; } diff --git a/include/stc/cbox.h b/include/stc/cbox.h index 0b6c29ec..4f0a2976 100644 --- a/include/stc/cbox.h +++ b/include/stc/cbox.h @@ -100,7 +100,7 @@ STC_INLINE _cx_raw _cx_memb(_toraw)(const _cx_self* self) STC_INLINE void _cx_memb(_drop)(_cx_self* self) { if (self->get) { i_keydrop(self->get); - c_FREE(self->get); + c_free(self->get); } } diff --git a/include/stc/ccommon.h b/include/stc/ccommon.h index 7c25d397..39ece500 100644 --- a/include/stc/ccommon.h +++ b/include/stc/ccommon.h @@ -68,51 +68,44 @@ #ifdef __cplusplus #include <new> - #define c_ALLOC(T) static_cast<T*>(c_MALLOC(sizeof(T))) - #define c_ALLOC_N(T, n) static_cast<T*>(c_MALLOC(sizeof(T)*(n))) + #define c_ALLOC(T) static_cast<T*>(c_malloc(c_sizeof(T))) + #define c_ALLOC_N(T, n) static_cast<T*>(c_malloc(c_sizeof(T)*(n))) #define c_NEW(T, ...) new (c_ALLOC(T)) T(__VA_ARGS__) #define c_LITERAL(T) T #else - #define c_ALLOC(T) ((T*)c_MALLOC(sizeof(T))) - #define c_ALLOC_N(T, n) ((T*)c_MALLOC(sizeof(T)*(n))) + #define c_ALLOC(T) ((T*)c_malloc(c_sizeof(T))) + #define c_ALLOC_N(T, n) ((T*)c_malloc(c_sizeof(T)*(n))) #define c_NEW(T, ...) ((T*)memcpy(c_ALLOC(T), (T[]){__VA_ARGS__}, sizeof(T))) #define c_LITERAL(T) (T) #endif -#ifndef c_MALLOC - #define c_MALLOC(sz) malloc(sz) - #define c_CALLOC(n, sz) calloc(n, sz) - #define c_REALLOC(p, sz) realloc(p, sz) - #define c_FREE(p) free(p) -#endif #ifndef c_malloc #define c_malloc(sz) malloc(c_i2u(sz)) #define c_calloc(n, sz) calloc(c_i2u(n), c_i2u(sz)) #define c_realloc(p, sz) realloc(p, c_i2u(sz)) #define c_free(p) free(p) #endif - #define c_static_assert(b) ((int)(0*sizeof(int[(b) ? 1 : -1]))) #define c_container_of(p, T, m) ((T*)((char*)(p) + 0*sizeof((p) == &((T*)0)->m) - offsetof(T, m))) -#define c_delete(T, ptr) do { T *_tp = ptr; T##_drop(_tp); c_FREE(_tp); } while (0) +#define c_delete(T, ptr) do { T *_tp = ptr; T##_drop(_tp); c_free(_tp); } while (0) #define c_swap(T, xp, yp) do { T *_xp = xp, *_yp = yp, \ _tv = *_xp; *_xp = *_yp; *_yp = _tv; } while (0) -#define c_LTu(a, b) ((size_t)(a) < (size_t)(b)) -#define c_u2i(u) ((intptr_t)((u) + 0*sizeof((u) == 1U))) -#define c_i2u(i) ((size_t)(i) + 0*sizeof((i) == 1)) -#define c_sizeof(x) (intptr_t)sizeof(x) +#define c_sizeof (intptr_t)sizeof +#define c_strlen(str) (intptr_t)strlen(str) +#define c_strncmp(d, s, ilen) strncmp(d, s, c_i2u(ilen)) #define c_memcpy(d, s, ilen) memcpy(d, s, c_i2u(ilen)) #define c_memmove(d, s, ilen) memmove(d, s, c_i2u(ilen)) #define c_memcmp(d, s, ilen) memcmp(d, s, c_i2u(ilen)) -#define c_strlen(str) (intptr_t)strlen(str) -#define c_strncmp(d, s, ilen) strncmp(d, s, c_i2u(ilen)) +#define c_u2i(u) ((intptr_t)((u) + 0*sizeof((u) == 1U))) +#define c_i2u(i) ((size_t)(i) + 0*sizeof((i) == 1)) +#define c_LTu(a, b) ((size_t)(a) < (size_t)(b)) // x and y are i_keyraw* type, defaults to i_key*: #define c_default_cmp(x, y) (c_default_less(y, x) - c_default_less(x, y)) #define c_default_less(x, y) (*(x) < *(y)) #define c_default_eq(x, y) (*(x) == *(y)) #define c_memcmp_eq(x, y) (memcmp(x, y, sizeof *(x)) == 0) -#define c_default_hash(x) cfasthash(x, sizeof *(x)) +#define c_default_hash(x) cfasthash(x, c_sizeof(*(x))) #define c_default_clone(v) (v) #define c_default_toraw(vp) (*(vp)) @@ -131,12 +124,12 @@ /* Function macros and others */ #define c_make(C, ...) \ - C##_from_n((C##_raw[])__VA_ARGS__, sizeof((C##_raw[])__VA_ARGS__)/sizeof(C##_raw)) + C##_from_n((C##_raw[])__VA_ARGS__, c_sizeof((C##_raw[])__VA_ARGS__)/c_sizeof(C##_raw)) typedef const char* crawstr; #define crawstr_cmp(xp, yp) strcmp(*(xp), *(yp)) #define crawstr_hash(p) cstrhash(*(p)) -#define crawstr_len(literal) (sizeof("" literal) - 1U) +#define crawstr_len(literal) (c_sizeof("" literal) - 1) #define c_ARRAYLEN(a) (intptr_t)(sizeof(a)/sizeof 0[a]) #define c_SV(...) c_MACRO_OVERLOAD(c_SV, __VA_ARGS__) @@ -147,9 +140,9 @@ typedef const char* crawstr; #define _c_ROTL(x, k) (x << (k) | x >> (8*sizeof(x) - (k))) -STC_INLINE uint64_t cfasthash(const void* key, size_t len) { +STC_INLINE uint64_t cfasthash(const void* key, intptr_t len) { const uint8_t *x = (const uint8_t*) key; - uint64_t u8, h = 1; size_t n = len >> 3; + uint64_t u8, h = 1; intptr_t n = len >> 3; uint32_t u4; while (n--) { memcpy(&u8, x, 8), x += 8; @@ -166,15 +159,15 @@ STC_INLINE uint64_t cfasthash(const void* key, size_t len) { } STC_INLINE uint64_t cstrhash(const char *str) - { return cfasthash(str, strlen(str)); } + { return cfasthash(str, c_strlen(str)); } STC_INLINE char* cstrnstrn(const char *str, const char *needle, - size_t slen, const size_t nlen) { + intptr_t slen, const intptr_t nlen) { if (!nlen) return (char *)str; if (nlen > slen) return NULL; slen -= nlen; do { - if (*str == *needle && !memcmp(str, needle, nlen)) + if (*str == *needle && !c_memcmp(str, needle, nlen)) return (char *)str; ++str; } while (slen--); @@ -191,7 +184,7 @@ STC_INLINE char* cstrnstrn(const char *str, const char *needle, ; it.ref != (C##_value*)_endref; C##_next(&it)) #define c_FORWHILE(i, C, start, cond) \ - for (struct {C##_iter it; C##_value *ref; size_t index;} \ + for (struct {C##_iter it; C##_value *ref; intptr_t index;} \ i = {.it=start, .ref=i.it.ref}; i.it.ref && (cond) \ ; C##_next(&i.it), i.ref = i.it.ref, ++i.index) @@ -211,7 +204,7 @@ STC_INLINE char* cstrnstrn(const char *str, const char *needle, #ifndef __cplusplus #define c_FORLIST(it, T, ...) \ for (struct {T* data; T* ref; int size, index;} \ - it = {.data=(T[])__VA_ARGS__, .ref=it.data, .size=sizeof((T[])__VA_ARGS__)/sizeof(T)} \ + it = {.data=(T[])__VA_ARGS__, .ref=it.data, .size=(int)(sizeof((T[])__VA_ARGS__)/sizeof(T))} \ ; it.index < it.size; ++it.ref, ++it.index) #else #include <initializer_list> @@ -244,12 +237,12 @@ STC_INLINE char* cstrnstrn(const char *str, const char *needle, #define c_drop(C, ...) do { c_FORLIST (_i, C*, {__VA_ARGS__}) C##_drop(*_i.ref); } while(0) #define c_find_if(...) c_MACRO_OVERLOAD(c_find_if, __VA_ARGS__) #define c_find_if_4(it, C, cnt, pred) do { \ - size_t index = 0; \ + intptr_t index = 0; \ for (it = C##_begin(&cnt); it.ref && !(pred); C##_next(&it)) \ ++index; \ } while (0) #define c_find_if_5(it, C, start, end, pred) do { \ - size_t index = 0; \ + intptr_t index = 0; \ const C##_value* _endref = (end).ref; \ for (it = start; it.ref != _endref && !(pred); C##_next(&it)) \ ++index; \ @@ -258,7 +251,7 @@ STC_INLINE char* cstrnstrn(const char *str, const char *needle, #define c_erase_if(it, C, cnt, pred) do { \ C##_iter it = C##_begin(&cnt); \ - for (size_t index = 0; it.ref; ++index) { \ + for (intptr_t index = 0; it.ref; ++index) { \ if (pred) it = C##_erase_at(&cnt, it); \ else C##_next(&it); \ } \ diff --git a/include/stc/cdeq.h b/include/stc/cdeq.h index d17182b1..f648547b 100644 --- a/include/stc/cdeq.h +++ b/include/stc/cdeq.h @@ -229,7 +229,7 @@ STC_DEF void _cx_memb(_shrink_to_fit)(_cx_self *self) { if (self->_len != self->_cap) { memmove(self->_base, self->data, self->_len*sizeof(i_key)); - _cx_value* d = (_cx_value*)c_REALLOC(self->_base, self->_len*sizeof(i_key)); + _cx_value* d = (_cx_value*)c_realloc(self->_base, self->_len*sizeof(i_key)); if (d) { self->_base = d; self->_cap = self->_len; @@ -242,7 +242,7 @@ STC_DEF void _cx_memb(_drop)(_cx_self* self) { if (self->_base) { _cx_memb(_clear)(self); - c_FREE(self->_base); + c_free(self->_base); } } @@ -250,7 +250,7 @@ static size_t _cx_memb(_realloc_)(_cx_self* self, const size_t n) { const size_t cap = (size_t)((float)self->_len*1.7f) + n + 7U; const size_t nfront = _cdeq_nfront(self); - _cx_value* d = (_cx_value*)c_REALLOC(self->_base, cap*sizeof(i_key)); + _cx_value* d = (_cx_value*)c_realloc(self->_base, cap*sizeof(i_key)); if (!d) return 0; self->_cap = cap; diff --git a/include/stc/clist.h b/include/stc/clist.h index fc4d8540..4eac2954 100644 --- a/include/stc/clist.h +++ b/include/stc/clist.h @@ -348,7 +348,7 @@ STC_DEF void _cx_memb(_erase_node_after)(_cx_self* self, _cx_node* ref) { _cx_node* node = _cx_memb(_unlink_node_after)(self, ref); i_keydrop((&node->value)); - c_FREE(node); + c_free(node); } STC_DEF _cx_node* diff --git a/include/stc/cmap.h b/include/stc/cmap.h index 49d7d159..f9cd6986 100644 --- a/include/stc/cmap.h +++ b/include/stc/cmap.h @@ -312,8 +312,8 @@ STC_INLINE void _cx_memb(_wipe_)(_cx_self* self) { STC_DEF void _cx_memb(_drop)(_cx_self* self) { _cx_memb(_wipe_)(self); - c_FREE(self->_hashx); - c_FREE((void *) self->table); + c_free(self->_hashx); + c_free((void *) self->table); } STC_DEF void _cx_memb(_clear)(_cx_self* self) { @@ -390,9 +390,9 @@ STC_DEF _cx_self _cx_memb(_clone)(_cx_self m) { if (m.table) { _cx_value *t = c_ALLOC_N(_cx_value, m.bucket_count), *dst = t, *m_end = m.table + m.bucket_count; - uint8_t *h = (uint8_t *)memcpy(c_MALLOC(m.bucket_count + 1), m._hashx, m.bucket_count + 1); + uint8_t *h = (uint8_t *)memcpy(c_malloc(m.bucket_count + 1), m._hashx, m.bucket_count + 1); if (!(t && h)) - { c_FREE(t), c_FREE(h), t = 0, h = 0, m.bucket_count = 0; } + { c_free(t), c_free(h), t = 0, h = 0, m.bucket_count = 0; } else for (; m.table != m_end; ++m.table, ++m._hashx, ++dst) if (*m._hashx) @@ -416,7 +416,7 @@ _cx_memb(_reserve)(_cx_self* self, const size_t _newcap) { #endif _cx_self m = { c_ALLOC_N(_cx_value, _nbuckets), - (uint8_t *) c_CALLOC(_nbuckets + 1, 1), + (uint8_t *) c_calloc(_nbuckets + 1, 1), self->size, (i_size)_nbuckets, }; bool ok = m.table && m._hashx; @@ -432,8 +432,8 @@ _cx_memb(_reserve)(_cx_self* self, const size_t _newcap) { } c_swap(_cx_self, self, &m); } - c_FREE(m._hashx); - c_FREE(m.table); + c_free(m._hashx); + c_free(m.table); return ok; } diff --git a/include/stc/cpque.h b/include/stc/cpque.h index 8bb70216..59419f16 100644 --- a/include/stc/cpque.h +++ b/include/stc/cpque.h @@ -55,7 +55,7 @@ STC_INLINE _cx_self _cx_memb(_from_n)(const _cx_raw* raw, size_t n) STC_INLINE bool _cx_memb(_reserve)(_cx_self* self, const size_t cap) { if (cap != self->_len && cap <= self->_cap) return true; - _cx_value *d = (_cx_value *)c_REALLOC(self->data, cap*sizeof *d); + _cx_value *d = (_cx_value *)c_realloc(self->data, cap*sizeof *d); return d ? (self->data = d, self->_cap = cap, true) : false; } @@ -79,7 +79,7 @@ STC_INLINE void _cx_memb(_clear)(_cx_self* self) { } STC_INLINE void _cx_memb(_drop)(_cx_self* self) - { _cx_memb(_clear)(self); c_FREE(self->data); } + { _cx_memb(_clear)(self); c_free(self->data); } STC_INLINE size_t _cx_memb(_size)(const _cx_self* q) { return q->_len; } diff --git a/include/stc/csmap.h b/include/stc/csmap.h index fba08eba..b92d25d8 100644 --- a/include/stc/csmap.h +++ b/include/stc/csmap.h @@ -228,7 +228,7 @@ STC_DEF bool _cx_memb(_reserve)(_cx_self* self, const size_t cap) { if (cap <= self->cap) return false; - _cx_node* nodes = (_cx_node*)c_REALLOC(self->nodes, (cap + 1)*sizeof(_cx_node)); + _cx_node* nodes = (_cx_node*)c_realloc(self->nodes, (cap + 1)*sizeof(_cx_node)); if (!nodes) return false; nodes[0] = c_LITERAL(_cx_node){{0, 0}, 0}; @@ -578,7 +578,7 @@ STC_DEF void _cx_memb(_drop)(_cx_self* self) { if (self->cap) { _cx_memb(_drop_r_)(self->nodes, self->root); - c_FREE(self->nodes); + c_free(self->nodes); } } diff --git a/include/stc/cstack.h b/include/stc/cstack.h index 2a4d620d..69ea6f0c 100644 --- a/include/stc/cstack.h +++ b/include/stc/cstack.h @@ -59,12 +59,12 @@ STC_INLINE void _cx_memb(_create)(_cx_self* self) { self->_len = 0; self->_cap = 0; self->data = NULL; } STC_INLINE _cx_self _cx_memb(_with_capacity)(size_t cap) { - _cx_self out = {(_cx_value *) c_MALLOC(cap*sizeof(i_key)), 0, cap}; + _cx_self out = {(_cx_value *) c_malloc(cap*sizeof(i_key)), 0, cap}; return out; } STC_INLINE _cx_self _cx_memb(_with_size)(size_t size, i_key null) { - _cx_self out = {(_cx_value *) c_MALLOC(size*sizeof null), size, size}; + _cx_self out = {(_cx_value *) c_malloc(size*sizeof null), size, size}; while (size) out.data[--size] = null; return out; } @@ -79,7 +79,7 @@ STC_INLINE void _cx_memb(_clear)(_cx_self* self) { STC_INLINE void _cx_memb(_drop)(_cx_self* self) { _cx_memb(_clear)(self); #ifndef i_capacity - c_FREE(self->data); + c_free(self->data); #endif } @@ -100,7 +100,7 @@ STC_INLINE size_t _cx_memb(_capacity)(const _cx_self* self) { STC_INLINE bool _cx_memb(_reserve)(_cx_self* self, size_t n) { if (n < self->_len) return true; #ifndef i_capacity - _cx_value *t = (_cx_value *)c_REALLOC(self->data, n*sizeof *t); + _cx_value *t = (_cx_value *)c_realloc(self->data, n*sizeof *t); if (t) { self->_cap = n, self->data = t; return true; } #endif return false; @@ -154,7 +154,7 @@ STC_INLINE _cx_value* _cx_memb(_emplace)(_cx_self* self, _cx_raw raw) #if !defined i_no_clone STC_INLINE _cx_self _cx_memb(_clone)(_cx_self v) { - _cx_self out = {(_cx_value *)c_MALLOC(v._len*sizeof(_cx_value)), v._len, v._len}; + _cx_self out = {(_cx_value *)c_malloc(v._len*sizeof(_cx_value)), v._len, v._len}; if (!out.data) out._cap = 0; else for (size_t i = 0; i < v._len; ++v.data) out.data[i++] = i_keyclone((*v.data)); diff --git a/include/stc/cstr.h b/include/stc/cstr.h index 071e40e8..9f6415ac 100644 --- a/include/stc/cstr.h +++ b/include/stc/cstr.h @@ -62,7 +62,7 @@ enum { cstr_s_cap = sizeof(cstr_buf) - 2 }; #define cstr_l_size(s) ((s)->lon.size) #define cstr_l_set_size(s, len) ((s)->lon.data[(s)->lon.size = (len)] = 0) #define cstr_l_data(s) (s)->lon.data -#define cstr_l_drop(s) c_FREE((s)->lon.data) +#define cstr_l_drop(s) c_free((s)->lon.data) #define cstr_is_long(s) ((s)->sml.size > 127) STC_API char* _cstr_init(cstr* self, size_t len, size_t cap); @@ -471,7 +471,7 @@ STC_DEF char* _cstr_internal_move(cstr* self, const size_t pos1, const size_t po STC_DEF char* _cstr_init(cstr* self, const size_t len, const size_t cap) { if (cap > cstr_s_cap) { - self->lon.data = (char *)c_MALLOC(cap + 1); + self->lon.data = (char *)c_malloc(cap + 1); cstr_l_set_size(self, len); cstr_l_set_cap(self, cap); return self->lon.data; @@ -485,26 +485,26 @@ STC_DEF void cstr_shrink_to_fit(cstr* self) { if (r.size == r.cap) return; if (r.size > cstr_s_cap) { - self->lon.data = (char *)c_REALLOC(self->lon.data, r.size + 1); + self->lon.data = (char *)c_realloc(self->lon.data, r.size + 1); cstr_l_set_cap(self, r.size); } else if (r.cap > cstr_s_cap) { memcpy(self->sml.data, r.data, r.size + 1); cstr_s_set_size(self, r.size); - c_FREE(r.data); + c_free(r.data); } } STC_DEF char* cstr_reserve(cstr* self, const size_t cap) { if (cstr_is_long(self)) { if (cap > cstr_l_cap(self)) { - self->lon.data = (char *)c_REALLOC(self->lon.data, cap + 1); + self->lon.data = (char *)c_realloc(self->lon.data, cap + 1); cstr_l_set_cap(self, cap); } return self->lon.data; } /* from short to long: */ if (cap > cstr_s_cap) { - char* data = (char *)c_MALLOC(cap + 1); + char* data = (char *)c_malloc(cap + 1); const size_t len = cstr_s_size(self); memcpy(data, self->sml.data, cstr_s_cap + 1); self->lon.data = data; diff --git a/include/stc/cvec.h b/include/stc/cvec.h index 2ff2c58a..83d94652 100644 --- a/include/stc/cvec.h +++ b/include/stc/cvec.h @@ -277,13 +277,13 @@ _cx_memb(_drop)(_cx_self* self) { if (self->_cap == 0) return; _cx_memb(_clear)(self); - c_FREE(self->data); + c_free(self->data); } STC_DEF bool _cx_memb(_reserve)(_cx_self* self, const size_t cap) { if (cap > self->_cap || (cap && cap == self->_len)) { - _cx_value* d = (_cx_value*)c_REALLOC(self->data, cap*sizeof(i_key)); + _cx_value* d = (_cx_value*)c_realloc(self->data, cap*sizeof(i_key)); if (!d) return false; self->data = d; diff --git a/include/stc/priv/altnames.h b/include/stc/priv/altnames.h index 695d3ebc..024868c2 100644 --- a/include/stc/priv/altnames.h +++ b/include/stc/priv/altnames.h @@ -23,10 +23,6 @@ #define c_alloc c_ALLOC #define c_alloc_n c_ALLOC_N #define c_new c_NEW -#define c_malloc c_MALLOC -#define c_calloc c_CALLOC -#define c_realloc c_REALLOC -#define c_free c_FREE #define c_arraylen c_ARRAYLEN #define c_forlist c_FORLIST #define c_forrange c_FORRANGE diff --git a/misc/archived/csmap.h b/misc/archived/csmap.h index 6f3ee98b..aa7fc85e 100644 --- a/misc/archived/csmap.h +++ b/misc/archived/csmap.h @@ -400,7 +400,7 @@ _cx_memb(_erase_r_)(_cx_node *tn, const _cx_rawkey* rkey, int *erased) { } else { /* unlink node */ tx = tn; tn = tn->link[tn->link[0]->level == 0]; - c_FREE(tx); + c_free(tx); } } if (tn->link[0]->level < tn->level - 1 || tn->link[1]->level < tn->level - 1) { @@ -492,7 +492,7 @@ _cx_memb(_drop_r_)(_cx_node* tn) { _cx_memb(_drop_r_)(tn->link[0]); _cx_memb(_drop_r_)(tn->link[1]); _cx_memb(_value_drop)(&tn->value); - c_FREE(tn); + c_free(tn); } } diff --git a/misc/archived/cstr.h b/misc/archived/cstr.h index f4e9dde2..9111fe6d 100644 --- a/misc/archived/cstr.h +++ b/misc/archived/cstr.h @@ -77,7 +77,7 @@ STC_INLINE size_t cstr_size(const cstr* self) { return _cstr_p(self)->size STC_INLINE size_t cstr_capacity(cstr s) { return _cstr_p(&s)->cap; } STC_INLINE bool cstr_empty(cstr s) { return _cstr_p(&s)->size == 0; } STC_INLINE void cstr_drop(cstr* self) - { if (_cstr_p(self)->cap) c_FREE(_cstr_p(self)); } + { if (_cstr_p(self)->cap) c_free(_cstr_p(self)); } STC_INLINE cstr cstr_clone(cstr s) { return cstr_from_n(s.str, _cstr_p(&s)->size); } STC_INLINE void cstr_clear(cstr* self) @@ -142,7 +142,7 @@ STC_INLINE char* cstr_append_uninit(cstr *self, size_t n) { STC_INLINE cstr* cstr_take(cstr* self, cstr s) { if (self->str != s.str && _cstr_p(self)->cap) - c_FREE(_cstr_p(self)); + c_free(_cstr_p(self)); self->str = s.str; return self; } @@ -202,7 +202,7 @@ cstr_reserve(cstr* self, const size_t cap) { cstr_priv *p = _cstr_p(self); const size_t oldcap = p->cap; if (cap > oldcap) { - p = (cstr_priv*) c_REALLOC(((oldcap != 0) & (p != &_cstr_nullrep)) ? p : NULL, _cstr_opt_mem(cap)); + p = (cstr_priv*) c_realloc(((oldcap != 0) & (p != &_cstr_nullrep)) ? p : NULL, _cstr_opt_mem(cap)); if (!p) return NULL; self->str = p->chr; if (oldcap == 0) self->str[p->size = 0] = '\0'; @@ -222,7 +222,7 @@ cstr_resize(cstr* self, const size_t len, const char fill) { STC_DEF cstr cstr_from_n(const char* str, const size_t n) { if (n == 0) return cstr_NULL; - cstr_priv* prv = (cstr_priv*) c_MALLOC(_cstr_opt_mem(n)); + cstr_priv* prv = (cstr_priv*) c_malloc(_cstr_opt_mem(n)); cstr s = {(char *) memcpy(prv->chr, str, n)}; s.str[prv->size = n] = '\0'; prv->cap = _cstr_opt_cap(n); @@ -313,11 +313,11 @@ STC_DEF void cstr_replace_at_sv(cstr* self, const size_t pos, size_t len, csview repl) { const size_t sz = cstr_size(self); if (len > sz - pos) len = sz - pos; - char buf[256], *xstr = repl.size > 256 ? c_MALLOC(repl.size) : buf; + char buf[256], *xstr = repl.size > 256 ? c_malloc(repl.size) : buf; memcpy(xstr, repl.str, repl.size); _cstr_internal_move(self, pos + len, pos + repl.size); memcpy(&self->str[pos], xstr, repl.size); - if (repl.size > 256) c_FREE(xstr); + if (repl.size > 256) c_free(xstr); } STC_DEF cstr diff --git a/misc/examples/rawptr_elements.c b/misc/examples/rawptr_elements.c index 05910c77..96a9ba86 100644 --- a/misc/examples/rawptr_elements.c +++ b/misc/examples/rawptr_elements.c @@ -13,7 +13,7 @@ typedef int64_t inttype; #define i_valfrom(raw) c_NEW(inttype, raw) #define i_valto(x) **x #define i_valclone(x) c_NEW(inttype, *x) -#define i_valdrop(x) c_FREE(*x) +#define i_valdrop(x) c_free(*x) #include <stc/cmap.h> // With cbox: diff --git a/misc/examples/shape.c b/misc/examples/shape.c index 75a5e174..9ce0b946 100644 --- a/misc/examples/shape.c +++ b/misc/examples/shape.c @@ -38,7 +38,7 @@ void Shape_delete(Shape* shape) { if (shape) { shape->api->drop(shape); - c_FREE(shape); + c_free(shape); } } diff --git a/src/cregex.c b/src/cregex.c index cf2f8eaf..8cffd077 100644 --- a/src/cregex.c +++ b/src/cregex.c @@ -549,7 +549,7 @@ _optimize(_Parser *par, _Reprog *pp) */ intptr_t ipp = (intptr_t)pp; size_t size = sizeof(_Reprog) + (size_t)(par->freep - pp->firstinst)*sizeof(_Reinst); - _Reprog *npp = (_Reprog *)c_REALLOC(pp, size); + _Reprog *npp = (_Reprog *)c_realloc(pp, size); ptrdiff_t diff = (intptr_t)npp - ipp; if ((npp == NULL) | (diff == 0)) @@ -844,10 +844,10 @@ _regcomp1(_Reprog *progp, _Parser *par, const char *s, int cflags) /* get memory for the program. estimated max usage */ const size_t instcap = 5 + 6*strlen(s); - _Reprog* pp = (_Reprog *)c_REALLOC(progp, sizeof(_Reprog) + instcap*sizeof(_Reinst)); + _Reprog* pp = (_Reprog *)c_realloc(progp, sizeof(_Reprog) + instcap*sizeof(_Reinst)); if (pp == NULL) { par->error = CREG_OUTOFMEMORY; - c_FREE(progp); + c_free(progp); return NULL; } pp->flags.icase = (cflags & CREG_C_ICASE) != 0; @@ -898,7 +898,7 @@ _regcomp1(_Reprog *progp, _Parser *par, const char *s, int cflags) pp->nsubids = (unsigned)par->cursubid; out: if (par->error) { - c_FREE(pp); + c_free(pp); pp = NULL; } return pp; @@ -1133,7 +1133,7 @@ _regexec2(const _Reprog *progp, /* program to run */ _Relist *relists; /* mark space */ - relists = (_Relist *)c_MALLOC(2 * _BIGLISTSIZE*sizeof(_Relist)); + relists = (_Relist *)c_malloc(2 * _BIGLISTSIZE*sizeof(_Relist)); if (relists == NULL) return -1; @@ -1143,7 +1143,7 @@ _regexec2(const _Reprog *progp, /* program to run */ j->reliste[1] = relists + 2*_BIGLISTSIZE - 2; rv = _regexec1(progp, bol, mp, ms, j, mflags); - c_FREE(relists); + c_free(relists); return rv; } @@ -1308,6 +1308,6 @@ cregex_replace_pattern_6(const char* pattern, const char* input, const char* rep void cregex_drop(cregex* self) { - c_FREE(self->prog); + c_free(self->prog); } #endif |
