koliseo 0.4.3
Loading...
Searching...
No Matches
koliseo.c File Reference
#include "koliseo.h"

Functions

void kls_print_title_2file (FILE *fp)
 Prints the title banner to the passed FILE pointer.
 
void kls_print_title (void)
 Prints the title banner to stdout.
 
const char * string_koliseo_version (void)
 Returns the constant string representing current version for Koliseo.
 
int int_koliseo_version (void)
 Returns the constant int representing current version for Koliseo.
 
const char * kls_reglist_backend_string (KLS_RegList_Alloc_Backend kls_be)
 
KLS_Conf kls_conf_init (int autoset_regions, int alloc_backend, ptrdiff_t reglist_kls_size, int autoset_temp_regions, int collect_stats, int verbose_lvl, 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.
 
ptrdiff_t kls_get_pos (const Koliseo *kls)
 Returns the current offset (position of pointer bumper) for the passed Koliseo.
 
int kls_get_maxRegions_KLS_BASIC (Koliseo *kls)
 Calcs the max number of possible KLS_PUSH ops when using KLS_BASIC reglist alloc backend.
 
int kls_temp_get_maxRegions_KLS_BASIC (Koliseo_Temp *t_kls)
 Calcs the max number of possible KLS_PUSH_T ops when using KLS_BASIC reglist alloc backend.
 
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.
 
Koliseo * kls_new_alloc (ptrdiff_t size, kls_alloc_func alloc_func)
 Takes a ptrdiff_t size and a function pointer to the allocation function.
 
Koliseo * kls_new_conf_alloc (ptrdiff_t size, KLS_Conf conf, kls_alloc_func alloc_func)
 Takes a ptrdiff_t size, a KLS_Conf to configure the new Koliseo, and an allocation function pointer.
 
Koliseo * kls_new_traced_alloc (ptrdiff_t size, const char *output_path, kls_alloc_func alloc_func)
 Takes a ptrdiff_t size, a filepath for the trace output file, and an allocation function pointer.
 
Koliseo * kls_new_dbg_alloc (ptrdiff_t size, kls_alloc_func alloc_func)
 Takes a ptrdiff_t size and an allocation function pointer, and returns a pointer to the prepared Koliseo.
 
Koliseo * kls_new_traced_AR_KLS_alloc (ptrdiff_t size, const char *output_path, ptrdiff_t reglist_kls_size, kls_alloc_func alloc_func)
 Takes a ptrdiff_t size and a filepath for the trace output file, and the needed parameters for a successful init of the prepared Koliseo.
 
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.
 
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_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_push_zero_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.
 
void * kls_push_zero_named (Koliseo *kls, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count, char *name, char *desc)
 Takes a Koliseo pointer, and ptrdiff_t values for size, align and count.
 
void * kls_temp_push_zero_named (Koliseo_Temp *t_kls, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count, char *name, char *desc)
 Takes a Koliseo_Temp, and ptrdiff_t values for size, align and count.
 
void * kls_push_zero_typed (Koliseo *kls, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count, int type, char *name, char *desc)
 Takes a Koliseo pointer, a KLS_Region_Type index, and ptrdiff_t values for size, align and count.
 
void * kls_temp_push_zero_typed (Koliseo_Temp *t_kls, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count, int type, char *name, char *desc)
 Takes a Koliseo_Temp, a KLS_Region_Type index, and ptrdiff_t values for size, align and count.
 
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 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_formatSize (ptrdiff_t size, char *outputBuffer, size_t bufferSize)
 Converts a ptrdiff_t size to human-readable SI units (modulo 1000).
 
void kls_show_toWin (Koliseo *kls, WINDOW *win)
 Prints fields and eventually KLS_Region_List from the passed Koliseo pointer, to the passed WINDOW pointer.
 
void kls_temp_show_toWin (Koliseo_Temp *t_kls, WINDOW *win)
 Takes a Koliseo_Temp pointer and prints fields and eventually KLS_Region_List from the referred Koliseo pointer, to the passed WINDOW pointer.
 
void kls_showList_toWin (Koliseo *kls, WINDOW *win)
 Displays a slideshow of KLS_Region_List from passed Koliseo, to the passed WINDOW pointer.
 
void kls_temp_showList_toWin (Koliseo_Temp *t_kls, WINDOW *win)
 Displays a slideshow of KLS_Region_List from passed Koliseo_Temp, to the passed WINDOW pointer.
 
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.
 
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.
 
bool kls_temp_set_conf (Koliseo_Temp *t_kls, KLS_Temp_Conf conf)
 Updates the KLS_Temp_Conf for the passed Koliseo_Temp pointer.
 
void kls_temp_end (Koliseo_Temp *tmp_kls)
 Ends passed Koliseo_Temp pointer.
 
KLS_Region_List kls_rl_emptyList (void)
 
bool kls_rl_empty (KLS_Region_List l)
 
KLS_list_element kls_rl_head (KLS_Region_List l)
 
KLS_Region_List kls_rl_tail (KLS_Region_List l)
 
KLS_Region_List kls_rl_cons (Koliseo *kls, KLS_list_element e, KLS_Region_List l)
 
KLS_region_list_item * kls_list_pop (Koliseo *kls)
 
KLS_Region_List kls_rl_t_cons (Koliseo_Temp *t_kls, KLS_list_element e, KLS_Region_List l)
 
KLS_region_list_item * kls_t_list_pop (Koliseo_Temp *t_kls)
 
void kls_rl_freeList (KLS_Region_List l)
 Frees all values and nodes for passed Region list.
 
void kls_rl_showList_toFile (KLS_Region_List l, FILE *fp)
 
void kls_rl_showList (KLS_Region_List l)
 
bool kls_rl_member (KLS_list_element el, KLS_Region_List l)
 
int kls_rl_length (KLS_Region_List l)
 
KLS_Region_List kls_rl_append (Koliseo *kls, KLS_Region_List l1, KLS_Region_List l2)
 
KLS_Region_List kls_rl_reverse (Koliseo *kls, KLS_Region_List l)
 
KLS_Region_List kls_rl_copy (Koliseo *kls, KLS_Region_List l)
 
KLS_Region_List kls_rl_delete (Koliseo *kls, KLS_list_element el, KLS_Region_List l)
 
KLS_Region_List kls_rl_insord (Koliseo *kls, KLS_list_element el, KLS_Region_List l)
 
KLS_Region_List kls_rl_insord_p (Koliseo *kls, KLS_list_element el, KLS_Region_List l)
 
KLS_Region_List kls_rl_mergeList (Koliseo *kls, KLS_Region_List l1, KLS_Region_List l2)
 
KLS_Region_List kls_rl_intersect (Koliseo *kls, KLS_Region_List l1, KLS_Region_List l2)
 
KLS_Region_List kls_rl_diff (Koliseo *kls, KLS_Region_List l1, KLS_Region_List l2)
 
bool kls_rl_isLess (KLS_Region *r1, KLS_Region *r2)
 Compares two regions and returns true if the first one has a smaller size.
 
bool kls_rl_isEqual (KLS_Region *r1, KLS_Region *r2)
 Compares two regions and returns true if their size is equal.
 
double kls_usageShare (KLS_Region *r, Koliseo *kls)
 Returns the ratio of memory used by the passed KLS_Region relative to the passed Koliseo as a double.
 
ptrdiff_t kls_regionSize (KLS_Region *r)
 Return size of a passed KLS_Region.
 
ptrdiff_t kls_avg_regionSize (Koliseo *kls)
 Return average region size in usage for the passed Koliseo.
 
void kls_usageReport_toFile (Koliseo *kls, FILE *fp)
 Prints an usage report for the passed Koliseo to the passed file.
 
void kls_usageReport (Koliseo *kls)
 Print usage report for passed Koliseo to stdout.
 
ptrdiff_t kls_type_usage (int type, Koliseo *kls)
 Calc memory used by the specific type of KLS_list_element.
 
const char * string_from_Gulp_Res (Gulp_Res g)
 Return a constant string for the passed Gulp_Res.
 
Kstr kstr_new (const char *data, size_t len)
 Returns a new Kstr with the passed args set.
 
Kstr kstr_from_c_lit (const char *c_lit)
 Returns a new Kstr from the passed null-terminated string.
 
bool kstr_eq (Kstr left, Kstr right)
 Checks if the two passed Kstr have exactly equal data.
 
bool kstr_eq_ignorecase (Kstr left, Kstr right)
 Checks if the two passed Kstr have equal data, ignoring case.
 
Kstr kstr_cut_l (Kstr *k, size_t n)
 Cuts the passed Kstr by up to n chars, from the left.
 
Kstr kstr_cut_r (Kstr *k, size_t n)
 Cuts the passed Kstr by up to n chars, from the right.
 
Kstr kstr_trim_left (Kstr kstr)
 Returns a new Kstr after removing heading spaces from the passed one.
 
Kstr kstr_trim_right (Kstr kstr)
 Returns a new Kstr after removing trailing spaces from the passed one.
 
Kstr kstr_trim (Kstr kstr)
 Returns a new Kstr after removing heading and trailing spaces from the passed one.
 
bool kstr_indexof (Kstr k, char c, int *idx)
 Checks if passed Kstr contains the passed char, and if so, sets the value pointed by idx to the first occurrence.
 
bool kstr_try_token (Kstr *k, char delim, Kstr *part)
 Scans the first passed Kstr and if the passed char is present, the old Kstr is set to second pointer and the first one is cut at the first occurrence of it.
 
Kstr kstr_token (Kstr *k, char delim)
 Scans the passed Kstr and cuts it up to the first occurrence of passed char, even if it is not present.
 
Kstr kstr_token_kstr (Kstr *k, Kstr delim)
 
char * kls_gulp_file_sized (Koliseo *kls, const char *filepath, Gulp_Res *err, size_t max_size)
 Tries mapping the passed file on the Koliseo.
 
char * try_kls_gulp_file (Koliseo *kls, const char *filepath, size_t max_size)
 Tries mapping the passed file on the Koliseo.
 
Kstr * kls_gulp_file_sized_to_kstr (Koliseo *kls, const char *filepath, Gulp_Res *err, size_t max_size, bool allow_nullchar)
 Tries mapping the passed file on the Koliseo.
 
Kstr * try_kls_gulp_file_to_kstr (Koliseo *kls, const char *filepath, size_t max_size, bool allow_nullchar)
 Tries mapping the passed file on the Koliseo.
 
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
 
KLS_Stats KLS_STATS_DEFAULT
 
const char * kls_reglist_backend_strings [KLS_REGLIST_TOTAL_BACKENDS]
 
char * kls_title [KLS_TITLEROWS+1]
 Defines title banner.
 
const char * gulp_res_names [TOT_GULP_RES+1]
 Contains the constant string representation of Gulp_Res values.
 

Function Documentation

◆ int_koliseo_version()

int int_koliseo_version ( void )

Returns the constant int representing current version for Koliseo.

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

◆ kls_avg_regionSize()

ptrdiff_t kls_avg_regionSize ( Koliseo * kls)

Return average region size in usage for the passed Koliseo.

Parameters
klsThe Koliseo to check usage for.
Returns
Average region size as ptrdiff_t.

◆ 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 autoset_regions,
int alloc_backend,
ptrdiff_t reglist_kls_size,
int autoset_temp_regions,
int collect_stats,
int verbose_lvl,
FILE * log_fp,
const char * log_filepath )

