diff options
author | Wayne Rowcliffe <war1025@gmail.com> | 2014-07-19 22:49:56 -0500 |
---|---|---|
committer | Wayne Rowcliffe <war1025@gmail.com> | 2014-07-22 05:28:17 -0500 |
commit | 9453b7230b68eef6a13403a124a288e9f95591cd (patch) | |
tree | 693aa9dbf43b3567de31763198596696bcd9e59d /src | |
parent | 845d1bfa905cf0d28d9a1a662e42525449dd1be4 (diff) | |
download | rneovim-9453b7230b68eef6a13403a124a288e9f95591cd.tar.gz rneovim-9453b7230b68eef6a13403a124a288e9f95591cd.tar.bz2 rneovim-9453b7230b68eef6a13403a124a288e9f95591cd.zip |
Statically allocate NameBuff
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/ex_cmds.c | 18 | ||||
-rw-r--r-- | src/nvim/globals.h | 22 | ||||
-rw-r--r-- | src/nvim/main.c | 20 | ||||
-rw-r--r-- | src/nvim/memory.c | 2 | ||||
-rw-r--r-- | src/nvim/quickfix.c | 6 | ||||
-rw-r--r-- | src/nvim/tempfile.c | 6 | ||||
-rw-r--r-- | src/nvim/vim.h | 12 |
7 files changed, 42 insertions, 44 deletions
diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 384eebe556..c516b24236 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -5156,7 +5156,11 @@ void fix_help_buffer(void) /* Find all "doc/ *.txt" files in this directory. */ add_pathsep(NameBuff); STRCAT(NameBuff, "doc/*.??[tx]"); - if (gen_expand_wildcards(1, &NameBuff, &fcount, + + // Note: We cannot just do `&NameBuff` because it is a statically sized array + // so `NameBuff == &NameBuff` according to C semantics. + char_u *buff_list[1] = {(char_u*) NameBuff}; + if (gen_expand_wildcards(1, buff_list, &fcount, &fnames, EW_FILE|EW_SILENT) == OK && fcount > 0) { int i1; @@ -5324,7 +5328,11 @@ void ex_helptags(exarg_T *eap) STRCPY(NameBuff, dirname); add_pathsep(NameBuff); STRCAT(NameBuff, "**"); - if (gen_expand_wildcards(1, &NameBuff, &filecount, &files, + + // Note: We cannot just do `&NameBuff` because it is a statically sized array + // so `NameBuff == &NameBuff` according to C semantics. + char_u *buff_list[1] = {(char_u*) NameBuff}; + if (gen_expand_wildcards(1, buff_list, &filecount, &files, EW_FILE|EW_SILENT) == FAIL || filecount == 0) { EMSG2("E151: No match: %s", NameBuff); @@ -5422,7 +5430,11 @@ helptags_one ( STRCPY(NameBuff, dir); STRCAT(NameBuff, "/**/*"); STRCAT(NameBuff, ext); - if (gen_expand_wildcards(1, &NameBuff, &filecount, &files, + + // Note: We cannot just do `&NameBuff` because it is a statically sized array + // so `NameBuff == &NameBuff` according to C semantics. + char_u *buff_list[1] = {(char_u*) NameBuff}; + if (gen_expand_wildcards(1, buff_list, &filecount, &files, EW_FILE|EW_SILENT) == FAIL || filecount == 0) { if (!got_int) diff --git a/src/nvim/globals.h b/src/nvim/globals.h index f9d5a766c8..c0122ae189 100644 --- a/src/nvim/globals.h +++ b/src/nvim/globals.h @@ -40,6 +40,20 @@ # define MSG_BUF_CLEN (MSG_BUF_LEN / 6) // cell length (worst case: utf-8 // takes 6 bytes for one cell) +/* + * Maximum length of a path (for non-unix systems) Make it a bit long, to stay + * on the safe side. But not too long to put on the stack. + * TODO(metrix78): Move this to os_defs.h + */ +#ifndef MAXPATHL +# ifdef MAXPATHLEN +# define MAXPATHL MAXPATHLEN +# else +# define MAXPATHL 256 +# endif +#endif + + /* Values for "starting" */ #define NO_SCREEN 2 /* no screen updating yet */ #define NO_BUFFERS 1 /* not all buffers loaded yet */ @@ -841,11 +855,9 @@ EXTERN int swap_exists_action INIT(= SEA_NONE); EXTERN int swap_exists_did_quit INIT(= FALSE); /* Selected "quit" at the dialog. */ -EXTERN char_u IObuff[IOSIZE]; /* sprintf's are done in this buffer, - size is IOSIZE */ -EXTERN char_u *NameBuff; /* file names are expanded in this - * buffer, size is MAXPATHL */ -EXTERN char_u msg_buf[MSG_BUF_LEN]; /* small buffer for messages */ +EXTERN char_u IObuff[IOSIZE]; /* sprintf's are done in this buffer */ +EXTERN char_u NameBuff[MAXPATHL]; /* buffer for expanding file names */ +EXTERN char_u msg_buf[MSG_BUF_LEN]; /* small buffer for messages */ /* When non-zero, postpone redrawing. */ EXTERN int RedrawingDisabled INIT(= 0); diff --git a/src/nvim/main.c b/src/nvim/main.c index ac1366bfd9..6b8c2f4d4d 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -144,10 +144,6 @@ int main(int argc, char **argv) char_u *fname = NULL; /* file name from command line */ mparm_T params; /* various parameters passed between * main() and other functions. */ - /* - * Do any system-specific initialisations. These can NOT use IObuff or - * NameBuff. Thus emsg2() cannot be called! - */ mch_early_init(); /* Many variables are in "params" so that we can pass them to invoked @@ -167,12 +163,6 @@ int main(int argc, char **argv) /* Init the table of Normal mode commands. */ init_normal_cmds(); - /* - * Allocate space for the generic buffers (needed for set_init_1() and - * EMSG2()). - */ - allocate_generic_buffers(); - #if defined(HAVE_LOCALE_H) || defined(X_LOCALE) /* * Setup to use the current locale (for ctype() and many other things). @@ -1477,16 +1467,6 @@ static void init_startuptime(mparm_T *paramp) } /* - * Allocate space for the generic buffers (needed for set_init_1() and - * EMSG2()). - */ -static void allocate_generic_buffers(void) -{ - NameBuff = xmalloc(MAXPATHL); - TIME_MSG("Allocated generic buffers"); -} - -/* * Check if we have an interactive window. * On the Amiga: If there is no window, we open one with a newcli command * (needed for :! to * work). mch_check_win() will also handle the -d or diff --git a/src/nvim/memory.c b/src/nvim/memory.c index 9f68b6066b..50dcca3c84 100644 --- a/src/nvim/memory.c +++ b/src/nvim/memory.c @@ -510,8 +510,6 @@ void free_all_mem(void) free_screenlines(); clear_hl_tables(); - - free(NameBuff); } #endif diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c index ff2123bac1..2415858e0f 100644 --- a/src/nvim/quickfix.c +++ b/src/nvim/quickfix.c @@ -3540,7 +3540,11 @@ void ex_helpgrep(exarg_T *eap) /* Find all "*.txt" and "*.??x" files in the "doc" directory. */ add_pathsep(NameBuff); STRCAT(NameBuff, "doc/*.\\(txt\\|??x\\)"); - if (gen_expand_wildcards(1, &NameBuff, &fcount, + + // Note: We cannot just do `&NameBuff` because it is a statically sized array + // so `NameBuff == &NameBuff` according to C semantics. + char_u *buff_list[1] = {(char_u*) NameBuff}; + if (gen_expand_wildcards(1, buff_list, &fcount, &fnames, EW_FILE|EW_SILENT) == OK && fcount > 0) { for (fi = 0; fi < fcount && !got_int; ++fi) { diff --git a/src/nvim/tempfile.c b/src/nvim/tempfile.c index 41fc163936..c25da77717 100644 --- a/src/nvim/tempfile.c +++ b/src/nvim/tempfile.c @@ -60,7 +60,11 @@ void vim_deltempdir(void) char_u **files; int file_count; - if (gen_expand_wildcards(1, &NameBuff, &file_count, &files, + + // Note: We cannot just do `&NameBuff` because it is a statically + // sized array so `NameBuff == &NameBuff` according to C semantics. + char_u *buff_list[1] = {(char_u*) NameBuff}; + if (gen_expand_wildcards(1, buff_list, &file_count, &files, EW_DIR|EW_FILE|EW_SILENT) == OK) { for (int i = 0; i < file_count; ++i) { os_remove((char *)files[i]); diff --git a/src/nvim/vim.h b/src/nvim/vim.h index 5d903633e4..6479aeaafb 100644 --- a/src/nvim/vim.h +++ b/src/nvim/vim.h @@ -45,18 +45,6 @@ Error: configure did not run properly.Check auto/config.log. #include "nvim/os_unix_defs.h" /* bring lots of system header files */ -/* - * Maximum length of a path (for non-unix systems) Make it a bit long, to stay - * on the safe side. But not too long to put on the stack. - */ -#ifndef MAXPATHL -# ifdef MAXPATHLEN -# define MAXPATHL MAXPATHLEN -# else -# define MAXPATHL 256 -# endif -#endif - #define NUMBUFLEN 30 /* length of a buffer to store a number in ASCII */ # define MAX_TYPENR 65535 |