koliseo 0.4.3
Loading...
Searching...
No Matches
koliseo.h
Go to the documentation of this file.
1// jgabaut @ github.com/jgabaut
2// SPDX-License-Identifier: GPL-3.0-only
3/*
4 Copyright (C) 2023-2024 jgabaut
5
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, version 3 of the License.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>.
17*/
18
19#ifndef KOLISEO_H_
20
21#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) //We need C11
22#define KOLISEO_H_
23
24#ifndef _WIN32
25#define _POSIX_C_SOURCE 200809L
26#endif
27
28#include <stdio.h>
29#include <stdint.h>
30#include <stddef.h>
31#include <stdlib.h>
32#include <stdarg.h>
33#include <assert.h>
34#include <string.h>
35#include <time.h>
36#include <stdbool.h>
37
38#ifdef KLS_DEBUG_CORE
39#include <time.h>
40
41#ifdef _WIN32
42#include <windows.h> //Used for QueryPerformanceFrequency(), QueryPerformanceCounter()
43#endif
44#endif //KLS_DEBUG_CORE
45
46#define KLS_MAJOR 0
47#define KLS_MINOR 4
48#define KLS_PATCH 3
50typedef void*(kls_alloc_func)(size_t);
52#define STRINGIFY_2(x) #x
53
54#define STRINGIFY(x) STRINGIFY_2(x)
55
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;
67
73extern const char* kls_reglist_backend_strings[KLS_REGLIST_TOTAL_BACKENDS];
74
80const char* kls_reglist_backend_string(KLS_RegList_Alloc_Backend kls_be);
81#endif // KOLISEO_HAS_REGION
82
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;
93#endif // KOLISEO_HAS_REGION
94 int kls_collect_stats;
95 int kls_verbose_lvl;
96 FILE *kls_log_fp;
97 const char *kls_log_filepath;
98} KLS_Conf;
99
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);
101
102void kls_dbg_features(void);
103
108typedef struct KLS_Stats {
109 int tot_pushes;
110 int tot_temp_pushes;
111 int tot_pops;
112 int tot_temp_pops;
113 int tot_logcalls;
114 int tot_hiccups;
115#ifdef KOLISEO_HAS_REGION
116 ptrdiff_t avg_region_size;
117#endif
118#ifdef KLS_DEBUG_CORE
119 double worst_pushcall_time;
120#endif
121} KLS_Stats;
122
128extern KLS_Conf KLS_DEFAULT_CONF;
129
135extern KLS_Stats KLS_STATS_DEFAULT;
136
141#ifdef KOLISEO_HAS_REGION
142#ifndef _WIN32
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 }"
144#else
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 }"
146#endif
147#else
148
149#define KLS_Conf_Fmt "KLS_Conf { collect_stats: %i, verbose_lvl: %i, log_filepath: \"%s\", log_fp: %p }"
150#endif // KOLISEO_HAS_REGION
151
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)
158#else
159#define KLS_Conf_Arg(conf) (conf.kls_collect_stats),(conf.kls_verbose_lvl),(conf.kls_log_filepath),(void*)(conf.kls_log_fp)
160#endif // KOLISEO_HAS_REGION
161
166#ifdef KOLISEO_HAS_REGION
167
168#ifndef _WIN32
169
170#ifdef KLS_DEBUG_CORE
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 }"
172#else
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 }"
174#endif // KLS_DEBUG_CORE
175
176#else
177
178#ifdef KLS_DEBUG_CORE
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 }"
180#else
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 }"
182#endif // KLS_DEBUG_CORE
183#endif // _WIN32
184
185#else
186
187#ifdef KLS_DEBUG_CORE
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 }"
189#else
190#define KLS_Stats_Fmt "KLS_Stats { tot_pushes: %i, tot_pops: %i, tot_temp_pushes: %i, tot_temp_pops: %i, tot_hiccups: %i }"
191#endif // KLS_DEBUG_CORE
192
193#endif // KOLISEO_HAS_REGION
194
199#ifdef KOLISEO_HAS_REGION
200#ifdef KLS_DEBUG_CORE
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)
202#else
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)
204#endif // KLS_DEBUG_CORE
205#else
206#ifdef KLS_DEBUG_CORE
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)
208#else
209#define KLS_Stats_Arg(stats) (stats.tot_pushes),(stats.tot_pops),(stats.tot_temp_pushes),(stats.tot_temp_pops),(stats.tot_hiccups)
210#endif // KLS_DEBUG_CORE
211#endif // KOLISEO_HAS_REGION
212
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;
224} KLS_Temp_Conf;
225#endif // KOLISEO_HAS_REGION
226
231#ifndef _WIN32
232#define KLS_Temp_Conf_Fmt "KLS_Temp_Conf {autoset_regions: %i, tkls_reglist_alloc_backend: %i, kls_reglist_kls_size: %li}"
233#else
234#define KLS_Temp_Conf_Fmt "KLS_Temp_Conf {autoset_regions: %i, tkls_reglist_alloc_backend: %i, kls_reglist_kls_size: %lli}"
235#endif
236
241#define KLS_Temp_Conf_Arg(conf) (conf.kls_autoset_regions),(conf.tkls_reglist_alloc_backend),(conf.kls_reglist_kls_size)
242
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";
258const char *string_koliseo_version(void);
259
263int int_koliseo_version(void);
264
265#ifdef KOLISEO_HAS_TITLE
266#define KLS_TITLEROWS 33
267extern char *kls_title[KLS_TITLEROWS + 1];
270void kls_print_title_2file(FILE * fp);
271void kls_print_title(void);
272#endif // KOLISEO_HAS_TITLE
273
274#define KLS_DEFAULT_SIZE (16*1024)
276#ifndef KLS_DEFAULT_ALIGNMENT
277#define KLS_DEFAULT_ALIGNMENT (2*sizeof(void *))
278#endif
279
284typedef enum KLS_Region_Type {
285 KLS_None = 0,
286 Temp_KLS_Header = 1,
287 KLS_Header = 2,
288} KLS_Region_Type;
289
294#define KLS_REGIONTYPE_MAX KLS_Header
295
300#define KLS_REGION_MAX_NAME_SIZE 15
305#define KLS_REGION_MAX_DESC_SIZE 20
306
307#ifdef KOLISEO_HAS_REGION
308
314typedef struct KLS_Region {
315 ptrdiff_t begin_offset;
316 ptrdiff_t end_offset;
317 ptrdiff_t size;
318 ptrdiff_t padding;
319 char name[KLS_REGION_MAX_NAME_SIZE + 1];
320 char desc[KLS_REGION_MAX_DESC_SIZE + 1];
321 int type;
322} KLS_Region;
323
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;
337
338typedef KLS_region_list_item *KLS_Region_List;
339#endif // KOLISEO_HAS_REGION
340
341struct Koliseo_Temp; //Forward declaration for Koliseo itself
342
351typedef struct Koliseo {
352 char *data;
353 ptrdiff_t size;
354 ptrdiff_t offset;
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;
360#endif
361 int has_temp;
362 KLS_Conf conf;
363 KLS_Stats stats;
364 struct Koliseo_Temp *t_kls;
365} Koliseo;
366
371#ifndef _WIN32
372#define KLSFmt "KLS {begin: %p, curr: %p, size: %li, offset: %li, has_temp: %i}"
373#else
374#define KLSFmt "KLS {begin: %p, curr: %p, size: %lli, offset: %lli, has_temp: %i}"
375#endif
376
381#define KLS_Arg(kls) (void*)(kls),(void*)((kls)+(kls->offset)),(kls->size),(kls->offset),(kls->has_temp)
382
390typedef struct Koliseo_Temp {
391 Koliseo *kls;
392 ptrdiff_t offset;
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;
398 KLS_Temp_Conf conf;
399#endif
400} Koliseo_Temp;
401
402void kls_log(Koliseo * kls, const char *tag, const char *format, ...);
403ptrdiff_t kls_get_pos(const Koliseo * kls);
404
405#ifdef KOLISEO_HAS_REGION
406int kls_get_maxRegions_KLS_BASIC(Koliseo * kls);
407int kls_temp_get_maxRegions_KLS_BASIC(Koliseo_Temp * t_kls);
408#endif
409
410Koliseo *kls_new_alloc(ptrdiff_t size, kls_alloc_func alloc_func);
411
412#ifndef KLS_DEFAULT_ALLOCF
413#define KLS_DEFAULT_ALLOCF malloc
414#endif
415
416#define kls_new(size) kls_new_alloc((size), KLS_DEFAULT_ALLOCF)
417//bool kls_set_conf(Koliseo* kls, KLS_Conf conf);
418Koliseo *kls_new_conf_alloc(ptrdiff_t size, KLS_Conf conf, kls_alloc_func alloc_func);
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)
422Koliseo *kls_new_dbg_alloc(ptrdiff_t size, kls_alloc_func alloc_func);
423#define kls_new_dbg(size) kls_new_dbg_alloc((size), KLS_DEFAULT_ALLOCF)
424Koliseo *kls_new_traced_AR_KLS_alloc(ptrdiff_t size, const char *output_path,
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)
427
428//void* kls_push(Koliseo* kls, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count);
429void *kls_push_zero(Koliseo * kls, ptrdiff_t size, ptrdiff_t align,
430 ptrdiff_t count);
431void *kls_push_zero_AR(Koliseo * kls, ptrdiff_t size, ptrdiff_t align,
432 ptrdiff_t count);
433#ifdef KOLISEO_HAS_REGION
434void *kls_push_zero_named(Koliseo * kls, ptrdiff_t size, ptrdiff_t align,
435 ptrdiff_t count, char *name, char *desc);
436void *kls_push_zero_typed(Koliseo * kls, ptrdiff_t size, ptrdiff_t align,
437 ptrdiff_t count, int type, char *name, char *desc);
438#endif // KOLISEO_HAS_REGION
439
443#define KLS_PUSH_ARR(kls, type, count) (type*)kls_push_zero_AR((kls), sizeof(type), _Alignof(type), (count))
444
449#define KLS_PUSH_STR(kls, cstr) KLS_PUSH_ARR((kls), char, strlen((cstr))+1)
450
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))
456#else
457#define KLS_PUSH_ARR_NAMED(kls, type, count, name, desc) KLS_PUSH_ARR((kls),type,(count))
458#endif // KOLISEO_HAS_REGION
459
463#define KLS_PUSH_STR_NAMED(kls, cstr, name, desc) KLS_PUSH_ARR_NAMED((kls), char, strlen((cstr)), (name), (desc))
464
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))
470#else
471#define KLS_PUSH_ARR_TYPED(kls, type, count, region_type, name, desc) KLS_PUSH_ARR((kls),type,(count))
472#endif // KOLISEO_HAS_REGION
473
477#define KLS_PUSH_STR_TYPED(kls, cstr, region_type, name, desc) KLS_PUSH_ARR_TYPED((kls), char, strlen((cstr)), (region_type), (name), (desc))
478
482#define KLS_PUSH(kls, type) KLS_PUSH_ARR((kls), type, 1)
483
487#define KLS_PUSH_NAMED(kls, type, name, desc) KLS_PUSH_ARR_NAMED((kls), type, 1, (name), (desc))
488
493#define KLS_PUSH_EX(kls, type, name) KLS_PUSH_NAMED((kls), type, (name), STRINGIFY(type))
494
498#define KLS_PUSH_TYPED(kls, type, region_type, name, desc) KLS_PUSH_ARR_TYPED((kls), type, 1, (region_type), (name), (desc))
499
504#define KLS_PUSH_TYPED_EX(kls, type, region_type, name) KLS_PUSH_TYPED((kls), type, (region_type), (name), STRINGIFY(type))
505
506void kls_clear(Koliseo * kls);
507void kls_free(Koliseo * kls);
508void print_kls_2file(FILE * fp, const Koliseo * kls);
509void print_dbg_kls(const Koliseo * kls);
510void kls_formatSize(ptrdiff_t size, char *outputBuffer, size_t bufferSize);
511
512#ifdef KOLISEO_HAS_CURSES
514#ifndef KOLISEO_CURSES_H_
515#define KOLISEO_CURSES_H_
516
517#ifndef _WIN32
518#include "ncurses.h"
519#else
520#include <ncursesw/ncurses.h>
521#endif // _WIN32
522
523void kls_show_toWin(Koliseo * kls, WINDOW * win);
524void kls_temp_show_toWin(Koliseo_Temp * t_kls, WINDOW * win);
525#ifdef KOLISEO_HAS_REGION
526void kls_showList_toWin(Koliseo * kls, WINDOW * win);
527void kls_temp_showList_toWin(Koliseo_Temp * t_kls, WINDOW * win);
528#endif // KOLISEO_HAS_REGION
529#endif //KOLISEO_CURSES_H_
530
531#endif //KOLISEO_HAS_CURSES
532
533Koliseo_Temp *kls_temp_start(Koliseo * kls);
534//bool kls_temp_set_conf(Koliseo_Temp* t_kls, KLS_Temp_Conf conf);
535void kls_temp_end(Koliseo_Temp * tmp_kls);
536void *kls_temp_push_zero_AR(Koliseo_Temp * t_kls, ptrdiff_t size,
537 ptrdiff_t align, ptrdiff_t count);
538#ifdef KOLISEO_HAS_REGION
539void *kls_temp_push_zero_named(Koliseo_Temp * t_kls, ptrdiff_t size,
540 ptrdiff_t align, ptrdiff_t count, char *name,
541 char *desc);
542void *kls_temp_push_zero_typed(Koliseo_Temp * t_kls, ptrdiff_t size,
543 ptrdiff_t align, ptrdiff_t count, int type,
544 char *name, char *desc);
545#endif // KOLISEO_HAS_REGION
546void print_temp_kls_2file(FILE * fp, const Koliseo_Temp * t_kls);
547void print_dbg_temp_kls(const Koliseo_Temp * t_kls);
548
552#define KLS_PUSH_ARR_T(kls_temp, type, count) (type*)kls_temp_push_zero_AR((kls_temp), sizeof(type), _Alignof(type), (count))
553
558#define KLS_PUSH_STR_T(kls_temp, cstr) KLS_PUSH_ARR_T((kls_temp), char, strlen((cstr))+1)
559
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))
565#else
566#define KLS_PUSH_ARR_T_NAMED(kls_temp, type, count, name, desc) KLS_PUSH_ARR_T((kls_temp),type,(count))
567#endif // KOLISEO_HAS_REGION
568
572#define KLS_PUSH_STR_T_NAMED(kls_temp, cstr, name, desc) KLS_PUSH_ARR_T_NAMED((kls_temp), char, strlen((cstr)), (name), (desc))
573
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))
579#else
580#define KLS_PUSH_ARR_T_TYPED(kls_temp, type, count, region_type, name, desc) KLS_PUSH_ARR_T((kls_temp),type,(count))
581#endif // KOLISEO_HAS_REGION
582
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))
587
591#define KLS_PUSH_T(kls_temp, type) KLS_PUSH_ARR_T((kls_temp), type, 1)
592
596#define KLS_PUSH_T_NAMED(kls_temp, type, name, desc) KLS_PUSH_ARR_T_NAMED((kls_temp), type, 1, (name), (desc))
597
602#define KLS_PUSH_T_EX(kls_temp, type, name) KLS_PUSH_T_NAMED((kls_temp), type, (name), STRINGIFY(type))
603
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))
608
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))
614
615#ifdef KOLISEO_HAS_REGION
616
617KLS_Region_List kls_rl_emptyList(void);
618#define KLS_RL_GETLIST() kls_rl_emptyList()
619bool kls_rl_empty(KLS_Region_List);
620KLS_list_element kls_rl_head(KLS_Region_List);
621KLS_Region_List kls_rl_tail(KLS_Region_List);
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);
625#endif // KOLISEO_HAS_EXPER
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);
629#endif // KOLISEO_HAS_EXPER
630
631void kls_rl_freeList(KLS_Region_List);
632#define KLS_RL_FREELIST(kls_list) kls_rl_freeList(kls_list)
633void kls_rl_showList(KLS_Region_List);
634#define kls_showList(list) kls_rl_showList((list))
635void kls_rl_showList_toFile(KLS_Region_List, FILE * fp);
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)
639bool kls_rl_member(KLS_list_element, KLS_Region_List);
640int kls_rl_length(KLS_Region_List);
641KLS_Region_List kls_rl_append(Koliseo *, KLS_Region_List, KLS_Region_List);
642KLS_Region_List kls_rl_reverse(Koliseo *, 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);
645
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);
653
654#define KLS_RL_DIFF(kls,kls_list1,kls_list2) kls_rl_diff(kls,kls_list1,kls_list2)
655bool kls_rl_isLess(KLS_list_element, KLS_list_element);
656bool kls_rl_isEqual(KLS_list_element, KLS_list_element);
657double kls_usageShare(KLS_list_element, Koliseo *);
658ptrdiff_t kls_regionSize(KLS_list_element);
659ptrdiff_t kls_avg_regionSize(Koliseo *);
660void kls_usageReport_toFile(Koliseo *, FILE *);
661void kls_usageReport(Koliseo *);
662ptrdiff_t kls_type_usage(int, Koliseo *);
663
664#endif // KOLISEO_HAS_REGION
665
666#ifdef KOLISEO_HAS_GULP
668#ifndef KOLISEO_GULP_H_
669#define KOLISEO_GULP_H_
670
671#include "ctype.h" // Needed for isspace()...
672
673typedef struct Kstr {
674 const char* data;
675 size_t len;
676} Kstr;
677
678Kstr kstr_new(const char* str, size_t len);
679Kstr kstr_from_c_lit(const char* c_lit);
680bool kstr_eq(Kstr left, Kstr right);
681bool kstr_eq_ignorecase(Kstr left, Kstr right);
682Kstr kstr_cut_l(Kstr *k, size_t n);
683Kstr kstr_cut_r(Kstr *k, size_t n);
684Kstr kstr_trim_left(Kstr kstr);
685Kstr kstr_trim_right(Kstr kstr);
686Kstr kstr_trim(Kstr kstr);
687bool kstr_indexof(Kstr k, char c, int* idx);
688Kstr kstr_token(Kstr* k, char delim);
689bool kstr_try_token(Kstr* k, char delim, Kstr* part);
690Kstr kstr_token_kstr(Kstr* k, Kstr delim);
691
692#define KSTR(c_lit) kstr_new(c_lit, sizeof(c_lit) - 1)
693#define KSTR_NULL kstr_new(NULL, 0)
694
698#define Kstr_Fmt "%.*s"
702#define Kstr_Arg(kstr) (int) (kstr.len), (kstr.data)
703
711#define ONEGB_DEC_INT 1073741824
712
717#define GULP_MAX_FILE_SIZE ONEGB_DEC_INT
718
723typedef enum Gulp_Res {
724 GULP_FILE_OK=0,
725 GULP_FILE_NOT_EXIST,
726 GULP_FILE_TOO_LARGE,
727 GULP_FILE_READ_ERROR,
728 GULP_FILE_CONTAINS_NULLCHAR,
729 GULP_FILE_KLS_NULL,
730 TOT_GULP_RES
731} Gulp_Res;
732
736#define Gulp_Res_Fmt "%s"
740#define Gulp_Res_Arg(gr) (string_from_Gulp_Res((gr)))
741
746extern const char* gulp_res_names[TOT_GULP_RES+1];
747const char* string_from_Gulp_Res(Gulp_Res g);
748
749//static char * kls_read_file(Koliseo* kls, const char * f_name, Gulp_Res * err, size_t * f_size, ...);
750char * kls_gulp_file_sized(Koliseo* kls, const char * filepath, Gulp_Res * err, size_t max_size);
751char * try_kls_gulp_file(Koliseo* kls, const char * filepath, size_t max_size);
752#define KLS_GULP_FILE(kls, filepath) try_kls_gulp_file((kls),(filepath), GULP_MAX_FILE_SIZE)
753//Kstr * kls_read_file_to_kstr(Koliseo* kls, const char * f_name, Gulp_Res * err, size_t * f_size, ...);
754Kstr * kls_gulp_file_sized_to_kstr(Koliseo* kls, const char * filepath, Gulp_Res * err, size_t max_size, bool allow_nullchar);
755Kstr * try_kls_gulp_file_to_kstr(Koliseo* kls, const char * filepath, size_t max_size, bool allow_nullchar);
756#define KLS_GULP_FILE_KSTR(kls, filepath) try_kls_gulp_file_to_kstr((kls),(filepath), GULP_MAX_FILE_SIZE, false)
757
758#endif //KOLISEO_GULP_H_
759
760#endif //KOLISEO_HAS_GULP
761
762#ifdef KOLISEO_HAS_EXPER
763
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);
766
771#define KLS_POP_ARR(kls, type, count) (type*)kls_pop_AR((kls), sizeof(type), _Alignof(type), (count))
772
777#define KLS_POP_STR(kls, cstr) KLS_POP_ARR((kls), char, strlen((cstr)))
778
783#define KLS_POP(kls, type) KLS_POP_ARR((kls), type, 1)
784
785void *kls_temp_pop(Koliseo_Temp * t_kls, ptrdiff_t size, ptrdiff_t align,
786 ptrdiff_t count);
787void *kls_temp_pop_AR(Koliseo_Temp *t_kls, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count);
788
793#define KLS_POP_ARR_T(kls_temp, type, count) (type*)kls_temp_pop_AR((kls_temp), sizeof(type), _Alignof(type), (count))
794
799#define KLS_POP_STR_T(kls_temp, cstr) KLS_POP_ARR_T((kls_temp), char, strlen((cstr)))
800
805#define KLS_POP_T(kls_temp, type) KLS_POP_ARR_T((kls_temp), type, 1)
806
807char* kls_strdup(Koliseo* kls, char* source);
808char** kls_strdup_arr(Koliseo* kls, size_t count, char** source);
809
817#define __KLS_STRCPY(dest, source) do {\
818 strcpy((dest), (source));\
819} while (0)
820
821/*
822 * Macro to dupe a C string to a passed Koliseo, returns a pointer to the allocated string.
823 * Unsafe, do not use.
824 * @see kls_strdup()
825 */
826#define KLS_STRDUP(kls, source) kls_strdup((kls), (source))
827
828char* kls_t_strdup(Koliseo_Temp* t_kls, char* source);
829char** kls_t_strdup_arr(Koliseo_Temp* t_kls, size_t count, char** source);
830
831/*
832 * Macro to dupe a C string to a passed Koliseo_Temp, returns a pointer to the allocated string.
833 * Unsafe, do not use.
834 * @see kls_t_strdup()
835 */
836#define KLS_STRDUP_T(t_kls, source) kls_t_strdup((t_kls), (source))
837
838#endif // KOLISEO_HAS_EXPER
839
840#else
841#error "This code requires C11 or later.\n _Alignof() is not available"
842#endif // __STDC_VERSION__ && __STDC_VERSION__ >= 201112L //We need C11
843
844#endif //KOLISEO_H_
845
846#ifdef LIST_T //This ensures the library never causes any trouble if this macro was not defined.
847// jgabaut @ github.com/jgabaut
848// SPDX-License-Identifier: GPL-3.0-only
849/*
850 Copyright (C) 2023-2024 jgabaut
851
852 This program is free software: you can redistribute it and/or modify
853 it under the terms of the GNU General Public License as published by
854 the Free Software Foundation, version 3 of the License.
855
856 This program is distributed in the hope that it will be useful,
857 but WITHOUT ANY WARRANTY; without even the implied warranty of
858 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
859 GNU General Public License for more details.
860
861 You should have received a copy of the GNU General Public License
862 along with this program. If not, see <https://www.gnu.org/licenses/>.
863*/
864// list.h
865// This is a template for a linked list, inspired by the dynamic array example in https://www.davidpriver.com/ctemplates.html#template-headers.
866// Include this header multiple times to implement a
867// simplistic linked list. Before inclusion define at
868// least DLIST_T to the type the linked list can hold.
869// See DLIST_NAME, DLIST_PREFIX and DLIST_LINKAGE for
870// other customization points.
871//
872// If you define DLIST_DECLS_ONLY, only the declarations
873// of the type and its function will be declared.
874//
875// Functions ending with _gl use malloc() for the nodes.
876// Functions ending with _kls expect a Koliseo arg to use for allocating nodes.
877//
878
879#ifndef LIST_HEADER_H
880#define LIST_HEADER_H
881// Inline functions, #defines and includes that will be
882// needed for all instantiations can go up here.
883#include <stdbool.h> // bool
884#include <stdlib.h> // malloc, size_t
885
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
889
890#define LIST_HEADER_VERSION "0.1.0"
891
892#endif // LIST_HEADER_H
893
894// NOTE: this section is *not* guarded as it is intended
895// to be included multiple times.
896
897#ifndef LIST_T
898#error "LIST_T must be defined"
899#endif
900
901// The name of the data type to be generated.
902// If not given, will expand to something like
903// `list_int` for an `int`.
904#ifndef LIST_NAME
905#define LIST_NAME LIST_COMB1(LIST_COMB1(list,_), LIST_T)
906#endif
907
908// Prefix for generated functions.
909#ifndef LIST_PREFIX
910#define LIST_PREFIX LIST_COMB1(LIST_NAME, _)
911#endif
912
913// Customize the linkage of the function.
914#ifndef LIST_LINKAGE
915#define LIST_LINKAGE static inline
916#endif
917
918// Suffix for generated list item struct.
919#ifndef LIST_I_SUFFIX
920#define LIST_I_SUFFIX item
921#endif
922
923// The name of the item data type to be generated.
924#ifndef LIST_ITEM_NAME
925#define LIST_ITEM_NAME LIST_COMB1(LIST_COMB1(LIST_T,_), LIST_I_SUFFIX)
926#endif
927
928typedef struct LIST_ITEM_NAME LIST_ITEM_NAME;
929struct LIST_ITEM_NAME {
930 LIST_T* value;
931 struct LIST_ITEM_NAME* next;
932};
933typedef LIST_ITEM_NAME* LIST_NAME;
934
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)
956
957#ifdef LIST_DECLS_ONLY
958
959LIST_LINKAGE
960LIST_NAME
961LIST_nullList(void);
962
963LIST_LINKAGE
964bool
965LIST_isEmpty(LIST_NAME list);
966
967LIST_LINKAGE
968LIST_T*
969LIST_head(LIST_NAME list);
970
971LIST_LINKAGE
972LIST_NAME
973LIST_tail(LIST_NAME list);
974
975LIST_LINKAGE
976LIST_NAME
977LIST_cons_gl(LIST_T* element, LIST_NAME list);
978
979LIST_LINKAGE
980LIST_NAME
981LIST_cons_kls(Koliseo* kls, LIST_T* element, LIST_NAME list);
982
983LIST_LINKAGE
984void
985LIST_free_gl(LIST_NAME list);
986
987LIST_LINKAGE
988bool
989LIST_member(LIST_T* element, LIST_NAME list);
990
991LIST_LINKAGE
992int
993LIST_length(LIST_NAME list);
994
995LIST_LINKAGE
996LIST_NAME
997LIST_append_gl(LIST_NAME l1, LIST_NAME l2);
998
999LIST_LINKAGE
1000LIST_NAME
1001LIST_append_kls(Koliseo* kls, LIST_NAME l1, LIST_NAME l2);
1002
1003LIST_LINKAGE
1004LIST_NAME
1005LIST_reverse_gl(LIST_NAME list);
1006
1007LIST_LINKAGE
1008LIST_NAME
1009LIST_reverse_kls(Koliseo* kls, LIST_NAME list);
1010
1011LIST_LINKAGE
1012LIST_NAME
1013LIST_copy_gl(LIST_NAME list);
1014
1015LIST_LINKAGE
1016LIST_NAME
1017LIST_copy_kls(Koliseo* kls, LIST_NAME list);
1018
1019LIST_LINKAGE
1020LIST_NAME
1021LIST_remove_gl(LIST_T* element, LIST_NAME list);
1022
1023LIST_LINKAGE
1024LIST_NAME
1025LIST_remove_kls(Koliseo* kls, LIST_T* element, LIST_NAME list);
1026
1027LIST_LINKAGE
1028LIST_NAME
1029LIST_intersect_gl(LIST_NAME l1, LIST_NAME l2);
1030
1031LIST_LINKAGE
1032LIST_NAME
1033LIST_intersect_kls(Koliseo* kls, LIST_NAME l1, LIST_NAME l2);
1034
1035LIST_LINKAGE
1036LIST_NAME
1037LIST_diff_gl(LIST_NAME l1, LIST_NAME l2);
1038
1039LIST_LINKAGE
1040LIST_NAME
1041LIST_diff_kls(Koliseo* kls, LIST_NAME l1, LIST_NAME l2);
1042#else
1043
1044LIST_LINKAGE
1045LIST_NAME
1046LIST_nullList(void)
1047{
1048 return NULL;
1049}
1050
1051LIST_LINKAGE
1052bool
1053LIST_isEmpty(LIST_NAME list)
1054{
1055 if (list == NULL) {
1056 return true;
1057 };
1058 return false;
1059}
1060
1061LIST_LINKAGE
1062LIST_T*
1063LIST_head(LIST_NAME list)
1064{
1065 if (LIST_isEmpty(list)) {
1066 fprintf(stderr, "%s at %i: %s(): List is empty.\n", __FILE__, __LINE__, __func__);
1067 return NULL;
1068 }
1069 return list->value;
1070}
1071
1072LIST_LINKAGE
1073LIST_NAME
1074LIST_tail(LIST_NAME list)
1075{
1076 if (LIST_isEmpty(list)) {
1077 fprintf(stderr, "%s at %i: %s(): List is empty.\n", __FILE__, __LINE__, __func__);
1078 return NULL;
1079 }
1080 return list->next;
1081}
1082
1083LIST_LINKAGE
1084LIST_NAME
1085LIST_cons_gl(LIST_T* element, LIST_NAME list)
1086{
1087 LIST_NAME t;
1088 t = (LIST_NAME) malloc(sizeof(LIST_ITEM_NAME));
1089 t->value = element;
1090 t->next = list;
1091 return t;
1092}
1093
1094LIST_LINKAGE
1095LIST_NAME
1096LIST_cons_kls(Koliseo* kls, LIST_T* element, LIST_NAME list)
1097{
1098 if (kls == NULL) {
1099 fprintf(stderr, "%s at %i: %s(): Koliseo is NULL.\n", __FILE__, __LINE__, __func__);
1100 return NULL;
1101 }
1102 LIST_NAME t;
1103 t = (LIST_NAME) KLS_PUSH_EX(kls, LIST_ITEM_NAME, "List node");
1104 if (t == NULL ) {
1105 fprintf(stderr, "%s at %i: %s(): Failed KLS_PUSH_EX() call.\n", __FILE__, __LINE__, __func__);
1106 return NULL;
1107 }
1108 t->value = element;
1109 t->next = list;
1110 return t;
1111}
1112
1113LIST_LINKAGE
1114void
1115LIST_free_gl(LIST_NAME list)
1116{
1117 if (LIST_isEmpty(list)) {
1118 return;
1119 } else {
1120 LIST_free_gl(LIST_tail(list));
1121 free(list);
1122 }
1123 return;
1124}
1125
1126LIST_LINKAGE
1127bool
1128LIST_member(LIST_T* element, LIST_NAME list)
1129{
1130 if (LIST_isEmpty(list)) {
1131 return false;
1132 } else {
1133 if (element == LIST_head(list)) {
1134 return true;
1135 } else {
1136 return LIST_member(element, LIST_tail(list));
1137 }
1138 }
1139}
1140
1141LIST_LINKAGE
1142int
1143LIST_length(LIST_NAME list)
1144{
1145 if (LIST_isEmpty(list)) {
1146 return 0;
1147 } else {
1148 return 1 + LIST_length(LIST_tail(list));
1149 }
1150}
1151
1152LIST_LINKAGE
1153LIST_NAME
1154LIST_append_gl(LIST_NAME l1, LIST_NAME l2)
1155{
1156 if (LIST_isEmpty(l1)) {
1157 return l2;
1158 } else {
1159 return LIST_cons_gl(LIST_head(l1), LIST_append_gl(LIST_tail(l1), l2));
1160 }
1161}
1162
1163LIST_LINKAGE
1164LIST_NAME
1165LIST_append_kls(Koliseo* kls, LIST_NAME l1, LIST_NAME l2)
1166{
1167 if (kls == NULL) {
1168 fprintf(stderr, "%s at %i: %s(): Koliseo is NULL.\n", __FILE__, __LINE__, __func__);
1169 return NULL;
1170 }
1171 if (LIST_isEmpty(l1)) {
1172 return l2;
1173 } else {
1174 return LIST_cons_kls(kls, LIST_head(l1), LIST_append_kls(kls, LIST_tail(l1), l2));
1175 }
1176}
1177
1178LIST_LINKAGE
1179LIST_NAME
1180LIST_reverse_gl(LIST_NAME list)
1181{
1182 if (LIST_isEmpty(list)) {
1183 return LIST_nullList();
1184 } else {
1185 return LIST_append_gl(LIST_reverse_gl(LIST_tail(list)), LIST_cons_gl(LIST_head(list), LIST_nullList()));
1186 }
1187}
1188
1189LIST_LINKAGE
1190LIST_NAME
1191LIST_reverse_kls(Koliseo* kls, LIST_NAME list)
1192{
1193 if (kls == NULL) {
1194 fprintf(stderr, "%s at %i: %s(): Koliseo is NULL.\n", __FILE__, __LINE__, __func__);
1195 return NULL;
1196 }
1197 if (LIST_isEmpty(list)) {
1198 return LIST_nullList();
1199 } else {
1200 return LIST_append_kls(kls, LIST_reverse_kls(kls, LIST_tail(list)), LIST_cons_kls(kls, LIST_head(list), LIST_nullList()));
1201 }
1202}
1203
1204LIST_LINKAGE
1205LIST_NAME
1206LIST_copy_gl(LIST_NAME list)
1207{
1208 if (LIST_isEmpty(list)) {
1209 return list;
1210 } else {
1211 return LIST_cons_gl(LIST_head(list), LIST_copy_gl(LIST_tail(list)));
1212 }
1213}
1214
1215LIST_LINKAGE
1216LIST_NAME
1217LIST_copy_kls(Koliseo* kls, LIST_NAME list)
1218{
1219 if (kls == NULL) {
1220 fprintf(stderr, "%s at %i: %s(): Koliseo is NULL.\n", __FILE__, __LINE__, __func__);
1221 return NULL;
1222 }
1223 if (LIST_isEmpty(list)) {
1224 return list;
1225 } else {
1226 return LIST_cons_kls(kls, LIST_head(list), LIST_copy_kls(kls, LIST_tail(list)));
1227 }
1228
1229}
1230
1231LIST_LINKAGE
1232LIST_NAME
1233LIST_remove_gl(LIST_T* element, LIST_NAME list)
1234{
1235 if (LIST_isEmpty(list)) {
1236 return LIST_nullList();
1237 } else {
1238 if (element == LIST_head(list)) {
1239 return LIST_tail(list);
1240 } else {
1241 return LIST_cons_gl(LIST_head(list), LIST_remove_gl(element, LIST_tail(list)));
1242 }
1243 }
1244}
1245
1246LIST_LINKAGE
1247LIST_NAME
1248LIST_remove_kls(Koliseo* kls, LIST_T* element, LIST_NAME list)
1249{
1250 if (kls == NULL) {
1251 fprintf(stderr, "%s at %i: %s(): Koliseo is NULL.\n", __FILE__, __LINE__, __func__);
1252 return NULL;
1253 }
1254 if (LIST_isEmpty(list)) {
1255 return LIST_nullList();
1256 } else {
1257 if (element == LIST_head(list)) {
1258 return LIST_tail(list);
1259 } else {
1260 return LIST_cons_kls(kls, LIST_head(list), LIST_remove_kls(kls, element, LIST_tail(list)));
1261 }
1262 }
1263}
1264
1265LIST_LINKAGE
1266LIST_NAME
1267LIST_intersect_gl(LIST_NAME l1, LIST_NAME l2)
1268{
1269 if (LIST_isEmpty(l1) || LIST_isEmpty(l2)) {
1270 return LIST_nullList();
1271 }
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));
1274 } else {
1275 return LIST_intersect_gl(LIST_tail(l1), l2);
1276 }
1277}
1278
1279LIST_LINKAGE
1280LIST_NAME
1281LIST_intersect_kls(Koliseo* kls, LIST_NAME l1, LIST_NAME l2)
1282{
1283 if (kls == NULL) {
1284 fprintf(stderr, "%s at %i: %s(): Koliseo is NULL.\n", __FILE__, __LINE__, __func__);
1285 return NULL;
1286 }
1287 if (LIST_isEmpty(l1) || LIST_isEmpty(l2)) {
1288 return LIST_nullList();
1289 }
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));
1292 } else {
1293 return LIST_intersect_kls(kls, LIST_tail(l1), l2);
1294 }
1295}
1296
1297LIST_LINKAGE
1298LIST_NAME
1299LIST_diff_gl(LIST_NAME l1, LIST_NAME l2)
1300{
1301 if (LIST_isEmpty(l1) || LIST_isEmpty(l2)) {
1302 return l1;
1303 } else {
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));
1306 } else {
1307 return LIST_diff_gl(LIST_tail(l1), l2);
1308 }
1309 }
1310}
1311
1312LIST_LINKAGE
1313LIST_NAME
1314LIST_diff_kls(Koliseo* kls, LIST_NAME l1, LIST_NAME l2)
1315{
1316 if (kls == NULL) {
1317 fprintf(stderr, "%s at %i: %s(): Koliseo is NULL.\n", __FILE__, __LINE__, __func__);
1318 return NULL;
1319 }
1320 if (LIST_isEmpty(l1) || LIST_isEmpty(l2)) {
1321 return l1;
1322 } else {
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));
1325 } else {
1326 return LIST_diff_kls(kls, LIST_tail(l1), l2);
1327 }
1328 }
1329}
1330#endif
1331
1332// Cleanup
1333// These need to be undef'ed so they can be redefined the
1334// next time you need to instantiate this template.
1335#undef LIST_T
1336#undef LIST_PREFIX
1337#undef LIST_NAME
1338#undef LIST_LINKAGE
1339#undef LIST_I_SUFFIX
1340#undef LIST_ITEM_NAME
1341#undef LIST_nullList
1342#undef LIST_isEmpty
1343#undef LIST_head
1344#undef LIST_tail
1345#undef LIST_cons_gl
1346#undef LIST_cons_kls
1347#undef LIST_free_gl
1348#undef LIST_member
1349#undef LIST_length
1350#undef LIST_append_gl
1351#undef LIST_append_kls
1352#undef LIST_reverse_gl
1353#undef LIST_reverse_kls
1354#undef LIST_copy_gl
1355#undef LIST_copy_kls
1356#undef LIST_remove_gl
1357#undef LIST_remove_kls
1358#undef LIST_intersect_gl
1359#undef LIST_intersect_kls
1360#undef LIST_diff_gl
1361#undef LIST_diff_kls
1362#ifdef LIST_DECLS_ONLY
1363#undef LIST_DECLS_ONLY
1364#endif // LIST_DECLS_ONLY
1365#endif // LIST_T
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