Used to prepare a KLS_Conf without caring about KOLISEO_HAS_REGIONS.

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_maxRegions_KLS_BASIC()

int kls_get_maxRegions_KLS_BASIC ( Koliseo * kls)

Calcs the max number of possible KLS_PUSH ops when using KLS_BASIC reglist alloc backend.

Returns
The max number of push ops possible, or -1 in case of error.

◆ 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_gulp_file_sized()

char * kls_gulp_file_sized ( Koliseo * kls,
const char * filepath,
Gulp_Res * err,
size_t max_size )

Tries mapping the passed file on the Koliseo.

Sets the passed Gulp_Res to the result of the operation, .

Parameters
klsThe Koliseo to push to.
filepathPath to the file to gulp.
errPointer to the Gulp_Res variable to store result.
max_sizeMax size allowed for the read file.
See also
KLS_GULP_FILE()

◆ kls_gulp_file_sized_to_kstr()

Kstr * kls_gulp_file_sized_to_kstr ( Koliseo * kls,
const char * filepath,
Gulp_Res * err,
size_t max_size,
bool allow_nullchar )

Tries mapping the passed file on the Koliseo.

Sets the passed Gulp_Res to the result of the operation.

Parameters
klsThe Koliseo to push to.
filepathPath to the file to gulp.
errPointer to the Gulp_Res variable to store result.
max_sizeMax size allowed for the read file.
allow_nullcharBool to avoid returning NULL for a binary file.
See also
KLS_GULP_FILE()
Returns
A Kstr for the passed filepath contents.

