Skip to content

Commit a8e691d

Browse files
committed
patch 7.4.2176
Problem: #ifdefs in main() are complicated. Solution: Always define vim_main2(). Move params to the file level. (suggested by Ken Takata)
1 parent 812ad4f commit a8e691d

6 files changed

Lines changed: 45 additions & 52 deletions

File tree

src/if_mzsch.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,8 +1009,11 @@ static intptr_t _tls_index = 0;
10091009
#endif
10101010

10111011
int
1012-
mzscheme_main(int argc, char** argv)
1012+
mzscheme_main()
10131013
{
1014+
int argc = 0;
1015+
char *argv = NULL;
1016+
10141017
#ifdef DYNAMIC_MZSCHEME
10151018
/*
10161019
* Racket requires trampolined startup. We can not load it later.
@@ -1019,16 +1022,16 @@ mzscheme_main(int argc, char** argv)
10191022
if (!mzscheme_enabled(FALSE))
10201023
{
10211024
disabled = TRUE;
1022-
return vim_main2(argc, argv);
1025+
return vim_main2();
10231026
}
10241027
#endif
10251028
#ifdef HAVE_TLS_SPACE
10261029
scheme_register_tls_space(&tls_space, _tls_index);
10271030
#endif
10281031
#ifdef TRAMPOLINED_MZVIM_STARTUP
1029-
return scheme_main_setup(TRUE, mzscheme_env_main, argc, argv);
1032+
return scheme_main_setup(TRUE, mzscheme_env_main, argc, &argv);
10301033
#else
1031-
return mzscheme_env_main(NULL, argc, argv);
1034+
return mzscheme_env_main(NULL, argc, &argv);
10321035
#endif
10331036
}
10341037

@@ -1056,7 +1059,7 @@ mzscheme_env_main(Scheme_Env *env, int argc, char **argv)
10561059
* We trampoline into vim_main2
10571060
* Passing argc, argv through from mzscheme_main
10581061
*/
1059-
vim_main_result = vim_main2(argc, argv);
1062+
vim_main_result = vim_main2();
10601063
#if !defined(TRAMPOLINED_MZVIM_STARTUP) && defined(MZ_PRECISE_GC)
10611064
/* releasing dummy */
10621065
MZ_GC_REG();

src/main.c

Lines changed: 29 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ static char_u *start_dir = NULL; /* current working dir on startup */
9292

9393
static int has_dash_c_arg = FALSE;
9494

95+
/* Various parameters passed between main() and other functions. */
96+
static mparm_T params;
97+
9598
int
9699
# ifdef VIMDLL
97100
_export
@@ -106,9 +109,6 @@ main
106109
# endif
107110
(int argc, char **argv)
108111
{
109-
char_u *fname = NULL; /* file name from command line */
110-
mparm_T params; /* various parameters passed between
111-
* main() and other functions. */
112112
#ifdef STARTUPTIME
113113
int i;
114114
#endif
@@ -157,6 +157,7 @@ main
157157
#endif
158158

159159
#ifdef STARTUPTIME
160+
/* Need to find "--startuptime" before actually parsing arguments. */
160161
for (i = 1; i < argc; ++i)
161162
{
162163
if (STRICMP(argv[i], "--startuptime") == 0 && i + 1 < argc)
@@ -241,7 +242,7 @@ main
241242
mch_chdir((char *)start_dir);
242243
}
243244
#endif
244-
fname = alist_name(&GARGLIST[0]);
245+
params.fname = alist_name(&GARGLIST[0]);
245246
}
246247

247248
#if defined(WIN32) && defined(FEAT_MBYTE)
@@ -263,7 +264,7 @@ main
263264
* Hint: to avoid this when typing a command use a forward slash.
264265
* If the cd fails, it doesn't matter.
265266
*/
266-
(void)vim_chdirfile(fname);
267+
(void)vim_chdirfile(params.fname);
267268
if (start_dir != NULL)
268269
mch_dirname(start_dir, MAXPATHL);
269270
}
@@ -281,7 +282,7 @@ main
281282
/*
282283
* When listing swap file names, don't do cursor positioning et. al.
283284
*/
284-
if (recoverymode && fname == NULL)
285+
if (recoverymode && params.fname == NULL)
285286
params.want_full_screen = FALSE;
286287

287288
/*
@@ -312,8 +313,8 @@ main
312313
if (getcwd((char *)NameBuff, MAXPATHL) != NULL
313314
&& STRCMP(NameBuff, "/") == 0)
314315
{
315-
if (fname != NULL)
316-
(void)vim_chdirfile(fname);
316+
if (params.fname != NULL)
317+
(void)vim_chdirfile(params.fname);
317318
else
318319
{
319320
expand_env((char_u *)"$HOME", NameBuff, MAXPATHL);
@@ -407,37 +408,23 @@ main
407408
* Newer version of MzScheme (Racket) require earlier (trampolined)
408409
* initialisation via scheme_main_setup.
409410
* Implement this by initialising it as early as possible
410-
* and splitting off remaining Vim main into vim_main2
411+
* and splitting off remaining Vim main into vim_main2().
411412
*/
412-
{
413-
/* Pack up preprocessed command line arguments.
414-
* It is safe because Scheme does not access argc/argv. */
415-
char *args[2];
416-
args[0] = (char *)fname;
417-
args[1] = (char *)&params;
418-
return mzscheme_main(2, args);
419-
}
420-
}
413+
return mzscheme_main();
414+
#else
415+
return vim_main2();
421416
#endif
417+
}
422418
#endif /* NO_VIM_MAIN */
423419

