diff options
| -rw-r--r-- | docs/ccommon_api.md | 2 | ||||
| -rw-r--r-- | include/stc/algo/coroutine.h | 2 | ||||
| -rw-r--r-- | include/stc/cstr.h | 3 | ||||
| -rw-r--r-- | misc/benchmarks/plotbench/plot.py | 4 | ||||
| -rw-r--r-- | misc/examples/triples.c | 10 |
5 files changed, 11 insertions, 10 deletions
diff --git a/docs/ccommon_api.md b/docs/ccommon_api.md index 930b8881..cd9be505 100644 --- a/docs/ccommon_api.md +++ b/docs/ccommon_api.md @@ -378,7 +378,7 @@ To resume the coroutine from where it was suspended with *cco_yield()*, simply c | | `cco_yield(ret)` | Yield/suspend execution and return ret | | | `cco_await(promise)` | Await/suspend until promise is true | | | `cco_await(promise, ret)` | Await/suspend with ret value | -| | `cco_return` | Execute final cleanup, enter done-state | +| | `cco_return` | Replaces return. Jump to cco_final: if exist| | | `cco_return_v(val)` | Yield final value, enter final-state | | | Semaphores: | | | | `cco_sem` | Semaphore type | diff --git a/include/stc/algo/coroutine.h b/include/stc/algo/coroutine.h index 81c75aa1..67ea5a40 100644 --- a/include/stc/algo/coroutine.h +++ b/include/stc/algo/coroutine.h @@ -87,7 +87,7 @@ enum { #define cco_run(co, call) while (call, !cco_done(co)) #define cco_final \ - *_state = cco_state_done; case cco_state_final + *_state = cco_state_final; case cco_state_final #define cco_return \ do { \ diff --git a/include/stc/cstr.h b/include/stc/cstr.h index d496b85e..03eefd2f 100644 --- a/include/stc/cstr.h +++ b/include/stc/cstr.h @@ -504,7 +504,8 @@ STC_DEF char* cstr_reserve(cstr* self, const intptr_t cap) { if (cap > cstr_s_cap) { char* data = (char *)c_malloc(cap + 1); const intptr_t len = cstr_s_size(self); - c_memcpy(data, self->sml.data, cstr_s_cap + 1); + /* copy full short buffer to emulate realloc() */ + c_memcpy(data, self->sml.data, cstr_s_cap + 2); self->lon.data = data; self->lon.size = (size_t)len; cstr_l_set_cap(self, cap); diff --git a/misc/benchmarks/plotbench/plot.py b/misc/benchmarks/plotbench/plot.py index 0ba92264..e65631b7 100644 --- a/misc/benchmarks/plotbench/plot.py +++ b/misc/benchmarks/plotbench/plot.py @@ -12,8 +12,8 @@ df = df[df.Method != 'total'] if n > 0: df = df[df.Compiler == comp[n]] -g = sns.catplot(data=df, x='Method', y='Seconds', hue='Library', col='C', kind='bar', - ci=68, legend=False, col_wrap=2, sharex=False, aspect=1.4, height=3.1) +g = sns.catplot(data=df, x='Method', y='Seconds', hue='Library', col='C', kind='bar', orient='v', + errorbar=('ci', 68), legend=False, col_wrap=2, sharex=False, aspect=1.4, height=3.1) g.set_xlabels('') g.add_legend(bbox_to_anchor=(0.75, 0.2), borderaxespad=0.) diff --git a/misc/examples/triples.c b/misc/examples/triples.c index 06142916..17e3d40b 100644 --- a/misc/examples/triples.c +++ b/misc/examples/triples.c @@ -32,7 +32,7 @@ struct triples { int cco_state; }; -bool triples_coro(struct triples* t) { +void triples_coro(struct triples* t) { cco_routine(t) { t->count = 0; for (t->c = 5; t->size; ++t->c) { @@ -41,15 +41,14 @@ bool triples_coro(struct triples* t) { if ((int64_t)t->a*t->a + (int64_t)t->b*t->b == (int64_t)t->c*t->c) { if (t->count++ == t->size) cco_return; - cco_yield(false); + cco_yield(); } } } } - cco_final: + cco_final: puts("done"); } - return true; } int main() @@ -61,7 +60,8 @@ int main() struct triples t = {INT32_MAX}; int n = 0; - while (!triples_coro(&t)) { + while (!cco_done(&t)) { + triples_coro(&t); if (gcd(t.a, t.b) > 1) continue; if (t.c < 100) |
