From 09d1cb649deed77d731e997be33070f8cbd4af38 Mon Sep 17 00:00:00 2001 From: Leonardo Vencovsky Date: Wed, 7 Oct 2020 15:02:27 -0300 Subject: [PATCH] Final touches to SAC List --- CHANGELOG | 4 ++++ src/sac_list.h | 59 +++++++++++++++----------------------------------- 2 files changed, 21 insertions(+), 42 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 120734c..35b0c76 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,9 @@ # RELEASE.MAJOR.MINOR +0.25.0 + New Project Architecture - Files are no longer separated in folders, but rather prefixed by their sub-library + Added sac_list.h + 0.24.0 A lot of breaking changes, with the library more modular now Comeback of PUBLIC and PRIVATE for the CMC sub-library diff --git a/src/sac_list.h b/src/sac_list.h index d34955a..05dff79 100644 --- a/src/sac_list.h +++ b/src/sac_list.h @@ -102,9 +102,6 @@ \ /* Value function table */ \ struct CMC_DEF_FVAL(SNAME) * f_val; \ -\ - /* Custom allocation functions */ \ - struct CMC_ALLOC_NODE_NAME *alloc; \ \ /* Custom callback functions */ \ CMC_CALLBACKS_DECL; \ @@ -139,10 +136,8 @@ \ /* Collection Functions */ \ /* Collection Allocation and Deallocation */ \ - struct SNAME *CMC_(PFX, _new)(struct CMC_DEF_FVAL(SNAME) * f_val); \ - struct SNAME *CMC_(PFX, _new_custom)(struct CMC_DEF_FVAL(SNAME) * f_val, \ - struct CMC_ALLOC_NODE_NAME * alloc, struct CMC_CALLBACKS_NAME * callbacks); \ - void CMC_(PFX, _clear)(struct SNAME * _list_); \ + struct SNAME CMC_(PFX, _new)(struct CMC_DEF_FVAL(SNAME) * f_val); \ + struct SNAME CMC_(PFX, _new_custom)(struct CMC_DEF_FVAL(SNAME) * f_val, struct CMC_CALLBACKS_NAME * callbacks); \ void CMC_(PFX, _free)(struct SNAME * _list_); \ /* Customization of Allocation and Callbacks */ \ void CMC_(PFX, _customize)(struct SNAME * _list_, \ @@ -169,7 +164,7 @@ size_t CMC_(PFX, _capacity)(struct SNAME * _list_); \ int CMC_(PFX, _flag)(struct SNAME * _list_); \ /* Collection Utility */ \ - struct SNAME *CMC_(PFX, _copy_of)(struct SNAME * _list_); \ + struct SNAME CMC_(PFX, _copy_of)(struct SNAME * _list_); \ bool CMC_(PFX, _equals)(struct SNAME * _list1_, struct SNAME * _list2_); /* ------------------------------------------------------------------------- @@ -180,38 +175,25 @@ /* Implementation Detail Functions */ \ /* None */ \ \ - struct SNAME *CMC_(PFX, _new)(struct CMC_DEF_FVAL(SNAME) * f_val) \ + struct SNAME CMC_(PFX, _new)(struct CMC_DEF_FVAL(SNAME) * f_val) \ { \ - return CMC_(PFX, _new_custom)(f_val, NULL, NULL); \ + return CMC_(PFX, _new_custom)(f_val, NULL); \ } \ \ - struct SNAME *CMC_(PFX, _new_custom)(struct CMC_DEF_FVAL(SNAME) * f_val, \ - struct CMC_ALLOC_NODE_NAME * alloc, struct CMC_CALLBACKS_NAME * callbacks) \ + struct SNAME CMC_(PFX, _new_custom)(struct CMC_DEF_FVAL(SNAME) * f_val, struct CMC_CALLBACKS_NAME * callbacks) \ { \ CMC_CALLBACKS_MAYBE_UNUSED(callbacks); \ \ if (!f_val) \ - return NULL; \ + return (struct SNAME) { .flag = CMC_FLAG_ERROR, 0 }; \ \ - if (!alloc) \ - alloc = &cmc_alloc_node_default; \ + struct SNAME _list_ = { 0 }; \ \ - struct SNAME *_list_ = alloc->calloc(1, sizeof(struct SNAME)); \ -\ - if (!_list_) \ - return NULL; \ -\ - _list_->f_val = f_val; \ - _list_->alloc = alloc; \ - CMC_CALLBACKS_ASSIGN(_list_, callbacks); \ + _list_.f_val = f_val; \ + CMC_CALLBACKS_ASSIGN(&_list_, callbacks); \ \ return _list_; \ } \ -\ - void CMC_(PFX, _clear)(struct SNAME * _list_) \ - { \ - memset(_list_, 0, sizeof(struct SNAME)); \ - } \ \ void CMC_(PFX, _free)(struct SNAME * _list_) \ { \ @@ -221,7 +203,7 @@ _list_->f_val->free(_list_->buffer[i]); \ } \ \ - _list_->alloc->free(_list_); \ + memset(_list_, 0, sizeof(struct SNAME)); \ } \ \ void CMC_(PFX, _customize)(struct SNAME * _list_, \ @@ -512,28 +494,21 @@ return _list_->flag; \ } \ \ - struct SNAME *CMC_(PFX, _copy_of)(struct SNAME * _list_) \ + struct SNAME CMC_(PFX, _copy_of)(struct SNAME * _list_) \ { \ - struct SNAME *result = CMC_(PFX, _new_custom)(_list_->f_val, _list_->alloc, NULL); \ + struct SNAME result = CMC_(PFX, _new_custom)(_list_->f_val, NULL); \ \ - if (!result) \ - { \ - _list_->flag = CMC_FLAG_ALLOC; \ - return NULL; \ - } \ -\ - CMC_CALLBACKS_ASSIGN(result, _list_->callbacks); \ + CMC_CALLBACKS_ASSIGN(&result, _list_->callbacks); \ \ if (_list_->f_val->cpy) \ { \ for (size_t i = 0; i < _list_->count; i++) \ - result->buffer[i] = _list_->f_val->cpy(_list_->buffer[i]); \ + result.buffer[i] = _list_->f_val->cpy(_list_->buffer[i]); \ } \ else \ - memcpy(result->buffer, _list_->buffer, sizeof(V) * _list_->count); \ -\ - result->count = _list_->count; \ + memcpy(result.buffer, _list_->buffer, sizeof(V) * _list_->count); \ \ + result.count = _list_->count; \ _list_->flag = CMC_FLAG_OK; \ \ return result; \