◆ kls_list_pop()

KLS_region_list_item * kls_list_pop ( Koliseo * kls)

◆ 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_alloc()

Koliseo * kls_new_alloc ( ptrdiff_t size,
kls_alloc_func alloc_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.
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_conf_alloc()

Koliseo * kls_new_conf_alloc ( ptrdiff_t size,
KLS_Conf conf,
kls_alloc_func alloc_func )

Takes a ptrdiff_t size, a KLS_Conf to configure the new Koliseo, and an allocation function pointer.

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.
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_dbg_alloc()

Koliseo * kls_new_dbg_alloc ( ptrdiff_t size,
kls_alloc_func alloc_func )

Takes a ptrdiff_t size and an allocation 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.
Returns
A pointer to the initialised Koliseo struct, with wanted config.
See also
Koliseo
KLS_Conf
kls_new_conf()

◆ kls_new_traced_alloc()

Koliseo * kls_new_traced_alloc ( ptrdiff_t size,
const char * output_path,
kls_alloc_func alloc_func )

Takes a ptrdiff_t size, a filepath for the trace output file, and an allocation 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.
Returns
A pointer to the initialised Koliseo struct, with wanted config.
See also
Koliseo
KLS_Conf
kls_new_conf_alloc()

◆ kls_new_traced_AR_KLS_alloc()

Koliseo * kls_new_traced_AR_KLS_alloc ( ptrdiff_t size,
const char * output_path,
ptrdiff_t reglist_kls_size,
kls_alloc_func alloc_func )

Takes a ptrdiff_t size and a filepath for the trace output file, and the needed parameters for a successful init of 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.
reglist_kls_sizeThe size to use for the inner reglist Koliseo.
alloc_funcThe allocation function to use.
Returns
A pointer to the initialised Koliseo struct, with wanted config.
See also
Koliseo
KLS_Conf
kls_new_conf_alloc()

◆ 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_print_title()

void kls_print_title ( void )

Prints the title banner to stdout.

See also
kls_title

◆ kls_print_title_2file()

void kls_print_title_2file ( FILE * fp)

Prints the title banner to the passed FILE pointer.

See also
kls_title
Parameters
fpThe FILE to print to.

◆ kls_push()

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.

Tries pushing the specified amount of memory to the Koliseo data field, or goes to exit() if the operation fails. Notably, it does NOT zero 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.

◆ 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.

◆ kls_push_zero_AR()

void * kls_push_zero_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 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.

◆ kls_push_zero_named()

void * kls_push_zero_named ( Koliseo * kls,
ptrdiff_t size,
ptrdiff_t align,
ptrdiff_t count,
char * name,
char * desc )

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. Uses the passed name and desc fields to initialise the allocated KLS_Region fields. 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.
nameThe name to assign to the resulting KLS_Region.
descThe desc to assign to the resulting KLS_Region.
Returns
A void pointer to the start of memory just pushed to the Koliseo.

◆ kls_push_zero_typed()

void * kls_push_zero_typed ( Koliseo * kls,
ptrdiff_t size,
ptrdiff_t align,
ptrdiff_t count,
int type,
char * name,
char * desc )

Takes a Koliseo pointer, a KLS_Region_Type index, 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. Uses the passed name and desc fields to initialise the allocated KLS_Region fields. 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.
typeThe type index for pushed KLS_Region.
nameThe name to assign to the resulting KLS_Region.
descThe desc to assign to the resulting KLS_Region.
Returns
A void pointer to the start of memory just pushed to the referred Koliseo.

◆ kls_regionSize()

ptrdiff_t kls_regionSize ( KLS_Region * r)

Return size of a passed KLS_Region.

Sugar.

Parameters
rThe KLS_Region.
Returns
Region size as ptrdiff_t.

◆ kls_reglist_backend_string()

const char * kls_reglist_backend_string ( KLS_RegList_Alloc_Backend kls_be)

◆ kls_rl_append()

KLS_Region_List kls_rl_append ( Koliseo * kls,
KLS_Region_List l1,
KLS_Region_List l2 )

◆ kls_rl_cons()

KLS_Region_List kls_rl_cons ( Koliseo * kls,
KLS_list_element e,
KLS_Region_List l )

◆ kls_rl_copy()

KLS_Region_List kls_rl_copy ( Koliseo * kls,
KLS_Region_List l )

◆ kls_rl_delete()

KLS_Region_List kls_rl_delete ( Koliseo * kls,
KLS_list_element el,
KLS_Region_List l )

◆ kls_rl_diff()

KLS_Region_List kls_rl_diff ( Koliseo * kls,
KLS_Region_List l1,
KLS_Region_List l2 )

◆ kls_rl_empty()

bool kls_rl_empty ( KLS_Region_List l)

◆ kls_rl_emptyList()

KLS_Region_List kls_rl_emptyList ( void )

◆ kls_rl_freeList()

void kls_rl_freeList ( KLS_Region_List l)

Frees all values and nodes for passed Region list.

Should only be used internally for operations with ALLOC_LIBC for allocation backend.

Parameters
lThe list to free (allocated by using malloc).

◆ kls_rl_head()

KLS_list_element kls_rl_head ( KLS_Region_List l)

◆ kls_rl_insord()

KLS_Region_List kls_rl_insord ( Koliseo * kls,
KLS_list_element el,
KLS_Region_List l )

◆ kls_rl_insord_p()

KLS_Region_List kls_rl_insord_p ( Koliseo * kls,
KLS_list_element el,
KLS_Region_List l )

◆ kls_rl_intersect()

KLS_Region_List kls_rl_intersect ( Koliseo * kls,
KLS_Region_List l1,
KLS_Region_List l2 )

◆ kls_rl_isEqual()

bool kls_rl_isEqual ( KLS_Region * r1,
KLS_Region * r2 )

Compares two regions and returns true if their size is equal.

Parameters
r1The first KLS_Region
r2The second KLS_Region
Returns
True if first region size is equal than second region size.

◆ kls_rl_isLess()

bool kls_rl_isLess ( KLS_Region * r1,
KLS_Region * r2 )

Compares two regions and returns true if the first one has a smaller size.

Parameters
r1The KLS_Region expected to be smaller
r2The KLS_Region expected to be bigger
Returns
True if first region size is less than second region size.

◆ kls_rl_length()

int kls_rl_length ( KLS_Region_List l)

◆ kls_rl_member()

bool kls_rl_member ( KLS_list_element el,
KLS_Region_List l )

◆ kls_rl_mergeList()

KLS_Region_List kls_rl_mergeList ( Koliseo * kls,
KLS_Region_List l1,
KLS_Region_List l2 )

◆ kls_rl_reverse()

KLS_Region_List kls_rl_reverse ( Koliseo * kls,
KLS_Region_List l )

◆ kls_rl_showList()

void kls_rl_showList ( KLS_Region_List l)

◆ kls_rl_showList_toFile()

void kls_rl_showList_toFile ( KLS_Region_List l,
FILE * fp )

◆ kls_rl_t_cons()

KLS_Region_List kls_rl_t_cons ( Koliseo_Temp * t_kls,
KLS_list_element e,
KLS_Region_List l )

◆ kls_rl_tail()

KLS_Region_List kls_rl_tail ( KLS_Region_List l)

◆ kls_show_toWin()

void kls_show_toWin ( Koliseo * kls,
WINDOW * win )

Prints fields and eventually KLS_Region_List from the passed Koliseo pointer, to the passed WINDOW pointer.

Parameters
klsThe Koliseo at hand.
winThe Window at hand.

◆ kls_showList_toWin()

void kls_showList_toWin ( Koliseo * kls,
WINDOW * win )

Displays a slideshow of KLS_Region_List from passed Koliseo, to the passed WINDOW pointer.

Parameters
klsThe Koliseo at hand.
winThe Window at hand.

◆ 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_list_pop()

KLS_region_list_item * kls_t_list_pop ( Koliseo_Temp * t_kls)

◆ 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_get_maxRegions_KLS_BASIC()

int kls_temp_get_maxRegions_KLS_BASIC ( Koliseo_Temp * t_kls)

Calcs the max number of possible KLS_PUSH_T ops when using KLS_BASIC reglist alloc backend.

Returns
The max number of temp push ops possible, or -1 in case of error.

◆ 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_AR()

void * kls_temp_push_zero_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 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.

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_push_zero_named()

void * kls_temp_push_zero_named ( Koliseo_Temp * t_kls,
ptrdiff_t size,
ptrdiff_t align,
ptrdiff_t count,
char * name,
char * desc )

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. Uses the passed name and desc fields to initialise the allocated KLS_Region fields. Notably, it zeroes the memory region.

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.
nameThe name to assign to the resulting KLS_Region.
descThe desc to assign to the resulting KLS_Region.
Returns
A void pointer to the start of memory just pushed to the Koliseo.

◆ kls_temp_push_zero_typed()

void * kls_temp_push_zero_typed ( Koliseo_Temp * t_kls,
ptrdiff_t size,
ptrdiff_t align,
ptrdiff_t count,
int type,
char * name,
char * desc )

Takes a Koliseo_Temp, a KLS_Region_Type index, 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. Uses the passed name and desc fields to initialise the allocated KLS_Region fields. Notably, it zeroes the memory region.

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.
typeThe type index for pushed KLS_Region.
nameThe name to assign to the resulting KLS_Region.
descThe desc to assign to the resulting KLS_Region.
Returns
A void pointer to the start of memory just pushed to the referred Koliseo.

◆ kls_temp_set_conf()

bool kls_temp_set_conf ( Koliseo_Temp * t_kls,
KLS_Temp_Conf conf )

Updates the KLS_Temp_Conf for the passed Koliseo_Temp pointer.

Parameters
t_klsThe Koliseo_Temp pointer to update.
confThe KLS_Temp_Conf to set.
Returns
A bool representing success.

◆ kls_temp_show_toWin()

void kls_temp_show_toWin ( Koliseo_Temp * t_kls,
WINDOW * win )

Takes a Koliseo_Temp pointer and prints fields and eventually KLS_Region_List from the referred Koliseo pointer, to the passed WINDOW pointer.

Parameters
t_klsThe Koliseo_Temp at hand.
winThe Window at hand.

◆ kls_temp_showList_toWin()

void kls_temp_showList_toWin ( Koliseo_Temp * t_kls,
WINDOW * win )

Displays a slideshow of KLS_Region_List from passed Koliseo_Temp, to the passed WINDOW pointer.

Parameters
t_klsThe Koliseo_Temp at hand.
winThe Window at hand.

◆ 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_type_usage()

ptrdiff_t kls_type_usage ( int type,
Koliseo * kls )

Calc memory used by the specific type of KLS_list_element.

See also
KLS_Region_List
Parameters
typeThe integer corresponding to element->type
klsThe Koliseo to check usage for.
Returns
The used memory size as ptrdiff_t.

◆ kls_usageReport()

void kls_usageReport ( Koliseo * kls)

Print usage report for passed Koliseo to stdout.

See also
kls_usageReport_toFile()
Parameters
klsThe Koliseo to print info for.

◆ kls_usageReport_toFile()

void kls_usageReport_toFile ( Koliseo * kls,
FILE * fp )

Prints an usage report for the passed Koliseo to the passed file.

See also
kls_usageShare()
Parameters
klsThe Koliseo to check.
fpThe file pointer to print to.

◆ kls_usageShare()

double kls_usageShare ( KLS_Region * r,
Koliseo * kls )

Returns the ratio of memory used by the passed KLS_Region relative to the passed Koliseo as a double.

Parameters
rThe KLS_Region to check relative size for.
klsThe Koliseo to check on.
Returns
A double representing percentage usage.

◆ kstr_cut_l()

Kstr kstr_cut_l ( Kstr * k,
size_t n )

Cuts the passed Kstr by up to n chars, from the left.

Returns cut portion as a new Kstr.

See also
Kstr
Parameters
kThe Kstr to cut.
nHow many chars to cut.
Returns
The cut part as a new Kstr.

◆ kstr_cut_r()

Kstr kstr_cut_r ( Kstr * k,
size_t n )

Cuts the passed Kstr by up to n chars, from the right.

Returns cut portion as a new Kstr.

See also
Kstr
Parameters
kThe Kstr to cut.
nHow many chars to cut.
Returns
The cut part as a new Kstr.

◆ kstr_eq()

bool kstr_eq ( Kstr left,
Kstr right )

Checks if the two passed Kstr have exactly equal data.

See also
Kstr
Parameters
leftThe first Kstr to compare.
rightThe second Kstr to compare.
Returns
A bool result for the comparation.

◆ kstr_eq_ignorecase()

bool kstr_eq_ignorecase ( Kstr left,
Kstr right )

Checks if the two passed Kstr have equal data, ignoring case.

See also
Kstr
Parameters
leftThe first Kstr to compare.
rightThe second Kstr to compare.
Returns
A bool result for the comparation.

◆ kstr_from_c_lit()

Kstr kstr_from_c_lit ( const char * c_lit)

Returns a new Kstr from the passed null-terminated string.

See also
Kstr
Parameters
c_litThe cstring pointer to set.
Returns
The resulting Kstr.

◆ kstr_indexof()

bool kstr_indexof ( Kstr k,
char c,
int * idx )

Checks if passed Kstr contains the passed char, and if so, sets the value pointed by idx to the first occurrence.

See also
Kstr
Parameters
kThe Kstr to scan.
cThe char to look for.
idxPointer to the value to be set as index.
Returns
false if the passed Kstr doesn't contain the passed char, true otherwise.

◆ kstr_new()

Kstr kstr_new ( const char * data,
size_t len )

Returns a new Kstr with the passed args set.

See also
Kstr
Parameters
dataThe string pointer to set.
lenThe len to set.
Returns
The resulting Kstr.

◆ kstr_token()

Kstr kstr_token ( Kstr * k,
char delim )

Scans the passed Kstr and cuts it up to the first occurrence of passed char, even if it is not present.

Returns a new Kstr with the original data.

See also
Kstr
Parameters
kThe Kstr to scan.
delimThe char to look for.
Returns
A new Kstr with the original data.

◆ kstr_token_kstr()

Kstr kstr_token_kstr ( Kstr * k,
Kstr delim )

◆ kstr_trim()

Kstr kstr_trim ( Kstr kstr)

Returns a new Kstr after removing heading and trailing spaces from the passed one.

See also
Kstr
kstr_trim_l()
kstr_trim_r()
Parameters
kstrThe Kstr to trim.
Returns
The resulting Kstr.

◆ kstr_trim_left()

Kstr kstr_trim_left ( Kstr kstr)

Returns a new Kstr after removing heading spaces from the passed one.

See also
Kstr
Parameters
kstrThe Kstr to trim.
Returns
The resulting Kstr.

◆ kstr_trim_right()

Kstr kstr_trim_right ( Kstr kstr)

Returns a new Kstr after removing trailing spaces from the passed one.

See also
Kstr
Parameters
kstrThe Kstr to trim.
Returns
The resulting Kstr.

◆ kstr_try_token()

bool kstr_try_token ( Kstr * k,
char delim,
Kstr * part )

Scans the first passed Kstr and if the passed char is present, the old Kstr is set to second pointer and the first one is cut at the first occurrence of it.

See also
Kstr
Parameters
kThe Kstr to scan.
delimThe char to look for.
partThe Kstr to set to the original data, if the delimiter is found.
Returns
false if the passed Kstr doesn't contain the passed char, true otherwise.

◆ 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_from_Gulp_Res()

const char * string_from_Gulp_Res ( Gulp_Res g)

Return a constant string for the passed Gulp_Res.

See also
gulp_res_names
Gulp_Res
Parameters
gThe Gulp_Res to get a string for.
Returns
A constant string representation of passed Gulp_Res.

◆ string_koliseo_version()

const char * string_koliseo_version ( void )

Returns the constant string representing current version for Koliseo.

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

◆ try_kls_gulp_file()

char * try_kls_gulp_file ( Koliseo * kls,
const char * filepath,
size_t max_size )

Tries mapping the passed file on the Koliseo.

Parameters
klsThe Koliseo to push to.
filepathPath to the file to gulp.
max_sizeMax size allowed for the read file.
See also
KLS_GULP_FILE()
Returns
A pointer to the string with file contents.

◆ try_kls_gulp_file_to_kstr()

Kstr * try_kls_gulp_file_to_kstr ( Koliseo * kls,
const char * filepath,
size_t max_size,
bool allow_nullchar )

Tries mapping the passed file on the Koliseo.

Parameters
klsThe Koliseo to push to.
filepathPath to the file to gulp.
max_sizeMax size allowed for the read file.
allow_nullcharBoolean to avoid returning NULL for a binary file.
See also
KLS_GULP_FILE()
Returns
A pointer to the Kstr with file contents.

Variable Documentation

◆ gulp_res_names

const char* gulp_res_names[TOT_GULP_RES+1]
Initial value:
= {
[GULP_FILE_OK] = "Success",
[GULP_FILE_NOT_EXIST] = "File does not exist",
[GULP_FILE_TOO_LARGE] = "File is too large",
[GULP_FILE_READ_ERROR] = "File could not be read",
[GULP_FILE_CONTAINS_NULLCHAR] = "File contains nullchar",
[GULP_FILE_KLS_NULL] = "Koliseo was NULL",
[TOT_GULP_RES] = "Total of Gulp_Res values",
}

Contains the constant string representation of Gulp_Res values.

See also
Gulp_Res

◆ KLS_DEFAULT_CONF

KLS_Conf KLS_DEFAULT_CONF
Initial value:
= {
.kls_autoset_regions = 0,
.kls_reglist_alloc_backend = KLS_REGLIST_ALLOC_LIBC,
.kls_reglist_kls_size = 0,
.kls_autoset_temp_regions = 0,
.kls_collect_stats = 0,
.kls_verbose_lvl = 0,
.kls_log_fp = NULL,
.kls_log_filepath = "",
}

◆ kls_reglist_backend_strings

const char* kls_reglist_backend_strings[KLS_REGLIST_TOTAL_BACKENDS]
Initial value:
= {
[KLS_REGLIST_ALLOC_LIBC] = "LIBC",
[KLS_REGLIST_ALLOC_KLS_BASIC] = "KLS_BASIC",
}

◆ KLS_STATS_DEFAULT

KLS_Stats KLS_STATS_DEFAULT
Initial value:
= {
.tot_pushes = 0,
.tot_temp_pushes = 0,
.tot_pops = 0,
.tot_temp_pops = 0,
.tot_logcalls = 0,
.tot_hiccups = 0,
.avg_region_size = 0,
.worst_pushcall_time = -1,
}

◆ kls_title

char* kls_title[KLS_TITLEROWS+1]

Defines title banner.