21#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
25#define _POSIX_C_SOURCE 200809L
50typedef void*(kls_alloc_func)(
size_t);
52#define STRINGIFY_2(x) #x
54#define STRINGIFY(x) STRINGIFY_2(x)
56#ifdef KOLISEO_HAS_REGION
62typedef enum KLS_RegList_Alloc_Backend {
63 KLS_REGLIST_ALLOC_LIBC = 0,
64 KLS_REGLIST_ALLOC_KLS_BASIC,
65 KLS_REGLIST_TOTAL_BACKENDS
66} KLS_RegList_Alloc_Backend;
87typedef struct KLS_Conf {
88#ifdef KOLISEO_HAS_REGION
89 int kls_autoset_regions;
90 KLS_RegList_Alloc_Backend kls_reglist_alloc_backend;
91 ptrdiff_t kls_reglist_kls_size;
92 int kls_autoset_temp_regions;
94 int kls_collect_stats;
97 const char *kls_log_filepath;
100KLS_Conf
kls_conf_init(
int autoset_regions,
int alloc_backend, ptrdiff_t reglist_kls_size,
int autoset_temp_regions,
int collect_stats,
int verbose_lvl, FILE* log_fp,
const char* log_filepath);
108typedef struct KLS_Stats {
115#ifdef KOLISEO_HAS_REGION
116 ptrdiff_t avg_region_size;
119 double worst_pushcall_time;
141#ifdef KOLISEO_HAS_REGION
143#define KLS_Conf_Fmt "KLS_Conf { autoset_regions: %i, reglist_backend: %s, reglist_kls_size: %li, autoset_temp_regions: %i, collect_stats: %i, verbose_lvl: %i, log_filepath: \"%s\", log_fp: %p }"
145#define KLS_Conf_Fmt "KLS_Conf { autoset_regions: %i, reglist_backend: %s, reglist_kls_size: %lli, autoset_temp_regions: %i, collect_stats: %i, verbose_lvl: %i, log_filepath: \"%s\", log_fp: %p }"
149#define KLS_Conf_Fmt "KLS_Conf { collect_stats: %i, verbose_lvl: %i, log_filepath: \"%s\", log_fp: %p }"
156#ifdef KOLISEO_HAS_REGION
157#define KLS_Conf_Arg(conf) (conf.kls_autoset_regions),kls_reglist_backend_string((conf.kls_reglist_alloc_backend)),(conf.kls_reglist_kls_size),(conf.kls_autoset_temp_regions),(conf.kls_collect_stats),(conf.kls_verbose_lvl),(conf.kls_log_filepath),(void*)(conf.kls_log_fp)
159#define KLS_Conf_Arg(conf) (conf.kls_collect_stats),(conf.kls_verbose_lvl),(conf.kls_log_filepath),(void*)(conf.kls_log_fp)
166#ifdef KOLISEO_HAS_REGION
171#define KLS_Stats_Fmt "KLS_Stats { tot_pushes: %i, tot_pops: %i, tot_temp_pushes: %i, tot_temp_pops: %i, avg_region_size: %li, tot_hiccups: %i, worst_push_time: %.9f }"
173#define KLS_Stats_Fmt "KLS_Stats { tot_pushes: %i, tot_pops: %i, tot_temp_pushes: %i, tot_temp_pops: %i, avg_region_size: %li, tot_hiccups: %i }"
179#define KLS_Stats_Fmt "KLS_Stats { tot_pushes: %i, tot_pops: %i, tot_temp_pushes: %i, tot_temp_pops: %i, avg_region_size: %lli, tot_hiccups: %i, worst_push_time: %.7f }"
181#define KLS_Stats_Fmt "KLS_Stats { tot_pushes: %i, tot_pops: %i, tot_temp_pushes: %i, tot_temp_pops: %i, avg_region_size: %lli, tot_hiccups: %i }"
188#define KLS_Stats_Fmt "KLS_Stats { tot_pushes: %i, tot_pops: %i, tot_temp_pushes: %i, tot_temp_pops: %i, tot_hiccups: %i, worst_push_time: %.7f }"
190#define KLS_Stats_Fmt "KLS_Stats { tot_pushes: %i, tot_pops: %i, tot_temp_pushes: %i, tot_temp_pops: %i, tot_hiccups: %i }"
199#ifdef KOLISEO_HAS_REGION
201#define KLS_Stats_Arg(stats) (stats.tot_pushes),(stats.tot_pops),(stats.tot_temp_pushes),(stats.tot_temp_pops),(stats.avg_region_size),(stats.tot_hiccups),(stats.worst_pushcall_time)
203#define KLS_Stats_Arg(stats) (stats.tot_pushes),(stats.tot_pops),(stats.tot_temp_pushes),(stats.tot_temp_pops),(stats.avg_region_size),(stats.tot_hiccups)
207#define KLS_Stats_Arg(stats) (stats.tot_pushes),(stats.tot_pops),(stats.tot_temp_pushes),(stats.tot_temp_pops),(stats.tot_hiccups),(stats.worst_pushcall_time)
209#define KLS_Stats_Arg(stats) (stats.tot_pushes),(stats.tot_pops),(stats.tot_temp_pushes),(stats.tot_temp_pops),(stats.tot_hiccups)
213#ifdef KOLISEO_HAS_REGION
220typedef struct KLS_Temp_Conf {
221 int kls_autoset_regions;
222 KLS_RegList_Alloc_Backend tkls_reglist_alloc_backend;
223 ptrdiff_t kls_reglist_kls_size;
232#define KLS_Temp_Conf_Fmt "KLS_Temp_Conf {autoset_regions: %i, tkls_reglist_alloc_backend: %i, kls_reglist_kls_size: %li}"
234#define KLS_Temp_Conf_Fmt "KLS_Temp_Conf {autoset_regions: %i, tkls_reglist_alloc_backend: %i, kls_reglist_kls_size: %lli}"
241#define KLS_Temp_Conf_Arg(conf) (conf.kls_autoset_regions),(conf.tkls_reglist_alloc_backend),(conf.kls_reglist_kls_size)
246static const int KOLISEO_API_VERSION_INT =
247 (KLS_MAJOR * 1000000 + KLS_MINOR * 10000 + KLS_PATCH * 100);
253static const char KOLISEO_API_VERSION_STRING[] =
"0.4.3";
265#ifdef KOLISEO_HAS_TITLE
266#define KLS_TITLEROWS 33
267extern char *
kls_title[KLS_TITLEROWS + 1];
274#define KLS_DEFAULT_SIZE (16*1024)
276#ifndef KLS_DEFAULT_ALIGNMENT
277#define KLS_DEFAULT_ALIGNMENT (2*sizeof(void *))
284typedef enum KLS_Region_Type {
294#define KLS_REGIONTYPE_MAX KLS_Header
300#define KLS_REGION_MAX_NAME_SIZE 15
305#define KLS_REGION_MAX_DESC_SIZE 20
307#ifdef KOLISEO_HAS_REGION
314typedef struct KLS_Region {
315 ptrdiff_t begin_offset;
316 ptrdiff_t end_offset;
319 char name[KLS_REGION_MAX_NAME_SIZE + 1];
320 char desc[KLS_REGION_MAX_DESC_SIZE + 1];
324static const char KOLISEO_DEFAULT_REGION_NAME[] =
"No Name";
325static const char KOLISEO_DEFAULT_REGION_DESC[] =
"No Desc";
327typedef KLS_Region *KLS_list_element;
333typedef struct KLS_list_region {
334 KLS_list_element value;
335 struct KLS_list_region *next;
336} KLS_region_list_item;
338typedef KLS_region_list_item *KLS_Region_List;
351typedef struct Koliseo {
355 ptrdiff_t prev_offset;
356#ifdef KOLISEO_HAS_REGION
357 KLS_Region_List regs;
358 struct Koliseo *reglist_kls;
359 int max_regions_kls_alloc_basic;
364 struct Koliseo_Temp *t_kls;
372#define KLSFmt "KLS {begin: %p, curr: %p, size: %li, offset: %li, has_temp: %i}"
374#define KLSFmt "KLS {begin: %p, curr: %p, size: %lli, offset: %lli, has_temp: %i}"
381#define KLS_Arg(kls) (void*)(kls),(void*)((kls)+(kls->offset)),(kls->size),(kls->offset),(kls->has_temp)
390typedef struct Koliseo_Temp {
393 ptrdiff_t prev_offset;
394#ifdef KOLISEO_HAS_REGION
395 KLS_Region_List t_regs;
396 Koliseo *reglist_kls;
397 int max_regions_kls_alloc_basic;
402void kls_log(Koliseo * kls,
const char *tag,
const char *format, ...);
405#ifdef KOLISEO_HAS_REGION
410Koliseo *
kls_new_alloc(ptrdiff_t size, kls_alloc_func alloc_func);
412#ifndef KLS_DEFAULT_ALLOCF
413#define KLS_DEFAULT_ALLOCF malloc
416#define kls_new(size) kls_new_alloc((size), KLS_DEFAULT_ALLOCF)
419#define kls_new_conf(size, conf) kls_new_conf_alloc((size), (conf), KLS_DEFAULT_ALLOCF)
420Koliseo *
kls_new_traced_alloc(ptrdiff_t size,
const char *output_path, kls_alloc_func alloc_func);
421#define kls_new_traced(size, output_path) kls_new_traced_alloc((size), (output_path), KLS_DEFAULT_ALLOCF)
423#define kls_new_dbg(size) kls_new_dbg_alloc((size), KLS_DEFAULT_ALLOCF)
425 ptrdiff_t reglist_kls_size, kls_alloc_func alloc_func);
426#define kls_new_traced_AR_KLS(size, output_path, reglist_kls_size) kls_new_traced_AR_KLS_alloc((size), (output_path), (reglist_kls_size), KLS_DEFAULT_ALLOCF)
429void *
kls_push_zero(Koliseo * kls, ptrdiff_t size, ptrdiff_t align,
433#ifdef KOLISEO_HAS_REGION
435 ptrdiff_t count,
char *name,
char *desc);
437 ptrdiff_t count,
int type,
char *name,
char *desc);
443#define KLS_PUSH_ARR(kls, type, count) (type*)kls_push_zero_AR((kls), sizeof(type), _Alignof(type), (count))
449#define KLS_PUSH_STR(kls, cstr) KLS_PUSH_ARR((kls), char, strlen((cstr))+1)
454#ifdef KOLISEO_HAS_REGION
455#define KLS_PUSH_ARR_NAMED(kls, type, count, name, desc) (type*)kls_push_zero_named((kls), sizeof(type), _Alignof(type), (count), (name), (desc))
457#define KLS_PUSH_ARR_NAMED(kls, type, count, name, desc) KLS_PUSH_ARR((kls),type,(count))
463#define KLS_PUSH_STR_NAMED(kls, cstr, name, desc) KLS_PUSH_ARR_NAMED((kls), char, strlen((cstr)), (name), (desc))
468#ifdef KOLISEO_HAS_REGION
469#define KLS_PUSH_ARR_TYPED(kls, type, count, region_type, name, desc) (type*)kls_push_zero_typed((kls), sizeof(type), _Alignof(type), (count), (region_type), (name), (desc))
471#define KLS_PUSH_ARR_TYPED(kls, type, count, region_type, name, desc) KLS_PUSH_ARR((kls),type,(count))
477#define KLS_PUSH_STR_TYPED(kls, cstr, region_type, name, desc) KLS_PUSH_ARR_TYPED((kls), char, strlen((cstr)), (region_type), (name), (desc))
482#define KLS_PUSH(kls, type) KLS_PUSH_ARR((kls), type, 1)
487#define KLS_PUSH_NAMED(kls, type, name, desc) KLS_PUSH_ARR_NAMED((kls), type, 1, (name), (desc))
493#define KLS_PUSH_EX(kls, type, name) KLS_PUSH_NAMED((kls), type, (name), STRINGIFY(type))
498#define KLS_PUSH_TYPED(kls, type, region_type, name, desc) KLS_PUSH_ARR_TYPED((kls), type, 1, (region_type), (name), (desc))
504#define KLS_PUSH_TYPED_EX(kls, type, region_type, name) KLS_PUSH_TYPED((kls), type, (region_type), (name), STRINGIFY(type))
510void kls_formatSize(ptrdiff_t size,
char *outputBuffer,
size_t bufferSize);
512#ifdef KOLISEO_HAS_CURSES
514#ifndef KOLISEO_CURSES_H_
515#define KOLISEO_CURSES_H_
520#include <ncursesw/ncurses.h>
525#ifdef KOLISEO_HAS_REGION
537 ptrdiff_t align, ptrdiff_t count);
538#ifdef KOLISEO_HAS_REGION
540 ptrdiff_t align, ptrdiff_t count,
char *name,
543 ptrdiff_t align, ptrdiff_t count,
int type,
544 char *name,
char *desc);
552#define KLS_PUSH_ARR_T(kls_temp, type, count) (type*)kls_temp_push_zero_AR((kls_temp), sizeof(type), _Alignof(type), (count))
558#define KLS_PUSH_STR_T(kls_temp, cstr) KLS_PUSH_ARR_T((kls_temp), char, strlen((cstr))+1)
563#ifdef KOLISEO_HAS_REGION
564#define KLS_PUSH_ARR_T_NAMED(kls_temp, type, count, name, desc) (type*)kls_temp_push_zero_named((kls_temp), sizeof(type), _Alignof(type), (count), (name), (desc))
566#define KLS_PUSH_ARR_T_NAMED(kls_temp, type, count, name, desc) KLS_PUSH_ARR_T((kls_temp),type,(count))
572#define KLS_PUSH_STR_T_NAMED(kls_temp, cstr, name, desc) KLS_PUSH_ARR_T_NAMED((kls_temp), char, strlen((cstr)), (name), (desc))
577#ifdef KOLISEO_HAS_REGION
578#define KLS_PUSH_ARR_T_TYPED(kls_temp, type, count, region_type, name, desc) (type*)kls_temp_push_zero_typed((kls_temp), sizeof(type), _Alignof(type), (count), (region_type), (name), (desc))
580#define KLS_PUSH_ARR_T_TYPED(kls_temp, type, count, region_type, name, desc) KLS_PUSH_ARR_T((kls_temp),type,(count))
586#define KLS_PUSH_STR_T_TYPED(kls_temp, cstr, region_type, name, desc) KLS_PUSH_ARR_T_TYPED((kls_temp), char, strlen((cstr)), (region_type), (name), (desc))
591#define KLS_PUSH_T(kls_temp, type) KLS_PUSH_ARR_T((kls_temp), type, 1)
596#define KLS_PUSH_T_NAMED(kls_temp, type, name, desc) KLS_PUSH_ARR_T_NAMED((kls_temp), type, 1, (name), (desc))
602#define KLS_PUSH_T_EX(kls_temp, type, name) KLS_PUSH_T_NAMED((kls_temp), type, (name), STRINGIFY(type))
607#define KLS_PUSH_T_TYPED(kls_temp, type, region_type, name, desc) KLS_PUSH_ARR_T_TYPED((kls_temp), type, 1, (region_type), (name), (desc))
613#define KLS_PUSH_T_TYPED_EX(kls_temp, type, region_type, name) KLS_PUSH_T_TYPED((kls_temp), type, (region_type), (name), STRINFIGY(type))
615#ifdef KOLISEO_HAS_REGION
618#define KLS_RL_GETLIST() kls_rl_emptyList()
622KLS_Region_List
kls_rl_cons(Koliseo *, KLS_list_element, KLS_Region_List);
623#ifdef KOLISEO_HAS_EXPER
624KLS_region_list_item* kls_rl_list_pop(Koliseo *kls);
626KLS_Region_List
kls_rl_t_cons(Koliseo_Temp *, KLS_list_element, KLS_Region_List);
627#ifdef KOLISEO_HAS_EXPER
628KLS_region_list_item* kls_rl_t_list_pop(Koliseo_Temp *t_kls);
632#define KLS_RL_FREELIST(kls_list) kls_rl_freeList(kls_list)
634#define kls_showList(list) kls_rl_showList((list))
636#define kls_showList_toFile(list, fp) kls_rl_showList_toFile((list), (fp))
637#define KLS_RL_ECHOLIST(kls_list) kls_rl_showList(kls_list)
638#define KLS_RL_PRINTLIST(kls_list,file) kls_rl_showList_toFile(kls_list,file)
641KLS_Region_List
kls_rl_append(Koliseo *, KLS_Region_List, KLS_Region_List);
643KLS_Region_List
kls_rl_copy(Koliseo *, KLS_Region_List);
644KLS_Region_List
kls_rl_delete(Koliseo *, KLS_list_element, KLS_Region_List);
646KLS_Region_List
kls_rl_insord(Koliseo *, KLS_list_element, KLS_Region_List);
647#define KLS_RL_PUSHLIST(kls,reg,kls_list) kls_rl_insord(kls,reg,kls_list)
648KLS_Region_List
kls_rl_insord_p(Koliseo *, KLS_list_element, KLS_Region_List);
649#define KLS_RL_PUSHLIST_P(kls,reg,kls_list) kls_rl_insord_p(kls,reg,kls_list)
650KLS_Region_List
kls_rl_mergeList(Koliseo *, KLS_Region_List, KLS_Region_List);
651KLS_Region_List
kls_rl_intersect(Koliseo *, KLS_Region_List, KLS_Region_List);
652KLS_Region_List
kls_rl_diff(Koliseo *, KLS_Region_List, KLS_Region_List);
654#define KLS_RL_DIFF(kls,kls_list1,kls_list2) kls_rl_diff(kls,kls_list1,kls_list2)
666#ifdef KOLISEO_HAS_GULP
668#ifndef KOLISEO_GULP_H_
669#define KOLISEO_GULP_H_
678Kstr
kstr_new(
const char* str,
size_t len);
680bool kstr_eq(Kstr left, Kstr right);
692#define KSTR(c_lit) kstr_new(c_lit, sizeof(c_lit) - 1)
693#define KSTR_NULL kstr_new(NULL, 0)
698#define Kstr_Fmt "%.*s"
702#define Kstr_Arg(kstr) (int) (kstr.len), (kstr.data)
711#define ONEGB_DEC_INT 1073741824
717#define GULP_MAX_FILE_SIZE ONEGB_DEC_INT
723typedef enum Gulp_Res {
727 GULP_FILE_READ_ERROR,
728 GULP_FILE_CONTAINS_NULLCHAR,
736#define Gulp_Res_Fmt "%s"
740#define Gulp_Res_Arg(gr) (string_from_Gulp_Res((gr)))
750char *
kls_gulp_file_sized(Koliseo* kls,
const char * filepath, Gulp_Res * err,
size_t max_size);
752#define KLS_GULP_FILE(kls, filepath) try_kls_gulp_file((kls),(filepath), GULP_MAX_FILE_SIZE)
756#define KLS_GULP_FILE_KSTR(kls, filepath) try_kls_gulp_file_to_kstr((kls),(filepath), GULP_MAX_FILE_SIZE, false)
762#ifdef KOLISEO_HAS_EXPER
764void *
kls_pop(Koliseo * kls, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count);
765void *
kls_pop_AR(Koliseo *kls, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count);
771#define KLS_POP_ARR(kls, type, count) (type*)kls_pop_AR((kls), sizeof(type), _Alignof(type), (count))
777#define KLS_POP_STR(kls, cstr) KLS_POP_ARR((kls), char, strlen((cstr)))
783#define KLS_POP(kls, type) KLS_POP_ARR((kls), type, 1)
785void *
kls_temp_pop(Koliseo_Temp * t_kls, ptrdiff_t size, ptrdiff_t align,
787void *
kls_temp_pop_AR(Koliseo_Temp *t_kls, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count);
793#define KLS_POP_ARR_T(kls_temp, type, count) (type*)kls_temp_pop_AR((kls_temp), sizeof(type), _Alignof(type), (count))
799#define KLS_POP_STR_T(kls_temp, cstr) KLS_POP_ARR_T((kls_temp), char, strlen((cstr)))
805#define KLS_POP_T(kls_temp, type) KLS_POP_ARR_T((kls_temp), type, 1)
817#define __KLS_STRCPY(dest, source) do {\
818 strcpy((dest), (source));\
826#define KLS_STRDUP(kls, source) kls_strdup((kls), (source))
836#define KLS_STRDUP_T(t_kls, source) kls_t_strdup((t_kls), (source))
841#error "This code requires C11 or later.\n _Alignof() is not available"
886#define LIST_IMPL(word) LIST_COMB1(LIST_PREFIX,word)
887#define LIST_COMB1(pre, word) LIST_COMB2(pre, word)
888#define LIST_COMB2(pre, word) pre##word
890#define LIST_HEADER_VERSION "0.1.0"
898#error "LIST_T must be defined"
905#define LIST_NAME LIST_COMB1(LIST_COMB1(list,_), LIST_T)
910#define LIST_PREFIX LIST_COMB1(LIST_NAME, _)
915#define LIST_LINKAGE static inline
920#define LIST_I_SUFFIX item
924#ifndef LIST_ITEM_NAME
925#define LIST_ITEM_NAME LIST_COMB1(LIST_COMB1(LIST_T,_), LIST_I_SUFFIX)
928typedef struct LIST_ITEM_NAME LIST_ITEM_NAME;
929struct LIST_ITEM_NAME {
931 struct LIST_ITEM_NAME* next;
933typedef LIST_ITEM_NAME* LIST_NAME;
935#define LIST_nullList LIST_IMPL(nullList)
936#define LIST_isEmpty LIST_IMPL(isEmpty)
937#define LIST_head LIST_IMPL(head)
938#define LIST_tail LIST_IMPL(tail)
939#define LIST_cons_gl LIST_IMPL(cons_gl)
940#define LIST_cons_kls LIST_IMPL(cons_kls)
941#define LIST_free_gl LIST_IMPL(free_gl)
942#define LIST_member LIST_IMPL(member)
943#define LIST_length LIST_IMPL(length)
944#define LIST_append_gl LIST_IMPL(append_gl)
945#define LIST_append_kls LIST_IMPL(append_kls)
946#define LIST_reverse_gl LIST_IMPL(reverse_gl)
947#define LIST_reverse_kls LIST_IMPL(reverse_kls)
948#define LIST_copy_gl LIST_IMPL(copy_gl)
949#define LIST_copy_kls LIST_IMPL(copy_kls)
950#define LIST_remove_gl LIST_IMPL(remove_gl)
951#define LIST_remove_kls LIST_IMPL(remove_kls)
952#define LIST_intersect_gl LIST_IMPL(intersect_gl)
953#define LIST_intersect_kls LIST_IMPL(intersect_kls)
954#define LIST_diff_gl LIST_IMPL(diff_gl)
955#define LIST_diff_kls LIST_IMPL(diff_kls)
957#ifdef LIST_DECLS_ONLY
965LIST_isEmpty(LIST_NAME list);
969LIST_head(LIST_NAME list);
973LIST_tail(LIST_NAME list);
977LIST_cons_gl(LIST_T* element, LIST_NAME list);
981LIST_cons_kls(Koliseo* kls, LIST_T* element, LIST_NAME list);
985LIST_free_gl(LIST_NAME list);
989LIST_member(LIST_T* element, LIST_NAME list);
993LIST_length(LIST_NAME list);
997LIST_append_gl(LIST_NAME l1, LIST_NAME l2);
1001LIST_append_kls(Koliseo* kls, LIST_NAME l1, LIST_NAME l2);
1005LIST_reverse_gl(LIST_NAME list);
1009LIST_reverse_kls(Koliseo* kls, LIST_NAME list);
1013LIST_copy_gl(LIST_NAME list);
1017LIST_copy_kls(Koliseo* kls, LIST_NAME list);
1021LIST_remove_gl(LIST_T* element, LIST_NAME list);
1025LIST_remove_kls(Koliseo* kls, LIST_T* element, LIST_NAME list);
1029LIST_intersect_gl(LIST_NAME l1, LIST_NAME l2);
1033LIST_intersect_kls(Koliseo* kls, LIST_NAME l1, LIST_NAME l2);
1037LIST_diff_gl(LIST_NAME l1, LIST_NAME l2);
1041LIST_diff_kls(Koliseo* kls, LIST_NAME l1, LIST_NAME l2);
1053LIST_isEmpty(LIST_NAME list)
1063LIST_head(LIST_NAME list)
1065 if (LIST_isEmpty(list)) {
1066 fprintf(stderr,
"%s at %i: %s(): List is empty.\n", __FILE__, __LINE__, __func__);
1074LIST_tail(LIST_NAME list)
1076 if (LIST_isEmpty(list)) {
1077 fprintf(stderr,
"%s at %i: %s(): List is empty.\n", __FILE__, __LINE__, __func__);
1085LIST_cons_gl(LIST_T* element, LIST_NAME list)
1088 t = (LIST_NAME) malloc(
sizeof(LIST_ITEM_NAME));
1096LIST_cons_kls(Koliseo* kls, LIST_T* element, LIST_NAME list)
1099 fprintf(stderr,
"%s at %i: %s(): Koliseo is NULL.\n", __FILE__, __LINE__, __func__);
1103 t = (LIST_NAME) KLS_PUSH_EX(kls, LIST_ITEM_NAME,
"List node");
1105 fprintf(stderr,
"%s at %i: %s(): Failed KLS_PUSH_EX() call.\n", __FILE__, __LINE__, __func__);
1115LIST_free_gl(LIST_NAME list)
1117 if (LIST_isEmpty(list)) {
1120 LIST_free_gl(LIST_tail(list));
1128LIST_member(LIST_T* element, LIST_NAME list)
1130 if (LIST_isEmpty(list)) {
1133 if (element == LIST_head(list)) {
1136 return LIST_member(element, LIST_tail(list));
1143LIST_length(LIST_NAME list)
1145 if (LIST_isEmpty(list)) {
1148 return 1 + LIST_length(LIST_tail(list));
1154LIST_append_gl(LIST_NAME l1, LIST_NAME l2)
1156 if (LIST_isEmpty(l1)) {
1159 return LIST_cons_gl(LIST_head(l1), LIST_append_gl(LIST_tail(l1), l2));
1165LIST_append_kls(Koliseo* kls, LIST_NAME l1, LIST_NAME l2)
1168 fprintf(stderr,
"%s at %i: %s(): Koliseo is NULL.\n", __FILE__, __LINE__, __func__);
1171 if (LIST_isEmpty(l1)) {
1174 return LIST_cons_kls(kls, LIST_head(l1), LIST_append_kls(kls, LIST_tail(l1), l2));
1180LIST_reverse_gl(LIST_NAME list)
1182 if (LIST_isEmpty(list)) {
1183 return LIST_nullList();
1185 return LIST_append_gl(LIST_reverse_gl(LIST_tail(list)), LIST_cons_gl(LIST_head(list), LIST_nullList()));
1191LIST_reverse_kls(Koliseo* kls, LIST_NAME list)
1194 fprintf(stderr,
"%s at %i: %s(): Koliseo is NULL.\n", __FILE__, __LINE__, __func__);
1197 if (LIST_isEmpty(list)) {
1198 return LIST_nullList();
1200 return LIST_append_kls(kls, LIST_reverse_kls(kls, LIST_tail(list)), LIST_cons_kls(kls, LIST_head(list), LIST_nullList()));
1206LIST_copy_gl(LIST_NAME list)
1208 if (LIST_isEmpty(list)) {
1211 return LIST_cons_gl(LIST_head(list), LIST_copy_gl(LIST_tail(list)));
1217LIST_copy_kls(Koliseo* kls, LIST_NAME list)
1220 fprintf(stderr,
"%s at %i: %s(): Koliseo is NULL.\n", __FILE__, __LINE__, __func__);
1223 if (LIST_isEmpty(list)) {
1226 return LIST_cons_kls(kls, LIST_head(list), LIST_copy_kls(kls, LIST_tail(list)));
1233LIST_remove_gl(LIST_T* element, LIST_NAME list)
1235 if (LIST_isEmpty(list)) {
1236 return LIST_nullList();
1238 if (element == LIST_head(list)) {
1239 return LIST_tail(list);
1241 return LIST_cons_gl(LIST_head(list), LIST_remove_gl(element, LIST_tail(list)));
1248LIST_remove_kls(Koliseo* kls, LIST_T* element, LIST_NAME list)
1251 fprintf(stderr,
"%s at %i: %s(): Koliseo is NULL.\n", __FILE__, __LINE__, __func__);
1254 if (LIST_isEmpty(list)) {
1255 return LIST_nullList();
1257 if (element == LIST_head(list)) {
1258 return LIST_tail(list);
1260 return LIST_cons_kls(kls, LIST_head(list), LIST_remove_kls(kls, element, LIST_tail(list)));
1267LIST_intersect_gl(LIST_NAME l1, LIST_NAME l2)
1269 if (LIST_isEmpty(l1) || LIST_isEmpty(l2)) {
1270 return LIST_nullList();
1272 if (LIST_member(LIST_head(l1), l2) && !(LIST_member(LIST_head(l1), LIST_tail(l2)))) {
1273 return LIST_cons_gl(LIST_head(l1), LIST_intersect_gl(LIST_tail(l1), l2));
1275 return LIST_intersect_gl(LIST_tail(l1), l2);
1281LIST_intersect_kls(Koliseo* kls, LIST_NAME l1, LIST_NAME l2)
1284 fprintf(stderr,
"%s at %i: %s(): Koliseo is NULL.\n", __FILE__, __LINE__, __func__);
1287 if (LIST_isEmpty(l1) || LIST_isEmpty(l2)) {
1288 return LIST_nullList();
1290 if (LIST_member(LIST_head(l1), l2) && !(LIST_member(LIST_head(l1), LIST_tail(l2)))) {
1291 return LIST_cons_kls(kls, LIST_head(l1), LIST_intersect_kls(kls, LIST_tail(l1), l2));
1293 return LIST_intersect_kls(kls, LIST_tail(l1), l2);
1299LIST_diff_gl(LIST_NAME l1, LIST_NAME l2)
1301 if (LIST_isEmpty(l1) || LIST_isEmpty(l2)) {
1304 if (!LIST_member(LIST_head(l1), l2) && !LIST_member(LIST_head(l1), LIST_tail(l1))) {
1305 return LIST_cons_gl(LIST_head(l1), LIST_diff_gl(LIST_tail(l1), l2));
1307 return LIST_diff_gl(LIST_tail(l1), l2);
1314LIST_diff_kls(Koliseo* kls, LIST_NAME l1, LIST_NAME l2)
1317 fprintf(stderr,
"%s at %i: %s(): Koliseo is NULL.\n", __FILE__, __LINE__, __func__);
1320 if (LIST_isEmpty(l1) || LIST_isEmpty(l2)) {
1323 if (!LIST_member(LIST_head(l1), l2) && !LIST_member(LIST_head(l1), LIST_tail(l1))) {
1324 return LIST_cons_kls(kls, LIST_head(l1), LIST_diff_kls(kls, LIST_tail(l1), l2));
1326 return LIST_diff_kls(kls, LIST_tail(l1), l2);
1340#undef LIST_ITEM_NAME
1350#undef LIST_append_gl
1351#undef LIST_append_kls
1352#undef LIST_reverse_gl
1353#undef LIST_reverse_kls
1356#undef LIST_remove_gl
1357#undef LIST_remove_kls
1358#undef LIST_intersect_gl
1359#undef LIST_intersect_kls
1362#ifdef LIST_DECLS_ONLY
1363#undef LIST_DECLS_ONLY
KLS_Region_List kls_rl_t_cons(Koliseo_Temp *t_kls, KLS_list_element e, KLS_Region_List l)
Definition koliseo.c:2800
void * kls_push_zero_AR(Koliseo *kls, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count)
Takes a Koliseo pointer, and ptrdiff_t values for size, align and count.
Definition koliseo.c:911
char * kls_strdup(Koliseo *kls, char *source)
Function to dupe a C string to a Koliseo, and return a pointer to the allocated string.
Definition koliseo.c:4141
void * kls_temp_pop(Koliseo_Temp *t_kls, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count)
Takes a Koliseo_Temp, and ptrdiff_t values for size, align and count.
Definition koliseo.c:4024
Koliseo_Temp * kls_temp_start(Koliseo *kls)
Starts a new savestate for the passed Koliseo pointer, by initialising its Koliseo_Temp pointer and r...
Definition koliseo.c:2461
KLS_Region_List kls_rl_cons(Koliseo *kls, KLS_list_element e, KLS_Region_List l)
Definition koliseo.c:2699
void kls_print_title(void)
Prints the title banner to stdout.
Definition koliseo.c:131
void print_dbg_temp_kls(const Koliseo_Temp *t_kls)
Prints header fields from the passed Koliseo_Temp pointer, to stderr.
Definition koliseo.c:1983
void print_temp_kls_2file(FILE *fp, const Koliseo_Temp *t_kls)
Prints header fields from the passed Koliseo_Temp pointer, to the passed FILE pointer.
Definition koliseo.c:1944
KLS_Region_List kls_rl_insord_p(Koliseo *kls, KLS_list_element el, KLS_Region_List l)
Definition koliseo.c:3056
char * kls_t_strdup(Koliseo_Temp *t_kls, char *source)
Function to dupe a C string to a Koliseo_Temp, and return a pointer to the allocated string.
Definition koliseo.c:4170
int kls_get_maxRegions_KLS_BASIC(Koliseo *kls)
Calcs the max number of possible KLS_PUSH ops when using KLS_BASIC reglist alloc backend.
Definition koliseo.c:252
const char * string_from_Gulp_Res(Gulp_Res g)
Return a constant string for the passed Gulp_Res.
Definition koliseo.c:3374
KLS_Stats KLS_STATS_DEFAULT
Definition koliseo.c:46
void kls_log(Koliseo *kls, const char *tag, const char *format,...)
Logs a message to the log_fp FILE field of the passed Koliseo pointer, if its conf....
Definition koliseo.c:325
Kstr * kls_gulp_file_sized_to_kstr(Koliseo *kls, const char *filepath, Gulp_Res *err, size_t max_size, bool allow_nullchar)
Tries mapping the passed file on the Koliseo.
Definition koliseo.c:3852
KLS_list_element kls_rl_head(KLS_Region_List l)
Definition koliseo.c:2681
void kls_temp_end(Koliseo_Temp *tmp_kls)
Ends passed Koliseo_Temp pointer.
Definition koliseo.c:2610
bool kls_rl_member(KLS_list_element el, KLS_Region_List l)
Definition koliseo.c:2959
void kls_dbg_features(void)
Prints enabled Koliseo features to stderr.
Definition koliseo.c:203
char ** kls_strdup_arr(Koliseo *kls, size_t count, char **source)
Function to dupe a C string array to a Koliseo, and return a pointer to the allocated array.
Definition koliseo.c:4154
bool kls_rl_isLess(KLS_Region *r1, KLS_Region *r2)
Compares two regions and returns true if the first one has a smaller size.
Definition koliseo.c:3196
void print_dbg_kls(const Koliseo *kls)
Prints header fields from the passed Koliseo pointer, to stderr.
Definition koliseo.c:1930
bool kstr_try_token(Kstr *k, char delim, Kstr *part)
Scans the first passed Kstr and if the passed char is present, the old Kstr is set to second pointer ...
Definition koliseo.c:3565
const char * string_koliseo_version(void)
Returns the constant string representing current version for Koliseo.
Definition koliseo.c:142
Kstr kstr_trim_left(Kstr kstr)
Returns a new Kstr after removing heading spaces from the passed one.
Definition koliseo.c:3494
bool kls_rl_empty(KLS_Region_List l)
Definition koliseo.c:2672
Koliseo * kls_new_dbg_alloc(ptrdiff_t size, kls_alloc_func alloc_func)
Takes a ptrdiff_t size and an allocation function pointer, and returns a pointer to the prepared Koli...
Definition koliseo.c:513
bool kstr_eq_ignorecase(Kstr left, Kstr right)
Checks if the two passed Kstr have equal data, ignoring case.
Definition koliseo.c:3432
char * kls_gulp_file_sized(Koliseo *kls, const char *filepath, Gulp_Res *err, size_t max_size)
Tries mapping the passed file on the Koliseo.
Definition koliseo.c:3712
ptrdiff_t kls_get_pos(const Koliseo *kls)
Returns the current offset (position of pointer bumper) for the passed Koliseo.
Definition koliseo.c:242
void * kls_temp_pop_AR(Koliseo_Temp *t_kls, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count)
Takes a Koliseo_Temp, and ptrdiff_t values for size, align and count.
Definition koliseo.c:4070
void * kls_pop_AR(Koliseo *kls, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count)
Takes a Koliseo pointer, and ptrdiff_t values for size, align and count.
Definition koliseo.c:3956
Kstr kstr_trim_right(Kstr kstr)
Returns a new Kstr after removing trailing spaces from the passed one.
Definition koliseo.c:3509
int kls_temp_get_maxRegions_KLS_BASIC(Koliseo_Temp *t_kls)
Calcs the max number of possible KLS_PUSH_T ops when using KLS_BASIC reglist alloc backend.
Definition koliseo.c:287
Kstr * try_kls_gulp_file_to_kstr(Koliseo *kls, const char *filepath, size_t max_size, bool allow_nullchar)
Tries mapping the passed file on the Koliseo.
Definition koliseo.c:3894
char * try_kls_gulp_file(Koliseo *kls, const char *filepath, size_t max_size)
Tries mapping the passed file on the Koliseo.
Definition koliseo.c:3753
Koliseo * kls_new_conf_alloc(ptrdiff_t size, KLS_Conf conf, kls_alloc_func alloc_func)
Takes a ptrdiff_t size, a KLS_Conf to configure the new Koliseo, and an allocation function pointer.
Definition koliseo.c:464
KLS_Region_List kls_rl_diff(Koliseo *kls, KLS_Region_List l1, KLS_Region_List l2)
Definition koliseo.c:3170
void kls_free(Koliseo *kls)
Calls kls_clear() on the passed Koliseo pointer and the frees the actual Koliseo.
Definition koliseo.c:2404
KLS_Region_List kls_rl_insord(Koliseo *kls, KLS_list_element el, KLS_Region_List l)
Definition koliseo.c:3038
KLS_Region_List kls_rl_emptyList(void)
Definition koliseo.c:2667
void kls_show_toWin(Koliseo *kls, WINDOW *win)
Prints fields and eventually KLS_Region_List from the passed Koliseo pointer, to the passed WINDOW po...
Definition koliseo.c:2018
Kstr kstr_cut_r(Kstr *k, size_t n)
Cuts the passed Kstr by up to n chars, from the right.
Definition koliseo.c:3477
void kls_rl_freeList(KLS_Region_List l)
Frees all values and nodes for passed Region list.
Definition koliseo.c:2896
Kstr kstr_from_c_lit(const char *c_lit)
Returns a new Kstr from the passed null-terminated string.
Definition koliseo.c:3401
Koliseo * kls_new_traced_alloc(ptrdiff_t size, const char *output_path, kls_alloc_func alloc_func)
Takes a ptrdiff_t size, a filepath for the trace output file, and an allocation function pointer.
Definition koliseo.c:489
char ** kls_t_strdup_arr(Koliseo_Temp *t_kls, size_t count, char **source)
Function to dupe a C string array to a Koliseo_Temp, and return a pointer to the allocated array.
Definition koliseo.c:4183
void * kls_temp_push_zero_AR(Koliseo_Temp *t_kls, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count)
Takes a Koliseo_Temp, and ptrdiff_t values for size, align and count.
Definition koliseo.c:1065
ptrdiff_t kls_regionSize(KLS_Region *r)
Return size of a passed KLS_Region.
Definition koliseo.c:3244
void * kls_push_zero_named(Koliseo *kls, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count, char *name, char *desc)
Takes a Koliseo pointer, and ptrdiff_t values for size, align and count.
Definition koliseo.c:1233
int kls_rl_length(KLS_Region_List l)
Definition koliseo.c:2972
Kstr kstr_cut_l(Kstr *k, size_t n)
Cuts the passed Kstr by up to n chars, from the left.
Definition koliseo.c:3458
void * kls_temp_push_zero_named(Koliseo_Temp *t_kls, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count, char *name, char *desc)
Takes a Koliseo_Temp, and ptrdiff_t values for size, align and count.
Definition koliseo.c:1393
void kls_usageReport_toFile(Koliseo *kls, FILE *fp)
Prints an usage report for the passed Koliseo to the passed file.
Definition koliseo.c:3287
KLS_Region_List kls_rl_copy(Koliseo *kls, KLS_Region_List l)
Definition koliseo.c:3008
KLS_Region_List kls_rl_reverse(Koliseo *kls, KLS_Region_List l)
Definition koliseo.c:2994
void * kls_push_zero(Koliseo *kls, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count)
Takes a Koliseo pointer, and ptrdiff_t values for size, align and count.
Definition koliseo.c:818
ptrdiff_t kls_avg_regionSize(Koliseo *kls)
Return average region size in usage for the passed Koliseo.
Definition koliseo.c:3254
KLS_Region_List kls_rl_delete(Koliseo *kls, KLS_list_element el, KLS_Region_List l)
Definition koliseo.c:3021
bool kls_rl_isEqual(KLS_Region *r1, KLS_Region *r2)
Compares two regions and returns true if their size is equal.
Definition koliseo.c:3210
void kls_temp_show_toWin(Koliseo_Temp *t_kls, WINDOW *win)
Takes a Koliseo_Temp pointer and prints fields and eventually KLS_Region_List from the referred Kolis...
Definition koliseo.c:2099
Kstr kstr_token(Kstr *k, char delim)
Scans the passed Kstr and cuts it up to the first occurrence of passed char, even if it is not presen...
Definition koliseo.c:3593
Koliseo * kls_new_alloc(ptrdiff_t size, kls_alloc_func alloc_func)
Takes a ptrdiff_t size and a function pointer to the allocation function.
Definition koliseo.c:367
void * kls_pop(Koliseo *kls, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count)
Takes a Koliseo pointer, and ptrdiff_t values for size, align and count.
Definition koliseo.c:3919
void * kls_temp_push_zero_typed(Koliseo_Temp *t_kls, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count, int type, char *name, char *desc)
Takes a Koliseo_Temp, a KLS_Region_Type index, and ptrdiff_t values for size, align and count.
Definition koliseo.c:1725
KLS_Region_List kls_rl_tail(KLS_Region_List l)
Definition koliseo.c:2690
KLS_Region_List kls_rl_append(Koliseo *kls, KLS_Region_List l1, KLS_Region_List l2)
Definition koliseo.c:2981
void kls_rl_showList_toFile(KLS_Region_List l, FILE *fp)
Definition koliseo.c:2915
KLS_Conf KLS_DEFAULT_CONF
Definition koliseo.c:33
const char * kls_reglist_backend_strings[KLS_REGLIST_TOTAL_BACKENDS]
Definition koliseo.c:62
void kls_print_title_2file(FILE *fp)
Prints the title banner to the passed FILE pointer.
Definition koliseo.c:115
KLS_Region_List kls_rl_mergeList(Koliseo *kls, KLS_Region_List l1, KLS_Region_List l2)
Definition koliseo.c:3119
Kstr kstr_trim(Kstr kstr)
Returns a new Kstr after removing heading and trailing spaces from the passed one.
Definition koliseo.c:3526
KLS_Region_List kls_rl_intersect(Koliseo *kls, KLS_Region_List l1, KLS_Region_List l2)
Definition koliseo.c:3149
void print_kls_2file(FILE *fp, const Koliseo *kls)
Prints header fields from the passed Koliseo pointer, to the passed FILE pointer.
Definition koliseo.c:1890
void kls_rl_showList(KLS_Region_List l)
Definition koliseo.c:2954
double kls_usageShare(KLS_Region *r, Koliseo *kls)
Returns the ratio of memory used by the passed KLS_Region relative to the passed Koliseo as a double.
Definition koliseo.c:3224
void kls_temp_showList_toWin(Koliseo_Temp *t_kls, WINDOW *win)
Displays a slideshow of KLS_Region_List from passed Koliseo_Temp, to the passed WINDOW pointer.
Definition koliseo.c:2288
void kls_showList_toWin(Koliseo *kls, WINDOW *win)
Displays a slideshow of KLS_Region_List from passed Koliseo, to the passed WINDOW pointer.
Definition koliseo.c:2201
ptrdiff_t kls_type_usage(int type, Koliseo *kls)
Calc memory used by the specific type of KLS_list_element.
Definition koliseo.c:3329
Kstr kstr_token_kstr(Kstr *k, Kstr delim)
Definition koliseo.c:3613
void kls_clear(Koliseo *kls)
Resets the offset field for the passed Koliseo pointer.
Definition koliseo.c:2384
const char * kls_reglist_backend_string(KLS_RegList_Alloc_Backend kls_be)
Definition koliseo.c:157
Koliseo * kls_new_traced_AR_KLS_alloc(ptrdiff_t size, const char *output_path, ptrdiff_t reglist_kls_size, kls_alloc_func alloc_func)
Takes a ptrdiff_t size and a filepath for the trace output file, and the needed parameters for a succ...
Definition koliseo.c:540
char * kls_title[KLS_TITLEROWS+1]
Defines title banner.
Definition koliseo.c:74
void * kls_push_zero_typed(Koliseo *kls, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count, int type, char *name, char *desc)
Takes a Koliseo pointer, a KLS_Region_Type index, and ptrdiff_t values for size, align and count.
Definition koliseo.c:1566
void kls_formatSize(ptrdiff_t size, char *outputBuffer, size_t bufferSize)
Converts a ptrdiff_t size to human-readable SI units (modulo 1000).
Definition koliseo.c:1995
void kls_usageReport(Koliseo *kls)
Print usage report for passed Koliseo to stdout.
Definition koliseo.c:3317
int int_koliseo_version(void)
Returns the constant int representing current version for Koliseo.
Definition koliseo.c:151
bool kstr_indexof(Kstr k, char c, int *idx)
Checks if passed Kstr contains the passed char, and if so, sets the value pointed by idx to the first...
Definition koliseo.c:3539
const char * gulp_res_names[TOT_GULP_RES+1]
Contains the constant string representation of Gulp_Res values.
Definition koliseo.c:3357
bool kstr_eq(Kstr left, Kstr right)
Checks if the two passed Kstr have exactly equal data.
Definition koliseo.c:3413
KLS_Conf kls_conf_init(int autoset_regions, int alloc_backend, ptrdiff_t reglist_kls_size, int autoset_temp_regions, int collect_stats, int verbose_lvl, FILE *log_fp, const char *log_filepath)
Used to prepare a KLS_Conf without caring about KOLISEO_HAS_REGIONS.
Definition koliseo.c:178
Kstr kstr_new(const char *data, size_t len)
Returns a new Kstr with the passed args set.
Definition koliseo.c:3387