koliseo 0.5.4
Loading...
Searching...
No Matches
koliseo.h File Reference
#include <stdio.h>
#include <stdint.h>
#include <stddef.h>
#include <stdlib.h>
#include <stdarg.h>
#include <assert.h>
#include <string.h>
#include <time.h>
#include <stdbool.h>

Go to the source code of this file.

Data Structures

struct  KLS_Err_Handlers
 Defines the handlers used for errors in push calls. More...
struct  KLS_Hooks
struct  KLS_Conf
 Defines flags for Koliseo. More...
struct  KLS_Stats
 Defines a stat struct for Koliseo. More...
struct  Koliseo
 Represents the initialised arena allocator struct. More...
struct  Koliseo_Temp
 Represents a savestate for a Koliseo. More...

Macros

#define KOLISEO_H_
#define _POSIX_C_SOURCE   200809L
#define KLS_MAJOR   0
 Represents current major release.
#define KLS_MINOR   5
 Represents current minor release.
#define KLS_PATCH   4
 Represents current patch release.
#define STRINGIFY_2(x)
#define STRINGIFY(x)
#define KLS_MAX(a, b)
#define KLS_DEFAULT_SIZE   (16*1024)
 Represents a simple default size for demo purposes.
#define KLS_DEFAULT_ALIGNMENT   (2*sizeof(void *))
 Represents a default alignment value.
#define KLS_DEFAULT_ERR_HANDLERS   (KLS_Err_Handlers) { .OOM_handler = &KLS_OOM_default_handler__, .PTRDIFF_MAX_handler = &KLS_PTRDIFF_MAX_default_handler__, .ZEROCOUNT_handler = &KLS_ZEROCOUNT_default_handler__, }
#define KLS_DEFAULT_HOOKS   &(KLS_Hooks){0}
 Defines default hooks that are loaded on kls_new() variants lacking explicit set of KLS_Hooks.
#define KLS_DEFAULT_EXTENSION_DATA   NULL
 Defines default hooks that are loaded on kls_new() variants lacking explicit set of KLS_Hooks.
#define KLS_Conf_Fmt   "KLS_Conf { collect_stats: %i, verbose_lvl: %i, log_filepath: \"%s\", log_fp: %p, block_while_has_temp: %i, allow_zerocount_push: %i }"
 Defines a format string for KLS_Conf.
#define KLS_Conf_Arg(conf)
 Defines a format macro for KLS_Conf args.
#define KLS_Stats_Fmt   "KLS_Stats { tot_pushes: %i, tot_pops: %i, tot_temp_pushes: %i, tot_temp_pops: %i, tot_hiccups: %i, worst_push_time: %.7f }"
 Defines a format string for KLS_Stats.
#define KLS_Stats_Arg(stats)
 Defines a format macro for KLS_Stats args.
#define KLS_MAX_EXTENSIONS   1
 Defines how many extensions can be handled at once.
#define KLS_DEFAULT_EXTENSIONS_LEN   0
 Defines how many extensions are loaded on kls_new() variants lacking explicit set of KLS_Hooks.
#define KLSFmt   "KLS {begin: %p, curr: %p, size: %li, offset: %li, has_temp: %i}"
 Defines a format string for Koliseo.
#define KLS_Arg(kls)
 Defines a format macro for Koliseo args.
#define KLS_DEFAULT_ALLOCF   malloc
 Defines the default allocation function.
#define KLS_DEFAULT_FREEF   free
 Defines the default free function.
#define kls__check_available(kls, size, align, count)
 Macro to return NULL on errors from kls__check_available_failable.
#define KLS_PUSH_ARR(kls, type, count)
 Macro used to request memory for an array of type values from a Koliseo.
#define KLS_PUSH_STR(kls, cstr)
 Macro to request memory for a C string from a Koliseo.
#define KLS_PUSH_ARR_NAMED(kls, type, count, name, desc)
 Macro used to request memory for an array of type values from a Koliseo, and assign a name and a description to the region item.
#define KLS_PUSH_STR_NAMED(kls, cstr, name, desc)
 Macro to request memory for a C string from a Koliseo, and assign a name and a description to the region item.
#define KLS_PUSH_ARR_TYPED(kls, type, count, region_type, name, desc)
 Macro used to request memory for an array of type values from a Koliseo, and assign a type, a name and a description to the region item.
#define KLS_PUSH_STR_TYPED(kls, cstr, region_type, name, desc)
 Macro to request memory for a C string from a Koliseo, and assign a type, a name and a description to the region item.
#define KLS_PUSH(kls, type)
 Macro used to request memory from a Koliseo.
#define KLS_PUSH_NAMED(kls, type, name, desc)
 Macro used to request memory from a Koliseo, and assign a name and a description to the region item.
#define KLS_PUSH_EX(kls, type, name)
 Macro used to request memory from a Koliseo, and assign a name to the region item.
#define KLS_PUSH_TYPED(kls, type, region_type, name, desc)
 Macro used to request memory from a Koliseo, and assign a a type, a name and a description to the region item.
#define KLS_PUSH_TYPED_EX(kls, type, region_type, name)
 Macro used to request memory from a Koliseo, and assign a type and a name to the region item.
#define KLS_PUSH_ARR_T(kls_temp, type, count)
 Macro used to request memory for an array of type values from a Koliseo_Temp.
#define KLS_PUSH_STR_T(kls_temp, cstr)
 Macro to request memory for a C string from a Koliseo_Temp.
#define KLS_PUSH_ARR_T_NAMED(kls_temp, type, count, name, desc)
 Macro used to request memory for an array of type values from a Koliseo_Temp, and assign a name and a description to the region item.
#define KLS_PUSH_STR_T_NAMED(kls_temp, cstr, name, desc)
 Macro to request memory for a C string from a Koliseo_Temp, and assign a name and a description to the region item.
#define KLS_PUSH_ARR_T_TYPED(kls_temp, type, count, region_type, name, desc)
 Macro used to request memory for an array of type values from a Koliseo_Temp, and assign a type, a name and a description to the region item.
#define KLS_PUSH_STR_T_TYPED(kls_temp, cstr, region_type, name, desc)
 Macro to request memory for a C string from a Koliseo_Temp, and assign a type, a name and a description to the region item.
#define KLS_PUSH_T(kls_temp, type)
 Macro used to request memory from a Koliseo_Temp.
#define KLS_PUSH_T_NAMED(kls_temp, type, name, desc)
 Macro used to request memory from a Koliseo_Temp, and assign a name and a description to the region item.
#define KLS_PUSH_T_EX(kls_temp, type, name)
 Macro used to request memory from a Koliseo_Temp, and assign a name to the region item.
#define KLS_PUSH_T_TYPED(kls_temp, type, region_type, name, desc)
 Macro used to request memory from a Koliseo_Temp, and assign a type, a name and a description to the region item.
