summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2022-04-27 15:11:30 +0200
committerTyge Løvset <[email protected]>2022-04-27 15:11:30 +0200
commitb76773eef93b487cf6c6d2784207e3cf2fe6fcd8 (patch)
tree56e644b6e5241b32bb2eca42807adc75e4390acd
parent37e950b8a93172f5f07fedaca54c9b2894416b5a (diff)
downloadSTC-modified-b76773eef93b487cf6c6d2784207e3cf2fe6fcd8.tar.gz
STC-modified-b76773eef93b487cf6c6d2784207e3cf2fe6fcd8.zip
Bugfix: cbox didn't use i_keyclone, and therefore did not deep clone properly.
-rw-r--r--examples/city.c10
-rw-r--r--examples/make.sh4
-rw-r--r--include/stc/cbox.h6
3 files changed, 13 insertions, 7 deletions
diff --git a/examples/city.c b/examples/city.c
index d1bee4b7..ec3338a7 100644
--- a/examples/city.c
+++ b/examples/city.c
@@ -17,6 +17,7 @@ static inline uint64_t City_hash(const City* a) {
}
static inline City City_clone(City c) {
+ printf("clone %s\n", cstr_str(&c.name));
c.name = cstr_clone(c.name);
c.country = cstr_clone(c.country);
return c;
@@ -27,13 +28,14 @@ static inline void City_drop(City* c) {
c_drop(cstr, &c->name, &c->country);
}
+
#define i_type CityArc
-#define i_val_bind City
-//#include <stc/cbox.h>
-#include <stc/carc.h>
+#define i_key_bind City
+#include <stc/cbox.h>
+//#include <stc/carc.h> // try instead of cbox.h
#define i_type Cities
-#define i_val_arcbox CityArc
+#define i_key_arcbox CityArc
#include <stc/cvec.h>
#define i_type CityMap
diff --git a/examples/make.sh b/examples/make.sh
index 4687ed97..af7eace9 100644
--- a/examples/make.sh
+++ b/examples/make.sh
@@ -1,6 +1,8 @@
#!/bin/bash
-cc='gcc -s -O2 -Wall -std=c99 -pedantic'
+cc='clang -s -O2 -Wall -std=c99 -pedantic'
+#cc='gcc -s -O2 -Wall -std=c99 -pedantic'
#cc='gcc -x c++ -s -O2 -Wall -std=c++20'
+#cc='g++ -x c++ -s -O2 -Wall'
#cc='clang -s -O2 -Wall -std=c99 -pedantic -DSTC_OLD_CSTR'
#cc='clang'
#cc='clang -c -DSTC_HEADER'
diff --git a/include/stc/cbox.h b/include/stc/cbox.h
index 14459640..780d6aaf 100644
--- a/include/stc/cbox.h
+++ b/include/stc/cbox.h
@@ -1,3 +1,4 @@
+
/* MIT License
*
* Copyright (c) 2022 Tyge Løvset, NORCE, www.norceresearch.no
@@ -127,8 +128,9 @@ _cx_memb(_reset_from)(_cx_self* self, i_key val) {
STC_INLINE _cx_self
_cx_memb(_clone)(_cx_self other) {
if (!other.get) return other;
- i_keyraw r = i_keyto(other.get);
- return c_make(_cx_self){c_new(i_key, i_keyfrom(r))};
+ _cx_self out = {c_alloc(i_key)};
+ *out.get = i_keyclone(*other.get);
+ return out;
}
STC_INLINE void