Skip to content

Commit 28fb79d

Browse files
committed
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.
1 parent 44132a1 commit 28fb79d

File tree

8 files changed

+50
-12
lines changed

8 files changed

+50
-12
lines changed

src/alloc.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/* vi:set ts=8 sts=4 sw=4:
2+
*
3+
* VIM - Vi IMproved by Bram Moolenaar
4+
*
5+
* Do ":help uganda" in Vim to read copying and usage conditions.
6+
* Do ":help credits" in Vim to see a list of people who contributed.
7+
*/
8+
9+
/*
10+
* alloc.h: enumeration of alloc IDs.
11+
* Each entry must be on exactly one line, GetAllocId() depends on that.
12+
*/
13+
typedef enum {
14+
aid_none = 0,
15+
aid_qf_dirname_start,
16+
aid_qf_dirname_now,
17+
aid_qf_namebuf,
18+
aid_qf_errmsg,
19+
aid_qf_pattern,
20+
} alloc_id_T;

src/globals.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1621,7 +1621,7 @@ EXTERN char *ignoredp;
16211621

16221622
#ifdef FEAT_EVAL
16231623
/* set by alloc_fail(): ID */
1624-
EXTERN int alloc_fail_id INIT(= 0);
1624+
EXTERN alloc_id_T alloc_fail_id INIT(= aid_none);
16251625
/* set by alloc_fail(), when zero alloc() returns NULL */
16261626
EXTERN int alloc_fail_countdown INIT(= -1);
16271627
/* set by alloc_fail(), number of times alloc() returns NULL */

src/misc2.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -837,12 +837,11 @@ alloc(size)
837837

838838
/*
839839
* alloc() with an ID for alloc_fail().
840-
* LAST_ID_USED: 5
841840
*/
842841
char_u *
843842
alloc_id(size, id)
844843
unsigned size;
845-
int id UNUSED;
844+
alloc_id_T id UNUSED;
846845
{
847846
#ifdef FEAT_EVAL
848847
if (alloc_fail_id == id && alloc_does_fail())
@@ -1001,13 +1000,12 @@ lalloc(size, message)
10011000

10021001
/*
10031002
* lalloc() with an ID for alloc_fail().
1004-
* See LAST_ID_USED above.
10051003
*/
10061004
char_u *
10071005
lalloc_id(size, message, id)
10081006
long_u size;
10091007
int message;
1010-
int id UNUSED;
1008+
alloc_id_T id UNUSED;
10111009
{
10121010
#ifdef FEAT_EVAL
10131011
if (alloc_fail_id == id && alloc_does_fail())

src/proto/misc2.pro

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ void adjust_cursor_col __ARGS((void));
2020
int leftcol_changed __ARGS((void));
2121
void vim_mem_profile_dump __ARGS((void));
2222
char_u *alloc __ARGS((unsigned size));
23-
char_u *alloc_id __ARGS((unsigned size, int id));
23+
char_u *alloc_id __ARGS((unsigned size, alloc_id_T id));
2424
char_u *alloc_clear __ARGS((unsigned size));
2525
char_u *alloc_check __ARGS((unsigned size));
2626
char_u *lalloc_clear __ARGS((long_u size, int message));
2727
char_u *lalloc __ARGS((long_u size, int message));
28-
char_u *lalloc_id __ARGS((long_u size, int message, int id));
28+
char_u *lalloc_id __ARGS((long_u size, int message, alloc_id_T id));
2929
void *mem_realloc __ARGS((void *ptr, size_t size));
3030
void do_outofmem_msg __ARGS((long_u size));
3131
void free_all_mem __ARGS((void));

src/testdir/runtest.vim

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,22 @@ set nomore
4343
" Output all messages in English.
4444
lang mess C
4545

46+
let s:srcdir = expand('%:p:h:h')
47+
48+
" Support function: get the alloc ID by name.
49+
function GetAllocId(name)
50+
exe 'split ' . s:srcdir . '/alloc.h'
51+
/typedef enum/
52+
let top = getline('.')
53+
let lnum = search('aid_' . a:name . ',')
54+
if lnum == 0
55+
call add(v:errors, 'Alloc ID ' . a:name . ' not defined')
56+
endif
57+
close
58+
return lnum - top
59+
endfunc
60+
61+
4662
" Source the test script. First grab the file name, in case the script
4763
" navigates away.
4864
let testname = expand('%')

src/testdir/test_quickfix.vim

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -278,35 +278,35 @@ function Test_cbuffer()
278278
endfunction
279279

280280
function Test_nomem()
281-
call alloc_fail(1, 0, 0)
281+
call alloc_fail(GetAllocId('qf_dirname_start'), 0, 0)
282282
try
283283
vimgrep vim runtest.vim
284284
catch
285285
call assert_true(v:exception =~ 'E342')
286286
endtry
287287

288-
call alloc_fail(2, 0, 0)
288+
call alloc_fail(GetAllocId('qf_dirname_now'), 0, 0)
289289
try
290290
vimgrep vim runtest.vim
291291
catch
292292
call assert_true(v:exception =~ 'E342')
293293
endtry
294294

295-
call alloc_fail(3, 0, 0)
295+
call alloc_fail(GetAllocId('qf_namebuf'), 0, 0)
296296
try
297297
cfile runtest.vim
298298
catch
299299
call assert_true(v:exception =~ 'E342')
300300
endtry
301301

302-
call alloc_fail(4, 0, 0)
302+
call alloc_fail(GetAllocId('qf_errmsg'), 0, 0)
303303
try
304304
cfile runtest.vim
305305
catch
306306
call assert_true(v:exception =~ 'E342')
307307
endtry
308308

309-
call alloc_fail(5, 0, 0)
309+
call alloc_fail(GetAllocId('qf_pattern'), 0, 0)
310310
try
311311
cfile runtest.vim
312312
catch

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,8 @@ static char *(features[]) =
741741

742742
static int included_patches[] =
743743
{ /* Add new patch number below this line */
744+
/**/
745+
1073,
744746
/**/
745747
1072,
746748
/**/

src/vim.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1765,6 +1765,8 @@ typedef int proftime_T; /* dummy for function prototypes */
17651765

17661766
#include "structs.h" /* file that defines many structures */
17671767

1768+
#include "alloc.h"
1769+
17681770
/* Values for "do_profiling". */
17691771
#define PROF_NONE 0 /* profiling not started */
17701772
#define PROF_YES 1 /* profiling busy */

0 commit comments

Comments
 (0)