#define KLS_PUSH_T_TYPED_EX(kls_temp, type, region_type, name)
 Macro used to request memory from a Koliseo_Temp, and assign a type and a name to the region item.
#define KLS_POP_ARR(kls, type, count)
 Macro used to "remove" memory as an array from a Koliseo.
#define KLS_POP_STR(kls, cstr)
 Macro to "remove" the memory for a C string from a Koliseo.
#define KLS_POP(kls, type)
 Macro used to "remove" memory from a Koliseo.
#define KLS_POP_ARR_T(kls_temp, type, count)
 Macro used to "remove" memory as an array from a Koliseo_Temp.
#define KLS_POP_STR_T(kls_temp, cstr)
 Macro to "remove" the memory for a C string from a Koliseo_Temp.
#define KLS_POP_T(kls_temp, type)
 Macro used to "remove" memory from a Koliseo_Temp.
#define KLS__STRCPY(dest, source)
 Macro to copy a C string from a source buffer to a destination buffer.
#define KLS_STRDUP(kls, source)
#define KLS_STRDUP_T(t_kls, source)

Typedefs

typedef void * kls_alloc_func(size_t)
 Used to select an allocation function for the arena's backing memory.
typedef void kls_free_func(void *)
 Used to select a free function for the arena's backing memory.
typedef void KLS_OOM_Handler(struct Koliseo *kls, ptrdiff_t available, ptrdiff_t padding, ptrdiff_t size, ptrdiff_t count)
 Used to pass an error handler for Out-Of-Memory error.
typedef void KLS_PTRDIFF_MAX_Handler(struct Koliseo *kls, ptrdiff_t size, ptrdiff_t count)
 Used to pass an error handler for count > (PTRDIFF_MAX / size) error.
typedef void KLS_ZEROCOUNT_Handler(struct Koliseo *kls, ptrdiff_t available, ptrdiff_t padding, ptrdiff_t size)
 Used to pass an error handler for zero-count push call error.
typedef struct KLS_Err_Handlers KLS_Err_Handlers
 Defines the handlers used for errors in push calls.
typedef void KLS_hook_on_new(struct Koliseo *kls)
 Used to pass an extension handler for kls_new_alloc().
typedef void KLS_hook_on_free(struct Koliseo *kls)
 Used to pass an extension handler for kls_free().
typedef void KLS_hook_on_push(struct Koliseo *kls, ptrdiff_t padding, const char *caller, void *user)
 Used to pass an extension handler for kls_push().
typedef void KLS_hook_on_temp_start(struct Koliseo_Temp *t_kls)
 Used to pass an extension handler for kls_temp_start().
typedef void KLS_hook_on_temp_free(struct Koliseo_Temp *t_kls)
 Used to pass an extension handler for kls_temp_end().
typedef void KLS_hook_on_temp_push(struct Koliseo_Temp *t_kls, ptrdiff_t padding, const char *caller, void *user)
 Used to pass an extension handler for kls_temp_push().
typedef struct KLS_Hooks KLS_Hooks
typedef struct KLS_Conf KLS_Conf
 Defines flags for Koliseo.
typedef struct KLS_Stats KLS_Stats
 Defines a stat struct for Koliseo.
typedef struct Koliseo Koliseo
 Represents the initialised arena allocator struct.
typedef struct Koliseo_Temp Koliseo_Temp
 Represents a savestate for a Koliseo.

Functions

const char * string_koliseo_version (void)
 Returns current koliseo version as a string.
int int_koliseo_version (void)
 Returns current koliseo version as an integer.
void KLS_OOM_default_handler__ (struct Koliseo *kls, ptrdiff_t available, ptrdiff_t padding, ptrdiff_t size, ptrdiff_t count)
 Used by default when no handler is passed.
void KLS_PTRDIFF_MAX_default_handler__ (struct Koliseo *kls, ptrdiff_t size, ptrdiff_t count)
 Used by default when no handler is passed.
void KLS_ZEROCOUNT_default_handler__ (struct Koliseo *kls, ptrdiff_t available, ptrdiff_t padding, ptrdiff_t size)
 Used by default when no handler is passed.
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.
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.
void kls_dbg_features (void)
 Prints enabled Koliseo features to stderr.
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.kls_verbose_lvl is >0.
ptrdiff_t kls_get_pos (const Koliseo *kls)
 Returns the current offset (position of pointer bumper) for the passed Koliseo.
Koliseokls_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.
Koliseokls_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.
Koliseokls_new (ptrdiff_t size)
 Takes a ptrdiff_t size.
Koliseokls_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 free function pointer.
Koliseokls_new_conf_alloc (ptrdiff_t size, KLS_Conf conf, kls_alloc_func alloc_func, kls_free_func kls_free_func)
 Takes a ptrdiff_t size, a KLS_Conf to configure the new Koliseo, an allocation function pointer and a free function pointer.
Koliseokls_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.
Koliseokls_new_conf (ptrdiff_t size, KLS_Conf conf)
 Takes a ptrdiff_t size and a KLS_Conf to configure the new Koliseo.
Koliseokls_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 free function pointer.
Koliseokls_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 free function pointer.
Koliseokls_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.
Koliseokls_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 free function pointer.
Koliseokls_new_traced (ptrdiff_t size, const char *output_path)
 Takes a ptrdiff_t size and a filepath for the trace output file.
Koliseokls_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.
Koliseokls_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, and returns a pointer to the prepared Koliseo.
Koliseokls_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, and returns a pointer to the prepared Koliseo.
Koliseokls_new_dbg_ext (ptrdiff_t size, KLS_Hooks *ext_handlers, void **user, size_t ext_len)
 Takes a ptrdiff_t size.
Koliseokls_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, and returns a pointer to the prepared Koliseo.
Koliseokls_new_dbg (ptrdiff_t size)
 Takes a ptrdiff_t size and returns a pointer to the prepared Koliseo.
Koliseokls_new_dbg_handled (ptrdiff_t size, KLS_Err_Handlers err_handlers)
 Takes a ptrdiff_t size and returns a pointer to the prepared Koliseo.
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.
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.
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.
void kls_clear (Koliseo *kls)
 Resets the offset field for the passed Koliseo pointer.
void kls_free (Koliseo *kls)
 Calls kls_clear() on the passed Koliseo pointer and the frees the actual Koliseo.
void print_kls_2file (FILE *fp, const Koliseo *kls)
 Prints header fields from the passed Koliseo pointer, to the passed FILE pointer.
void print_dbg_kls (const Koliseo *kls)
 Prints header fields from the passed Koliseo pointer, to stderr.
void kls_formatSize (ptrdiff_t size, char *outputBuffer, size_t bufferSize)
 Converts a ptrdiff_t size to human-readable SI units (modulo 1000).
Koliseo_Tempkls_temp_start (Koliseo *kls)
 Starts a new savestate for the passed Koliseo pointer, by initialising its Koliseo_Temp pointer and returning it.
