summaryrefslogtreecommitdiffhomepage
path: root/include/stc/ccommon.h
diff options
context:
space:
mode:
authortylov <[email protected]>2023-07-13 08:36:14 +0200
committertylov <[email protected]>2023-07-13 13:03:51 +0200
commit0073f0a2d67239f019041f07d9a322df03fc7ae4 (patch)
tree51e2e31d5159d2be013c54a94d3b3ff5ef624edb /include/stc/ccommon.h
parentebe5abc29d51c643520301e42124365477f44957 (diff)
downloadSTC-modified-0073f0a2d67239f019041f07d9a322df03fc7ae4.tar.gz
STC-modified-0073f0a2d67239f019041f07d9a322df03fc7ae4.zip
Moved c_defer() macro from raii.h to ccommon.h. Some changes in cspan.
Diffstat (limited to 'include/stc/ccommon.h')
-rw-r--r--include/stc/ccommon.h5
1 files changed, 4 insertions, 1 deletions
diff --git a/include/stc/ccommon.h b/include/stc/ccommon.h
index efbebdc3..45c3a360 100644
--- a/include/stc/ccommon.h
+++ b/include/stc/ccommon.h
@@ -69,6 +69,7 @@ typedef long long _llong;
#define c_new(T, ...) ((T*)memcpy(malloc(sizeof(T)), ((T[]){__VA_ARGS__}), sizeof(T)))
#define c_LITERAL(T) (T)
#endif
+#define c_new_n(T, n) ((T*)malloc(sizeof(T)*(n)))
#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))
@@ -89,12 +90,12 @@ typedef long long _llong;
_tv = *_xp; *_xp = *_yp; *_yp = _tv; } while (0)
#define c_sizeof (intptr_t)sizeof
#define c_strlen(s) (intptr_t)strlen(s)
+
#define c_strncmp(a, b, ilen) strncmp(a, b, 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_memset(d, val, ilen) memset(d, val, c_i2u(ilen))
#define c_memcmp(a, b, ilen) memcmp(a, b, 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))
@@ -228,6 +229,8 @@ STC_INLINE intptr_t cnextpow2(intptr_t n) {
; it.index < it.size; ++it.ref, ++it.index)
#endif
+#define c_defer(...) \
+ for (int _i = 1; _i; _i = 0, __VA_ARGS__)
#define c_drop(C, ...) \
do { c_forlist (_i, C*, {__VA_ARGS__}) C##_drop(*_i.ref); } while(0)