Karsten Hopp 92d8bb
To: vim_dev@googlegroups.com
Karsten Hopp 92d8bb
Subject: Patch 7.3.441
Karsten Hopp 92d8bb
Fcc: outbox
Karsten Hopp 92d8bb
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp 92d8bb
Mime-Version: 1.0
Karsten Hopp 92d8bb
Content-Type: text/plain; charset=UTF-8
Karsten Hopp 92d8bb
Content-Transfer-Encoding: 8bit
Karsten Hopp 92d8bb
------------
Karsten Hopp 92d8bb
Karsten Hopp 92d8bb
Patch 7.3.441
Karsten Hopp 92d8bb
Problem:    Newer versions of MzScheme (Racket) require earlier (trampolined)
Karsten Hopp 92d8bb
            initialisation.
Karsten Hopp 92d8bb
Solution:   Call mzscheme_main() early in main(). (Sergey Khorev)
Karsten Hopp 92d8bb
Files:      src/Make_mvc.mak, src/if_mzsch.c, src/main.c,
Karsten Hopp 92d8bb
            src/proto/if_mzsch.pro
Karsten Hopp 92d8bb
    
Karsten Hopp 92d8bb
Karsten Hopp 92d8bb
*** ../vim-7.3.440/src/Make_mvc.mak	2011-09-14 19:01:38.000000000 +0200
Karsten Hopp 92d8bb
--- src/Make_mvc.mak	2012-02-12 01:46:05.000000000 +0100
Karsten Hopp 92d8bb
***************
Karsten Hopp 92d8bb
*** 740,745 ****
Karsten Hopp 92d8bb
--- 740,747 ----
Karsten Hopp 92d8bb
  !endif
Karsten Hopp 92d8bb
  !endif
Karsten Hopp 92d8bb
  MZSCHEME_OBJ = $(OUTDIR)\if_mzsch.obj
Karsten Hopp 92d8bb
+ # increase stack size
Karsten Hopp 92d8bb
+ MZSCHEME_LIB = $(MZSCHEME_LIB) /STACK:8388608
Karsten Hopp 92d8bb
  !endif
Karsten Hopp 92d8bb
  
Karsten Hopp 92d8bb
  # Perl interface
Karsten Hopp 92d8bb
*** ../vim-7.3.440/src/if_mzsch.c	2010-11-03 21:59:23.000000000 +0100
Karsten Hopp 92d8bb
--- src/if_mzsch.c	2012-02-12 01:47:31.000000000 +0100
Karsten Hopp 92d8bb
***************
Karsten Hopp 92d8bb
*** 31,38 ****
Karsten Hopp 92d8bb
   * depend". */
Karsten Hopp 92d8bb
  #if defined(FEAT_MZSCHEME) || defined(PROTO)
Karsten Hopp 92d8bb
  
Karsten Hopp 92d8bb
- #include <assert.h>
Karsten Hopp 92d8bb
- 
Karsten Hopp 92d8bb
  /* Base data structures */
Karsten Hopp 92d8bb
  #define SCHEME_VIMBUFFERP(obj)  SAME_TYPE(SCHEME_TYPE(obj), mz_buffer_type)
Karsten Hopp 92d8bb
  #define SCHEME_VIMWINDOWP(obj)  SAME_TYPE(SCHEME_TYPE(obj), mz_window_type)
Karsten Hopp 92d8bb
--- 31,36 ----
Karsten Hopp 92d8bb
***************
Karsten Hopp 92d8bb
*** 559,575 ****
Karsten Hopp 92d8bb
      hMzSch = vimLoadLib(sch_dll);
Karsten Hopp 92d8bb
      hMzGC = vimLoadLib(gc_dll);
Karsten Hopp 92d8bb
  
Karsten Hopp 92d8bb
!     if (!hMzSch)
Karsten Hopp 92d8bb
      {
Karsten Hopp 92d8bb
  	if (verbose)
Karsten Hopp 92d8bb
! 	    EMSG2(_(e_loadlib), sch_dll);
Karsten Hopp 92d8bb
  	return FAIL;
Karsten Hopp 92d8bb
      }
Karsten Hopp 92d8bb
  