void kls_temp_end (Koliseo_Temp *tmp_kls)
 Ends passed Koliseo_Temp pointer.
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.
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.
void print_dbg_temp_kls (const Koliseo_Temp *t_kls)
 Prints header fields from the passed Koliseo_Temp pointer, to stderr.
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.
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.
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.
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.
char * kls_strdup (Koliseo *kls, char *source)
 Function to dupe a C string to a Koliseo, and return a pointer to the allocated string.
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.
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.
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.

Variables

KLS_Conf KLS_DEFAULT_CONF
 Default KLS_Conf used by kls_new().
KLS_Stats KLS_STATS_DEFAULT
 Default KLS_Stats values, used by kls_new().

Macro Definition Documentation

◆ _POSIX_C_SOURCE

#define _POSIX_C_SOURCE   200809L

◆ kls__check_available

#define kls__check_available ( kls,
size,
align,
count )
Value:
do { \
int res = kls__check_available_failable((kls), (size), (align), (count), __func__); \
if (res != 0) return NULL; \
} while(0)
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

Macro to return NULL on errors from kls__check_available_failable.

See also
kls__check_available_failable

◆ KLS__STRCPY

#define KLS__STRCPY ( dest,
source )
Value:
do {\
strcpy((dest), (source));\
} while (0)

Macro to copy a C string from a source buffer to a destination buffer.

Unsafe, do not use. Used in KLS_STRDUP() and KLS_STRDUP_T().

See also
KLS_STRDUP()
KLS_STRDUP_T()

◆ KLS_Arg

#define KLS_Arg ( kls)
Value:
(void*)(kls),(void*)((kls)+(kls->offset)),(kls->size),(kls->offset),(kls->has_temp)

Defines a format macro for Koliseo args.

See also
KLSFmt

◆ KLS_Conf_Arg

#define KLS_Conf_Arg ( conf)
Value:
(conf.kls_collect_stats),(conf.kls_verbose_lvl),(conf.kls_log_filepath),(void*)(conf.kls_log_fp),(conf.kls_block_while_has_temp),(conf.kls_allow_zerocount_push)

Defines a format macro for KLS_Conf args.

See also
KLS_Conf_Fmt

◆ KLS_Conf_Fmt

#define KLS_Conf_Fmt   "KLS_Conf { collect_stats: %i, verbose_lvl: %i, log_filepath: \"%s\", log_fp: %p, block_while_has_temp: %i, allow_zerocount_push: %i }"

Defines a format string for KLS_Conf.

See also
KLS_Conf_Arg()

◆ KLS_DEFAULT_ALIGNMENT

#define KLS_DEFAULT_ALIGNMENT   (2*sizeof(void *))

Represents a default alignment value.

Not used.

◆ KLS_DEFAULT_ALLOCF

#define KLS_DEFAULT_ALLOCF   malloc

Defines the default allocation function.

◆ KLS_DEFAULT_ERR_HANDLERS

#define KLS_DEFAULT_ERR_HANDLERS   (KLS_Err_Handlers) { .OOM_handler = &KLS_OOM_default_handler__, .PTRDIFF_MAX_handler = &KLS_PTRDIFF_MAX_default_handler__, .ZEROCOUNT_handler = &KLS_ZEROCOUNT_default_handler__, }

◆ KLS_DEFAULT_EXTENSION_DATA

#define KLS_DEFAULT_EXTENSION_DATA   NULL

Defines default hooks that are loaded on kls_new() variants lacking explicit set of KLS_Hooks.

Useful to be redefined by an extension file, together with KLS_DEFAULT_HOOKS.

See also
KLS_DEFAULT_HOOKS
KLS_DEFAULT_EXTENSIONS_LEN

◆ KLS_DEFAULT_EXTENSIONS_LEN

#define KLS_DEFAULT_EXTENSIONS_LEN   0

Defines how many extensions are loaded on kls_new() variants lacking explicit set of KLS_Hooks.

Useful to be redefined by an extension file, together with KLS_DEFAULT_HOOKS.

See also
KLS_DEFAULT_HOOKS
KLS_Hooks
Koliseo

◆ KLS_DEFAULT_FREEF

#define KLS_DEFAULT_FREEF   free

Defines the default free function.

◆ KLS_DEFAULT_HOOKS

#define KLS_DEFAULT_HOOKS   &(KLS_Hooks){0}

Defines default hooks that are loaded on kls_new() variants lacking explicit set of KLS_Hooks.

Useful to be redefined by an extension file, together with KLS_DEFAULT_EXTENSION_DATA.

See also
KLS_DEFAULT_EXTENSION_DATA
KLS_DEFAULT_EXTENSIONS_LEN
KLS_Hooks

◆ KLS_DEFAULT_SIZE

#define KLS_DEFAULT_SIZE   (16*1024)

Represents a simple default size for demo purposes.

◆ KLS_MAJOR

#define KLS_MAJOR   0

Represents current major release.

◆ KLS_MAX

#define KLS_MAX ( a,
b )
Value:
((a) > (b) ? (a) : (b))

◆ KLS_MAX_EXTENSIONS

#define KLS_MAX_EXTENSIONS   1

Defines how many extensions can be handled at once.

See also
KLS_Hooks
Koliseo

◆ KLS_MINOR

#define KLS_MINOR   5

Represents current minor release.

◆ KLS_PATCH

#define KLS_PATCH   4

Represents current patch release.

◆ KLS_POP

#define KLS_POP ( kls,
type )
Value:
KLS_POP_ARR((kls), type, 1)
#define KLS_POP_ARR(kls, type, count)
Macro used to "remove" memory as an array from a Koliseo.
Definition koliseo.h:613

Macro used to "remove" memory from a Koliseo.

Rewinds the pointer by the requested type and returns a pointer to that memory before updating the Koliseo index. It's up to you to copy your item somewhere else before calling any PUSH operation again, as that memory should be overwritten.

◆ KLS_POP_ARR

#define KLS_POP_ARR ( kls,
type,
count )
Value:
(type*)kls_pop_AR((kls), sizeof(type), _Alignof(type), (count))
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:1902

Macro used to "remove" memory as an array from a Koliseo.

Rewinds the pointer by the requested type and returns a pointer to that memory before updating the Koliseo index. It's up to you to copy your item somewhere else before calling any PUSH operation again, as that memory should be overwritten.

◆ KLS_POP_ARR_T

#define KLS_POP_ARR_T ( kls_temp,
type,
count )
Value:
(type*)kls_temp_pop_AR((kls_temp), sizeof(type), _Alignof(type), (count))
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:1985

Macro used to "remove" memory as an array from a Koliseo_Temp.

Rewinds the pointer by the requested type and returns a pointer to that memory before updating the Koliseo_Temp index. It's up to you to copy your item somewhere else before calling any PUSH operation again, as that memory should be overwritten.

