Skip to content

Commit

Permalink
feat: 0.3.4 add kls_get_maxRegions_KLS_BASIC() (#39)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
jgabaut committed Oct 23, 2023
1 parent 1e3a497 commit 91d097d
Show file tree
Hide file tree
Showing 9 changed files with 143 additions and 43 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/make-anviltest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
workflow_dispatch:

jobs:
build:
anviltest:
runs-on: ubuntu-latest

steps:
Expand Down
53 changes: 27 additions & 26 deletions bin/stego.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions bin/v0.3.4/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#amboso compliant version folder, will ignore everything inside BUT the gitignore, to keep the clean dir
*
!.gitignore
!static
1 change: 1 addition & 0 deletions bin/v0.3.4/static
4 changes: 2 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Define the package name and version
AC_INIT([koliseo], [0.3.3], [[email protected]])
AC_INIT([koliseo], [0.3.4], [[email protected]])

# Verify automake version and enable foreign option
AM_INIT_AUTOMAKE([foreign -Wall])
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/koliseo.doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
99 changes: 95 additions & 4 deletions src/koliseo.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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)
Expand Down
16 changes: 8 additions & 8 deletions src/koliseo.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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().*/

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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*);
Expand Down
5 changes: 4 additions & 1 deletion static/demo.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit 91d097d

Please sign in to comment.