diff options
| author | Tyge Løvset <[email protected]> | 2022-10-27 23:21:13 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2022-10-27 23:21:13 +0200 |
| commit | 426d0a4cef8f9910fd4f8209ee0e57bd9ff4c1e8 (patch) | |
| tree | 68e8b4792ee3f914a7ae934d2cf40ece7483d362 | |
| parent | ce04aa8562b71a0c7ab7906132807150c724c258 (diff) | |
| parent | 89429e8e8242df35bc482c13c4a9f2b23e62e51d (diff) | |
| download | STC-modified-426d0a4cef8f9910fd4f8209ee0e57bd9ff4c1e8.tar.gz STC-modified-426d0a4cef8f9910fd4f8209ee0e57bd9ff4c1e8.zip | |
Merge branch 'master' of github.com:tylov/STC
| -rw-r--r-- | examples/box2.c | 12 | ||||
| -rw-r--r-- | examples/rawptr_elements.c | 2 | ||||
| -rw-r--r-- | include/stc/carc.h | 10 | ||||
| -rw-r--r-- | include/stc/cbox.h | 10 | ||||
| -rw-r--r-- | include/stc/ccommon.h | 1 | ||||
| -rw-r--r-- | include/stc/template.h | 8 |
6 files changed, 25 insertions, 18 deletions
diff --git a/examples/box2.c b/examples/box2.c index f64eb239..03f7d8bd 100644 --- a/examples/box2.c +++ b/examples/box2.c @@ -30,12 +30,12 @@ struct { #include <stc/cbox.h> // cbox_BoxPoint Point origin(void) { - return (Point){ .x=0.0, .y=0.0 }; + return (Point){ .x=1.0, .y=2.0 }; } cbox_Point boxed_origin(void) { // Allocate this point on the heap, and return a pointer to it - return cbox_Point_from((Point){ .x=0.0, .y=0.0 }); + return cbox_Point_make((Point){ .x=2.0, .y=3.0 }); } @@ -50,10 +50,10 @@ int main(void) { // Declare auto-deleted box objects c_auto (cbox_Rectangle, boxed_rectangle) c_auto (cbox_Point, boxed_point) - c_auto (cbox_BoxPoint, box_in_a_box) + c_auto (cbox_BoxPoint, box_in_a_box, boxbox2) { // Heap allocated rectangle - boxed_rectangle = cbox_Rectangle_from((Rectangle){ + boxed_rectangle = cbox_Rectangle_make((Rectangle){ .top_left = origin(), .bottom_right = (Point){ .x=3.0, .y=-4.0 } }); @@ -62,7 +62,9 @@ int main(void) { boxed_point = cbox_Point_from(origin()); // Double indirection - box_in_a_box = cbox_BoxPoint_from(boxed_origin()); + box_in_a_box = cbox_BoxPoint_make(boxed_origin()); + boxbox2 = cbox_BoxPoint_from(point); // !! + printf("boxbox2: x=%f\n", boxbox2.get->get->x); printf("Point occupies %" c_ZU " bytes on the stack\n", sizeof(point)); diff --git a/examples/rawptr_elements.c b/examples/rawptr_elements.c index 095357ca..37f1fe32 100644 --- a/examples/rawptr_elements.c +++ b/examples/rawptr_elements.c @@ -46,7 +46,7 @@ int main() puts("\nIBox map:"); - SIBoxMap_insert(&m2, cstr_from("Hello"), IBox_from(123)); + SIBoxMap_insert(&m2, cstr_from("Hello"), IBox_make(123)); SIBoxMap_emplace(&m2, "World", 999); c_forpair (name, number, SIBoxMap, m2) printf("%s: %d\n", cstr_str(_.name), *_.number->get); diff --git a/include/stc/carc.h b/include/stc/carc.h index 91de0931..4e03af9b 100644 --- a/include/stc/carc.h +++ b/include/stc/carc.h @@ -113,7 +113,7 @@ STC_INLINE _cx_self _cx_memb(_from_ptr)(_cx_value* p) { } // c++: std::make_shared<_cx_value>(val) -STC_INLINE _cx_self _cx_memb(_from)(_cx_value val) { +STC_INLINE _cx_self _cx_memb(_make)(_cx_value val) { _cx_self ptr; _cx_carc_rep *rep = c_alloc(_cx_carc_rep); *(ptr.use_count = &rep->counter) = 1; @@ -150,11 +150,11 @@ STC_INLINE void _cx_memb(_reset_to)(_cx_self* self, _cx_value* p) { } #ifndef _i_no_emplace -STC_INLINE _cx_self _cx_memb(_new)(_cx_raw raw) - { return _cx_memb(_from)(i_keyfrom(raw)); } +STC_INLINE _cx_self _cx_memb(_from)(_cx_raw raw) + { return _cx_memb(_make)(i_keyfrom(raw)); } #else -STC_INLINE _cx_self _cx_memb(_new)(_cx_value val) - { return _cx_memb(_from)(val); } +STC_INLINE _cx_self _cx_memb(_from)(_cx_value val) + { return _cx_memb(_make)(val); } #endif // does not use i_keyclone, so OK to always define. diff --git a/include/stc/cbox.h b/include/stc/cbox.h index cb8b7069..fb4452a4 100644 --- a/include/stc/cbox.h +++ b/include/stc/cbox.h @@ -94,7 +94,7 @@ STC_INLINE _cx_self _cx_memb(_from_ptr)(_cx_value* p) { return c_make(_cx_self){p}; } // c++: std::make_unique<i_key>(val) -STC_INLINE _cx_self _cx_memb(_from)(_cx_value val) { +STC_INLINE _cx_self _cx_memb(_make)(_cx_value val) { _cx_self ptr = {c_alloc(_cx_value)}; *ptr.get = val; return ptr; } @@ -129,11 +129,11 @@ STC_INLINE void _cx_memb(_reset_to)(_cx_self* self, _cx_value* p) { } #ifndef _i_no_emplace -STC_INLINE _cx_self _cx_memb(_new)(_cx_raw raw) - { return _cx_memb(_from)(i_keyfrom(raw)); } +STC_INLINE _cx_self _cx_memb(_from)(_cx_raw raw) + { return _cx_memb(_make)(i_keyfrom(raw)); } #else -STC_INLINE _cx_self _cx_memb(_new)(_cx_value val) - { return _cx_memb(_from)(val); } +STC_INLINE _cx_self _cx_memb(_from)(_cx_value val) + { return _cx_memb(_make)(val); } #endif #if !defined _i_no_clone diff --git a/include/stc/ccommon.h b/include/stc/ccommon.h index fb4129b3..8d1f236b 100644 --- a/include/stc/ccommon.h +++ b/include/stc/ccommon.h @@ -112,6 +112,7 @@ #define c_no_clone (1<<2) #define c_no_cmp (1<<3) #define c_no_hash (1<<4) +#define c_no_from (1<<5) /* Generic algorithms */ diff --git a/include/stc/template.h b/include/stc/template.h index ae66502d..42a07634 100644 --- a/include/stc/template.h +++ b/include/stc/template.h @@ -115,7 +115,9 @@ #elif defined i_keyboxed #define i_keyclass i_keyboxed #define i_rawclass c_paste(i_keyboxed, _raw) - #define i_keyfrom c_paste(i_keyboxed, _new) + #if !c_option(c_no_from) + #define i_keyfrom c_paste(i_keyboxed, _from) + #endif #if !defined _i_no_hash #define i_eq c_paste(i_keyboxed, _raw_eq) #endif @@ -215,7 +217,9 @@ #elif defined i_valboxed #define i_valclass i_valboxed #define i_valraw c_paste(i_valboxed, _raw) - #define i_valfrom c_paste(i_valboxed, _new) + #if !c_option(c_no_from) + #define i_valfrom c_paste(i_valboxed, _from) + #endif #endif #ifdef i_valclass |