◆ KLS_POP_STR

#define KLS_POP_STR ( kls,
cstr )
Value:
KLS_POP_ARR((kls), char, strlen((cstr)))

Macro to "remove" the memory for a C string from a Koliseo.

Rewinds the pointer by the string's memory and returns a pointer to that memory before updating the Koliseo index. It's up to you to copy your string somewhere else before calling any PUSH operation again, as that memory should be overwritten.

◆ KLS_POP_STR_T

#define KLS_POP_STR_T ( kls_temp,
cstr )
Value:
KLS_POP_ARR_T((kls_temp), char, strlen((cstr)))
#define KLS_POP_ARR_T(kls_temp, type, count)
Macro used to "remove" memory as an array from a Koliseo_Temp.
Definition koliseo.h:635

Macro to "remove" the memory for a C string from a Koliseo_Temp.

Rewinds the pointer by the string's memory and returns a pointer to that memory before updating the Koliseo_Temp index. It's up to you to copy your string somewhere else before calling any PUSH operation again, as that memory should be overwritten.

◆ KLS_POP_T

#define KLS_POP_T ( kls_temp,
type )
Value:
KLS_POP_ARR_T((kls_temp), type, 1)

Macro used to "remove" memory from a Koliseo_Temp.

Rewinds the pointer by the requested type and returns a pointer to that memory before updating the Koliseo_Temp index. It's up to you to copy your item somewhere else before calling any PUSH operation again, as that memory should be overwritten.

◆ KLS_PUSH

#define KLS_PUSH ( kls,
type )
Value:
KLS_PUSH_ARR((kls), type, 1)
#define KLS_PUSH_ARR(kls, type, count)
Macro used to request memory for an array of type values from a Koliseo.
Definition koliseo.h:464

Macro used to request memory from a Koliseo.

◆ KLS_PUSH_ARR

#define KLS_PUSH_ARR ( kls,
type,
count )
Value:
(type*)kls_push_zero_ext((kls), sizeof(type), _Alignof(type), (count))
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

Macro used to request memory for an array of type values from a Koliseo.

◆ KLS_PUSH_ARR_NAMED

#define KLS_PUSH_ARR_NAMED ( kls,
type,
count,
name,
desc )
Value:
KLS_PUSH_ARR((kls),type,(count))

Macro used to request memory for an array of type values from a Koliseo, and assign a name and a description to the region item.

◆ KLS_PUSH_ARR_T

#define KLS_PUSH_ARR_T ( kls_temp,
type,
count )
Value:
(type*)kls_temp_push_zero_ext((kls_temp), sizeof(type), _Alignof(type), (count))
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

Macro used to request memory for an array of type values from a Koliseo_Temp.

◆ KLS_PUSH_ARR_T_NAMED

#define KLS_PUSH_ARR_T_NAMED ( kls_temp,
type,
count,
name,
desc )
Value:
KLS_PUSH_ARR_T((kls_temp),type,(count))
#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:549

Macro used to request memory for an array of type values from a Koliseo_Temp, and assign a name and a description to the region item.

◆ KLS_PUSH_ARR_T_TYPED

#define KLS_PUSH_ARR_T_TYPED ( kls_temp,
type,
count,
region_type,
name,
desc )
Value:
KLS_PUSH_ARR_T((kls_temp),type,(count))

Macro used to request memory for an array of type values from a Koliseo_Temp, and assign a type, a name and a description to the region item.

◆ KLS_PUSH_ARR_TYPED

#define KLS_PUSH_ARR_TYPED ( kls,
type,
count,
region_type,
name,
desc )
Value:
KLS_PUSH_ARR((kls),type,(count))

Macro used to request memory for an array of type values from a Koliseo, and assign a type, a name and a description to the region item.

◆ KLS_PUSH_EX

#define KLS_PUSH_EX ( kls,
type,
name )
Value:
KLS_PUSH_NAMED((kls), type, (name), STRINGIFY(type))
#define STRINGIFY(x)
Definition koliseo.h:87
#define KLS_PUSH_NAMED(kls, type, name, desc)
Macro used to request memory from a Koliseo, and assign a name and a description to the region item.
Definition koliseo.h:500

Macro used to request memory from a Koliseo, and assign a name to the region item.

The description field is automatically filled with the stringized passed type.

◆ KLS_PUSH_NAMED

#define KLS_PUSH_NAMED ( kls,
type,
name,
desc )
Value:
KLS_PUSH_ARR_NAMED((kls), type, 1, (name), (desc))
#define KLS_PUSH_ARR_NAMED(kls, type, count, name, desc)
Definition kls_region.h:223

Macro used to request memory from a Koliseo, and assign a name and a description to the region item.

◆ KLS_PUSH_STR

#define KLS_PUSH_STR ( kls,
cstr )
Value:
KLS_PUSH_ARR((kls), char, strlen((cstr))+1)

Macro to request memory for a C string from a Koliseo.

See also
KLS_STRDUP()

◆ KLS_PUSH_STR_NAMED

#define KLS_PUSH_STR_NAMED ( kls,
cstr,
name,
desc )
Value:
KLS_PUSH_ARR_NAMED((kls), char, strlen((cstr))+1, (name), (desc))

Macro to request memory for a C string from a Koliseo, and assign a name and a description to the region item.

◆ KLS_PUSH_STR_T

#define KLS_PUSH_STR_T ( kls_temp,
cstr )
Value:
KLS_PUSH_ARR_T((kls_temp), char, strlen((cstr))+1)

Macro to request memory for a C string from a Koliseo_Temp.

See also
KLS_STRDUP_T()

◆ KLS_PUSH_STR_T_NAMED

#define KLS_PUSH_STR_T_NAMED ( kls_temp,
cstr,
name,
desc )
Value:
KLS_PUSH_ARR_T_NAMED((kls_temp), char, strlen((cstr))+1, (name), (desc))
#define KLS_PUSH_ARR_T_NAMED(kls_temp, type, count, name, desc)
Definition kls_region.h:229

Macro to request memory for a C string from a Koliseo_Temp, and assign a name and a description to the region item.

◆ KLS_PUSH_STR_T_TYPED

#define KLS_PUSH_STR_T_TYPED ( kls_temp,
cstr,
region_type,
name,
desc )
Value:
KLS_PUSH_ARR_T_TYPED((kls_temp), char, strlen((cstr))+1, (region_type), (name), (desc))
#define KLS_PUSH_ARR_T_TYPED(kls_temp, type, count, region_type, name, desc)
Definition kls_region.h:232

Macro to request memory for a C string from a Koliseo_Temp, and assign a type, a name and a description to the region item.

◆ KLS_PUSH_STR_TYPED

