19#ifndef _POSIX_C_SOURCE
20#define _POSIX_C_SOURCE 200809L
28 .block_while_has_temp = 1,
29 .allow_zerocount_push = 0,
34#ifndef KOLISEO_HAS_LOCATE
39 .OOM_handler = &KLS_OOM_default_handler_dbg__,
40 .PTRDIFF_MAX_handler = &KLS_PTRDIFF_MAX_default_handler_dbg__,
41 .ZEROCOUNT_handler = &KLS_ZEROCOUNT_default_handler_dbg__,
53 .worst_pushcall_time = -1,
65 return KOLISEO_API_VERSION_STRING;
74 return KOLISEO_API_VERSION_INT;
77#if defined(__SANITIZE_ADDRESS__)
78#include <sanitizer/asan_interface.h>
79#define KLS_ASAN_POISON(addr, size) __asan_poison_memory_region((addr), (size))
80#define KLS_ASAN_UNPOISON(addr, size) __asan_unpoison_memory_region((addr), (size))
82#define KLS_ASAN_POISON(addr, size) ((void)0)
83#define KLS_ASAN_UNPOISON(addr, size) ((void)0)
95#ifndef KOLISEO_HAS_LOCATE
98void KLS_OOM_default_handler_dbg__(
Koliseo* kls, ptrdiff_t available, ptrdiff_t padding, ptrdiff_t size, ptrdiff_t count, Koliseo_Loc loc)
101#ifndef KOLISEO_HAS_LOCATE
103 "[KLS] Out of memory. size*count [%td] was bigger than available-padding [%td].\n",
104 size * count, available - padding);
107 "[KLS] " KLS_Loc_Fmt
"Out of memory. size*count [%td] was bigger than available-padding [%td].\n",
109 size * count, available - padding);
115#ifndef KOLISEO_HAS_LOCATE
118void KLS_PTRDIFF_MAX_default_handler_dbg__(
struct Koliseo* kls, ptrdiff_t size, ptrdiff_t count, Koliseo_Loc loc)
122#ifndef KOLISEO_HAS_LOCATE
124 "[KLS] count [%td] was bigger than PTRDIFF_MAX/size [%li].\n",
125 count, PTRDIFF_MAX / size);
128 "[KLS] " KLS_Loc_Fmt
"count [%td] was bigger than PTRDIFF_MAX/size [%li].\n",
130 count, PTRDIFF_MAX / size);
133#ifndef KOLISEO_HAS_LOCATE
135 "[KLS] count [%td] was bigger than PTRDIFF_MAX/size [%lli].\n",
136 count, PTRDIFF_MAX / size);
139 "[KLS] " KLS_Loc_Fmt
"count [%td] was bigger than PTRDIFF_MAX/size [%lli].\n",
141 count, PTRDIFF_MAX / size);
157#ifndef KOLISEO_HAS_LOCATE
160void KLS_ZEROCOUNT_default_handler_dbg__(
Koliseo* kls, ptrdiff_t available, ptrdiff_t padding, ptrdiff_t size, Koliseo_Loc loc)
163#ifndef KOLISEO_HAS_LOCATE
165 "[KLS] Doing a zero-count push. size [%td] padding [%td] available [%td].\n",
166 size, padding, available);
169 "[KLS] " KLS_Loc_Fmt
"Doing a zero-count push. size [%td] padding [%td] available [%td].\n",
171 size, padding, available);
196#ifndef KOLISEO_HAS_LOCATE
206#ifndef KOLISEO_HAS_LOCATE
216#ifndef KOLISEO_HAS_LOCATE
230KLS_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)
233 return kls_conf_init_handled(collect_stats, verbose_lvl, block_while_has_temp, allow_zerocount_push, growable, log_fp, log_filepath, err_handlers);
241#ifdef KOLISEO_HAS_LOCATE
242 bool kls_locate =
true;
244 bool kls_locate =
false;
247 bool kls_debug =
true;
249 bool kls_debug =
false;
251#ifdef KOLISEO_HAS_EXPER
252 bool kls_exper =
true;
254 bool kls_exper =
false;
261 int total_enabled = 0;
262 for (
int i=0; i<3; i++) {
267 fprintf(stderr,
"[KLS] Enabled features: {");
268 if (total_enabled == 0) {
269 fprintf(stderr,
"none}\n");
273 fprintf(stderr,
"debug%s", (total_enabled > 1 ?
", " :
""));
277 fprintf(stderr,
"locate%s", (total_enabled > 1 ?
", " :
""));
281 fprintf(stderr,
"exper");
283 fprintf(stderr,
"}\n");
309#ifndef KOLISEO_HAS_LOCATE
312void* 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)
315 if (!kls)
return NULL;
317 while (current->
next != NULL) {
318 current = current->
next;
321 const ptrdiff_t available = current->
size - current->
offset;
328#ifndef KOLISEO_HAS_LOCATE
330 "[KLS] %s(): size [%td] was < 1.\n",
335 "[KLS] " KLS_Loc_Fmt
"%s(): size [%td] was < 1.\n",
343#ifndef KOLISEO_HAS_LOCATE
345 "[KLS] %s(): align [%td] was < 1.\n",
350 "[KLS] " KLS_Loc_Fmt
"%s(): align [%td] was < 1.\n",
358#ifndef KOLISEO_HAS_LOCATE
360 "[KLS] %s(): align [%td] was not a power of 2.\n",
365 "[KLS] " KLS_Loc_Fmt
"%s(): align [%td] was not a power of 2.\n",
373#ifndef KOLISEO_HAS_LOCATE
375 "[KLS] %s(): count [%td] was < 0.\n",
380 "[KLS] " KLS_Loc_Fmt
"%s(): count [%td] was < 0.\n",
389#ifndef KOLISEO_HAS_LOCATE
395#ifndef KOLISEO_HAS_LOCATE
397 "[KLS] %s(): Doing a zero-count push. size [%td] padding [%td] available [%td].\n",
399 size, padding, available);
402 "[KLS] " KLS_Loc_Fmt
"%s(): Doing a zero-count push. size [%td] padding [%td] available [%td].\n",
405 size, padding, available);
413#ifndef KOLISEO_HAS_LOCATE
414 fprintf(stderr,
"[ERROR] [%s()]: Passed Koliseo has an open Koliseo_Temp session.\n", caller_name);
416 fprintf(stderr,
"[ERROR] " KLS_Loc_Fmt
"[%s()]: Passed Koliseo has an open Koliseo_Temp session.\n", KLS_Loc_Arg(loc), caller_name);
417 kls_log(kls,
"ERROR", KLS_Loc_Fmt
"[%s()]: Passed Koliseo has an open Koliseo_Temp session.", KLS_Loc_Arg(loc), caller_name);
424#ifndef KOLISEO_HAS_LOCATE
431#ifndef KOLISEO_HAS_LOCATE
433 "[KLS] %s(): count [%td] was bigger than PTRDIFF_MAX/size [%li].\n",
435 count, PTRDIFF_MAX / size);
438 "[KLS] " KLS_Loc_Fmt
"%s(): count [%td] was bigger than PTRDIFF_MAX/size [%li].\n",
441 count, PTRDIFF_MAX / size);
444#ifndef KOLISEO_HAS_LOCATE
446 "[KLS] %s(): count [%td] was bigger than PTRDIFF_MAX/size [%lli].\n",
448 count, PTRDIFF_MAX / size);
451 "[KLS] " KLS_Loc_Fmt
"%s(): count [%td] was bigger than PTRDIFF_MAX/size [%lli].\n",
454 count, PTRDIFF_MAX / size);
462#ifndef KOLISEO_HAS_LOCATE
468#ifndef KOLISEO_HAS_LOCATE
470 "[KLS] %s(): Out of memory. size*count [%td] was bigger than available-padding [%td].\n",
472 size * count, available - padding);
475 "[KLS] " KLS_Loc_Fmt
"%s(): Out of memory. size*count [%td] was bigger than available-padding [%td].\n",
478 size * count, available - padding);
484 fprintf(stderr,
"[KLS] %s(): unexpected error code [%i]\n", __func__, r.
error);
502 fprintf(stderr,
"[KLS] %s(): Passed kls was NULL.\n", __func__);
508 va_start(args, format);
511 "[KLS] %s(): Failed opening file to print logs.\n",
514 time_t now = time(0);
515 const struct tm *mytime = localtime(&now);
516 char timeheader[500];
517 if (strftime(timeheader,
sizeof timeheader,
"%X", mytime)) {
518 fprintf(fp,
"[%-10.10s] [%s] [", tag, timeheader);
519 vfprintf(fp, format, args);
544#ifndef KOLISEO_HAS_LOCATE
550 if (size < (ptrdiff_t)
sizeof(
Koliseo)) {
551#ifndef KOLISEO_HAS_LOCATE
553 "[ERROR] at %s(): invalid requested kls size (%td). Min accepted is: (%td).\n",
554 __func__, size, (ptrdiff_t)
sizeof(
Koliseo));
557 "[ERROR] " KLS_Loc_Fmt
"%s(): invalid requested kls size (%td). Min accepted is: (%td).\n",
558 KLS_Loc_Arg(loc), __func__, size, (ptrdiff_t)
sizeof(
Koliseo));
563 void *p = alloc_func(size);
572 kls->
offset =
sizeof(*kls);
582 kls->
hooks = ext_handlers;
591 kls_log(kls,
"KLS",
"API Level { %i } -> Allocated (%s) for new KLS.",
593 kls_log(kls,
"KLS",
"KLS offset: { %p }.", kls);
594 kls_log(kls,
"KLS",
"Allocation begin offset: { %p }.",
603#ifndef KOLISEO_HAS_LOCATE
604 fprintf(stderr,
"[KLS] Failed %s() call.\n", __func__);
606 fprintf(stderr,
"[KLS] " KLS_Loc_Fmt
"Failed %s() call.\n", KLS_Loc_Arg(loc), __func__);
634#ifndef KOLISEO_HAS_LOCATE
640#ifndef KOLISEO_HAS_LOCATE
683 bool conf_res = kls_set_conf(k, conf);
686 "[ERROR] [%s()]: Failed to set config for new Koliseo.\n",
765#ifndef KLS_DEBUG_CORE
767 "[WARN] %s(): KLS_DEBUG_CORE is not defined. No tracing allowed.\n",
771 .collect_stats = 1,.verbose_lvl =
772 1,.log_filepath = output_path,
773#ifndef KOLISEO_HAS_LOCATE
777 .err_handlers.OOM_handler = (err_handlers.
OOM_handler != NULL ? err_handlers.
OOM_handler : &KLS_OOM_default_handler_dbg__),
888#ifndef KLS_DEBUG_CORE
890 "[WARN] %s(): KLS_DEBUG_CORE is not defined. No debugging support.\n",
894 .collect_stats = 1,.verbose_lvl = 0,
895#ifndef KOLISEO_HAS_LOCATE
899 .err_handlers.OOM_handler = ( err_handlers.
OOM_handler != NULL ? err_handlers.
OOM_handler : &KLS_OOM_default_handler_dbg__),
996 fprintf(stderr,
"[ERROR] [%s()]: Passed Koliseo was NULL.\n", __func__);
1004#ifdef KLS_DEBUG_CORE
1005#ifdef KLS_SETCONF_DEBUG
1007 "[%s()]: Preliminary set of conf.log_fp to stderr.",
1015 "[ERROR] at %s(): passed OOM_handler is NULL. Using default.\n",
1017#ifdef KLS_DEBUG_CORE
1018#ifdef KLS_SETCONF_DEBUG
1020 "[%s()]: Passed OOM_handler was NULL, using default.",
1024#ifndef KOLISEO_HAS_LOCATE
1033 "[ERROR] at %s(): passed PTRDIFF_MAX_handler is NULL. Using default.\n",
1035#ifdef KLS_DEBUG_CORE
1036#ifdef KLS_SETCONF_DEBUG
1038 "[%s()]: Passed PTRDIFF_MAX_handler was NULL, using default.",
1042#ifndef KOLISEO_HAS_LOCATE
1049#ifndef KLS_DEBUG_CORE
1052 "[WARN] [%s()]: KLS_DEBUG_CORE is not defined. Stats may not be collected in full.\n",
1059#ifdef KLS_DEBUG_CORE
1060#ifdef KLS_SETCONF_DEBUG
1062 "[%s()]: kls->conf.log_fp was not NULL. Overriding it.",
1068 FILE *log_fp = NULL;
1072 "[ERROR] [%s()]: Failed opening logfile at {\"%s\"} [write].\n",
1076 fprintf(log_fp,
"%s",
"");
1082 "[ERROR] [%s()]: Failed opening logfile at {\"%s\"} [append].\n",
1092static bool kls__try_grow(
Koliseo* kls, ptrdiff_t needed);
1105#ifndef KOLISEO_HAS_LOCATE
1108KLS_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)
1111#ifdef KLS_DEBUG_CORE
1113 struct timespec start_time, end_time;
1114 clock_gettime(CLOCK_MONOTONIC, &start_time);
1116 LARGE_INTEGER start_time, end_time, frequency;
1117 QueryPerformanceFrequency(&frequency);
1118 QueryPerformanceCounter(&start_time);
1123 fprintf(stderr,
"[ERROR] [%s()]: Passed Koliseo was NULL.\n", caller_name);
1133#ifndef KOLISEO_HAS_LOCATE
1136 KLS_Push_Error res = kls__check_available_dbg(kls, size, align, count, __func__, loc);
1145 while (current->
next != NULL) {
1146 current = current->
next;
1148 const ptrdiff_t pad = -current->
offset & (align - 1);
1150 char *p = current->
data + current->
offset + pad;
1152 current->
offset += pad + size * count;
1160#ifdef KLS_DEBUG_CORE
1161 kls_log(current,
"KLS",
"Pushed zeroes on KLS, size (%s). Curr offset: { %p }.", h_size, current->
data + current->
offset);
1164 clock_gettime(CLOCK_MONOTONIC, &end_time);
1165 double elapsed_time =
1166 (end_time.tv_sec - start_time.tv_sec) + (end_time.tv_nsec -
1167 start_time.tv_nsec) / 1e9;
1169 QueryPerformanceCounter(&end_time);
1170 double elapsed_time =
1171 (double)(end_time.QuadPart -
1172 start_time.QuadPart) / frequency.QuadPart;
1200#ifndef KOLISEO_HAS_LOCATE
1203KLS_Push_Error kls__check_available_dbg(
Koliseo* kls, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count,
const char* caller_name, Koliseo_Loc loc)
1206 assert(kls != NULL);
1207 assert(caller_name != NULL);
1217 if (! ((align & (align - 1)) == 0)) {
1221 while (current->
next != NULL) {
1222 current = current->
next;
1224 const ptrdiff_t available = current->
size - current->
offset;
1225 const ptrdiff_t padding = -current->
offset & (align - 1);
1230#ifdef KLS_DEBUG_CORE
1231 kls_log(current,
"DEBUG",
"Accepting zero-count push: conf.allow_zerocount_push was 1");
1236 if (count > PTRDIFF_MAX / size || available - padding < size * count) {
1237 if (count > PTRDIFF_MAX / size) {
1240 if (current->
conf.
growable == 1 && kls__try_grow(current, size + count + padding)) {
1260#ifndef KOLISEO_HAS_LOCATE
1263KLS_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)
1266#ifdef KLS_DEBUG_CORE
1268 struct timespec start_time, end_time;
1269 clock_gettime(CLOCK_MONOTONIC, &start_time);
1271 LARGE_INTEGER start_time, end_time, frequency;
1272 QueryPerformanceFrequency(&frequency);
1273 QueryPerformanceCounter(&start_time);
1277 if (kls_t == NULL) {
1278 fprintf(stderr,
"[ERROR] [%s()]: Passed Koliseo_Temp was NULL.\n",
1284 fprintf(stderr,
"[ERROR] [%s()]: Referred Koliseo was NULL.\n",
1288#ifndef KOLISEO_HAS_LOCATE
1291 KLS_Push_Error res = kls__check_available_dbg(kls, size, align, count, __func__, loc);
1300 while (current->
next != NULL) {
1301 current = current->
next;
1303 ptrdiff_t pad = -current->
offset & (align - 1);
1304 char *p = current->
data + current->
offset + pad;
1307 current->
offset += pad + size * count;
1315#ifdef KLS_DEBUG_CORE
1318 clock_gettime(CLOCK_MONOTONIC, &end_time);
1319 double elapsed_time =
1320 (end_time.tv_sec - start_time.tv_sec) + (end_time.tv_nsec -
1321 start_time.tv_nsec) / 1e9;
1323 QueryPerformanceCounter(&end_time);
1324 double elapsed_time =
1325 (double)(end_time.QuadPart -
1326 start_time.QuadPart) / frequency.QuadPart;
1332 kls_log(current,
"KLS",
"Pushed zeroes on Temp_KLS, size (%s). Curr offset: { %p }.", h_size, current->
data + current->
offset);
1343bool kls__try_grow(
Koliseo* kls, ptrdiff_t needed)
1345 assert(kls->
next == NULL);
1346 ptrdiff_t new_size =
KLS_MAX(kls->
size * 2, needed);
1351 kls_log(kls,
"DEBUG",
"%s(): growing Koliseo, new size: {%td}", __func__, new_size);
1352 if (!new_kls)
return false;
1353 kls->
next = new_kls;
1369 ptrdiff_t padding = 0;
1370#ifndef KOLISEO_HAS_LOCATE
1374 KLS_Push_Result res = kls__advance_dbg(kls, size, align, count, &padding, __func__, KLS_HERE);
1375 return kls__handle_push_result_dbg(kls, res, size, align, count, padding, __func__, KLS_HERE);
1389#ifndef KOLISEO_HAS_LOCATE
1393void *kls_push_zero_dbg(
Koliseo *kls, ptrdiff_t size, ptrdiff_t align,
1394 ptrdiff_t count, Koliseo_Loc loc)
1397 ptrdiff_t padding = 0;
1398#ifndef KOLISEO_HAS_LOCATE
1402 KLS_Push_Result res = kls__advance_dbg(kls, size, align, count, &padding, __func__, loc);
1403 void* p = kls__handle_push_result_dbg(kls, res, size, align, count, padding, __func__, loc);
1405 if (!p)
return NULL;
1407 memset(p, 0, size * count);
1422#ifndef KOLISEO_HAS_LOCATE
1426void *kls_push_zero_ext_dbg(
Koliseo *kls, ptrdiff_t size, ptrdiff_t align,
1427 ptrdiff_t count, Koliseo_Loc loc)
1431 ptrdiff_t padding = 0;
1432#ifndef KOLISEO_HAS_LOCATE
1436 KLS_Push_Result res = kls__advance_dbg(kls, size, align, count, &padding, __func__, loc);
1437 void* p = kls__handle_push_result_dbg(kls, res, size, align, count, padding, __func__, loc);
1439 if (!p)
return NULL;
1441 memset(p, 0, size * count);
1444 while (current->
next != NULL) {
1445 current = current->
next;
1471#ifndef KOLISEO_HAS_LOCATE
1474char* kls_vsprintf_dbg(
Koliseo* kls, Koliseo_Loc loc,
const char* fmt, va_list args)
1478 va_copy(args_copy, args);
1479 int len = vsnprintf(NULL, 0, fmt, args);
1480#ifndef KOLISEO_HAS_LOCATE
1483 char* str = kls_push_zero_ext_dbg(kls,
sizeof(
char),
KLS_ALIGNOF(
char), len+1, loc);
1485 vsnprintf(str, len+1, fmt, args_copy);
1496#ifndef KOLISEO_HAS_LOCATE
1499char* kls_sprintf_dbg(
Koliseo* kls, Koliseo_Loc loc,
const char* fmt, ...)
1503 va_start(args, fmt);
1504#ifndef KOLISEO_HAS_LOCATE
1507 char* str = kls_vsprintf_dbg(kls, loc, fmt, args);
1524#ifndef KOLISEO_HAS_LOCATE
1526 ptrdiff_t align, ptrdiff_t count)
1528void *kls_temp_push_zero_ext_dbg(
Koliseo_Temp *t_kls, ptrdiff_t size,
1529 ptrdiff_t align, ptrdiff_t count, Koliseo_Loc loc)
1533 ptrdiff_t padding = 0;
1535#ifndef KOLISEO_HAS_LOCATE
1538 KLS_Push_Result res = kls__temp_advance_dbg(t_kls, size, align, count, &padding, __func__, loc);
1540 if (res.
error)
return NULL;
1542 memset(res.
p, 0, size * count);
1546 while (current->
next != NULL) {
1547 current = current->
next;
1557#ifndef KOLISEO_HAS_LOCATE
1560char* kls_temp_vsprintf_dbg(
Koliseo_Temp* kls_t, Koliseo_Loc loc,
const char* fmt, va_list args)
1564 va_copy(args_copy, args);
1565 int len = vsnprintf(NULL, 0, fmt, args);
1566#ifndef KOLISEO_HAS_LOCATE
1569 char* str = kls_temp_push_zero_ext_dbg(kls_t,
sizeof(
char),
KLS_ALIGNOF(
char), len+1, loc);
1571 vsnprintf(str, len+1, fmt, args_copy);
1583#ifndef KOLISEO_HAS_LOCATE
1586char* kls_temp_sprintf_dbg(
Koliseo_Temp* kls_t, Koliseo_Loc loc,
const char* fmt, ...)
1590 va_start(args, fmt);
1591#ifndef KOLISEO_HAS_LOCATE
1594 char* str = kls_temp_vsprintf_dbg(kls_t, loc, fmt, args);
1611#ifndef KOLISEO_HAS_LOCATE
1613 ptrdiff_t old_count, ptrdiff_t new_count)
1615void *kls_repush_dbg(
Koliseo *kls,
void* old, ptrdiff_t size, ptrdiff_t align,
1616 ptrdiff_t old_count, ptrdiff_t new_count, Koliseo_Loc loc)
1620#ifndef KOLISEO_HAS_LOCATE
1622 "[KLS] %s(): old was NULL.\n",
1626 "[KLS] " KLS_Loc_Fmt
"%s(): old was NULL.\n",
1632 if (old_count < 0) {
1633#ifndef KOLISEO_HAS_LOCATE
1635 "[KLS] %s(): old_count [%td] was < 0.\n",
1640 "[KLS] " KLS_Loc_Fmt
"%s(): old_count [%td] was < 0.\n",
1647 if (new_count < 0) {
1648#ifndef KOLISEO_HAS_LOCATE
1650 "[KLS] %s(): new_count [%td] was < 0.\n",
1655 "[KLS] " KLS_Loc_Fmt
"%s(): new_count [%td] was < 0.\n",
1663#ifndef KOLISEO_HAS_LOCATE
1665 "[KLS] %s(): size [%td] was < 1.\n",
1670 "[KLS] " KLS_Loc_Fmt
"%s(): size [%td] was < 1.\n",
1678#ifndef KOLISEO_HAS_LOCATE
1680 "[KLS] %s(): align [%td] was < 1.\n",
1685 "[KLS] " KLS_Loc_Fmt
"%s(): align [%td] was < 1.\n",
1692 if (! ((align & (align - 1)) == 0)) {
1693#ifndef KOLISEO_HAS_LOCATE
1695 "[KLS] %s(): align [%td] was not a power of 2.\n",
1700 "[KLS] " KLS_Loc_Fmt
"%s(): align [%td] was not a power of 2.\n",
1708 fprintf(stderr,
"%s(): kls has an active temp\n", __func__);
1711 size_t old_size = old_count * size;
1712 size_t new_size = new_count * size;
1714 if (new_ptr && old_size > 0) {
1715 memcpy(new_ptr, old, old_size < new_size ? old_size : new_size);
1731#ifndef KOLISEO_HAS_LOCATE
1733 ptrdiff_t old_count, ptrdiff_t new_count)
1735void *kls_temp_repush_dbg(
Koliseo_Temp *t_kls,
void* old, ptrdiff_t size, ptrdiff_t align,
1736 ptrdiff_t old_count, ptrdiff_t new_count, Koliseo_Loc loc)
1740#ifndef KOLISEO_HAS_LOCATE
1742 "[KLS] %s(): old was NULL.\n",
1746 "[KLS] " KLS_Loc_Fmt
"%s(): old was NULL.\n",
1752 if (old_count < 0) {
1753#ifndef KOLISEO_HAS_LOCATE
1755 "[KLS] %s(): old_count [%td] was < 0.\n",
1760 "[KLS] " KLS_Loc_Fmt
"%s(): old_count [%td] was < 0.\n",
1767 if (new_count < 0) {
1768#ifndef KOLISEO_HAS_LOCATE
1770 "[KLS] %s(): new_count [%td] was < 0.\n",
1775 "[KLS] " KLS_Loc_Fmt
"%s(): new_count [%td] was < 0.\n",
1783#ifndef KOLISEO_HAS_LOCATE
1785 "[KLS] %s(): size [%td] was < 1.\n",
1790 "[KLS] " KLS_Loc_Fmt
"%s(): size [%td] was < 1.\n",
1798#ifndef KOLISEO_HAS_LOCATE
1800 "[KLS] %s(): align [%td] was < 1.\n",
1805 "[KLS] " KLS_Loc_Fmt
"%s(): align [%td] was < 1.\n",
1812 if (! ((align & (align - 1)) == 0)) {
1813#ifndef KOLISEO_HAS_LOCATE
1815 "[KLS] %s(): align [%td] was not a power of 2.\n",
1820 "[KLS] " KLS_Loc_Fmt
"%s(): align [%td] was not a power of 2.\n",
1827 size_t old_size = old_count * size;
1828 size_t new_size = new_count * size;
1830 if (new_ptr && old_size > 0) {
1831 memcpy(new_ptr, old, old_size < new_size ? old_size : new_size);
1844 fprintf(stderr,
"print_kls_2file(): fp was NULL.\n");
1848 fprintf(fp,
"[KLS] kls was NULL.\n");
1855 fprintf(fp,
"\n[KLS] Size: { %td }\n", kls->
size);
1856 char human_size[200];
1857 char curr_size[200];
1859 fprintf(fp,
"[KLS] Size (Human): { %s }\n", human_size);
1861 fprintf(fp,
"[KLS] Used (Human): { %s }\n", curr_size);
1862 fprintf(fp,
"[KLS] Offset: { %td }\n", kls->
offset);
1863 fprintf(fp,
"[KLS] Prev_Offset: { %td }\n", kls->
prev_offset);
1875 fprintf(stderr,
"[ERROR] [%s()]: Passed Koliseo was NULL.\n", __func__);
1889 fprintf(stderr,
"print_temp_kls_2file(): fp was NULL.\n");
1892 if (t_kls == NULL) {
1893 fprintf(fp,
"[KLS_T] t_kls was NULL.");
1894 }
else if (t_kls->
kls == NULL) {
1895 fprintf(fp,
"[KLS_T] [%s()]: Referred Koliseo was NULL.\n", __func__);
1899 fprintf(fp,
"\n[KLS_T] Temp Size: { %td }\n",
1901 fprintf(fp,
"\n[KLS_T] Refer Size: { %td }\n", kls->
size);
1902 char human_size[200];
1903 char curr_size[200];
1905 sizeof(human_size));
1906 fprintf(fp,
"[KLS_T] Temp Size Human: { %s }\n", human_size);
1908 fprintf(fp,
"[KLS_T] Refer Size Human: { %s }\n", human_size);
1910 fprintf(fp,
"[KLS_T] Inner Used (Human): { %s }\n", curr_size);
1912 fprintf(fp,
"[KLS_T] Temp Used (Human): { %s }\n", curr_size);
1913 fprintf(fp,
"[KLS_T] Inner Offset: { %td }\n", kls->
offset);
1914 fprintf(fp,
"[KLS_T] Temp Offset: { %td }\n", t_kls->
offset);
1915 fprintf(fp,
"[KLS_T] Inner Prev_Offset: { %td }\n", kls->
prev_offset);
1916 fprintf(fp,
"[KLS_T] Temp Prev_Offset: { %td }\n\n",
1939 const char *units[] =
1940 {
"bytes",
"KB",
"MB",
"GB",
"TB",
"PB",
"EB",
"ZB",
"YB" };
1941 const int numUnits =
sizeof(units) /
sizeof(units[0]);
1944 double sizeValue = (double)size;
1946 while (sizeValue >= 1000 && unitIndex < numUnits - 1) {
1951 snprintf(outputBuffer, bufferSize,
"%.2f %s", sizeValue, units[unitIndex]);
1962 fprintf(stderr,
"[ERROR] [%s()]: Passed Koliseo was NULL.\n", __func__);
1967 kls->
offset =
sizeof(*kls);
1980#ifdef KLS_DEBUG_CORE
1981 kls_log(kls,
"KLS",
"API Level { %i } -> Cleared offsets for KLS.",
1994 fprintf(stderr,
"[ERROR] [%s()]: Passed Koliseo was NULL.\n", __func__);
2000#ifdef KLS_DEBUG_CORE
2002 "API Level { %i } -> KLS had an active Koliseo_Temp.",
2013 k->extension_data = NULL;
2017 current->
next = NULL;
2019#ifdef KLS_DEBUG_CORE
2020 kls_log(current,
"KLS",
"API Level { %i } -> Freeing KLS.",
2025#ifdef KLS_DEBUG_CORE
2026 kls_log(current,
"KLS",
"Closing kls log file. Path: {\"%s\"}.",
2029 int close_res = fclose(current->
conf.
log_fp);
2030 if (close_res != 0) {
2032 "[ERROR] %s(): Failed fclose() on log_fp. Path: {\"%s\"}.",
2038 "[INFO] %s(): kls->conf.log_fp is %s. Not closing it.\n",
2040 (current->
conf.
log_fp == stdout ?
"stdout" :
"stderr"));
2045 "[ERROR] %s(): free function was NULL.\n", __func__);
2060#ifndef KOLISEO_HAS_LOCATE
2067 fprintf(stderr,
"[ERROR] [%s()]: Passed Koliseo was NULL.\n", __func__);
2071 while (current->
next != NULL) {
2072 current = current->
next;
2076 "[ERROR] [%s()]: Passed Koliseo->has_temp is not 0. {%i}\n",
2078#ifdef KLS_DEBUG_CORE
2079 kls_log(current,
"ERROR",
"[%s()]: Passed Koliseo->has_temp != 0 . {%i}",
2085 ptrdiff_t off = current->
offset;
2091#ifdef KLS_DEBUG_CORE
2097 current->
t_kls = tmp;
2102#ifdef KLS_DEBUG_CORE
2103 kls_log(current,
"KLS",
"Prepared new Temp KLS.");
2114 if (tmp_kls == NULL) {
2115 fprintf(stderr,
"[ERROR] [%s()]: Passed Koliseo_Temp was NULL.\n",
2121 if (kls_ref == NULL) {
2122 fprintf(stderr,
"[ERROR] [%s()]: Referred Koliseo was NULL.\n",
2132#ifdef KLS_DEBUG_CORE
2133 kls_log(kls_ref,
"KLS",
"Ended Temp KLS.");
2137#if defined(__SANITIZE_ADDRESS__)
2138 ptrdiff_t old_offset = tmp_kls->
kls->
offset;
2139 ptrdiff_t new_offset = tmp_kls->
offset;
2146 if (to_free != NULL) {
2159#ifdef KOLISEO_HAS_EXPER
2171 fprintf(stderr,
"[ERROR] [%s()]: Passed Koliseo was NULL.\n", __func__);
2174 ptrdiff_t padding = -kls->
offset & (align - 1);
2175 if (count > PTRDIFF_MAX / size
2176 || (kls->
size + kls->
offset) < (size * count)) {
2177 fprintf(stderr,
"[KLS] Failed %s() call.\n", __func__);
2181 char *p = kls->
data + kls->
offset - padding - size * count;
2183 kls->
offset -= padding + size * count;
2184#ifdef KLS_DEBUG_CORE
2185 kls_log(kls,
"KLS",
"Popped (%td) for KLS. Curr offset: { %p }",
2205 if (t_kls == NULL) {
2206 fprintf(stderr,
"[ERROR] [%s()]: Passed Koliseo_Temp was NULL.\n",
2212 fprintf(stderr,
"[ERROR] [%s()]: Referred Koliseo was NULL.\n",
2216 ptrdiff_t padding = -kls->
offset & (align - 1);
2217 if (count > PTRDIFF_MAX / size
2218 || (kls->
size + kls->
offset) < (size * count)) {
2219 fprintf(stderr,
"[KLS] Failed %s() call.\n", __func__);
2223 char *p = kls->
data + kls->
offset - padding - size * count;
2225 kls->
offset -= padding + size * count;
2226#ifdef KLS_DEBUG_CORE
2227 kls_log(kls,
"KLS",
"Popped (%td) for Temp_KLS. Curr offset: { %p }.", size, kls->
data + kls->
offset);
2256 char** strings = NULL;
2258 for (
int i=0; i < count; i++) {
2285 char** strings = NULL;
2287 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:851
Koliseo * kls_new(ptrdiff_t size)
Takes a ptrdiff_t size.
Definition koliseo.c:659
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:2241
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:2202
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:2061
void print_dbg_temp_kls(const Koliseo_Temp *t_kls)
Prints header fields from the passed Koliseo_Temp pointer, to stderr.
Definition koliseo.c:1925
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:1732
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:952
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:1886
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:2270
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:798
KLS_Stats KLS_STATS_DEFAULT
Default KLS_Stats values, used by kls_new().
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:499
char * kls_vsprintf(Koliseo *kls, const char *fmt, va_list args)
Definition koliseo.c:1472
void kls_temp_end(Koliseo_Temp *tmp_kls)
Ends passed Koliseo_Temp pointer.
Definition koliseo.c:2112
void kls_dbg_features(void)
Prints enabled Koliseo features to stderr.
Definition koliseo.c:239
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:2254
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:1525
void print_dbg_kls(const Koliseo *kls)
Prints header fields from the passed Koliseo pointer, to stderr.
Definition koliseo.c:1872
const char * string_koliseo_version(void)
Returns the constant string representing current version for Koliseo.
Definition koliseo.c:63
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:1612
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:1106
char * kls_temp_vsprintf(Koliseo_Temp *kls_t, const char *fmt, va_list args)
Definition koliseo.c:1558
ptrdiff_t kls_get_pos(const Koliseo *kls)
Returns the current offset (position of pointer bumper) for the passed Koliseo.
Definition koliseo.c:292
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:886
#define KLS_ASAN_UNPOISON(addr, size)
Definition koliseo.c:83
void kls_free(Koliseo *kls)
Calls kls_clear() on the passed Koliseo pointer and the frees the actual Koliseo.
Definition koliseo.c:1991
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:182
Koliseo * kls_new_dbg_ext(ptrdiff_t size, KLS_Hooks ext_handlers, void *user)
Takes a ptrdiff_t size.
Definition koliseo.c:935
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:1584
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:2283
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:1367
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:920
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:1201
#define KLS_ASAN_POISON(addr, size)
Definition koliseo.c:82
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:1390
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:635
Koliseo * kls_new_dbg(ptrdiff_t size)
Takes a ptrdiff_t size and returns a pointer to the prepared Koliseo.
Definition koliseo.c:967
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:834
char * kls_sprintf(Koliseo *kls, const char *fmt,...)
Takes a Koliseo pointer, and a format cstring, plus varargs.
Definition koliseo.c:1497
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:868
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:2168
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:680
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:116
KLS_Conf KLS_DEFAULT_CONF
Config used by any new Koliseo by default.
Definition koliseo.c:25
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:230
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:158
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:310
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:545
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:1841
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:762
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:982
void kls_clear(Koliseo *kls)
Resets the offset field for the passed Koliseo pointer.
Definition koliseo.c:1959
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:1423
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:1937
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:96
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:709
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:1261
int int_koliseo_version(void)
Returns the constant int representing current version for Koliseo.
Definition koliseo.c:72
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:815
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:742
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:726
void kls_free_func(void *)
Used to select a free function for the arena's backing memory.
Definition koliseo.h:92
#define KLS_PUSH_STR_T(kls_temp, cstr)
Macro to request memory for a C string from a Koliseo_Temp.
Definition koliseo.h:643
#define KLS_Stats_Fmt
Defines a format string for KLS_Stats.
Definition koliseo.h:293
#define KLS_PUSH_STR(kls, cstr)
Macro to request memory for a C string from a Koliseo.
Definition koliseo.h:526
#define KLS_Conf_Arg(conf)
Defines a format macro for KLS_Conf args.
Definition koliseo.h:286
#define KLS_DEFAULT_FREEF
Defines the default free function.
Definition koliseo.h:410
#define KLS_DEFAULT_ALLOCF
Defines the default allocation function.
Definition koliseo.h:406
#define KLS_PUSH(kls, type)
Macro used to request memory from a Koliseo.
Definition koliseo.h:563
#define KLS__STRCPY(dest, source)
Macro to copy a C string from a source buffer to a destination buffer.
Definition koliseo.h:747
#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:220
void * kls_alloc_func(size_t)
Used to select an allocation function for the arena's backing memory.
Definition koliseo.h:91
#define KLS_MAX(a, b)
Definition koliseo.h:98
#define KLS_STRDUP(kls, source)
Definition koliseo.h:756
KLS_Push_Error
Defines the result for kls__check_available().
Definition koliseo.h:366
@ KLS_PUSH_NEGATIVE_COUNT
Definition koliseo.h:371
@ KLS_PUSH_ZEROCOUNT
Definition koliseo.h:372
@ KLS_PUSH_ALIGN_NOT_POW2
Definition koliseo.h:370
@ KLS_PUSH_WITH_TEMP_ACTIVE
Definition koliseo.h:373
@ KLS_PUSH_OOM
Definition koliseo.h:375
@ KLS_PUSH_PTRDIFF_MAX
Definition koliseo.h:374
@ KLS_PUSH_SIZE_LT1
Definition koliseo.h:368
@ KLS_PUSH_ALIGN_LT1
Definition koliseo.h:369
@ KLS_PUSH_OK
Definition koliseo.h:367
#define KLS_Stats_Arg(stats)
Defines a format macro for KLS_Stats args.
Definition koliseo.h:303
#define KLS_Conf_Fmt
Defines a format string for KLS_Conf.
Definition koliseo.h:280
#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:631
#define KLS_STRDUP_T(t_kls, source)
Definition koliseo.h:766
#define KLS_DEFAULT_ERR_HANDLERS
Definition koliseo.h:178
#define KLS_PUSH_ARR(kls, type, count)
Macro used to request memory for an array of type values from a Koliseo.
Definition koliseo.h:514
Defines flags for Koliseo.
Definition koliseo.h:227
int growable
If set to 1, make the Koliseo grow when a out of memory for a push call.
Definition koliseo.h:234
int verbose_lvl
If > 0, makes the Koliseo try to acquire kls_log_fp from kls_log_filepath.
Definition koliseo.h:229
const char * log_filepath
String representing the path to the Koliseo logfile.
Definition koliseo.h:231
FILE * log_fp
FILE pointer used by the Koliseo to print its kls_log() output.
Definition koliseo.h:230
int allow_zerocount_push
If set to 1, make the Koliseo accept push calls with a count of 0.
Definition koliseo.h:233
int collect_stats
If set to 1, make the Koliseo collect performance stats.
Definition koliseo.h:228
KLS_Err_Handlers err_handlers
Used to pass custom error handlers for push calls.
Definition koliseo.h:235
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:232
Defines the handlers used for errors in push calls.
Definition koliseo.h:171
KLS_OOM_Handler * OOM_handler
Pointer to handler for Out-Of-Memory errors in push calls.
Definition koliseo.h:172
KLS_ZEROCOUNT_Handler * ZEROCOUNT_handler
Pointer to handler for zero-count errors in push calls.
Definition koliseo.h:174
KLS_PTRDIFF_MAX_Handler * PTRDIFF_MAX_handler
Pointer to handler for count > (PTRDIFF_MAX / size) errors in push calls.
Definition koliseo.h:173
KLS_hook_on_temp_start * on_temp_start_handler
Used to pass custom start handler for kls_temp_start calls.
Definition koliseo.h:199
KLS_hook_on_free * on_free_handler
Used to pass custom free handler for kls_free calls.
Definition koliseo.h:197
KLS_hook_on_temp_free * on_temp_free_handler
Used to pass custom free handler for kls_temp_end calls.
Definition koliseo.h:200
KLS_hook_on_push * on_push_handler
Used to pass custom push handler for kls_push calls.
Definition koliseo.h:198
KLS_hook_on_new * on_new_handler
Used to pass custom new handler for kls_new_alloc calls.
Definition koliseo.h:196
KLS_hook_on_temp_push * on_temp_push_handler
Used to pass custom push handler for kls_temp_push calls.
Definition koliseo.h:201
Defines the result for kls__advance() and kls__temp_advance().
Definition koliseo.h:383
KLS_Push_Error error
Definition koliseo.h:385
void * p
Definition koliseo.h:384
Defines a stat struct for Koliseo.
Definition koliseo.h:248
int tot_pops
Total POP calls done.
Definition koliseo.h:251
double worst_pushcall_time
DEPRECATED: support for timing will be dropped in the next release.
Definition koliseo.h:258
int tot_temp_pushes
Total PUSH_T calls done.
Definition koliseo.h:250
int tot_pushes
Total PUSH calls done.
Definition koliseo.h:249
int tot_temp_pops
Total POP_T calls done.
Definition koliseo.h:252
Represents a savestate for a Koliseo.
Definition koliseo.h:355
ptrdiff_t offset
Current position of memory pointer.
Definition koliseo.h:357
ptrdiff_t prev_offset
Previous position of memory pointer.
Definition koliseo.h:358
Koliseo * kls
Reference to the actual Koliseo we're saving.
Definition koliseo.h:356
Represents the initialised arena allocator struct.
Definition koliseo.h:316
ptrdiff_t size
Size of data field.
Definition koliseo.h:318
ptrdiff_t offset
Current position of memory pointer.
Definition koliseo.h:319
ptrdiff_t prev_offset
Previous position of memory pointer.
Definition koliseo.h:320
KLS_Conf conf
Contains flags to change the Koliseo behaviour.
Definition koliseo.h:322
struct Koliseo_Temp * t_kls
Points to related active Kolieo_Temp, when has_temp == 1.
Definition koliseo.h:324
KLS_Hooks hooks
Contains handlers for extensions.
Definition koliseo.h:325
char * data
Points to data field.
Definition koliseo.h:317
struct Koliseo * next
Points to the next Koliseo when conf.growable == 1.
Definition koliseo.h:329
void * extension_data
Points to data for extensions.
Definition koliseo.h:326
int has_temp
When == 1, a Koliseo_Temp is currently active on this Koliseo.
Definition koliseo.h:321
KLS_Stats stats
Contains stats for Koliseo performance analysis.
Definition koliseo.h:323
kls_free_func * free_func
Points to the free function for the arena's backing memory.
Definition koliseo.h:328