Patch 7.4.2062
Problem:    Using dummy variable to compute struct member offset.
Solution:   Use offsetof().
Files:      src/globals.h, src/macros.h, src/vim.h, src/spell.c


*** ../vim-7.4.2061/src/globals.h       2016-07-17 18:28:59.023697505 +0200
--- src/globals.h       2016-07-17 20:20:28.785985851 +0200
***************
*** 1649,1666 ****
  #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
--- 1649,1654 ----
*** ../vim-7.4.2061/src/macros.h        2016-03-11 22:52:00.742438030 +0100
--- src/macros.h        2016-07-17 20:20:40.357866769 +0200
***************
*** 353,355 ****
--- 353,366 ----
  #  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)
*** ../vim-7.4.2061/src/vim.h   2016-07-17 18:28:59.023697505 +0200
--- src/vim.h   2016-07-17 20:22:15.688885608 +0200
***************
*** 505,510 ****
--- 505,513 ----
  #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>
*** ../vim-7.4.2061/src/spell.c 2016-07-10 22:11:11.874751282 +0200
--- src/spell.c 2016-07-17 20:29:58.040123674 +0200
***************
*** 600,607 ****
      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 HI2WC(hi)     ((wordcount_T *)((hi)->hi_key - WC_KEY_OFF))
  #define MAXWORDCOUNT 0xffff
  
--- 600,606 ----
      char_u    wc_word[1];         /* word, actually longer */
  } wordcount_T;
  
! #define WC_KEY_OFF  offsetof(wordcount_T, wc_word)
  #define HI2WC(hi)     ((wordcount_T *)((hi)->hi_key - WC_KEY_OFF))
  #define MAXWORDCOUNT 0xffff
  
*** ../vim-7.4.2061/src/version.c       2016-07-17 19:25:00.968690723 +0200
--- src/version.c       2016-07-17 20:36:57.431799758 +0200
***************
*** 760,761 ****
--- 760,763 ----
  {   /* Add new patch number below this line */
+ /**/
+     2062,
  /**/

-- 
A real patriot is the fellow who gets a parking ticket and rejoices
that the system works.


 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Raspunde prin e-mail lui