summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2016-01-09 22:28:33 +0100
committerBram Moolenaar <Bram@vim.org>2016-01-09 22:28:33 +0100
commit28fb79db6b52d1154e8dc63d227673648c2fce15 (patch)
tree4a1a10e264249d9851ffb9b7396ade0fc808fec6
parent44132a10aeb45c957959cafb4ac39d3f478be98c (diff)
patch 7.4.1073v7.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.
-rw-r--r--src/alloc.h20
-rw-r--r--src/globals.h2
-rw-r--r--src/misc2.c6
-rw-r--r--src/proto/misc2.pro4
-rw-r--r--src/testdir/runtest.vim16
-rw-r--r--src/testdir/test_quickfix.vim10
-rw-r--r--src/version.c2
-rw-r--r--src/vim.h2
8 files changed, 50 insertions, 12 deletions
diff --git a/src/alloc.h b/src/alloc.h
new file mode 100644
index 0000000000..c237ef348c
--- /dev/null
+++ b/src/alloc.h
@@ -0,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;
diff --git a/src/globals.h b/src/globals.h
index 54a1d7256b..0931466e94 100644
--- a/src/globals.h
+++ b/src/globals.h
@@ -1621,7 +1621,7 @@ EXTERN char *ignoredp;
#ifdef FEAT_EVAL
/* set by alloc_fail(): ID */
-EXTERN int alloc_fail_id INIT(= 0);
+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 */
diff --git a/src/misc2.c b/src/misc2.c
index d8202f88a9..8540212554 100644
--- a/src/misc2.c
+++ b/src/misc2.c
@@ -837,12 +837,11 @@ alloc(size)
/*
* alloc() with an ID for alloc_fail().
- * LAST_ID_USED: 5
*/
char_u *
alloc_id(size, id)
unsigned size;
- int id UNUSED;
+ alloc_id_T id UNUSED;
{
#ifdef FEAT_EVAL
if (alloc_fail_id == id && alloc_does_fail())
@@ -1001,13 +1000,12 @@ theend:
/*
* 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;
+ alloc_id_T id UNUSED;
{
#ifdef FEAT_EVAL
if (alloc_fail_id == id && alloc_does_fail())
diff --git a/src/proto/misc2.pro b/src/proto/misc2.pro
index 35e1a8ec86..3d1f10ad55 100644
--- a/src/proto/misc2.pro
+++ b/src/proto/misc2.pro
@@ -20,12 +20,12 @@ void adjust_cursor_col __ARGS((void));
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_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, int id));
+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));
diff --git a/src/testdir/runtest.vim b/src/testdir/runtest.vim
index 734039aca1..72b21d5ae8 100644
--- a/src/testdir/runtest.vim
+++ b/src/testdir/runtest.vim
@@ -43,6 +43,22 @@ set nomore
" 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('%')
diff --git a/src/testdir/test_quickfix.vim b/src/testdir/test_quickfix.vim
index fb05b7d780..b9f3f7bbbe 100644
--- a/src/testdir/test_quickfix.vim
+++ b/src/testdir/test_quickfix.vim
@@ -278,35 +278,35 @@ function Test_cbuffer()
endfunction
function Test_nomem()
- call alloc_fail(1, 0, 0)
+ 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(2, 0, 0)
+ 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(3, 0, 0)
+ call alloc_fail(GetAllocId('qf_namebuf'), 0, 0)
try
cfile runtest.vim
catch
call assert_true(v:exception =~ 'E342')
endtry
- call alloc_fail(4, 0, 0)
+ call alloc_fail(GetAllocId('qf_errmsg'), 0, 0)
try
cfile runtest.vim
catch
call assert_true(v:exception =~ 'E342')
endtry
- call alloc_fail(5, 0, 0)
+ call alloc_fail(GetAllocId('qf_pattern'), 0, 0)
try
cfile runtest.vim
catch
diff --git a/src/version.c b/src/version.c
index ad87d1dad7..46e5aa7da2 100644
--- a/src/version.c
+++ b/src/version.c
@@ -742,6 +742,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 1073,
+/**/
1072,
/**/
1071,
diff --git a/src/vim.h b/src/vim.h
index 1a176beaee..fd0b0b0dc1 100644
--- a/src/vim.h
+++ b/src/vim.h
@@ -1765,6 +1765,8 @@ typedef int proftime_T; /* dummy for function prototypes */
#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 */