]> granicus.if.org Git - vim/commitdiff
patch 7.4.2062 v7.4.2062
authorBram Moolenaar <Bram@vim.org>
Sun, 17 Jul 2016 18:37:43 +0000 (20:37 +0200)
committerBram Moolenaar <Bram@vim.org>
Sun, 17 Jul 2016 18:37:43 +0000 (20:37 +0200)
Problem:    Using dummy variable to compute struct member offset.
Solution:   Use offsetof().

src/globals.h
src/macros.h
src/spell.c
src/version.c
src/vim.h

index 07e3cf7b26cb5b43439f7a3a166e1c7a208dd4b9..f33120214a73959ca721ee6b58fc1faa92caf819 100644 (file)
@@ -1649,18 +1649,6 @@ EXTERN int  did_add_timer INIT(= FALSE);
 #ifdef FEAT_EVAL
 EXTERN time_T time_for_testing INIT(= 0);
 
-/*
- * 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.
- */
-EXTERN dictitem_T dumdi;
-# define DI2HIKEY(di) ((di)->di_key)
-# define HIKEY2DI(p)  ((dictitem_T *)(p - (dumdi.di_key - (char_u *)&dumdi)))
-# define HI2DI(hi)     HIKEY2DI((hi)->hi_key)
-
 /* Abort conversion to string after a recursion error. */
 EXTERN int  did_echo_string_emsg INIT(= FALSE);
 #endif
index ca54cb42e01fdda77c20799a4bf62e07b6aed6fa..ae784d6cc1a1e4ae3da7754d343ffb3b62e386ac 100644 (file)
 #  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)
index af96891076da0269738354f8ea39094345e33ae3..f6ab0dffb1e399572f43280ae2b0e5d9cb8a68b5 100644 (file)
@@ -600,8 +600,7 @@ typedef struct wordcount_S
     char_u     wc_word[1];         /* word, actually longer */
 } wordcount_T;
 
-static wordcount_T dumwc;
-#define WC_KEY_OFF  (unsigned)(dumwc.wc_word - (char_u *)&dumwc)
+#define WC_KEY_OFF  offsetof(wordcount_T, wc_word)
 #define HI2WC(hi)     ((wordcount_T *)((hi)->hi_key - WC_KEY_OFF))
 #define MAXWORDCOUNT 0xffff
 
index 5be01ae8e869f07f1e7946ccaef7b962fb2e55d2..665c93e92873dd9c4e168415fc10627535eec435 100644 (file)
@@ -758,6 +758,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2062,
 /**/
     2061,
 /**/
index 5067c5a885061a9df05956f54bc6631bdb56ab29..49fb8704cdc2f6e092fee0b3ac09c11dd01dbecb 100644 (file)
--- a/src/vim.h
+++ b/src/vim.h
@@ -505,6 +505,9 @@ typedef unsigned long u8char_T;         /* long should be 32 bits or more */
 #endif
 #include <stdarg.h>
 
+/* for offsetof() */
+#include <stddef.h>
+
 #if defined(HAVE_SYS_SELECT_H) && \
        (!defined(HAVE_SYS_TIME_H) || defined(SYS_SELECT_WITH_SYS_TIME))
 # include <sys/select.h>