23 .block_while_has_temp = 1,
24 .allow_zerocount_push = 0,
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__,
48 .worst_pushcall_time = -1,
60 return KOLISEO_API_VERSION_STRING;
69 return KOLISEO_API_VERSION_INT;
72#if defined(__SANITIZE_ADDRESS__)
73#include <sanitizer/asan_interface.h>
74#define KLS_ASAN_POISON(addr, size) __asan_poison_memory_region((addr), (size))
75#define KLS_ASAN_UNPOISON(addr, size) __asan_unpoison_memory_region((addr), (size))
77#define KLS_ASAN_POISON(addr, size) ((void)0)
78#define KLS_ASAN_UNPOISON(addr, size) ((void)0)
90#ifndef KOLISEO_HAS_LOCATE
93void KLS_OOM_default_handler_dbg__(
Koliseo* kls, ptrdiff_t available, ptrdiff_t padding, ptrdiff_t size, ptrdiff_t count, Koliseo_Loc loc)
96#ifndef KOLISEO_HAS_LOCATE
98 "[KLS] Out of memory. size*count [%td] was bigger than available-padding [%td].\n",
99 size * count, available - padding);
102 "[KLS] " KLS_Loc_Fmt
"Out of memory. size*count [%td] was bigger than available-padding [%td].\n",
104 size * count, available - padding);
110#ifndef KOLISEO_HAS_LOCATE
113void KLS_PTRDIFF_MAX_default_handler_dbg__(
struct Koliseo* kls, ptrdiff_t size, ptrdiff_t count, Koliseo_Loc loc)
117#ifndef KOLISEO_HAS_LOCATE
119 "[KLS] count [%td] was bigger than PTRDIFF_MAX/size [%li].\n",
120 count, PTRDIFF_MAX / size);
123 "[KLS] " KLS_Loc_Fmt
"count [%td] was bigger than PTRDIFF_MAX/size [%li].\n",
125 count, PTRDIFF_MAX / size);
128#ifndef KOLISEO_HAS_LOCATE
130 "[KLS] count [%td] was bigger than PTRDIFF_MAX/size [%lli].\n",
131 count, PTRDIFF_MAX / size);
134 "[KLS] " KLS_Loc_Fmt
"count [%td] was bigger than PTRDIFF_MAX/size [%lli].\n",
136 count, PTRDIFF_MAX / size);
152#ifndef KOLISEO_HAS_LOCATE
155void KLS_ZEROCOUNT_default_handler_dbg__(
Koliseo* kls, ptrdiff_t available, ptrdiff_t padding, ptrdiff_t size, Koliseo_Loc loc)
158#ifndef KOLISEO_HAS_LOCATE
160 "[KLS] Doing a zero-count push. size [%td] padding [%td] available [%td].\n",
161 size, padding, available);
164 "[KLS] " KLS_Loc_Fmt
"Doing a zero-count push. size [%td] padding [%td] available [%td].\n",
166 size, padding, available);
191#ifndef KOLISEO_HAS_LOCATE
201#ifndef KOLISEO_HAS_LOCATE
211#ifndef KOLISEO_HAS_LOCATE
225KLS_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)
228 return kls_conf_init_handled(collect_stats, verbose_lvl, block_while_has_temp, allow_zerocount_push, growable, log_fp, log_filepath, err_handlers);
236#ifdef KOLISEO_HAS_LOCATE
237 bool kls_locate =
true;
239 bool kls_locate =
false;
242 bool kls_debug =
true;
244 bool kls_debug =
false;
246#ifdef KOLISEO_HAS_EXPER
247 bool kls_exper =
true;
249 bool kls_exper =
false;
256 int total_enabled = 0;
257 for (
int i=0; i<3; i++) {
262 fprintf(stderr,
"[KLS] Enabled features: {");
263 if (total_enabled == 0) {
264 fprintf(stderr,
"none}\n");
268 fprintf(stderr,
"debug%s", (total_enabled > 1 ?
", " :
""));
272 fprintf(stderr,
"locate%s", (total_enabled > 1 ?
", " :
""));
276 fprintf(stderr,
"exper");
278 fprintf(stderr,
"}\n");
304#ifndef KOLISEO_HAS_LOCATE
307void* 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)
310 if (!kls)
return NULL;
312 while (current->
next != NULL) {
313 current = current->
next;
316 const ptrdiff_t available = current->
size - current->
offset;
323#ifndef KOLISEO_HAS_LOCATE
325 "[KLS] %s(): size [%td] was < 1.\n",
330 "[KLS] " KLS_Loc_Fmt
"%s(): size [%td] was < 1.\n",
338#ifndef KOLISEO_HAS_LOCATE
340 "[KLS] %s(): align [%td] was < 1.\n",
345 "[KLS] " KLS_Loc_Fmt
"%s(): align [%td] was < 1.\n",
353#ifndef KOLISEO_HAS_LOCATE
355 "[KLS] %s(): align [%td] was not a power of 2.\n",
360 "[KLS] " KLS_Loc_Fmt
"%s(): align [%td] was not a power of 2.\n",
368#ifndef KOLISEO_HAS_LOCATE
370 "[KLS] %s(): count [%td] was < 0.\n",
375 "[KLS] " KLS_Loc_Fmt
"%s(): count [%td] was < 0.\n",
384#ifndef KOLISEO_HAS_LOCATE
390#ifndef KOLISEO_HAS_LOCATE
392 "[KLS] %s(): Doing a zero-count push. size [%td] padding [%td] available [%td].\n",
394 size, padding, available);
397 "[KLS] " KLS_Loc_Fmt
"%s(): Doing a zero-count push. size [%td] padding [%td] available [%td].\n",
400 size, padding, available);
408#ifndef KOLISEO_HAS_LOCATE
409 fprintf(stderr,
"[ERROR] [%s()]: Passed Koliseo has an open Koliseo_Temp session.\n", caller_name);
411 fprintf(stderr,
"[ERROR] " KLS_Loc_Fmt
"[%s()]: Passed Koliseo has an open Koliseo_Temp session.\n", KLS_Loc_Arg(loc), caller_name);
412 kls_log(kls,
"ERROR", KLS_Loc_Fmt
"[%s()]: Passed Koliseo has an open Koliseo_Temp session.", KLS_Loc_Arg(loc), caller_name);
419#ifndef KOLISEO_HAS_LOCATE
426#ifndef KOLISEO_HAS_LOCATE
428 "[KLS] %s(): count [%td] was bigger than PTRDIFF_MAX/size [%li].\n",
430 count, PTRDIFF_MAX / size);
433 "[KLS] " KLS_Loc_Fmt
"%s(): count [%td] was bigger than PTRDIFF_MAX/size [%li].\n",
436 count, PTRDIFF_MAX / size);
439#ifndef KOLISEO_HAS_LOCATE
441 "[KLS] %s(): count [%td] was bigger than PTRDIFF_MAX/size [%lli].\n",
443 count, PTRDIFF_MAX / size);
446 "[KLS] " KLS_Loc_Fmt
"%s(): count [%td] was bigger than PTRDIFF_MAX/size [%lli].\n",
449 count, PTRDIFF_MAX / size);
457#ifndef KOLISEO_HAS_LOCATE
463#ifndef KOLISEO_HAS_LOCATE
465 "[KLS] %s(): Out of memory. size*count [%td] was bigger than available-padding [%td].\n",
467 size * count, available - padding);
470 "[KLS] " KLS_Loc_Fmt
"%s(): Out of memory. size*count [%td] was bigger than available-padding [%td].\n",
473 size * count, available - padding);
479 fprintf(stderr,
"[KLS] %s(): unexpected error code [%i]\n", __func__, r.
error);
497 fprintf(stderr,
"[KLS] %s(): Passed kls was NULL.\n", __func__);
503 va_start(args, format);
506 "[KLS] %s(): Failed opening file to print logs.\n",
509 time_t now = time(0);
510 const struct tm *mytime = localtime(&now);
511 char timeheader[500];
512 if (strftime(timeheader,
sizeof timeheader,
"%X", mytime)) {
513 fprintf(fp,
"[%-10.10s] [%s] [", tag, timeheader);
514 vfprintf(fp, format, args);
539#ifndef KOLISEO_HAS_LOCATE
545 if (size < (ptrdiff_t)
sizeof(
Koliseo)) {
546#ifndef KOLISEO_HAS_LOCATE
548 "[ERROR] at %s(): invalid requested kls size (%td). Min accepted is: (%td).\n",
549 __func__, size, (ptrdiff_t)
sizeof(
Koliseo));
552 "[ERROR] " KLS_Loc_Fmt
"%s(): invalid requested kls size (%td). Min accepted is: (%td).\n",
553 KLS_Loc_Arg(loc), __func__, size, (ptrdiff_t)
sizeof(
Koliseo));
558 void *p = alloc_func(size);
567 kls->
offset =
sizeof(*kls);
577 kls->
hooks = ext_handlers;
586 kls_log(kls,
"KLS",
"API Level { %i } -> Allocated (%s) for new KLS.",
588 kls_log(kls,
"KLS",
"KLS offset: { %p }.", kls);
589 kls_log(kls,
"KLS",
"Allocation begin offset: { %p }.",
598#ifndef KOLISEO_HAS_LOCATE
599 fprintf(stderr,
"[KLS] Failed %s() call.\n", __func__);
601 fprintf(stderr,
"[KLS] " KLS_Loc_Fmt
"Failed %s() call.\n", KLS_Loc_Arg(loc), __func__);
629#ifndef KOLISEO_HAS_LOCATE
635#ifndef KOLISEO_HAS_LOCATE
678 bool conf_res = kls_set_conf(k, conf);
681 "[ERROR] [%s()]: Failed to set config for new Koliseo.\n",
760#ifndef KLS_DEBUG_CORE
762 "[WARN] %s(): KLS_DEBUG_CORE is not defined. No tracing allowed.\n",
766 .collect_stats = 1,.verbose_lvl =
767 1,.log_filepath = output_path,
768#ifndef KOLISEO_HAS_LOCATE
772 .err_handlers.OOM_handler = (err_handlers.
OOM_handler != NULL ? err_handlers.
OOM_handler : &KLS_OOM_default_handler_dbg__),
883#ifndef KLS_DEBUG_CORE
885 "[WARN] %s(): KLS_DEBUG_CORE is not defined. No debugging support.\n",
889 .collect_stats = 1,.verbose_lvl = 0,
890#ifndef KOLISEO_HAS_LOCATE
894 .err_handlers.OOM_handler = ( err_handlers.
OOM_handler != NULL ? err_handlers.
OOM_handler : &KLS_OOM_default_handler_dbg__),
991 fprintf(stderr,
"[ERROR] [%s()]: Passed Koliseo was NULL.\n", __func__);
1000#ifdef KLS_SETCONF_DEBUG
1002 "[%s()]: Preliminary set of conf.log_fp to stderr.",
1010 "[ERROR] at %s(): passed OOM_handler is NULL. Using default.\n",
1012#ifdef KLS_DEBUG_CORE
1013#ifdef KLS_SETCONF_DEBUG
1015 "[%s()]: Passed OOM_handler was NULL, using default.",
1019#ifndef KOLISEO_HAS_LOCATE
1028 "[ERROR] at %s(): passed PTRDIFF_MAX_handler is NULL. Using default.\n",
1030#ifdef KLS_DEBUG_CORE
1031#ifdef KLS_SETCONF_DEBUG
1033 "[%s()]: Passed PTRDIFF_MAX_handler was NULL, using default.",
1037#ifndef KOLISEO_HAS_LOCATE
1044#ifndef KLS_DEBUG_CORE
1047 "[WARN] [%s()]: KLS_DEBUG_CORE is not defined. Stats may not be collected in full.\n",
1054#ifdef KLS_DEBUG_CORE
1055#ifdef KLS_SETCONF_DEBUG
1057 "[%s()]: kls->conf.log_fp was not NULL. Overriding it.",
1063 FILE *log_fp = NULL;
1067 "[ERROR] [%s()]: Failed opening logfile at {\"%s\"} [write].\n",
1071 fprintf(log_fp,
"%s",
"");
1077 "[ERROR] [%s()]: Failed opening logfile at {\"%s\"} [append].\n",
1087static bool kls__try_grow(
Koliseo* kls, ptrdiff_t needed);
1100#ifndef KOLISEO_HAS_LOCATE
1103KLS_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)
1106#ifdef KLS_DEBUG_CORE
1108 struct timespec start_time, end_time;
1109 clock_gettime(CLOCK_MONOTONIC, &start_time);
1111 LARGE_INTEGER start_time, end_time, frequency;
1112 QueryPerformanceFrequency(&frequency);
1113 QueryPerformanceCounter(&start_time);
1118 fprintf(stderr,
"[ERROR] [%s()]: Passed Koliseo was NULL.\n", caller_name);
1128#ifndef KOLISEO_HAS_LOCATE
1131 KLS_Push_Error res = kls__check_available_dbg(kls, size, align, count, __func__, loc);
1140 while (current->
next != NULL) {
1141 current = current->
next;
1143 const ptrdiff_t pad = -current->
offset & (align - 1);
1145 char *p = current->
data + current->
offset + pad;
1147 current->
offset += pad + size * count;
1155#ifdef KLS_DEBUG_CORE
1156 kls_log(current,
"KLS",
"Pushed zeroes on KLS, size (%s). Curr offset: { %p }.", h_size, current->
data + current->
offset);
1159 clock_gettime(CLOCK_MONOTONIC, &end_time);
1160 double elapsed_time =
1161 (end_time.tv_sec - start_time.tv_sec) + (end_time.tv_nsec -
1162 start_time.tv_nsec) / 1e9;
1164 QueryPerformanceCounter(&end_time);
1165 double elapsed_time =
1166 (double)(end_time.QuadPart -
1167 start_time.QuadPart) / frequency.QuadPart;
1195#ifndef KOLISEO_HAS_LOCATE
1198KLS_Push_Error kls__check_available_dbg(
Koliseo* kls, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count,
const char* caller_name, Koliseo_Loc loc)
1201 assert(kls != NULL);
1202 assert(caller_name != NULL);
1212 if (! ((align & (align - 1)) == 0)) {
1216 while (current->
next != NULL) {
1217 current = current->
next;
1219 const ptrdiff_t available = current->
size - current->
offset;
1220 const ptrdiff_t padding = -current->
offset & (align - 1);
1225#ifdef KLS_DEBUG_CORE
1226 kls_log(current,
"DEBUG",
"Accepting zero-count push: conf.allow_zerocount_push was 1");
1231 if (count > PTRDIFF_MAX / size || available - padding < size * count) {
1232 if (count > PTRDIFF_MAX / size) {
1235 if (current->
conf.
growable == 1 && kls__try_grow(current, size + count + padding)) {
1255#ifndef KOLISEO_HAS_LOCATE
1258KLS_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)
1261#ifdef KLS_DEBUG_CORE
1263 struct timespec start_time, end_time;
1264 clock_gettime(CLOCK_MONOTONIC, &start_time);
1266 LARGE_INTEGER start_time, end_time, frequency;
1267 QueryPerformanceFrequency(&frequency);
1268 QueryPerformanceCounter(&start_time);
1272 if (kls_t == NULL) {
1273 fprintf(stderr,
"[ERROR] [%s()]: Passed Koliseo_Temp was NULL.\n",
1279 fprintf(stderr,
"[ERROR] [%s()]: Referred Koliseo was NULL.\n",
1283#ifndef KOLISEO_HAS_LOCATE
1286 KLS_Push_Error res = kls__check_available_dbg(kls, size, align, count, __func__, loc);
1295 while (current->
next != NULL) {
1296 current = current->
next;
1298 ptrdiff_t pad = -current->
offset & (align - 1);
1299 char *p = current->
data + current->
offset + pad;
1302 current->
offset += pad + size * count;
1310#ifdef KLS_DEBUG_CORE
1313 clock_gettime(CLOCK_MONOTONIC, &end_time);
1314 double elapsed_time =
1315 (end_time.tv_sec - start_time.tv_sec) + (end_time.tv_nsec -
1316 start_time.tv_nsec) / 1e9;
1318 QueryPerformanceCounter(&end_time);
1319 double elapsed_time =
1320 (double)(end_time.QuadPart -
1321 start_time.QuadPart) / frequency.QuadPart;
1327 kls_log(current,
"KLS",
"Pushed zeroes on Temp_KLS, size (%s). Curr offset: { %p }.", h_size, current->
data + current->
offset);
1338bool kls__try_grow(
Koliseo* kls, ptrdiff_t needed)
1340 assert(kls->
next == NULL);
1341 ptrdiff_t new_size =
KLS_MAX(kls->
size * 2, needed);
1346 kls_log(kls,
"DEBUG",
"%s(): growing Koliseo, new size: {%td}", __func__, new_size);
1347 if (!new_kls)
return false;
1348 kls->
next = new_kls;
1364 ptrdiff_t padding = 0;
1365#ifndef KOLISEO_HAS_LOCATE
1369 KLS_Push_Result res = kls__advance_dbg(kls, size, align, count, &padding, __func__, KLS_HERE);
1370 return kls__handle_push_result_dbg(kls, res, size, align, count, padding, __func__, KLS_HERE);
1384#ifndef KOLISEO_HAS_LOCATE
1388void *kls_push_zero_dbg(
Koliseo *kls, ptrdiff_t size, ptrdiff_t align,
1389 ptrdiff_t count, Koliseo_Loc loc)
1392 ptrdiff_t padding = 0;
1393#ifndef KOLISEO_HAS_LOCATE
1397 KLS_Push_Result res = kls__advance_dbg(kls, size, align, count, &padding, __func__, loc);
1398 void* p = kls__handle_push_result_dbg(kls, res, size, align, count, padding, __func__, loc);
1400 if (!p)
return NULL;
1402 memset(p, 0, size * count);
1417#ifndef KOLISEO_HAS_LOCATE
1421void *kls_push_zero_ext_dbg(
Koliseo *kls, ptrdiff_t size, ptrdiff_t align,
1422 ptrdiff_t count, Koliseo_Loc loc)
1426 ptrdiff_t padding = 0;
1427#ifndef KOLISEO_HAS_LOCATE
1431 KLS_Push_Result res = kls__advance_dbg(kls, size, align, count, &padding, __func__, loc);
1432 void* p = kls__handle_push_result_dbg(kls, res, size, align, count, padding, __func__, loc);
1434 if (!p)
return NULL;
1436 memset(p, 0, size * count);
1439 while (current->
next != NULL) {
1440 current = current->
next;
1466#ifndef KOLISEO_HAS_LOCATE
1469char* kls_vsprintf_dbg(
Koliseo* kls, Koliseo_Loc loc,
const char* fmt, va_list args)
1473 va_copy(args_copy, args);
1474 int len = vsnprintf(NULL, 0, fmt, args);
1475#ifndef KOLISEO_HAS_LOCATE
1478 char* str = kls_push_zero_ext_dbg(kls,
sizeof(
char),
KLS_ALIGNOF(
char), len+1, loc);
1480 vsnprintf(str, len+1, fmt, args_copy);
1491#ifndef KOLISEO_HAS_LOCATE
1494char* kls_sprintf_dbg(
Koliseo* kls, Koliseo_Loc loc,
const char* fmt, ...)
1498 va_start(args, fmt);
1499#ifndef KOLISEO_HAS_LOCATE
1502 char* str = kls_vsprintf_dbg(kls, loc, fmt, args);
1519#ifndef KOLISEO_HAS_LOCATE
1521 ptrdiff_t align, ptrdiff_t count)
1523void *kls_temp_push_zero_ext_dbg(
Koliseo_Temp *t_kls, ptrdiff_t size,
1524 ptrdiff_t align, ptrdiff_t count, Koliseo_Loc loc)
1528 ptrdiff_t padding = 0;
1530#ifndef KOLISEO_HAS_LOCATE
1533 KLS_Push_Result res = kls__temp_advance_dbg(t_kls, size, align, count, &padding, __func__, loc);
1535 if (res.
error)
return NULL;
1537 memset(res.
p, 0, size * count);
1541 while (current->
next != NULL) {
1542 current = current->
next;
1552#ifndef KOLISEO_HAS_LOCATE
1555char* kls_temp_vsprintf_dbg(
Koliseo_Temp* kls_t, Koliseo_Loc loc,
const char* fmt, va_list args)
1559 va_copy(args_copy, args);
1560 int len = vsnprintf(NULL, 0, fmt, args);
1561#ifndef KOLISEO_HAS_LOCATE
1564 char* str = kls_temp_push_zero_ext_dbg(kls_t,
sizeof(
char),
KLS_ALIGNOF(
char), len+1, loc);
1566 vsnprintf(str, len+1, fmt, args_copy);
1578#ifndef KOLISEO_HAS_LOCATE
1581char* kls_temp_sprintf_dbg(
Koliseo_Temp* kls_t, Koliseo_Loc loc,
const char* fmt, ...)
1585 va_start(args, fmt);
1586#ifndef KOLISEO_HAS_LOCATE
1589 char* str = kls_temp_vsprintf_dbg(kls_t, loc, fmt, args);
1606#ifndef KOLISEO_HAS_LOCATE
1608 ptrdiff_t old_count, ptrdiff_t new_count)
1610void *kls_repush_dbg(
Koliseo *kls,
void* old, ptrdiff_t size, ptrdiff_t align,
1611 ptrdiff_t old_count, ptrdiff_t new_count, Koliseo_Loc loc)
1615#ifndef KOLISEO_HAS_LOCATE
1617 "[KLS] %s(): old was NULL.\n",
1621 "[KLS] " KLS_Loc_Fmt
"%s(): old was NULL.\n",
1627 if (old_count < 0) {
1628#ifndef KOLISEO_HAS_LOCATE
1630 "[KLS] %s(): old_count [%td] was < 0.\n",
1635 "[KLS] " KLS_Loc_Fmt
"%s(): old_count [%td] was < 0.\n",
1642 if (new_count < 0) {
1643#ifndef KOLISEO_HAS_LOCATE
1645 "[KLS] %s(): new_count [%td] was < 0.\n",
1650 "[KLS] " KLS_Loc_Fmt
"%s(): new_count [%td] was < 0.\n",
1658#ifndef KOLISEO_HAS_LOCATE
1660 "[KLS] %s(): size [%td] was < 1.\n",
1665 "[KLS] " KLS_Loc_Fmt
"%s(): size [%td] was < 1.\n",
1673#ifndef KOLISEO_HAS_LOCATE
1675 "[KLS] %s(): align [%td] was < 1.\n",
1680 "[KLS] " KLS_Loc_Fmt
"%s(): align [%td] was < 1.\n",
1687 if (! ((align & (align - 1)) == 0)) {
1688#ifndef KOLISEO_HAS_LOCATE
1690 "[KLS] %s(): align [%td] was not a power of 2.\n",
1695 "[KLS] " KLS_Loc_Fmt
"%s(): align [%td] was not a power of 2.\n",
1703 fprintf(stderr,
"%s(): kls has an active temp\n", __func__);
1706 size_t old_size = old_count * size;
1707 size_t new_size = new_count * size;
1709 if (new_ptr && old_size > 0) {
1710 memcpy(new_ptr, old, old_size < new_size ? old_size : new_size);
1726#ifndef KOLISEO_HAS_LOCATE
1728 ptrdiff_t old_count, ptrdiff_t new_count)
1730void *kls_temp_repush_dbg(
Koliseo_Temp *t_kls,
void* old, ptrdiff_t size, ptrdiff_t align,
1731 ptrdiff_t old_count, ptrdiff_t new_count, Koliseo_Loc loc)
1735#ifndef KOLISEO_HAS_LOCATE
1737 "[KLS] %s(): old was NULL.\n",
1741 "[KLS] " KLS_Loc_Fmt
"%s(): old was NULL.\n",
1747 if (old_count < 0) {
1748#ifndef KOLISEO_HAS_LOCATE
1750 "[KLS] %s(): old_count [%td] was < 0.\n",
1755 "[KLS] " KLS_Loc_Fmt
"%s(): old_count [%td] was < 0.\n",
1762 if (new_count < 0) {
1763#ifndef KOLISEO_HAS_LOCATE
1765 "[KLS] %s(): new_count [%td] was < 0.\n",
1770 "[KLS] " KLS_Loc_Fmt
"%s(): new_count [%td] was < 0.\n",
1778#ifndef KOLISEO_HAS_LOCATE
1780 "[KLS] %s(): size [%td] was < 1.\n",
1785 "[KLS] " KLS_Loc_Fmt
"%s(): size [%td] was < 1.\n",
1793#ifndef KOLISEO_HAS_LOCATE
1795 "[KLS] %s(): align [%td] was < 1.\n",
1800 "[KLS] " KLS_Loc_Fmt
"%s(): align [%td] was < 1.\n",
1807 if (! ((align & (align - 1)) == 0)) {
1808#ifndef KOLISEO_HAS_LOCATE
1810 "[KLS] %s(): align [%td] was not a power of 2.\n",
1815 "[KLS] " KLS_Loc_Fmt
"%s(): align [%td] was not a power of 2.\n",
1822 size_t old_size = old_count * size;
1823 size_t new_size = new_count * size;
1825 if (new_ptr && old_size > 0) {
1826 memcpy(new_ptr, old, old_size < new_size ? old_size : new_size);
1839 fprintf(stderr,
"print_kls_2file(): fp was NULL.\n");
1843 fprintf(fp,
"[KLS] kls was NULL.\n");
1850 fprintf(fp,
"\n[KLS] Size: { %td }\n", kls->
size);
1851 char human_size[200];
1852 char curr_size[200];
1854 fprintf(fp,
"[KLS] Size (Human): { %s }\n", human_size);
1856 fprintf(fp,
"[KLS] Used (Human): { %s }\n", curr_size);
1857 fprintf(fp,
"[KLS] Offset: { %td }\n", kls->
offset);
1858 fprintf(fp,
"[KLS] Prev_Offset: { %td }\n", kls->
prev_offset);
1870 fprintf(stderr,
"[ERROR] [%s()]: Passed Koliseo was NULL.\n", __func__);
1884 fprintf(stderr,
"print_temp_kls_2file(): fp was NULL.\n");
1887 if (t_kls == NULL) {
1888 fprintf(fp,
"[KLS_T] t_kls was NULL.");
1889 }
else if (t_kls->
kls == NULL) {
1890 fprintf(fp,
"[KLS_T] [%s()]: Referred Koliseo was NULL.\n", __func__);
1894 fprintf(fp,
"\n[KLS_T] Temp Size: { %td }\n",
1896 fprintf(fp,
"\n[KLS_T] Refer Size: { %td }\n", kls->
size);
1897 char human_size[200];
1898 char curr_size[200];
1900 sizeof(human_size));
1901 fprintf(fp,
"[KLS_T] Temp Size Human: { %s }\n", human_size);
1903 fprintf(fp,
"[KLS_T] Refer Size Human: { %s }\n", human_size);
1905 fprintf(fp,
"[KLS_T] Inner Used (Human): { %s }\n", curr_size);
1907 fprintf(fp,
"[KLS_T] Temp Used (Human): { %s }\n", curr_size);
1908 fprintf(fp,
"[KLS_T] Inner Offset: { %td }\n", kls->
offset);
1909 fprintf(fp,
"[KLS_T] Temp Offset: { %td }\n", t_kls->
offset);
1910 fprintf(fp,
"[KLS_T] Inner Prev_Offset: { %td }\n", kls->
prev_offset);
1911 fprintf(fp,
"[KLS_T] Temp Prev_Offset: { %td }\n\n",
1934 const char *units[] =
1935 {
"bytes",
"KB",
"MB",
"GB",
"TB",
"PB",
"EB",
"ZB",
"YB" };
1936 const int numUnits =
sizeof(units) /
sizeof(units[0]);
1939 double sizeValue = (double)size;
1941 while (sizeValue >= 1000 && unitIndex < numUnits - 1) {
1946 snprintf(outputBuffer, bufferSize,
"%.2f %s", sizeValue, units[unitIndex]);
1957 fprintf(stderr,
"[ERROR] [%s()]: Passed Koliseo was NULL.\n", __func__);
1962 kls->
offset =
sizeof(*kls);
1975#ifdef KLS_DEBUG_CORE
1976 kls_log(kls,
"KLS",
"API Level { %i } -> Cleared offsets for KLS.",
1989 fprintf(stderr,
"[ERROR] [%s()]: Passed Koliseo was NULL.\n", __func__);
1995#ifdef KLS_DEBUG_CORE
1997 "API Level { %i } -> KLS had an active Koliseo_Temp.",
2008 k->extension_data = NULL;
2012 current->
next = NULL;
2014#ifdef KLS_DEBUG_CORE
2015 kls_log(current,
"KLS",
"API Level { %i } -> Freeing KLS.",
2020#ifdef KLS_DEBUG_CORE
2021 kls_log(current,
"KLS",
"Closing kls log file. Path: {\"%s\"}.",
2024 int close_res = fclose(current->
conf.
log_fp);
2025 if (close_res != 0) {
2027 "[ERROR] %s(): Failed fclose() on log_fp. Path: {\"%s\"}.",
2033 "[INFO] %s(): kls->conf.log_fp is %s. Not closing it.\n",
2035 (current->
conf.
log_fp == stdout ?
"stdout" :
"stderr"));
2040 "[ERROR] %s(): free function was NULL.\n", __func__);
2055#ifndef KOLISEO_HAS_LOCATE
2062 fprintf(stderr,
"[ERROR] [%s()]: Passed Koliseo was NULL.\n", __func__);
2066 while (current->
next != NULL) {
2067 current = current->
next;
2071 "[ERROR] [%s()]: Passed Koliseo->has_temp is not 0. {%i}\n",
2073#ifdef KLS_DEBUG_CORE
2074 kls_log(current,
"ERROR",
"[%s()]: Passed Koliseo->has_temp != 0 . {%i}",
2080 ptrdiff_t off = current->
offset;
2086#ifdef KLS_DEBUG_CORE
2092 current->
t_kls = tmp;
2097#ifdef KLS_DEBUG_CORE
2098 kls_log(current,
"KLS",
"Prepared new Temp KLS.");
2109 if (tmp_kls == NULL) {
2110 fprintf(stderr,
"[ERROR] [%s()]: Passed Koliseo_Temp was NULL.\n",
2116 if (kls_ref == NULL) {
2117 fprintf(stderr,
"[ERROR] [%s()]: Referred Koliseo was NULL.\n",
2127#ifdef KLS_DEBUG_CORE
2128 kls_log(kls_ref,
"KLS",
"Ended Temp KLS.");
2132#if defined(__SANITIZE_ADDRESS__)
2133 ptrdiff_t old_offset = tmp_kls->
kls->
offset;
2134 ptrdiff_t new_offset = tmp_kls->
offset;
2141 if (to_free != NULL) {
2154#ifdef KOLISEO_HAS_EXPER
2166 fprintf(stderr,
"[ERROR] [%s()]: Passed Koliseo was NULL.\n", __func__);
2169 ptrdiff_t padding = -kls->
offset & (align - 1);
2170 if (count > PTRDIFF_MAX / size
2171 || (kls->
size + kls->
offset) < (size * count)) {
2172 fprintf(stderr,
"[KLS] Failed %s() call.\n", __func__);
2176 char *p = kls->
data + kls->
offset - padding - size * count;
2178 kls->
offset -= padding + size * count;
2179#ifdef KLS_DEBUG_CORE
2180 kls_log(kls,
"KLS",
"Popped (%td) for KLS. Curr offset: { %p }",
2200 if (t_kls == NULL) {
2201 fprintf(stderr,
"[ERROR] [%s()]: Passed Koliseo_Temp was NULL.\n",
2207 fprintf(stderr,
"[ERROR] [%s()]: Referred Koliseo was NULL.\n",
2211 ptrdiff_t padding = -kls->
offset & (align - 1);
2212 if (count > PTRDIFF_MAX / size
2213 || (kls->
size + kls->
offset) < (size * count)) {
2214 fprintf(stderr,
"[KLS] Failed %s() call.\n", __func__);
2218 char *p = kls->
data + kls->
offset - padding - size * count;
2220 kls->
offset -= padding + size * count;
2221#ifdef KLS_DEBUG_CORE
2222 kls_log(kls,
"KLS",
"Popped (%td) for Temp_KLS. Curr offset: { %p }.", size, kls->
data + kls->
offset);
2251 char** strings = NULL;
2253 for (
int i=0; i < count; i++) {
2280 char** strings = NULL;
2282 for (
int i=0; i < count; i++) {
#define KLS_DEFAULT_HOOKS
Definition kls_region.h:162
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:846
Koliseo * kls_new(ptrdiff_t size)
Takes a ptrdiff_t size.
Definition koliseo.c:654
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:2236
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:2197
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:2056
void print_dbg_temp_kls(const Koliseo_Temp *t_kls)
Prints header fields from the passed Koliseo_Temp pointer, to stderr.
Definition koliseo.c:1920
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:1727
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:947
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:1881
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:2265
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:793
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:494
char * kls_vsprintf(Koliseo *kls, const char *fmt, va_list args)
Definition koliseo.c:1467
void kls_temp_end(Koliseo_Temp *tmp_kls)
Ends passed Koliseo_Temp pointer.
Definition koliseo.c:2107
void kls_dbg_features(void)
Prints enabled Koliseo features to stderr.
Definition koliseo.c:234
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:2249
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:1520
void print_dbg_kls(const Koliseo *kls)
Prints header fields from the passed Koliseo pointer, to stderr.
Definition koliseo.c:1867
const char * string_koliseo_version(void)
Returns the constant string representing current version for Koliseo.
Definition koliseo.c:58
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:1607
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:1101
char * kls_temp_vsprintf(Koliseo_Temp *kls_t, const char *fmt, va_list args)
Definition koliseo.c:1553
ptrdiff_t kls_get_pos(const Koliseo *kls)
Returns the current offset (position of pointer bumper) for the passed Koliseo.
Definition koliseo.c:287
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)
Takes a ptrdiff_t size, an allocation function pointer and a free function pointer,...
Definition koliseo.c:881
#define KLS_ASAN_UNPOISON(addr, size)
Definition koliseo.c:78
void kls_free(Koliseo *kls)
Calls kls_clear() on the passed Koliseo pointer and the frees the actual Koliseo.
Definition koliseo.c:1986
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:177
Koliseo * kls_new_dbg_ext(ptrdiff_t size, KLS_Hooks ext_handlers, void *user)
Takes a ptrdiff_t size.
Definition koliseo.c:930
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:1579
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:2278
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:1362
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:915
KLS_Push_Error kls__check_available(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:1196
#define KLS_ASAN_POISON(addr, size)
Definition koliseo.c:77
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:1385
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:630
Koliseo * kls_new_dbg(ptrdiff_t size)
Takes a ptrdiff_t size and returns a pointer to the prepared Koliseo.
Definition koliseo.c:962
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:829
char * kls_sprintf(Koliseo *kls, const char *fmt,...)
Takes a Koliseo pointer, and a format cstring, plus varargs.
Definition koliseo.c:1492
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:863
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:2163
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)
Takes a ptrdiff_t size, a KLS_Conf to configure the new Koliseo, an allocation function pointer and a...
Definition koliseo.c:675
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:111
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:225
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:153
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)
Handles a KLS_Push_Result.
Definition koliseo.c:305
Koliseo * kls_new_alloc_ext(ptrdiff_t size, kls_alloc_func alloc_func, kls_free_func free_func, KLS_Hooks ext_handlers, void *user)
Takes a ptrdiff_t size and a function pointer to the allocation function.
Definition koliseo.c:540
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:1836
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)
Takes a ptrdiff_t size, a filepath for the trace output file, an allocation function pointer and a fr...
Definition koliseo.c:757
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:977
void kls_clear(Koliseo *kls)
Resets the offset field for the passed Koliseo pointer.
Definition koliseo.c:1954
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:1418
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:1932
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:91
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:704
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:1256
int int_koliseo_version(void)
Returns the constant int representing current version for Koliseo.
Definition koliseo.c:67
Koliseo * kls_new_traced_ext(ptrdiff_t size, const char *output_path, KLS_Hooks ext_handlers, void *user)
Takes a ptrdiff_t size and a filepath for the trace output file.
Definition koliseo.c:810
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:737
Koliseo * kls_new_conf_ext(ptrdiff_t size, KLS_Conf conf, KLS_Hooks ext_handlers, void *user)
Takes a ptrdiff_t size and a KLS_Conf to configure the new Koliseo.
Definition koliseo.c:721
void kls_free_func(void *)
Used to select a free function for the arena's backing memory.
Definition koliseo.h:96
#define KLS_PUSH_STR_T(kls_temp, cstr)
Macro to request memory for a C string from a Koliseo_Temp.
Definition koliseo.h:644
#define KLS_Stats_Fmt
Defines a format string for KLS_Stats.
Definition koliseo.h:294
#define KLS_PUSH_STR(kls, cstr)
Macro to request memory for a C string from a Koliseo.
Definition koliseo.h:527
#define KLS_Conf_Arg(conf)
Defines a format macro for KLS_Conf args.
Definition koliseo.h:287
#define KLS_DEFAULT_FREEF
Defines the default free function.
Definition koliseo.h:411
#define KLS_DEFAULT_ALLOCF
Defines the default allocation function.
Definition koliseo.h:407
#define KLS_PUSH(kls, type)
Macro used to request memory from a Koliseo.
Definition koliseo.h:564
#define KLS__STRCPY(dest, source)
Macro to copy a C string from a source buffer to a destination buffer.
Definition koliseo.h:748
#define KLS_ALIGNOF
Definition koliseo.h:24
#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:95
#define KLS_MAX(a, b)
Definition koliseo.h:102
#define KLS_STRDUP(kls, source)
Definition koliseo.h:757
KLS_Push_Error
Defines the result for kls__check_available().
Definition koliseo.h:367
@ KLS_PUSH_NEGATIVE_COUNT
Definition koliseo.h:372
@ KLS_PUSH_ZEROCOUNT
Definition koliseo.h:373
@ KLS_PUSH_ALIGN_NOT_POW2
Definition koliseo.h:371
@ KLS_PUSH_WITH_TEMP_ACTIVE
Definition koliseo.h:374
@ KLS_PUSH_OOM
Definition koliseo.h:376
@ KLS_PUSH_PTRDIFF_MAX
Definition koliseo.h:375
@ KLS_PUSH_SIZE_LT1
Definition koliseo.h:369
@ KLS_PUSH_ALIGN_LT1
Definition koliseo.h:370
@ KLS_PUSH_OK
Definition koliseo.h:368
#define KLS_Stats_Arg(stats)
Defines a format macro for KLS_Stats args.
Definition koliseo.h:304
#define KLS_Conf_Fmt
Defines a format string for KLS_Conf.
Definition koliseo.h:281
#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:632
#define KLS_STRDUP_T(t_kls, source)
Definition koliseo.h:767
#define KLS_DEFAULT_ERR_HANDLERS
Definition koliseo.h:182
#define KLS_PUSH_ARR(kls, type, count)
Macro used to request memory for an array of type values from a Koliseo.
Definition koliseo.h:515
Defines flags for Koliseo.
Definition koliseo.h:231
int growable
If set to 1, make the Koliseo grow when a out of memory for a push call.
Definition koliseo.h:238
int verbose_lvl
If > 0, makes the Koliseo try to acquire kls_log_fp from kls_log_filepath.
Definition koliseo.h:233
const char * log_filepath
String representing the path to the Koliseo logfile.
Definition koliseo.h:235
FILE * log_fp
FILE pointer used by the Koliseo to print its kls_log() output.
Definition koliseo.h:234
int allow_zerocount_push
If set to 1, make the Koliseo accept push calls with a count of 0.
Definition koliseo.h:237
int collect_stats
If set to 1, make the Koliseo collect performance stats.
Definition koliseo.h:232
KLS_Err_Handlers err_handlers
Used to pass custom error handlers for push calls.
Definition koliseo.h:239
int 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
Defines the handlers used for errors in push calls.
Definition koliseo.h:175
KLS_OOM_Handler * OOM_handler
Pointer to handler for Out-Of-Memory errors in push calls.
Definition koliseo.h:176
KLS_ZEROCOUNT_Handler * ZEROCOUNT_handler
Pointer to handler for zero-count errors in push calls.
Definition koliseo.h:178
KLS_PTRDIFF_MAX_Handler * PTRDIFF_MAX_handler
Pointer to handler for count > (PTRDIFF_MAX / size) errors in push calls.
Definition koliseo.h:177
KLS_hook_on_temp_start * on_temp_start_handler
Used to pass custom start handler for kls_temp_start calls.
Definition koliseo.h:203
KLS_hook_on_free * on_free_handler
Used to pass custom free handler for kls_free calls.
Definition koliseo.h:201
KLS_hook_on_temp_free * on_temp_free_handler
Used to pass custom free handler for kls_temp_end calls.
Definition koliseo.h:204
KLS_hook_on_push * on_push_handler
Used to pass custom push handler for kls_push calls.
Definition koliseo.h:202
KLS_hook_on_new * on_new_handler
Used to pass custom new handler for kls_new_alloc calls.
Definition koliseo.h:200
KLS_hook_on_temp_push * on_temp_push_handler
Used to pass custom push handler for kls_temp_push calls.
Definition koliseo.h:205
Defines the result for kls__advance() and kls__temp_advance().
Definition koliseo.h:384
KLS_Push_Error error
Definition koliseo.h:386
void * p
Definition koliseo.h:385
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:259
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_temp_pops
Total POP_T calls done.
Definition koliseo.h:256
Represents a savestate for a Koliseo.
Definition koliseo.h:356
ptrdiff_t offset
Current position of memory pointer.
Definition koliseo.h:358
ptrdiff_t prev_offset
Previous position of memory pointer.
Definition koliseo.h:359
Koliseo * kls
Reference to the actual Koliseo we're saving.
Definition koliseo.h:357
Represents the initialised arena allocator struct.
Definition koliseo.h:317
ptrdiff_t size
Size of data field.
Definition koliseo.h:319
ptrdiff_t offset
Current position of memory pointer.
Definition koliseo.h:320
ptrdiff_t prev_offset
Previous position of memory pointer.
Definition koliseo.h:321
KLS_Conf conf
Contains flags to change the Koliseo behaviour.
Definition koliseo.h:323
struct Koliseo_Temp * t_kls
Points to related active Kolieo_Temp, when has_temp == 1.
Definition koliseo.h:325
KLS_Hooks hooks
Contains handlers for extensions.
Definition koliseo.h:326
char * data
Points to data field.
Definition koliseo.h:318
struct Koliseo * next
Points to the next Koliseo when conf.growable == 1.
Definition koliseo.h:330
void * extension_data
Points to data for extensions.
Definition koliseo.h:327
int has_temp
When == 1, a Koliseo_Temp is currently active on this Koliseo.
Definition koliseo.h:322
KLS_Stats stats
Contains stats for Koliseo performance analysis.
Definition koliseo.h:324
kls_free_func * free_func
Points to the free function for the arena's backing memory.
Definition koliseo.h:329