From b0013aa7f2237fb88daf3f2ba856c8cdfe222fa2 Mon Sep 17 00:00:00 2001 From: ken Date: Sun, 26 Feb 2017 13:03:29 -0800 Subject: [PATCH] ston testing --- Makefile | 7 ++++--- src/testston.c | 16 ++++++++++++++++ ston/ston_ht.h | 17 ++++++++++------- 3 files changed, 30 insertions(+), 10 deletions(-) create mode 100644 src/testston.c diff --git a/Makefile b/Makefile index 62bf119..7b8934d 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ # This makefile builds APC, the Asset Package Compiler for Henge, on the system. ################################################################################ # Driver sources -DRIVERS ?= apc testapc +DRIVERS ?= apc testapc testston # Debug Level DEBUG ?= 1 @@ -50,10 +50,11 @@ cTRG := $(patsubst %.c,%.o,$(cSRC) $(cGEN)) ldSRC := $(filter-out $(DRIVERS:%=\%/%.o),$(cTRG)) cTRG += $(cTRG:%.o=%-d.o) ldTRG := $(DRIVERS:%=%-d) $(DRIVERS) -ldDEP = $(filter %/$1.o,$(cTRG)) $(if $(filter %-d,$1),$(ldSRC:%.o=%-d.o),$(ldSRC)) +ldDEP = $(filter %/$1.o,$(cTRG)) +ldDEP += $(if $(filter testston%,$1),,$(if $(filter %-d,$1),$(ldSRC:%.o=%-d.o),$(ldSRC))) # Determine if '1' is newer than '2' -TSTAMP = $(if $(wildcard $1),$(shell stat -c %Y $1),0$(info nots: $1)) +TSTAMP = $(if $(wildcard $1),$(shell stat -c %Y $1),) NEWER = $(eval 4 := $(call TSTAMP,$(dir $2)$1)) NEWER += $(eval 5 := $(call TSTAMP,$2)) NEWER += $(if $(filter $5,$(firstword $(sort $4 $5))),$1,$2) diff --git a/src/testston.c b/src/testston.c new file mode 100644 index 0000000..71c0110 --- /dev/null +++ b/src/testston.c @@ -0,0 +1,16 @@ +#include "../ston/ston.h" +#include //malloc +#include //print + +int main(int argc, char* argv[]) +{ ston_ht ht; + uint32_t* htval; + + if ((ht = ston_ht32_new(2,1,0,malloc)) == NULL) + fprintf(stderr,"Could not allocate ht32\n"); + ston_ht32_insertx(ht,50,1,200); + htval = ston_ht32_entry(ht,50,1); + printf("[50][1] = %i\n",*htval); + free(ht); + return 0; +} diff --git a/ston/ston_ht.h b/ston/ston_ht.h index a0bf05f..11454b3 100644 --- a/ston/ston_ht.h +++ b/ston/ston_ht.h @@ -45,11 +45,17 @@ #ifndef STON_FUNC #define STON_FUNC STON_FUNC_STATIC STON_FUNC_INLINE #endif //STON_FUNC -#ifndef STON_NOSTDIO +#ifdef STON_HT_FREAD #include #include //memcpy +#include #include -#endif //STON_NOSTDIO +STON_FUNC_STATIC +STON_FUNC_NOINLINE +ston_ht ston_ht32_fread(FILE*,long,void*(*)(size_t)); +#else +#include +#endif //STON_HT_FREAD #include /* STON Hashtable Structure Hashtables are stored as dynamically sized two dimensional arrays @@ -61,9 +67,6 @@ typedef struct ston_ht_header_t STON_FUNC size_t ston_up2pow(size_t); -STON_FUNC_STATIC -STON_FUNC_NOINLINE -ston_ht ston_ht32_fread(FILE*,long,void*(*)(size_t)); STON_FUNC ston_ht ston_ht32_create(uint16_t,size_t,uint8_t,void*(*)(size_t)); STON_FUNC @@ -71,7 +74,7 @@ uint32_t* ston_ht32_row(ston_ht,uint32_t); STON_FUNC uint32_t ston_ht32_insert(ston_ht,uint32_t,uint16_t,uint32_t); -#define ston_ht32_new(_COL,_N,_F,_FN) ston_ht32_create(_COLS,ston_up2pow(_N << 1),_F,_FN) +#define ston_ht32_new(_COL,_N,_F,_FN) ston_ht32_create(_COL,ston_up2pow(_N << 1),_F,_FN) #define ston_ht32_entry(_HT,_KEY,_COL) (ston_ht32_row(_HT,_KEY) + _COL) #define ston_ht32_insertx(_HT,_KEY,_COL,_VAL) *ston_ht32_entry(_HT,_KEY,_COL) = _VAL #define ston_ht_size(_HT) ((_HT)->ht_columns << (_HT)->ht_2pow) @@ -123,7 +126,7 @@ ston_ht ston_ht32_create return ht; } -#ifndef STON_NO_STDIO +#ifdef STON_HT_FREAD /* Reads a 32-bit hash table out of the provided file at the provide fpos, into a buffer allocated by alloc_fn. Memory is allocated to the stack until the entire structure is verified, and all file operations are finished. -- 2.18.0