Karsten Hopp 92d8bb
!     if (!hMzGC)
Karsten Hopp 92d8bb
      {
Karsten Hopp 92d8bb
  	if (verbose)
Karsten Hopp 92d8bb
! 	    EMSG2(_(e_loadlib), gc_dll);
Karsten Hopp 92d8bb
  	return FAIL;
Karsten Hopp 92d8bb
      }
Karsten Hopp 92d8bb
  
Karsten Hopp 92d8bb
--- 557,573 ----
Karsten Hopp 92d8bb
      hMzSch = vimLoadLib(sch_dll);
Karsten Hopp 92d8bb
      hMzGC = vimLoadLib(gc_dll);
Karsten Hopp 92d8bb
  
Karsten Hopp 92d8bb
!     if (!hMzGC)
Karsten Hopp 92d8bb
      {
Karsten Hopp 92d8bb
  	if (verbose)
Karsten Hopp 92d8bb
! 	    EMSG2(_(e_loadlib), gc_dll);
Karsten Hopp 92d8bb
  	return FAIL;
Karsten Hopp 92d8bb
      }
Karsten Hopp 92d8bb
  
Karsten Hopp 92d8bb
!     if (!hMzSch)
Karsten Hopp 92d8bb
      {
Karsten Hopp 92d8bb
  	if (verbose)
Karsten Hopp 92d8bb
! 	    EMSG2(_(e_loadlib), sch_dll);
Karsten Hopp 92d8bb
  	return FAIL;
Karsten Hopp 92d8bb
      }
Karsten Hopp 92d8bb
  
Karsten Hopp 92d8bb
***************
Karsten Hopp 92d8bb
*** 798,862 ****
Karsten Hopp 92d8bb
  static __declspec(thread) void *tls_space;
Karsten Hopp 92d8bb
  #endif
Karsten Hopp 92d8bb
  
Karsten Hopp 92d8bb
!     void
Karsten Hopp 92d8bb
! mzscheme_main(void)
Karsten Hopp 92d8bb
  {
Karsten Hopp 92d8bb
  #if MZSCHEME_VERSION_MAJOR >= 500 && defined(WIN32) && defined(USE_THREAD_LOCAL)
Karsten Hopp 92d8bb
      scheme_register_tls_space(&tls_space, 0);
Karsten Hopp 92d8bb
  #endif
Karsten Hopp 92d8bb
! #if defined(MZ_PRECISE_GC) && MZSCHEME_VERSION_MAJOR >= 400
Karsten Hopp 92d8bb
!     /* use trampoline for precise GC in MzScheme >= 4.x */
Karsten Hopp 92d8bb
!     scheme_main_setup(TRUE, mzscheme_env_main, 0, NULL);
Karsten Hopp 92d8bb
  #else
Karsten Hopp 92d8bb
!     mzscheme_env_main(NULL, 0, NULL);
Karsten Hopp 92d8bb
  #endif
Karsten Hopp 92d8bb
  }
Karsten Hopp 92d8bb
  
Karsten Hopp 92d8bb
      static int
