Skip to content

Commit

Permalink
Did the following...
Browse files Browse the repository at this point in the history
- build.sh formatting
- darr.c is now just darr.h (header only)
- fixed formatting of src/*
  • Loading branch information
tilkinsc committed Jan 15, 2019
1 parent 18e1fb6 commit 4f6e186
Show file tree
Hide file tree
Showing 8 changed files with 187 additions and 209 deletions.
12 changes: 6 additions & 6 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@


# Default env vars
if [ -z "$debug" ]; then debug=0; fi
if [ -z "$debug_coverage" ]; then debug_coverage=0; fi
if [ -z "$GCC" ]; then GCC="gcc"; fi
if [ -z "$AR" ]; then AR="ar"; fi
if [ -z "$MAKE" ]; then MAKE="make"; fi
if [ -z "$GCC_VER" ]; then GCC_VER=gnu99; fi
if [ -z "$debug" ]; then debug=0; fi
if [ -z "$debug_coverage" ]; then debug_coverage=0; fi
if [ -z "$GCC" ]; then GCC="gcc"; fi
if [ -z "$AR" ]; then AR="ar"; fi
if [ -z "$MAKE" ]; then MAKE="make"; fi
if [ -z "$GCC_VER" ]; then GCC_VER=gnu99; fi


# On help message request
Expand Down
40 changes: 0 additions & 40 deletions src/darr.c

This file was deleted.

34 changes: 25 additions & 9 deletions src/darr.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <stdlib.h>
#include <string.h>


typedef struct tagArray {
size_t size;
size_t cap;
Expand All @@ -35,6 +36,30 @@ typedef struct tagArray {
} Array;



static inline Array* array_new(size_t init_size, size_t increment, size_t type_size) {
Array* arr = malloc(sizeof(Array));
if(arr == 0)
return 0;
arr->size = 0;
arr->cap = init_size;
arr->increment = increment;
arr->type_size = type_size;
arr->data = malloc(init_size * sizeof(void*));
if(arr->data == 0) {
free(arr);
return 0;
}
return arr;
}

static inline void array_free(void* arr) {
Array* a = (Array*) arr;
free(a->data);
free(a);
}


static int array_ensure_size(Array* arr, size_t size) {
if(arr->size + size >= arr->cap) {
arr->data = realloc(arr->data, (arr->cap + arr->increment) * sizeof(void*));
Expand All @@ -46,15 +71,6 @@ static int array_ensure_size(Array* arr, size_t size) {
}


Array* array_new(size_t init_size, size_t increment, size_t type_size);

static inline void array_free(void* arr) {
Array* a = (Array*) arr;
free(a->data);
free(a);
}


static inline int array_push(Array* arr, void* data) {
if(array_ensure_size(arr, 1) == 0)
return 0;
Expand Down
Loading

0 comments on commit 4f6e186

Please sign in to comment.