#define KLS_PUSH_STR_TYPED ( kls,
cstr,
region_type,
name,
desc )
Value:
KLS_PUSH_ARR_TYPED((kls), char, strlen((cstr))+1, (region_type), (name), (desc))
#define KLS_PUSH_ARR_TYPED(kls, type, count, region_type, name, desc)
Definition kls_region.h:226

Macro to request memory for a C string from a Koliseo, and assign a type, a name and a description to the region item.

◆ KLS_PUSH_T

#define KLS_PUSH_T ( kls_temp,
type )
Value:
KLS_PUSH_ARR_T((kls_temp), type, 1)

Macro used to request memory from a Koliseo_Temp.

◆ KLS_PUSH_T_EX

#define KLS_PUSH_T_EX ( kls_temp,
type,
name )
Value:
KLS_PUSH_T_NAMED((kls_temp), type, (name), STRINGIFY(type))
#define KLS_PUSH_T_NAMED(kls_temp, type, name, desc)
Macro used to request memory from a Koliseo_Temp, and assign a name and a description to the region i...
Definition koliseo.h:585

Macro used to request memory from a Koliseo_Temp, and assign a name to the region item.

The description field is automatically filled with the stringized passed type.

◆ KLS_PUSH_T_NAMED

#define KLS_PUSH_T_NAMED ( kls_temp,
type,
name,
desc )
Value:
KLS_PUSH_ARR_T_NAMED((kls_temp), type, 1, (name), (desc))

Macro used to request memory from a Koliseo_Temp, and assign a name and a description to the region item.

◆ KLS_PUSH_T_TYPED

#define KLS_PUSH_T_TYPED ( kls_temp,
type,
region_type,
name,
desc )
Value:
KLS_PUSH_ARR_T_TYPED((kls_temp), type, 1, (region_type), (name), (desc))

Macro used to request memory from a Koliseo_Temp, and assign a type, a name and a description to the region item.

◆ KLS_PUSH_T_TYPED_EX

#define KLS_PUSH_T_TYPED_EX ( kls_temp,
type,
region_type,
name )
Value:
KLS_PUSH_T_TYPED((kls_temp), type, (region_type), (name), STRINFIGY(type))
#define KLS_PUSH_T_TYPED(kls_temp, type, region_type, name, desc)
Macro used to request memory from a Koliseo_Temp, and assign a type, a name and a description to the ...
Definition koliseo.h:596

Macro used to request memory from a Koliseo_Temp, and assign a type and a name to the region item.

The description field is automatically filled with the stringized passed type.

◆ KLS_PUSH_TYPED

#define KLS_PUSH_TYPED ( kls,
type,
region_type,
name,
desc )
Value:
KLS_PUSH_ARR_TYPED((kls), type, 1, (region_type), (name), (desc))

Macro used to request memory from a Koliseo, and assign a a type, a name and a description to the region item.

◆ KLS_PUSH_TYPED_EX

#define KLS_PUSH_TYPED_EX ( kls,
type,
region_type,
name )
Value:
KLS_PUSH_TYPED((kls), type, (region_type), (name), STRINGIFY(type))
#define KLS_PUSH_TYPED(kls, type, region_type, name, desc)
Macro used to request memory from a Koliseo, and assign a a type, a name and a description to the reg...
Definition koliseo.h:511

Macro used to request memory from a Koliseo, and assign a type and a name to the region item.

The description field is automatically filled with the stringized passed type.

◆ KLS_Stats_Arg

#define KLS_Stats_Arg ( stats)
Value:
(stats.tot_pushes),(stats.tot_pops),(stats.tot_temp_pushes),(stats.tot_temp_pops),(stats.tot_hiccups),(stats.worst_pushcall_time)

Defines a format macro for KLS_Stats args.

See also
KLS_Stats_Fmt

◆ KLS_Stats_Fmt

#define KLS_Stats_Fmt   "KLS_Stats { tot_pushes: %i, tot_pops: %i, tot_temp_pushes: %i, tot_temp_pops: %i, tot_hiccups: %i, worst_push_time: %.7f }"

Defines a format string for KLS_Stats.

See also
KLS_Stats_Arg()

◆ KLS_STRDUP

#define KLS_STRDUP ( kls,
source )
Value:
kls_strdup((kls), (source))
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:2028

◆ KLS_STRDUP_T

#define KLS_STRDUP_T ( t_kls,
source )
Value:
kls_t_strdup((t_kls), (source))
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:2057

◆ KLSFmt

#define KLSFmt   "KLS {begin: %p, curr: %p, size: %li, offset: %li, has_temp: %i}"

Defines a format string for Koliseo.

See also
KLSArg()

◆ KOLISEO_H_

#define KOLISEO_H_

◆ STRINGIFY

#define STRINGIFY ( x)
Value:
#define STRINGIFY_2(x)
Definition koliseo.h:85

◆ STRINGIFY_2

#define STRINGIFY_2 ( x)
Value:
#x

Typedef Documentation

◆ kls_alloc_func

typedef void * kls_alloc_func(size_t)

Used to select an allocation function for the arena's backing memory.

◆ KLS_Conf

typedef struct KLS_Conf KLS_Conf

Defines flags for Koliseo.

See also
Koliseo

◆ KLS_Err_Handlers

typedef struct KLS_Err_Handlers KLS_Err_Handlers

Defines the handlers used for errors in push calls.

See also
KLS_Conf

◆ kls_free_func

typedef void kls_free_func(void *)

Used to select a free function for the arena's backing memory.

◆ KLS_hook_on_free

typedef void KLS_hook_on_free(struct Koliseo *kls)

Used to pass an extension handler for kls_free().

◆ KLS_hook_on_new

typedef void KLS_hook_on_new(struct Koliseo *kls)

Used to pass an extension handler for kls_new_alloc().

◆ KLS_hook_on_push

typedef void KLS_hook_on_push(struct Koliseo *kls, ptrdiff_t padding, const char *caller, void *user)

Used to pass an extension handler for kls_push().

◆ KLS_hook_on_temp_free

typedef void KLS_hook_on_temp_free(struct Koliseo_Temp *t_kls)

Used to pass an extension handler for kls_temp_end().

◆ KLS_hook_on_temp_push

typedef void KLS_hook_on_temp_push(struct Koliseo_Temp *t_kls, ptrdiff_t padding, const char *caller, void *user)

Used to pass an extension handler for kls_temp_push().

◆ KLS_hook_on_temp_start

typedef void KLS_hook_on_temp_start(struct Koliseo_Temp *t_kls)

Used to pass an extension handler for kls_temp_start().

◆ KLS_Hooks

typedef struct KLS_Hooks KLS_Hooks

◆ KLS_OOM_Handler

typedef void KLS_OOM_Handler(struct Koliseo *kls, ptrdiff_t available, ptrdiff_t padding, ptrdiff_t size, ptrdiff_t count)

Used to pass an error handler for Out-Of-Memory error.

◆ KLS_PTRDIFF_MAX_Handler

