Patch 7.4.1073
Problem:    Alloc_id depends on numbers, may use the same one twice.  It's not
            clear from the number what it's for.
Solution:   Use an enum.  Add a function to lookup the enum value from the
            name.
Files:      src/misc2.c, src/vim.h, src/alloc.h, src/globals.h,
            src/testdir/runtest.vim, src/proto/misc2.pro,
            src/testdir/test_quickfix.vim


*** ../vim-7.4.1072/src/misc2.c 2016-01-09 18:52:36.360327748 +0100
--- src/misc2.c 2016-01-09 22:14:32.856763929 +0100
***************
*** 837,848 ****
  
  /*
   * alloc() with an ID for alloc_fail().
-  * LAST_ID_USED: 5
   */
      char_u *
  alloc_id(size, id)
      unsigned  size;
!     int               id UNUSED;
  {
  #ifdef FEAT_EVAL
      if (alloc_fail_id == id && alloc_does_fail())
--- 837,847 ----
  
  /*
   * alloc() with an ID for alloc_fail().
   */
      char_u *
  alloc_id(size, id)
      unsigned  size;
!     alloc_id_T        id UNUSED;
  {
  #ifdef FEAT_EVAL
      if (alloc_fail_id == id && alloc_does_fail())
***************
*** 1001,1013 ****
  
  /*
   * lalloc() with an ID for alloc_fail().
-  * See LAST_ID_USED above.
   */
      char_u *
  lalloc_id(size, message, id)
      long_u    size;
      int               message;
!     int               id UNUSED;
  {
  #ifdef FEAT_EVAL
      if (alloc_fail_id == id && alloc_does_fail())
--- 1000,1011 ----
  
  /*
   * lalloc() with an ID for alloc_fail().
   */
      char_u *
  lalloc_id(size, message, id)
      long_u    size;
      int               message;
!     alloc_id_T        id UNUSED;
  {
  #ifdef FEAT_EVAL
      if (alloc_fail_id == id && alloc_does_fail())
*** ../vim-7.4.1072/src/vim.h   2016-01-02 17:54:04.427793224 +0100
--- src/vim.h   2016-01-09 21:59:34.842561893 +0100
***************
*** 1765,1770 ****
--- 1765,1772 ----
  
  #include "structs.h"      /* file that defines many structures */
  
+ #include "alloc.h"
+ 
  /* Values for "do_profiling". */
  #define PROF_NONE     0       /* profiling not started */
  #define PROF_YES      1       /* profiling busy */
*** ../vim-7.4.1072/src/alloc.h 2016-01-09 22:25:55.609296505 +0100
--- src/alloc.h 2016-01-09 22:17:38.146736802 +0100
***************
*** 0 ****
--- 1,20 ----
+ /* vi:set ts=8 sts=4 sw=4:
+  *
+  * VIM - Vi IMproved  by Bram Moolenaar
+  *
+  * Do ":help uganda"  in Vim to read copying and usage conditions.
+  * Do ":help credits" in Vim to see a list of people who contributed.
+  */
+ 
+ /*
+  * alloc.h: enumeration of alloc IDs.
+  * Each entry must be on exactly one line, GetAllocId() depends on that.
+  */
+ typedef enum {
+       aid_none = 0,
+       aid_qf_dirname_start,
+       aid_qf_dirname_now,
+       aid_qf_namebuf,
+       aid_qf_errmsg,
+       aid_qf_pattern,
+ } alloc_id_T;
*** ../vim-7.4.1072/src/globals.h       2016-01-07 21:24:57.329499581 +0100
--- src/globals.h       2016-01-09 22:17:59.938498423 +0100
***************
*** 1621,1627 ****
  
  #ifdef FEAT_EVAL
  /* set by alloc_fail(): ID */
! EXTERN int  alloc_fail_id INIT(= 0);
  /* set by alloc_fail(), when zero alloc() returns NULL */
  EXTERN int  alloc_fail_countdown INIT(= -1);
  /* set by alloc_fail(), number of times alloc() returns NULL */
--- 1621,1627 ----
  
  #ifdef FEAT_EVAL
  /* set by alloc_fail(): ID */
! EXTERN alloc_id_T  alloc_fail_id INIT(= aid_none);
  /* set by alloc_fail(), when zero alloc() returns NULL */
  EXTERN int  alloc_fail_countdown INIT(= -1);
  /* set by alloc_fail(), number of times alloc() returns NULL */
*** ../vim-7.4.1072/src/testdir/runtest.vim     2016-01-09 20:22:55.421559364 
+0100
--- src/testdir/runtest.vim     2016-01-09 22:12:37.218029278 +0100
***************
*** 43,48 ****
--- 43,64 ----
  " Output all messages in English.
  lang mess C
  
+ let s:srcdir = expand('%:p:h:h')
+ 
+ " Support function: get the alloc ID by name.
+ function GetAllocId(name)
+   exe 'split ' . s:srcdir . '/alloc.h'
+   /typedef enum/
+   let top = getline('.')
+   let lnum = search('aid_' . a:name . ',')
+   if lnum == 0
+     call add(v:errors, 'Alloc ID ' . a:name . ' not defined')
+   endif
+   close
+   return lnum - top
+ endfunc
+ 
+ 
  " Source the test script.  First grab the file name, in case the script
  " navigates away.
  let testname = expand('%')
*** ../vim-7.4.1072/src/proto/misc2.pro 2016-01-07 22:33:56.588461212 +0100
--- src/proto/misc2.pro 2016-01-09 22:09:14.172243048 +0100
***************
*** 20,31 ****
  int leftcol_changed __ARGS((void));
  void vim_mem_profile_dump __ARGS((void));
  char_u *alloc __ARGS((unsigned size));
! char_u *alloc_id __ARGS((unsigned size, int id));
  char_u *alloc_clear __ARGS((unsigned size));
  char_u *alloc_check __ARGS((unsigned size));
  char_u *lalloc_clear __ARGS((long_u size, int message));
  char_u *lalloc __ARGS((long_u size, int message));
! char_u *lalloc_id __ARGS((long_u size, int message, int id));
  void *mem_realloc __ARGS((void *ptr, size_t size));
  void do_outofmem_msg __ARGS((long_u size));
  void free_all_mem __ARGS((void));
--- 20,31 ----
  int leftcol_changed __ARGS((void));
  void vim_mem_profile_dump __ARGS((void));
  char_u *alloc __ARGS((unsigned size));
! char_u *alloc_id __ARGS((unsigned size, alloc_id_T id));
  char_u *alloc_clear __ARGS((unsigned size));
  char_u *alloc_check __ARGS((unsigned size));
  char_u *lalloc_clear __ARGS((long_u size, int message));
  char_u *lalloc __ARGS((long_u size, int message));
! char_u *lalloc_id __ARGS((long_u size, int message, alloc_id_T id));
  void *mem_realloc __ARGS((void *ptr, size_t size));
  void do_outofmem_msg __ARGS((long_u size));
  void free_all_mem __ARGS((void));
*** ../vim-7.4.1072/src/testdir/test_quickfix.vim       2016-01-09 
20:22:55.421559364 +0100
--- src/testdir/test_quickfix.vim       2016-01-09 22:13:13.757629433 +0100
***************
*** 278,312 ****
  endfunction
  
  function Test_nomem()
!   call alloc_fail(1, 0, 0)
    try
      vimgrep vim runtest.vim
    catch
      call assert_true(v:exception =~ 'E342')
    endtry
  
!   call alloc_fail(2, 0, 0)
    try
      vimgrep vim runtest.vim
    catch
      call assert_true(v:exception =~ 'E342')
    endtry
  
!   call alloc_fail(3, 0, 0)
    try
      cfile runtest.vim
    catch
      call assert_true(v:exception =~ 'E342')
    endtry
  
!   call alloc_fail(4, 0, 0)
    try
      cfile runtest.vim
    catch
      call assert_true(v:exception =~ 'E342')
    endtry
  
!   call alloc_fail(5, 0, 0)
    try
      cfile runtest.vim
    catch
--- 278,312 ----
  endfunction
  
  function Test_nomem()
!   call alloc_fail(GetAllocId('qf_dirname_start'), 0, 0)
    try
      vimgrep vim runtest.vim
    catch
      call assert_true(v:exception =~ 'E342')
    endtry
  
!   call alloc_fail(GetAllocId('qf_dirname_now'), 0, 0)
    try
      vimgrep vim runtest.vim
    catch
      call assert_true(v:exception =~ 'E342')
    endtry
  
!   call alloc_fail(GetAllocId('qf_namebuf'), 0, 0)
    try
      cfile runtest.vim
    catch
      call assert_true(v:exception =~ 'E342')
    endtry
  
!   call alloc_fail(GetAllocId('qf_errmsg'), 0, 0)
    try
      cfile runtest.vim
    catch
      call assert_true(v:exception =~ 'E342')
    endtry
  
!   call alloc_fail(GetAllocId('qf_pattern'), 0, 0)
    try
      cfile runtest.vim
    catch
*** ../vim-7.4.1072/src/version.c       2016-01-09 21:08:24.527969866 +0100
--- src/version.c       2016-01-09 22:16:19.311599228 +0100
***************
*** 743,744 ****
--- 743,746 ----
  {   /* Add new patch number below this line */
+ /**/
+     1073,
  /**/

-- 
Every time I lose weight, it finds me again!

 /// 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