Karsten Hopp 92d8bb
! mzscheme_env_main(Scheme_Env *env, int argc UNUSED, char **argv UNUSED)
Karsten Hopp 92d8bb
  {
Karsten Hopp 92d8bb
!     /* neither argument nor return values are used */
Karsten Hopp 92d8bb
! #ifdef MZ_PRECISE_GC
Karsten Hopp 92d8bb
! # if MZSCHEME_VERSION_MAJOR < 400
Karsten Hopp 92d8bb
!     /*
Karsten Hopp 92d8bb
!      * Starting from version 4.x, embedding applications must use
Karsten Hopp 92d8bb
!      * scheme_main_setup/scheme_main_stack_setup trampolines
Karsten Hopp 92d8bb
!      * rather than setting stack base directly with scheme_set_stack_base
Karsten Hopp 92d8bb
!      */
Karsten Hopp 92d8bb
      Scheme_Object   *dummy = NULL;
Karsten Hopp 92d8bb
      MZ_GC_DECL_REG(1);
Karsten Hopp 92d8bb
      MZ_GC_VAR_IN_REG(0, dummy);
Karsten Hopp 92d8bb
  
Karsten Hopp 92d8bb
      stack_base = &__gc_var_stack__;
Karsten Hopp 92d8bb
  # else
Karsten Hopp 92d8bb
-     /* environment has been created by us by Scheme */
Karsten Hopp 92d8bb
-     environment = env;
Karsten Hopp 92d8bb
- # endif
Karsten Hopp 92d8bb
-     /*
Karsten Hopp 92d8bb
-      * In 4.x, all activities must be performed inside trampoline
Karsten Hopp 92d8bb
-      * so we are forced to initialise GC immediately
Karsten Hopp 92d8bb
-      * This can be postponed in 3.x but I see no point in implementing
Karsten Hopp 92d8bb
-      * a feature which will work in older versions only.
Karsten Hopp 92d8bb
-      * One would better use conservative GC if he needs dynamic MzScheme
Karsten Hopp 92d8bb
-      */
Karsten Hopp 92d8bb
-     mzscheme_init();
Karsten Hopp 92d8bb
- #else
Karsten Hopp 92d8bb
      int dummy = 0;
Karsten Hopp 92d8bb
      stack_base = (void *)&dummy;
Karsten Hopp 92d8bb
  #endif
Karsten Hopp 92d8bb
!     main_loop(FALSE, FALSE);
Karsten Hopp 92d8bb
! #if defined(MZ_PRECISE_GC) && MZSCHEME_VERSION_MAJOR < 400
Karsten Hopp 92d8bb
      /* releasing dummy */
Karsten Hopp 92d8bb
      MZ_GC_REG();
Karsten Hopp 92d8bb
      MZ_GC_UNREG();
Karsten Hopp 92d8bb
  #endif
Karsten Hopp 92d8bb
!     return 0;
Karsten Hopp 92d8bb
  }
Karsten Hopp 92d8bb
  
Karsten Hopp 92d8bb
      static void
Karsten Hopp 92d8bb
  startup_mzscheme(void)
