aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2017-04-14 14:20:18 +0200
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2018-07-01 00:18:44 +0200
commit017a4deba447a51d12cd397cd47f666ec20dc2e5 (patch)
treea4cb0c2c197b9fceaf828b65b96fed139fa207c4
parent12ade83c58720c9e0c18789f5ea6078a9eec1505 (diff)
downloadsparse-dev-017a4deba447a51d12cd397cd47f666ec20dc2e5.tar.gz
ptrmap: add type-safe interface
Add the external, type-safe, API for the ptrmap implementation. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r--ptrmap.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/ptrmap.h b/ptrmap.h
index 070db15e..cbbb61da 100644
--- a/ptrmap.h
+++ b/ptrmap.h
@@ -3,6 +3,22 @@
struct ptrmap;
+#define DECLARE_PTRMAP(name, ktype, vtype) \
+ struct name ## _pair { ktype key; vtype val; }; \
+ struct name { struct name ## _pair block[1]; }; \
+ static inline \
+ void name##_add(struct name **map, ktype k, vtype v) { \
+ __ptrmap_add((struct ptrmap**)map, k, v); \
+ } \
+ static inline \
+ void name##_update(struct name **map, ktype k, vtype v) { \
+ __ptrmap_update((struct ptrmap**)map, k, v); \
+ } \
+ static inline \
+ vtype name##_lookup(struct name *map, ktype k) { \
+ vtype val = __ptrmap_lookup((struct ptrmap*)map, k); \
+ return val; \
+ } \
/* ptrmap.c */
void __ptrmap_add(struct ptrmap **mapp, void *key, void *val);