21#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
25#define _POSIX_C_SOURCE 200809L
48#include <profileapi.h>
52#ifdef KOLISEO_HAS_LOCATE
53typedef struct Koliseo_Loc {
59#define KLS_HERE (Koliseo_Loc){ \
69#define KLS_Loc_Fmt "[%s:%i at %s():] "
75#define KLS_Loc_Arg(loc) (loc.file), (loc.line), (loc.func)
82typedef void*(kls_alloc_func)(
size_t);
84#define STRINGIFY_2(x) #x
86#define STRINGIFY(x) STRINGIFY_2(x)
88#ifdef KOLISEO_HAS_REGION
94typedef enum KLS_RegList_Alloc_Backend {
95 KLS_REGLIST_ALLOC_LIBC = 0,
96 KLS_REGLIST_ALLOC_KLS_BASIC,
97 KLS_REGLIST_TOTAL_BACKENDS
98} KLS_RegList_Alloc_Backend;
118static const int KOLISEO_API_VERSION_INT =
119 (KLS_MAJOR * 1000000 + KLS_MINOR * 10000 + KLS_PATCH * 100);
125static const char KOLISEO_API_VERSION_STRING[] =
"0.4.6";
137#define KLS_DEFAULT_SIZE (16*1024)
139#ifndef KLS_DEFAULT_ALIGNMENT
140#define KLS_DEFAULT_ALIGNMENT (2*sizeof(void *))
147typedef enum KLS_Region_Type {
157#define KLS_REGIONTYPE_MAX KLS_Header
163#define KLS_REGION_MAX_NAME_SIZE 15
168#define KLS_REGION_MAX_DESC_SIZE 20
170#ifdef KOLISEO_HAS_REGION
177typedef struct KLS_Region {
178 ptrdiff_t begin_offset;
179 ptrdiff_t end_offset;
182 char name[KLS_REGION_MAX_NAME_SIZE + 1];
183 char desc[KLS_REGION_MAX_DESC_SIZE + 1];
187static const char KOLISEO_DEFAULT_REGION_NAME[] =
"No Name";
188static const char KOLISEO_DEFAULT_REGION_DESC[] =
"No Desc";
190typedef KLS_Region *KLS_list_element;
196typedef struct KLS_list_region {
197 KLS_list_element value;
198 struct KLS_list_region *next;
199} KLS_region_list_item;
201typedef KLS_region_list_item *KLS_Region_List;
207#ifndef KOLISEO_HAS_LOCATE
208typedef void(KLS_OOM_Handler)(
struct Koliseo* kls, ptrdiff_t available, ptrdiff_t padding, ptrdiff_t size, ptrdiff_t count);
210typedef void(KLS_OOM_Handler)(
struct Koliseo* kls, ptrdiff_t available, ptrdiff_t padding, ptrdiff_t size, ptrdiff_t count, Koliseo_Loc loc);
213#ifndef KOLISEO_HAS_LOCATE
214typedef void(KLS_PTRDIFF_MAX_Handler)(
struct Koliseo* kls, ptrdiff_t size, ptrdiff_t count);
216typedef void(KLS_PTRDIFF_MAX_Handler)(
struct Koliseo* kls, ptrdiff_t size, ptrdiff_t count, Koliseo_Loc loc);
219#ifndef KOLISEO_HAS_LOCATE
220void KLS_OOM_default_handler__(
struct Koliseo* kls, ptrdiff_t available, ptrdiff_t padding, ptrdiff_t size, ptrdiff_t count);
222void KLS_OOM_default_handler_dbg__(
struct Koliseo* kls, ptrdiff_t available, ptrdiff_t padding, ptrdiff_t size, ptrdiff_t count, Koliseo_Loc loc);
225#ifndef KOLISEO_HAS_LOCATE
228void KLS_PTRDIFF_MAX_default_handler_dbg__(
struct Koliseo* kls, ptrdiff_t size, ptrdiff_t count, Koliseo_Loc loc);
235typedef struct KLS_Err_Handlers {
236 KLS_OOM_Handler* OOM_handler;
237 KLS_PTRDIFF_MAX_Handler* PTRDIFF_MAX_handler;
240#ifndef KOLISEO_HAS_LOCATE
241#define KLS_DEFAULT_ERR_HANDLERS (KLS_Err_Handlers) { .OOM_handler = &KLS_OOM_default_handler__, .PTRDIFF_MAX_handler = &KLS_PTRDIFF_MAX_default_handler__, }
243#define KLS_DEFAULT_ERR_HANDLERS (KLS_Err_Handlers) { .OOM_handler = &KLS_OOM_default_handler_dbg__, .PTRDIFF_MAX_handler = &KLS_PTRDIFF_MAX_default_handler_dbg__, }
250typedef struct KLS_Conf {
251#ifdef KOLISEO_HAS_REGION
252 int kls_autoset_regions;
253 KLS_RegList_Alloc_Backend kls_reglist_alloc_backend;
254 ptrdiff_t kls_reglist_kls_size;
255 int kls_autoset_temp_regions;
257 int kls_collect_stats;
260 const char *kls_log_filepath;
261 int kls_block_while_has_temp;
262 KLS_Err_Handlers err_handlers;
265KLS_Conf
kls_conf_init_handled(
int autoset_regions,
int alloc_backend, ptrdiff_t reglist_kls_size,
int autoset_temp_regions,
int collect_stats,
int verbose_lvl,
int block_while_has_temp, FILE* log_fp,
const char* log_filepath, KLS_Err_Handlers err_handlers);
267KLS_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,
int block_while_has_temp, FILE* log_fp,
const char* log_filepath);
275typedef struct KLS_Stats {
282#ifdef KOLISEO_HAS_REGION
283 ptrdiff_t avg_region_size;
286 double worst_pushcall_time;
308#ifdef KOLISEO_HAS_REGION
310#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 }"
312#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 }"
316#define KLS_Conf_Fmt "KLS_Conf { collect_stats: %i, verbose_lvl: %i, log_filepath: \"%s\", log_fp: %p }"
323#ifdef KOLISEO_HAS_REGION
324#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)
326#define KLS_Conf_Arg(conf) (conf.kls_collect_stats),(conf.kls_verbose_lvl),(conf.kls_log_filepath),(void*)(conf.kls_log_fp)
333#ifdef KOLISEO_HAS_REGION
338#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 }"
340#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 }"
346#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 }"
348#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 }"
355#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 }"
357#define KLS_Stats_Fmt "KLS_Stats { tot_pushes: %i, tot_pops: %i, tot_temp_pushes: %i, tot_temp_pops: %i, tot_hiccups: %i }"
366#ifdef KOLISEO_HAS_REGION
368#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)
370#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)
374#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)
376#define KLS_Stats_Arg(stats) (stats.tot_pushes),(stats.tot_pops),(stats.tot_temp_pushes),(stats.tot_temp_pops),(stats.tot_hiccups)
380#ifdef KOLISEO_HAS_REGION
387typedef struct KLS_Temp_Conf {
388 int kls_autoset_regions;
389 KLS_RegList_Alloc_Backend tkls_reglist_alloc_backend;
390 ptrdiff_t kls_reglist_kls_size;
399#define KLS_Temp_Conf_Fmt "KLS_Temp_Conf {autoset_regions: %i, tkls_reglist_alloc_backend: %i, kls_reglist_kls_size: %li}"
401#define KLS_Temp_Conf_Fmt "KLS_Temp_Conf {autoset_regions: %i, tkls_reglist_alloc_backend: %i, kls_reglist_kls_size: %lli}"
408#define KLS_Temp_Conf_Arg(conf) (conf.kls_autoset_regions),(conf.tkls_reglist_alloc_backend),(conf.kls_reglist_kls_size)
418typedef struct Koliseo {
422 ptrdiff_t prev_offset;
423#ifdef KOLISEO_HAS_REGION
424 KLS_Region_List regs;
425 struct Koliseo *reglist_kls;
426 int max_regions_kls_alloc_basic;
431 struct Koliseo_Temp *t_kls;
439#define KLSFmt "KLS {begin: %p, curr: %p, size: %li, offset: %li, has_temp: %i}"
441#define KLSFmt "KLS {begin: %p, curr: %p, size: %lli, offset: %lli, has_temp: %i}"
448#define KLS_Arg(kls) (void*)(kls),(void*)((kls)+(kls->offset)),(kls->size),(kls->offset),(kls->has_temp)
457typedef struct Koliseo_Temp {
460 ptrdiff_t prev_offset;
461#ifdef KOLISEO_HAS_REGION
462 KLS_Region_List t_regs;
463 Koliseo *reglist_kls;
464 int max_regions_kls_alloc_basic;
469void kls_log(Koliseo * kls,
const char *tag,
const char *format, ...);
472#ifdef KOLISEO_HAS_REGION
477#ifndef KOLISEO_HAS_LOCATE
478Koliseo *
kls_new_alloc(ptrdiff_t size, kls_alloc_func alloc_func);
480Koliseo *kls_new_alloc_dbg(ptrdiff_t size, kls_alloc_func alloc_func, Koliseo_Loc loc);
481#define kls_new_alloc(size, alloc_func) kls_new_alloc_dbg((size), (alloc_func), KLS_HERE)
484#ifndef KLS_DEFAULT_ALLOCF
485#define KLS_DEFAULT_ALLOCF malloc
488#define kls_new(size) kls_new_alloc((size), KLS_DEFAULT_ALLOCF)
491#define kls_new_conf(size, conf) kls_new_conf_alloc((size), (conf), KLS_DEFAULT_ALLOCF)
492Koliseo *
kls_new_traced_alloc_handled(ptrdiff_t size,
const char *output_path, kls_alloc_func alloc_func, KLS_Err_Handlers err_handlers);
493Koliseo *
kls_new_traced_alloc(ptrdiff_t size,
const char *output_path, kls_alloc_func alloc_func);
494#define kls_new_traced(size, output_path) kls_new_traced_alloc((size), (output_path), KLS_DEFAULT_ALLOCF)
495#define kls_new_traced_handled(size, output_path, err_handlers) kls_new_traced_alloc_handled((size), (output_path), KLS_DEFAULT_ALLOCF, (err_handlers))
498#define kls_new_dbg(size) kls_new_dbg_alloc((size), KLS_DEFAULT_ALLOCF)
499#define kls_new_dbg_handled(size, err_handlers) kls_new_dbg_alloc_handled((size), KLS_DEFAULT_ALLOCF,(err_handlers))
501 ptrdiff_t reglist_kls_size, kls_alloc_func alloc_func, KLS_Err_Handlers err_handlers);
503 ptrdiff_t reglist_kls_size, kls_alloc_func alloc_func);
504#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)
505#define kls_new_traced_AR_KLS_handled(size, output_path, reglist_kls_size, err_handlers) kls_new_traced_AR_KLS_alloc_handled((size), (output_path), (reglist_kls_size), KLS_DEFAULT_ALLOCF, (err_handlers))
509#ifndef KOLISEO_HAS_LOCATE
510void *
kls_push_zero(Koliseo * kls, ptrdiff_t size, ptrdiff_t align,
513void *kls_push_zero_dbg(Koliseo * kls, ptrdiff_t size, ptrdiff_t align,
514 ptrdiff_t count, Koliseo_Loc loc);
516#define kls_push_zero(kls, size, align, count) kls_push_zero_dbg((kls), (size), (align), (count), KLS_HERE)
519#ifndef KOLISEO_HAS_LOCATE
523void *kls_push_zero_AR_dbg(Koliseo * kls, ptrdiff_t size, ptrdiff_t align,
524 ptrdiff_t count, Koliseo_Loc loc);
525#define kls_push_zero_AR(kls, size, align, count) kls_push_zero_AR_dbg((kls), (size), (align), (count), KLS_HERE)
528#ifdef KOLISEO_HAS_REGION
530#ifndef KOLISEO_HAS_LOCATE
532 ptrdiff_t count,
char *name,
char *desc);
534void *kls_push_zero_named_dbg(Koliseo * kls, ptrdiff_t size, ptrdiff_t align,
535 ptrdiff_t count,
char *name,
char *desc, Koliseo_Loc loc);
536#define kls_push_zero_named(kls, size, align, count, name, desc) kls_push_zero_named_dbg((kls), (size), (align), (count), (name), (desc), KLS_HERE)
539#ifndef KOLISEO_HAS_LOCATE
541 ptrdiff_t count,
int type,
char *name,
char *desc);
543void *kls_push_zero_typed_dbg(Koliseo * kls, ptrdiff_t size, ptrdiff_t align,
544 ptrdiff_t count,
int type,
char *name,
char *desc, Koliseo_Loc loc);
545#define kls_push_zero_typed(kls, size, align, count, type, name, desc) kls_push_zero_typed_dbg((kls), (size), (align), (count), (type), (name), (desc), KLS_HERE)
552#define KLS_PUSH_ARR(kls, type, count) (type*)kls_push_zero_AR((kls), sizeof(type), _Alignof(type), (count))
558#define KLS_PUSH_STR(kls, cstr) KLS_PUSH_ARR((kls), char, strlen((cstr))+1)
563#ifdef KOLISEO_HAS_REGION
564#define KLS_PUSH_ARR_NAMED(kls, type, count, name, desc) (type*)kls_push_zero_named((kls), sizeof(type), _Alignof(type), (count), (name), (desc))
566#define KLS_PUSH_ARR_NAMED(kls, type, count, name, desc) KLS_PUSH_ARR((kls),type,(count))
572#define KLS_PUSH_STR_NAMED(kls, cstr, name, desc) KLS_PUSH_ARR_NAMED((kls), char, strlen((cstr)), (name), (desc))
577#ifdef KOLISEO_HAS_REGION
578#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))
580#define KLS_PUSH_ARR_TYPED(kls, type, count, region_type, name, desc) KLS_PUSH_ARR((kls),type,(count))
586#define KLS_PUSH_STR_TYPED(kls, cstr, region_type, name, desc) KLS_PUSH_ARR_TYPED((kls), char, strlen((cstr)), (region_type), (name), (desc))
591#define KLS_PUSH(kls, type) KLS_PUSH_ARR((kls), type, 1)
596#define KLS_PUSH_NAMED(kls, type, name, desc) KLS_PUSH_ARR_NAMED((kls), type, 1, (name), (desc))
602#define KLS_PUSH_EX(kls, type, name) KLS_PUSH_NAMED((kls), type, (name), STRINGIFY(type))
607#define KLS_PUSH_TYPED(kls, type, region_type, name, desc) KLS_PUSH_ARR_TYPED((kls), type, 1, (region_type), (name), (desc))
613#define KLS_PUSH_TYPED_EX(kls, type, region_type, name) KLS_PUSH_TYPED((kls), type, (region_type), (name), STRINGIFY(type))
619void kls_formatSize(ptrdiff_t size,
char *outputBuffer,
size_t bufferSize);
621#ifndef KOLISEO_HAS_LOCATE
624Koliseo_Temp *kls_temp_start_dbg(Koliseo * kls, Koliseo_Loc loc);
625#define kls_temp_start(kls) kls_temp_start_dbg((kls), KLS_HERE)
630#ifndef KOLISEO_HAS_LOCATE
632 ptrdiff_t align, ptrdiff_t count);
634void *kls_temp_push_zero_AR_dbg(Koliseo_Temp * t_kls, ptrdiff_t size,
635 ptrdiff_t align, ptrdiff_t count, Koliseo_Loc loc);
636#define kls_temp_push_zero_AR(t_kls, size, align, count) kls_temp_push_zero_AR_dbg((t_kls), (size), (align), (count), KLS_HERE)
639#ifdef KOLISEO_HAS_REGION
640#ifndef KOLISEO_HAS_LOCATE
642 ptrdiff_t align, ptrdiff_t count,
char *name,
645void *kls_temp_push_zero_named_dbg(Koliseo_Temp * t_kls, ptrdiff_t size,
646 ptrdiff_t align, ptrdiff_t count,
char *name,
647 char *desc, Koliseo_Loc loc);
648#define kls_temp_push_zero_named(t_kls, size, align, count, name, desc) kls_temp_push_zero_named_dbg((t_kls), (size), (align), (count), (name), (desc), KLS_HERE)
651#ifndef KOLISEO_HAS_LOCATE
653 ptrdiff_t align, ptrdiff_t count,
int type,
654 char *name,
char *desc);
656void *kls_temp_push_zero_typed_dbg(Koliseo_Temp * t_kls, ptrdiff_t size,
657 ptrdiff_t align, ptrdiff_t count,
int type,
658 char *name,
char *desc, Koliseo_Loc loc);
659#define kls_temp_push_zero_typed(t_kls, size, align, count, type, name, desc) kls_temp_push_zero_typed_dbg((t_kls), (size), (align), (count), (type), (name), (desc), KLS_HERE)
668#define KLS_PUSH_ARR_T(kls_temp, type, count) (type*)kls_temp_push_zero_AR((kls_temp), sizeof(type), _Alignof(type), (count))
674#define KLS_PUSH_STR_T(kls_temp, cstr) KLS_PUSH_ARR_T((kls_temp), char, strlen((cstr))+1)
679#ifdef KOLISEO_HAS_REGION
680#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))
682#define KLS_PUSH_ARR_T_NAMED(kls_temp, type, count, name, desc) KLS_PUSH_ARR_T((kls_temp),type,(count))
688#define KLS_PUSH_STR_T_NAMED(kls_temp, cstr, name, desc) KLS_PUSH_ARR_T_NAMED((kls_temp), char, strlen((cstr)), (name), (desc))
693#ifdef KOLISEO_HAS_REGION
694#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))
696#define KLS_PUSH_ARR_T_TYPED(kls_temp, type, count, region_type, name, desc) KLS_PUSH_ARR_T((kls_temp),type,(count))
702#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))
707#define KLS_PUSH_T(kls_temp, type) KLS_PUSH_ARR_T((kls_temp), type, 1)
712#define KLS_PUSH_T_NAMED(kls_temp, type, name, desc) KLS_PUSH_ARR_T_NAMED((kls_temp), type, 1, (name), (desc))
718#define KLS_PUSH_T_EX(kls_temp, type, name) KLS_PUSH_T_NAMED((kls_temp), type, (name), STRINGIFY(type))
723#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))
729#define KLS_PUSH_T_TYPED_EX(kls_temp, type, region_type, name) KLS_PUSH_T_TYPED((kls_temp), type, (region_type), (name), STRINFIGY(type))
731#ifdef KOLISEO_HAS_REGION
734#define KLS_RL_GETLIST() kls_rl_emptyList()
738KLS_Region_List
kls_rl_cons(Koliseo *, KLS_list_element, KLS_Region_List);
739#ifdef KOLISEO_HAS_EXPER
740KLS_region_list_item* kls_rl_list_pop(Koliseo *kls);
742KLS_Region_List
kls_rl_t_cons(Koliseo_Temp *, KLS_list_element, KLS_Region_List);
743#ifdef KOLISEO_HAS_EXPER
744KLS_region_list_item* kls_rl_t_list_pop(Koliseo_Temp *t_kls);
748#define KLS_RL_FREELIST(kls_list) kls_rl_freeList(kls_list)
750#define kls_showList(list) kls_rl_showList((list))
752#define kls_showList_toFile(list, fp) kls_rl_showList_toFile((list), (fp))
753#define KLS_RL_ECHOLIST(kls_list) kls_rl_showList(kls_list)
754#define KLS_RL_PRINTLIST(kls_list,file) kls_rl_showList_toFile(kls_list,file)
757KLS_Region_List
kls_rl_append(Koliseo *, KLS_Region_List, KLS_Region_List);
759KLS_Region_List
kls_rl_copy(Koliseo *, KLS_Region_List);
760KLS_Region_List
kls_rl_delete(Koliseo *, KLS_list_element, KLS_Region_List);
762KLS_Region_List
kls_rl_insord(Koliseo *, KLS_list_element, KLS_Region_List);
763#define KLS_RL_PUSHLIST(kls,reg,kls_list) kls_rl_insord(kls,reg,kls_list)
764KLS_Region_List
kls_rl_insord_p(Koliseo *, KLS_list_element, KLS_Region_List);
765#define KLS_RL_PUSHLIST_P(kls,reg,kls_list) kls_rl_insord_p(kls,reg,kls_list)
766KLS_Region_List
kls_rl_mergeList(Koliseo *, KLS_Region_List, KLS_Region_List);
767KLS_Region_List
kls_rl_intersect(Koliseo *, KLS_Region_List, KLS_Region_List);
768KLS_Region_List
kls_rl_diff(Koliseo *, KLS_Region_List, KLS_Region_List);
770#define KLS_RL_DIFF(kls,kls_list1,kls_list2) kls_rl_diff(kls,kls_list1,kls_list2)
782#ifdef KOLISEO_HAS_GULP
784#ifndef KOLISEO_GULP_H_
785#define KOLISEO_GULP_H_
794Kstr
kstr_new(
const char* str,
size_t len);
796bool kstr_eq(Kstr left, Kstr right);
808#define KSTR(c_lit) kstr_new(c_lit, sizeof(c_lit) - 1)
809#define KSTR_NULL kstr_new(NULL, 0)
814#define Kstr_Fmt "%.*s"
818#define Kstr_Arg(kstr) (int) (kstr.len), (kstr.data)
827#define ONEGB_DEC_INT 1073741824
833#define GULP_MAX_FILE_SIZE ONEGB_DEC_INT
839typedef enum Gulp_Res {
843 GULP_FILE_READ_ERROR,
844 GULP_FILE_CONTAINS_NULLCHAR,
852#define Gulp_Res_Fmt "%s"
856#define Gulp_Res_Arg(gr) (string_from_Gulp_Res((gr)))
866char *
kls_gulp_file_sized(Koliseo* kls,
const char * filepath, Gulp_Res * err,
size_t max_size);
868#define KLS_GULP_FILE(kls, filepath) try_kls_gulp_file((kls),(filepath), GULP_MAX_FILE_SIZE)
872#define KLS_GULP_FILE_KSTR(kls, filepath) try_kls_gulp_file_to_kstr((kls),(filepath), GULP_MAX_FILE_SIZE, false)
878#ifdef KOLISEO_HAS_EXPER
880void *
kls_pop(Koliseo * kls, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count);
881void *
kls_pop_AR(Koliseo *kls, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count);
887#define KLS_POP_ARR(kls, type, count) (type*)kls_pop_AR((kls), sizeof(type), _Alignof(type), (count))
893#define KLS_POP_STR(kls, cstr) KLS_POP_ARR((kls), char, strlen((cstr)))
899#define KLS_POP(kls, type) KLS_POP_ARR((kls), type, 1)
901void *
kls_temp_pop(Koliseo_Temp * t_kls, ptrdiff_t size, ptrdiff_t align,
903void *
kls_temp_pop_AR(Koliseo_Temp *t_kls, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count);
909#define KLS_POP_ARR_T(kls_temp, type, count) (type*)kls_temp_pop_AR((kls_temp), sizeof(type), _Alignof(type), (count))
915#define KLS_POP_STR_T(kls_temp, cstr) KLS_POP_ARR_T((kls_temp), char, strlen((cstr)))
921#define KLS_POP_T(kls_temp, type) KLS_POP_ARR_T((kls_temp), type, 1)
933#define KLS__STRCPY(dest, source) do {\
934 strcpy((dest), (source));\
942#define KLS_STRDUP(kls, source) kls_strdup((kls), (source))
952#define KLS_STRDUP_T(t_kls, source) kls_t_strdup((t_kls), (source))
957#error "This code requires C11 or later.\n _Alignof() is not available"
KLS_Region_List kls_rl_t_cons(Koliseo_Temp *t_kls, KLS_list_element e, KLS_Region_List l)
Definition koliseo.c:2461
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:1335
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:3802
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:3685
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:2119
KLS_Region_List kls_rl_cons(Koliseo *kls, KLS_list_element e, KLS_Region_List l)
Definition koliseo.c:2360
void print_dbg_temp_kls(const Koliseo_Temp *t_kls)
Prints header fields from the passed Koliseo_Temp pointer, to stderr.
Definition koliseo.c:2007
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:1968
KLS_Region_List kls_rl_insord_p(Koliseo *kls, KLS_list_element el, KLS_Region_List l)
Definition koliseo.c:2717
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:3831
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:332
const char * string_from_Gulp_Res(Gulp_Res g)
Return a constant string for the passed Gulp_Res.
Definition koliseo.c:3035
KLS_Stats KLS_STATS_DEFAULT
Definition koliseo.c:66
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:405
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:3513
KLS_list_element kls_rl_head(KLS_Region_List l)
Definition koliseo.c:2342
void kls_temp_end(Koliseo_Temp *tmp_kls)
Ends passed Koliseo_Temp pointer.
Definition koliseo.c:2271
bool kls_rl_member(KLS_list_element el, KLS_Region_List l)
Definition koliseo.c:2620
void kls_dbg_features(void)
Prints enabled Koliseo features to stderr.
Definition koliseo.c:249
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:3815
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:2857
void print_dbg_kls(const Koliseo *kls)
Prints header fields from the passed Koliseo pointer, to stderr.
Definition koliseo.c:1954
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:3226
const char * string_koliseo_version(void)
Returns the constant string representing current version for Koliseo.
Definition koliseo.c:94
Kstr kstr_trim_left(Kstr kstr)
Returns a new Kstr after removing heading spaces from the passed one.
Definition koliseo.c:3155
KLS_Conf kls_conf_init_handled(int autoset_regions, int alloc_backend, ptrdiff_t reglist_kls_size, int autoset_temp_regions, int collect_stats, int verbose_lvl, int block_while_has_temp, FILE *log_fp, const char *log_filepath, KLS_Err_Handlers err_handlers)
Used to prepare a KLS_Conf without caring about KOLISEO_HAS_REGIONS.
Definition koliseo.c:193
bool kls_rl_empty(KLS_Region_List l)
Definition koliseo.c:2333
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:668
bool kstr_eq_ignorecase(Kstr left, Kstr right)
Checks if the two passed Kstr have equal data, ignoring case.
Definition koliseo.c:3093
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:3373
ptrdiff_t kls_get_pos(const Koliseo *kls)
Returns the current offset (position of pointer bumper) for the passed Koliseo.
Definition koliseo.c:322
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:3731
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:3617
Kstr kstr_trim_right(Kstr kstr)
Returns a new Kstr after removing trailing spaces from the passed one.
Definition koliseo.c:3170
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:367
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:3555
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:3414
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:559
KLS_Region_List kls_rl_diff(Koliseo *kls, KLS_Region_List l1, KLS_Region_List l2)
Definition koliseo.c:2831
void kls_free(Koliseo *kls)
Calls kls_clear() on the passed Koliseo pointer and the frees the actual Koliseo.
Definition koliseo.c:2061
KLS_Region_List kls_rl_insord(Koliseo *kls, KLS_list_element el, KLS_Region_List l)
Definition koliseo.c:2699
KLS_Region_List kls_rl_emptyList(void)
Definition koliseo.c:2328
Kstr kstr_cut_r(Kstr *k, size_t n)
Cuts the passed Kstr by up to n chars, from the right.
Definition koliseo.c:3138
void kls_rl_freeList(KLS_Region_List l)
Frees all values and nodes for passed Region list.
Definition koliseo.c:2557
Kstr kstr_from_c_lit(const char *c_lit)
Returns a new Kstr from the passed null-terminated string.
Definition koliseo.c:3062
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:619
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:3844
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:1432
ptrdiff_t kls_regionSize(KLS_Region *r)
Return size of a passed KLS_Region.
Definition koliseo.c:2905
Koliseo * kls_new_dbg_alloc_handled(ptrdiff_t size, kls_alloc_func alloc_func, KLS_Err_Handlers err_handlers)
Takes a ptrdiff_t size and an allocation function pointer, and returns a pointer to the prepared Koli...
Definition koliseo.c:636
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:1530
int kls_rl_length(KLS_Region_List l)
Definition koliseo.c:2633
Kstr kstr_cut_l(Kstr *k, size_t n)
Cuts the passed Kstr by up to n chars, from the left.
Definition koliseo.c:3119
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:1628
void kls_usageReport_toFile(Koliseo *kls, FILE *fp)
Prints an usage report for the passed Koliseo to the passed file.
Definition koliseo.c:2948
KLS_Region_List kls_rl_copy(Koliseo *kls, KLS_Region_List l)
Definition koliseo.c:2669
KLS_Region_List kls_rl_reverse(Koliseo *kls, KLS_Region_List l)
Definition koliseo.c:2655
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:1095
ptrdiff_t kls_avg_regionSize(Koliseo *kls)
Return average region size in usage for the passed Koliseo.
Definition koliseo.c:2915
KLS_Region_List kls_rl_delete(Koliseo *kls, KLS_list_element el, KLS_Region_List l)
Definition koliseo.c:2682
bool kls_rl_isEqual(KLS_Region *r1, KLS_Region *r2)
Compares two regions and returns true if their size is equal.
Definition koliseo.c:2871
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:3254
Koliseo * kls_new_traced_AR_KLS_alloc_handled(ptrdiff_t size, const char *output_path, ptrdiff_t reglist_kls_size, kls_alloc_func alloc_func, KLS_Err_Handlers err_handlers)
Takes a ptrdiff_t size and a filepath for the trace output file, and the needed parameters for a succ...
Definition koliseo.c:687
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:449
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:3580
void KLS_PTRDIFF_MAX_default_handler__(struct Koliseo *kls, ptrdiff_t size, ptrdiff_t count)
Definition koliseo.c:156
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:1824
KLS_Region_List kls_rl_tail(KLS_Region_List l)
Definition koliseo.c:2351
KLS_Region_List kls_rl_append(Koliseo *kls, KLS_Region_List l1, KLS_Region_List l2)
Definition koliseo.c:2642
void kls_rl_showList_toFile(KLS_Region_List l, FILE *fp)
Definition koliseo.c:2576
KLS_Conf KLS_DEFAULT_CONF
Config used by any new Koliseo by default.
Definition koliseo.c:43
const char * kls_reglist_backend_strings[KLS_REGLIST_TOTAL_BACKENDS]
Definition koliseo.c:82
Koliseo * kls_new_traced_alloc_handled(ptrdiff_t size, const char *output_path, kls_alloc_func alloc_func, KLS_Err_Handlers err_handlers)
Takes a ptrdiff_t size, a filepath for the trace output file, and an allocation function pointer.
Definition koliseo.c:585
KLS_Region_List kls_rl_mergeList(Koliseo *kls, KLS_Region_List l1, KLS_Region_List l2)
Definition koliseo.c:2780
Kstr kstr_trim(Kstr kstr)
Returns a new Kstr after removing heading and trailing spaces from the passed one.
Definition koliseo.c:3187
KLS_Region_List kls_rl_intersect(Koliseo *kls, KLS_Region_List l1, KLS_Region_List l2)
Definition koliseo.c:2810
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:1914
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, int block_while_has_temp, FILE *log_fp, const char *log_filepath)
Used to prepare a KLS_Conf without caring about KOLISEO_HAS_REGIONS.
Definition koliseo.c:240
void kls_rl_showList(KLS_Region_List l)
Definition koliseo.c:2615
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:2885
ptrdiff_t kls_type_usage(int type, Koliseo *kls)
Calc memory used by the specific type of KLS_list_element.
Definition koliseo.c:2990
Kstr kstr_token_kstr(Kstr *k, Kstr delim)
Definition koliseo.c:3274
void kls_clear(Koliseo *kls)
Resets the offset field for the passed Koliseo pointer.
Definition koliseo.c:2041
const char * kls_reglist_backend_string(KLS_RegList_Alloc_Backend kls_be)
Definition koliseo.c:109
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:730
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:1727
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:2019
void KLS_OOM_default_handler__(Koliseo *kls, ptrdiff_t available, ptrdiff_t padding, ptrdiff_t size, ptrdiff_t count)
Used internally for handling Out-Of-Memory in push calls when no user handler is provided.
Definition koliseo.c:136
void kls_usageReport(Koliseo *kls)
Print usage report for passed Koliseo to stdout.
Definition koliseo.c:2978
int int_koliseo_version(void)
Returns the constant int representing current version for Koliseo.
Definition koliseo.c:103
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:3200
const char * gulp_res_names[TOT_GULP_RES+1]
Contains the constant string representation of Gulp_Res values.
Definition koliseo.c:3018
bool kstr_eq(Kstr left, Kstr right)
Checks if the two passed Kstr have exactly equal data.
Definition koliseo.c:3074
Kstr kstr_new(const char *data, size_t len)
Returns a new Kstr with the passed args set.
Definition koliseo.c:3048