summaryrefslogtreecommitdiff
path: root/src/macros.h
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2016-07-17 20:37:43 +0200
committerBram Moolenaar <Bram@vim.org>2016-07-17 20:37:43 +0200
commit840268400dc8fda62a14f8a084e8b1ea46619454 (patch)
treeb0e1ff5ffdb4a9cf5862d41f6a1f3e11f27f3ff1 /src/macros.h
parente87e6dddc2b2a99572ec0db0833c052214c4fbd3 (diff)
downloadvim-840268400dc8fda62a14f8a084e8b1ea46619454.zip
patch 7.4.2062
Problem: Using dummy variable to compute struct member offset. Solution: Use offsetof().
Diffstat (limited to 'src/macros.h')
-rw-r--r--src/macros.h11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/macros.h b/src/macros.h
index ca54cb42e..ae784d6cc 100644
--- a/src/macros.h
+++ b/src/macros.h
@@ -353,3 +353,14 @@
# endif
# endif
#endif
+
+/*
+ * In a hashtab item "hi_key" points to "di_key" in a dictitem.
+ * This avoids adding a pointer to the hashtab item.
+ * DI2HIKEY() converts a dictitem pointer to a hashitem key pointer.
+ * HIKEY2DI() converts a hashitem key pointer to a dictitem pointer.
+ * HI2DI() converts a hashitem pointer to a dictitem pointer.
+ */
+# define DI2HIKEY(di) ((di)->di_key)
+# define HIKEY2DI(p) ((dictitem_T *)(p - offsetof(dictitem_T, di_key)))
+# define HI2DI(hi) HIKEY2DI((hi)->hi_key)