From 91d097d7b0518cbde556d095b88c4a1c0955e649 Mon Sep 17 00:00:00 2001 From: jgabaut <109908086+jgabaut@users.noreply.github.com> Date: Mon, 23 Oct 2023 16:36:01 +0200 Subject: [PATCH] feat: 0.3.4 add kls_get_maxRegions_KLS_BASIC() (#39) * feat: drop KLS_REGIONS_MAX_IMPL() * feat: add kls_get_maxRegions_KLS_BASIC() * feat: use kls_maxRegions_KLS_BASIC() for init of reglist_kls * feat: add kls_temp_get_maxRegions_KLS_BASIC() * feat: handle KLS_BASIC in kls_insord_p() * chore: update stego.lock --- .github/workflows/make-anviltest.yml | 2 +- bin/stego.lock | 53 +++++++-------- bin/v0.3.4/.gitignore | 4 ++ bin/v0.3.4/static | 1 + configure.ac | 4 +- docs/koliseo.doxyfile | 2 +- src/koliseo.c | 99 ++++++++++++++++++++++++++-- src/koliseo.h | 16 ++--- static/demo.c | 5 +- 9 files changed, 143 insertions(+), 43 deletions(-) create mode 100644 bin/v0.3.4/.gitignore create mode 120000 bin/v0.3.4/static diff --git a/.github/workflows/make-anviltest.yml b/.github/workflows/make-anviltest.yml index da3e1da..ae3e4fd 100644 --- a/.github/workflows/make-anviltest.yml +++ b/.github/workflows/make-anviltest.yml @@ -9,7 +9,7 @@ on: workflow_dispatch: jobs: - build: + anviltest: runs-on: ubuntu-latest steps: diff --git a/bin/stego.lock b/bin/stego.lock index d3896f7..1256b48 100644 --- a/bin/stego.lock +++ b/bin/stego.lock @@ -5,33 +5,34 @@ demo# executable file name tests# tests folder name 0.1.0# autoconf and automake support version [Supported versions] -0.1.0# First release -0.1.1# abort() on failed operations -0.1.2# print_kls_2file() -0.1.3# update prev_offset on kls_push() -0.1.5# add kls_log(), fixes -0.1.6# functional Koliseo_Temp -0.1.7# add Region_List -0.1.8# improved Region API -0.1.9# add kls_usageReport() -0.1.10# add ncurses debug functions -0.1.11# add kls_formatSize() -0.1.12# add int API lvl, vargs log -0.1.13# log API level -0.1.15# add KLS_PUSH_TYPED() -0.1.16# add KLS_PUSH_T_TYPED() -0.1.17# add kls_type_usage() -0.1.18# kls_push_zero_typed() expects int -0.1.19# add kls_print_title() -0.1.20# add kls->has_temp, KLS_PUSH_T doesn't account for AUTOREGION -0.1.21# add MINGW32_BUILD preprocessor directives -0.1.22# add KLS_DEBUG_CORE preprocessor directives to enable API call logs -0.2.0# Reworked Koliseo_Temp API with split functions -0.2.1# Fix build for mingw32 -0.2.3# Add missing NULL checks, bump amboso to 1.6.6 -0.2.4# Add KLSFmt and KLS_Arg(), fix missing fprintf() args -0.2.5# Fix push sizes in logs, add address logging +0.1.0# First release - Unsupported +0.1.1# abort() on failed operations - Unsupported +0.1.2# print_kls_2file() - Unsupported +0.1.3# update prev_offset on kls_push() - Unsupported +0.1.5# add kls_log(), fixes - Unsupported +0.1.6# functional Koliseo_Temp - Deprecated, low support +0.1.7# add Region_List - Deprecated, low support +0.1.8# improved Region API - Deprecated, low support +0.1.9# add kls_usageReport() - Deprecated, low support +0.1.10# add ncurses debug functions - Deprecated, low support +0.1.11# add kls_formatSize() - Deprecated, low support +0.1.12# add int API lvl, vargs log - Deprecated, low support +0.1.13# log API level - Deprecated, low support +0.1.15# add KLS_PUSH_TYPED() - Deprecated, low support +0.1.16# add KLS_PUSH_T_TYPED() - Deprecated, low support +0.1.17# add kls_type_usage() - Deprecated, low support +0.1.18# kls_push_zero_typed() expects int - Deprecated, low support +0.1.19# add kls_print_title() - Deprecated, low support +0.1.20# add kls->has_temp, KLS_PUSH_T doesn't account for AUTOREGION - Deprecated, low support +0.1.21# add MINGW32_BUILD preprocessor directives - Deprecated, low support +0.1.22# add KLS_DEBUG_CORE preprocessor directives to enable API call logs - Deprecated, low support +0.2.0# Reworked Koliseo_Temp API with split functions - Deprecated, low support +0.2.1# Fix build for mingw32 - Deprecated, low support +0.2.3# Add missing NULL checks, bump amboso to 1.6.6 - Deprecated, low support +0.2.4# Add KLSFmt and KLS_Arg(), fix missing fprintf() args - Deprecated +0.2.5# Fix push sizes in logs, add address logging - Deprecated 0.3.0# Clean namespace, add KLS_Conf and KLS_Temp_Conf. Drops KOLISEO_AUTOSET_REGIONS and KOLISEO_AUTOSET_TEMP_REGIONS globals. 0.3.1# Close kls logfile on kls_free(). Drops KOLISEO_DEBUG, KOLISEO_DEBUG_FP globals. Extend KLS_Conf, remove kls_set_conf() from header. 0.3.2# Add backend selection for automatic KLS_Region list. 0.3.3# Fix Koliseo_Temp reglist_kls having a static size +0.3.4# Add kls_maxRegions_KLS_BASIC, handle KLS_BASIC in kls_insord_p(), fix list macros args diff --git a/bin/v0.3.4/.gitignore b/bin/v0.3.4/.gitignore new file mode 100644 index 0000000..f915d8e --- /dev/null +++ b/bin/v0.3.4/.gitignore @@ -0,0 +1,4 @@ +#amboso compliant version folder, will ignore everything inside BUT the gitignore, to keep the clean dir +* +!.gitignore +!static diff --git a/bin/v0.3.4/static b/bin/v0.3.4/static new file mode 120000 index 0000000..382349a --- /dev/null +++ b/bin/v0.3.4/static @@ -0,0 +1 @@ +../../static/ \ No newline at end of file diff --git a/configure.ac b/configure.ac index 1e2524d..cb6e5a0 100644 --- a/configure.ac +++ b/configure.ac @@ -1,5 +1,5 @@ # Define the package name and version -AC_INIT([koliseo], [0.3.3], [jgabaut@github.com]) +AC_INIT([koliseo], [0.3.4], [jgabaut@github.com]) # Verify automake version and enable foreign option AM_INIT_AUTOMAKE([foreign -Wall]) @@ -48,7 +48,7 @@ fi # Set a default version number if not specified externally AC_ARG_VAR([VERSION], [Version number]) if test -z "$VERSION"; then - VERSION="0.3.3" + VERSION="0.3.4" fi # Output variables to the config.h header diff --git a/docs/koliseo.doxyfile b/docs/koliseo.doxyfile index df1da1b..a213e70 100644 --- a/docs/koliseo.doxyfile +++ b/docs/koliseo.doxyfile @@ -48,7 +48,7 @@ PROJECT_NAME = "koliseo" # could be handy for archiving the generated documentation or if some version # control system is used. -PROJECT_NUMBER = "0.3.3" +PROJECT_NUMBER = "0.3.4" # Using the PROJECT_BRIEF tag one can provide an optional one line description # for a project that appears at the top of each page and should give viewer a diff --git a/src/koliseo.c b/src/koliseo.c index 19471a5..44c5e2d 100644 --- a/src/koliseo.c +++ b/src/koliseo.c @@ -113,6 +113,59 @@ ptrdiff_t kls_get_pos(Koliseo* kls) { return kls->offset; } +/** + * Calcs the max number of possible KLS_PUSH ops when using KLS_BASIC reglist alloc backend. + * @return The max number of push ops possible, or -1 in case of error. + */ +int kls_get_maxRegions_KLS_BASIC(Koliseo* kls) { + if (kls == NULL) { + #ifdef KLS_DEBUG_CORE + fprintf(stderr,"[ERROR] %s(): passed Koliseo was NULL.\n",__func__); + #endif + return -1; + } + if (kls->conf.kls_reglist_alloc_backend != KLS_REGLIST_ALLOC_KLS_BASIC) { + #ifdef KLS_DEBUG_CORE + fprintf(stderr,"[ERROR] %s(): conf.kls_reglist_backend was {%i}, expected KLS_REGLIST_ALLOC_KLS_BASIC: {%i}.\n",__func__,kls->conf.kls_reglist_alloc_backend, KLS_REGLIST_ALLOC_KLS_BASIC); + #endif + return -1; + } + if (kls->reglist_kls == NULL) { + #ifdef KLS_DEBUG_CORE + fprintf(stderr,"[ERROR] %s(): passed Koliseo->reglist_kls was NULL.\n",__func__); + #endif + return -1; + } + return (kls->reglist_kls->size - sizeof(Koliseo)) / (sizeof(KLS_Region) + sizeof(KLS_region_list_item)); +} + + +/** + * Calcs the max number of possible KLS_PUSH_T ops when using KLS_BASIC reglist alloc backend. + * @return The max number of temp push ops possible, or -1 in case of error. + */ +int kls_temp_get_maxRegions_KLS_BASIC(Koliseo_Temp* t_kls) { + if (t_kls == NULL) { + #ifdef KLS_DEBUG_CORE + fprintf(stderr,"[ERROR] %s(): passed Koliseo_Temp was NULL.\n",__func__); + #endif + return -1; + } + if (t_kls->conf.tkls_reglist_alloc_backend != KLS_REGLIST_ALLOC_KLS_BASIC) { + #ifdef KLS_DEBUG_CORE + fprintf(stderr,"[ERROR] %s(): conf.tkls_reglist_backend was {%i}, expected KLS_REGLIST_ALLOC_KLS_BASIC: {%i}.\n",__func__,t_kls->conf.tkls_reglist_alloc_backend, KLS_REGLIST_ALLOC_KLS_BASIC); + #endif + return -1; + } + if (t_kls->reglist_kls == NULL) { + #ifdef KLS_DEBUG_CORE + fprintf(stderr,"[ERROR] %s(): passed Koliseo_Temp->reglist_kls was NULL.\n",__func__); + #endif + return -1; + } + return (t_kls->reglist_kls->size - sizeof(Koliseo)) / (sizeof(KLS_Region) + sizeof(KLS_region_list_item)); +} + /** * Logs a message to the log_fp FILE field of the passed Koliseo pointer, if its conf.kls_verbose_lvl is >0. * @param kls The Koliseo pointer hosting the log_fp FILE pointer. @@ -339,7 +392,7 @@ bool kls_set_conf(Koliseo* kls, KLS_Conf conf) { exit(EXIT_FAILURE); } kls->reglist_kls = reglist_kls; - kls->max_regions_kls_alloc_basic = (reglist_kls->size - sizeof(Koliseo))/(sizeof(KLS_region_list_item) + sizeof(KLS_Region)); + kls->max_regions_kls_alloc_basic = kls_get_maxRegions_KLS_BASIC(kls); #ifdef KLS_DEBUG_CORE kls_log(kls,"KLS","%s(): Re-Init of KLS_Region_List for kls. Max regions: {%i}.", __func__, kls->max_regions_kls_alloc_basic); @@ -2025,7 +2078,7 @@ Koliseo_Temp* kls_temp_start(Koliseo* kls) { .kls_reglist_kls_size = kls->conf.kls_reglist_kls_size, }; tmp->reglist_kls = kls_new(tmp->conf.kls_reglist_kls_size); - tmp->max_regions_kls_alloc_basic = (tmp->reglist_kls->size - sizeof(Koliseo))/(sizeof(KLS_region_list_item) + sizeof(KLS_Region)); + tmp->max_regions_kls_alloc_basic = kls_temp_get_maxRegions_KLS_BASIC(tmp); } break; default: { @@ -2205,6 +2258,14 @@ KLS_Region_List kls_cons(Koliseo* kls, KLS_list_element e, KLS_Region_List l) { } break; case KLS_REGLIST_ALLOC_KLS_BASIC: { + if (kls->reglist_kls == NULL) { + fprintf(stderr,"[ERROR] at %s(): Koliseo->reglist_kls was NULL.\n",__func__); + #ifdef KLS_DEBUG_CORE + kls_log(kls,"ERROR","at %s(): Koliseo->reglist_kls was NULL.\n",__func__); + #endif + kls_free(kls); + exit(EXIT_FAILURE); + } t = KLS_PUSH(kls->reglist_kls,KLS_region_list_item,1); } break; @@ -2432,7 +2493,11 @@ KLS_Region_List kls_insord(Koliseo* kls, KLS_list_element el, KLS_Region_List l) } } -KLS_Region_List kls_insord_p(KLS_list_element el, KLS_Region_List l) { +KLS_Region_List kls_insord_p(Koliseo* kls, KLS_list_element el, KLS_Region_List l) { + if (kls == NULL) { + fprintf(stderr,"[ERROR] [%s()]: Koliseo was NULL.\n", __func__); + exit(EXIT_FAILURE); + } KLS_Region_List pprec, patt = l, paux; bool found = false; pprec = NULL; @@ -2448,7 +2513,33 @@ KLS_Region_List kls_insord_p(KLS_list_element el, KLS_Region_List l) { pprec = patt; patt = patt->next; } } - paux = (KLS_Region_List) malloc(sizeof(KLS_region_list_item)); + switch (kls->conf.kls_reglist_alloc_backend) { + case KLS_REGLIST_ALLOC_LIBC: { + paux = (KLS_Region_List) malloc(sizeof(KLS_region_list_item)); + } + break; + case KLS_REGLIST_ALLOC_KLS_BASIC: { + if (kls->reglist_kls == NULL) { + fprintf(stderr,"[ERROR] at %s(): Koliseo->reglist_kls was NULL.\n",__func__); + #ifdef KLS_DEBUG_CORE + kls_log(kls,"ERROR","at %s(): Koliseo->reglist_kls was NULL.\n",__func__); + #endif + kls_free(kls); + exit(EXIT_FAILURE); + } + paux = KLS_PUSH(kls->reglist_kls,KLS_region_list_item,1); + } + break; + default: { + fprintf(stderr,"[ERROR] at %s(): Unexpected conf.kls_reglist_alloc_backend value: {%i}.\n",__func__,kls->conf.kls_reglist_alloc_backend); + #ifdef KLS_DEBUG_CORE + kls_log(kls,"ERROR","at %s(): Unexpected conf.kls_reglist_alloc_backend value: {%i}.\n",__func__,kls->conf.kls_reglist_alloc_backend); + #endif + kls_free(kls); + exit(EXIT_FAILURE); + } + break; + } paux->value = el; paux->next = patt; if (patt == l) diff --git a/src/koliseo.h b/src/koliseo.h index 306ded7..533aeef 100644 --- a/src/koliseo.h +++ b/src/koliseo.h @@ -24,7 +24,7 @@ #define KLS_MAJOR 0 /**< Represents current major release.*/ #define KLS_MINOR 3 /**< Represents current minor release.*/ -#define KLS_PATCH 3 /**< Represents current patch release.*/ +#define KLS_PATCH 4 /**< Represents current patch release.*/ /*! \mainpage Koliseo index page * @@ -155,7 +155,7 @@ static const int KOLISEO_API_VERSION_INT = (KLS_MAJOR*1000000+KLS_MINOR*10000+KL /** * Defines current API version string. */ -static const char KOLISEO_API_VERSION_STRING[] = "0.3.3"; /**< Represents current version with MAJOR.MINOR.PATCH format.*/ +static const char KOLISEO_API_VERSION_STRING[] = "0.3.4"; /**< Represents current version with MAJOR.MINOR.PATCH format.*/ const char* string_koliseo_version(void); @@ -216,8 +216,6 @@ typedef struct KLS_Region { int type; /**< Used to identify which type the KLS_Region holds.*/ } KLS_Region; -#define KLS_REGIONS_MAX_IMPL(kls) (kls->size)/sizeof(KLS_Region) - static const char KOLISEO_DEFAULT_REGION_NAME[] = "No Name"; /**< Represents default Region name, used for kls_push_zero().*/ static const char KOLISEO_DEFAULT_REGION_DESC[] = "No Desc"; /**< Represents default Region desc, used for kls_push_zero().*/ @@ -294,6 +292,8 @@ typedef struct Koliseo_Temp { void kls_log(Koliseo* kls, const char* tag, const char* format, ...); ptrdiff_t kls_get_pos(Koliseo* kls); +int kls_get_maxRegions_KLS_BASIC(Koliseo* kls); +int kls_temp_get_maxRegions_KLS_BASIC(Koliseo_Temp* t_kls); Koliseo* kls_new(ptrdiff_t size); //bool kls_set_conf(Koliseo* kls, KLS_Conf conf); @@ -379,14 +379,14 @@ KLS_Region_List kls_copy(Koliseo*,KLS_Region_List); KLS_Region_List kls_delete(Koliseo*,KLS_list_element, KLS_Region_List); KLS_Region_List kls_insord(Koliseo*,KLS_list_element, KLS_Region_List); -#define KLS_PUSHLIST(reg,kls_list) kls_insord(reg,kls_list) -KLS_Region_List kls_insord_p(KLS_list_element, KLS_Region_List); -#define KLS_PUSHLIST_P(reg,kls_list) kls_insord_p(reg,kls_list) +#define KLS_PUSHLIST(kls,reg,kls_list) kls_insord(kls,reg,kls_list) +KLS_Region_List kls_insord_p(Koliseo*,KLS_list_element, KLS_Region_List); +#define KLS_PUSHLIST_P(kls,reg,kls_list) kls_insord_p(kls,reg,kls_list) KLS_Region_List kls_mergeList(Koliseo*,KLS_Region_List, KLS_Region_List); KLS_Region_List kls_intersect(Koliseo*,KLS_Region_List, KLS_Region_List); KLS_Region_List kls_diff(Koliseo*,KLS_Region_List, KLS_Region_List); -#define KLS_DIFF(kls_list1,kls_list2) kls_diff(kls_list1,kls_list2) +#define KLS_DIFF(kls,kls_list1,kls_list2) kls_diff(kls,kls_list1,kls_list2) bool kls_isLess(KLS_list_element, KLS_list_element); bool kls_isEqual(KLS_list_element, KLS_list_element); double kls_usageShare(KLS_list_element, Koliseo*); diff --git a/static/demo.c b/static/demo.c index 2e19ab1..6de48d1 100644 --- a/static/demo.c +++ b/static/demo.c @@ -48,7 +48,10 @@ int main(int argc, char** argv) { #ifndef _WIN32 printf("kls size: (%li) kls_region size: (%li)\n", kls->size, sizeof(KLS_Region)); - printf("Max KLS_Region on this size: %li\n", KLS_REGIONS_MAX_IMPL(kls)); + printf("Max KLS_Region on this size, when reglist alloc backend is KLS_BASIC: %i\n", kls_get_maxRegions_KLS_BASIC(kls)); + #else + printf("kls size: (%lli) kls_region size: (%lli)\n", kls->size, sizeof(KLS_Region)); + printf("Max KLS_Region on this size, when reglist alloc backend is KLS_BASIC: %i\n", kls_get_maxRegions_KLS_BASIC(kls)); #endif printf(KLS_Conf_Fmt "\n", KLS_Conf_Arg(kls->conf));