diff options
| author | tylov <[email protected]> | 2023-07-13 08:36:14 +0200 |
|---|---|---|
| committer | tylov <[email protected]> | 2023-07-13 13:03:51 +0200 |
| commit | 0073f0a2d67239f019041f07d9a322df03fc7ae4 (patch) | |
| tree | 51e2e31d5159d2be013c54a94d3b3ff5ef624edb /include | |
| parent | ebe5abc29d51c643520301e42124365477f44957 (diff) | |
| download | STC-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')
| -rw-r--r-- | include/stc/algo/raii.h | 3 | ||||
| -rw-r--r-- | include/stc/ccommon.h | 5 | ||||
| -rw-r--r-- | include/stc/cspan.h | 9 |
3 files changed, 7 insertions, 10 deletions
diff --git a/include/stc/algo/raii.h b/include/stc/algo/raii.h index b0008a96..584f5c59 100644 --- a/include/stc/algo/raii.h +++ b/include/stc/algo/raii.h @@ -23,9 +23,6 @@ #ifndef STC_RAII_INCLUDED #define STC_RAII_INCLUDED -#define c_defer(...) \ - for (int _i = 1; _i; _i = 0, __VA_ARGS__) - #define c_with(...) c_MACRO_OVERLOAD(c_with, __VA_ARGS__) #define c_with_2(declvar, drop) \ for (declvar, *_i, **_ip = &_i; _ip; _ip = 0, drop) 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) diff --git a/include/stc/cspan.h b/include/stc/cspan.h index 4d091395..358d5bf0 100644 --- a/include/stc/cspan.h +++ b/include/stc/cspan.h @@ -130,9 +130,7 @@ using_cspan_tuple(7); using_cspan_tuple(8); #define cspan_size(self) _cspan_size((self)->shape, cspan_rank(self)) #define cspan_rank(self) c_arraylen((self)->shape) #define cspan_is_order_F(self) ((self)->stride.d[0] < (self)->stride.d[cspan_rank(self) - 1]) - #define cspan_index(self, ...) c_PASTE(cspan_idx_, c_NUMARGS(__VA_ARGS__))(self, __VA_ARGS__) - #define cspan_at(self, ...) ((self)->data + cspan_index(self, __VA_ARGS__)) #define cspan_front(self) ((self)->data) #define cspan_back(self) ((self)->data + cspan_size(self) - 1) @@ -151,7 +149,7 @@ using_cspan_tuple(7); using_cspan_tuple(8); #define cspan_submd4(OutSpan, self, ...) _cspan_submdN(OutSpan, 4, self, __VA_ARGS__) #define _cspan_submdN(OutSpan, N, self, ...) \ - _cspan_submd##N(c_static_assert(cspan_rank((OutSpan*)0) == N - c_NUMARGS(__VA_ARGS__)), self, __VA_ARGS__) + (OutSpan)_cspan_submd##N(c_static_assert(cspan_rank((OutSpan*)0) == N - c_NUMARGS(__VA_ARGS__)), self, __VA_ARGS__) #define _cspan_submd2(ok, self, x) \ {.data=cspan_at(self, x, 0) + ok, .shape={(self)->shape[1]}, .stride={.d={(self)->stride.d[1]}}} @@ -171,9 +169,8 @@ using_cspan_tuple(7); using_cspan_tuple(8); #define _cspan_submd4_5(ok, self, x, y, z) \ {.data=cspan_at(self, x, y, z, 0) + ok, .shape={(self)->shape[3]}, .stride={.d={(self)->stride.d[3]}}} -#define cspan_md(array, ...) cspan_md_ordered('C', array, __VA_ARGS__) -#define cspan_md_left(array, ...) cspan_md_ordered('F', array, __VA_ARGS__) -#define cspan_md_ordered(order, array, ...) \ +#define cspan_md(array, ...) cspan_md_order('C', array, __VA_ARGS__) +#define cspan_md_order(order, array, ...) /* order='C' or 'F' */ \ {.data=array, .shape={__VA_ARGS__}, \ .stride=*(c_PASTE(cspan_tuple, c_NUMARGS(__VA_ARGS__))*)_cspan_shape2stride(order, ((int32_t[]){__VA_ARGS__}), c_NUMARGS(__VA_ARGS__))} |
