summaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2023-02-16 19:13:52 +0100
committerTyge Løvset <[email protected]>2023-02-16 19:13:52 +0100
commit8864c11b2b85f832ce746a902b43ecf170e2eebc (patch)
tree8f5f51456182b96e0feb6b5869576033ed962ad6 /include
parent290055ad96c22fd9dfb539d0217e45cd2f1cdb91 (diff)
downloadSTC-modified-8864c11b2b85f832ce746a902b43ecf170e2eebc.tar.gz
STC-modified-8864c11b2b85f832ce746a902b43ecf170e2eebc.zip
Reverted and removed maps put function. Renamed clist node api functions. Minor fix in template.h
Diffstat (limited to 'include')
-rw-r--r--include/stc/ccommon.h8
-rw-r--r--include/stc/clist.h42
-rw-r--r--include/stc/cmap.h5
-rw-r--r--include/stc/csmap.h5
-rw-r--r--include/stc/cstr.h14
-rw-r--r--include/stc/priv/template.h8
6 files changed, 39 insertions, 43 deletions
diff --git a/include/stc/ccommon.h b/include/stc/ccommon.h
index 04c26d4c..db9a2f5c 100644
--- a/include/stc/ccommon.h
+++ b/include/stc/ccommon.h
@@ -121,16 +121,16 @@
#define c_make(C, ...) \
C##_from_n((C##_raw[])__VA_ARGS__, c_sizeof((C##_raw[])__VA_ARGS__)/c_sizeof(C##_raw))
-#define c_arraylen(a) \
- (intptr_t)(sizeof(a)/sizeof 0[a])
+
+#define c_arraylen(a) (intptr_t)(sizeof(a)/sizeof 0[a])
+#define c_litstrlen(literal) (c_sizeof("" literal) - 1)
typedef const char* crawstr;
#define crawstr_cmp(xp, yp) strcmp(*(xp), *(yp))
#define crawstr_hash(p) cstrhash(*(p))
-#define crawstr_len(literal) (c_sizeof("" literal) - 1)
#define c_sv(...) c_MACRO_OVERLOAD(c_sv, __VA_ARGS__)
-#define c_sv_1(lit) c_sv_2(lit, crawstr_len(lit))
+#define c_sv_1(lit) c_sv_2(lit, c_litstrlen(lit))
#define c_sv_2(str, n) (c_LITERAL(csview){str, n})
#define c_SV(sv) (int)(sv).size, (sv).str // print csview: use format "%.*s"
diff --git a/include/stc/clist.h b/include/stc/clist.h
index f257bc19..c1716c81 100644
--- a/include/stc/clist.h
+++ b/include/stc/clist.h
@@ -71,9 +71,9 @@ _c_clist_complete_types(clist_VOID, dummy);
#define _c_clist_insert_entry_after(ref, val) \
_cx_node *entry = (_cx_node *)i_malloc(c_sizeof *entry); entry->value = val; \
- _c_clist_insert_node_after(ref, entry)
+ _c_clist_insert_after_node(ref, entry)
-#define _c_clist_insert_node_after(ref, entry) \
+#define _c_clist_insert_after_node(ref, entry) \
if (ref) entry->next = ref->next, ref->next = entry; \
else entry->next = entry
// +: set self->last based on node
@@ -106,10 +106,10 @@ STC_API int _cx_memb(_sort_cmp_)(const clist_VOID_node* x, const cli
STC_API void _cx_memb(_reverse)(_cx_self* self);
STC_API _cx_iter _cx_memb(_splice)(_cx_self* self, _cx_iter it, _cx_self* other);
STC_API _cx_self _cx_memb(_split_off)(_cx_self* self, _cx_iter it1, _cx_iter it2);
-STC_API _cx_value* _cx_memb(_push_node_back)(_cx_self* self, _cx_node* node);
-STC_API _cx_value* _cx_memb(_insert_node_after)(_cx_self* self, _cx_node* ref, _cx_node* node);
-STC_API _cx_node* _cx_memb(_unlink_node_after)(_cx_self* self, _cx_node* ref);
-STC_API void _cx_memb(_erase_node_after)(_cx_self* self, _cx_node* ref);
+STC_API _cx_value* _cx_memb(_push_back_node)(_cx_self* self, _cx_node* node);
+STC_API _cx_value* _cx_memb(_insert_after_node)(_cx_self* self, _cx_node* ref, _cx_node* node);
+STC_API _cx_node* _cx_memb(_unlink_after_node)(_cx_self* self, _cx_node* ref);
+STC_API void _cx_memb(_erase_after_node)(_cx_self* self, _cx_node* ref);
STC_INLINE _cx_node* _cx_memb(_get_node)(_cx_value* vp) { return _clist_tonode(vp); }
#if !defined i_no_clone
@@ -144,9 +144,9 @@ STC_INLINE void _cx_memb(_clear)(_cx_self* self) { _cx_memb(_drop)(self)
STC_INLINE _cx_value* _cx_memb(_push)(_cx_self* self, i_key value)
{ return _cx_memb(_push_back)(self, value); }
STC_INLINE void _cx_memb(_pop_front)(_cx_self* self)
- { assert(!_cx_memb(_empty)(self)); _cx_memb(_erase_node_after)(self, self->last); }
+ { assert(!_cx_memb(_empty)(self)); _cx_memb(_erase_after_node)(self, self->last); }
STC_INLINE _cx_node* _cx_memb(_unlink_node_front)(_cx_self* self)
- { return _cx_memb(_unlink_node_after)(self, self->last); }
+ { return _cx_memb(_unlink_after_node)(self, self->last); }
STC_INLINE _cx_value* _cx_memb(_front)(const _cx_self* self) { return &self->last->next->value; }
STC_INLINE _cx_value* _cx_memb(_back)(const _cx_self* self) { return &self->last->value; }
@@ -281,7 +281,7 @@ _cx_memb(_clone)(_cx_self cx) {
STC_DEF void
_cx_memb(_drop)(_cx_self* self) {
- while (self->last) _cx_memb(_erase_node_after)(self, self->last);
+ while (self->last) _cx_memb(_erase_after_node)(self, self->last);
}
STC_DEF _cx_value*
@@ -300,15 +300,15 @@ _cx_memb(_push_front)(_cx_self* self, i_key value) {
}
STC_DEF _cx_value*
-_cx_memb(_push_node_back)(_cx_self* self, _cx_node* node) {
- _c_clist_insert_node_after(self->last, node);
+_cx_memb(_push_back_node)(_cx_self* self, _cx_node* node) {
+ _c_clist_insert_after_node(self->last, node);
self->last = node;
return &node->value;
}
STC_DEF _cx_value*
-_cx_memb(_insert_node_after)(_cx_self* self, _cx_node* ref, _cx_node* node) {
- _c_clist_insert_node_after(ref, node);
+_cx_memb(_insert_after_node)(_cx_self* self, _cx_node* ref, _cx_node* node) {
+ _c_clist_insert_after_node(ref, node);
if (!self->last)
self->last = node;
return &node->value;
@@ -330,7 +330,7 @@ STC_DEF _cx_iter
_cx_memb(_erase_at)(_cx_self* self, _cx_iter it) {
_cx_node *node = _clist_tonode(it.ref);
it.ref = (node == self->last) ? NULL : &node->next->value;
- _cx_memb(_erase_node_after)(self, it.prev);
+ _cx_memb(_erase_after_node)(self, it.prev);
return it;
}
@@ -338,21 +338,21 @@ STC_DEF _cx_iter
_cx_memb(_erase_range)(_cx_self* self, _cx_iter it1, _cx_iter it2) {
_cx_node *end = it2.ref ? _clist_tonode(it2.ref) : self->last->next;
if (it1.ref != it2.ref) do {
- _cx_memb(_erase_node_after)(self, it1.prev);
+ _cx_memb(_erase_after_node)(self, it1.prev);
if (!self->last) break;
} while (it1.prev->next != end);
return it2;
}
STC_DEF void
-_cx_memb(_erase_node_after)(_cx_self* self, _cx_node* ref) {
- _cx_node* node = _cx_memb(_unlink_node_after)(self, ref);
+_cx_memb(_erase_after_node)(_cx_self* self, _cx_node* ref) {
+ _cx_node* node = _cx_memb(_unlink_after_node)(self, ref);
i_keydrop((&node->value));
i_free(node);
}
STC_DEF _cx_node*
-_cx_memb(_unlink_node_after)(_cx_self* self, _cx_node* ref) {
+_cx_memb(_unlink_after_node)(_cx_self* self, _cx_node* ref) {
_cx_node* node = ref->next, *next = node->next;
ref->next = next;
if (node == next)
@@ -366,8 +366,8 @@ STC_DEF void
_cx_memb(_reverse)(_cx_self* self) {
_cx_self rev = {NULL};
while (self->last) {
- _cx_node* node = _cx_memb(_unlink_node_after)(self, self->last);
- _cx_memb(_insert_node_after)(&rev, rev.last, node);
+ _cx_node* node = _cx_memb(_unlink_after_node)(self, self->last);
+ _cx_memb(_insert_after_node)(&rev, rev.last, node);
}
*self = rev;
}
@@ -422,7 +422,7 @@ _cx_memb(_remove)(_cx_self* self, _cx_raw val) {
node = prev->next;
_cx_raw r = i_keyto((&node->value));
if (i_eq((&r), (&val))) {
- _cx_memb(_erase_node_after)(self, prev), ++n;
+ _cx_memb(_erase_after_node)(self, prev), ++n;
if (!self->last) break;
} else
prev = node;
diff --git a/include/stc/cmap.h b/include/stc/cmap.h
index 5e370167..83beb92c 100644
--- a/include/stc/cmap.h
+++ b/include/stc/cmap.h
@@ -130,11 +130,6 @@ STC_INLINE bool _cx_memb(_contains)(const _cx_self* self, _cx_rawkey rke
STC_API _cx_result _cx_memb(_insert_or_assign)(_cx_self* self, i_key key, i_val mapped);
#if !defined i_no_emplace
STC_API _cx_result _cx_memb(_emplace_or_assign)(_cx_self* self, _cx_rawkey rkey, i_valraw rmapped);
- STC_INLINE _cx_result _cx_memb(_put)(_cx_self* self, _cx_rawkey rkey, i_valraw rmapped)
- { return _cx_memb(_emplace_or_assign)(self, rkey, rmapped); }
- #else
- STC_INLINE _cx_result _cx_memb(_put)(_cx_self* self, i_key key, i_val mapped)
- { return _cx_memb(_insert_or_assign)(self, key, mapped); }
#endif
STC_INLINE const _cx_mapped*
diff --git a/include/stc/csmap.h b/include/stc/csmap.h
index 48e1eb62..bca0343c 100644
--- a/include/stc/csmap.h
+++ b/include/stc/csmap.h
@@ -186,11 +186,6 @@ _cx_memb(_shrink_to_fit)(_cx_self *self) {
STC_API _cx_result _cx_memb(_insert_or_assign)(_cx_self* self, i_key key, i_val mapped);
#if !defined i_no_emplace
STC_API _cx_result _cx_memb(_emplace_or_assign)(_cx_self* self, _cx_rawkey rkey, i_valraw rmapped);
- STC_INLINE _cx_result _cx_memb(_put)(_cx_self* self, _cx_rawkey rkey, i_valraw rmapped)
- { return _cx_memb(_emplace_or_assign)(self, rkey, rmapped); }
- #else
- STC_INLINE _cx_result _cx_memb(_put)(_cx_self* self, i_key key, i_val mapped)
- { return _cx_memb(_insert_or_assign)(self, key, mapped); }
#endif
STC_INLINE const _cx_mapped*
diff --git a/include/stc/cstr.h b/include/stc/cstr.h
index ce6dba81..694c02d0 100644
--- a/include/stc/cstr.h
+++ b/include/stc/cstr.h
@@ -69,13 +69,13 @@ STC_API char* _cstr_internal_move(cstr* self, intptr_t pos1, intptr_t pos2);
/**************************** PUBLIC API **********************************/
-#define cstr_lit(literal) cstr_from_n(literal, crawstr_len(literal))
+#define cstr_lit(literal) cstr_from_n(literal, c_litstrlen(literal))
#define cstr_NULL (c_LITERAL(cstr){{{0}, 0}})
#define cstr_toraw(self) cstr_str(self)
STC_API char* cstr_reserve(cstr* self, intptr_t cap);
STC_API void cstr_shrink_to_fit(cstr* self);
-STC_API void cstr_resize(cstr* self, intptr_t size, char value);
+STC_API char* cstr_resize(cstr* self, intptr_t size, char value);
STC_API intptr_t cstr_find_at(const cstr* self, intptr_t pos, const char* search);
STC_API char* cstr_assign_n(cstr* self, const char* str, intptr_t len);
STC_API char* cstr_append_n(cstr* self, const char* str, intptr_t len);
@@ -514,13 +514,15 @@ STC_DEF char* cstr_reserve(cstr* self, const intptr_t cap) {
return self->sml.data;
}
-STC_DEF void cstr_resize(cstr* self, const intptr_t size, const char value) {
+STC_DEF char* cstr_resize(cstr* self, const intptr_t size, const char value) {
cstr_buf r = cstr_buffer(self);
if (size > r.size) {
- if (size > r.cap) r.data = cstr_reserve(self, size);
+ if (size > r.cap && !(r.data = cstr_reserve(self, size)))
+ return NULL;
c_memset(r.data + r.size, value, size - r.size);
}
_cstr_set_size(self, size);
+ return r.data;
}
STC_DEF intptr_t cstr_find_at(const cstr* self, const intptr_t pos, const char* search) {
@@ -532,8 +534,7 @@ STC_DEF intptr_t cstr_find_at(const cstr* self, const intptr_t pos, const char*
STC_DEF char* cstr_assign_n(cstr* self, const char* str, const intptr_t len) {
char* d = cstr_reserve(self, len);
- c_memmove(d, str, len);
- _cstr_set_size(self, len);
+ if (d) { c_memmove(d, str, len); _cstr_set_size(self, len); }
return d;
}
@@ -542,6 +543,7 @@ STC_DEF char* cstr_append_n(cstr* self, const char* str, const intptr_t len) {
if (r.size + len > r.cap) {
const size_t off = (size_t)(str - r.data);
r.data = cstr_reserve(self, r.size*3/2 + len);
+ if (!r.data) return NULL;
if (off <= (size_t)r.size) str = r.data + off; /* handle self append */
}
c_memcpy(r.data + r.size, str, len);
diff --git a/include/stc/priv/template.h b/include/stc/priv/template.h
index 3bef2c9a..4b5c60cf 100644
--- a/include/stc/priv/template.h
+++ b/include/stc/priv/template.h
@@ -128,7 +128,6 @@
#elif defined i_keyboxed
#define i_keyclass i_keyboxed
#define i_rawclass c_PASTE(i_keyboxed, _raw)
- #define i_keyfrom c_PASTE(i_keyboxed, _from)
#ifndef i_no_eq
#define i_eq c_PASTE(i_keyboxed, _raw_eq)
#endif
@@ -148,6 +147,9 @@
#if !defined i_keyto && defined i_keyraw
#define i_keyto c_PASTE(i_key, _toraw)
#endif
+ #if !defined i_keyfrom && defined i_keyraw
+ #define i_keyfrom c_PASTE(i_key, _from)
+ #endif
#ifndef i_keydrop
#define i_keydrop c_PASTE(i_key, _drop)
#endif
@@ -233,7 +235,6 @@
#elif defined i_valboxed
#define i_valclass i_valboxed
#define i_valraw c_PASTE(i_valboxed, _raw)
- #define i_valfrom c_PASTE(i_valboxed, _from)
#endif
#ifdef i_valclass
@@ -244,6 +245,9 @@
#if !defined i_valto && defined i_valraw
#define i_valto c_PASTE(i_val, _toraw)
#endif
+ #if !defined i_valfrom && defined i_valraw
+ #define i_valfrom c_PASTE(i_val, _from)
+ #endif
#ifndef i_valdrop
#define i_valdrop c_PASTE(i_val, _drop)
#endif