typedef void KLS_PTRDIFF_MAX_Handler(struct Koliseo *kls, ptrdiff_t size, ptrdiff_t count)

Used to pass an error handler for count > (PTRDIFF_MAX / size) error.

◆ KLS_Stats

typedef struct KLS_Stats KLS_Stats

Defines a stat struct for Koliseo.

See also
Koliseo

◆ KLS_ZEROCOUNT_Handler

typedef void KLS_ZEROCOUNT_Handler(struct Koliseo *kls, ptrdiff_t available, ptrdiff_t padding, ptrdiff_t size)

Used to pass an error handler for zero-count push call error.

◆ Koliseo

typedef struct Koliseo Koliseo

Represents the initialised arena allocator struct.

See also
kls_new()
kls_clear()
kls_free()
KLS_PUSH()
KLS_POP()

◆ Koliseo_Temp

typedef struct Koliseo_Temp Koliseo_Temp

Represents a savestate for a Koliseo.

See also
kls_temp_start()
kls_temp_end()
KLS_PUSH()
KLS_POP()

Function Documentation

◆ int_koliseo_version()

int int_koliseo_version ( void )

Returns current koliseo version as an integer.

Returns current koliseo version as an integer.

Returns
A constant int in numeric format for current Koliseo version.

◆ kls__check_available_failable()

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.

Checks if the passed Koliseo can fit the requested allocation. In case of errors, tries calling the appropriate handler.

Parameters
klsThe Koliseo to check space for.
sizeThe size of the type to allocate.
alignThe alignment of the type to allocate.
countThe count of allocations.
caller_nameName for caller. Used for error reporting.
Returns
0 for success, other values for errors. May exit of some errors without a custom handler.
See also
Koliseo

◆ kls_clear()

void kls_clear ( Koliseo * kls)

Resets the offset field for the passed Koliseo pointer.

Notably, it sets the prev_offset field to the previous offset, thus remembering where last allocation was before the clear.

Parameters
klsThe Koliseo at hand.

◆ kls_conf_init()

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.

See also
KLS_Conf

◆ kls_conf_init_handled()

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.

Passes custom error handlers for errors in push calls.

See also
KLS_Conf

◆ kls_dbg_features()

void kls_dbg_features ( void )

Prints enabled Koliseo features to stderr.

◆ kls_formatSize()

void kls_formatSize ( ptrdiff_t size,
char * outputBuffer,
size_t bufferSize )

Converts a ptrdiff_t size to human-readable SI units (modulo 1000).

Fills outputBuffer with the converted string.

Parameters
sizeThe size at hand.
outputBufferThe output buffer.
bufferSizeThe output buffer size.

◆ kls_free()

void kls_free ( Koliseo * kls)

Calls kls_clear() on the passed Koliseo pointer and the frees the actual Koliseo.

Parameters
klsThe Koliseo at hand.
See also
kls_clear()

◆ kls_get_pos()

ptrdiff_t kls_get_pos ( const Koliseo * kls)

Returns the current offset (position of pointer bumper) for the passed Koliseo.

Parameters
klsThe Koliseo at hand.
Returns
A ptrdiff_t value for current position.

◆ kls_log()

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.kls_verbose_lvl is >0.

Parameters
klsThe Koliseo pointer hosting the log_fp FILE pointer.
tagTag for a message.
formatThe message format string.

◆ kls_new()

Koliseo * kls_new ( ptrdiff_t size)

Takes a ptrdiff_t size.

Allocates the backing memory for a Koliseo. Sets the KLS_Conf field to KLS_DEFAULT_CONF. Sets the fields with appropriate values if memory allocation was successful, goes to exit() otherwise.

Parameters
sizeThe size for Koliseo data field.
Returns
A pointer to the initialised Koliseo struct.
See also
Koliseo
Koliseo_Temp
KLS_DEFAULT_CONF
kls_new_alloc()

◆ kls_new_alloc()

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.

Allocates the backing memory for a Koliseo. Sets the KLS_Conf field to KLS_DEFAULT_CONF. Sets the fields with appropriate values if memory allocation was successful, goes to exit() otherwise.

Parameters
sizeThe size for Koliseo data field.
alloc_funcThe allocation function to use to init the Koliseo.
Returns
A pointer to the initialised Koliseo struct.
See also
Koliseo
Koliseo_Temp
KLS_DEFAULT_CONF
kls_new()
kls_temp_start()
kls_temp_end()

◆ kls_new_alloc_ext()

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.

Additional arguments are for extensions. Allocates the backing memory for a Koliseo. Sets the KLS_Conf field to KLS_DEFAULT_CONF. Sets the fields with appropriate values if memory allocation was successful, goes to exit() otherwise.

Parameters
sizeThe size for Koliseo data field.
alloc_funcThe allocation function to use to init the Koliseo.
Returns
A pointer to the initialised Koliseo struct.
See also
Koliseo
Koliseo_Temp
KLS_DEFAULT_CONF
KLS_Hooks
kls_new()
kls_temp_start()
kls_temp_end()

◆ kls_new_conf()

Koliseo * kls_new_conf ( ptrdiff_t size,
KLS_Conf conf )

Takes a ptrdiff_t size and a KLS_Conf to configure the new Koliseo.

Returns the new Koliseo.

Parameters
sizeThe size for Koliseo data field.
confThe KLS_Conf for the new Koliseo.
Returns
A pointer to the initialised Koliseo struct, with wanted config.
See also
Koliseo
KLS_Conf
KLS_DEFAULT_CONF
kls_new_alloc_ext()

◆ kls_new_conf_alloc()

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 free function pointer.

Additional arguments are for extensions. Calls kls_new_alloc() to initialise the Koliseo, then calls kls_set_conf() to update the config. Returns the new Koliseo.

Parameters
sizeThe size for Koliseo data field.
confThe KLS_Conf for the new Koliseo.
alloc_funcThe allocation function to use.
free_funcThe free function to use.
Returns
A pointer to the initialised Koliseo struct, with wanted config.
See also
Koliseo
KLS_Conf
KLS_DEFAULT_CONF
kls_new_alloc()
kls_set_conf()

◆ kls_new_conf_alloc_ext()

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 free function pointer.

Additional arguments are for extensions. Calls kls_new_alloc() to initialise the Koliseo, then calls kls_set_conf() to update the config. Returns the new Koliseo.

Parameters
sizeThe size for Koliseo data field.
confThe KLS_Conf for the new Koliseo.
alloc_funcThe allocation function to use.
free_funcThe free function to use.
Returns
A pointer to the initialised Koliseo struct, with wanted config.
See also
Koliseo
KLS_Conf
KLS_DEFAULT_CONF
kls_new_alloc_ext()
kls_set_conf()

◆ kls_new_conf_ext()

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.

Additional arguments are for extensions. Returns the new Koliseo.

