]> git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - gmqcc.h
Fix type punning warnings
[xonotic/gmqcc.git] / gmqcc.h
diff --git a/gmqcc.h b/gmqcc.h
index dc3de394495d5396a8ecd94eb411939f59e882be..b27d4adb1acf4f1cef4e26a16c202c0e6604a8c8 100644 (file)
--- a/gmqcc.h
+++ b/gmqcc.h
@@ -1,6 +1,7 @@
 /*
  * Copyright (C) 2012
- *     Dale Weiler, Wolfgang Bumiller
+ *     Dale Weiler
+ *     Wolfgang Bumiller
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy of
  * this software and associated documentation files (the "Software"), to deal in
@@ -241,7 +242,7 @@ uint32_t util_crc32(uint32_t crc, const char *data, size_t len);
 #define INT2FLT(Y) *((float  *)&(Y))
 
 /* New flexible vector implementation from Dale */
-#define _vec_raw(A) (((size_t*)(void*)(A)) - 2)
+#define _vec_raw(A) (*((size_t**)((void*)(&(A))))-2)
 #define _vec_beg(A) (_vec_raw(A)[0])
 #define _vec_end(A) (_vec_raw(A)[1])
 #define _vec_needsgrow(A,N) ((!(A)) || (_vec_end(A) + (N) >= _vec_beg(A)))
@@ -270,6 +271,13 @@ typedef struct hash_table_t {
 /*
  * hashtable implementation:
  * 
+ * Note:
+ *      This was designed for pointers:  you manage the life of the object yourself
+ *      if you do use this for non-pointers please be warned that the object may not
+ *      be valid if the duration of it exceeds (i.e on stack).  So you need to allocate
+ *      yourself, or put those in global scope to ensure duration is for the whole
+ *      runtime.
+ * 
  * util_htnew(size)                             -- to make a new hashtable
  * util_htset(table, key, value, sizeof(value)) -- to set something in the table
  * util_htget(table, key)                       -- to get something from the table
@@ -280,8 +288,8 @@ typedef struct hash_table_t {
  * ht    foo  = util_htnew(1024);
  * int   data = 100;
  * char *test = "hello world\n";
- * util_htset(foo, "foo", (void*)&data, sizeof(int));
- * util_gtset(foo, "bar", (void*)test,  strlen(test));
+ * util_htset(foo, "foo", (void*)&data);
+ * util_gtset(foo, "bar", (void*)test);
  * 
  * printf("foo: %d, bar %s",
  *     *((int *)util_htget(foo, "foo")),
@@ -290,10 +298,13 @@ typedef struct hash_table_t {
  * 
  * util_htdel(foo);
  */
-hash_table_t *util_htnew(size_t size);
-void          util_htset(hash_table_t *ht, const char *key, void *value, size_t size);
-void         *util_htget(hash_table_t *ht, const char *key);
-void          util_htdel(hash_table_t *ht);
+hash_table_t *util_htnew (size_t size);
+void          util_htset (hash_table_t *ht, const char *key, void *value);
+void         *util_htget (hash_table_t *ht, const char *key);
+void          util_htdel (hash_table_t *ht);
+size_t        util_hthash(hash_table_t *ht, const char *key);
+void         *util_htgeth(hash_table_t *ht, const char *key, size_t hash);
+void          util_htseth(hash_table_t *ht, const char *key, size_t hash, void *value);
 /*===================================================================*/
 /*=========================== code.c ================================*/
 /*===================================================================*/