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;
82#ifndef KOLISEO_HAS_LOCATE
85void KLS_OOM_default_handler_dbg__(
Koliseo* kls, ptrdiff_t available, ptrdiff_t padding, ptrdiff_t size, ptrdiff_t count, Koliseo_Loc loc)
88#ifndef KOLISEO_HAS_LOCATE
90 "[KLS] Out of memory. size*count [%td] was bigger than available-padding [%td].\n",
91 size * count, available - padding);
94 "[KLS] " KLS_Loc_Fmt
"Out of memory. size*count [%td] was bigger than available-padding [%td].\n",
96 size * count, available - padding);
102#ifndef KOLISEO_HAS_LOCATE
105void KLS_PTRDIFF_MAX_default_handler_dbg__(
struct Koliseo* kls, ptrdiff_t size, ptrdiff_t count, Koliseo_Loc loc)
109#ifndef KOLISEO_HAS_LOCATE
111 "[KLS] count [%td] was bigger than PTRDIFF_MAX/size [%li].\n",
112 count, PTRDIFF_MAX / size);
115 "[KLS] " KLS_Loc_Fmt
"count [%td] was bigger than PTRDIFF_MAX/size [%li].\n",
117 count, PTRDIFF_MAX / size);
120#ifndef KOLISEO_HAS_LOCATE
122 "[KLS] count [%td] was bigger than PTRDIFF_MAX/size [%lli].\n",
123 count, PTRDIFF_MAX / size);
126 "[KLS] " KLS_Loc_Fmt
"count [%td] was bigger than PTRDIFF_MAX/size [%lli].\n",
128 count, PTRDIFF_MAX / size);
144#ifndef KOLISEO_HAS_LOCATE
147void KLS_ZEROCOUNT_default_handler_dbg__(
Koliseo* kls, ptrdiff_t available, ptrdiff_t padding, ptrdiff_t size, Koliseo_Loc loc)
150#ifndef KOLISEO_HAS_LOCATE
152 "[KLS] Doing a zero-count push. size [%td] padding [%td] available [%td].\n",
153 size, padding, available);
156 "[KLS] " KLS_Loc_Fmt
"Doing a zero-count push. size [%td] padding [%td] available [%td].\n",
158 size, padding, available);
183#ifndef KOLISEO_HAS_LOCATE
193#ifndef KOLISEO_HAS_LOCATE
203#ifndef KOLISEO_HAS_LOCATE
217KLS_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)
220 return kls_conf_init_handled(collect_stats, verbose_lvl, block_while_has_temp, allow_zerocount_push, growable, log_fp, log_filepath, err_handlers);
228#ifdef KOLISEO_HAS_LOCATE
229 bool kls_locate =
true;
231 bool kls_locate =
false;
234 bool kls_debug =
true;
236 bool kls_debug =
false;
238#ifdef KOLISEO_HAS_EXPER
239 bool kls_exper =
true;
241 bool kls_exper =
false;
248 int total_enabled = 0;
249 for (
int i=0; i<3; i++) {
254 fprintf(stderr,
"[KLS] Enabled features: {");
255 if (total_enabled == 0) {
256 fprintf(stderr,
"none}\n");
260 fprintf(stderr,
"debug%s", (total_enabled > 1 ?
", " :
""));
264 fprintf(stderr,
"locate%s", (total_enabled > 1 ?
", " :
""));
268 fprintf(stderr,
"exper");
270 fprintf(stderr,
"}\n");
293 fprintf(stderr,
"[KLS] %s(): Passed kls was NULL.\n", __func__);
299 va_start(args, format);
302 "[KLS] %s(): Failed opening file to print logs.\n",
305 time_t now = time(0);
306 const struct tm *mytime = localtime(&now);
307 char timeheader[500];
308 if (strftime(timeheader,
sizeof timeheader,
"%X", mytime)) {
309 fprintf(fp,
"[%-10.10s] [%s] [", tag, timeheader);
310 vfprintf(fp, format, args);
335#ifndef KOLISEO_HAS_LOCATE
341 if (size < (ptrdiff_t)
sizeof(
Koliseo)) {
342#ifndef KOLISEO_HAS_LOCATE
344 "[ERROR] at %s(): invalid requested kls size (%td). Min accepted is: (%td).\n",
345 __func__, size, (ptrdiff_t)
sizeof(
Koliseo));
348 "[ERROR] " KLS_Loc_Fmt
"%s(): invalid requested kls size (%td). Min accepted is: (%td).\n",
349 KLS_Loc_Arg(loc), __func__, size, (ptrdiff_t)
sizeof(
Koliseo));
354 void *p = alloc_func(size);
363 kls->
offset =
sizeof(*kls);
372 for (
size_t i=0; i < kls->
hooks_len; i++) {
373 kls->
hooks[i] = ext_handlers[i];
375 for (
size_t i=0; i < kls->
hooks_len; i++) {
385 kls_log(kls,
"KLS",
"API Level { %i } -> Allocated (%s) for new KLS.",
387 kls_log(kls,
"KLS",
"KLS offset: { %p }.", kls);
388 kls_log(kls,
"KLS",
"Allocation begin offset: { %p }.",
392 for (
size_t i=0; i < kls->
hooks_len; i++) {
399#ifndef KOLISEO_HAS_LOCATE
400 fprintf(stderr,
"[KLS] Failed %s() call.\n", __func__);
402 fprintf(stderr,
"[KLS] " KLS_Loc_Fmt
"Failed %s() call.\n", KLS_Loc_Arg(loc), __func__);
430#ifndef KOLISEO_HAS_LOCATE
436#ifndef KOLISEO_HAS_LOCATE
479 bool conf_res = kls_set_conf(k, conf);
482 "[ERROR] [%s()]: Failed to set config for new Koliseo.\n",
561#ifndef KLS_DEBUG_CORE
563 "[WARN] %s(): KLS_DEBUG_CORE is not defined. No tracing allowed.\n",
567 .kls_collect_stats = 1,.kls_verbose_lvl =
568 1,.kls_log_filepath = output_path,
569#ifndef KOLISEO_HAS_LOCATE
573 .err_handlers.OOM_handler = (err_handlers.
OOM_handler != NULL ? err_handlers.
OOM_handler : &KLS_OOM_default_handler_dbg__),
684#ifndef KLS_DEBUG_CORE
686 "[WARN] %s(): KLS_DEBUG_CORE is not defined. No debugging support.\n",
690 .kls_collect_stats = 1,.kls_verbose_lvl = 0,
691#ifndef KOLISEO_HAS_LOCATE
695 .err_handlers.OOM_handler = ( err_handlers.
OOM_handler != NULL ? err_handlers.
OOM_handler : &KLS_OOM_default_handler_dbg__),
792 fprintf(stderr,
"[ERROR] [%s()]: Passed Koliseo was NULL.\n", __func__);
801#ifdef KLS_SETCONF_DEBUG
803 "[%s()]: Preliminary set of conf.kls_log_fp to stderr.",
811 "[ERROR] at %s(): passed OOM_handler is NULL. Using default.\n",
814#ifdef KLS_SETCONF_DEBUG
816 "[%s()]: Passed OOM_handler was NULL, using default.",
820#ifndef KOLISEO_HAS_LOCATE
829 "[ERROR] at %s(): passed PTRDIFF_MAX_handler is NULL. Using default.\n",
832#ifdef KLS_SETCONF_DEBUG
834 "[%s()]: Passed PTRDIFF_MAX_handler was NULL, using default.",
838#ifndef KOLISEO_HAS_LOCATE
845#ifndef KLS_DEBUG_CORE
848 "[WARN] [%s()]: KLS_DEBUG_CORE is not defined. Stats may not be collected in full.\n",
856#ifdef KLS_SETCONF_DEBUG
858 "[%s()]: kls->conf.kls_log_fp was not NULL. Overriding it.",
871 "[ERROR] [%s()]: Failed opening logfile at {\"%s\"} [write].\n",
875 fprintf(log_fp,
"%s",
"");
881 "[ERROR] [%s()]: Failed opening logfile at {\"%s\"} [append].\n",
891static bool kls__try_grow(
Koliseo* kls, ptrdiff_t needed);
905#ifndef KOLISEO_HAS_LOCATE
908int kls__check_available_failable_dbg(
Koliseo* kls, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count,
const char* caller_name, Koliseo_Loc loc)
912 assert(caller_name != NULL);
914#ifndef KOLISEO_HAS_LOCATE
916 "[KLS] %s(): count [%td] was < 0.\n",
921 "[KLS] " KLS_Loc_Fmt
"%s(): count [%td] was < 0.\n",
929#ifndef KOLISEO_HAS_LOCATE
931 "[KLS] %s(): size [%td] was < 1.\n",
936 "[KLS] " KLS_Loc_Fmt
"%s(): size [%td] was < 1.\n",
944#ifndef KOLISEO_HAS_LOCATE
946 "[KLS] %s(): align [%td] was < 1.\n",
951 "[KLS] " KLS_Loc_Fmt
"%s(): align [%td] was < 1.\n",
958 if (! ((align & (align - 1)) == 0)) {
959#ifndef KOLISEO_HAS_LOCATE
961 "[KLS] %s(): align [%td] was not a power of 2.\n",
966 "[KLS] " KLS_Loc_Fmt
"%s(): align [%td] was not a power of 2.\n",
974 while (current->
next != NULL) {
975 current = current->
next;
977 const ptrdiff_t available = current->
size - current->
offset;
978 const ptrdiff_t padding = -current->
offset & (align - 1);
979 bool ZEROCOUNT_happened =
false;
980 bool ZEROCOUNT_handled =
false;
983 ZEROCOUNT_happened =
true;
985#ifndef KOLISEO_HAS_LOCATE
990 ZEROCOUNT_handled =
true;
992#ifndef KOLISEO_HAS_LOCATE
994 "[KLS] %s(): Doing a zero-count push. size [%td] padding [%td] available [%td].\n",
996 size, padding, available);
999 "[KLS] " KLS_Loc_Fmt
"%s(): Doing a zero-count push. size [%td] padding [%td] available [%td].\n",
1002 size, padding, available);
1008#ifdef KLS_DEBUG_CORE
1009 kls_log(current,
"DEBUG",
"Accepting zero-count push: conf.kls_allow_zerocount_push was 1");
1014 if (ZEROCOUNT_happened && ZEROCOUNT_handled) {
1015#ifdef KLS_DEBUG_CORE
1016 kls_log(current,
"DEBUG",
"Requested a zero-count push while kls_allow_zerocount_push is not 1, but the error handler returned instead of exiting.");
1018#ifndef KOLISEO_HAS_LOCATE
1020 "[KLS] %s(): Doing a zero-count push. size [%td] padding [%td] available [%td].\n",
1022 size, padding, available);
1025 "[KLS] " KLS_Loc_Fmt
"%s(): Doing a zero-count push. size [%td] padding [%td] available [%td].\n",
1028 size, padding, available);
1034 bool OOM_happened =
false;
1035 bool OOM_handled =
false;
1036 bool PTRDIFF_MAX_happened =
false;
1037 bool PTRDIFF_MAX_handled =
false;
1038 if (count > PTRDIFF_MAX / size || available - padding < size * count) {
1039 if (count > PTRDIFF_MAX / size) {
1040 PTRDIFF_MAX_happened =
true;
1042#ifndef KOLISEO_HAS_LOCATE
1047 PTRDIFF_MAX_handled =
true;
1050#ifndef KOLISEO_HAS_LOCATE
1052 "[KLS] %s(): count [%td] was bigger than PTRDIFF_MAX/size [%li].\n",
1054 count, PTRDIFF_MAX / size);
1057 "[KLS] " KLS_Loc_Fmt
"%s(): count [%td] was bigger than PTRDIFF_MAX/size [%li].\n",
1060 count, PTRDIFF_MAX / size);
1063#ifndef KOLISEO_HAS_LOCATE
1065 "[KLS] %s(): count [%td] was bigger than PTRDIFF_MAX/size [%lli].\n",
1067 count, PTRDIFF_MAX / size);
1070 "[KLS] " KLS_Loc_Fmt
"%s(): count [%td] was bigger than PTRDIFF_MAX/size [%lli].\n",
1073 count, PTRDIFF_MAX / size);
1078 if (current->
conf.
kls_growable == 1 && kls__try_grow(current, size + count + padding)) {
1081 OOM_happened =
true;
1083#ifndef KOLISEO_HAS_LOCATE
1090#ifndef KOLISEO_HAS_LOCATE
1092 "[KLS] %s(): Out of memory. size*count [%td] was bigger than available-padding [%td].\n",
1094 size * count, available - padding);
1097 "[KLS] " KLS_Loc_Fmt
"%s(): Out of memory. size*count [%td] was bigger than available-padding [%td].\n",
1100 size * count, available - padding);
1104 if (PTRDIFF_MAX_happened) {
1106#ifndef KOLISEO_HAS_LOCATE
1107 fprintf(stderr,
"[KLS] %s(): PTRDIFF_MAX fault happened and was handled.\n", caller_name);
1108#ifdef KLS_DEBUG_CORE
1109 kls_log(current,
"DEBUG",
"%s(): PTRDIFF_MAX fault happened and was handled.", caller_name);
1112 fprintf(stderr,
"[KLS] " KLS_Loc_Fmt
"%s(): PTRDIFF_MAX fault happened and was handled.\n", KLS_Loc_Arg(loc), caller_name);
1113#ifdef KLS_DEBUG_CORE
1114 kls_log(current,
"DEBUG", KLS_Loc_Fmt
"%s(): PTRDIFF_MAX fault happened and was handled.", KLS_Loc_Arg(loc), caller_name);
1119 }
else if (OOM_happened) {
1121#ifndef KOLISEO_HAS_LOCATE
1122 fprintf(stderr,
"[KLS] %s(): OOM fault happened and was handled.\n", caller_name);
1123#ifdef KLS_DEBUG_CORE
1124 kls_log(current,
"DEBUG",
"%s(): OOM fault happened and was handled.", caller_name);
1127 fprintf(stderr,
"[KLS] " KLS_Loc_Fmt
"%s(): OOM fault happened and was handled.\n", KLS_Loc_Arg(loc), caller_name);
1128#ifdef KLS_DEBUG_CORE
1129 kls_log(current,
"DEBUG", KLS_Loc_Fmt
"%s(): OOM fault happened and was handled.", KLS_Loc_Arg(loc), caller_name);
1135#ifndef KOLISEO_HAS_LOCATE
1136 fprintf(stderr,
"[KLS] Failed %s() call.\n", caller_name);
1138 fprintf(stderr,
"[KLS] " KLS_Loc_Fmt
"Failed %s() call.\n", KLS_Loc_Arg(loc), caller_name);
1146bool kls__try_grow(
Koliseo* kls, ptrdiff_t needed)
1148 ptrdiff_t new_size =
KLS_MAX(kls->
size * 2, needed);
1150 kls_log(kls,
"DEBUG",
"%s(): growing Koliseo, new size: {%td}", __func__, new_size);
1151 if (!new_kls)
return false;
1152 kls->
next = new_kls;
1168#ifdef KLS_DEBUG_CORE
1170 struct timespec start_time, end_time;
1171 clock_gettime(CLOCK_MONOTONIC, &start_time);
1173 LARGE_INTEGER start_time, end_time, frequency;
1174 QueryPerformanceFrequency(&frequency);
1175 QueryPerformanceCounter(&start_time);
1180 fprintf(stderr,
"[ERROR] [%s()]: Passed Koliseo was NULL.\n", __func__);
1184 fprintf(stderr,
"[ERROR] [%s()]: Passed Koliseo has an open Koliseo_Temp session.\n", __func__);
1185#ifdef KLS_DEBUG_CORE
1186 kls_log(kls,
"ERROR",
"[%s()]: Passed Koliseo has an open Koliseo_Temp session.", __func__);
1191#ifndef KOLISEO_HAS_LOCATE
1194 kls__check_available_dbg(kls, size, align, count, KLS_HERE);
1197 while (current->
next != NULL) {
1198 current = current->
next;
1200 ptrdiff_t padding = -current->
offset & (align - 1);
1201 char *p = current->
data + current->
offset + padding;
1203 current->
offset += padding + size * count;
1208#ifdef KLS_DEBUG_CORE
1209 kls_log(current,
"KLS",
"Curr offset: { %p }.", current + current->
offset);
1210 kls_log(current,
"KLS",
"API Level { %i } -> Pushed size (%s) for KLS.",
1217 clock_gettime(CLOCK_MONOTONIC, &end_time);
1218 double elapsed_time =
1219 (end_time.tv_sec - start_time.tv_sec) + (end_time.tv_nsec -
1220 start_time.tv_nsec) / 1e9;
1222 QueryPerformanceCounter(&end_time);
1223 double elapsed_time =
1224 (double)(end_time.QuadPart -
1225 start_time.QuadPart) / frequency.QuadPart;
1247#ifndef KOLISEO_HAS_LOCATE
1251void *kls_push_zero_dbg(
Koliseo *kls, ptrdiff_t size, ptrdiff_t align,
1252 ptrdiff_t count, Koliseo_Loc loc)
1256#ifdef KLS_DEBUG_CORE
1258 struct timespec start_time, end_time;
1259 clock_gettime(CLOCK_MONOTONIC, &start_time);
1261 LARGE_INTEGER start_time, end_time, frequency;
1262 QueryPerformanceFrequency(&frequency);
1263 QueryPerformanceCounter(&start_time);
1268 fprintf(stderr,
"[ERROR] [%s()]: Passed Koliseo was NULL.\n", __func__);
1272#ifndef KOLISEO_HAS_LOCATE
1273 fprintf(stderr,
"[ERROR] [%s()]: Passed Koliseo has an open Koliseo_Temp session.\n", __func__);
1275 fprintf(stderr,
"[ERROR] " KLS_Loc_Fmt
"[%s()]: Passed Koliseo has an open Koliseo_Temp session.\n", KLS_Loc_Arg(loc), __func__);
1276 kls_log(kls,
"ERROR", KLS_Loc_Fmt
"[%s()]: Passed Koliseo has an open Koliseo_Temp session.", KLS_Loc_Arg(loc), __func__);
1281#ifndef KOLISEO_HAS_LOCATE
1284 kls__check_available_dbg(kls, size, align, count, loc);
1287 while (current->
next != NULL) {
1288 current = current->
next;
1290 ptrdiff_t padding = -current->
offset & (align - 1);
1291 char *p = current->
data + current->
offset + padding;
1293 memset(p, 0, size * count);
1295 current->
offset += padding + size * count;
1300#ifdef KLS_DEBUG_CORE
1301 kls_log(current,
"KLS",
"Curr offset: { %p }.", current + current->
offset);
1302 kls_log(current,
"KLS",
"API Level { %i } -> Pushed zeroes, size (%s) for KLS.",
1309 clock_gettime(CLOCK_MONOTONIC, &end_time);
1310 double elapsed_time =
1311 (end_time.tv_sec - start_time.tv_sec) + (end_time.tv_nsec -
1312 start_time.tv_nsec) / 1e9;
1314 QueryPerformanceCounter(&end_time);
1315 double elapsed_time =
1316 (double)(end_time.QuadPart -
1317 start_time.QuadPart) / frequency.QuadPart;
1339#ifndef KOLISEO_HAS_LOCATE
1343void *kls_push_zero_ext_dbg(
Koliseo *kls, ptrdiff_t size, ptrdiff_t align,
1344 ptrdiff_t count, Koliseo_Loc loc)
1348#ifdef KLS_DEBUG_CORE
1350 struct timespec start_time, end_time;
1351 clock_gettime(CLOCK_MONOTONIC, &start_time);
1353 LARGE_INTEGER start_time, end_time, frequency;
1354 QueryPerformanceFrequency(&frequency);
1355 QueryPerformanceCounter(&start_time);
1360 fprintf(stderr,
"[ERROR] [%s()]: Passed Koliseo was NULL.\n", __func__);
1364#ifndef KOLISEO_HAS_LOCATE
1365 fprintf(stderr,
"[ERROR] [%s()]: Passed Koliseo has an open Koliseo_Temp session.\n", __func__);
1367 fprintf(stderr,
"[ERROR] " KLS_Loc_Fmt
"[%s()]: Passed Koliseo has an open Koliseo_Temp session.\n", KLS_Loc_Arg(loc), __func__);
1368 kls_log(kls,
"ERROR", KLS_Loc_Fmt
"[%s()]: Passed Koliseo has an open Koliseo_Temp session.", KLS_Loc_Arg(loc), __func__);
1374#ifndef KOLISEO_HAS_LOCATE
1377 kls__check_available_dbg(kls, size, align, count, loc);
1380 while (current->
next != NULL) {
1381 current = current->
next;
1383 ptrdiff_t padding = -current->
offset & (align - 1);
1384 char *p = current->
data + current->
offset + padding;
1386 memset(p, 0, size * count);
1388 current->
offset += padding + size * count;
1390 for (
size_t i=0; i < kls->
hooks_len; i++) {
1417#ifdef KLS_DEBUG_CORE
1418 kls_log(current,
"KLS",
"Curr offset: { %p }.", current + current->
offset);
1419 kls_log(current,
"KLS",
"API Level { %i } -> Pushed zeroes, size (%s) for KLS.",
1426 clock_gettime(CLOCK_MONOTONIC, &end_time);
1427 double elapsed_time =
1428 (end_time.tv_sec - start_time.tv_sec) + (end_time.tv_nsec -
1429 start_time.tv_nsec) / 1e9;
1431 QueryPerformanceCounter(&end_time);
1432 double elapsed_time =
1433 (double)(end_time.QuadPart -
1434 start_time.QuadPart) / frequency.QuadPart;
1457#ifndef KOLISEO_HAS_LOCATE
1459 ptrdiff_t align, ptrdiff_t count)
1461void *kls_temp_push_zero_ext_dbg(
Koliseo_Temp *t_kls, ptrdiff_t size,
1462 ptrdiff_t align, ptrdiff_t count, Koliseo_Loc loc)
1466#ifdef KLS_DEBUG_CORE
1468 struct timespec start_time, end_time;
1469 clock_gettime(CLOCK_MONOTONIC, &start_time);
1471 LARGE_INTEGER start_time, end_time, frequency;
1472 QueryPerformanceFrequency(&frequency);
1473 QueryPerformanceCounter(&start_time);
1477 if (t_kls == NULL) {
1478 fprintf(stderr,
"[ERROR] [%s()]: Passed Koliseo_Temp was NULL.\n",
1484 fprintf(stderr,
"[ERROR] [%s()]: Referred Koliseo was NULL.\n",
1488#ifndef KOLISEO_HAS_LOCATE
1491 kls__check_available_dbg(kls, size, align, count, loc);
1494 while (current->
next != NULL) {
1495 current = current->
next;
1497 ptrdiff_t padding = -current->
offset & (align - 1);
1498 char *p = current->
data + current->
offset + padding;
1500 memset(p, 0, size * count);
1502 current->
offset += padding + size * count;
1504 for (
size_t i=0; i < kls->
hooks_len; i++) {
1515#ifdef KLS_DEBUG_CORE
1518 clock_gettime(CLOCK_MONOTONIC, &end_time);
1519 double elapsed_time =
1520 (end_time.tv_sec - start_time.tv_sec) + (end_time.tv_nsec -
1521 start_time.tv_nsec) / 1e9;
1523 QueryPerformanceCounter(&end_time);
1524 double elapsed_time =
1525 (double)(end_time.QuadPart -
1526 start_time.QuadPart) / frequency.QuadPart;
1532 kls_log(current,
"KLS",
"Curr offset: { %p }.", current + current->
offset);
1534 "API Level { %i } -> Pushed zeroes, size (%s) for Temp_KLS.",
1557#ifndef KOLISEO_HAS_LOCATE
1559 ptrdiff_t old_count, ptrdiff_t new_count)
1561void *kls_repush_dbg(
Koliseo *kls,
void* old, ptrdiff_t size, ptrdiff_t align,
1562 ptrdiff_t old_count, ptrdiff_t new_count, Koliseo_Loc loc)
1566#ifndef KOLISEO_HAS_LOCATE
1568 "[KLS] %s(): old was NULL.\n",
1572 "[KLS] " KLS_Loc_Fmt
"%s(): old was NULL.\n",
1578 if (old_count < 0) {
1579#ifndef KOLISEO_HAS_LOCATE
1581 "[KLS] %s(): old_count [%td] was < 0.\n",
1586 "[KLS] " KLS_Loc_Fmt
"%s(): old_count [%td] was < 0.\n",
1593 if (new_count < 0) {
1594#ifndef KOLISEO_HAS_LOCATE
1596 "[KLS] %s(): new_count [%td] was < 0.\n",
1601 "[KLS] " KLS_Loc_Fmt
"%s(): new_count [%td] was < 0.\n",
1609#ifndef KOLISEO_HAS_LOCATE
1611 "[KLS] %s(): size [%td] was < 1.\n",
1616 "[KLS] " KLS_Loc_Fmt
"%s(): size [%td] was < 1.\n",
1624#ifndef KOLISEO_HAS_LOCATE
1626 "[KLS] %s(): align [%td] was < 1.\n",
1631 "[KLS] " KLS_Loc_Fmt
"%s(): align [%td] was < 1.\n",
1638 if (! ((align & (align - 1)) == 0)) {
1639#ifndef KOLISEO_HAS_LOCATE
1641 "[KLS] %s(): align [%td] was not a power of 2.\n",
1646 "[KLS] " KLS_Loc_Fmt
"%s(): align [%td] was not a power of 2.\n",
1654 fprintf(stderr,
"%s(): kls has an active temp\n", __func__);
1657 size_t old_size = old_count * size;
1658 size_t new_size = new_count * size;
1660 if (new_ptr && old_size > 0) {
1661 memcpy(new_ptr, old, old_size < new_size ? old_size : new_size);
1677#ifndef KOLISEO_HAS_LOCATE
1679 ptrdiff_t old_count, ptrdiff_t new_count)
1681void *kls_temp_repush_dbg(
Koliseo_Temp *t_kls,
void* old, ptrdiff_t size, ptrdiff_t align,
1682 ptrdiff_t old_count, ptrdiff_t new_count, Koliseo_Loc loc)
1686#ifndef KOLISEO_HAS_LOCATE
1688 "[KLS] %s(): old was NULL.\n",
1692 "[KLS] " KLS_Loc_Fmt
"%s(): old was NULL.\n",
1698 if (old_count < 0) {
1699#ifndef KOLISEO_HAS_LOCATE
1701 "[KLS] %s(): old_count [%td] was < 0.\n",
1706 "[KLS] " KLS_Loc_Fmt
"%s(): old_count [%td] was < 0.\n",
1713 if (new_count < 0) {
1714#ifndef KOLISEO_HAS_LOCATE
1716 "[KLS] %s(): new_count [%td] was < 0.\n",
1721 "[KLS] " KLS_Loc_Fmt
"%s(): new_count [%td] was < 0.\n",
1729#ifndef KOLISEO_HAS_LOCATE
1731 "[KLS] %s(): size [%td] was < 1.\n",
1736 "[KLS] " KLS_Loc_Fmt
"%s(): size [%td] was < 1.\n",
1744#ifndef KOLISEO_HAS_LOCATE
1746 "[KLS] %s(): align [%td] was < 1.\n",
1751 "[KLS] " KLS_Loc_Fmt
"%s(): align [%td] was < 1.\n",
1758 if (! ((align & (align - 1)) == 0)) {
1759#ifndef KOLISEO_HAS_LOCATE
1761 "[KLS] %s(): align [%td] was not a power of 2.\n",
1766 "[KLS] " KLS_Loc_Fmt
"%s(): align [%td] was not a power of 2.\n",
1773 size_t old_size = old_count * size;
1774 size_t new_size = new_count * size;
1776 if (new_ptr && old_size > 0) {
1777 memcpy(new_ptr, old, old_size < new_size ? old_size : new_size);
1790 fprintf(stderr,
"print_kls_2file(): fp was NULL.\n");
1794 fprintf(fp,
"[KLS] kls was NULL.\n");
1801 fprintf(fp,
"\n[KLS] Size: { %td }\n", kls->
size);
1802 char human_size[200];
1803 char curr_size[200];
1805 fprintf(fp,
"[KLS] Size (Human): { %s }\n", human_size);
1807 fprintf(fp,
"[KLS] Used (Human): { %s }\n", curr_size);
1808 fprintf(fp,
"[KLS] Offset: { %td }\n", kls->
offset);
1809 fprintf(fp,
"[KLS] Prev_Offset: { %td }\n", kls->
prev_offset);
1821 fprintf(stderr,
"[ERROR] [%s()]: Passed Koliseo was NULL.\n", __func__);
1835 fprintf(stderr,
"print_temp_kls_2file(): fp was NULL.\n");
1838 if (t_kls == NULL) {
1839 fprintf(fp,
"[KLS_T] t_kls was NULL.");
1840 }
else if (t_kls->
kls == NULL) {
1841 fprintf(fp,
"[KLS_T] [%s()]: Referred Koliseo was NULL.\n", __func__);
1845 fprintf(fp,
"\n[KLS_T] Temp Size: { %td }\n",
1847 fprintf(fp,
"\n[KLS_T] Refer Size: { %td }\n", kls->
size);
1848 char human_size[200];
1849 char curr_size[200];
1851 sizeof(human_size));
1852 fprintf(fp,
"[KLS_T] Temp Size Human: { %s }\n", human_size);
1854 fprintf(fp,
"[KLS_T] Refer Size Human: { %s }\n", human_size);
1856 fprintf(fp,
"[KLS_T] Inner Used (Human): { %s }\n", curr_size);
1858 fprintf(fp,
"[KLS_T] Temp Used (Human): { %s }\n", curr_size);
1859 fprintf(fp,
"[KLS_T] Inner Offset: { %td }\n", kls->
offset);
1860 fprintf(fp,
"[KLS_T] Temp Offset: { %td }\n", t_kls->
offset);
1861 fprintf(fp,
"[KLS_T] Inner Prev_Offset: { %td }\n", kls->
prev_offset);
1862 fprintf(fp,
"[KLS_T] Temp Prev_Offset: { %td }\n\n",
1885 const char *units[] =
1886 {
"bytes",
"KB",
"MB",
"GB",
"TB",
"PB",
"EB",
"ZB",
"YB" };
1887 const int numUnits =
sizeof(units) /
sizeof(units[0]);
1890 double sizeValue = (double)size;
1892 while (sizeValue >= 1000 && unitIndex < numUnits - 1) {
1897 snprintf(outputBuffer, bufferSize,
"%.2f %s", sizeValue, units[unitIndex]);
1908 fprintf(stderr,
"[ERROR] [%s()]: Passed Koliseo was NULL.\n", __func__);
1913 kls->
offset =
sizeof(*kls);
1914#ifdef KLS_DEBUG_CORE
1915 kls_log(kls,
"KLS",
"API Level { %i } -> Cleared offsets for KLS.",
1928 fprintf(stderr,
"[ERROR] [%s()]: Passed Koliseo was NULL.\n", __func__);
1934 current->
next = NULL;
1935 for (
size_t i=0; i < current->
hooks_len; i++) {
1942#ifdef KLS_DEBUG_CORE
1944 "API Level { %i } -> KLS had an active Koliseo_Temp.",
1950#ifdef KLS_DEBUG_CORE
1951 kls_log(current,
"KLS",
"API Level { %i } -> Freeing KLS.",
1956#ifdef KLS_DEBUG_CORE
1957 kls_log(current,
"KLS",
"Closing kls log file. Path: {\"%s\"}.",
1961 if (close_res != 0) {
1963 "[ERROR] %s(): Failed fclose() on log_fp. Path: {\"%s\"}.",
1969 "[INFO] %s(): kls->conf.kls_log_fp is %s. Not closing it.\n",
1976 "[ERROR] %s(): free function was NULL.\n", __func__);
1991#ifndef KOLISEO_HAS_LOCATE
1998 fprintf(stderr,
"[ERROR] [%s()]: Passed Koliseo was NULL.\n", __func__);
2002 while (current->
next != NULL) {
2003 current = current->
next;
2007 "[ERROR] [%s()]: Passed Koliseo->has_temp is not 0. {%i}\n",
2009#ifdef KLS_DEBUG_CORE
2010 kls_log(current,
"ERROR",
"[%s()]: Passed Koliseo->has_temp != 0 . {%i}",
2019 ptrdiff_t off = current->
offset;
2025#ifdef KLS_DEBUG_CORE
2031 current->
t_kls = tmp;
2032 for (
size_t i=0; i < kls->
hooks_len; i++) {
2038#ifdef KLS_DEBUG_CORE
2039 kls_log(current,
"KLS",
"Prepared new Temp KLS.");
2050 if (tmp_kls == NULL) {
2051 fprintf(stderr,
"[ERROR] [%s()]: Passed Koliseo_Temp was NULL.\n",
2057 if (kls_ref == NULL) {
2058 fprintf(stderr,
"[ERROR] [%s()]: Referred Koliseo was NULL.\n",
2063 for (
size_t i=0; i < kls_ref->
hooks_len; i++) {
2070#ifdef KLS_DEBUG_CORE
2071 kls_log(kls_ref,
"KLS",
"Ended Temp KLS.");
2080 if (to_free != NULL) {
2092#ifdef KOLISEO_HAS_EXPER
2104 fprintf(stderr,
"[ERROR] [%s()]: Passed Koliseo was NULL.\n", __func__);
2107 ptrdiff_t padding = -kls->
offset & (align - 1);
2108 if (count > PTRDIFF_MAX / size
2109 || (kls->
size + kls->
offset) < (size * count)) {
2110 fprintf(stderr,
"[KLS] Failed %s() call.\n", __func__);
2114 char *p = kls->
data + kls->
offset - padding - size * count;
2116 kls->
offset -= padding + size * count;
2117#ifdef KLS_DEBUG_CORE
2118 kls_log(kls,
"KLS",
"API Level { %i } -> Popped (%li) for KLS.",
2141 fprintf(stderr,
"[ERROR] [%s()]: Passed Koliseo was NULL.\n", __func__);
2144 ptrdiff_t padding = -kls->
offset & (align - 1);
2145 if (count > PTRDIFF_MAX / size
2146 || (kls->
size + kls->
offset) < (size * count)) {
2147 fprintf(stderr,
"[KLS] Failed %s() call.\n", __func__);
2151 char *p = kls->
data + kls->
offset - padding - size * count;
2153 kls->
offset -= padding + size * count;
2154#ifdef KLS_DEBUG_CORE
2155 kls_log(kls,
"KLS",
"API Level { %i } -> Popped (%li) for KLS.",
2178 if (t_kls == NULL) {
2179 fprintf(stderr,
"[ERROR] [%s()]: Passed Koliseo_Temp was NULL.\n",
2185 fprintf(stderr,
"[ERROR] [%s()]: Referred Koliseo was NULL.\n",
2189 ptrdiff_t padding = -kls->
offset & (align - 1);
2190 if (count > PTRDIFF_MAX / size
2191 || (kls->
size + kls->
offset) < (size * count)) {
2192 fprintf(stderr,
"[KLS] Failed %s() call.\n", __func__);
2196 char *p = kls->
data + kls->
offset - padding - size * count;
2198 kls->
offset -= padding + size * count;
2199#ifdef KLS_DEBUG_CORE
2200 kls_log(kls,
"KLS",
"Curr offset: { %p }.", kls + kls->
offset);
2201 kls_log(kls,
"KLS",
"API Level { %i } -> Popped (%li) for Temp_KLS.",
2223 if (t_kls == NULL) {
2224 fprintf(stderr,
"[ERROR] [%s()]: Passed Koliseo_Temp was NULL.\n",
2230 fprintf(stderr,
"[ERROR] [%s()]: Referred Koliseo was NULL.\n",
2234 ptrdiff_t padding = -kls->
offset & (align - 1);
2235 if (count > PTRDIFF_MAX / size
2236 || (kls->
size + kls->
offset) < (size * count)) {
2237 fprintf(stderr,
"[KLS] Failed %s() call.\n", __func__);
2241 char *p = kls->
data + kls->
offset - padding - size * count;
2243 kls->
offset -= padding + size * count;
2244#ifdef KLS_DEBUG_CORE
2245 kls_log(kls,
"KLS",
"Curr offset: { %p }.", kls + kls->
offset);
2246 kls_log(kls,
"KLS",
"API Level { %i } -> Popped (%li) for Temp_KLS.",
2279 char** strings = NULL;
2281 for (
int i=0; i < count; i++) {
2308 char** strings = NULL;
2310 for (
int i=0; i < count; i++) {
#define KLS_DEFAULT_HOOKS
Definition kls_region.h:162
#define KLS_DEFAULT_EXTENSIONS_LEN
Definition kls_region.h:173
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:647
Koliseo * kls_new(ptrdiff_t size)
Takes a ptrdiff_t size.
Definition koliseo.c:455
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:2264
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:2175
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:1992
void print_dbg_temp_kls(const Koliseo_Temp *t_kls)
Prints header fields from the passed Koliseo_Temp pointer, to stderr.
Definition koliseo.c:1871
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:1678
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:748
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:1832
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:2293
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:594
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:290
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:558
void kls_temp_end(Koliseo_Temp *tmp_kls)
Ends passed Koliseo_Temp pointer.
Definition koliseo.c:2048
void kls_dbg_features(void)
Prints enabled Koliseo features to stderr.
Definition koliseo.c:226
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:2277
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:1458
void print_dbg_kls(const Koliseo *kls)
Prints header fields from the passed Koliseo pointer, to stderr.
Definition koliseo.c:1818
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:1558
ptrdiff_t kls_get_pos(const Koliseo *kls)
Returns the current offset (position of pointer bumper) for the passed Koliseo.
Definition koliseo.c:279
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:2221
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:2138
void kls_free(Koliseo *kls)
Calls kls_clear() on the passed Koliseo pointer and the frees the actual Koliseo.
Definition koliseo.c:1925
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:169
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:611
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:2306
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:1165
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:716
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:1248
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:431
Koliseo * kls_new_dbg(ptrdiff_t size)
Takes a ptrdiff_t size and returns a pointer to the prepared Koliseo.
Definition koliseo.c:763
int 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:906
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:630
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:476
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:664
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:2101
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:103
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:217
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:145
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:731
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:336
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:1787
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:682
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:778
void kls_clear(Koliseo *kls)
Resets the offset field for the passed Koliseo pointer.
Definition koliseo.c:1905
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:1340
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:1883
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:83
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:505
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:538
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:522
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:594
#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:509
#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:405
#define KLS_DEFAULT_ALLOCF
Defines the default allocation function.
Definition koliseo.h:401
#define KLS_PUSH(kls, type)
Macro used to request memory from a Koliseo.
Definition koliseo.h:534
#define KLS__STRCPY(dest, source)
Macro to copy a C string from a source buffer to a destination buffer.
Definition koliseo.h:698
#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:707
#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__check_available(kls, size, align, count)
Macro to return NULL on errors from kls__check_available_failable.
Definition koliseo.h:440
#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:588
#define KLS_STRDUP_T(t_kls, source)
Definition koliseo.h:717
#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:493
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 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:377
ptrdiff_t offset
Current position of memory pointer.
Definition koliseo.h:379
ptrdiff_t prev_offset
Previous position of memory pointer.
Definition koliseo.h:380
Koliseo * kls
Reference to the actual Koliseo we're saving.
Definition koliseo.h:378
Represents the initialised arena allocator struct.
Definition koliseo.h:338
ptrdiff_t size
Size of data field.
Definition koliseo.h:340
ptrdiff_t offset
Current position of memory pointer.
Definition koliseo.h:341
ptrdiff_t prev_offset
Previous position of memory pointer.
Definition koliseo.h:342
KLS_Conf conf
Contains flags to change the Koliseo behaviour.
Definition koliseo.h:344
void * extension_data[KLS_MAX_EXTENSIONS]
Points to data for extensions.
Definition koliseo.h:348
struct Koliseo_Temp * t_kls
Points to related active Kolieo_Temp, when has_temp == 1.
Definition koliseo.h:346
char * data
Points to data field.
Definition koliseo.h:339
size_t hooks_len
Length for hooks and extension_data.
Definition koliseo.h:349
struct Koliseo * next
Points to the next Koliseo when conf.kls_growable == 1.
Definition koliseo.h:351
int has_temp
When == 1, a Koliseo_Temp is currently active on this Koliseo.
Definition koliseo.h:343
KLS_Stats stats
Contains stats for Koliseo performance analysis.
Definition koliseo.h:345
KLS_Hooks hooks[KLS_MAX_EXTENSIONS]
Contains handlers for extensions.
Definition koliseo.h:347
kls_free_func * free_func
Points to the free function for the arena's backing memory.
Definition koliseo.h:350