Parameters
sizeThe size for Koliseo data field.
confThe KLS_Conf for the new Koliseo.
Returns
A pointer to the initialised Koliseo struct, with wanted config.
See also
Koliseo
KLS_Conf
KLS_DEFAULT_CONF
kls_new_alloc_ext()

◆ kls_new_dbg()

Koliseo * kls_new_dbg ( ptrdiff_t size)

Takes a ptrdiff_t size and returns a pointer to the prepared Koliseo.

Calls kls_new_conf_alloc() to initialise the Koliseo with the proper config for a debug Koliseo (printing to stderr).

Parameters
sizeThe size for Koliseo data field.
Returns
A pointer to the initialised Koliseo struct, with wanted config.
See also
Koliseo
KLS_Conf
kls_new_conf()

◆ kls_new_dbg_alloc()

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, and returns a pointer to the prepared Koliseo.

Calls kls_new_conf_alloc() to initialise the Koliseo with the proper config for a debug Koliseo (printing to stderr).

Parameters
sizeThe size for Koliseo data field.
alloc_funcThe allocation function to use.
free_funcThe free function to use.
Returns
A pointer to the initialised Koliseo struct, with wanted config.
See also
Koliseo
KLS_Conf
kls_new_conf()

◆ kls_new_dbg_alloc_handled()

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, and returns a pointer to the prepared Koliseo.

Calls kls_new_conf_alloc() to initialise the Koliseo with the proper config for a debug Koliseo (printing to stderr).

Parameters
sizeThe size for Koliseo data field.
alloc_funcThe allocation function to use.
free_funcThe free function to use.
err_handlersThe error handlers for errors in push calls.
Returns
A pointer to the initialised Koliseo struct, with wanted config.
See also
Koliseo
KLS_Conf
kls_new_conf()

◆ kls_new_dbg_alloc_handled_ext()

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, and returns a pointer to the prepared Koliseo.

Additional arguments are for extensions. Calls kls_new_conf_alloc() to initialise the Koliseo with the proper config for a debug Koliseo (printing to stderr).

Parameters
sizeThe size for Koliseo data field.
alloc_funcThe allocation function to use.
free_funcThe free function to use.
err_handlersThe error handlers for errors in push calls.
Returns
A pointer to the initialised Koliseo struct, with wanted config.
See also
Koliseo
KLS_Conf
kls_new_conf_alloc_ext()

◆ kls_new_dbg_ext()

Koliseo * kls_new_dbg_ext ( ptrdiff_t size,
KLS_Hooks * ext_handlers,
void ** user,
size_t ext_len )

Takes a ptrdiff_t size.

Additional arguments are for extensions. Calls kls_new_conf_alloc() to initialise the Koliseo with the proper config for a debug Koliseo (printing to stderr).

Parameters
sizeThe size for Koliseo data field.
Returns
A pointer to the initialised Koliseo struct, with wanted config.
See also
Koliseo
KLS_Conf
kls_new_conf()

◆ kls_new_dbg_handled()

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.

Calls kls_new_conf_alloc() to initialise the Koliseo with the proper config for a debug Koliseo (printing to stderr).

Parameters
sizeThe size for Koliseo data field.
err_handlersThe error handlers for errors in push calls.
Returns
A pointer to the initialised Koliseo struct, with wanted config.
See also
Koliseo
KLS_Conf
kls_new_conf()

◆ kls_new_traced()

Koliseo * kls_new_traced ( ptrdiff_t size,
const char * output_path )

Takes a ptrdiff_t size and a filepath for the trace output file.

Returns a pointer to the prepared Koliseo. Calls kls_new_conf_alloc() to initialise the Koliseo with the proper config for a traced Koliseo, logging to the passed filepath.

Parameters
sizeThe size for Koliseo data field.
output_pathThe filepath for log output.
Returns
A pointer to the initialised Koliseo struct, with wanted config.
See also
Koliseo
KLS_Conf
kls_new_conf_alloc()

◆ kls_new_traced_alloc()

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 free function pointer.

Returns a pointer to the prepared Koliseo. Calls kls_new_conf_alloc() to initialise the Koliseo with the proper config for a traced Koliseo, logging to the passed filepath.

Parameters
sizeThe size for Koliseo data field.
output_pathThe filepath for log output.
alloc_funcThe allocation function to use.
free_funcThe free function to use.
Returns
A pointer to the initialised Koliseo struct, with wanted config.
See also
Koliseo
KLS_Conf
kls_new_conf_alloc()

◆ kls_new_traced_alloc_handled()

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 free function pointer.

Returns a pointer to the prepared Koliseo. Calls kls_new_conf_alloc() to initialise the Koliseo with the proper config for a traced Koliseo, logging to the passed filepath.

Parameters
sizeThe size for Koliseo data field.
output_pathThe filepath for log output.
alloc_funcThe allocation function to use.
free_funcThe free function to use.
err_handlersThe error handlers struct for errors in push calls.
Returns
A pointer to the initialised Koliseo struct, with wanted config.
See also
Koliseo
KLS_Conf
kls_new_conf_alloc()

◆ kls_new_traced_alloc_handled_ext()

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 free function pointer.

Additional arguments are for extensions. Returns a pointer to the prepared Koliseo. Calls kls_new_conf_alloc() to initialise the Koliseo with the proper config for a traced Koliseo, logging to the passed filepath.

Parameters
sizeThe size for Koliseo data field.
output_pathThe filepath for log output.
alloc_funcThe allocation function to use.
free_funcThe free function to use.
err_handlersThe error handlers struct for errors in push calls.
Returns
A pointer to the initialised Koliseo struct, with wanted config.
See also
Koliseo
KLS_Conf
kls_new_conf_alloc_ext()

◆ kls_new_traced_ext()

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.

Additional arguments are for extensions. Returns a pointer to the prepared Koliseo. Calls kls_new_conf_alloc() to initialise the Koliseo with the proper config for a traced Koliseo, logging to the passed filepath.

Parameters
sizeThe size for Koliseo data field.
output_pathThe filepath for log output.
Returns
A pointer to the initialised Koliseo struct, with wanted config.
See also
Koliseo
KLS_Conf
kls_new_conf_alloc()

◆ kls_new_traced_handled()

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.

Returns a pointer to the prepared Koliseo. Calls kls_new_conf_alloc() to initialise the Koliseo with the proper config for a traced Koliseo, logging to the passed filepath.

Parameters
sizeThe size for Koliseo data field.
output_pathThe filepath for log output.
err_handlersThe error handlers struct for errors in push calls.
Returns
A pointer to the initialised Koliseo struct, with wanted config.
See also
Koliseo
KLS_Conf
kls_new_conf_alloc()

◆ KLS_OOM_default_handler__()

void KLS_OOM_default_handler__ ( Koliseo * kls,
ptrdiff_t available,
ptrdiff_t padding,
ptrdiff_t size,
ptrdiff_t count )

Used by default when no handler is passed.