Karsten Hopp 92d8bb
  {
Karsten Hopp 92d8bb
! #if !defined(MZ_PRECISE_GC) || MZSCHEME_VERSION_MAJOR < 400
Karsten Hopp 92d8bb
      scheme_set_stack_base(stack_base, 1);
Karsten Hopp 92d8bb
  #endif
Karsten Hopp 92d8bb
  
Karsten Hopp 92d8bb
--- 796,863 ----
Karsten Hopp 92d8bb
  static __declspec(thread) void *tls_space;
Karsten Hopp 92d8bb
  #endif
Karsten Hopp 92d8bb
  
Karsten Hopp 92d8bb
! /*
Karsten Hopp 92d8bb
!  * Since version 4.x precise GC requires trampolined startup.
Karsten Hopp 92d8bb
!  * Futures and places in version 5.x need it too.
Karsten Hopp 92d8bb
!  */
Karsten Hopp 92d8bb
! #if defined(MZ_PRECISE_GC) && MZSCHEME_VERSION_MAJOR >= 400 \
Karsten Hopp 92d8bb
!     || MZSCHEME_VERSION_MAJOR >= 500 && (defined(MZ_USE_FUTURES) || defined(MZ_USE_PLACES))
Karsten Hopp 92d8bb
! # ifdef DYNAMIC_MZSCHEME
Karsten Hopp 92d8bb
! #  error Precise GC v.4+ or Racket with futures/places do not support dynamic MzScheme
Karsten Hopp 92d8bb
! # endif
Karsten Hopp 92d8bb
! # define TRAMPOLINED_MZVIM_STARTUP
Karsten Hopp 92d8bb
! #endif
Karsten Hopp 92d8bb
! 
Karsten Hopp 92d8bb
!     int
Karsten Hopp 92d8bb
! mzscheme_main(int argc, char** argv)
Karsten Hopp 92d8bb
  {
Karsten Hopp 92d8bb
  #if MZSCHEME_VERSION_MAJOR >= 500 && defined(WIN32) && defined(USE_THREAD_LOCAL)
Karsten Hopp 92d8bb
      scheme_register_tls_space(&tls_space, 0);
Karsten Hopp 92d8bb
  #endif
Karsten Hopp 92d8bb
! #ifdef TRAMPOLINED_MZVIM_STARTUP
Karsten Hopp 92d8bb
!     return scheme_main_setup(TRUE, mzscheme_env_main, argc, argv);
Karsten Hopp 92d8bb
  #else
Karsten Hopp 92d8bb
!     return mzscheme_env_main(NULL, argc, argv);
Karsten Hopp 92d8bb
  #endif
Karsten Hopp 92d8bb
  }
Karsten Hopp 92d8bb
  
Karsten Hopp 92d8bb
      static int
Karsten Hopp 92d8bb
! mzscheme_env_main(Scheme_Env *env, int argc, char **argv)
Karsten Hopp 92d8bb
  {
Karsten Hopp 92d8bb
!     int vim_main_result;
Karsten Hopp 92d8bb
! #ifdef TRAMPOLINED_MZVIM_STARTUP
Karsten Hopp 92d8bb
!     /* Scheme has created the environment for us */
Karsten Hopp 92d8bb
!     environment = env;
Karsten Hopp 92d8bb
! #else
Karsten Hopp 92d8bb
! # ifdef MZ_PRECISE_GC
Karsten Hopp 92d8bb
      Scheme_Object   *dummy = NULL;
Karsten Hopp 92d8bb
      MZ_GC_DECL_REG(1);
Karsten Hopp 92d8bb
      MZ_GC_VAR_IN_REG(0, dummy);
Karsten Hopp 92d8bb
  
Karsten Hopp 92d8bb
      stack_base = &__gc_var_stack__;
Karsten Hopp 92d8bb
  # else
Karsten Hopp 92d8bb
      int dummy = 0;
Karsten Hopp 92d8bb
      stack_base = (void *)&dummy;
Karsten Hopp 92d8bb
+ # endif
Karsten Hopp 92d8bb
  #endif
Karsten Hopp 92d8bb
! 
Karsten Hopp 92d8bb
!     /* mzscheme_main is called as a trampoline from main.
Karsten Hopp 92d8bb
!      * We trampoline into vim_main2
Karsten Hopp 92d8bb
!      * Passing argc, argv through from mzscheme_main
Karsten Hopp 92d8bb
!      */
Karsten Hopp 92d8bb
!     vim_main_result = vim_main2(argc, argv);
Karsten Hopp 92d8bb
! #if !defined(TRAMPOLINED_MZVIM_STARTUP) && defined(MZ_PRECISE_GC)
Karsten Hopp 92d8bb
      /* releasing dummy */
Karsten Hopp 92d8bb
      MZ_GC_REG();
Karsten Hopp 92d8bb
      MZ_GC_UNREG();
Karsten Hopp 92d8bb
  #endif
Karsten Hopp 92d8bb
!     return vim_main_result;
Karsten Hopp 92d8bb
  }
Karsten Hopp 92d8bb
  
Karsten Hopp 92d8bb
      static void
Karsten Hopp 92d8bb
  startup_mzscheme(void)
Karsten Hopp 92d8bb
  {
Karsten Hopp 92d8bb
! #ifndef TRAMPOLINED_MZVIM_STARTUP
Karsten Hopp 92d8bb
      scheme_set_stack_base(stack_base, 1);
Karsten Hopp 92d8bb
  #endif
Karsten Hopp 92d8bb
  
Karsten Hopp 92d8bb
***************
Karsten Hopp 92d8bb
*** 868,874 ****
Karsten Hopp 92d8bb
      MZ_REGISTER_STATIC(exn_message);
Karsten Hopp 92d8bb
      MZ_REGISTER_STATIC(vim_exn);
Karsten Hopp 92d8bb
  
Karsten Hopp 92d8bb
! #if !defined(MZ_PRECISE_GC) || MZSCHEME_VERSION_MAJOR < 400
Karsten Hopp 92d8bb
      /* in newer versions of precise GC the initial env has been created */
Karsten Hopp 92d8bb
      environment = scheme_basic_env();
Karsten Hopp 92d8bb
  #endif
Karsten Hopp 92d8bb
--- 869,875 ----
Karsten Hopp 92d8bb
      MZ_REGISTER_STATIC(exn_message);
Karsten Hopp 92d8bb
      MZ_REGISTER_STATIC(vim_exn);
Karsten Hopp 92d8bb
  
Karsten Hopp 92d8bb
! #ifndef TRAMPOLINED_MZVIM_STARTUP
Karsten Hopp 92d8bb
      /* in newer versions of precise GC the initial env has been created */
Karsten Hopp 92d8bb
      environment = scheme_basic_env();
Karsten Hopp 92d8bb
  #endif
Karsten Hopp 92d8bb
***************
Karsten Hopp 92d8bb
*** 3013,3019 ****
Karsten Hopp 92d8bb
  	MZ_GC_REG();
Karsten Hopp 92d8bb
  
Karsten Hopp 92d8bb
  	tmp = scheme_make_struct_names(exn_name, scheme_null, 0, &nc);
Karsten Hopp 92d8bb
- 	assert(nc <= 5);
Karsten Hopp 92d8bb
  	mch_memmove(exn_names, tmp, nc * sizeof(Scheme_Object *));
Karsten Hopp 92d8bb
  	MZ_GC_CHECK();
Karsten Hopp 92d8bb
  
Karsten Hopp 92d8bb
--- 3014,3019 ----
Karsten Hopp 92d8bb
*** ../vim-7.3.440/src/main.c	2011-12-08 15:57:54.000000000 +0100
Karsten Hopp 92d8bb
--- src/main.c	2012-02-12 01:49:50.000000000 +0100
Karsten Hopp 92d8bb
***************
Karsten Hopp 92d8bb
*** 554,559 ****
Karsten Hopp 92d8bb
--- 554,584 ----
Karsten Hopp 92d8bb
      debug_break_level = params.use_debug_break_level;
Karsten Hopp 92d8bb
  #endif
Karsten Hopp 92d8bb
  
Karsten Hopp 92d8bb
+ #ifdef FEAT_MZSCHEME
Karsten Hopp 92d8bb
+     /*
Karsten Hopp 92d8bb
+      * Newer version of MzScheme (Racket) require earlier (trampolined)
Karsten Hopp 92d8bb
+      * initialisation via scheme_main_setup.
Karsten Hopp 92d8bb
+      * Implement this by initialising it as early as possible
Karsten Hopp 92d8bb
+      * and splitting off remaining Vim main into vim_main2
Karsten Hopp 92d8bb
+      */
Karsten Hopp 92d8bb
+     {
Karsten Hopp 92d8bb
+ 	/* Pack up preprocessed command line arguments.
Karsten Hopp 92d8bb
+ 	 * It is safe because Scheme does not access argc/argv. */
Karsten Hopp 92d8bb
+ 	char *args[2];
Karsten Hopp 92d8bb
+ 	args[0] = (char *)fname;
Karsten Hopp 92d8bb
+ 	args[1] = (char *)¶m;;
Karsten Hopp 92d8bb
+ 	return mzscheme_main(2, args);
Karsten Hopp 92d8bb
+     }
Karsten Hopp 92d8bb
+ }
Karsten Hopp 92d8bb
+ 
Karsten Hopp 92d8bb
+ int vim_main2(int argc, char **argv)
Karsten Hopp 92d8bb
+ {
Karsten Hopp 92d8bb
+     char_u	*fname = (char_u *)argv[0];
Karsten Hopp 92d8bb
+     mparm_T	params;
Karsten Hopp 92d8bb
+ 
Karsten Hopp 92d8bb
+     memcpy(&params, argv[1], sizeof(params));
Karsten Hopp 92d8bb
+ #endif
Karsten Hopp 92d8bb
+ 
Karsten Hopp 92d8bb
      /* Execute --cmd arguments. */
Karsten Hopp 92d8bb
      exe_pre_commands(&params);
Karsten Hopp 92d8bb
  
Karsten Hopp 92d8bb
***************
Karsten Hopp 92d8bb
*** 957,970 ****
Karsten Hopp 92d8bb
  
Karsten Hopp 92d8bb
      /*
Karsten Hopp 92d8bb
       * Call the main command loop.  This never returns.
Karsten Hopp 92d8bb
!      * For embedded MzScheme the main_loop will be called by Scheme
Karsten Hopp 92d8bb
!      * for proper stack tracking
Karsten Hopp 92d8bb
!      */
Karsten Hopp 92d8bb
! #ifndef FEAT_MZSCHEME
Karsten Hopp 92d8bb
      main_loop(FALSE, FALSE);
Karsten Hopp 92d8bb
- #else
Karsten Hopp 92d8bb
-     mzscheme_main();
Karsten Hopp 92d8bb
- #endif
Karsten Hopp 92d8bb
  
Karsten Hopp 92d8bb
      return 0;
Karsten Hopp 92d8bb
  }
Karsten Hopp 92d8bb
--- 982,989 ----
Karsten Hopp 92d8bb
  
Karsten Hopp 92d8bb
      /*
Karsten Hopp 92d8bb
       * Call the main command loop.  This never returns.
Karsten Hopp 92d8bb
!     */
Karsten Hopp 92d8bb
      main_loop(FALSE, FALSE);
Karsten Hopp 92d8bb
  
Karsten Hopp 92d8bb
      return 0;
Karsten Hopp 92d8bb
  }
