21 .kls_collect_stats = 0,
23 .kls_block_while_has_temp = 1,
24 .kls_allow_zerocount_push = 0,
27 .kls_log_filepath =
"",
29#ifndef KOLISEO_HAS_LOCATE
34 .OOM_handler = &KLS_OOM_default_handler_dbg__,
35 .PTRDIFF_MAX_handler = &KLS_PTRDIFF_MAX_default_handler_dbg__,
36 .ZEROCOUNT_handler = &KLS_ZEROCOUNT_default_handler_dbg__,
49 .worst_pushcall_time = -1,
61 return KOLISEO_API_VERSION_STRING;
70 return KOLISEO_API_VERSION_INT;
73#if defined(__SANITIZE_ADDRESS__)
74#include <sanitizer/asan_interface.h>
75#define KLS_ASAN_POISON(addr, size) __asan_poison_memory_region((addr), (size))
76#define KLS_ASAN_UNPOISON(addr, size) __asan_unpoison_memory_region((addr), (size))
78#define KLS_ASAN_POISON(addr, size) ((void)0)
79#define KLS_ASAN_UNPOISON(addr, size) ((void)0)
91#ifndef KOLISEO_HAS_LOCATE
94void KLS_OOM_default_handler_dbg__(
Koliseo* kls, ptrdiff_t available, ptrdiff_t padding, ptrdiff_t size, ptrdiff_t count, Koliseo_Loc loc)
97#ifndef KOLISEO_HAS_LOCATE
99 "[KLS] Out of memory. size*count [%td] was bigger than available-padding [%td].\n",
100 size * count, available - padding);
103 "[KLS] " KLS_Loc_Fmt
"Out of memory. size*count [%td] was bigger than available-padding [%td].\n",
105 size * count, available - padding);
111#ifndef KOLISEO_HAS_LOCATE
114void KLS_PTRDIFF_MAX_default_handler_dbg__(
struct Koliseo* kls, ptrdiff_t size, ptrdiff_t count, Koliseo_Loc loc)
118#ifndef KOLISEO_HAS_LOCATE
120 "[KLS] count [%td] was bigger than PTRDIFF_MAX/size [%li].\n",
121 count, PTRDIFF_MAX / size);
124 "[KLS] " KLS_Loc_Fmt
"count [%td] was bigger than PTRDIFF_MAX/size [%li].\n",
126 count, PTRDIFF_MAX / size);
129#ifndef KOLISEO_HAS_LOCATE
131 "[KLS] count [%td] was bigger than PTRDIFF_MAX/size [%lli].\n",
132 count, PTRDIFF_MAX / size);
135 "[KLS] " KLS_Loc_Fmt
"count [%td] was bigger than PTRDIFF_MAX/size [%lli].\n",
137 count, PTRDIFF_MAX / size);
153#ifndef KOLISEO_HAS_LOCATE
156void KLS_ZEROCOUNT_default_handler_dbg__(
Koliseo* kls, ptrdiff_t available, ptrdiff_t padding, ptrdiff_t size, Koliseo_Loc loc)
159#ifndef KOLISEO_HAS_LOCATE
161 "[KLS] Doing a zero-count push. size [%td] padding [%td] available [%td].\n",
162 size, padding, available);
165 "[KLS] " KLS_Loc_Fmt
"Doing a zero-count push. size [%td] padding [%td] available [%td].\n",
167 size, padding, available);
192#ifndef KOLISEO_HAS_LOCATE
202#ifndef KOLISEO_HAS_LOCATE
212#ifndef KOLISEO_HAS_LOCATE
226KLS_Conf kls_conf_init(
int collect_stats,
int verbose_lvl,
int block_while_has_temp,
int allow_zerocount_push,
int growable, FILE* log_fp,
const char* log_filepath)
229 return kls_conf_init_handled(collect_stats, verbose_lvl, block_while_has_temp, allow_zerocount_push, growable, log_fp, log_filepath, err_handlers);
237#ifdef KOLISEO_HAS_LOCATE
238 bool kls_locate =
true;
240 bool kls_locate =
false;
243 bool kls_debug =
true;
245 bool kls_debug =
false;
247#ifdef KOLISEO_HAS_EXPER
248 bool kls_exper =
true;
250 bool kls_exper =
false;
257 int total_enabled = 0;
258 for (
int i=0; i<3; i++) {
263 fprintf(stderr,
"[KLS] Enabled features: {");
264 if (total_enabled == 0) {
265 fprintf(stderr,
"none}\n");
269 fprintf(stderr,
"debug%s", (total_enabled > 1 ?
", " :
""));
273 fprintf(stderr,
"locate%s", (total_enabled > 1 ?
", " :
""));
277 fprintf(stderr,
"exper");
279 fprintf(stderr,
"}\n");
293#ifndef KOLISEO_HAS_LOCATE
296void* kls__handle_push_result_dbg(
Koliseo* kls,
KLS_Push_Result r, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count, ptrdiff_t padding,
const char* caller_name, Koliseo_Loc loc)
299 if (!kls)
return NULL;
301 while (current->
next != NULL) {
302 current = current->
next;
305 const ptrdiff_t available = current->
size - current->
offset;
312#ifndef KOLISEO_HAS_LOCATE
314 "[KLS] %s(): size [%td] was < 1.\n",
319 "[KLS] " KLS_Loc_Fmt
"%s(): size [%td] was < 1.\n",
327#ifndef KOLISEO_HAS_LOCATE
329 "[KLS] %s(): align [%td] was < 1.\n",
334 "[KLS] " KLS_Loc_Fmt
"%s(): align [%td] was < 1.\n",
342#ifndef KOLISEO_HAS_LOCATE
344 "[KLS] %s(): align [%td] was not a power of 2.\n",
349 "[KLS] " KLS_Loc_Fmt
"%s(): align [%td] was not a power of 2.\n",
357#ifndef KOLISEO_HAS_LOCATE
359 "[KLS] %s(): count [%td] was < 0.\n",
364 "[KLS] " KLS_Loc_Fmt
"%s(): count [%td] was < 0.\n",
373#ifndef KOLISEO_HAS_LOCATE
379#ifndef KOLISEO_HAS_LOCATE
381 "[KLS] %s(): Doing a zero-count push. size [%td] padding [%td] available [%td].\n",
383 size, padding, available);
386 "[KLS] " KLS_Loc_Fmt
"%s(): Doing a zero-count push. size [%td] padding [%td] available [%td].\n",
389 size, padding, available);
397#ifndef KOLISEO_HAS_LOCATE
398 fprintf(stderr,
"[ERROR] [%s()]: Passed Koliseo has an open Koliseo_Temp session.\n", caller_name);
400 fprintf(stderr,
"[ERROR] " KLS_Loc_Fmt
"[%s()]: Passed Koliseo has an open Koliseo_Temp session.\n", KLS_Loc_Arg(loc), caller_name);
401 kls_log(kls,
"ERROR", KLS_Loc_Fmt
"[%s()]: Passed Koliseo has an open Koliseo_Temp session.", KLS_Loc_Arg(loc), caller_name);
408#ifndef KOLISEO_HAS_LOCATE
415#ifndef KOLISEO_HAS_LOCATE
417 "[KLS] %s(): count [%td] was bigger than PTRDIFF_MAX/size [%li].\n",
419 count, PTRDIFF_MAX / size);
422 "[KLS] " KLS_Loc_Fmt
"%s(): count [%td] was bigger than PTRDIFF_MAX/size [%li].\n",
425 count, PTRDIFF_MAX / size);
428#ifndef KOLISEO_HAS_LOCATE
430 "[KLS] %s(): count [%td] was bigger than PTRDIFF_MAX/size [%lli].\n",
432 count, PTRDIFF_MAX / size);
435 "[KLS] " KLS_Loc_Fmt
"%s(): count [%td] was bigger than PTRDIFF_MAX/size [%lli].\n",
438 count, PTRDIFF_MAX / size);
446#ifndef KOLISEO_HAS_LOCATE
452#ifndef KOLISEO_HAS_LOCATE
454 "[KLS] %s(): Out of memory. size*count [%td] was bigger than available-padding [%td].\n",
456 size * count, available - padding);
459 "[KLS] " KLS_Loc_Fmt
"%s(): Out of memory. size*count [%td] was bigger than available-padding [%td].\n",
462 size * count, available - padding);
468 fprintf(stderr,
"[KLS] %s(): unexpected error code [%i]\n", __func__, r.
error);
486 fprintf(stderr,
"[KLS] %s(): Passed kls was NULL.\n", __func__);
492 va_start(args, format);
495 "[KLS] %s(): Failed opening file to print logs.\n",
498 time_t now = time(0);
499 const struct tm *mytime = localtime(&now);
500 char timeheader[500];
501 if (strftime(timeheader,
sizeof timeheader,
"%X", mytime)) {
502 fprintf(fp,
"[%-10.10s] [%s] [", tag, timeheader);
503 vfprintf(fp, format, args);
528#ifndef KOLISEO_HAS_LOCATE
534 if (size < (ptrdiff_t)
sizeof(
Koliseo)) {
535#ifndef KOLISEO_HAS_LOCATE
537 "[ERROR] at %s(): invalid requested kls size (%td). Min accepted is: (%td).\n",
538 __func__, size, (ptrdiff_t)
sizeof(
Koliseo));
541 "[ERROR] " KLS_Loc_Fmt
"%s(): invalid requested kls size (%td). Min accepted is: (%td).\n",
542 KLS_Loc_Arg(loc), __func__, size, (ptrdiff_t)
sizeof(
Koliseo));
547 void *p = alloc_func(size);
556 kls->
offset =
sizeof(*kls);
567 for (
size_t i=0; i < kls->
hooks_len; i++) {
568 kls->
hooks[i] = ext_handlers[i];
570 for (
size_t i=0; i < kls->
hooks_len; i++) {
580 kls_log(kls,
"KLS",
"API Level { %i } -> Allocated (%s) for new KLS.",
582 kls_log(kls,
"KLS",
"KLS offset: { %p }.", kls);
583 kls_log(kls,
"KLS",
"Allocation begin offset: { %p }.",
587 for (
size_t i=0; i < kls->
hooks_len; i++) {
594#ifndef KOLISEO_HAS_LOCATE
595 fprintf(stderr,
"[KLS] Failed %s() call.\n", __func__);
597 fprintf(stderr,
"[KLS] " KLS_Loc_Fmt
"Failed %s() call.\n", KLS_Loc_Arg(loc), __func__);
625#ifndef KOLISEO_HAS_LOCATE
631#ifndef KOLISEO_HAS_LOCATE
674 bool conf_res = kls_set_conf(k, conf);
677 "[ERROR] [%s()]: Failed to set config for new Koliseo.\n",
756#ifndef KLS_DEBUG_CORE
758 "[WARN] %s(): KLS_DEBUG_CORE is not defined. No tracing allowed.\n",
762 .kls_collect_stats = 1,.kls_verbose_lvl =
763 1,.kls_log_filepath = output_path,
764#ifndef KOLISEO_HAS_LOCATE
768 .err_handlers.OOM_handler = (err_handlers.
OOM_handler != NULL ? err_handlers.
OOM_handler : &KLS_OOM_default_handler_dbg__),
879#ifndef KLS_DEBUG_CORE
881 "[WARN] %s(): KLS_DEBUG_CORE is not defined. No debugging support.\n",
885 .kls_collect_stats = 1,.kls_verbose_lvl = 0,
886#ifndef KOLISEO_HAS_LOCATE
890 .err_handlers.OOM_handler = ( err_handlers.
OOM_handler != NULL ? err_handlers.
OOM_handler : &KLS_OOM_default_handler_dbg__),
987 fprintf(stderr,
"[ERROR] [%s()]: Passed Koliseo was NULL.\n", __func__);
996#ifdef KLS_SETCONF_DEBUG
998 "[%s()]: Preliminary set of conf.kls_log_fp to stderr.",
1006 "[ERROR] at %s(): passed OOM_handler is NULL. Using default.\n",
1008#ifdef KLS_DEBUG_CORE
1009#ifdef KLS_SETCONF_DEBUG
1011 "[%s()]: Passed OOM_handler was NULL, using default.",
1015#ifndef KOLISEO_HAS_LOCATE
1024 "[ERROR] at %s(): passed PTRDIFF_MAX_handler is NULL. Using default.\n",
1026#ifdef KLS_DEBUG_CORE
1027#ifdef KLS_SETCONF_DEBUG
1029 "[%s()]: Passed PTRDIFF_MAX_handler was NULL, using default.",
1033#ifndef KOLISEO_HAS_LOCATE
1040#ifndef KLS_DEBUG_CORE
1043 "[WARN] [%s()]: KLS_DEBUG_CORE is not defined. Stats may not be collected in full.\n",
1050#ifdef KLS_DEBUG_CORE
1051#ifdef KLS_SETCONF_DEBUG
1053 "[%s()]: kls->conf.kls_log_fp was not NULL. Overriding it.",
1062 FILE *log_fp = NULL;
1066 "[ERROR] [%s()]: Failed opening logfile at {\"%s\"} [write].\n",
1070 fprintf(log_fp,
"%s",
"");
1076 "[ERROR] [%s()]: Failed opening logfile at {\"%s\"} [append].\n",
1086static bool kls__try_grow(
Koliseo* kls, ptrdiff_t needed);
1099#ifndef KOLISEO_HAS_LOCATE
1102KLS_Push_Result kls__advance_dbg(
Koliseo* kls, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count, ptrdiff_t* padding,
const char* caller_name, Koliseo_Loc loc)
1105#ifdef KLS_DEBUG_CORE
1107 struct timespec start_time, end_time;
1108 clock_gettime(CLOCK_MONOTONIC, &start_time);
1110 LARGE_INTEGER start_time, end_time, frequency;
1111 QueryPerformanceFrequency(&frequency);
1112 QueryPerformanceCounter(&start_time);
1117 fprintf(stderr,
"[ERROR] [%s()]: Passed Koliseo was NULL.\n", caller_name);
1127#ifndef KOLISEO_HAS_LOCATE
1130 KLS_Push_Error res = kls__check_available_failable_dbg(kls, size, align, count, __func__, loc);
1139 while (current->
next != NULL) {
1140 current = current->
next;
1142 const ptrdiff_t pad = -current->
offset & (align - 1);
1144 char *p = current->
data + current->
offset + pad;
1146 current->
offset += pad + size * count;
1154#ifdef KLS_DEBUG_CORE
1155 kls_log(current,
"KLS",
"Curr offset: { %p }.", current + current->
offset);
1156 kls_log(current,
"KLS",
"API Level { %i } -> Pushed zeroes, size (%s) for KLS.",
1163 clock_gettime(CLOCK_MONOTONIC, &end_time);
1164 double elapsed_time =
1165 (end_time.tv_sec - start_time.tv_sec) + (end_time.tv_nsec -
1166 start_time.tv_nsec) / 1e9;
1168 QueryPerformanceCounter(&end_time);
1169 double elapsed_time =
1170 (double)(end_time.QuadPart -
1171 start_time.QuadPart) / frequency.QuadPart;
1199#ifndef KOLISEO_HAS_LOCATE
1202KLS_Push_Error kls__check_available_failable_dbg(
Koliseo* kls, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count,
const char* caller_name, Koliseo_Loc loc)
1205 assert(kls != NULL);
1206 assert(caller_name != NULL);
1216 if (! ((align & (align - 1)) == 0)) {
1220 while (current->
next != NULL) {
1221 current = current->
next;
1223 const ptrdiff_t available = current->
size - current->
offset;
1224 const ptrdiff_t padding = -current->
offset & (align - 1);
1229#ifdef KLS_DEBUG_CORE
1230 kls_log(current,
"DEBUG",
"Accepting zero-count push: conf.kls_allow_zerocount_push was 1");
1235 if (count > PTRDIFF_MAX / size || available - padding < size * count) {
1236 if (count > PTRDIFF_MAX / size) {
1239 if (current->
conf.
kls_growable == 1 && kls__try_grow(current, size + count + padding)) {
1259#ifndef KOLISEO_HAS_LOCATE
1262KLS_Push_Result kls__temp_advance_dbg(
Koliseo_Temp* kls_t, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count, ptrdiff_t* padding,
const char* caller_name, Koliseo_Loc loc)
1265#ifdef KLS_DEBUG_CORE
1267 struct timespec start_time, end_time;
1268 clock_gettime(CLOCK_MONOTONIC, &start_time);
1270 LARGE_INTEGER start_time, end_time, frequency;
1271 QueryPerformanceFrequency(&frequency);
1272 QueryPerformanceCounter(&start_time);
1276 if (kls_t == NULL) {
1277 fprintf(stderr,
"[ERROR] [%s()]: Passed Koliseo_Temp was NULL.\n",
1283 fprintf(stderr,
"[ERROR] [%s()]: Referred Koliseo was NULL.\n",
1287#ifndef KOLISEO_HAS_LOCATE
1290 KLS_Push_Error res = kls__check_available_failable_dbg(kls, size, align, count, __func__, loc);
1299 while (current->
next != NULL) {
1300 current = current->
next;
1302 ptrdiff_t pad = -current->
offset & (align - 1);
1303 char *p = current->
data + current->
offset + pad;
1306 current->
offset += pad + size * count;
1314#ifdef KLS_DEBUG_CORE
1317 clock_gettime(CLOCK_MONOTONIC, &end_time);
1318 double elapsed_time =
1319 (end_time.tv_sec - start_time.tv_sec) + (end_time.tv_nsec -
1320 start_time.tv_nsec) / 1e9;
1322 QueryPerformanceCounter(&end_time);
1323 double elapsed_time =
1324 (double)(end_time.QuadPart -
1325 start_time.QuadPart) / frequency.QuadPart;
1331 kls_log(current,
"KLS",
"Curr offset: { %p }.", current + current->
offset);
1333 "API Level { %i } -> Pushed zeroes, size (%s) for Temp_KLS.",
1348bool kls__try_grow(
Koliseo* kls, ptrdiff_t needed)
1350 ptrdiff_t new_size =
KLS_MAX(kls->
size * 2, needed);
1352 kls_log(kls,
"DEBUG",
"%s(): growing Koliseo, new size: {%td}", __func__, new_size);
1353 if (!new_kls)
return false;
1354 kls->
next = new_kls;
1370 ptrdiff_t padding = 0;
1371#ifndef KOLISEO_HAS_LOCATE
1375 KLS_Push_Result res = kls__advance_dbg(kls, size, align, count, &padding, __func__, KLS_HERE);
1376 return kls__handle_push_result_dbg(kls, res, size, align, count, padding, __func__, KLS_HERE);
1390#ifndef KOLISEO_HAS_LOCATE
1394void *kls_push_zero_dbg(
Koliseo *kls, ptrdiff_t size, ptrdiff_t align,
1395 ptrdiff_t count, Koliseo_Loc loc)
1398 ptrdiff_t padding = 0;
1399#ifndef KOLISEO_HAS_LOCATE
1403 KLS_Push_Result res = kls__advance_dbg(kls, size, align, count, &padding, __func__, loc);
1404 void* p = kls__handle_push_result_dbg(kls, res, size, align, count, padding, __func__, loc);
1406 if (!p)
return NULL;
1408 memset(p, 0, size * count);
1423#ifndef KOLISEO_HAS_LOCATE
1427void *kls_push_zero_ext_dbg(
Koliseo *kls, ptrdiff_t size, ptrdiff_t align,
1428 ptrdiff_t count, Koliseo_Loc loc)
1432 ptrdiff_t padding = 0;
1433#ifndef KOLISEO_HAS_LOCATE
1437 KLS_Push_Result res = kls__advance_dbg(kls, size, align, count, &padding, __func__, loc);
1438 void* p = kls__handle_push_result_dbg(kls, res, size, align, count, padding, __func__, loc);
1440 if (!p)
return NULL;
1442 memset(p, 0, size * count);
1445 while (current->
next != NULL) {
1446 current = current->
next;
1449 for (
size_t i=0; i < current->
hooks_len; i++) {
1474#ifndef KOLISEO_HAS_LOCATE
1477char* kls_vsprintf_dbg(
Koliseo* kls, Koliseo_Loc loc,
const char* fmt, va_list args)
1481 va_copy(args_copy, args);
1482 int len = vsnprintf(NULL, 0, fmt, args);
1483#ifndef KOLISEO_HAS_LOCATE
1486 char* str = kls_push_zero_ext_dbg(kls,
sizeof(
char),
KLS_ALIGNOF(
char), len+1, loc);
1488 vsnprintf(str, len+1, fmt, args_copy);
1499#ifndef KOLISEO_HAS_LOCATE
1502char* kls_sprintf_dbg(
Koliseo* kls, Koliseo_Loc loc,
const char* fmt, ...)
1506 va_start(args, fmt);
1507#ifndef KOLISEO_HAS_LOCATE
1510 char* str = kls_vsprintf_dbg(kls, loc, fmt, args);
1527#ifndef KOLISEO_HAS_LOCATE
1529 ptrdiff_t align, ptrdiff_t count)
1531void *kls_temp_push_zero_ext_dbg(
Koliseo_Temp *t_kls, ptrdiff_t size,
1532 ptrdiff_t align, ptrdiff_t count, Koliseo_Loc loc)
1536 ptrdiff_t padding = 0;
1538#ifndef KOLISEO_HAS_LOCATE
1541 KLS_Push_Result res = kls__temp_advance_dbg(t_kls, size, align, count, &padding, __func__, loc);
1543 if (res.
error)
return NULL;
1545 memset(res.
p, 0, size * count);
1549 while (current->
next != NULL) {
1550 current = current->
next;
1553 for (
size_t i=0; i < current->
hooks_len; i++) {
1562#ifndef KOLISEO_HAS_LOCATE
1565char* kls_temp_vsprintf_dbg(
Koliseo_Temp* kls_t, Koliseo_Loc loc,
const char* fmt, va_list args)
1569 va_copy(args_copy, args);
1570 int len = vsnprintf(NULL, 0, fmt, args);
1571#ifndef KOLISEO_HAS_LOCATE
1574 char* str = kls_temp_push_zero_ext_dbg(kls_t,
sizeof(
char),
KLS_ALIGNOF(
char), len+1, loc);
1576 vsnprintf(str, len+1, fmt, args_copy);
1588#ifndef KOLISEO_HAS_LOCATE
1591char* kls_temp_sprintf_dbg(
Koliseo_Temp* kls_t, Koliseo_Loc loc,
const char* fmt, ...)
1595 va_start(args, fmt);
1596#ifndef KOLISEO_HAS_LOCATE
1599 char* str = kls_temp_vsprintf_dbg(kls_t, loc, fmt, args);
1616#ifndef KOLISEO_HAS_LOCATE
1618 ptrdiff_t old_count, ptrdiff_t new_count)
1620void *kls_repush_dbg(
Koliseo *kls,
void* old, ptrdiff_t size, ptrdiff_t align,
1621 ptrdiff_t old_count, ptrdiff_t new_count, Koliseo_Loc loc)
1625#ifndef KOLISEO_HAS_LOCATE
1627 "[KLS] %s(): old was NULL.\n",
1631 "[KLS] " KLS_Loc_Fmt
"%s(): old was NULL.\n",
1637 if (old_count < 0) {
1638#ifndef KOLISEO_HAS_LOCATE
1640 "[KLS] %s(): old_count [%td] was < 0.\n",
1645 "[KLS] " KLS_Loc_Fmt
"%s(): old_count [%td] was < 0.\n",
1652 if (new_count < 0) {
1653#ifndef KOLISEO_HAS_LOCATE
1655 "[KLS] %s(): new_count [%td] was < 0.\n",
1660 "[KLS] " KLS_Loc_Fmt
"%s(): new_count [%td] was < 0.\n",
1668#ifndef KOLISEO_HAS_LOCATE
1670 "[KLS] %s(): size [%td] was < 1.\n",
1675 "[KLS] " KLS_Loc_Fmt
"%s(): size [%td] was < 1.\n",
1683#ifndef KOLISEO_HAS_LOCATE
1685 "[KLS] %s(): align [%td] was < 1.\n",
1690 "[KLS] " KLS_Loc_Fmt
"%s(): align [%td] was < 1.\n",
1697 if (! ((align & (align - 1)) == 0)) {
1698#ifndef KOLISEO_HAS_LOCATE
1700 "[KLS] %s(): align [%td] was not a power of 2.\n",
1705 "[KLS] " KLS_Loc_Fmt
"%s(): align [%td] was not a power of 2.\n",
1713 fprintf(stderr,
"%s(): kls has an active temp\n", __func__);
1716 size_t old_size = old_count * size;
1717 size_t new_size = new_count * size;
1719 if (new_ptr && old_size > 0) {
1720 memcpy(new_ptr, old, old_size < new_size ? old_size : new_size);
1736#ifndef KOLISEO_HAS_LOCATE
1738 ptrdiff_t old_count, ptrdiff_t new_count)
1740void *kls_temp_repush_dbg(
Koliseo_Temp *t_kls,
void* old, ptrdiff_t size, ptrdiff_t align,
1741 ptrdiff_t old_count, ptrdiff_t new_count, Koliseo_Loc loc)
1745#ifndef KOLISEO_HAS_LOCATE
1747 "[KLS] %s(): old was NULL.\n",
1751 "[KLS] " KLS_Loc_Fmt
"%s(): old was NULL.\n",
1757 if (old_count < 0) {
1758#ifndef KOLISEO_HAS_LOCATE
1760 "[KLS] %s(): old_count [%td] was < 0.\n",
1765 "[KLS] " KLS_Loc_Fmt
"%s(): old_count [%td] was < 0.\n",
1772 if (new_count < 0) {
1773#ifndef KOLISEO_HAS_LOCATE
1775 "[KLS] %s(): new_count [%td] was < 0.\n",
1780 "[KLS] " KLS_Loc_Fmt
"%s(): new_count [%td] was < 0.\n",
1788#ifndef KOLISEO_HAS_LOCATE
1790 "[KLS] %s(): size [%td] was < 1.\n",
1795 "[KLS] " KLS_Loc_Fmt
"%s(): size [%td] was < 1.\n",
1803#ifndef KOLISEO_HAS_LOCATE
1805 "[KLS] %s(): align [%td] was < 1.\n",
1810 "[KLS] " KLS_Loc_Fmt
"%s(): align [%td] was < 1.\n",
1817 if (! ((align & (align - 1)) == 0)) {
1818#ifndef KOLISEO_HAS_LOCATE
1820 "[KLS] %s(): align [%td] was not a power of 2.\n",
1825 "[KLS] " KLS_Loc_Fmt
"%s(): align [%td] was not a power of 2.\n",
1832 size_t old_size = old_count * size;
1833 size_t new_size = new_count * size;
1835 if (new_ptr && old_size > 0) {
1836 memcpy(new_ptr, old, old_size < new_size ? old_size : new_size);
1849 fprintf(stderr,
"print_kls_2file(): fp was NULL.\n");
1853 fprintf(fp,
"[KLS] kls was NULL.\n");
1860 fprintf(fp,
"\n[KLS] Size: { %td }\n", kls->
size);
1861 char human_size[200];
1862 char curr_size[200];
1864 fprintf(fp,
"[KLS] Size (Human): { %s }\n", human_size);
1866 fprintf(fp,
"[KLS] Used (Human): { %s }\n", curr_size);
1867 fprintf(fp,
"[KLS] Offset: { %td }\n", kls->
offset);
1868 fprintf(fp,
"[KLS] Prev_Offset: { %td }\n", kls->
prev_offset);
1880 fprintf(stderr,
"[ERROR] [%s()]: Passed Koliseo was NULL.\n", __func__);
1894 fprintf(stderr,
"print_temp_kls_2file(): fp was NULL.\n");
1897 if (t_kls == NULL) {
1898 fprintf(fp,
"[KLS_T] t_kls was NULL.");
1899 }
else if (t_kls->
kls == NULL) {
1900 fprintf(fp,
"[KLS_T] [%s()]: Referred Koliseo was NULL.\n", __func__);
1904 fprintf(fp,
"\n[KLS_T] Temp Size: { %td }\n",
1906 fprintf(fp,
"\n[KLS_T] Refer Size: { %td }\n", kls->
size);
1907 char human_size[200];
1908 char curr_size[200];
1910 sizeof(human_size));
1911 fprintf(fp,
"[KLS_T] Temp Size Human: { %s }\n", human_size);
1913 fprintf(fp,
"[KLS_T] Refer Size Human: { %s }\n", human_size);
1915 fprintf(fp,
"[KLS_T] Inner Used (Human): { %s }\n", curr_size);
1917 fprintf(fp,
"[KLS_T] Temp Used (Human): { %s }\n", curr_size);
1918 fprintf(fp,
"[KLS_T] Inner Offset: { %td }\n", kls->
offset);
1919 fprintf(fp,
"[KLS_T] Temp Offset: { %td }\n", t_kls->
offset);
1920 fprintf(fp,
"[KLS_T] Inner Prev_Offset: { %td }\n", kls->
prev_offset);
1921 fprintf(fp,
"[KLS_T] Temp Prev_Offset: { %td }\n\n",
1944 const char *units[] =
1945 {
"bytes",
"KB",
"MB",
"GB",
"TB",
"PB",
"EB",
"ZB",
"YB" };
1946 const int numUnits =
sizeof(units) /
sizeof(units[0]);
1949 double sizeValue = (double)size;
1951 while (sizeValue >= 1000 && unitIndex < numUnits - 1) {
1956 snprintf(outputBuffer, bufferSize,
"%.2f %s", sizeValue, units[unitIndex]);
1967 fprintf(stderr,
"[ERROR] [%s()]: Passed Koliseo was NULL.\n", __func__);
1972 kls->
offset =
sizeof(*kls);
1974#ifdef KLS_DEBUG_CORE
1975 kls_log(kls,
"KLS",
"API Level { %i } -> Cleared offsets for KLS.",
1988 fprintf(stderr,
"[ERROR] [%s()]: Passed Koliseo was NULL.\n", __func__);
1994 current->
next = NULL;
1995 for (
size_t i=0; i < current->
hooks_len; i++) {
2002#ifdef KLS_DEBUG_CORE
2004 "API Level { %i } -> KLS had an active Koliseo_Temp.",
2010#ifdef KLS_DEBUG_CORE
2011 kls_log(current,
"KLS",
"API Level { %i } -> Freeing KLS.",
2016#ifdef KLS_DEBUG_CORE
2017 kls_log(current,
"KLS",
"Closing kls log file. Path: {\"%s\"}.",
2021 if (close_res != 0) {
2023 "[ERROR] %s(): Failed fclose() on log_fp. Path: {\"%s\"}.",
2029 "[INFO] %s(): kls->conf.kls_log_fp is %s. Not closing it.\n",
2036 "[ERROR] %s(): free function was NULL.\n", __func__);
2051#ifndef KOLISEO_HAS_LOCATE
2058 fprintf(stderr,
"[ERROR] [%s()]: Passed Koliseo was NULL.\n", __func__);
2062 while (current->
next != NULL) {
2063 current = current->
next;
2067 "[ERROR] [%s()]: Passed Koliseo->has_temp is not 0. {%i}\n",
2069#ifdef KLS_DEBUG_CORE
2070 kls_log(current,
"ERROR",
"[%s()]: Passed Koliseo->has_temp != 0 . {%i}",
2079 ptrdiff_t off = current->
offset;
2085#ifdef KLS_DEBUG_CORE
2091 current->
t_kls = tmp;
2092 for (
size_t i=0; i < current->
hooks_len; i++) {
2098#ifdef KLS_DEBUG_CORE
2099 kls_log(current,
"KLS",
"Prepared new Temp KLS.");
2110 if (tmp_kls == NULL) {
2111 fprintf(stderr,
"[ERROR] [%s()]: Passed Koliseo_Temp was NULL.\n",
2117 if (kls_ref == NULL) {
2118 fprintf(stderr,
"[ERROR] [%s()]: Referred Koliseo was NULL.\n",
2123 for (
size_t i=0; i < kls_ref->
hooks_len; i++) {
2130#ifdef KLS_DEBUG_CORE
2131 kls_log(kls_ref,
"KLS",
"Ended Temp KLS.");
2135#if defined(__SANITIZE_ADDRESS__)
2136 ptrdiff_t old_offset = tmp_kls->
kls->
offset;
2137 ptrdiff_t new_offset = tmp_kls->
offset;
2144 if (to_free != NULL) {
2157#ifdef KOLISEO_HAS_EXPER
2169 fprintf(stderr,
"[ERROR] [%s()]: Passed Koliseo was NULL.\n", __func__);
2172 ptrdiff_t padding = -kls->
offset & (align - 1);
2173 if (count > PTRDIFF_MAX / size
2174 || (kls->
size + kls->
offset) < (size * count)) {
2175 fprintf(stderr,
"[KLS] Failed %s() call.\n", __func__);
2179 char *p = kls->
data + kls->
offset - padding - size * count;
2181 kls->
offset -= padding + size * count;
2182#ifdef KLS_DEBUG_CORE
2183 kls_log(kls,
"KLS",
"API Level { %i } -> Popped (%li) for KLS.",
2206 fprintf(stderr,
"[ERROR] [%s()]: Passed Koliseo was NULL.\n", __func__);
2209 ptrdiff_t padding = -kls->
offset & (align - 1);
2210 if (count > PTRDIFF_MAX / size
2211 || (kls->
size + kls->
offset) < (size * count)) {
2212 fprintf(stderr,
"[KLS] Failed %s() call.\n", __func__);
2216 char *p = kls->
data + kls->
offset - padding - size * count;
2218 kls->
offset -= padding + size * count;
2219#ifdef KLS_DEBUG_CORE
2220 kls_log(kls,
"KLS",
"API Level { %i } -> Popped (%li) for KLS.",
2243 if (t_kls == NULL) {
2244 fprintf(stderr,
"[ERROR] [%s()]: Passed Koliseo_Temp was NULL.\n",
2250 fprintf(stderr,
"[ERROR] [%s()]: Referred Koliseo was NULL.\n",
2254 ptrdiff_t padding = -kls->
offset & (align - 1);
2255 if (count > PTRDIFF_MAX / size
2256 || (kls->
size + kls->
offset) < (size * count)) {
2257 fprintf(stderr,
"[KLS] Failed %s() call.\n", __func__);
2261 char *p = kls->
data + kls->
offset - padding - size * count;
2263 kls->
offset -= padding + size * count;
2264#ifdef KLS_DEBUG_CORE
2265 kls_log(kls,
"KLS",
"Curr offset: { %p }.", kls + kls->
offset);
2266 kls_log(kls,
"KLS",
"API Level { %i } -> Popped (%li) for Temp_KLS.",
2288 if (t_kls == NULL) {
2289 fprintf(stderr,
"[ERROR] [%s()]: Passed Koliseo_Temp was NULL.\n",
2295 fprintf(stderr,
"[ERROR] [%s()]: Referred Koliseo was NULL.\n",
2299 ptrdiff_t padding = -kls->
offset & (align - 1);
2300 if (count > PTRDIFF_MAX / size
2301 || (kls->
size + kls->
offset) < (size * count)) {
2302 fprintf(stderr,
"[KLS] Failed %s() call.\n", __func__);
2306 char *p = kls->
data + kls->
offset - padding - size * count;
2308 kls->
offset -= padding + size * count;
2309#ifdef KLS_DEBUG_CORE
2310 kls_log(kls,
"KLS",
"Curr offset: { %p }.", kls + kls->
offset);
2311 kls_log(kls,
"KLS",
"API Level { %i } -> Popped (%li) for Temp_KLS.",
2344 char** strings = NULL;
2346 for (
int i=0; i < count; i++) {
2373 char** strings = NULL;
2375 for (
int i=0; i < count; i++) {
#define KLS_DEFAULT_HOOKS
Definition kls_region.h:162
#define KLS_DEFAULT_EXTENSIONS_LEN
DEPRECATED: Support for multiple extension will be dropped in the next release.
Definition kls_region.h:176
Koliseo * kls_new_traced(ptrdiff_t size, const char *output_path)
Takes a ptrdiff_t size and a filepath for the trace output file.
Definition koliseo.c:842
Koliseo * kls_new(ptrdiff_t size)
Takes a ptrdiff_t size.
Definition koliseo.c:650
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:2329
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:2240
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:2052
void print_dbg_temp_kls(const Koliseo_Temp *t_kls)
Prints header fields from the passed Koliseo_Temp pointer, to stderr.
Definition koliseo.c:1930
void * kls_temp_repush(Koliseo_Temp *t_kls, void *old, ptrdiff_t size, ptrdiff_t align, ptrdiff_t old_count, ptrdiff_t new_count)
Takes a Koliseo_Temp pointer, and a void pointer to the old allocation, ptrdiff_t values for size,...
Definition koliseo.c:1737
Koliseo * kls_new_dbg_alloc(ptrdiff_t size, kls_alloc_func alloc_func, kls_free_func free_func)
Takes a ptrdiff_t size, an allocation function pointer and a free function pointer,...
Definition koliseo.c:943
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:1891
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:2358
Koliseo * kls_new_traced_alloc_handled(ptrdiff_t size, const char *output_path, kls_alloc_func alloc_func, kls_free_func free_func, KLS_Err_Handlers err_handlers)
Takes a ptrdiff_t size, a filepath for the trace output file, an allocation function pointer and a fr...
Definition koliseo.c:789
KLS_Stats KLS_STATS_DEFAULT
Default KLS_Stats values, used by kls_new().
Definition koliseo.c:41
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:483
Koliseo * kls_new_traced_alloc_handled_ext(ptrdiff_t size, const char *output_path, kls_alloc_func alloc_func, kls_free_func free_func, KLS_Err_Handlers err_handlers, KLS_Hooks *ext_handlers, void **user, size_t ext_len)
Takes a ptrdiff_t size, a filepath for the trace output file, an allocation function pointer and a fr...
Definition koliseo.c:753
char * kls_vsprintf(Koliseo *kls, const char *fmt, va_list args)
Definition koliseo.c:1475
void kls_temp_end(Koliseo_Temp *tmp_kls)
Ends passed Koliseo_Temp pointer.
Definition koliseo.c:2108
void kls_dbg_features(void)
Prints enabled Koliseo features to stderr.
Definition koliseo.c:235
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:2342
void * kls_temp_push_zero_ext(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:1528
void print_dbg_kls(const Koliseo *kls)
Prints header fields from the passed Koliseo pointer, to stderr.
Definition koliseo.c:1877
const char * string_koliseo_version(void)
Returns the constant string representing current version for Koliseo.
Definition koliseo.c:59
void * kls_repush(Koliseo *kls, void *old, ptrdiff_t size, ptrdiff_t align, ptrdiff_t old_count, ptrdiff_t new_count)
Takes a Koliseo pointer, and a void pointer to the old allocation, ptrdiff_t values for size,...
Definition koliseo.c:1617
KLS_Push_Result kls__advance(Koliseo *kls, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count, ptrdiff_t *padding, const char *caller_name)
Takes a Koliseo pointer, and ptrdiff_t values for size, align and count.
Definition koliseo.c:1100
char * kls_temp_vsprintf(Koliseo_Temp *kls_t, const char *fmt, va_list args)
Definition koliseo.c:1563
ptrdiff_t kls_get_pos(const Koliseo *kls)
Returns the current offset (position of pointer bumper) for the passed Koliseo.
Definition koliseo.c:288
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:2286
#define KLS_ASAN_UNPOISON(addr, size)
Definition koliseo.c:79
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:2203
void kls_free(Koliseo *kls)
Calls kls_clear() on the passed Koliseo pointer and the frees the actual Koliseo.
Definition koliseo.c:1985
KLS_Conf kls_conf_init_handled(int collect_stats, int verbose_lvl, int block_while_has_temp, int allow_zerocount_push, int growable, 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:178
Koliseo * kls_new_traced_ext(ptrdiff_t size, const char *output_path, KLS_Hooks *ext_handlers, void **user, size_t ext_len)
Takes a ptrdiff_t size and a filepath for the trace output file.
Definition koliseo.c:806
char * kls_temp_sprintf(Koliseo_Temp *kls_t, const char *fmt,...)
Takes a Koliseo_Temp pointer, and a format cstring, plus varargs.
Definition koliseo.c:1589
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:2371
void * kls_push(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:1368
Koliseo * kls_new_dbg_alloc_handled(ptrdiff_t size, kls_alloc_func alloc_func, kls_free_func free_func, KLS_Err_Handlers err_handlers)
Takes a ptrdiff_t size, an allocation function pointer and a free function pointer,...
Definition koliseo.c:911
#define KLS_ASAN_POISON(addr, size)
Definition koliseo.c:78
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:1391
Koliseo * kls_new_alloc(ptrdiff_t size, kls_alloc_func alloc_func, kls_free_func free_func)
Takes a ptrdiff_t size and a function pointer to the allocation function.
Definition koliseo.c:626
Koliseo * kls_new_dbg(ptrdiff_t size)
Takes a ptrdiff_t size and returns a pointer to the prepared Koliseo.
Definition koliseo.c:958
Koliseo * kls_new_traced_alloc(ptrdiff_t size, const char *output_path, kls_alloc_func alloc_func, kls_free_func free_func)
Takes a ptrdiff_t size, a filepath for the trace output file, an allocation function pointer and a fr...
Definition koliseo.c:825
char * kls_sprintf(Koliseo *kls, const char *fmt,...)
Takes a Koliseo pointer, and a format cstring, plus varargs.
Definition koliseo.c:1500
Koliseo * kls_new_conf_alloc_ext(ptrdiff_t size, KLS_Conf conf, kls_alloc_func alloc_func, kls_free_func free_func, KLS_Hooks *ext_handlers, void **user, size_t ext_len)
Takes a ptrdiff_t size, a KLS_Conf to configure the new Koliseo, an allocation function pointer and a...
Definition koliseo.c:671
Koliseo * kls_new_traced_handled(ptrdiff_t size, const char *output_path, KLS_Err_Handlers err_handlers)
Takes a ptrdiff_t size and a filepath for the trace output file.
Definition koliseo.c:859
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:2166
void KLS_PTRDIFF_MAX_default_handler__(struct Koliseo *kls, ptrdiff_t size, ptrdiff_t count)
Used by default when no handler is passed.
Definition koliseo.c:112
KLS_Conf KLS_DEFAULT_CONF
Config used by any new Koliseo by default.
Definition koliseo.c:20
KLS_Conf kls_conf_init(int collect_stats, int verbose_lvl, int block_while_has_temp, int allow_zerocount_push, int growable, FILE *log_fp, const char *log_filepath)
Used to prepare a KLS_Conf without caring about KOLISEO_HAS_REGIONS.
Definition koliseo.c:226
void KLS_ZEROCOUNT_default_handler__(Koliseo *kls, ptrdiff_t available, ptrdiff_t padding, ptrdiff_t size)
Used internally for handling zero-count in push calls when no user handler is provided.
Definition koliseo.c:154
KLS_Push_Error kls__check_available_failable(Koliseo *kls, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count, const char *caller_name)
Takes a Koliseo, a ptrdiff_t size, align and count, and a caller name.
Definition koliseo.c:1200
void * kls__handle_push_result(Koliseo *kls, KLS_Push_Result r, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count, ptrdiff_t padding, const char *caller_name)
Definition koliseo.c:294
Koliseo * kls_new_dbg_ext(ptrdiff_t size, KLS_Hooks *ext_handlers, void **user, size_t ext_len)
Takes a ptrdiff_t size.
Definition koliseo.c:926
Koliseo * kls_new_alloc_ext(ptrdiff_t size, kls_alloc_func alloc_func, kls_free_func free_func, KLS_Hooks *ext_handlers, void **user, size_t ext_len)
Takes a ptrdiff_t size and a function pointer to the allocation function.
Definition koliseo.c:529
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:1846
Koliseo * kls_new_dbg_alloc_handled_ext(ptrdiff_t size, kls_alloc_func alloc_func, kls_free_func free_func, KLS_Err_Handlers err_handlers, KLS_Hooks *ext_handlers, void **user, size_t ext_len)
Takes a ptrdiff_t size, an allocation function pointer and a free function pointer,...
Definition koliseo.c:877
Koliseo * kls_new_dbg_handled(ptrdiff_t size, KLS_Err_Handlers err_handlers)
Takes a ptrdiff_t size and returns a pointer to the prepared Koliseo.
Definition koliseo.c:973
void kls_clear(Koliseo *kls)
Resets the offset field for the passed Koliseo pointer.
Definition koliseo.c:1964
void * kls_push_zero_ext(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:1424
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:1942
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:92
Koliseo * kls_new_conf_alloc(ptrdiff_t size, KLS_Conf conf, kls_alloc_func alloc_func, kls_free_func free_func)
Takes a ptrdiff_t size, a KLS_Conf to configure the new Koliseo, an allocation function pointer and a...
Definition koliseo.c:700
KLS_Push_Result kls__temp_advance(Koliseo_Temp *kls_t, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count, ptrdiff_t *padding, const char *caller_name)
Takes a Koliseo_Temp, and ptrdiff_t values for size, align and count.
Definition koliseo.c:1260
int int_koliseo_version(void)
Returns the constant int representing current version for Koliseo.
Definition koliseo.c:68
Koliseo * kls_new_conf(ptrdiff_t size, KLS_Conf conf)
Takes a ptrdiff_t size and a KLS_Conf to configure the new Koliseo.
Definition koliseo.c:733
Koliseo * kls_new_conf_ext(ptrdiff_t size, KLS_Conf conf, KLS_Hooks *ext_handlers, void **user, size_t ext_len)
Takes a ptrdiff_t size and a KLS_Conf to configure the new Koliseo.
Definition koliseo.c:717
void kls_free_func(void *)
Used to select a free function for the arena's backing memory.
Definition koliseo.h:94
#define KLS_PUSH_STR_T(kls_temp, cstr)
Macro to request memory for a C string from a Koliseo_Temp.
Definition koliseo.h:680
#define KLS_Stats_Fmt
Defines a format string for KLS_Stats.
Definition koliseo.h:295
#define KLS_PUSH_STR(kls, cstr)
Macro to request memory for a C string from a Koliseo.
Definition koliseo.h:566
#define KLS_Conf_Arg(conf)
Defines a format macro for KLS_Conf args.
Definition koliseo.h:288
#define KLS_DEFAULT_FREEF
Defines the default free function.
Definition koliseo.h:434
#define KLS_DEFAULT_ALLOCF
Defines the default allocation function.
Definition koliseo.h:430
#define KLS_PUSH(kls, type)
Macro used to request memory from a Koliseo.
Definition koliseo.h:601
#define KLS__STRCPY(dest, source)
Macro to copy a C string from a source buffer to a destination buffer.
Definition koliseo.h:784
#define KLS_ALIGNOF
Definition koliseo.h:22
#define KLS_DEFAULT_EXTENSION_DATA
Defines default hooks that are loaded on kls_new() variants lacking explicit set of KLS_Hooks.
Definition koliseo.h:224
void * kls_alloc_func(size_t)
Used to select an allocation function for the arena's backing memory.
Definition koliseo.h:93
#define KLS_MAX(a, b)
Definition koliseo.h:100
#define KLS_STRDUP(kls, source)
Definition koliseo.h:793
KLS_Push_Error
Defines the result for kls__check_available_failable().
Definition koliseo.h:390
@ KLS_PUSH_NEGATIVE_COUNT
Definition koliseo.h:395
@ KLS_PUSH_ZEROCOUNT
Definition koliseo.h:396
@ KLS_PUSH_ALIGN_NOT_POW2
Definition koliseo.h:394
@ KLS_PUSH_WITH_TEMP_ACTIVE
Definition koliseo.h:397
@ KLS_PUSH_OOM
Definition koliseo.h:399
@ KLS_PUSH_PTRDIFF_MAX
Definition koliseo.h:398
@ KLS_PUSH_SIZE_LT1
Definition koliseo.h:392
@ KLS_PUSH_ALIGN_LT1
Definition koliseo.h:393
@ KLS_PUSH_OK
Definition koliseo.h:391
#define KLS_Stats_Arg(stats)
Defines a format macro for KLS_Stats args.
Definition koliseo.h:305
#define KLS_Conf_Fmt
Defines a format string for KLS_Conf.
Definition koliseo.h:282
#define KLS_PUSH_ARR_T(kls_temp, type, count)
Macro used to request memory for an array of type values from a Koliseo_Temp.
Definition koliseo.h:669
#define KLS_STRDUP_T(t_kls, source)
Definition koliseo.h:803
#define KLS_DEFAULT_ERR_HANDLERS
Definition koliseo.h:180
#define KLS_PUSH_ARR(kls, type, count)
Macro used to request memory for an array of type values from a Koliseo.
Definition koliseo.h:555
Defines flags for Koliseo.
Definition koliseo.h:231
int kls_growable
If set to 1, make the Koliseo grow when a out of memory for a push call.
Definition koliseo.h:238
int kls_collect_stats
If set to 1, make the Koliseo collect performance stats.
Definition koliseo.h:232
int kls_allow_zerocount_push
If set to 1, make the Koliseo accept push calls with a count of 0.
Definition koliseo.h:237
int kls_block_while_has_temp
If set to 1, make the Koliseo reject push calls while it has an open Koliseo_Temp.
Definition koliseo.h:236
int kls_verbose_lvl
If > 0, makes the Koliseo try to acquire kls_log_fp from kls_log_filepath.
Definition koliseo.h:233
KLS_Err_Handlers err_handlers
Used to pass custom error handlers for push calls.
Definition koliseo.h:239
const char * kls_log_filepath
String representing the path to the Koliseo logfile.
Definition koliseo.h:235
FILE * kls_log_fp
FILE pointer used by the Koliseo to print its kls_log() output.
Definition koliseo.h:234
Defines the handlers used for errors in push calls.
Definition koliseo.h:173
KLS_OOM_Handler * OOM_handler
Pointer to handler for Out-Of-Memory errors in push calls.
Definition koliseo.h:174
KLS_ZEROCOUNT_Handler * ZEROCOUNT_handler
Pointer to handler for zero-count errors in push calls.
Definition koliseo.h:176
KLS_PTRDIFF_MAX_Handler * PTRDIFF_MAX_handler
Pointer to handler for count > (PTRDIFF_MAX / size) errors in push calls.
Definition koliseo.h:175
KLS_hook_on_temp_start * on_temp_start_handler
Used to pass custom start handler for kls_temp_start calls.
Definition koliseo.h:201
KLS_hook_on_free * on_free_handler
Used to pass custom free handler for kls_free calls.
Definition koliseo.h:199
KLS_hook_on_temp_free * on_temp_free_handler
Used to pass custom free handler for kls_temp_end calls.
Definition koliseo.h:202
KLS_hook_on_push * on_push_handler
Used to pass custom push handler for kls_push calls.
Definition koliseo.h:200
KLS_hook_on_new * on_new_handler
Used to pass custom new handler for kls_new_alloc calls.
Definition koliseo.h:198
KLS_hook_on_temp_push * on_temp_push_handler
Used to pass custom push handler for kls_temp_push calls.
Definition koliseo.h:203
Defines the result for kls__advance() and kls__temp_advance().
Definition koliseo.h:407
KLS_Push_Error error
Definition koliseo.h:409
void * p
Definition koliseo.h:408
Defines a stat struct for Koliseo.
Definition koliseo.h:252
int tot_pops
Total POP calls done.
Definition koliseo.h:255
double worst_pushcall_time
Longest time taken by a PUSH call.
Definition koliseo.h:260
int tot_temp_pushes
Total PUSH_T calls done.
Definition koliseo.h:254
int tot_pushes
Total PUSH calls done.
Definition koliseo.h:253
int tot_hiccups
Total hiccups encountered.
Definition koliseo.h:258
int tot_temp_pops
Total POP_T calls done.
Definition koliseo.h:256
Represents a savestate for a Koliseo.
Definition koliseo.h:379
ptrdiff_t offset
Current position of memory pointer.
Definition koliseo.h:381
ptrdiff_t prev_offset
Previous position of memory pointer.
Definition koliseo.h:382
Koliseo * kls
Reference to the actual Koliseo we're saving.
Definition koliseo.h:380
Represents the initialised arena allocator struct.
Definition koliseo.h:340
ptrdiff_t size
Size of data field.
Definition koliseo.h:342
ptrdiff_t offset
Current position of memory pointer.
Definition koliseo.h:343
ptrdiff_t prev_offset
Previous position of memory pointer.
Definition koliseo.h:344
KLS_Conf conf
Contains flags to change the Koliseo behaviour.
Definition koliseo.h:346
void * extension_data[KLS_MAX_EXTENSIONS]
Points to data for extensions.
Definition koliseo.h:350
struct Koliseo_Temp * t_kls
Points to related active Kolieo_Temp, when has_temp == 1.
Definition koliseo.h:348
char * data
Points to data field.
Definition koliseo.h:341
size_t hooks_len
Length for hooks and extension_data.
Definition koliseo.h:351
struct Koliseo * next
Points to the next Koliseo when conf.kls_growable == 1.
Definition koliseo.h:353
int has_temp
When == 1, a Koliseo_Temp is currently active on this Koliseo.
Definition koliseo.h:345
KLS_Stats stats
Contains stats for Koliseo performance analysis.
Definition koliseo.h:347
KLS_Hooks hooks[KLS_MAX_EXTENSIONS]
Contains handlers for extensions.
Definition koliseo.h:349
kls_free_func * free_func
Points to the free function for the arena's backing memory.
Definition koliseo.h:352