Used by default when no handler is passed.

Parameters
klsThe Koliseo used in the push call
availableThe Koliseo's available memory
paddingThe current push call's padding
sizeThe current push call's size
countThe current push call's count
See also
KLS_Conf

◆ kls_pop()

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.

Tries popping the specified amount of memory from the Koliseo data field, marking it as free (as far as Koliseo is concerned), or goes to exit() if the operation fails.

Parameters
klsThe Koliseo at hand.
sizeThe size for data to pop.
alignThe alignment for data to pop.
countThe multiplicative quantity to scale data size to pop for.
Returns
A void pointer to the start of memory just popped from the Koliseo.

◆ kls_pop_AR()

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.

Tries popping the specified amount of memory from the Koliseo data field, marking it as free (as far as Koliseo is concerned), or goes to exit() if the operation fails.

Parameters
klsThe Koliseo at hand.
sizeThe size for data to pop.
alignThe alignment for data to pop.
countThe multiplicative quantity to scale data size to pop for.
Returns
A void pointer to the start of memory just popped from the Koliseo.

◆ KLS_PTRDIFF_MAX_default_handler__()

void KLS_PTRDIFF_MAX_default_handler__ ( struct Koliseo * kls,
ptrdiff_t size,
ptrdiff_t count )

Used by default when no handler is passed.

◆ kls_push_zero()

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.

Tries pushing the specified amount of memory to the Koliseo data field, or goes to exit() if the operation fails. Notably, it zeroes the memory region.

Parameters
klsThe Koliseo at hand.
sizeThe size for data to push.
alignThe alignment for data to push.
countThe multiplicative quantity to scale data size to push for.
Returns
A void pointer to the start of memory just pushed to the Koliseo, or NULL for errors.

◆ kls_push_zero_ext()

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.

Tries pushing the specified amount of memory to the Koliseo data field, or goes to exit() if the operation fails. Notably, it zeroes the memory region.

Parameters
klsThe Koliseo at hand.
sizeThe size for data to push.
alignThe alignment for data to push.
countThe multiplicative quantity to scale data size to push for.
Returns
A void pointer to the start of memory just pushed to the Koliseo, or NULL for errors.

◆ kls_strdup()

char * kls_strdup ( Koliseo * kls,
char * source )

Function to dupe a C string to a Koliseo, and return a pointer to the allocated string.

Unsafe, do not use.

See also
KLS_PUSH_STR()
KLS__STRCPY()

◆ kls_strdup_arr()

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.

Unsafe, do not use.

See also
KLS_STRDUP()
KLS__STRCPY()

◆ kls_t_strdup()

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.

Unsafe, do not use.

See also
KLS_PUSH_STR_T()
KLS__STRCPY()

◆ kls_t_strdup_arr()

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.

Unsafe, do not use.

See also
KLS_STRDUP_T()
KLS__STRCPY()

◆ kls_temp_end()

void kls_temp_end ( Koliseo_Temp * tmp_kls)

Ends passed Koliseo_Temp pointer.

Parameters
tmp_klsThe Koliseo_Temp at hand.

◆ kls_temp_pop()

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.

Tries popping the specified amount of memory from the Koliseo data field, marking it as free (as far as Koliseo is concerned), or goes to exit() if the operation fails.

Parameters
t_klsThe Koliseo_Temp at hand.
sizeThe size for data to pop.
alignThe alignment for data to pop.
countThe multiplicative quantity to scale data size to pop for.
Returns
A void pointer to the start of memory just popped from the referred Koliseo.

◆ kls_temp_pop_AR()

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.

Tries popping the specified amount of memory from the Koliseo data field, marking it as free (as far as Koliseo is concerned), or goes to exit() if the operation fails.

Parameters
t_klsThe Koliseo_Temp at hand.
sizeThe size for data to pop.
alignThe alignment for data to pop.
countThe multiplicative quantity to scale data size to pop for.
Returns
A void pointer to the start of memory just popped from the referred Koliseo.

◆ kls_temp_push_zero_ext()

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.

Tries pushing the specified amount of memory to the referred Koliseo data field, or goes to exit() if the operation fails. Notably, it zeroes the memory region. Will be removed in 0.6, leaving kls_temp_push_zero_ext() as its replacement.

Parameters
t_klsThe Koliseo_Temp at hand.
sizeThe size for data to push.
alignThe alignment for data to push.
countThe multiplicative quantity to scale data size to push for.
Returns
A void pointer to the start of memory just pushed to the referred Koliseo.

◆ kls_temp_start()

Koliseo_Temp * kls_temp_start ( Koliseo * kls)

Starts a new savestate for the passed Koliseo pointer, by initialising its Koliseo_Temp pointer and returning it.

Notably, you should not use the original while using the copy.

Parameters
klsThe Koliseo at hand.
Returns
A Koliseo_Temp struct.
See also
Koliseo_Temp

◆ KLS_ZEROCOUNT_default_handler__()

void KLS_ZEROCOUNT_default_handler__ ( Koliseo * kls,
ptrdiff_t available,
ptrdiff_t padding,
ptrdiff_t size )

Used by default when no handler is passed.

Used by default when no handler is passed.

By default, it goes to exit().

Parameters
klsThe Koliseo used in the push call
availableThe Koliseo's available memory
paddingThe current push call's padding
sizeThe current push call's size
See also
KLS_Conf

◆ print_dbg_kls()

void print_dbg_kls ( const Koliseo * kls)

Prints header fields from the passed Koliseo pointer, to stderr.

Parameters
klsThe Koliseo at hand.

◆ print_dbg_temp_kls()

void print_dbg_temp_kls ( const Koliseo_Temp * t_kls)

Prints header fields from the passed Koliseo_Temp pointer, to stderr.

Parameters
t_klsThe Koliseo_Temp at hand.

◆ print_kls_2file()

void print_kls_2file ( FILE * fp,
const Koliseo * kls )

Prints header fields from the passed Koliseo pointer, to the passed FILE pointer.

Parameters
fpThe FILE pointer to print to.
klsThe Koliseo at hand.

◆ print_temp_kls_2file()

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.

Parameters
fpThe FILE pointer to print to.
t_klsThe Koliseo_Temp at hand.

◆ string_koliseo_version()

const char * string_koliseo_version ( void )

Returns current koliseo version as a string.

Returns current koliseo version as a string.

Returns
A constant string in MAJOR-MINOR-PATCH format for current Koliseo version.

Variable Documentation

◆ KLS_DEFAULT_CONF

KLS_Conf KLS_DEFAULT_CONF
extern

Default KLS_Conf used by kls_new().

See also
kls_new()
KLS_Conf

Default KLS_Conf used by kls_new().

◆ KLS_STATS_DEFAULT

KLS_Stats KLS_STATS_DEFAULT
extern

Default KLS_Stats values, used by kls_new().

See also
kls_new()
KLS_Stats