424-
/* vim_main2() needs to be produced when FEAT_MZSCHEME is defined even when
425-
* NO_VIM_MAIN is defined. */
426-
#ifdef FEAT_MZSCHEME
420+
/*
421+
* vim_main2() is needed for FEAT_MZSCHEME, but we define it always to keep
422+
* things simple.
423+
* It is also defined when NO_VIM_MAIN is defined, but then it's empty.
424+
*/
427425
int
428-
vim_main2(int argc UNUSED, char **argv UNUSED)
426+
vim_main2(void)
429427
{
430-
# ifndef NO_VIM_MAIN
431-
char_u *fname = (char_u *)argv[0];
432-
mparm_T params;
433-
434-
memcpy(&params, argv[1], sizeof(params));
435-
# else
436-
return 0;
437-
}
438-
# endif
439-
#endif
440-
441428
#ifndef NO_VIM_MAIN
442429
/* Reset 'loadplugins' for "-u NONE" before "--cmd" arguments.
443430
* Allows for setting 'loadplugins' there. */
@@ -493,7 +480,7 @@ vim_main2(int argc UNUSED, char **argv UNUSED)
493480
* This uses the 'dir' option, therefore it must be after the
494481
* initializations.
495482
*/
496-
if (recoverymode && fname == NULL)
483+
if (recoverymode && params.fname == NULL)
497484
{
498485
recover_names(NULL, TRUE, 0, NULL);
499486
mch_exit(0);
@@ -888,16 +875,17 @@ vim_main2(int argc UNUSED, char **argv UNUSED)
888875
*/
889876
main_loop(FALSE, FALSE);
890877

878+
#endif /* NO_VIM_MAIN */
879+
891880
return 0;
892881
}
893-
#endif /* NO_VIM_MAIN */
894882
#endif /* PROTO */
895883

896884
/*
897885
* Initialisation shared by main() and some tests.
898886
*/
899887
void
900-
common_init(mparm_T *params)
888+
common_init(mparm_T *paramp)
901889
{
902890

903891
#ifdef FEAT_MBYTE
@@ -914,7 +902,7 @@ common_init(mparm_T *params)
914902
#ifdef MAC_OS_CLASSIC
915903
/* Prepare for possibly starting GUI sometime */
916904
/* Macintosh needs this before any memory is allocated. */
917-
gui_prepare(&params->argc, params->argv);
905+
gui_prepare(&paramp->argc, paramp->argv);
918906
TIME_MSG("GUI prepared");
919907
#endif
920908

@@ -963,14 +951,14 @@ common_init(mparm_T *params)
963951
* --socketid
964952
* --windowid
965953
*/
966-
early_arg_scan(params);
954+
early_arg_scan(paramp);
967955

968956
#ifdef FEAT_SUN_WORKSHOP
969-
findYourself(params->argv[0]);
957+
findYourself(paramp->argv[0]);
970958
#endif
971959
#if defined(FEAT_GUI) && !defined(MAC_OS_CLASSIC)
972960
/* Prepare for possibly starting GUI sometime */
973-
gui_prepare(&params->argc, params->argv);
961+
gui_prepare(&paramp->argc, paramp->argv);
974962
TIME_MSG("GUI prepared");
975963
#endif
976964

@@ -985,7 +973,7 @@ common_init(mparm_T *params)
985973
* (needed for :! to * work). mch_check_win() will also handle the -d or
986974
* -dev argument.
987975
*/
988-
params->stdout_isatty = (mch_check_win(params->argc, params->argv) != FAIL);
976+
paramp->stdout_isatty = (mch_check_win(paramp->argc, paramp->argv) != FAIL);
989977
TIME_MSG("window checked");
990978

991979
/*

src/proto/if_mzsch.pro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ int mzscheme_enabled(int verbose);
33
void mzvim_check_threads(void);
44
void mzvim_reset_timer(void);
55
void mzscheme_end(void);
6-
int mzscheme_main(int argc, char **argv);
6+
int mzscheme_main(void);
77
void mzscheme_buffer_free(buf_T *buf);
88
void mzscheme_window_free(win_T *win);
99
void ex_mzscheme(exarg_T *eap);

src/structs.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3160,7 +3160,7 @@ struct timer_S
31603160
timer_T *tr_prev;
31613161
proftime_T tr_due; /* when the callback is to be invoked */
31623162
int tr_repeat; /* number of times to repeat, -1 forever */
3163-
long tr_interval; /* only set when it repeats */
3163+
long tr_interval; /* msec */
31643164
char_u *tr_callback; /* allocated */
31653165
partial_T *tr_partial;
31663166
#endif
@@ -3180,6 +3180,8 @@ typedef struct
31803180
int argc;
31813181
char **argv;
31823182

3183+
char_u *fname; /* first file to edit */
3184+
31833185
int evim_mode; /* started as "evim" */
31843186
char_u *use_vimrc; /* vimrc from -u argument */
31853187

src/version.c

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

764764
static int included_patches[] =
765765
{ /* Add new patch number below this line */
766+
/**/
767+
2176,
766768
/**/
767769
2175,
768770
/**/

src/vim.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2439,10 +2439,8 @@ typedef enum
24392439
#define JSON_JS 1 /* use JS instead of JSON */
24402440
#define JSON_NO_NONE 2 /* v:none item not allowed */
24412441

2442-
#ifdef FEAT_MZSCHEME
2443-
/* this is in main.c, cproto can't handle it. */
2444-
int vim_main2(int argc, char **argv);
2445-
#endif
2442+
/* This is in main.c, cproto can't handle it. */
2443+
int vim_main2(void);
24462444

24472445
/* Used for flags of do_in_path() */
24482446
#define DIP_ALL 0x01 /* all matches, not just the first one */

0 commit comments

Comments
 (0)