Karsten Hopp 92d8bb
*** ../vim-7.3.440/src/proto/if_mzsch.pro	2010-08-15 21:57:28.000000000 +0200
Karsten Hopp 92d8bb
--- src/proto/if_mzsch.pro	2012-02-12 01:50:57.000000000 +0100
Karsten Hopp 92d8bb
***************
Karsten Hopp 92d8bb
*** 14,19 ****
Karsten Hopp 92d8bb
  void mzvim_reset_timer __ARGS((void));
Karsten Hopp 92d8bb
  void *mzvim_eval_string __ARGS((char_u *str));
Karsten Hopp 92d8bb
  int mzthreads_allowed __ARGS((void));
Karsten Hopp 92d8bb
! void mzscheme_main __ARGS((void));
Karsten Hopp 92d8bb
  void do_mzeval __ARGS((char_u *str, typval_T *rettv));
Karsten Hopp 92d8bb
  /* vim: set ft=c : */
Karsten Hopp 92d8bb
--- 14,20 ----
Karsten Hopp 92d8bb
  void mzvim_reset_timer __ARGS((void));
Karsten Hopp 92d8bb
  void *mzvim_eval_string __ARGS((char_u *str));
Karsten Hopp 92d8bb
  int mzthreads_allowed __ARGS((void));
