Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 0.1.20 kls->has_temp #21

Merged
merged 3 commits into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion amboso
1 change: 1 addition & 0 deletions bin/stego.lock
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ tests# tests folder name
0.1.17# add kls_type_usage()
0.1.18# kls_push_zero_typed() expects int
0.1.19# add kls_print_title()
0.1.20# add kls->has_temp, KLS_PUSH_T doesn't account for AUTOREGION
4 changes: 4 additions & 0 deletions bin/v0.1.20/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#amboso compliant version folder, will ignore everything inside BUT the gitignore, to keep the clean dir
*
!.gitignore
!static
1 change: 1 addition & 0 deletions bin/v0.1.20/static
4 changes: 2 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Define the package name and version
AC_INIT([koliseo], [0.1.19], [[email protected]])
AC_INIT([koliseo], [0.1.20], [[email protected]])

# Verify automake version and enable foreign option
AM_INIT_AUTOMAKE([foreign -Wall])
Expand All @@ -24,7 +24,7 @@ fi
# Set a default version number if not specified externally
AC_ARG_VAR([VERSION], [Version number])
if test -z "$VERSION"; then
VERSION="0.1.19"
VERSION="0.1.20"
fi

# Output variables to the config.h header
Expand Down
2 changes: 1 addition & 1 deletion docs/koliseo.doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ PROJECT_NAME = "koliseo"
# could be handy for archiving the generated documentation or if some version
# control system is used.

PROJECT_NUMBER = "0.1.19"
PROJECT_NUMBER = "0.1.20"

# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a
Expand Down
42 changes: 42 additions & 0 deletions src/koliseo.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ Koliseo* kls_new(ptrdiff_t size) {
kls->size = size;
kls->offset = sizeof(*kls);
kls->prev_offset = kls->offset;
kls->has_temp = 0;
if (KOLISEO_AUTOSET_REGIONS == 1) {
kls_log("KLS","Init of Region_List for kls.");
Region* kls_header = (Region*) malloc(sizeof(Region));
Expand Down Expand Up @@ -228,6 +229,44 @@ void* kls_push(Koliseo* kls, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count) {
* @return A void pointer to the start of memory just pushed to the Koliseo.
*/
void* kls_push_zero(Koliseo* kls, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count) {
ptrdiff_t available = kls->size - kls->offset;
ptrdiff_t padding = -kls->offset & (align -1);
if (count > PTRDIFF_MAX/size || (available - padding) < (size*count)) {
if (count > PTRDIFF_MAX/size) {
fprintf(stderr, "[KSL] count [%li] was bigger than PTRDIFF_MAX/size [%li].\n", count, PTRDIFF_MAX/size);
} else {
fprintf(stderr, "[KLS] Out of memory. size*count [%li] was bigger than available-padding [%li].\n", size*count, available-padding);
}
fprintf(stderr,"[KLS] Failed kls_push_zero() call.\n");
abort();
//return 0;
}
char* p = kls->data + kls->offset + padding;
//Zero new area
memset(p, 0, size*count);
kls->prev_offset = kls->offset;
kls->offset += padding + size*count;
char h_size[200];
kls_formatSize(size,h_size,sizeof(h_size));
//sprintf(msg,"Pushed zeroes, size (%li) for KLS.",size);
//kls_log("KLS",msg);
kls_log("KLS","API Level { %i } -> Pushed zeroes, size (%s) for KLS.",h_size);
if (KOLISEO_DEBUG == 1) {
print_kls_2file(KOLISEO_DEBUG_FP,kls);
}
return p;
}

/**
* 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 abort() if the operation fails.
* Notably, it zeroes the memory region.
* @param kls The Koliseo at hand.
* @param size The size for data to push.
* @param align The alignment for data to push.
* @param count The multiplicative quantity to scale data size to push for.
* @return A void pointer to the start of memory just pushed to the Koliseo.
*/
void* kls_push_zero_AR(Koliseo* kls, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count) {
ptrdiff_t available = kls->size - kls->offset;
ptrdiff_t padding = -kls->offset & (align -1);
if (count > PTRDIFF_MAX/size || (available - padding) < (size*count)) {
Expand Down Expand Up @@ -589,10 +628,12 @@ void kls_free(Koliseo* kls) {
* @see Koliseo_Temp
*/
Koliseo_Temp kls_temp_start(Koliseo* kls) {
assert(kls->has_temp == 0); //TODO handle this more gracefully
Koliseo_Temp tmp;
tmp.kls = kls;
tmp.prev_offset = kls->prev_offset;
tmp.offset = kls->offset;
kls->has_temp = 1;
kls_log("KLS","Prepared new Temp KLS.");
return tmp;
}
Expand All @@ -606,6 +647,7 @@ void kls_temp_end(Koliseo_Temp tmp_kls) {
tmp_kls.kls->prev_offset = tmp_kls.prev_offset;
tmp_kls.kls->offset = tmp_kls.offset;
kls_log("KLS","Ended Temp KLS.");
tmp_kls.kls->has_temp = 0;
}


Expand Down
14 changes: 8 additions & 6 deletions src/koliseo.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

#define KLS_MAJOR 0 /**< Represents current major release.*/
#define KLS_MINOR 1 /**< Represents current minor release.*/
#define KLS_PATCH 19 /**< Represents current patch release.*/
#define KLS_PATCH 20 /**< Represents current patch release.*/

/**
* Global variable for debug flag.
Expand All @@ -28,7 +28,7 @@ extern int KOLISEO_AUTOSET_REGIONS;
extern FILE* KOLISEO_DEBUG_FP;

static const int KOLISEO_API_VERSION_INT = (KLS_MAJOR*1000000+KLS_MINOR*10000+KLS_PATCH*100); /**< Represents current version with numeric format.*/
static const char KOLISEO_API_VERSION_STRING[] = "0.1.19"; /**< Represents current version with MAJOR.MINOR.PATCH format.*/
static const char KOLISEO_API_VERSION_STRING[] = "0.1.20"; /**< Represents current version with MAJOR.MINOR.PATCH format.*/

const char* string_koliseo_version(void);

Expand Down Expand Up @@ -108,6 +108,7 @@ typedef struct Koliseo {
ptrdiff_t offset; /**< Current position of memory pointer.*/
ptrdiff_t prev_offset; /**< Previous position of memory pointer.*/
Region_List regs; /**< List of allocated Regions*/
int has_temp; /**< When == 1, a Koliseo_Temp is currently active on this Koliseo.*/
} Koliseo;

/**
Expand All @@ -129,11 +130,12 @@ Koliseo* kls_new(ptrdiff_t size);

//void* kls_push(Koliseo* kls, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count);
void* kls_push_zero(Koliseo* kls, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count);
void* kls_push_zero_AR(Koliseo* kls, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count);
void* kls_push_zero_named(Koliseo* kls, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count, char* name, char* desc);
void* kls_push_zero_typed(Koliseo* kls, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count, int type, char* name, char* desc);
void* kls_pop(Koliseo* kls, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count);

#define KLS_PUSH(kls, type, count) (type*)kls_push_zero(kls, sizeof(type), _Alignof(type), count)
#define KLS_PUSH(kls, type, count) (type*)kls_push_zero_AR(kls, sizeof(type), _Alignof(type), count)
#define KLS_PUSH_NAMED(kls, type, count, name, desc) (type*)kls_push_zero_named(kls, sizeof(type), _Alignof(type), count, name, desc)
#define KLS_PUSH_TYPED(kls, type, count, region_type, name, desc) (type*)kls_push_zero_typed(kls, sizeof(type), _Alignof(type), count, region_type, name, desc)
#define KLS_POP(kls, type, count) (type*)kls_pop(kls, sizeof(type), _Alignof(type), count)
Expand All @@ -159,9 +161,9 @@ void kls_showList_toWin(Koliseo* kls, WINDOW* win);
Koliseo_Temp kls_temp_start(Koliseo* kls);
void kls_temp_end(Koliseo_Temp tmp_kls);

#define KLS_PUSH_T(kls_temp, type, count) (type*)KLS_PUSH(kls_temp.kls, type, count)
#define KLS_PUSH_T_NAMED(kls_temp, type, count, name, desc) (type*)KLS_PUSH_NAMED(kls_temp.kls, type, count, name, desc)
#define KLS_PUSH_T_TYPED(kls_temp, type, count, region_type, name, desc) (type*)KLS_PUSH_TYPED(kls_temp.kls, type, count, region_type, name, desc)
#define KLS_PUSH_T(kls_temp, type, count) (type*)kls_push_zero(kls_temp.kls, sizeof(type), _Alignof(type), count)
#define KLS_PUSH_T_NAMED(kls_temp, type, count, name, desc) (type*)kls_push_zero(kls_temp.kls, sizeof(type), _Alignof(type), count)
#define KLS_PUSH_T_TYPED(kls_temp, type, count, region_type, name, desc) (type*)kls_push_zero(kls_temp.kls, sizeof(type), _Alignof(type), count)
#define KLS_POP_T(kls_temp, type, count) (type*)KLS_POP(kls_temp.kls, type, count)

Region_List kls_emptyList(void);
Expand Down
2 changes: 1 addition & 1 deletion static/amboso.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef AMBOSO_H
#define AMBOSO_H
#define AMBOSO_CV "1.6.3"
#define AMBOSO_CV "1.6.4"
char* getAmbosoVersion(void);
#endif