aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Peter McGoron 2024-06-13 21:01:03 -0400
committerGravatar Peter McGoron 2024-06-13 21:01:03 -0400
commit5b8775dab611d6a57654356be96c2124cbab7faf (patch)
tree06c570f120e9a491978eaded02abb0f68072d2cf
parenthashtable test (diff)
add fake struct to help with type checker
-rw-r--r--examples/hashtable/uns_hashtable.c2
-rw-r--r--include/uns.h12
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. */