Karsten Hopp 92d8bb
! int mzscheme_main __ARGS((int argc, char **argv));
Karsten Hopp 92d8bb
  void do_mzeval __ARGS((char_u *str, typval_T *rettv));
Karsten Hopp 92d8bb
+ int vim_main2 __ARGS((int argc, char **argv));
Karsten Hopp 92d8bb
  /* vim: set ft=c : */
Karsten Hopp 92d8bb
*** ../vim-7.3.440/src/version.c	2012-02-12 01:35:06.000000000 +0100
Karsten Hopp 92d8bb
--- src/version.c	2012-02-12 01:54:14.000000000 +0100
Karsten Hopp 92d8bb
***************
Karsten Hopp 92d8bb
*** 716,717 ****
Karsten Hopp 92d8bb
--- 716,719 ----
Karsten Hopp 92d8bb
  {   /* Add new patch number below this line */
Karsten Hopp 92d8bb
+ /**/
Karsten Hopp 92d8bb
+     441,
Karsten Hopp 92d8bb
  /**/
Karsten Hopp 92d8bb
Karsten Hopp 92d8bb
-- 
Karsten Hopp 92d8bb
hundred-and-one symptoms of being an internet addict:
Karsten Hopp 92d8bb
43. You tell the kids they can't use the computer because "Daddy's got work to
Karsten Hopp 92d8bb
    do" and you don't even have a job.
Karsten Hopp 92d8bb
Karsten Hopp 92d8bb
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp 92d8bb
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp 92d8bb
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
Karsten Hopp 92d8bb
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///