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

Added LIST_allocator API #74

Closed
wants to merge 2 commits into from
Closed
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
26 changes: 24 additions & 2 deletions src/koliseo.h
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,10 @@ char** kls_t_strdup_arr(Koliseo_Temp* t_kls, size_t count, char** source);
#define LIST_COMB1(pre, word) LIST_COMB2(pre, word)
#define LIST_COMB2(pre, word) pre##word

#define LIST_HEADER_VERSION "0.1.0"
// Customize memory allocator function for list generated header
#define LIST_DEFAULT_ALLOCF malloc

#define LIST_HEADER_VERSION "0.1.1"

#endif // LIST_HEADER_H

Expand Down Expand Up @@ -936,6 +939,7 @@ typedef LIST_ITEM_NAME* LIST_NAME;
#define LIST_isEmpty LIST_IMPL(isEmpty)
#define LIST_head LIST_IMPL(head)
#define LIST_tail LIST_IMPL(tail)
#define LIST_allocator LIST_IMPL(allocator)
#define LIST_cons_gl LIST_IMPL(cons_gl)
#define LIST_cons_kls LIST_IMPL(cons_kls)
#define LIST_free_gl LIST_IMPL(free_gl)
Expand Down Expand Up @@ -972,6 +976,10 @@ LIST_LINKAGE
LIST_NAME
LIST_tail(LIST_NAME list);

LIST_LINKAGE
LIST_NAME
LIST_allocator(void);

LIST_LINKAGE
LIST_NAME
LIST_cons_gl(LIST_T* element, LIST_NAME list);
Expand Down Expand Up @@ -1080,12 +1088,25 @@ LIST_tail(LIST_NAME list)
return list->next;
}

LIST_LINKAGE
LIST_NAME
LIST_allocator(void)
{
return (LIST_NAME) LIST_DEFAULT_ALLOCF(sizeof(LIST_ITEM_NAME));
}

LIST_LINKAGE
LIST_NAME
LIST_cons_gl(LIST_T* element, LIST_NAME list)
{
LIST_NAME t;
t = (LIST_NAME) malloc(sizeof(LIST_ITEM_NAME));
t = LIST_allocator();
if (t == NULL)
{
fprintf(stderr, "%s at %i: %s(): LIST_allocator failed.\n", __FILE__, __LINE__, __func__);
return NULL;
}

t->value = element;
t->next = list;
return t;
Expand Down Expand Up @@ -1342,6 +1363,7 @@ LIST_diff_kls(Koliseo* kls, LIST_NAME l1, LIST_NAME l2)
#undef LIST_isEmpty
#undef LIST_head
#undef LIST_tail
#undef LIST_allocator
#undef LIST_cons_gl
#undef LIST_cons_kls
#undef LIST_free_gl
Expand Down