From 96a572458d7ab43d19b060a867cf80c37b6473ec Mon Sep 17 00:00:00 2001 From: Tyge Løvset Date: Tue, 3 Nov 2020 09:41:36 +0100 Subject: Small API change c_withbuffer() and doc fix. --- examples/bits.c | 5 ++--- stc/carray.h | 9 +++++---- stc/cbitset.h | 10 +++++----- stc/ccommon.h | 4 ++-- stc/cstr.h | 2 +- stc/cvec.h | 2 +- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/examples/bits.c b/examples/bits.c index 8bb187a6..8e1533cc 100644 --- a/examples/bits.c +++ b/examples/bits.c @@ -8,9 +8,8 @@ int main() { cbitset_reset(&set, 9); cbitset_resize(&set, 43, false); - cstr_t str = cbitset_to_str(set); - c_print(1, " str: {}\n", str.str); - cstr_del(&str); + c_withbuffer (str, char, set.size + 1) + c_print(1, " str: {}\n", cbitset_to_str(set, str, 0, -1)); c_print(1, "{:4}: ", set.size); c_forrange (i, int, set.size) diff --git a/stc/carray.h b/stc/carray.h index 5ff95513..c7b3fd36 100644 --- a/stc/carray.h +++ b/stc/carray.h @@ -30,18 +30,19 @@ Multi-dimensional generic array allocated as one block of heap-memory. // demo: #include +#include using_carray(f, float); int main() { - carray3f a3 = carray3f_make(30, 20, 10, 0.f); + carray3f a3 = carray3f_init(30, 20, 10, 0.f); *carray3f_at(a3, 5, 4, 3) = 10.2f; // a3[5][4][3] carray2f a2 = carray3f_at1(a3, 5); // sub-array reference: a2 = a3[5] - printf("%f\n", *carray2f_at(a2, 4, 3)); // lookup a2[4][3] (=10.2f) - printf("%f\n", *carray3f_at(a3, 5, 4, 3)); // same data location, via a3 array. + c_printf(1, "{}\n", *carray2f_at(a2, 4, 3)); // lookup a2[4][3] (=10.2f) + c_printf(1, "{}\n", *carray3f_at(a3, 5, 4, 3)); // same data location, via a3 array. carray2f_del(&a2); // does nothing, since it is a sub-array. - carray3f_del(&a3); // also invalidates a2. + carray3f_del(&a3); // destroy a3, invalidates a2. } */ diff --git a/stc/cbitset.h b/stc/cbitset.h index 28c1a9ef..946f9545 100644 --- a/stc/cbitset.h +++ b/stc/cbitset.h @@ -51,7 +51,7 @@ typedef struct cbitset { uint64_t* _arr; size_t size; } cbitset_t; STC_API cbitset_t cbitset_with_size(size_t size, bool value); STC_API cbitset_t cbitset_from_str(const char* str); -STC_API cstr_t cbitset_to_str(cbitset_t set); +STC_API char* cbitset_to_str(cbitset_t set, char* str, size_t start, intptr_t stop); STC_API cbitset_t cbitset_clone(cbitset_t other); STC_API void cbitset_resize(cbitset_t* self, size_t size, bool value); STC_API size_t cbitset_count(cbitset_t set); @@ -190,10 +190,10 @@ STC_DEF cbitset_t cbitset_from_str(const char* str) { for (size_t i=0; i> 6) * 8; diff --git a/stc/ccommon.h b/stc/ccommon.h index 5b35459b..75567256 100644 --- a/stc/ccommon.h +++ b/stc/ccommon.h @@ -103,8 +103,8 @@ #define c_break_with continue #define c_withfile(f, open) for (FILE *f = open; f; fclose(f), f = NULL) -#define c_withbuffer(type, b, n) c_withbuffer_x(type, b, n, 256) -#define c_withbuffer_x(type, b, n, BYTES) \ +#define c_withbuffer(b, type, n) c_withbuffer_x(b, type, n, 256) +#define c_withbuffer_x(b, type, n, BYTES) \ for (type __b[((BYTES) - 1) / sizeof(type) + 1], \ *b = (n) * sizeof *b > (BYTES) ? c_new_2(type, n) : __b; \ b; b != __b ? c_free(b) : (void)0, b = NULL) diff --git a/stc/cstr.h b/stc/cstr.h index 0a8a34c6..077d8e9f 100644 --- a/stc/cstr.h +++ b/stc/cstr.h @@ -331,7 +331,7 @@ STC_INLINE void _cstr_internal_move(cstr_t* self, size_t pos1, size_t pos2) { STC_DEF void cstr_replace_n(cstr_t* self, size_t pos, size_t len, const char* str, size_t n) { - c_withbuffer (char, xstr, n) { + c_withbuffer (xstr, char, n) { memcpy(xstr, str, n); _cstr_internal_move(self, pos + len, pos + n); memcpy(&self->str[pos], xstr, n); diff --git a/stc/cvec.h b/stc/cvec.h index bc629973..65abfa8a 100644 --- a/stc/cvec.h +++ b/stc/cvec.h @@ -242,7 +242,7 @@ STC_DEF cvec_##X##_iter_t \ cvec_##X##_insert_range_p(cvec_##X* self, cvec_##X##_value_t* pos, const cvec_##X##_value_t* first, const cvec_##X##_value_t* finish) { \ size_t len = finish - first, idx = pos - self->data, size = cvec_size(*self); \ - c_withbuffer (cvec_##X##_value_t, buf, len) { \ + c_withbuffer (buf, cvec_##X##_value_t, len) { \ for (size_t i=0; i cvec_capacity(*self)) \ -- cgit v1.2.3