From 5b8775dab611d6a57654356be96c2124cbab7faf Mon Sep 17 00:00:00 2001 From: Peter McGoron Date: Thu, 13 Jun 2024 21:01:03 -0400 Subject: [PATCH] add fake struct to help with type checker --- examples/hashtable/uns_hashtable.c | 2 +- include/uns.h | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/examples/hashtable/uns_hashtable.c b/examples/hashtable/uns_hashtable.c index a2a5f7b..3721ab8 100644 --- a/examples/hashtable/uns_hashtable.c +++ b/examples/hashtable/uns_hashtable.c @@ -174,7 +174,7 @@ void uns_hashtable_add(struct uns_gc *gc, struct uns_ctr *htbl, if (uns_hashtable_used(gc, htbl) >= uns_hashtable_len(gc, htbl)*7/10) uns_hashtable_resize(gc, htbl, uns_hashtable_len(gc, htbl)*2); - if (search_for_container(gc, htbl, &container, string->p, string_len, &hash)) { + if (search_for_container(gc, htbl, &container, (unsigned char *)string->p, string_len, &hash)) { old_value->p = gc->record_get_ptr(container.p, VALUE); gc->record_set_ptr(container.p, VALUE, value->p); return; diff --git a/include/uns.h b/include/uns.h index 93a859d..d88397c 100644 --- a/include/uns.h +++ b/include/uns.h @@ -38,6 +38,14 @@ typedef UNS_WORD uns_word; typedef UNS_SIGNED_WORD uns_sword; +/* This struct doesn't exist and is used to make a unique pointer for + * type checking. + * + * This pointer must be what was returned from an allocation (i.e. it points + * to the first byte but before any hidden header data). + */ +typedef struct uns_ptr *Uns_ptr; + /** Doubly linked list used to * * 1) Store roots of the GC, @@ -89,8 +97,8 @@ struct uns_gc { */ size_t (*len)(void *); - void (*record_set_ptr)(void *, size_t, void *); - void *(*record_get_ptr)(void *, size_t); + void (*record_set_ptr)(Uns_ptr, size_t, void *); + void *(*record_get_ptr)(Uns_ptr, size_t); }; /** Add a root to the GC. The root must point to valid memory, or NULL. */