From a2920800007c291bdf2b5264622cbc713d4961ee Mon Sep 17 00:00:00 2001 From: default Date: Sat, 25 May 2024 08:24:08 +0200 Subject: [PATCH] Backport from xs (fix regex.h compilation with tcc). --- xs.h | 24 +++++++++++------------- xs_regex.h | 5 +++++ xs_set.h | 5 ++--- xs_url.h | 5 ++--- xs_version.h | 2 +- 5 files changed, 21 insertions(+), 20 deletions(-) diff --git a/xs.h b/xs.h index f361830..972665c 100644 --- a/xs.h +++ b/xs.h @@ -798,11 +798,10 @@ int xs_list_len(const xs_list *list) { XS_ASSERT_TYPE_NULL(list, XSTYPE_LIST); - int c = 0; - xs_list *p = (xs_list *)list; + int c = 0, ct = 0; const xs_val *v; - while (xs_list_iter(&p, &v)) + while (xs_list_next(list, &v, &ct)) c++; return c; @@ -817,11 +816,10 @@ const xs_val *xs_list_get(const xs_list *list, int num) if (num < 0) num = xs_list_len(list) + num; - int c = 0; - xs_list *p = (xs_list *)list; + int c = 0, ct = 0; const xs_val *v; - while (xs_list_iter(&p, &v)) { + while (xs_list_next(list, &v, &ct)) { if (c == num) return v; @@ -880,16 +878,16 @@ xs_list *xs_list_dequeue(xs_list *list, xs_val **data, int last) { XS_ASSERT_TYPE(list, XSTYPE_LIST); - xs_list *p = list; + int ct = 0; const xs_val *v = NULL; if (!last) { /* get the first */ - xs_list_iter(&p, &v); + xs_list_next(list, &v, &ct); } else { /* iterate to the end */ - while (xs_list_iter(&p, &v)); + while (xs_list_next(list, &v, &ct)); } if (v != NULL) { @@ -909,11 +907,11 @@ int xs_list_in(const xs_list *list, const xs_val *val) XS_ASSERT_TYPE_NULL(list, XSTYPE_LIST); int n = 0; - xs_list *p = (xs_list *)list; + int ct = 0; const xs_val *v; int sz = xs_size(val); - while (xs_list_iter(&p, &v)) { + while (xs_list_next(list, &v, &ct)) { if (sz == xs_size(v) && memcmp(val, v, sz) == 0) return n; @@ -930,13 +928,13 @@ xs_str *xs_join(const xs_list *list, const char *sep) XS_ASSERT_TYPE(list, XSTYPE_LIST); xs_str *s = NULL; - xs_list *p = (xs_list *)list; const xs_val *v; int c = 0; + int ct = 0; int offset = 0; int ssz = strlen(sep); - while (xs_list_iter(&p, &v)) { + while (xs_list_next(list, &v, &ct)) { /* refuse to join non-string values */ if (xs_type(v) == XSTYPE_STRING) { int sz; diff --git a/xs_regex.h b/xs_regex.h index cdb2cf8..d8d2d1d 100644 --- a/xs_regex.h +++ b/xs_regex.h @@ -16,6 +16,11 @@ xs_list *xs_regex_replace_in(xs_str *str, const char *rx, const char *rep, int c #ifdef XS_IMPLEMENTATION +#ifdef __TINYC__ +/* fix a compilation error in tcc */ +#define _REGEX_NELTS(n) +#endif + #include xs_list *xs_regex_split_n(const char *str, const char *rx, int count) diff --git a/xs_set.h b/xs_set.h index 12bac94..d320d34 100644 --- a/xs_set.h +++ b/xs_set.h @@ -85,7 +85,6 @@ int xs_set_add(xs_set *s, const xs_val *data) { /* is it 'full'? */ if (s->used >= s->elems / 2) { - char *p; const xs_val *v; /* expand! */ @@ -96,8 +95,8 @@ int xs_set_add(xs_set *s, const xs_val *data) memset(s->hash, '\0', s->elems * sizeof(int)); /* add the list elements back */ - p = s->list; - while (xs_list_iter(&p, &v)) + int ct = 0; + while (xs_list_next(s->list, &v, &ct)) _store_hash(s, v, v - s->list); } diff --git a/xs_url.h b/xs_url.h index 488a65f..606c3e4 100644 --- a/xs_url.h +++ b/xs_url.h @@ -51,11 +51,10 @@ xs_dict *xs_url_vars(const char *str) /* split by arguments */ xs *args = xs_split(str, "&"); - xs_list *l; + int ct = 0; const xs_val *v; - l = args; - while (xs_list_iter(&l, &v)) { + while (xs_list_next(args, &v, &ct)) { xs *kv = xs_split_n(v, "=", 1); if (xs_list_len(kv) == 2) { diff --git a/xs_version.h b/xs_version.h index 9fb70ef..7a7ba53 100644 --- a/xs_version.h +++ b/xs_version.h @@ -1 +1 @@ -/* 65265483c102909393287bfb173d1a7ae9c3be00 2024-05-23T09:57:20+02:00 */ +/* 65769f25ed99b886a643522bef21628396cd118d 2024-05-25T08:18:51+02:00 */