1 To: vim_dev@googlegroups.com
4 From: Bram Moolenaar <Bram@moolenaar.net>
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
11 Problem: Newer versions of MzScheme (Racket) require earlier (trampolined)
13 Solution: Call mzscheme_main() early in main(). (Sergey Khorev)
14 Files: src/Make_mvc.mak, src/if_mzsch.c, src/main.c,
15 src/proto/if_mzsch.pro
18 *** ../vim-7.3.440/src/Make_mvc.mak 2011-09-14 19:01:38.000000000 +0200
19 --- src/Make_mvc.mak 2012-02-12 01:46:05.000000000 +0100
25 MZSCHEME_OBJ = $(OUTDIR)\if_mzsch.obj
26 + # increase stack size
27 + MZSCHEME_LIB = $(MZSCHEME_LIB) /STACK:8388608
31 *** ../vim-7.3.440/src/if_mzsch.c 2010-11-03 21:59:23.000000000 +0100
32 --- src/if_mzsch.c 2012-02-12 01:47:31.000000000 +0100
36 #if defined(FEAT_MZSCHEME) || defined(PROTO)
40 /* Base data structures */
41 #define SCHEME_VIMBUFFERP(obj) SAME_TYPE(SCHEME_TYPE(obj), mz_buffer_type)
42 #define SCHEME_VIMWINDOWP(obj) SAME_TYPE(SCHEME_TYPE(obj), mz_window_type)
46 hMzSch = vimLoadLib(sch_dll);
47 hMzGC = vimLoadLib(gc_dll);
52 ! EMSG2(_(e_loadlib), sch_dll);
59 ! EMSG2(_(e_loadlib), gc_dll);
64 hMzSch = vimLoadLib(sch_dll);
65 hMzGC = vimLoadLib(gc_dll);
70 ! EMSG2(_(e_loadlib), gc_dll);
77 ! EMSG2(_(e_loadlib), sch_dll);
83 static __declspec(thread) void *tls_space;
89 #if MZSCHEME_VERSION_MAJOR >= 500 && defined(WIN32) && defined(USE_THREAD_LOCAL)
90 scheme_register_tls_space(&tls_space, 0);
92 ! #if defined(MZ_PRECISE_GC) && MZSCHEME_VERSION_MAJOR >= 400
93 ! /* use trampoline for precise GC in MzScheme >= 4.x */
94 ! scheme_main_setup(TRUE, mzscheme_env_main, 0, NULL);
96 ! mzscheme_env_main(NULL, 0, NULL);
101 ! mzscheme_env_main(Scheme_Env *env, int argc UNUSED, char **argv UNUSED)
103 ! /* neither argument nor return values are used */
104 ! #ifdef MZ_PRECISE_GC
105 ! # if MZSCHEME_VERSION_MAJOR < 400
107 ! * Starting from version 4.x, embedding applications must use
108 ! * scheme_main_setup/scheme_main_stack_setup trampolines
109 ! * rather than setting stack base directly with scheme_set_stack_base
111 Scheme_Object *dummy = NULL;
113 MZ_GC_VAR_IN_REG(0, dummy);
115 stack_base = &__gc_var_stack__;
117 - /* environment has been created by us by Scheme */
121 - * In 4.x, all activities must be performed inside trampoline
122 - * so we are forced to initialise GC immediately
123 - * This can be postponed in 3.x but I see no point in implementing
124 - * a feature which will work in older versions only.
125 - * One would better use conservative GC if he needs dynamic MzScheme
130 stack_base = (void *)&dummy;
132 ! main_loop(FALSE, FALSE);
133 ! #if defined(MZ_PRECISE_GC) && MZSCHEME_VERSION_MAJOR < 400
134 /* releasing dummy */
142 startup_mzscheme(void)
144 ! #if !defined(MZ_PRECISE_GC) || MZSCHEME_VERSION_MAJOR < 400
145 scheme_set_stack_base(stack_base, 1);
149 static __declspec(thread) void *tls_space;
153 ! * Since version 4.x precise GC requires trampolined startup.
154 ! * Futures and places in version 5.x need it too.
156 ! #if defined(MZ_PRECISE_GC) && MZSCHEME_VERSION_MAJOR >= 400 \
157 ! || MZSCHEME_VERSION_MAJOR >= 500 && (defined(MZ_USE_FUTURES) || defined(MZ_USE_PLACES))
158 ! # ifdef DYNAMIC_MZSCHEME
159 ! # error Precise GC v.4+ or Racket with futures/places do not support dynamic MzScheme
161 ! # define TRAMPOLINED_MZVIM_STARTUP
165 ! mzscheme_main(int argc, char** argv)
167 #if MZSCHEME_VERSION_MAJOR >= 500 && defined(WIN32) && defined(USE_THREAD_LOCAL)
168 scheme_register_tls_space(&tls_space, 0);
170 ! #ifdef TRAMPOLINED_MZVIM_STARTUP
171 ! return scheme_main_setup(TRUE, mzscheme_env_main, argc, argv);
173 ! return mzscheme_env_main(NULL, argc, argv);
178 ! mzscheme_env_main(Scheme_Env *env, int argc, char **argv)
180 ! int vim_main_result;
181 ! #ifdef TRAMPOLINED_MZVIM_STARTUP
182 ! /* Scheme has created the environment for us */
185 ! # ifdef MZ_PRECISE_GC
186 Scheme_Object *dummy = NULL;
188 MZ_GC_VAR_IN_REG(0, dummy);
190 stack_base = &__gc_var_stack__;
193 stack_base = (void *)&dummy;
197 ! /* mzscheme_main is called as a trampoline from main.
198 ! * We trampoline into vim_main2
199 ! * Passing argc, argv through from mzscheme_main
201 ! vim_main_result = vim_main2(argc, argv);
202 ! #if !defined(TRAMPOLINED_MZVIM_STARTUP) && defined(MZ_PRECISE_GC)
203 /* releasing dummy */
207 ! return vim_main_result;
211 startup_mzscheme(void)
213 ! #ifndef TRAMPOLINED_MZVIM_STARTUP
214 scheme_set_stack_base(stack_base, 1);
219 MZ_REGISTER_STATIC(exn_message);
220 MZ_REGISTER_STATIC(vim_exn);
222 ! #if !defined(MZ_PRECISE_GC) || MZSCHEME_VERSION_MAJOR < 400
223 /* in newer versions of precise GC the initial env has been created */
224 environment = scheme_basic_env();
227 MZ_REGISTER_STATIC(exn_message);
228 MZ_REGISTER_STATIC(vim_exn);
230 ! #ifndef TRAMPOLINED_MZVIM_STARTUP
231 /* in newer versions of precise GC the initial env has been created */
232 environment = scheme_basic_env();
238 tmp = scheme_make_struct_names(exn_name, scheme_null, 0, &nc);
240 mch_memmove(exn_names, tmp, nc * sizeof(Scheme_Object *));
244 *** ../vim-7.3.440/src/main.c 2011-12-08 15:57:54.000000000 +0100
245 --- src/main.c 2012-02-12 01:49:50.000000000 +0100
249 debug_break_level = params.use_debug_break_level;
252 + #ifdef FEAT_MZSCHEME
254 + * Newer version of MzScheme (Racket) require earlier (trampolined)
255 + * initialisation via scheme_main_setup.
256 + * Implement this by initialising it as early as possible
257 + * and splitting off remaining Vim main into vim_main2
260 + /* Pack up preprocessed command line arguments.
261 + * It is safe because Scheme does not access argc/argv. */
263 + args[0] = (char *)fname;
264 + args[1] = (char *)¶ms;
265 + return mzscheme_main(2, args);
269 + int vim_main2(int argc, char **argv)
271 + char_u *fname = (char_u *)argv[0];
274 + memcpy(¶ms, argv[1], sizeof(params));
277 /* Execute --cmd arguments. */
278 exe_pre_commands(¶ms);
284 * Call the main command loop. This never returns.
285 ! * For embedded MzScheme the main_loop will be called by Scheme
286 ! * for proper stack tracking
288 ! #ifndef FEAT_MZSCHEME
289 main_loop(FALSE, FALSE);
299 * Call the main command loop. This never returns.
301 main_loop(FALSE, FALSE);
305 *** ../vim-7.3.440/src/proto/if_mzsch.pro 2010-08-15 21:57:28.000000000 +0200
306 --- src/proto/if_mzsch.pro 2012-02-12 01:50:57.000000000 +0100
309 void mzvim_reset_timer __ARGS((void));
310 void *mzvim_eval_string __ARGS((char_u *str));
311 int mzthreads_allowed __ARGS((void));
312 ! void mzscheme_main __ARGS((void));
313 void do_mzeval __ARGS((char_u *str, typval_T *rettv));
314 /* vim: set ft=c : */
316 void mzvim_reset_timer __ARGS((void));
317 void *mzvim_eval_string __ARGS((char_u *str));
318 int mzthreads_allowed __ARGS((void));
319 ! int mzscheme_main __ARGS((int argc, char **argv));
320 void do_mzeval __ARGS((char_u *str, typval_T *rettv));
321 + int vim_main2 __ARGS((int argc, char **argv));
322 /* vim: set ft=c : */
323 *** ../vim-7.3.440/src/version.c 2012-02-12 01:35:06.000000000 +0100
324 --- src/version.c 2012-02-12 01:54:14.000000000 +0100
328 { /* Add new patch number below this line */
334 hundred-and-one symptoms of being an internet addict:
335 43. You tell the kids they can't use the computer because "Daddy's got work to
336 do" and you don't even have a job.
338 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
339 /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
340 \\\ an exciting new programming language -- http://www.Zimbu.org ///
341 \\\ help me help AIDS victims -- http://ICCF-Holland.org ///