home *** CD-ROM | disk | FTP | other *** search
/ vim.ftp.fu-berlin.de / 2015-02-03.vim.ftp.fu-berlin.de.tar / vim.ftp.fu-berlin.de / patches / 7.2 / 7.2.191 < prev    next >
Encoding:
Internet Message Format  |  2009-05-25  |  104.0 KB

  1. To: vim-dev@vim.org
  2. Subject: Patch 7.2.191
  3. Fcc: outbox
  4. From: Bram Moolenaar <Bram@moolenaar.net>
  5. Mime-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. ------------
  9.  
  10. Patch 7.2.191
  11. Problem:    Mzscheme interface doesn't work on Ubuntu.
  12. Solution:   Change autoconf rules.  Define missing macro.  Some changes to
  13.         avoid gcc warnings.  Remove per-buffer namespace. (Sergey Khorev)
  14. Files:        runtime/doc/if_mzsch.txt, src/Makefile, src/Make_ming.mak,
  15.         src/Make_mvc.mak, src/auto/configure, src/configure.in,
  16.         src/config.mk.in, src/eval.c, src/if_mzsch.c, src/if_mzsch.h,
  17.         src/main.c, src/proto/if_mzsch.pro
  18.  
  19.  
  20. *** ../vim-7.2.190/runtime/doc/if_mzsch.txt    2008-08-09 19:36:48.000000000 +0200
  21. --- runtime/doc/if_mzsch.txt    2009-05-26 18:49:53.000000000 +0200
  22. ***************
  23. *** 1,4 ****
  24. ! *if_mzsch.txt*  For Vim version 7.2.  Last change: 2008 Jun 28
  25.   
  26.   
  27.             VIM REFERENCE MANUAL    by Sergey Khorev
  28. --- 1,4 ----
  29. ! *if_mzsch.txt*  For Vim version 7.2.  Last change: 2009 May 26
  30.   
  31.   
  32.             VIM REFERENCE MANUAL    by Sergey Khorev
  33. ***************
  34. *** 42,51 ****
  35.   
  36.                               *:mzfile* *:mzf*
  37.   :[range]mzf[ile] {file}    Execute the MzScheme script in {file}.  {not in Vi}
  38. -             All statements are executed in the namespace of the
  39. -             buffer that was current during :mzfile start.
  40. -             If you want to access other namespaces, use
  41. -             'parameterize'.
  42.   
  43.   All of these commands do essentially the same thing - they execute a piece of
  44.   MzScheme code, with the "current range" set to the given line
  45. --- 42,47 ----
  46. ***************
  47. *** 54,61 ****
  48.   In the case of :mzscheme, the code to execute is in the command-line.
  49.   In the case of :mzfile, the code to execute is the contents of the given file.
  50.   
  51. - Each buffer has its own MzScheme namespace. Global namespace is bound to
  52. - the "global-namespace" value from the 'vimext' module.
  53.   MzScheme interface defines exception exn:vim, derived from exn.
  54.   It is raised for various Vim errors.
  55.   
  56. --- 50,55 ----
  57. ***************
  58. *** 79,118 ****
  59.   e.g.: >
  60.       :mzscheme (require (prefix vim- vimext))
  61.   <
  62. ! All the examples below assume this naming scheme.  Note that you need to do
  63. ! this again for every buffer.
  64.   
  65. - The auto-instantiation can be achieved with autocommands, e.g. you can put
  66. - something like this in your .vimrc (EOFs should not have indentation): >
  67. -     function s:MzRequire()
  68. -     if has("mzscheme")
  69. -         :mz << EOF
  70. -         (require (prefix vim- vimext))
  71. -         (let ((buf (vim-get-buff-by-name (vim-eval "expand(\"<afile>\")"))))
  72. -           (when (and buf (not (eq? buf (vim-curr-buff))))
  73. -         (parameterize ((current-namespace (vim-get-buff-namespace buf)))
  74. -           (namespace-attach-module vim-global-namespace 'vimext)
  75. -           (namespace-require '(prefix vim vimext)))))
  76. -     EOF
  77. -     endif
  78. -     endfunction
  79. -     function s:MzStartup()
  80. -     if has("mzscheme")
  81. -         au BufNew,BufNewFile,BufAdd,BufReadPre * :call s:MzRequire()
  82. -         :mz << EOF
  83. -         (current-library-collection-paths
  84. -         (cons
  85. -             (build-path (find-system-path 'addon-dir) (version) "collects")
  86. -             (current-library-collection-paths)))
  87. -     EOF
  88. -     endif
  89. -     endfunction
  90. -     call s:MzStartup()
  91. - <
  92. - The global namespace just instantiated this module with the prefix "vimext:".
  93.                               *mzscheme-sandbox*
  94.   When executed in the |sandbox|, access to some filesystem and Vim interface
  95.   procedures is restricted.
  96. --- 73,80 ----
  97.   e.g.: >
  98.       :mzscheme (require (prefix vim- vimext))
  99.   <
  100. ! All the examples below assume this naming scheme. 
  101.   
  102.                               *mzscheme-sandbox*
  103.   When executed in the |sandbox|, access to some filesystem and Vim interface
  104.   procedures is restricted.
  105. ***************
  106. *** 121,135 ****
  107.   2. Examples                        *mzscheme-examples*
  108.   >
  109.       :mzscheme (display "Hello")
  110.       :mzscheme (vim-set-buff-line 10 "This is line #10")
  111.   <
  112.   Inline script usage: >
  113.       function! <SID>SetFirstLine()
  114.           :mz << EOF
  115.           (display "!!!")
  116.           (vim-set-buff-line 1 "This is line #1")
  117.           (vim-beep)
  118. !         EOF
  119.       endfunction
  120.   
  121.       nmap <F9> :call <SID>SetFirstLine() <CR>
  122. --- 83,102 ----
  123.   2. Examples                        *mzscheme-examples*
  124.   >
  125.       :mzscheme (display "Hello")
  126. +     :mz (display (string-append "Using MzScheme version " (version)))
  127. +     :mzscheme (require (prefix vim- vimext)) ; for MzScheme < 4.x
  128. +     :mzscheme (require (prefix-in vim- 'vimext)) ; MzScheme 4.x
  129.       :mzscheme (vim-set-buff-line 10 "This is line #10")
  130.   <
  131.   Inline script usage: >
  132.       function! <SID>SetFirstLine()
  133.           :mz << EOF
  134.           (display "!!!")
  135. +         (require (prefix vim- vimext))
  136. +         ; for newer versions (require (prefix-in vim- 'vimext))
  137.           (vim-set-buff-line 1 "This is line #1")
  138.           (vim-beep)
  139. !     EOF
  140.       endfunction
  141.   
  142.       nmap <F9> :call <SID>SetFirstLine() <CR>
  143. ***************
  144. *** 137,153 ****
  145.   File execution: >
  146.       :mzfile supascript.scm
  147.   <
  148. ! Accessing the current buffer namespace from an MzScheme program running in
  149. ! another buffer within |:mzfile|-executed script : >
  150. !     ; Move to the window below
  151. !     (vim-command "wincmd j")
  152. !     ; execute in the context of buffer, to which window belongs
  153. !     ; assume that buffer has 'textstring' defined
  154. !     (parameterize ((current-namespace
  155. !             (vim-get-buff-namespace (vim-curr-buff))))
  156. !      (eval '(vim-set-buff-line 1 textstring)))
  157. ! <
  158.   
  159.   ==============================================================================
  160.   3. Threads                        *mzscheme-threads*
  161.   
  162. --- 104,136 ----
  163.   File execution: >
  164.       :mzfile supascript.scm
  165.   <
  166. ! Vim exception handling: >
  167. !     :mz << EOF
  168. !     (require (prefix vim- vimext))
  169. !     ; for newer versions (require (prefix-in vim- 'vimext))
  170. !     (with-handlers
  171. !       ([exn:vim? (lambda (e) (display (exn-message e)))])
  172. !       (vim-eval "nonsense-string"))
  173. !     EOF
  174. ! <
  175. ! Auto-instantiation of vimext module (can be placed in your |vimrc|): >
  176. !     function! MzRequire()
  177. !     :redir => l:mzversion
  178. !     :mz (version)
  179. !     :redir END
  180. !     if strpart(l:mzversion, 1, 1) < "4"
  181. !         " MzScheme versions < 4.x:
  182. !         :mz (require (prefix vim- vimext))
  183. !     else
  184. !         " newer versions:
  185. !         :mz (require (prefix-in vim- 'vimext))
  186. !     endif
  187. !     endfunction
  188.   
  189. +     if has("mzscheme")
  190. +     silent call MzRequire()
  191. +     endif
  192. + <
  193.   ==============================================================================
  194.   3. Threads                        *mzscheme-threads*
  195.   
  196. ***************
  197. *** 168,178 ****
  198.   Common
  199.   ------
  200.       (command {command-string})        Perform the vim ":Ex" style command.
  201. !     (eval {expr-string})        Evaluate the vim expression to a string.
  202. !                     A |List| is turned into a string by
  203. !                     joining the items and inserting line
  204. !                     breaks.
  205. !                     NOTE clashes with MzScheme eval
  206.       (range-start)            Start/End of the range passed with
  207.       (range-end)                the Scheme command.
  208.       (beep)                beep
  209. --- 151,161 ----
  210.   Common
  211.   ------
  212.       (command {command-string})        Perform the vim ":Ex" style command.
  213. !     (eval {expr-string})        Evaluate the vim expression into
  214. !                     respective MzScheme object: |Lists| are
  215. !                     represented as Scheme lists,
  216. !                     |Dictionaries| as hash tables.
  217. !                     NOTE the name clashes with MzScheme eval
  218.       (range-start)            Start/End of the range passed with
  219.       (range-end)                the Scheme command.
  220.       (beep)                beep
  221. ***************
  222. *** 186,192 ****
  223.                       be set. The symbol 'global can be passed
  224.                       as {buffer-or-window}. Then |:setglobal|
  225.                       will be used.
  226. -     global-namespace            The MzScheme main namespace.
  227.   
  228.   Buffers                             *mzscheme-buffer*
  229.   -------
  230. --- 169,174 ----
  231. ***************
  232. *** 228,234 ****
  233.                       if there is no such buffer.
  234.       (get-buff-by-num {buffernum})   Get a buffer by its number (return #f if
  235.                       there is no buffer with this number).
  236. -     (get-buff-namespace [buffer])   Get buffer namespace.
  237.   
  238.   Windows                                *mzscheme-window*
  239.   ------
  240. --- 210,215 ----
  241. ***************
  242. *** 250,256 ****
  243.       (set-cursor (line . col) [window])  Set cursor position.
  244.   
  245.   ==============================================================================
  246. ! 5. Dynamic loading                    *mzscheme-dynamic*
  247.   
  248.   On MS-Windows the MzScheme libraries can be loaded dynamically. The |:version|
  249.   output then includes |+mzscheme/dyn|.
  250. --- 231,237 ----
  251.       (set-cursor (line . col) [window])  Set cursor position.
  252.   
  253.   ==============================================================================
  254. ! 5. Dynamic loading                    *mzscheme-dynamic* *E812*
  255.   
  256.   On MS-Windows the MzScheme libraries can be loaded dynamically. The |:version|
  257.   output then includes |+mzscheme/dyn|.
  258. *** ../vim-7.2.190/src/Makefile    2009-05-26 18:12:19.000000000 +0200
  259. --- src/Makefile    2009-05-26 22:54:48.000000000 +0200
  260. ***************
  261. *** 536,542 ****
  262.   # Use this with GCC to check for mistakes, unused arguments, etc.
  263.   #CFLAGS = -g -Wall -Wextra -Wmissing-prototypes -Wunreachable-code
  264.   #PYTHON_CFLAGS_EXTRA = -Wno-missing-field-initializers
  265. ! #MZSCHEME_CFLAGS_EXTRA = -Wno-unreachable-code
  266.   
  267.   # EFENCE - Electric-Fence malloc debugging: catches memory accesses beyond
  268.   # allocated memory (and makes every malloc()/free() very slow).
  269. --- 536,542 ----
  270.   # Use this with GCC to check for mistakes, unused arguments, etc.
  271.   #CFLAGS = -g -Wall -Wextra -Wmissing-prototypes -Wunreachable-code
  272.   #PYTHON_CFLAGS_EXTRA = -Wno-missing-field-initializers
  273. ! #MZSCHEME_CFLAGS_EXTRA = -Wno-unreachable-code -Wno-unused-parameter
  274.   
  275.   # EFENCE - Electric-Fence malloc debugging: catches memory accesses beyond
  276.   # allocated memory (and makes every malloc()/free() very slow).
  277. ***************
  278. *** 2200,2205 ****
  279. --- 2200,2206 ----
  280.       -rm -f $(TOOLS) auto/osdef.h auto/pathdef.c auto/if_perl.c
  281.       -rm -f conftest* *~ auto/link.sed
  282.       -rm -rf $(APPDIR)
  283. +     -rm -rf mzscheme_base.c
  284.       if test -d $(PODIR); then \
  285.           cd $(PODIR); $(MAKE) prefix=$(DESTDIR)$(prefix) clean; \
  286.       fi
  287. ***************
  288. *** 2433,2440 ****
  289.   objects/if_xcmdsrv.o: if_xcmdsrv.c
  290.       $(CCC) -o $@ if_xcmdsrv.c
  291.   
  292. ! objects/if_mzsch.o: if_mzsch.c
  293.       $(CCC) -o $@ $(MZSCHEME_CFLAGS_EXTRA) if_mzsch.c
  294.   
  295.   objects/if_perl.o: auto/if_perl.c
  296.       $(CCC) -o $@ auto/if_perl.c
  297. --- 2434,2444 ----
  298.   objects/if_xcmdsrv.o: if_xcmdsrv.c
  299.       $(CCC) -o $@ if_xcmdsrv.c
  300.   
  301. ! objects/if_mzsch.o: if_mzsch.c $(MZSCHEME_EXTRA)
  302.       $(CCC) -o $@ $(MZSCHEME_CFLAGS_EXTRA) if_mzsch.c
  303. +  
  304. + mzscheme_base.c:
  305. +     $(MZSCHEME_MZC) --c-mods mzscheme_base.c ++lib scheme/base
  306.   
  307.   objects/if_perl.o: auto/if_perl.c
  308.       $(CCC) -o $@ auto/if_perl.c
  309. *** ../vim-7.2.190/src/Make_ming.mak    2007-08-12 15:24:29.000000000 +0200
  310. --- src/Make_ming.mak    2009-05-26 18:54:15.000000000 +0200
  311. ***************
  312. *** 115,122 ****
  313. --- 115,135 ----
  314.   MZSCHEME_VER=205_000
  315.   endif
  316.   
  317. + ifndef MZSCHEME_PRECISE_GC
  318. + MZSCHEME_PRECISE_GC=no
  319. + endif
  320. + # for version 4.x we need to generate byte-code for Scheme base
  321. + ifndef MZSCHEME_GENERATE_BASE
  322. + MZSCHEME_GENERATE_BASE=no
  323. + endif
  324.   ifeq (no,$(DYNAMIC_MZSCHEME))
  325. + ifeq (yes,$(MZSCHEME_PRECISE_GC))
  326. + MZSCHEME_LIB=-lmzsch$(MZSCHEME_VER)
  327. + else
  328.   MZSCHEME_LIB = -lmzsch$(MZSCHEME_VER) -lmzgc$(MZSCHEME_VER)
  329. + endif
  330.   # the modern MinGW can dynamically link to dlls directly.
  331.   # point MZSCHEME_DLLS to where you put libmzschXXXXXXX.dll and libgcXXXXXXX.dll
  332.   ifndef MZSCHEME_DLLS
  333. ***************
  334. *** 410,415 ****
  335. --- 423,435 ----
  336.   ifdef MZSCHEME
  337.   OBJ += $(OUTDIR)/if_mzsch.o
  338.   MZSCHEME_INCL = if_mzsch.h
  339. + ifeq (yes,$(MZSCHEME_GENERATE_BASE))
  340. + CFLAGS += -DINCLUDE_MZSCHEME_BASE
  341. + MZ_EXTRA_DEP += mzscheme_base.c
  342. + endif
  343. + ifeq (yes,$(MZSCHEME_PRECISE_GC))
  344. + CFLAGS += -DMZ_PRECISE_GC
  345. + endif
  346.   endif
  347.   ifdef PYTHON
  348.   OBJ += $(OUTDIR)/if_python.o
  349. ***************
  350. *** 588,593 ****
  351. --- 608,619 ----
  352.   $(OUTDIR)/netbeans.o:    netbeans.c $(INCL) $(NBDEBUG_INCL) $(NBDEBUG_SRC)
  353.       $(CC) -c $(CFLAGS) netbeans.c -o $(OUTDIR)/netbeans.o
  354.   
  355. + $(OUTDIR)/if_mzsch.o:    if_mzsch.c $(INCL) if_mzsch.h $(MZ_EXTRA_DEP)
  356. +     $(CC) -c $(CFLAGS) if_mzsch.c -o $(OUTDIR)/if_mzsch.o
  357. + mzscheme_base.c:
  358. +     $(MZSCHEME)/mzc --c-mods mzscheme_base.c ++lib scheme/base
  359.   pathdef.c: $(INCL)
  360.   ifneq (sh.exe, $(SHELL))
  361.       @echo creating pathdef.c
  362. *** ../vim-7.2.190/src/Make_mvc.mak    2009-02-04 18:34:54.000000000 +0100
  363. --- src/Make_mvc.mak    2009-05-26 18:54:51.000000000 +0200
  364. ***************
  365. *** 34,39 ****
  366. --- 34,40 ----
  367.   #      MZSCHEME=[Path to MzScheme directory]
  368.   #      DYNAMIC_MZSCHEME=yes (to load the MzScheme DLLs dynamically)
  369.   #      MZSCHEME_VER=[version, 205_000, ...]
  370. + #      MZSCHEME_DEBUG=no
  371.   #
  372.   #    Perl interface:
  373.   #      PERL=[Path to Perl directory]
  374. ***************
  375. *** 621,635 ****
  376. --- 622,658 ----
  377.   MZSCHEME_VER = 205_000
  378.   !endif
  379.   CFLAGS = $(CFLAGS) -DFEAT_MZSCHEME -I $(MZSCHEME)\include
  380. + !if EXIST("$(MZSCHEME)\collects\scheme\base.ss")
  381. + # for MzScheme 4.x we need to include byte code for basic Scheme stuff
  382. + MZSCHEME_EXTRA_DEP = mzscheme_base.c
  383. + CFLAGS = $(CFLAGS) -DINCLUDE_MZSCHEME_BASE
  384. + !endif
  385. + !if EXIST("$(MZSCHEME)\lib\msvc\libmzsch$(MZSCHEME_VER).lib") \
  386. +     && !EXIST("$(MZSCHEME)\lib\msvc\libmzgc$(MZSCHEME_VER).lib")
  387. + !message Building with Precise GC
  388. + MZSCHEME_PRECISE_GC = yes
  389. + CFLAGS = $(CFLAGS) -DMZ_PRECISE_GC
  390. + !endif
  391.   !if "$(DYNAMIC_MZSCHEME)" == "yes"
  392. + !if "$(MZSCHEME_PRECISE_GC)" == "yes"
  393. + !error MzScheme with Precise GC cannot be loaded dynamically
  394. + !endif
  395.   !message MzScheme DLLs will be loaded dynamically
  396.   CFLAGS = $(CFLAGS) -DDYNAMIC_MZSCHEME \
  397.           -DDYNAMIC_MZSCH_DLL=\"libmzsch$(MZSCHEME_VER).dll\" \
  398.           -DDYNAMIC_MZGC_DLL=\"libmzgc$(MZSCHEME_VER).dll\"
  399.   !else
  400. + !if "$(MZSCHEME_DEBUG)" == "yes"
  401. + CFLAGS = $(CFLAGS) -DMZSCHEME_FORCE_GC
  402. + !endif
  403. + !if "$(MZSCHEME_PRECISE_GC)" == "yes"
  404. + # Precise GC does not use separate dll
  405. + MZSCHEME_LIB = $(MZSCHEME)\lib\msvc\libmzsch$(MZSCHEME_VER).lib
  406. + !else
  407.   MZSCHEME_LIB = $(MZSCHEME)\lib\msvc\libmzgc$(MZSCHEME_VER).lib \
  408.           $(MZSCHEME)\lib\msvc\libmzsch$(MZSCHEME_VER).lib
  409.   !endif
  410. + !endif
  411.   MZSCHEME_OBJ = $(OUTDIR)\if_mzsch.obj
  412.   !endif
  413.   
  414. ***************
  415. *** 930,938 ****
  416.   $(OUTDIR)/if_perlsfio.obj: $(OUTDIR) if_perlsfio.c  $(INCL)
  417.       $(CC) $(CFLAGS) $(PERL_INC) if_perlsfio.c
  418.   
  419. ! $(OUTDIR)/if_mzsch.obj: $(OUTDIR) if_mzsch.c  $(INCL)
  420.       $(CC) $(CFLAGS) if_mzsch.c \
  421.           -DMZSCHEME_COLLECTS=\"$(MZSCHEME:\=\\)\\collects\"
  422.   
  423.   $(OUTDIR)/if_python.obj: $(OUTDIR) if_python.c  $(INCL)
  424.       $(CC) $(CFLAGS) $(PYTHON_INC) if_python.c
  425. --- 953,963 ----
  426.   $(OUTDIR)/if_perlsfio.obj: $(OUTDIR) if_perlsfio.c  $(INCL)
  427.       $(CC) $(CFLAGS) $(PERL_INC) if_perlsfio.c
  428.   
  429. ! $(OUTDIR)/if_mzsch.obj: $(OUTDIR) if_mzsch.c  $(INCL) $(MZSCHEME_EXTRA_DEP)
  430.       $(CC) $(CFLAGS) if_mzsch.c \
  431.           -DMZSCHEME_COLLECTS=\"$(MZSCHEME:\=\\)\\collects\"
  432. + mzscheme_base.c:
  433. +     $(MZSCHEME)\mzc --c-mods mzscheme_base.c ++lib scheme/base
  434.   
  435.   $(OUTDIR)/if_python.obj: $(OUTDIR) if_python.c  $(INCL)
  436.       $(CC) $(CFLAGS) $(PYTHON_INC) if_python.c
  437. *** ../vim-7.2.190/src/auto/configure    2009-05-21 23:25:38.000000000 +0200
  438. --- src/auto/configure    2009-05-26 19:12:29.000000000 +0200
  439. ***************
  440. *** 701,706 ****
  441. --- 701,708 ----
  442.   shrpenv
  443.   vi_cv_perllib
  444.   vi_cv_path_perl
  445. + MZSCHEME_MZC
  446. + MZSCHEME_EXTRA
  447.   MZSCHEME_CFLAGS
  448.   MZSCHEME_LIBS
  449.   MZSCHEME_PRO
  450. ***************
  451. *** 4641,4648 ****
  452.   $as_echo "\"$PLTHOME\"" >&6; }
  453.       vi_cv_path_mzscheme_pfx="$PLTHOME"
  454.       else
  455. !     { $as_echo "$as_me:$LINENO: result: \"not set\"" >&5
  456. ! $as_echo "\"not set\"" >&6; }
  457.           # Extract the first word of "mzscheme", so it can be a program name with args.
  458.   set dummy mzscheme; ac_word=$2
  459.   { $as_echo "$as_me:$LINENO: checking for $ac_word" >&5
  460. --- 4643,4650 ----
  461.   $as_echo "\"$PLTHOME\"" >&6; }
  462.       vi_cv_path_mzscheme_pfx="$PLTHOME"
  463.       else
  464. !     { $as_echo "$as_me:$LINENO: result: not set" >&5
  465. ! $as_echo "not set" >&6; }
  466.           # Extract the first word of "mzscheme", so it can be a program name with args.
  467.   set dummy mzscheme; ac_word=$2
  468.   { $as_echo "$as_me:$LINENO: checking for $ac_word" >&5
  469. ***************
  470. *** 4697,4712 ****
  471.   if test "${vi_cv_path_mzscheme_pfx+set}" = set; then
  472.     $as_echo_n "(cached) " >&6
  473.   else
  474. !    vi_cv_path_mzscheme_pfx=`
  475. !         ${vi_cv_path_mzscheme} -evm \
  476. !         "(display (simplify-path        \
  477.              (build-path (call-with-values    \
  478.           (lambda () (split-path (find-system-path (quote exec-file)))) \
  479. !         (lambda (base name must-be-dir?) base)) (quote up))))"`
  480.   fi
  481.   { $as_echo "$as_me:$LINENO: result: $vi_cv_path_mzscheme_pfx" >&5
  482.   $as_echo "$vi_cv_path_mzscheme_pfx" >&6; }
  483. !                 vi_cv_path_mzscheme_pfx=`echo "$vi_cv_path_mzscheme_pfx" | sed 's+/$++'`
  484.       fi
  485.       fi
  486.     fi
  487. --- 4699,4714 ----
  488.   if test "${vi_cv_path_mzscheme_pfx+set}" = set; then
  489.     $as_echo_n "(cached) " >&6
  490.   else
  491. !                   echo "(display (simplify-path        \
  492.              (build-path (call-with-values    \
  493.           (lambda () (split-path (find-system-path (quote exec-file)))) \
  494. !         (lambda (base name must-be-dir?) base)) (quote up))))" > mzdirs.scm
  495. !                  vi_cv_path_mzscheme_pfx=`${vi_cv_path_mzscheme} -r mzdirs.scm | \
  496. !         sed -e 's+/$++'`
  497.   fi
  498.   { $as_echo "$as_me:$LINENO: result: $vi_cv_path_mzscheme_pfx" >&5
  499.   $as_echo "$vi_cv_path_mzscheme_pfx" >&6; }
  500. !         rm -f mzdirs.scm
  501.       fi
  502.       fi
  503.     fi
  504. ***************
  505. *** 4716,4736 ****
  506.       { $as_echo "$as_me:$LINENO: checking if scheme.h can be found in $vi_cv_path_mzscheme_pfx/include" >&5
  507.   $as_echo_n "checking if scheme.h can be found in $vi_cv_path_mzscheme_pfx/include... " >&6; }
  508.       if test -f $vi_cv_path_mzscheme_pfx/include/scheme.h; then
  509. !       { $as_echo "$as_me:$LINENO: result: \"yes\"" >&5
  510. ! $as_echo "\"yes\"" >&6; }
  511.       else
  512. !       { $as_echo "$as_me:$LINENO: result: \"no\"" >&5
  513. ! $as_echo "\"no\"" >&6; }
  514. !       { $as_echo "$as_me:$LINENO: checking if scheme.h can be found in $vi_cv_path_mzscheme_pfx/plt/include" >&5
  515. ! $as_echo_n "checking if scheme.h can be found in $vi_cv_path_mzscheme_pfx/plt/include... " >&6; }
  516.         if test -f $vi_cv_path_mzscheme_pfx/include/plt/scheme.h; then
  517. !     { $as_echo "$as_me:$LINENO: result: \"yes\"" >&5
  518. ! $as_echo "\"yes\"" >&6; }
  519. !     SCHEME_INC=/plt
  520.         else
  521. !     { $as_echo "$as_me:$LINENO: result: \"no\"" >&5
  522. ! $as_echo "\"no\"" >&6; }
  523. !     vi_cv_path_mzscheme_pfx=
  524.         fi
  525.       fi
  526.     fi
  527. --- 4718,4749 ----
  528.       { $as_echo "$as_me:$LINENO: checking if scheme.h can be found in $vi_cv_path_mzscheme_pfx/include" >&5
  529.   $as_echo_n "checking if scheme.h can be found in $vi_cv_path_mzscheme_pfx/include... " >&6; }
  530.       if test -f $vi_cv_path_mzscheme_pfx/include/scheme.h; then
  531. !       SCHEME_INC=${vi_cv_path_mzscheme_pfx}/include
  532. !       { $as_echo "$as_me:$LINENO: result: yes" >&5
  533. ! $as_echo "yes" >&6; }
  534.       else
  535. !       { $as_echo "$as_me:$LINENO: result: no" >&5
  536. ! $as_echo "no" >&6; }
  537. !       { $as_echo "$as_me:$LINENO: checking if scheme.h can be found in $vi_cv_path_mzscheme_pfx/include/plt" >&5
  538. ! $as_echo_n "checking if scheme.h can be found in $vi_cv_path_mzscheme_pfx/include/plt... " >&6; }
  539.         if test -f $vi_cv_path_mzscheme_pfx/include/plt/scheme.h; then
  540. !     { $as_echo "$as_me:$LINENO: result: yes" >&5
  541. ! $as_echo "yes" >&6; }
  542. !     SCHEME_INC=${vi_cv_path_mzscheme_pfx}/include/plt
  543.         else
  544. !     { $as_echo "$as_me:$LINENO: result: no" >&5
  545. ! $as_echo "no" >&6; }
  546. !     { $as_echo "$as_me:$LINENO: checking if scheme.h can be found in /usr/include/plt/" >&5
  547. ! $as_echo_n "checking if scheme.h can be found in /usr/include/plt/... " >&6; }
  548. !     if test -f /usr/include/plt/scheme.h; then
  549. !       { $as_echo "$as_me:$LINENO: result: yes" >&5
  550. ! $as_echo "yes" >&6; }
  551. !       SCHEME_INC=/usr/include/plt
  552. !     else
  553. !       { $as_echo "$as_me:$LINENO: result: no" >&5
  554. ! $as_echo "no" >&6; }
  555. !       vi_cv_path_mzscheme_pfx=
  556. !     fi
  557.         fi
  558.       fi
  559.     fi
  560. ***************
  561. *** 4738,4758 ****
  562.     if test "X$vi_cv_path_mzscheme_pfx" != "X"; then
  563.       if test "x$MACOSX" = "xyes"; then
  564.         MZSCHEME_LIBS="-framework PLT_MzScheme"
  565.       elif test -f "${vi_cv_path_mzscheme_pfx}/lib/libmzgc.a"; then
  566.         MZSCHEME_LIBS="${vi_cv_path_mzscheme_pfx}/lib/libmzscheme.a ${vi_cv_path_mzscheme_pfx}/lib/libmzgc.a"
  567.       else
  568. !       MZSCHEME_LIBS="-L${vi_cv_path_mzscheme_pfx}/lib -lmzscheme -lmzgc"
  569.         if test "$GCC" = yes; then
  570. !             MZSCHEME_LIBS="$MZSCHEME_LIBS -Wl,-rpath -Wl,${vi_cv_path_mzscheme_pfx}/lib"
  571.         elif test "`(uname) 2>/dev/null`" = SunOS &&
  572.                      uname -r | grep '^5' >/dev/null; then
  573. !     MZSCHEME_LIBS="$MZSCHEME_LIBS -R ${vi_cv_path_mzscheme_pfx}/lib"
  574.         fi
  575.       fi
  576.       if test -d $vi_cv_path_mzscheme_pfx/lib/plt/collects; then
  577.         SCHEME_COLLECTS=lib/plt/
  578.       fi
  579. !     MZSCHEME_CFLAGS="-I${vi_cv_path_mzscheme_pfx}/include${SCHEME_INC}   \
  580.         -DMZSCHEME_COLLECTS='\"${vi_cv_path_mzscheme_pfx}/${SCHEME_COLLECTS}collects\"'"
  581.       MZSCHEME_SRC="if_mzsch.c"
  582.       MZSCHEME_OBJ="objects/if_mzsch.o"
  583. --- 4751,4784 ----
  584.     if test "X$vi_cv_path_mzscheme_pfx" != "X"; then
  585.       if test "x$MACOSX" = "xyes"; then
  586.         MZSCHEME_LIBS="-framework PLT_MzScheme"
  587. +     elif test -f "${vi_cv_path_mzscheme_pfx}/lib/libmzscheme3m.a"; then
  588. +       MZSCHEME_LIBS="${vi_cv_path_mzscheme_pfx}/lib/libmzscheme3m.a"
  589. +       MZSCHEME_CFLAGS="-DMZ_PRECISE_GC"
  590.       elif test -f "${vi_cv_path_mzscheme_pfx}/lib/libmzgc.a"; then
  591.         MZSCHEME_LIBS="${vi_cv_path_mzscheme_pfx}/lib/libmzscheme.a ${vi_cv_path_mzscheme_pfx}/lib/libmzgc.a"
  592.       else
  593. !             if test -f "${vi_cv_path_mzscheme_pfx}/lib/libmzscheme3m.so"; then
  594. !         MZSCHEME_LIBS="-L${vi_cv_path_mzscheme_pfx}/lib -lmzscheme3m"
  595. !     MZSCHEME_CFLAGS="-DMZ_PRECISE_GC"
  596. !       else
  597. !         MZSCHEME_LIBS="-L${vi_cv_path_mzscheme_pfx}/lib -lmzscheme -lmzgc"
  598. !       fi
  599.         if test "$GCC" = yes; then
  600. !             MZSCHEME_LIBS="${MZSCHEME_LIBS} -Wl,-rpath -Wl,${vi_cv_path_mzscheme_pfx}/lib"
  601.         elif test "`(uname) 2>/dev/null`" = SunOS &&
  602.                      uname -r | grep '^5' >/dev/null; then
  603. !     MZSCHEME_LIBS="${MZSCHEME_LIBS} -R ${vi_cv_path_mzscheme_pfx}/lib"
  604.         fi
  605.       fi
  606.       if test -d $vi_cv_path_mzscheme_pfx/lib/plt/collects; then
  607.         SCHEME_COLLECTS=lib/plt/
  608.       fi
  609. !     if test -f "${vi_cv_path_mzscheme_pfx}/${SCHEME_COLLECTS}collects/scheme/base.ss" ; then
  610. !             MZSCHEME_EXTRA="mzscheme_base.c"
  611. !       MZSCHEME_CFLAGS="${MZSCHEME_CFLAGS} -DINCLUDE_MZSCHEME_BASE"
  612. !       MZSCHEME_MZC="${vi_cv_path_mzscheme_pfx}/bin/mzc"
  613. !     fi
  614. !     MZSCHEME_CFLAGS="${MZSCHEME_CFLAGS} -I${SCHEME_INC} \
  615.         -DMZSCHEME_COLLECTS='\"${vi_cv_path_mzscheme_pfx}/${SCHEME_COLLECTS}collects\"'"
  616.       MZSCHEME_SRC="if_mzsch.c"
  617.       MZSCHEME_OBJ="objects/if_mzsch.o"
  618. ***************
  619. *** 4767,4772 ****
  620. --- 4793,4800 ----
  621.   
  622.   
  623.   
  624.   fi
  625.   
  626.   
  627. *** ../vim-7.2.190/src/configure.in    2009-05-21 23:25:38.000000000 +0200
  628. --- src/configure.in    2009-05-26 18:57:35.000000000 +0200
  629. ***************
  630. *** 414,420 ****
  631.       AC_MSG_RESULT("$PLTHOME")
  632.       vi_cv_path_mzscheme_pfx="$PLTHOME"
  633.       else
  634. !     AC_MSG_RESULT("not set")
  635.       dnl -- try to find MzScheme executable
  636.       AC_PATH_PROG(vi_cv_path_mzscheme, mzscheme)
  637.   
  638. --- 414,420 ----
  639.       AC_MSG_RESULT("$PLTHOME")
  640.       vi_cv_path_mzscheme_pfx="$PLTHOME"
  641.       else
  642. !     AC_MSG_RESULT(not set)
  643.       dnl -- try to find MzScheme executable
  644.       AC_PATH_PROG(vi_cv_path_mzscheme, mzscheme)
  645.   
  646. ***************
  647. *** 430,443 ****
  648.       if test "X$vi_cv_path_mzscheme" != "X"; then
  649.           dnl -- find where MzScheme thinks it was installed
  650.           AC_CACHE_CHECK(MzScheme install prefix,vi_cv_path_mzscheme_pfx,
  651. !         [ vi_cv_path_mzscheme_pfx=`
  652. !         ${vi_cv_path_mzscheme} -evm \
  653. !         "(display (simplify-path        \
  654.              (build-path (call-with-values    \
  655.           (lambda () (split-path (find-system-path (quote exec-file)))) \
  656. !         (lambda (base name must-be-dir?) base)) (quote up))))"` ])
  657. !         dnl Remove a trailing slash.
  658. !         vi_cv_path_mzscheme_pfx=`echo "$vi_cv_path_mzscheme_pfx" | sed 's+/$++'`
  659.       fi
  660.       fi
  661.     fi
  662. --- 430,445 ----
  663.       if test "X$vi_cv_path_mzscheme" != "X"; then
  664.           dnl -- find where MzScheme thinks it was installed
  665.           AC_CACHE_CHECK(MzScheme install prefix,vi_cv_path_mzscheme_pfx,
  666. !         dnl different versions of MzScheme differ in command line processing
  667. !         dnl use universal approach
  668. !         echo "(display (simplify-path        \
  669.              (build-path (call-with-values    \
  670.           (lambda () (split-path (find-system-path (quote exec-file)))) \
  671. !         (lambda (base name must-be-dir?) base)) (quote up))))" > mzdirs.scm
  672. !         dnl Remove a trailing slash
  673. !         [ vi_cv_path_mzscheme_pfx=`${vi_cv_path_mzscheme} -r mzdirs.scm | \
  674. !         sed -e 's+/$++'` ])
  675. !         rm -f mzdirs.scm
  676.       fi
  677.       fi
  678.     fi
  679. ***************
  680. *** 446,461 ****
  681.     if test "X$vi_cv_path_mzscheme_pfx" != "X"; then
  682.       AC_MSG_CHECKING(if scheme.h can be found in $vi_cv_path_mzscheme_pfx/include)
  683.       if test -f $vi_cv_path_mzscheme_pfx/include/scheme.h; then
  684. !       AC_MSG_RESULT("yes")
  685.       else
  686. !       AC_MSG_RESULT("no")
  687. !       AC_MSG_CHECKING(if scheme.h can be found in $vi_cv_path_mzscheme_pfx/plt/include)
  688.         if test -f $vi_cv_path_mzscheme_pfx/include/plt/scheme.h; then
  689. !     AC_MSG_RESULT("yes")
  690. !     SCHEME_INC=/plt
  691.         else
  692. !     AC_MSG_RESULT("no")
  693. !     vi_cv_path_mzscheme_pfx=
  694.         fi
  695.       fi
  696.     fi
  697. --- 448,471 ----
  698.     if test "X$vi_cv_path_mzscheme_pfx" != "X"; then
  699.       AC_MSG_CHECKING(if scheme.h can be found in $vi_cv_path_mzscheme_pfx/include)
  700.       if test -f $vi_cv_path_mzscheme_pfx/include/scheme.h; then
  701. !       SCHEME_INC=${vi_cv_path_mzscheme_pfx}/include
  702. !       AC_MSG_RESULT(yes)
  703.       else
  704. !       AC_MSG_RESULT(no)
  705. !       AC_MSG_CHECKING(if scheme.h can be found in $vi_cv_path_mzscheme_pfx/include/plt)
  706.         if test -f $vi_cv_path_mzscheme_pfx/include/plt/scheme.h; then
  707. !     AC_MSG_RESULT(yes)
  708. !     SCHEME_INC=${vi_cv_path_mzscheme_pfx}/include/plt
  709.         else
  710. !     AC_MSG_RESULT(no)
  711. !     AC_MSG_CHECKING(if scheme.h can be found in /usr/include/plt/)
  712. !     if test -f /usr/include/plt/scheme.h; then
  713. !       AC_MSG_RESULT(yes)
  714. !       SCHEME_INC=/usr/include/plt
  715. !     else
  716. !       AC_MSG_RESULT(no)
  717. !       vi_cv_path_mzscheme_pfx=
  718. !     fi
  719.         fi
  720.       fi
  721.     fi
  722. ***************
  723. *** 463,485 ****
  724.     if test "X$vi_cv_path_mzscheme_pfx" != "X"; then
  725.       if test "x$MACOSX" = "xyes"; then
  726.         MZSCHEME_LIBS="-framework PLT_MzScheme"
  727.       elif test -f "${vi_cv_path_mzscheme_pfx}/lib/libmzgc.a"; then
  728.         MZSCHEME_LIBS="${vi_cv_path_mzscheme_pfx}/lib/libmzscheme.a ${vi_cv_path_mzscheme_pfx}/lib/libmzgc.a"
  729.       else
  730. !       MZSCHEME_LIBS="-L${vi_cv_path_mzscheme_pfx}/lib -lmzscheme -lmzgc"
  731.         if test "$GCC" = yes; then
  732.       dnl Make Vim remember the path to the library.  For when it's not in
  733.       dnl $LD_LIBRARY_PATH.
  734. !     MZSCHEME_LIBS="$MZSCHEME_LIBS -Wl,-rpath -Wl,${vi_cv_path_mzscheme_pfx}/lib"
  735.         elif test "`(uname) 2>/dev/null`" = SunOS &&
  736.                      uname -r | grep '^5' >/dev/null; then
  737. !     MZSCHEME_LIBS="$MZSCHEME_LIBS -R ${vi_cv_path_mzscheme_pfx}/lib"
  738.         fi
  739.       fi
  740.       if test -d $vi_cv_path_mzscheme_pfx/lib/plt/collects; then
  741.         SCHEME_COLLECTS=lib/plt/
  742.       fi
  743. !     MZSCHEME_CFLAGS="-I${vi_cv_path_mzscheme_pfx}/include${SCHEME_INC}   \
  744.         -DMZSCHEME_COLLECTS='\"${vi_cv_path_mzscheme_pfx}/${SCHEME_COLLECTS}collects\"'"
  745.       MZSCHEME_SRC="if_mzsch.c"
  746.       MZSCHEME_OBJ="objects/if_mzsch.o"
  747. --- 473,510 ----
  748.     if test "X$vi_cv_path_mzscheme_pfx" != "X"; then
  749.       if test "x$MACOSX" = "xyes"; then
  750.         MZSCHEME_LIBS="-framework PLT_MzScheme"
  751. +     elif test -f "${vi_cv_path_mzscheme_pfx}/lib/libmzscheme3m.a"; then
  752. +       MZSCHEME_LIBS="${vi_cv_path_mzscheme_pfx}/lib/libmzscheme3m.a"
  753. +       MZSCHEME_CFLAGS="-DMZ_PRECISE_GC"
  754.       elif test -f "${vi_cv_path_mzscheme_pfx}/lib/libmzgc.a"; then
  755.         MZSCHEME_LIBS="${vi_cv_path_mzscheme_pfx}/lib/libmzscheme.a ${vi_cv_path_mzscheme_pfx}/lib/libmzgc.a"
  756.       else
  757. !       dnl Using shared objects
  758. !       if test -f "${vi_cv_path_mzscheme_pfx}/lib/libmzscheme3m.so"; then
  759. !         MZSCHEME_LIBS="-L${vi_cv_path_mzscheme_pfx}/lib -lmzscheme3m"
  760. !     MZSCHEME_CFLAGS="-DMZ_PRECISE_GC"
  761. !       else
  762. !         MZSCHEME_LIBS="-L${vi_cv_path_mzscheme_pfx}/lib -lmzscheme -lmzgc"
  763. !       fi
  764.         if test "$GCC" = yes; then
  765.       dnl Make Vim remember the path to the library.  For when it's not in
  766.       dnl $LD_LIBRARY_PATH.
  767. !     MZSCHEME_LIBS="${MZSCHEME_LIBS} -Wl,-rpath -Wl,${vi_cv_path_mzscheme_pfx}/lib"
  768.         elif test "`(uname) 2>/dev/null`" = SunOS &&
  769.                      uname -r | grep '^5' >/dev/null; then
  770. !     MZSCHEME_LIBS="${MZSCHEME_LIBS} -R ${vi_cv_path_mzscheme_pfx}/lib"
  771.         fi
  772.       fi
  773.       if test -d $vi_cv_path_mzscheme_pfx/lib/plt/collects; then
  774.         SCHEME_COLLECTS=lib/plt/
  775.       fi
  776. !     if test -f "${vi_cv_path_mzscheme_pfx}/${SCHEME_COLLECTS}collects/scheme/base.ss" ; then
  777. !       dnl need to generate bytecode for MzScheme base
  778. !       MZSCHEME_EXTRA="mzscheme_base.c"
  779. !       MZSCHEME_CFLAGS="${MZSCHEME_CFLAGS} -DINCLUDE_MZSCHEME_BASE"
  780. !       MZSCHEME_MZC="${vi_cv_path_mzscheme_pfx}/bin/mzc"
  781. !     fi
  782. !     MZSCHEME_CFLAGS="${MZSCHEME_CFLAGS} -I${SCHEME_INC} \
  783.         -DMZSCHEME_COLLECTS='\"${vi_cv_path_mzscheme_pfx}/${SCHEME_COLLECTS}collects\"'"
  784.       MZSCHEME_SRC="if_mzsch.c"
  785.       MZSCHEME_OBJ="objects/if_mzsch.o"
  786. ***************
  787. *** 491,496 ****
  788. --- 516,523 ----
  789.     AC_SUBST(MZSCHEME_PRO)
  790.     AC_SUBST(MZSCHEME_LIBS)
  791.     AC_SUBST(MZSCHEME_CFLAGS)
  792. +   AC_SUBST(MZSCHEME_EXTRA)
  793. +   AC_SUBST(MZSCHEME_MZC)
  794.   fi
  795.   
  796.   
  797. *** ../vim-7.2.190/src/config.mk.in    2008-06-25 00:49:03.000000000 +0200
  798. --- src/config.mk.in    2009-05-26 18:57:49.000000000 +0200
  799. ***************
  800. *** 41,46 ****
  801. --- 41,48 ----
  802.   MZSCHEME_OBJ    = @MZSCHEME_OBJ@
  803.   MZSCHEME_CFLAGS    = @MZSCHEME_CFLAGS@
  804.   MZSCHEME_PRO    = @MZSCHEME_PRO@
  805. + MZSCHEME_EXTRA  = @MZSCHEME_EXTRA@
  806. + MZSCHEME_MZC    = @MZSCHEME_MZC@
  807.   
  808.   PERL        = @vi_cv_path_perl@
  809.   PERLLIB        = @vi_cv_perllib@
  810. *** ../vim-7.2.190/src/eval.c    2009-05-24 13:40:17.000000000 +0200
  811. --- src/eval.c    2009-05-26 18:58:20.000000000 +0200
  812. ***************
  813. *** 5866,5872 ****
  814.       return item1 == NULL && item2 == NULL;
  815.   }
  816.   
  817. ! #if defined(FEAT_PYTHON) || defined(PROTO)
  818.   /*
  819.    * Return the dictitem that an entry in a hashtable points to.
  820.    */
  821. --- 5866,5872 ----
  822.       return item1 == NULL && item2 == NULL;
  823.   }
  824.   
  825. ! #if defined(FEAT_PYTHON) || defined(FEAT_MZSCHEME) || defined(PROTO)
  826.   /*
  827.    * Return the dictitem that an entry in a hashtable points to.
  828.    */
  829. *** ../vim-7.2.190/src/if_mzsch.c    2009-05-17 16:23:20.000000000 +0200
  830. --- src/if_mzsch.c    2009-05-26 19:24:18.000000000 +0200
  831. ***************
  832. *** 4,9 ****
  833. --- 4,11 ----
  834.    * Original work by Brent Fulgham <bfulgham@debian.org>
  835.    * (Based on lots of help from Matthew Flatt)
  836.    *
  837. +  * TODO Convert byte-strings to char strings?
  838. +  *
  839.    * This consists of six parts:
  840.    * 1. MzScheme interpreter main program
  841.    * 2. Routines that handle the external interface between MzScheme and
  842. ***************
  843. *** 18,24 ****
  844.    *    garbage collector will do it self
  845.    * 2. Requires at least NORMAL features. I can't imagine why one may want
  846.    *    to build with SMALL or TINY features but with MzScheme interface.
  847. !  * 3. I don't use K&R-style functions. Anyway, MzScheme headers are ANSI.
  848.    */
  849.   
  850.   #include "vim.h"
  851. --- 20,26 ----
  852.    *    garbage collector will do it self
  853.    * 2. Requires at least NORMAL features. I can't imagine why one may want
  854.    *    to build with SMALL or TINY features but with MzScheme interface.
  855. !  * 3. I don't use K&R-style functions. Anyways, MzScheme headers are ANSI.
  856.    */
  857.   
  858.   #include "vim.h"
  859. ***************
  860. *** 29,42 ****
  861.    * depend". */
  862.   #if defined(FEAT_MZSCHEME) || defined(PROTO)
  863.   
  864.   /* Base data structures */
  865.   #define SCHEME_VIMBUFFERP(obj)  SAME_TYPE(SCHEME_TYPE(obj), mz_buffer_type)
  866.   #define SCHEME_VIMWINDOWP(obj)  SAME_TYPE(SCHEME_TYPE(obj), mz_window_type)
  867.   
  868.   typedef struct
  869.   {
  870. !     Scheme_Type        tag;
  871. !     Scheme_Env        *env;
  872.       buf_T        *buf;
  873.   } vim_mz_buffer;
  874.   
  875. --- 31,45 ----
  876.    * depend". */
  877.   #if defined(FEAT_MZSCHEME) || defined(PROTO)
  878.   
  879. + #include <assert.h>
  880.   /* Base data structures */
  881.   #define SCHEME_VIMBUFFERP(obj)  SAME_TYPE(SCHEME_TYPE(obj), mz_buffer_type)
  882.   #define SCHEME_VIMWINDOWP(obj)  SAME_TYPE(SCHEME_TYPE(obj), mz_window_type)
  883.   
  884.   typedef struct
  885.   {
  886. !     Scheme_Object   so;
  887.       buf_T        *buf;
  888.   } vim_mz_buffer;
  889.   
  890. ***************
  891. *** 44,50 ****
  892.   
  893.   typedef struct
  894.   {
  895. !     Scheme_Type        tag;
  896.       win_T        *win;
  897.   } vim_mz_window;
  898.   
  899. --- 47,53 ----
  900.   
  901.   typedef struct
  902.   {
  903. !     Scheme_Object   so;
  904.       win_T        *win;
  905.   } vim_mz_window;
  906.   
  907. ***************
  908. *** 67,85 ****
  909.       Scheme_Object   *port;
  910.   } Port_Info;
  911.   
  912. - /* info for closed prim */
  913. - /*
  914. -  * data have different means:
  915. -  * for do_eval it is char*
  916. -  * for do_apply is Apply_Onfo*
  917. -  * for do_load is Port_Info*
  918. -  */
  919. - typedef struct
  920. - {
  921. -     void    *data;
  922. -     Scheme_Env    *env;
  923. - } Cmd_Info;
  924.   /* info for do_apply */
  925.   typedef struct
  926.   {
  927. --- 70,75 ----
  928. ***************
  929. *** 122,128 ****
  930.   static Scheme_Object *insert_buffer_line_list(void *, int, Scheme_Object **);
  931.   static Scheme_Object *get_range_start(void *, int, Scheme_Object **);
  932.   static Scheme_Object *get_range_end(void *, int, Scheme_Object **);
  933. - static Scheme_Object *get_buffer_namespace(void *, int, Scheme_Object **);
  934.   static vim_mz_buffer *get_vim_curr_buffer(void);
  935.   
  936.   /*  Window-related commands */
  937. --- 112,117 ----
  938. ***************
  939. *** 163,170 ****
  940.   static int do_mzscheme_command(exarg_T *, void *, Scheme_Closed_Prim *what);
  941.   static void startup_mzscheme(void);
  942.   static char *string_to_line(Scheme_Object *obj);
  943. - static int mzscheme_io_init(void);
  944. - static void mzscheme_interface_init(vim_mz_buffer *self);
  945.   static void do_output(char *mesg, long len);
  946.   static void do_printf(char *format, ...);
  947.   static void do_flush(void);
  948. --- 152,157 ----
  949. ***************
  950. *** 174,192 ****
  951.   static Scheme_Object *do_eval(void *, int noargc, Scheme_Object **noargv);
  952.   static Scheme_Object *do_load(void *, int noargc, Scheme_Object **noargv);
  953.   static Scheme_Object *do_apply(void *, int noargc, Scheme_Object **noargv);
  954. ! static void register_vim_exn(Scheme_Env *env);
  955.   static vim_mz_buffer *get_buffer_arg(const char *fname, int argnum,
  956.       int argc, Scheme_Object **argv);
  957.   static vim_mz_window *get_window_arg(const char *fname, int argnum,
  958.       int argc, Scheme_Object **argv);
  959. - static void add_vim_exn(Scheme_Env *env);
  960.   static int line_in_range(linenr_T, buf_T *);
  961.   static void check_line_range(linenr_T, buf_T *);
  962.   static void mz_fix_cursor(int lo, int hi, int extra);
  963.   
  964. ! static int eval_in_namespace(void *, Scheme_Closed_Prim *, Scheme_Env *,
  965. !         Scheme_Object **ret);
  966. ! static void make_modules(Scheme_Env *);
  967.   
  968.   #ifdef DYNAMIC_MZSCHEME
  969.   
  970. --- 161,212 ----
  971.   static Scheme_Object *do_eval(void *, int noargc, Scheme_Object **noargv);
  972.   static Scheme_Object *do_load(void *, int noargc, Scheme_Object **noargv);
  973.   static Scheme_Object *do_apply(void *, int noargc, Scheme_Object **noargv);
  974. ! static void register_vim_exn(void);
  975.   static vim_mz_buffer *get_buffer_arg(const char *fname, int argnum,
  976.       int argc, Scheme_Object **argv);
  977.   static vim_mz_window *get_window_arg(const char *fname, int argnum,
  978.       int argc, Scheme_Object **argv);
  979.   static int line_in_range(linenr_T, buf_T *);
  980.   static void check_line_range(linenr_T, buf_T *);
  981.   static void mz_fix_cursor(int lo, int hi, int extra);
  982.   
  983. ! static int eval_with_exn_handling(void *, Scheme_Closed_Prim *,
  984. !         Scheme_Object **ret);
  985. ! static void make_modules(void);
  986. ! static void init_exn_catching_apply(void);
  987. ! static int mzscheme_env_main(Scheme_Env *env, int argc, char **argv);
  988. ! static int mzscheme_init(void);
  989. ! #ifdef FEAT_EVAL
  990. ! static Scheme_Object *vim_to_mzscheme(typval_T *vim_value, int depth,
  991. !     Scheme_Hash_Table *visited);
  992. ! #endif
  993. ! #ifdef MZ_PRECISE_GC
  994. ! static int buffer_size_proc(void *obj)
  995. ! {
  996. !     return gcBYTES_TO_WORDS(sizeof(vim_mz_buffer));
  997. ! }
  998. ! static int buffer_mark_proc(void *obj)
  999. ! {
  1000. !     return buffer_size_proc(obj);
  1001. ! }
  1002. ! static int buffer_fixup_proc(void *obj)
  1003. ! {
  1004. !     return buffer_size_proc(obj);
  1005. ! }
  1006. ! static int window_size_proc(void *obj)
  1007. ! {
  1008. !     return gcBYTES_TO_WORDS(sizeof(vim_mz_window));
  1009. ! }
  1010. ! static int window_mark_proc(void *obj)
  1011. ! {
  1012. !     return window_size_proc(obj);
  1013. ! }
  1014. ! static int window_fixup_proc(void *obj)
  1015. ! {
  1016. !     return window_size_proc(obj);
  1017. ! }
  1018. ! #endif
  1019.   
  1020.   #ifdef DYNAMIC_MZSCHEME
  1021.   
  1022. ***************
  1023. *** 260,267 ****
  1024.       (Scheme_Closed_Prim *prim, void *data, const char *name, mzshort mina,
  1025.        mzshort maxa);
  1026.   static Scheme_Object *(*dll_scheme_make_integer_value)(long i);
  1027. - static Scheme_Object *(*dll_scheme_make_namespace)(int argc,
  1028. -     Scheme_Object *argv[]);
  1029.   static Scheme_Object *(*dll_scheme_make_pair)(Scheme_Object *car,
  1030.       Scheme_Object *cdr);
  1031.   static Scheme_Object *(*dll_scheme_make_prim_w_arity)(Scheme_Prim *prim,
  1032. --- 280,285 ----
  1033. ***************
  1034. *** 311,316 ****
  1035. --- 329,345 ----
  1036.   static Scheme_Object *(*dll_scheme_char_string_to_path)
  1037.       (Scheme_Object *s);
  1038.   # endif
  1039. + static Scheme_Hash_Table *(*dll_scheme_make_hash_table)(int type);
  1040. + static void (*dll_scheme_hash_set)(Scheme_Hash_Table *table,
  1041. +     Scheme_Object *key, Scheme_Object *value);
  1042. + static Scheme_Object *(*dll_scheme_hash_get)(Scheme_Hash_Table *table,
  1043. +     Scheme_Object *key);
  1044. + static Scheme_Object *(*dll_scheme_make_double)(double d);
  1045. + # ifdef INCLUDE_MZSCHEME_BASE
  1046. + static Scheme_Object *(*dll_scheme_make_sized_byte_string)(char *chars,
  1047. +     long len, int copy);
  1048. + static Scheme_Object *(*dll_scheme_namespace_require)(Scheme_Object *req);
  1049. + # endif
  1050.   
  1051.   /* arrays are imported directly */
  1052.   # define scheme_eof dll_scheme_eof
  1053. ***************
  1054. *** 368,374 ****
  1055.   # define scheme_lookup_global dll_scheme_lookup_global
  1056.   # define scheme_make_closed_prim_w_arity dll_scheme_make_closed_prim_w_arity
  1057.   # define scheme_make_integer_value dll_scheme_make_integer_value
  1058. - # define scheme_make_namespace dll_scheme_make_namespace
  1059.   # define scheme_make_pair dll_scheme_make_pair
  1060.   # define scheme_make_prim_w_arity dll_scheme_make_prim_w_arity
  1061.   # if MZSCHEME_VERSION_MAJOR < 299
  1062. --- 397,402 ----
  1063. ***************
  1064. *** 403,408 ****
  1065. --- 431,444 ----
  1066.   #  define scheme_char_string_to_path \
  1067.       dll_scheme_char_string_to_path
  1068.   # endif
  1069. + # define scheme_make_hash_table dll_scheme_make_hash_table
  1070. + # define scheme_hash_set dll_scheme_hash_set
  1071. + # define scheme_hash_get dll_scheme_hash_get
  1072. + # define scheme_make_double dll_scheme_make_double
  1073. + # ifdef INCLUDE_MZSCHEME_BASE
  1074. + #  define scheme_make_sized_byte_string dll_scheme_make_sized_byte_string
  1075. + #  define scheme_namespace_require dll_scheme_namespace_require
  1076. + # endif
  1077.   
  1078.   typedef struct
  1079.   {
  1080. ***************
  1081. *** 468,474 ****
  1082.       {"scheme_make_closed_prim_w_arity",
  1083.       (void **)&dll_scheme_make_closed_prim_w_arity},
  1084.       {"scheme_make_integer_value", (void **)&dll_scheme_make_integer_value},
  1085. -     {"scheme_make_namespace", (void **)&dll_scheme_make_namespace},
  1086.       {"scheme_make_pair", (void **)&dll_scheme_make_pair},
  1087.       {"scheme_make_prim_w_arity", (void **)&dll_scheme_make_prim_w_arity},
  1088.   # if MZSCHEME_VERSION_MAJOR < 299
  1089. --- 504,509 ----
  1090. ***************
  1091. *** 502,510 ****
  1092.       {"scheme_current_config", (void **)&dll_scheme_current_config},
  1093.       {"scheme_char_string_to_byte_string",
  1094.       (void **)&dll_scheme_char_string_to_byte_string},
  1095. !     {"scheme_char_string_to_path",
  1096. !     (void **)&dll_scheme_char_string_to_path},
  1097.   # endif
  1098.       {NULL, NULL}};
  1099.   
  1100.   static HINSTANCE hMzGC = 0;
  1101. --- 537,552 ----
  1102.       {"scheme_current_config", (void **)&dll_scheme_current_config},
  1103.       {"scheme_char_string_to_byte_string",
  1104.       (void **)&dll_scheme_char_string_to_byte_string},
  1105. !     {"scheme_char_string_to_path", (void **)&dll_scheme_char_string_to_path},
  1106.   # endif
  1107. +     {"scheme_make_hash_table", (void **)&dll_scheme_make_hash_table},
  1108. +     {"scheme_hash_set", (void **)&dll_scheme_hash_set},
  1109. +     {"scheme_hash_get", (void **)&dll_scheme_hash_get},
  1110. +     {"scheme_make_double", (void **)&dll_scheme_make_double},
  1111. + # ifdef INCLUDE_MZSCHEME_BASE
  1112. +     {"scheme_make_sized_byte_string", (void **)&dll_scheme_make_sized_byte_string},
  1113. +     {"scheme_namespace_require", (void **)&dll_scheme_namespace_require},
  1114. + #endif
  1115.       {NULL, NULL}};
  1116.   
  1117.   static HINSTANCE hMzGC = 0;
  1118. ***************
  1119. *** 592,597 ****
  1120. --- 634,644 ----
  1121.   }
  1122.   #endif /* DYNAMIC_MZSCHEME */
  1123.   
  1124. + /* need to put it here for dynamic stuff to work */
  1125. + #ifdef INCLUDE_MZSCHEME_BASE
  1126. + # include "mzscheme_base.c"
  1127. + #endif
  1128.   /*
  1129.    *========================================================================
  1130.    *  1. MzScheme interpreter startup
  1131. ***************
  1132. *** 601,621 ****
  1133.   static Scheme_Type mz_buffer_type;
  1134.   static Scheme_Type mz_window_type;
  1135.   
  1136. ! static int initialized = 0;
  1137.   
  1138.   /* global environment */
  1139.   static Scheme_Env    *environment = NULL;
  1140.   /* output/error handlers */
  1141.   static Scheme_Object *curout = NULL;
  1142.   static Scheme_Object *curerr = NULL;
  1143. ! /* vim:exn exception */
  1144.   static Scheme_Object *exn_catching_apply = NULL;
  1145.   static Scheme_Object *exn_p = NULL;
  1146.   static Scheme_Object *exn_message = NULL;
  1147.   static Scheme_Object *vim_exn = NULL; /* Vim Error exception */
  1148. !  /* values for exn:vim - constructor, predicate, accessors etc */
  1149. ! static Scheme_Object *vim_exn_names = NULL;
  1150. ! static Scheme_Object *vim_exn_values = NULL;
  1151.   
  1152.   static long range_start;
  1153.   static long range_end;
  1154. --- 648,669 ----
  1155.   static Scheme_Type mz_buffer_type;
  1156.   static Scheme_Type mz_window_type;
  1157.   
  1158. ! static int initialized = FALSE;
  1159.   
  1160.   /* global environment */
  1161.   static Scheme_Env    *environment = NULL;
  1162.   /* output/error handlers */
  1163.   static Scheme_Object *curout = NULL;
  1164.   static Scheme_Object *curerr = NULL;
  1165. ! /* exn:vim exception */
  1166.   static Scheme_Object *exn_catching_apply = NULL;
  1167.   static Scheme_Object *exn_p = NULL;
  1168.   static Scheme_Object *exn_message = NULL;
  1169.   static Scheme_Object *vim_exn = NULL; /* Vim Error exception */
  1170. ! #if !defined(MZ_PRECISE_GC) || MZSCHEME_VERSION_MAJOR < 400
  1171. ! static void *stack_base = NULL;
  1172. ! #endif
  1173.   
  1174.   static long range_start;
  1175.   static long range_end;
  1176. ***************
  1177. *** 668,677 ****
  1178.   timer_proc(HWND hwnd, UINT uMsg, UINT idEvent, DWORD dwTime)
  1179.   # elif defined(FEAT_GUI_GTK)
  1180.       static gint
  1181. ! timer_proc(gpointer data UNUSED)
  1182.   # elif defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_ATHENA)
  1183.       static void
  1184. ! timer_proc(XtPointer timed_out UNUSED, XtIntervalId *interval_id UNUSED)
  1185.   # elif defined(FEAT_GUI_MAC)
  1186.       pascal void
  1187.   timer_proc(EventLoopTimerRef theTimer, void *userData)
  1188. --- 716,725 ----
  1189.   timer_proc(HWND hwnd, UINT uMsg, UINT idEvent, DWORD dwTime)
  1190.   # elif defined(FEAT_GUI_GTK)
  1191.       static gint
  1192. ! timer_proc(gpointer data)
  1193.   # elif defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_ATHENA)
  1194.       static void
  1195. ! timer_proc(XtPointer timed_out, XtIntervalId *interval_id)
  1196.   # elif defined(FEAT_GUI_MAC)
  1197.       pascal void
  1198.   timer_proc(EventLoopTimerRef theTimer, void *userData)
  1199. ***************
  1200. *** 751,762 ****
  1201.   #endif
  1202.   }
  1203.   
  1204.       static void
  1205.   startup_mzscheme(void)
  1206.   {
  1207. !     Scheme_Object *proc_make_security_guard;
  1208. !     scheme_set_stack_base(NULL, 1);
  1209.   
  1210.       MZ_REGISTER_STATIC(environment);
  1211.       MZ_REGISTER_STATIC(curout);
  1212. --- 799,862 ----
  1213.   #endif
  1214.   }
  1215.   
  1216. +     void
  1217. + mzscheme_main(void)
  1218. + {
  1219. + #if defined(MZ_PRECISE_GC) && MZSCHEME_VERSION_MAJOR >= 400
  1220. +     /* use trampoline for precise GC in MzScheme >= 4.x */
  1221. +     scheme_main_setup(TRUE, mzscheme_env_main, 0, NULL);
  1222. + #else
  1223. +     mzscheme_env_main(NULL, 0, NULL);
  1224. + #endif
  1225. + }
  1226. +     static int
  1227. + mzscheme_env_main(Scheme_Env *env, int argc, char **argv)
  1228. + {
  1229. +     /* neither argument nor return values are used */
  1230. + #ifdef MZ_PRECISE_GC
  1231. + # if MZSCHEME_VERSION_MAJOR < 400
  1232. +     /*
  1233. +      * Starting from version 4.x, embedding applications must use
  1234. +      * scheme_main_setup/scheme_main_stack_setup trampolines
  1235. +      * rather than setting stack base directly with scheme_set_stack_base
  1236. +      */
  1237. +     Scheme_Object   *dummy = NULL;
  1238. +     MZ_GC_DECL_REG(1);
  1239. +     MZ_GC_VAR_IN_REG(0, dummy);
  1240. +     stack_base = &__gc_var_stack__;
  1241. + # else
  1242. +     /* environment has been created by us by Scheme */
  1243. +     environment = env;
  1244. + # endif
  1245. +     /*
  1246. +      * In 4.x, all activities must be performed inside trampoline
  1247. +      * so we are forced to initialise GC immediately
  1248. +      * This can be postponed in 3.x but I see no point in implementing
  1249. +      * a feature which will work in older versions only.
  1250. +      * One would better use conservative GC if he needs dynamic MzScheme
  1251. +      */
  1252. +     mzscheme_init();
  1253. + #else
  1254. +     int dummy = 0;
  1255. +     stack_base = (void *)&dummy;
  1256. + #endif
  1257. +     main_loop(FALSE, FALSE);
  1258. + #if defined(MZ_PRECISE_GC) && MZSCHEME_VERSION_MAJOR < 400
  1259. +     /* releasing dummy */
  1260. +     MZ_GC_REG();
  1261. +     MZ_GC_UNREG();
  1262. + #endif
  1263. +     return 0;
  1264. + }
  1265.       static void
  1266.   startup_mzscheme(void)
  1267.   {
  1268. ! #if !defined(MZ_PRECISE_GC) || MZSCHEME_VERSION_MAJOR < 400
  1269. !     scheme_set_stack_base(stack_base, 1);
  1270. ! #endif
  1271.   
  1272.       MZ_REGISTER_STATIC(environment);
  1273.       MZ_REGISTER_STATIC(curout);
  1274. ***************
  1275. *** 765,774 ****
  1276.       MZ_REGISTER_STATIC(exn_p);
  1277.       MZ_REGISTER_STATIC(exn_message);
  1278.       MZ_REGISTER_STATIC(vim_exn);
  1279. -     MZ_REGISTER_STATIC(vim_exn_names);
  1280. -     MZ_REGISTER_STATIC(vim_exn_values);
  1281.   
  1282.       environment = scheme_basic_env();
  1283.   
  1284.       /* redirect output */
  1285.       scheme_console_output = do_output;
  1286. --- 865,899 ----
  1287.       MZ_REGISTER_STATIC(exn_p);
  1288.       MZ_REGISTER_STATIC(exn_message);
  1289.       MZ_REGISTER_STATIC(vim_exn);
  1290.   
  1291. + #if !defined(MZ_PRECISE_GC) || MZSCHEME_VERSION_MAJOR < 400
  1292. +     /* in newer versions of precise GC the initial env has been created */
  1293.       environment = scheme_basic_env();
  1294. + #endif
  1295. +     MZ_GC_CHECK();
  1296. + #ifdef INCLUDE_MZSCHEME_BASE
  1297. +     {
  1298. +     /*
  1299. +      * versions 4.x do not provide Scheme bindings by defaults
  1300. +      * we need to add them explicitly
  1301. +      */
  1302. +     Scheme_Object *scheme_base_symbol = NULL;
  1303. +     MZ_GC_DECL_REG(1);
  1304. +     MZ_GC_VAR_IN_REG(0, scheme_base_symbol);
  1305. +     MZ_GC_REG();
  1306. +     /* invoke function from generated and included base.c */
  1307. +     declare_modules(environment);
  1308. +     scheme_base_symbol = scheme_intern_symbol("scheme/base");
  1309. +     MZ_GC_CHECK();
  1310. +     scheme_namespace_require(scheme_base_symbol);
  1311. +     MZ_GC_CHECK();
  1312. +     MZ_GC_UNREG();
  1313. +     }
  1314. + #endif
  1315. +     register_vim_exn();
  1316. +     /* use new environment to initialise exception handling */
  1317. +     init_exn_catching_apply();
  1318.   
  1319.       /* redirect output */
  1320.       scheme_console_output = do_output;
  1321. ***************
  1322. *** 776,823 ****
  1323.   
  1324.   #ifdef MZSCHEME_COLLECTS
  1325.       /* setup 'current-library-collection-paths' parameter */
  1326. -     scheme_set_param(scheme_config, MZCONFIG_COLLECTION_PATHS,
  1327. -         scheme_make_pair(
  1328.   # if MZSCHEME_VERSION_MAJOR >= 299
  1329. !         scheme_char_string_to_path(
  1330. !             scheme_byte_string_to_char_string(
  1331. !             scheme_make_byte_string(MZSCHEME_COLLECTS))),
  1332.   # else
  1333. !         scheme_make_string(MZSCHEME_COLLECTS),
  1334.   # endif
  1335. -         scheme_null));
  1336.   #endif
  1337.   #ifdef HAVE_SANDBOX
  1338. !     /* setup sandbox guards */
  1339. !     proc_make_security_guard = scheme_lookup_global(
  1340. !         scheme_intern_symbol("make-security-guard"),
  1341. !         environment);
  1342. !     if (proc_make_security_guard != NULL)
  1343. !     {
  1344. !     Scheme_Object *args[3];
  1345. !     Scheme_Object *guard;
  1346. !     args[0] = scheme_get_param(scheme_config, MZCONFIG_SECURITY_GUARD);
  1347. !     args[1] = scheme_make_prim_w_arity(sandbox_file_guard,
  1348. !         "sandbox-file-guard", 3, 3);
  1349. !     args[2] = scheme_make_prim_w_arity(sandbox_network_guard,
  1350. !         "sandbox-network-guard", 4, 4);
  1351. !     guard = scheme_apply(proc_make_security_guard, 3, args);
  1352. !     scheme_set_param(scheme_config, MZCONFIG_SECURITY_GUARD, guard);
  1353.       }
  1354.   #endif
  1355.       /* Create buffer and window types for use in Scheme code */
  1356.       mz_buffer_type = scheme_make_type("<vim-buffer>");
  1357.       mz_window_type = scheme_make_type("<vim-window>");
  1358.   
  1359. !     register_vim_exn(environment);
  1360. !     make_modules(environment);
  1361.   
  1362.       /*
  1363.        * setup callback to receive notifications
  1364.        * whether thread scheduling is (or not) required
  1365.        */
  1366.       scheme_notify_multithread = notify_multithread;
  1367. -     initialized = 1;
  1368.   }
  1369.   
  1370.   /*
  1371. --- 901,1031 ----
  1372.   
  1373.   #ifdef MZSCHEME_COLLECTS
  1374.       /* setup 'current-library-collection-paths' parameter */
  1375.   # if MZSCHEME_VERSION_MAJOR >= 299
  1376. !     {
  1377. !     Scheme_Object    *coll_byte_string = NULL;
  1378. !     Scheme_Object    *coll_char_string = NULL;
  1379. !     Scheme_Object    *coll_path = NULL;
  1380. !     Scheme_Object    *coll_pair = NULL;
  1381. !     Scheme_Config    *config = NULL;
  1382. !     MZ_GC_DECL_REG(5);
  1383. !     MZ_GC_VAR_IN_REG(0, coll_byte_string);
  1384. !     MZ_GC_VAR_IN_REG(1, coll_char_string);
  1385. !     MZ_GC_VAR_IN_REG(2, coll_path);
  1386. !     MZ_GC_VAR_IN_REG(3, coll_pair);
  1387. !     MZ_GC_VAR_IN_REG(4, config);
  1388. !     MZ_GC_REG();
  1389. !     coll_byte_string = scheme_make_byte_string(MZSCHEME_COLLECTS);
  1390. !     MZ_GC_CHECK();
  1391. !     coll_char_string = scheme_byte_string_to_char_string(coll_byte_string);
  1392. !     MZ_GC_CHECK();
  1393. !     coll_path = scheme_char_string_to_path(coll_char_string);
  1394. !     MZ_GC_CHECK();
  1395. !     coll_pair = scheme_make_pair(coll_path, scheme_null);
  1396. !     MZ_GC_CHECK();
  1397. !     config = scheme_config;
  1398. !     MZ_GC_CHECK();
  1399. !     scheme_set_param(config, MZCONFIG_COLLECTION_PATHS, coll_pair);
  1400. !     MZ_GC_CHECK();
  1401. !     MZ_GC_UNREG();
  1402. !     }
  1403.   # else
  1404. !     {
  1405. !     Scheme_Object    *coll_string = NULL;
  1406. !     Scheme_Object    *coll_pair = NULL;
  1407. !     Scheme_Config    *config = NULL;
  1408. !     MZ_GC_DECL_REG(3);
  1409. !     MZ_GC_VAR_IN_REG(0, coll_string);
  1410. !     MZ_GC_VAR_IN_REG(1, coll_pair);
  1411. !     MZ_GC_VAR_IN_REG(2, config);
  1412. !     MZ_GC_REG();
  1413. !     coll_string = scheme_make_string(MZSCHEME_COLLECTS);
  1414. !     MZ_GC_CHECK();
  1415. !     coll_pair = scheme_make_pair(coll_string, scheme_null);
  1416. !     MZ_GC_CHECK();
  1417. !     config = scheme_config;
  1418. !     MZ_GC_CHECK();
  1419. !     scheme_set_param(config, MZCONFIG_COLLECTION_PATHS, coll_pair);
  1420. !     MZ_GC_CHECK();
  1421. !     MZ_GC_UNREG();
  1422. !     }
  1423.   # endif
  1424.   #endif
  1425.   #ifdef HAVE_SANDBOX
  1426. !     {
  1427. !     Scheme_Object    *make_security_guard = NULL;
  1428. !     MZ_GC_DECL_REG(1);
  1429. !     MZ_GC_VAR_IN_REG(0, make_security_guard);
  1430. !     MZ_GC_REG();
  1431. ! #if MZSCHEME_VERSION_MAJOR < 400
  1432. !     {
  1433. !         Scheme_Object    *make_security_guard_symbol = NULL;
  1434. !         MZ_GC_DECL_REG(1);
  1435. !         MZ_GC_VAR_IN_REG(0, make_security_guard_symbol);
  1436. !         MZ_GC_REG();
  1437. !         make_security_guard_symbol = scheme_intern_symbol("make-security-guard");
  1438. !         MZ_GC_CHECK();
  1439. !         make_security_guard = scheme_lookup_global(
  1440. !             make_security_guard_symbol, environment);
  1441. !         MZ_GC_UNREG();
  1442. !     }
  1443. ! #else
  1444. !     make_security_guard = scheme_builtin_value("make-security-guard");
  1445. !     MZ_GC_CHECK();
  1446. ! #endif
  1447. !     /* setup sandbox guards */
  1448. !     if (make_security_guard != NULL)
  1449. !     {
  1450. !         Scheme_Object   *args[3] = {NULL, NULL, NULL};
  1451. !         Scheme_Object   *guard = NULL;
  1452. !         Scheme_Config   *config = NULL;
  1453. !         MZ_GC_DECL_REG(5);
  1454. !         MZ_GC_ARRAY_VAR_IN_REG(0, args, 3);
  1455. !         MZ_GC_VAR_IN_REG(3, guard);
  1456. !         MZ_GC_VAR_IN_REG(4, config);
  1457. !         MZ_GC_REG();
  1458. !         config = scheme_config;
  1459. !         MZ_GC_CHECK();
  1460. !         args[0] = scheme_get_param(config, MZCONFIG_SECURITY_GUARD);
  1461. !         MZ_GC_CHECK();
  1462. !         args[1] = scheme_make_prim_w_arity(sandbox_file_guard,
  1463. !             "sandbox-file-guard", 3, 3);
  1464. !         args[2] = scheme_make_prim_w_arity(sandbox_network_guard,
  1465. !             "sandbox-network-guard", 4, 4);
  1466. !         guard = scheme_apply(make_security_guard, 3, args);
  1467. !         MZ_GC_CHECK();
  1468. !         scheme_set_param(config, MZCONFIG_SECURITY_GUARD, guard);
  1469. !         MZ_GC_CHECK();
  1470. !         MZ_GC_UNREG();
  1471. !     }
  1472. !     MZ_GC_UNREG();
  1473.       }
  1474.   #endif
  1475.       /* Create buffer and window types for use in Scheme code */
  1476.       mz_buffer_type = scheme_make_type("<vim-buffer>");
  1477. +     MZ_GC_CHECK();
  1478.       mz_window_type = scheme_make_type("<vim-window>");
  1479. +     MZ_GC_CHECK();
  1480. + #ifdef MZ_PRECISE_GC
  1481. +     GC_register_traversers(mz_buffer_type,
  1482. +         buffer_size_proc, buffer_mark_proc, buffer_fixup_proc,
  1483. +         TRUE, TRUE);
  1484. +     GC_register_traversers(mz_window_type,
  1485. +         window_size_proc, window_mark_proc, window_fixup_proc,
  1486. +         TRUE, TRUE);
  1487. + #endif
  1488.   
  1489. !     make_modules();
  1490.   
  1491.       /*
  1492.        * setup callback to receive notifications
  1493.        * whether thread scheduling is (or not) required
  1494.        */
  1495.       scheme_notify_multithread = notify_multithread;
  1496.   }
  1497.   
  1498.   /*
  1499. ***************
  1500. *** 827,897 ****
  1501.       static int
  1502.   mzscheme_init(void)
  1503.   {
  1504. -     int do_require = FALSE;
  1505.       if (!initialized)
  1506.       {
  1507. -     do_require = TRUE;
  1508.   #ifdef DYNAMIC_MZSCHEME
  1509.       if (!mzscheme_enabled(TRUE))
  1510.       {
  1511. !         EMSG(_("???: Sorry, this command is disabled, the MzScheme library could not be loaded."));
  1512.           return -1;
  1513.       }
  1514.   #endif
  1515.       startup_mzscheme();
  1516. !     if (mzscheme_io_init())
  1517. !         return -1;
  1518. !     }
  1519. !     /* recreate ports each call effectivelly clearing these ones */
  1520. !     curout = scheme_make_string_output_port();
  1521. !     curerr = scheme_make_string_output_port();
  1522. !     scheme_set_param(scheme_config, MZCONFIG_OUTPUT_PORT, curout);
  1523. !     scheme_set_param(scheme_config, MZCONFIG_ERROR_PORT, curerr);
  1524. !     if (do_require)
  1525. !     {
  1526. !     /* auto-instantiate in basic env */
  1527. !     eval_in_namespace("(require (prefix vimext: vimext))", do_eval,
  1528. !         environment, NULL);
  1529.       }
  1530. -     return 0;
  1531. - }
  1532. - /*
  1533. -  * This routine fills the namespace with various important routines that can
  1534. -  * be used within MzScheme.
  1535. -  */
  1536. -     static void
  1537. - mzscheme_interface_init(vim_mz_buffer *mzbuff)
  1538. - {
  1539. -     Scheme_Object   *attach;
  1540. -     mzbuff->env = (Scheme_Env *)scheme_make_namespace(0, NULL);
  1541. -     /*
  1542. -      * attach instantiated modules from global namespace
  1543. -      * so they can be easily instantiated in the buffer namespace
  1544. -      */
  1545. -     attach = scheme_lookup_global(
  1546. -         scheme_intern_symbol("namespace-attach-module"),
  1547. -         environment);
  1548. -     if (attach != NULL)
  1549.       {
  1550. !     Scheme_Object   *ret;
  1551. !     Scheme_Object    *args[2];
  1552. !     args[0] = (Scheme_Object *)environment;
  1553. !     args[1] = scheme_intern_symbol("vimext");
  1554. !     ret = (Scheme_Object *)mzvim_apply(attach, 2, args);
  1555.       }
  1556.   
  1557. !     add_vim_exn(mzbuff->env);
  1558.   }
  1559.   
  1560.   /*
  1561. --- 1035,1072 ----
  1562.       static int
  1563.   mzscheme_init(void)
  1564.   {
  1565.       if (!initialized)
  1566.       {
  1567.   #ifdef DYNAMIC_MZSCHEME
  1568.       if (!mzscheme_enabled(TRUE))
  1569.       {
  1570. !         EMSG(_("E812: Sorry, this command is disabled, the MzScheme libraries could not be loaded."));
  1571.           return -1;
  1572.       }
  1573.   #endif
  1574.       startup_mzscheme();
  1575. !     initialized = TRUE;
  1576.       }
  1577.       {
  1578. !     Scheme_Config    *config = NULL;
  1579. !     MZ_GC_DECL_REG(1);
  1580. !     MZ_GC_VAR_IN_REG(0, config);
  1581. !     MZ_GC_REG();
  1582. !     config = scheme_config;
  1583. !     MZ_GC_CHECK();
  1584. !     /* recreate ports each call effectivelly clearing these ones */
  1585. !     curout = scheme_make_string_output_port();
  1586. !     MZ_GC_CHECK();
  1587. !     curerr = scheme_make_string_output_port();
  1588. !     MZ_GC_CHECK();
  1589. !     scheme_set_param(config, MZCONFIG_OUTPUT_PORT, curout);
  1590. !     MZ_GC_CHECK();
  1591. !     scheme_set_param(config, MZCONFIG_ERROR_PORT, curerr);
  1592. !     MZ_GC_CHECK();
  1593. !     MZ_GC_UNREG();
  1594.       }
  1595.   
  1596. !     return 0;
  1597.   }
  1598.   
  1599.   /*
  1600. ***************
  1601. *** 901,928 ****
  1602.    */
  1603.   
  1604.   /*
  1605. !  * Evaluate command in namespace with exception handling
  1606.    */
  1607.       static int
  1608. ! eval_in_namespace(void *data, Scheme_Closed_Prim *what, Scheme_Env *env,
  1609. !         Scheme_Object **ret)
  1610.   {
  1611. !     Scheme_Object   *value;
  1612. !     Scheme_Object   *exn;
  1613. !     Cmd_Info        info;   /* closure info */
  1614. !     info.data = data;
  1615. !     info.env = env;
  1616. !     scheme_set_param(scheme_config, MZCONFIG_ENV,
  1617. !         (Scheme_Object *) env);
  1618. !     /*
  1619. !      * ensure all evaluations will be in current buffer namespace,
  1620. !      * the second argument to scheme_eval_string isn't enough!
  1621. !      */
  1622. !     value = _apply_thunk_catch_exceptions(
  1623. !         scheme_make_closed_prim_w_arity(what, &info, "mzvim", 0, 0),
  1624. !         &exn);
  1625.   
  1626.       if (!value)
  1627.       {
  1628. --- 1076,1100 ----
  1629.    */
  1630.   
  1631.   /*
  1632. !  * Evaluate command with exception handling
  1633.    */
  1634.       static int
  1635. ! eval_with_exn_handling(void *data, Scheme_Closed_Prim *what, Scheme_Object **ret)
  1636.   {
  1637. !     Scheme_Object   *value = NULL;
  1638. !     Scheme_Object   *exn = NULL;
  1639. !     Scheme_Object   *prim = NULL;
  1640. !     MZ_GC_DECL_REG(3);
  1641. !     MZ_GC_VAR_IN_REG(0, value);
  1642. !     MZ_GC_VAR_IN_REG(1, exn);
  1643. !     MZ_GC_VAR_IN_REG(2, prim);
  1644. !     MZ_GC_REG();
  1645. !     prim = scheme_make_closed_prim_w_arity(what, data, "mzvim", 0, 0);
  1646. !     MZ_GC_CHECK();
  1647. !     value = _apply_thunk_catch_exceptions(prim, &exn);
  1648. !     MZ_GC_CHECK();
  1649.   
  1650.       if (!value)
  1651.       {
  1652. ***************
  1653. *** 930,938 ****
  1654.       /* Got an exn? */
  1655.       if (value)
  1656.       {
  1657. !         scheme_display(value, curerr);  /*  Send to stderr-vim */
  1658.           do_flush();
  1659.       }
  1660.       /* `raise' was called on some arbitrary value */
  1661.       return FAIL;
  1662.       }
  1663. --- 1102,1112 ----
  1664.       /* Got an exn? */
  1665.       if (value)
  1666.       {
  1667. !         scheme_display(value, curerr);   /*  Send to stderr-vim */
  1668. !         MZ_GC_CHECK();
  1669.           do_flush();
  1670.       }
  1671. +     MZ_GC_UNREG();
  1672.       /* `raise' was called on some arbitrary value */
  1673.       return FAIL;
  1674.       }
  1675. ***************
  1676. *** 941,949 ****
  1677. --- 1115,1127 ----
  1678.       *ret = value;
  1679.       /* Print any result, as long as it's not a void */
  1680.       else if (!SCHEME_VOIDP(value))
  1681. +     {
  1682.       scheme_display(value, curout);  /* Send to stdout-vim */
  1683. +     MZ_GC_CHECK();
  1684. +     }
  1685.   
  1686.       do_flush();
  1687. +     MZ_GC_UNREG();
  1688.       return OK;
  1689.   }
  1690.   
  1691. ***************
  1692. *** 957,963 ****
  1693.       range_start = eap->line1;
  1694.       range_end = eap->line2;
  1695.   
  1696. !     return eval_in_namespace(data, what, get_vim_curr_buffer()->env, NULL);
  1697.   }
  1698.   
  1699.   /*
  1700. --- 1135,1141 ----
  1701.       range_start = eap->line1;
  1702.       range_end = eap->line2;
  1703.   
  1704. !     return eval_with_exn_handling(data, what, NULL);
  1705.   }
  1706.   
  1707.   /*
  1708. ***************
  1709. *** 974,979 ****
  1710. --- 1152,1158 ----
  1711.       bp->buf = INVALID_BUFFER_VALUE;
  1712.       buf->b_mzscheme_ref = NULL;
  1713.       scheme_gc_ptr_ok(bp);
  1714. +     MZ_GC_CHECK();
  1715.       }
  1716.   }
  1717.   
  1718. ***************
  1719. *** 990,995 ****
  1720. --- 1169,1175 ----
  1721.       wp->win = INVALID_WINDOW_VALUE;
  1722.       win->w_mzscheme_ref = NULL;
  1723.       scheme_gc_ptr_ok(wp);
  1724. +     MZ_GC_CHECK();
  1725.       }
  1726.   }
  1727.   
  1728. ***************
  1729. *** 1014,1031 ****
  1730.       }
  1731.   }
  1732.   
  1733. - /* eval MzScheme string */
  1734. -     void *
  1735. - mzvim_eval_string(char_u *str)
  1736. - {
  1737. -     Scheme_Object *ret = NULL;
  1738. -     if (mzscheme_init())
  1739. -     return FAIL;
  1740. -     eval_in_namespace(str, do_eval, get_vim_curr_buffer()->env, &ret);
  1741. -     return ret;
  1742. - }
  1743.   /*
  1744.    * apply MzScheme procedure with arguments,
  1745.    * handling errors
  1746. --- 1194,1199 ----
  1747. ***************
  1748. *** 1033,1075 ****
  1749.       Scheme_Object *
  1750.   mzvim_apply(Scheme_Object *proc, int argc, Scheme_Object **argv)
  1751.   {
  1752. -     Apply_Info    data;
  1753. -     Scheme_Object *ret = NULL;
  1754.       if (mzscheme_init())
  1755.       return FAIL;
  1756.   
  1757. !     data.proc = proc;
  1758. !     data.argc = argc;
  1759. !     data.argv = argv;
  1760. !     eval_in_namespace(&data, do_apply, get_vim_curr_buffer()->env, &ret);
  1761. !     return ret;
  1762.   }
  1763.   
  1764.       static Scheme_Object *
  1765.   do_load(void *data, int noargc, Scheme_Object **noargv)
  1766.   {
  1767. !     Cmd_Info        *info = (Cmd_Info *)data;
  1768. !     Scheme_Object   *result = scheme_void;
  1769. !     Scheme_Object   *expr;
  1770. !     char_u        *file = scheme_malloc_fail_ok(
  1771. !                       scheme_malloc_atomic, MAXPATHL + 1);
  1772. !     Port_Info        *pinfo = (Port_Info *)(info->data);
  1773.   
  1774.       /* make Vim expansion */
  1775. !     expand_env((char_u *)pinfo->name, file, MAXPATHL);
  1776. !     /* scheme_load looks strange working with namespaces and error handling*/
  1777.       pinfo->port = scheme_open_input_file(file, "mzfile");
  1778. !     scheme_count_lines(pinfo->port); /* to get accurate read error location*/
  1779.   
  1780.       /* Like REPL but print only last result */
  1781.       while (!SCHEME_EOFP(expr = scheme_read(pinfo->port)))
  1782. !     result = scheme_eval(expr, info->env);
  1783.   
  1784.       /* errors will be caught in do_mzscheme_comamnd and ex_mzfile */
  1785.       scheme_close_input_port(pinfo->port);
  1786.       pinfo->port = NULL;
  1787.       return result;
  1788.   }
  1789.   
  1790. --- 1201,1265 ----
  1791.       Scheme_Object *
  1792.   mzvim_apply(Scheme_Object *proc, int argc, Scheme_Object **argv)
  1793.   {
  1794.       if (mzscheme_init())
  1795.       return FAIL;
  1796. +     else
  1797. +     {
  1798. +     Apply_Info    data = {NULL, 0, NULL};
  1799. +     Scheme_Object    *ret = NULL;
  1800.   
  1801. !     MZ_GC_DECL_REG(5);
  1802. !     MZ_GC_VAR_IN_REG(0, ret);
  1803. !     MZ_GC_VAR_IN_REG(1, data.proc);
  1804. !     MZ_GC_ARRAY_VAR_IN_REG(2, data.argv, argc);
  1805. !     MZ_GC_REG();
  1806. !     data.proc = proc;
  1807. !     data.argc = argc;
  1808. !     data.argv = argv;
  1809. !     eval_with_exn_handling(&data, do_apply, &ret);
  1810. !     MZ_GC_UNREG();
  1811. !     return ret;
  1812. !     }
  1813.   }
  1814.   
  1815.       static Scheme_Object *
  1816.   do_load(void *data, int noargc, Scheme_Object **noargv)
  1817.   {
  1818. !     Scheme_Object   *expr = NULL;
  1819. !     Scheme_Object   *result = NULL;
  1820. !     char        *file = NULL;
  1821. !     Port_Info        *pinfo = (Port_Info *)data;
  1822. !     MZ_GC_DECL_REG(3);
  1823. !     MZ_GC_VAR_IN_REG(0, expr);
  1824. !     MZ_GC_VAR_IN_REG(1, result);
  1825. !     MZ_GC_VAR_IN_REG(2, file);
  1826. !     MZ_GC_REG();
  1827. !     file = (char *)scheme_malloc_fail_ok(scheme_malloc_atomic, MAXPATHL + 1);
  1828. !     MZ_GC_CHECK();
  1829.   
  1830.       /* make Vim expansion */
  1831. !     expand_env((char_u *)pinfo->name, (char_u *)file, MAXPATHL);
  1832.       pinfo->port = scheme_open_input_file(file, "mzfile");
  1833. !     MZ_GC_CHECK();
  1834. !     scheme_count_lines(pinfo->port);  /* to get accurate read error location*/
  1835. !     MZ_GC_CHECK();
  1836.   
  1837.       /* Like REPL but print only last result */
  1838.       while (!SCHEME_EOFP(expr = scheme_read(pinfo->port)))
  1839. !     {
  1840. !     result = scheme_eval(expr, environment);
  1841. !     MZ_GC_CHECK();
  1842. !     }
  1843.   
  1844.       /* errors will be caught in do_mzscheme_comamnd and ex_mzfile */
  1845.       scheme_close_input_port(pinfo->port);
  1846. +     MZ_GC_CHECK();
  1847.       pinfo->port = NULL;
  1848. +     MZ_GC_UNREG();
  1849.       return result;
  1850.   }
  1851.   
  1852. ***************
  1853. *** 1077,1089 ****
  1854.       void
  1855.   ex_mzfile(exarg_T *eap)
  1856.   {
  1857. !     Port_Info    pinfo;
  1858.   
  1859.       pinfo.name = (char *)eap->arg;
  1860. -     pinfo.port = NULL;
  1861.       if (do_mzscheme_command(eap, &pinfo, do_load) != OK
  1862.           && pinfo.port != NULL)    /* looks like port was not closed */
  1863.       scheme_close_input_port(pinfo.port);
  1864.   }
  1865.   
  1866.   
  1867. --- 1267,1286 ----
  1868.       void
  1869.   ex_mzfile(exarg_T *eap)
  1870.   {
  1871. !     Port_Info    pinfo = {NULL, NULL};
  1872. !     MZ_GC_DECL_REG(1);
  1873. !     MZ_GC_VAR_IN_REG(0, pinfo.port);
  1874. !     MZ_GC_REG();
  1875.   
  1876.       pinfo.name = (char *)eap->arg;
  1877.       if (do_mzscheme_command(eap, &pinfo, do_load) != OK
  1878.           && pinfo.port != NULL)    /* looks like port was not closed */
  1879. +     {
  1880.       scheme_close_input_port(pinfo.port);
  1881. +     MZ_GC_CHECK();
  1882. +     }
  1883. +     MZ_GC_UNREG();
  1884.   }
  1885.   
  1886.   
  1887. ***************
  1888. *** 1103,1116 ****
  1889.           "(with-handlers ([void (lambda (exn) (cons #f exn))]) "
  1890.           "(cons #t (thunk))))";
  1891.   
  1892. !     /* make sure we have a namespace with the standard syntax: */
  1893. !     Scheme_Env *env = (Scheme_Env *)scheme_make_namespace(0, NULL);
  1894. !     add_vim_exn(env);
  1895. !     exn_catching_apply = scheme_eval_string(e, env);
  1896. !     exn_p = scheme_lookup_global(scheme_intern_symbol("exn?"), env);
  1897. !     exn_message = scheme_lookup_global(
  1898. !         scheme_intern_symbol("exn-message"), env);
  1899.       }
  1900.   }
  1901.   
  1902. --- 1300,1311 ----
  1903.           "(with-handlers ([void (lambda (exn) (cons #f exn))]) "
  1904.           "(cons #t (thunk))))";
  1905.   
  1906. !     exn_catching_apply = scheme_eval_string(e, environment);
  1907. !     MZ_GC_CHECK();
  1908. !     exn_p = scheme_builtin_value("exn?");
  1909. !     MZ_GC_CHECK();
  1910. !     exn_message = scheme_builtin_value("exn-message");
  1911. !     MZ_GC_CHECK();
  1912.       }
  1913.   }
  1914.   
  1915. ***************
  1916. *** 1124,1131 ****
  1917.   {
  1918.       Scheme_Object *v;
  1919.   
  1920. -     init_exn_catching_apply();
  1921.       v = _scheme_apply(exn_catching_apply, 1, &f);
  1922.       /* v is a pair: (cons #t value) or (cons #f exn) */
  1923.   
  1924. --- 1319,1324 ----
  1925. ***************
  1926. *** 1141,1148 ****
  1927.       static Scheme_Object *
  1928.   extract_exn_message(Scheme_Object *v)
  1929.   {
  1930. -     init_exn_catching_apply();
  1931.       if (SCHEME_TRUEP(_scheme_apply(exn_p, 1, &v)))
  1932.       return _scheme_apply(exn_message, 1, &v);
  1933.       else
  1934. --- 1334,1339 ----
  1935. ***************
  1936. *** 1152,1167 ****
  1937.       static Scheme_Object *
  1938.   do_eval(void *s, int noargc, Scheme_Object **noargv)
  1939.   {
  1940. !     Cmd_Info    *info = (Cmd_Info *)s;
  1941. !     return scheme_eval_string_all((char *)(info->data), info->env, TRUE);
  1942.   }
  1943.   
  1944.       static Scheme_Object *
  1945.   do_apply(void *a, int noargc, Scheme_Object **noargv)
  1946.   {
  1947. !     Apply_Info    *info = (Apply_Info *)(((Cmd_Info *)a)->data);
  1948.       return scheme_apply(info->proc, info->argc, info->argv);
  1949.   }
  1950.   
  1951. --- 1343,1355 ----
  1952.       static Scheme_Object *
  1953.   do_eval(void *s, int noargc, Scheme_Object **noargv)
  1954.   {
  1955. !     return scheme_eval_string_all((char *)s, environment, TRUE);
  1956.   }
  1957.   
  1958.       static Scheme_Object *
  1959.   do_apply(void *a, int noargc, Scheme_Object **noargv)
  1960.   {
  1961. !     Apply_Info    *info = (Apply_Info *)a;
  1962.       return scheme_apply(info->proc, info->argc, info->argv);
  1963.   }
  1964.   
  1965. ***************
  1966. *** 1219,1224 ****
  1967. --- 1407,1413 ----
  1968.       long length;
  1969.   
  1970.       buff = scheme_get_sized_string_output(curerr, &length);
  1971. +     MZ_GC_CHECK();
  1972.       if (length)
  1973.       {
  1974.       do_err_output(buff, length);
  1975. ***************
  1976. *** 1226,1242 ****
  1977.       }
  1978.   
  1979.       buff = scheme_get_sized_string_output(curout, &length);
  1980.       if (length)
  1981.       do_output(buff, length);
  1982.   }
  1983.   
  1984. -     static int
  1985. - mzscheme_io_init(void)
  1986. - {
  1987. -     /* Nothing needed so far... */
  1988. -     return 0;
  1989. - }
  1990.   /*
  1991.    *========================================================================
  1992.    *  4. Implementation of the Vim Features for MzScheme
  1993. --- 1415,1425 ----
  1994.       }
  1995.   
  1996.       buff = scheme_get_sized_string_output(curout, &length);
  1997. +     MZ_GC_CHECK();
  1998.       if (length)
  1999.       do_output(buff, length);
  2000.   }
  2001.   
  2002.   /*
  2003.    *========================================================================
  2004.    *  4. Implementation of the Vim Features for MzScheme
  2005. ***************
  2006. *** 1263,1284 ****
  2007.   vim_eval(void *data, int argc, Scheme_Object **argv)
  2008.   {
  2009.   #ifdef FEAT_EVAL
  2010. !     Vim_Prim        *prim = (Vim_Prim *)data;
  2011. !     char        *expr;
  2012. !     char        *str;
  2013. !     Scheme_Object   *result;
  2014.   
  2015. !     expr = SCHEME_STR_VAL(GUARANTEE_STRING(prim->name, 0));
  2016.   
  2017. !     str = (char *)eval_to_string((char_u *)expr, NULL, TRUE);
  2018.   
  2019. !     if (str == NULL)
  2020.       raise_vim_exn(_("invalid expression"));
  2021.   
  2022. !     result = scheme_make_string(str);
  2023. !     vim_free(str);
  2024.   
  2025.       return result;
  2026.   #else
  2027.       raise_vim_exn(_("expressions disabled at compile time"));
  2028. --- 1446,1475 ----
  2029.   vim_eval(void *data, int argc, Scheme_Object **argv)
  2030.   {
  2031.   #ifdef FEAT_EVAL
  2032. !     Vim_Prim        *prim = (Vim_Prim *)data;
  2033. !     char        *expr;
  2034. !     Scheme_Object    *result;
  2035. !     /* hash table to store visited values to avoid infinite loops */
  2036. !     Scheme_Hash_Table    *visited = NULL;
  2037. !     typval_T        *vim_result;
  2038. !     MZ_GC_DECL_REG(1);
  2039. !     MZ_GC_VAR_IN_REG(0, visited);
  2040. !     MZ_GC_REG();
  2041.   
  2042. !     visited = scheme_make_hash_table(SCHEME_hash_ptr);
  2043. !     MZ_GC_CHECK();
  2044.   
  2045. !     expr = SCHEME_STR_VAL(GUARANTEE_STRING(prim->name, 0));
  2046. !     vim_result = eval_expr((char_u *)expr, NULL);
  2047.   
  2048. !     if (vim_result == NULL)
  2049.       raise_vim_exn(_("invalid expression"));
  2050.   
  2051. !     result = vim_to_mzscheme(vim_result, 1, visited);
  2052. !     free_tv(vim_result);
  2053.   
  2054. +     MZ_GC_UNREG();
  2055.       return result;
  2056.   #else
  2057.       raise_vim_exn(_("expressions disabled at compile time"));
  2058. ***************
  2059. *** 1318,1324 ****
  2060.       Vim_Prim        *prim = (Vim_Prim *)data;
  2061.       char_u        *name;
  2062.       long        value;
  2063. !     char_u        *strval;
  2064.       int            rc;
  2065.       Scheme_Object   *rval;
  2066.       int            opt_flags = 0;
  2067. --- 1509,1515 ----
  2068.       Vim_Prim        *prim = (Vim_Prim *)data;
  2069.       char_u        *name;
  2070.       long        value;
  2071. !     char        *strval;
  2072.       int            rc;
  2073.       Scheme_Object   *rval;
  2074.       int            opt_flags = 0;
  2075. ***************
  2076. *** 1333,1338 ****
  2077. --- 1524,1530 ----
  2078.       {
  2079.           MZ_REGISTER_STATIC(M_global);
  2080.           M_global = scheme_intern_symbol("global");
  2081. +         MZ_GC_CHECK();
  2082.       }
  2083.   
  2084.       if (argv[1] == M_global)
  2085. ***************
  2086. *** 1354,1360 ****
  2087.           scheme_wrong_type(prim->name, "vim-buffer/window", 1, argc, argv);
  2088.       }
  2089.   
  2090. !     rc = get_option_value(name, &value, &strval, opt_flags);
  2091.       curbuf = save_curb;
  2092.       curwin = save_curw;
  2093.   
  2094. --- 1546,1552 ----
  2095.           scheme_wrong_type(prim->name, "vim-buffer/window", 1, argc, argv);
  2096.       }
  2097.   
  2098. !     rc = get_option_value(name, &value, (char_u **)&strval, opt_flags);
  2099.       curbuf = save_curb;
  2100.       curwin = save_curw;
  2101.   
  2102. ***************
  2103. *** 1364,1369 ****
  2104. --- 1556,1562 ----
  2105.       return scheme_make_integer_value(value);
  2106.       case 0:
  2107.       rval = scheme_make_string(strval);
  2108. +     MZ_GC_CHECK();
  2109.       vim_free(strval);
  2110.       return rval;
  2111.       case -1:
  2112. ***************
  2113. *** 1393,1398 ****
  2114. --- 1586,1592 ----
  2115.       {
  2116.           MZ_REGISTER_STATIC(M_global);
  2117.           M_global = scheme_intern_symbol("global");
  2118. +         MZ_GC_CHECK();
  2119.       }
  2120.   
  2121.       if (argv[1] == M_global)
  2122. ***************
  2123. *** 1463,1469 ****
  2124. --- 1657,1666 ----
  2125.   
  2126.       for (w = firstwin; w != NULL; w = w->w_next)
  2127.       if (w->w_buffer == buf->buf)
  2128. +     {
  2129.           list = scheme_make_pair(window_new(w), list);
  2130. +         MZ_GC_CHECK();
  2131. +     }
  2132.   
  2133.       return list;
  2134.   }
  2135. ***************
  2136. *** 1471,1477 ****
  2137.       static Scheme_Object *
  2138.   window_new(win_T *win)
  2139.   {
  2140. !     vim_mz_window *self;
  2141.   
  2142.       /* We need to handle deletion of windows underneath us.
  2143.        * If we add a "w_mzscheme_ref" field to the win_T structure,
  2144. --- 1668,1678 ----
  2145.       static Scheme_Object *
  2146.   window_new(win_T *win)
  2147.   {
  2148. !     vim_mz_window *self = NULL;
  2149. !     MZ_GC_DECL_REG(1);
  2150. !     MZ_GC_VAR_IN_REG(0, self);
  2151. !     MZ_GC_REG();
  2152.   
  2153.       /* We need to handle deletion of windows underneath us.
  2154.        * If we add a "w_mzscheme_ref" field to the win_T structure,
  2155. ***************
  2156. *** 1485,1497 ****
  2157.       return win->w_mzscheme_ref;
  2158.   
  2159.       self = scheme_malloc_fail_ok(scheme_malloc, sizeof(vim_mz_window));
  2160.       vim_memset(self, 0, sizeof(vim_mz_window));
  2161.       scheme_dont_gc_ptr(self);    /* because win isn't visible to GC */
  2162.       win->w_mzscheme_ref = self;
  2163.       self->win = win;
  2164. !     self->tag = mz_window_type;
  2165.   
  2166.       return (Scheme_Object *)(self);
  2167.   }
  2168.   
  2169. --- 1686,1699 ----
  2170.       return win->w_mzscheme_ref;
  2171.   
  2172.       self = scheme_malloc_fail_ok(scheme_malloc, sizeof(vim_mz_window));
  2173.       vim_memset(self, 0, sizeof(vim_mz_window));
  2174.       scheme_dont_gc_ptr(self);    /* because win isn't visible to GC */
  2175. +     MZ_GC_CHECK();
  2176.       win->w_mzscheme_ref = self;
  2177.       self->win = win;
  2178. !     self->so.type = mz_window_type;
  2179.   
  2180. +     MZ_GC_UNREG();
  2181.       return (Scheme_Object *)(self);
  2182.   }
  2183.   
  2184. ***************
  2185. *** 1660,1666 ****
  2186.   /*
  2187.    *===========================================================================
  2188.    *  6. Vim Buffer-related Manipulation Functions
  2189. -  *     Note that each buffer should have its own private namespace.
  2190.    *===========================================================================
  2191.    */
  2192.   
  2193. --- 1862,1867 ----
  2194. ***************
  2195. *** 1669,1682 ****
  2196.   mzscheme_open_buffer(void *data, int argc, Scheme_Object **argv)
  2197.   {
  2198.       Vim_Prim        *prim = (Vim_Prim *)data;
  2199. !     char        *fname;
  2200.       int            num = 0;
  2201.       Scheme_Object   *onum;
  2202.   
  2203.   #ifdef HAVE_SANDBOX
  2204.       sandbox_check();
  2205.   #endif
  2206. !     fname = SCHEME_STR_VAL(GUARANTEE_STRING(prim->name, 0));
  2207.       /* TODO make open existing file */
  2208.       num = buflist_add(fname, BLN_LISTED | BLN_CURBUF);
  2209.   
  2210. --- 1870,1883 ----
  2211.   mzscheme_open_buffer(void *data, int argc, Scheme_Object **argv)
  2212.   {
  2213.       Vim_Prim        *prim = (Vim_Prim *)data;
  2214. !     char_u        *fname;
  2215.       int            num = 0;
  2216.       Scheme_Object   *onum;
  2217.   
  2218.   #ifdef HAVE_SANDBOX
  2219.       sandbox_check();
  2220.   #endif
  2221. !     fname = (char_u *)SCHEME_STR_VAL(GUARANTEE_STRING(prim->name, 0));
  2222.       /* TODO make open existing file */
  2223.       num = buflist_add(fname, BLN_LISTED | BLN_CURBUF);
  2224.   
  2225. ***************
  2226. *** 1712,1718 ****
  2227.       buf_T    *buf;
  2228.       char_u    *fname;
  2229.   
  2230. !     fname = SCHEME_STR_VAL(GUARANTEE_STRING(prim->name, 0));
  2231.   
  2232.       for (buf = firstbuf; buf; buf = buf->b_next)
  2233.       if (buf->b_ffname == NULL || buf->b_sfname == NULL)
  2234. --- 1913,1919 ----
  2235.       buf_T    *buf;
  2236.       char_u    *fname;
  2237.   
  2238. !     fname = (char_u *)SCHEME_STR_VAL(GUARANTEE_STRING(prim->name, 0));
  2239.   
  2240.       for (buf = firstbuf; buf; buf = buf->b_next)
  2241.       if (buf->b_ffname == NULL || buf->b_sfname == NULL)
  2242. ***************
  2243. *** 1783,1789 ****
  2244.       Vim_Prim        *prim = (Vim_Prim *)data;
  2245.       vim_mz_buffer   *buf = get_buffer_arg(prim->name, 0, argc, argv);
  2246.   
  2247. !     return scheme_make_string(buf->buf->b_ffname);
  2248.   }
  2249.   
  2250.   /* (curr-buff) */
  2251. --- 1984,1990 ----
  2252.       Vim_Prim        *prim = (Vim_Prim *)data;
  2253.       vim_mz_buffer   *buf = get_buffer_arg(prim->name, 0, argc, argv);
  2254.   
  2255. !     return scheme_make_string((char *)buf->buf->b_ffname);
  2256.   }
  2257.   
  2258.   /* (curr-buff) */
  2259. ***************
  2260. *** 1796,1802 ****
  2261.       static Scheme_Object *
  2262.   buffer_new(buf_T *buf)
  2263.   {
  2264. !     vim_mz_buffer *self;
  2265.   
  2266.       /* We need to handle deletion of buffers underneath us.
  2267.        * If we add a "b_mzscheme_ref" field to the buf_T structure,
  2268. --- 1997,2007 ----
  2269.       static Scheme_Object *
  2270.   buffer_new(buf_T *buf)
  2271.   {
  2272. !     vim_mz_buffer *self = NULL;
  2273. !     MZ_GC_DECL_REG(1);
  2274. !     MZ_GC_VAR_IN_REG(0, self);
  2275. !     MZ_GC_REG();
  2276.   
  2277.       /* We need to handle deletion of buffers underneath us.
  2278.        * If we add a "b_mzscheme_ref" field to the buf_T structure,
  2279. ***************
  2280. *** 1806,1820 ****
  2281.       return buf->b_mzscheme_ref;
  2282.   
  2283.       self = scheme_malloc_fail_ok(scheme_malloc, sizeof(vim_mz_buffer));
  2284.       vim_memset(self, 0, sizeof(vim_mz_buffer));
  2285. !     scheme_dont_gc_ptr(self);    /* because buf isn't visible to GC */
  2286.       buf->b_mzscheme_ref = self;
  2287.       self->buf = buf;
  2288. !     self->tag = mz_buffer_type;
  2289. !     mzscheme_interface_init(self);    /* Set up namespace */
  2290.   
  2291.       return (Scheme_Object *)(self);
  2292.   }
  2293.   
  2294. --- 2011,2024 ----
  2295.       return buf->b_mzscheme_ref;
  2296.   
  2297.       self = scheme_malloc_fail_ok(scheme_malloc, sizeof(vim_mz_buffer));
  2298.       vim_memset(self, 0, sizeof(vim_mz_buffer));
  2299. !     scheme_dont_gc_ptr(self); /* because buf isn't visible to GC */
  2300. !     MZ_GC_CHECK();
  2301.       buf->b_mzscheme_ref = self;
  2302.       self->buf = buf;
  2303. !     self->so.type = mz_buffer_type;
  2304.   
  2305. +     MZ_GC_UNREG();
  2306.       return (Scheme_Object *)(self);
  2307.   }
  2308.   
  2309. ***************
  2310. *** 1845,1858 ****
  2311.       Vim_Prim        *prim = (Vim_Prim *)data;
  2312.       vim_mz_buffer   *buf;
  2313.       int            linenr;
  2314. !     char        *line;
  2315.   
  2316.       buf = get_buffer_arg(prim->name, 1, argc, argv);
  2317.       linenr = SCHEME_INT_VAL(GUARANTEE_INTEGER(prim->name, 0));
  2318.       line = ml_get_buf(buf->buf, (linenr_T)linenr, FALSE);
  2319.   
  2320.       raise_if_error();
  2321. !     return scheme_make_string(line);
  2322.   }
  2323.   
  2324.   
  2325. --- 2049,2062 ----
  2326.       Vim_Prim        *prim = (Vim_Prim *)data;
  2327.       vim_mz_buffer   *buf;
  2328.       int            linenr;
  2329. !     char_u        *line;
  2330.   
  2331.       buf = get_buffer_arg(prim->name, 1, argc, argv);
  2332.       linenr = SCHEME_INT_VAL(GUARANTEE_INTEGER(prim->name, 0));
  2333.       line = ml_get_buf(buf->buf, (linenr_T)linenr, FALSE);
  2334.   
  2335.       raise_if_error();
  2336. !     return scheme_make_string((char *)line);
  2337.   }
  2338.   
  2339.   
  2340. ***************
  2341. *** 1869,1875 ****
  2342.       Vim_Prim        *prim = (Vim_Prim *)data;
  2343.       vim_mz_buffer   *buf;
  2344.       int            i, hi, lo, n;
  2345. !     Scheme_Object   *list;
  2346.   
  2347.       buf = get_buffer_arg(prim->name, 2, argc, argv);
  2348.       list = scheme_null;
  2349. --- 2073,2083 ----
  2350.       Vim_Prim        *prim = (Vim_Prim *)data;
  2351.       vim_mz_buffer   *buf;
  2352.       int            i, hi, lo, n;
  2353. !     Scheme_Object   *list = NULL;
  2354. !     MZ_GC_DECL_REG(1);
  2355. !     MZ_GC_VAR_IN_REG(0, list);
  2356. !     MZ_GC_REG();
  2357.   
  2358.       buf = get_buffer_arg(prim->name, 2, argc, argv);
  2359.       list = scheme_null;
  2360. ***************
  2361. *** 1897,1904 ****
  2362.   
  2363.       /* Set the list item */
  2364.       list = scheme_make_pair(str, list);
  2365.       }
  2366.       return list;
  2367.   }
  2368.   
  2369. --- 2105,2113 ----
  2370.   
  2371.       /* Set the list item */
  2372.       list = scheme_make_pair(str, list);
  2373. +     MZ_GC_CHECK();
  2374.       }
  2375. !     MZ_GC_UNREG();
  2376.       return list;
  2377.   }
  2378.   
  2379. ***************
  2380. *** 1925,1935 ****
  2381.        */
  2382.       Vim_Prim        *prim = (Vim_Prim *)data;
  2383.       vim_mz_buffer   *buf;
  2384. !     Scheme_Object   *line;
  2385.       char        *save;
  2386. -     buf_T        *savebuf;
  2387.       int            n;
  2388.   
  2389.   #ifdef HAVE_SANDBOX
  2390.       sandbox_check();
  2391.   #endif
  2392. --- 2134,2147 ----
  2393.        */
  2394.       Vim_Prim        *prim = (Vim_Prim *)data;
  2395.       vim_mz_buffer   *buf;
  2396. !     Scheme_Object   *line = NULL;
  2397.       char        *save;
  2398.       int            n;
  2399.   
  2400. +     MZ_GC_DECL_REG(1);
  2401. +     MZ_GC_VAR_IN_REG(0, line);
  2402. +     MZ_GC_REG();
  2403.   #ifdef HAVE_SANDBOX
  2404.       sandbox_check();
  2405.   #endif
  2406. ***************
  2407. *** 1943,1949 ****
  2408.   
  2409.       if (SCHEME_FALSEP(line))
  2410.       {
  2411. !     savebuf = curbuf;
  2412.       curbuf = buf->buf;
  2413.   
  2414.       if (u_savedel((linenr_T)n, 1L) == FAIL)
  2415. --- 2155,2162 ----
  2416.   
  2417.       if (SCHEME_FALSEP(line))
  2418.       {
  2419. !     buf_T        *savebuf = curbuf;
  2420.       curbuf = buf->buf;
  2421.   
  2422.       if (u_savedel((linenr_T)n, 1L) == FAIL)
  2423. ***************
  2424. *** 1962,1994 ****
  2425.   
  2426.       curbuf = savebuf;
  2427.   
  2428.       raise_if_error();
  2429.       return scheme_void;
  2430.       }
  2431.   
  2432. !     /* Otherwise it's a line */
  2433. !     save = string_to_line(line);
  2434. !     savebuf = curbuf;
  2435.   
  2436. !     curbuf = buf->buf;
  2437.   
  2438. -     if (u_savesub((linenr_T)n) == FAIL)
  2439. -     {
  2440. -     curbuf = savebuf;
  2441. -     raise_vim_exn(_("cannot save undo information"));
  2442. -     }
  2443. -     else if (ml_replace((linenr_T)n, (char_u *)save, TRUE) == FAIL)
  2444. -     {
  2445.       curbuf = savebuf;
  2446. -     raise_vim_exn(_("cannot replace line"));
  2447. -     }
  2448. -     else
  2449. -     changed_bytes((linenr_T)n, 0);
  2450.   
  2451. !     curbuf = savebuf;
  2452.   
  2453. !     raise_if_error();
  2454. !     return scheme_void;
  2455.   }
  2456.   
  2457.   /*
  2458. --- 2175,2230 ----
  2459.   
  2460.       curbuf = savebuf;
  2461.   
  2462. +     MZ_GC_UNREG();
  2463.       raise_if_error();
  2464.       return scheme_void;
  2465.       }
  2466. +     else
  2467. +     {
  2468. +     /* Otherwise it's a line */
  2469. +     buf_T        *savebuf = curbuf;
  2470.   
  2471. !     save = string_to_line(line);
  2472.   
  2473. !     curbuf = buf->buf;
  2474. !     if (u_savesub((linenr_T)n) == FAIL)
  2475. !     {
  2476. !         curbuf = savebuf;
  2477. !         vim_free(save);
  2478. !         raise_vim_exn(_("cannot save undo information"));
  2479. !     }
  2480. !     else if (ml_replace((linenr_T)n, (char_u *)save, TRUE) == FAIL)
  2481. !     {
  2482. !         curbuf = savebuf;
  2483. !         vim_free(save);
  2484. !         raise_vim_exn(_("cannot replace line"));
  2485. !     }
  2486. !     else
  2487. !     {
  2488. !         vim_free(save);
  2489. !         changed_bytes((linenr_T)n, 0);
  2490. !     }
  2491.   
  2492.       curbuf = savebuf;
  2493.   
  2494. !     /* Check that the cursor is not beyond the end of the line now. */
  2495. !     if (buf->buf == curwin->w_buffer)
  2496. !         check_cursor_col();
  2497.   
  2498. !     MZ_GC_UNREG();
  2499. !     raise_if_error();
  2500. !     return scheme_void;
  2501. !     }
  2502. ! }
  2503. !     static void
  2504. ! free_array(char **array)
  2505. ! {
  2506. !     char **curr = array;
  2507. !     while (*curr != NULL)
  2508. !     vim_free(*curr++);
  2509. !     vim_free(array);
  2510.   }
  2511.   
  2512.   /*
  2513. ***************
  2514. *** 2013,2027 ****
  2515.        *      3. Anything else - this is an error.
  2516.        */
  2517.       Vim_Prim        *prim = (Vim_Prim *)data;
  2518. !     vim_mz_buffer   *buf;
  2519. !     Scheme_Object   *line_list;
  2520. !     Scheme_Object   *line;
  2521. !     Scheme_Object   *rest;
  2522. !     char        **array;
  2523. !     buf_T        *savebuf;
  2524.       int            i, old_len, new_len, hi, lo;
  2525.       long        extra;
  2526.   
  2527.   #ifdef HAVE_SANDBOX
  2528.       sandbox_check();
  2529.   #endif
  2530. --- 2249,2263 ----
  2531.        *      3. Anything else - this is an error.
  2532.        */
  2533.       Vim_Prim        *prim = (Vim_Prim *)data;
  2534. !     vim_mz_buffer   *buf = NULL;
  2535. !     Scheme_Object   *line_list = NULL;
  2536.       int            i, old_len, new_len, hi, lo;
  2537.       long        extra;
  2538.   
  2539. +     MZ_GC_DECL_REG(1);
  2540. +     MZ_GC_VAR_IN_REG(0, line_list);
  2541. +     MZ_GC_REG();
  2542.   #ifdef HAVE_SANDBOX
  2543.       sandbox_check();
  2544.   #endif
  2545. ***************
  2546. *** 2047,2053 ****
  2547.   
  2548.       if (SCHEME_FALSEP(line_list) || SCHEME_NULLP(line_list))
  2549.       {
  2550. !     savebuf = curbuf;
  2551.       curbuf = buf->buf;
  2552.   
  2553.       if (u_savedel((linenr_T)lo, (long)old_len) == FAIL)
  2554. --- 2283,2289 ----
  2555.   
  2556.       if (SCHEME_FALSEP(line_list) || SCHEME_NULLP(line_list))
  2557.       {
  2558. !     buf_T    *savebuf = curbuf;
  2559.       curbuf = buf->buf;
  2560.   
  2561.       if (u_savedel((linenr_T)lo, (long)old_len) == FAIL)
  2562. ***************
  2563. *** 2070,2167 ****
  2564.   
  2565.       curbuf = savebuf;
  2566.   
  2567.       raise_if_error();
  2568.       return scheme_void;
  2569.       }
  2570.   
  2571. !     /* List */
  2572. !     new_len = scheme_proper_list_length(line_list);
  2573. !     if (new_len < 0)    /* improper or cyclic list */
  2574. !     scheme_wrong_type(prim->name, "proper list",
  2575. !         2, argc, argv);
  2576.   
  2577. !     /* Using MzScheme allocator, so we don't need to free this and
  2578. !      * can safely keep pointers to GC collected strings
  2579. !      */
  2580. !     array = (char **)scheme_malloc_fail_ok(scheme_malloc,
  2581. !         (unsigned)(new_len * sizeof(char *)));
  2582.   
  2583. !     rest = line_list;
  2584. !     for (i = 0; i < new_len; ++i)
  2585. !     {
  2586. !     line = SCHEME_CAR(rest);
  2587. !     rest = SCHEME_CDR(rest);
  2588. !     if (!SCHEME_STRINGP(line))
  2589. !         scheme_wrong_type(prim->name, "string-list", 2, argc, argv);
  2590. !     array[i] = string_to_line(line);
  2591. !     }
  2592.   
  2593. !     savebuf = curbuf;
  2594. !     curbuf = buf->buf;
  2595.   
  2596. !     if (u_save((linenr_T)(lo-1), (linenr_T)hi) == FAIL)
  2597. !     {
  2598. !     curbuf = savebuf;
  2599. !     raise_vim_exn(_("cannot save undo information"));
  2600. !     }
  2601.   
  2602. !     /*
  2603. !      * If the size of the range is reducing (ie, new_len < old_len) we
  2604. !      * need to delete some old_len. We do this at the start, by
  2605. !      * repeatedly deleting line "lo".
  2606. !      */
  2607. !     for (i = 0; i < old_len - new_len; ++i)
  2608. !     {
  2609. !     if (ml_delete((linenr_T)lo, FALSE) == FAIL)
  2610. !     {
  2611. !         curbuf = savebuf;
  2612. !         raise_vim_exn(_("cannot delete line"));
  2613. !     }
  2614. !     extra--;
  2615. !     }
  2616.   
  2617. !     /*
  2618. !      * For as long as possible, replace the existing old_len with the
  2619. !      * new old_len. This is a more efficient operation, as it requires
  2620. !      * less memory allocation and freeing.
  2621. !      */
  2622. !     for (i = 0; i < old_len && i < new_len; i++)
  2623. !     if (ml_replace((linenr_T)(lo+i), (char_u *)array[i], TRUE) == FAIL)
  2624. !     {
  2625. !         curbuf = savebuf;
  2626. !         raise_vim_exn(_("cannot replace line"));
  2627. !     }
  2628.   
  2629. !     /*
  2630. !      * Now we may need to insert the remaining new_len.  We don't need to
  2631. !      * free the string passed back because MzScheme has control of that
  2632. !      * memory.
  2633. !      */
  2634. !     while (i < new_len)
  2635. !     {
  2636. !     if (ml_append((linenr_T)(lo + i - 1),
  2637. !         (char_u *)array[i], 0, FALSE) == FAIL)
  2638. !     {
  2639. !         curbuf = savebuf;
  2640. !         raise_vim_exn(_("cannot insert line"));
  2641.       }
  2642. -     ++i;
  2643. -     ++extra;
  2644. -     }
  2645.   
  2646. !     /*
  2647. !      * Adjust marks. Invalidate any which lie in the
  2648. !      * changed range, and move any in the remainder of the buffer.
  2649. !      */
  2650. !     mark_adjust((linenr_T)lo, (linenr_T)(hi - 1), (long)MAXLNUM, (long)extra);
  2651. !     changed_lines((linenr_T)lo, 0, (linenr_T)hi, (long)extra);
  2652.   
  2653. !     if (buf->buf == curwin->w_buffer)
  2654. !     mz_fix_cursor(lo, hi, extra);
  2655. !     curbuf = savebuf;
  2656.   
  2657. !     raise_if_error();
  2658. !     return scheme_void;
  2659.   }
  2660.   
  2661.   /*
  2662. --- 2306,2426 ----
  2663.   
  2664.       curbuf = savebuf;
  2665.   
  2666. +     MZ_GC_UNREG();
  2667.       raise_if_error();
  2668.       return scheme_void;
  2669.       }
  2670. +     else
  2671. +     {
  2672. +     buf_T    *savebuf = curbuf;
  2673.   
  2674. !     /* List */
  2675. !     new_len = scheme_proper_list_length(line_list);
  2676. !     MZ_GC_CHECK();
  2677. !     if (new_len < 0)    /* improper or cyclic list */
  2678. !         scheme_wrong_type(prim->name, "proper list",
  2679. !             2, argc, argv);
  2680. !     else
  2681. !     {
  2682. !         char        **array = NULL;
  2683. !         Scheme_Object   *line = NULL;
  2684. !         Scheme_Object   *rest = NULL;
  2685. !         MZ_GC_DECL_REG(2);
  2686. !         MZ_GC_VAR_IN_REG(0, line);
  2687. !         MZ_GC_VAR_IN_REG(1, rest);
  2688. !         MZ_GC_REG();
  2689.   
  2690. !         array = (char **)alloc(new_len * sizeof(char *));
  2691. !         vim_memset(array, 0, new_len * sizeof(char *));
  2692.   
  2693. !         rest = line_list;
  2694. !         for (i = 0; i < new_len; ++i)
  2695. !         {
  2696. !         line = SCHEME_CAR(rest);
  2697. !         rest = SCHEME_CDR(rest);
  2698. !         if (!SCHEME_STRINGP(line))
  2699. !         {
  2700. !             free_array(array);
  2701. !             scheme_wrong_type(prim->name, "string-list", 2, argc, argv);
  2702. !         }
  2703. !         array[i] = string_to_line(line);
  2704. !         }
  2705.   
  2706. !         curbuf = buf->buf;
  2707.   
  2708. !         if (u_save((linenr_T)(lo-1), (linenr_T)hi) == FAIL)
  2709. !         {
  2710. !         curbuf = savebuf;
  2711. !         free_array(array);
  2712. !         raise_vim_exn(_("cannot save undo information"));
  2713. !         }
  2714.   
  2715. !         /*
  2716. !          * If the size of the range is reducing (ie, new_len < old_len) we
  2717. !          * need to delete some old_len. We do this at the start, by
  2718. !          * repeatedly deleting line "lo".
  2719. !          */
  2720. !         for (i = 0; i < old_len - new_len; ++i)
  2721. !         {
  2722. !         if (ml_delete((linenr_T)lo, FALSE) == FAIL)
  2723. !         {
  2724. !             curbuf = savebuf;
  2725. !             free_array(array);
  2726. !             raise_vim_exn(_("cannot delete line"));
  2727. !         }
  2728. !         extra--;
  2729. !         }
  2730.   
  2731. !         /*
  2732. !          * For as long as possible, replace the existing old_len with the
  2733. !          * new old_len. This is a more efficient operation, as it requires
  2734. !          * less memory allocation and freeing.
  2735. !          */
  2736. !         for (i = 0; i < old_len && i < new_len; i++)
  2737. !         if (ml_replace((linenr_T)(lo+i), (char_u *)array[i], TRUE) == FAIL)
  2738. !         {
  2739. !             curbuf = savebuf;
  2740. !             free_array(array);
  2741. !             raise_vim_exn(_("cannot replace line"));
  2742. !         }
  2743.   
  2744. !         /*
  2745. !          * Now we may need to insert the remaining new_len.  We don't need to
  2746. !          * free the string passed back because MzScheme has control of that
  2747. !          * memory.
  2748. !          */
  2749. !         while (i < new_len)
  2750. !         {
  2751. !         if (ml_append((linenr_T)(lo + i - 1),
  2752. !                 (char_u *)array[i], 0, FALSE) == FAIL)
  2753. !         {
  2754. !             curbuf = savebuf;
  2755. !             free_array(array);
  2756. !             raise_vim_exn(_("cannot insert line"));
  2757. !         }
  2758. !         ++i;
  2759. !         ++extra;
  2760. !         }
  2761. !         MZ_GC_UNREG();
  2762. !         free_array(array);
  2763.       }
  2764.   
  2765. !     /*
  2766. !      * Adjust marks. Invalidate any which lie in the
  2767. !      * changed range, and move any in the remainder of the buffer.
  2768. !      */
  2769. !     mark_adjust((linenr_T)lo, (linenr_T)(hi - 1), (long)MAXLNUM, (long)extra);
  2770. !     changed_lines((linenr_T)lo, 0, (linenr_T)hi, (long)extra);
  2771.   
  2772. !     if (buf->buf == curwin->w_buffer)
  2773. !         mz_fix_cursor(lo, hi, extra);
  2774. !     curbuf = savebuf;
  2775.   
  2776. !     MZ_GC_UNREG();
  2777. !     raise_if_error();
  2778. !     return scheme_void;
  2779. !     }
  2780.   }
  2781.   
  2782.   /*
  2783. ***************
  2784. *** 2179,2193 ****
  2785.   insert_buffer_line_list(void *data, int argc, Scheme_Object **argv)
  2786.   {
  2787.       Vim_Prim        *prim = (Vim_Prim *)data;
  2788. !     vim_mz_buffer   *buf;
  2789. !     Scheme_Object   *list;
  2790. !     Scheme_Object   *line;
  2791. !     Scheme_Object   *rest;
  2792. !     char        **array;
  2793. !     char        *str;
  2794. !     buf_T        *savebuf;
  2795.       int            i, n, size;
  2796.   
  2797.   #ifdef HAVE_SANDBOX
  2798.       sandbox_check();
  2799.   #endif
  2800. --- 2438,2452 ----
  2801.   insert_buffer_line_list(void *data, int argc, Scheme_Object **argv)
  2802.   {
  2803.       Vim_Prim        *prim = (Vim_Prim *)data;
  2804. !     vim_mz_buffer   *buf = NULL;
  2805. !     Scheme_Object   *list = NULL;
  2806. !     char        *str = NULL;
  2807.       int            i, n, size;
  2808.   
  2809. +     MZ_GC_DECL_REG(1);
  2810. +     MZ_GC_VAR_IN_REG(0, list);
  2811. +     MZ_GC_REG();
  2812.   #ifdef HAVE_SANDBOX
  2813.       sandbox_check();
  2814.   #endif
  2815. ***************
  2816. *** 2206,2294 ****
  2817.       check_line_range(n, buf->buf);
  2818.       if (SCHEME_STRINGP(list))
  2819.       {
  2820. !     str = string_to_line(list);
  2821.   
  2822. !     savebuf = curbuf;
  2823.       curbuf = buf->buf;
  2824.   
  2825.       if (u_save((linenr_T)n, (linenr_T)(n+1)) == FAIL)
  2826.       {
  2827.           curbuf = savebuf;
  2828.           raise_vim_exn(_("cannot save undo information"));
  2829.       }
  2830.       else if (ml_append((linenr_T)n, (char_u *)str, 0, FALSE) == FAIL)
  2831.       {
  2832.           curbuf = savebuf;
  2833.           raise_vim_exn(_("cannot insert line"));
  2834.       }
  2835.       else
  2836.           appended_lines_mark((linenr_T)n, 1L);
  2837.   
  2838.       curbuf = savebuf;
  2839.       update_screen(VALID);
  2840.   
  2841.       raise_if_error();
  2842.       return scheme_void;
  2843.       }
  2844.   
  2845.       /* List */
  2846.       size = scheme_proper_list_length(list);
  2847.       if (size < 0)    /* improper or cyclic list */
  2848.       scheme_wrong_type(prim->name, "proper list",
  2849.           2, argc, argv);
  2850. !     /* Using MzScheme allocator, so we don't need to free this and
  2851. !      * can safely keep pointers to GC collected strings
  2852. !      */
  2853. !     array = (char **)scheme_malloc_fail_ok(
  2854. !         scheme_malloc, (unsigned)(size * sizeof(char *)));
  2855. !     rest = list;
  2856. !     for (i = 0; i < size; ++i)
  2857.       {
  2858. !     line = SCHEME_CAR(rest);
  2859. !     rest = SCHEME_CDR(rest);
  2860. !     array[i] = string_to_line(line);
  2861. !     }
  2862.   
  2863. !     savebuf = curbuf;
  2864. !     curbuf = buf->buf;
  2865.   
  2866. !     if (u_save((linenr_T)n, (linenr_T)(n + 1)) == FAIL)
  2867. !     {
  2868. !     curbuf = savebuf;
  2869. !     raise_vim_exn(_("cannot save undo information"));
  2870. !     }
  2871. !     else
  2872. !     {
  2873.       for (i = 0; i < size; ++i)
  2874. !         if (ml_append((linenr_T)(n + i), (char_u *)array[i],
  2875. !             0, FALSE) == FAIL)
  2876. !         {
  2877. !         curbuf = savebuf;
  2878. !         raise_vim_exn(_("cannot insert line"));
  2879. !         }
  2880.   
  2881. !     if (i > 0)
  2882. !         appended_lines_mark((linenr_T)n, (long)i);
  2883. !     }
  2884.   
  2885. !     curbuf = savebuf;
  2886. !     update_screen(VALID);
  2887.   
  2888.       raise_if_error();
  2889.       return scheme_void;
  2890.   }
  2891.   
  2892. - /* (get-buff-namespace [buffer]) */
  2893. -     static Scheme_Object *
  2894. - get_buffer_namespace(void *data, int argc, Scheme_Object **argv)
  2895. - {
  2896. -     Vim_Prim    *prim = (Vim_Prim *)data;
  2897. -     return (Scheme_Object *)get_buffer_arg(prim->name, 0, argc, argv)->env;
  2898. - }
  2899.   /*
  2900.    * Predicates
  2901.    */
  2902. --- 2465,2563 ----
  2903.       check_line_range(n, buf->buf);
  2904.       if (SCHEME_STRINGP(list))
  2905.       {
  2906. !     buf_T        *savebuf = curbuf;
  2907.   
  2908. !     str = string_to_line(list);
  2909.       curbuf = buf->buf;
  2910.   
  2911.       if (u_save((linenr_T)n, (linenr_T)(n+1)) == FAIL)
  2912.       {
  2913.           curbuf = savebuf;
  2914. +         vim_free(str);
  2915.           raise_vim_exn(_("cannot save undo information"));
  2916.       }
  2917.       else if (ml_append((linenr_T)n, (char_u *)str, 0, FALSE) == FAIL)
  2918.       {
  2919.           curbuf = savebuf;
  2920. +         vim_free(str);
  2921.           raise_vim_exn(_("cannot insert line"));
  2922.       }
  2923.       else
  2924. +     {
  2925. +         vim_free(str);
  2926.           appended_lines_mark((linenr_T)n, 1L);
  2927. +     }
  2928.   
  2929.       curbuf = savebuf;
  2930.       update_screen(VALID);
  2931.   
  2932. +     MZ_GC_UNREG();
  2933.       raise_if_error();
  2934.       return scheme_void;
  2935.       }
  2936.   
  2937.       /* List */
  2938.       size = scheme_proper_list_length(list);
  2939. +     MZ_GC_CHECK();
  2940.       if (size < 0)    /* improper or cyclic list */
  2941.       scheme_wrong_type(prim->name, "proper list",
  2942.           2, argc, argv);
  2943. !     else
  2944.       {
  2945. !     Scheme_Object   *line = NULL;
  2946. !     Scheme_Object   *rest = NULL;
  2947. !     char        **array;
  2948. !     buf_T        *savebuf = curbuf;
  2949. !     MZ_GC_DECL_REG(2);
  2950. !     MZ_GC_VAR_IN_REG(0, line);
  2951. !     MZ_GC_VAR_IN_REG(1, rest);
  2952. !     MZ_GC_REG();
  2953.   
  2954. !     array = (char **)alloc(size * sizeof(char *));
  2955. !     vim_memset(array, 0, size * sizeof(char *));
  2956.   
  2957. !     rest = list;
  2958.       for (i = 0; i < size; ++i)
  2959. !     {
  2960. !         line = SCHEME_CAR(rest);
  2961. !         rest = SCHEME_CDR(rest);
  2962. !         array[i] = string_to_line(line);
  2963. !     }
  2964.   
  2965. !     curbuf = buf->buf;
  2966.   
  2967. !     if (u_save((linenr_T)n, (linenr_T)(n + 1)) == FAIL)
  2968. !     {
  2969. !         curbuf = savebuf;
  2970. !         free_array(array);
  2971. !         raise_vim_exn(_("cannot save undo information"));
  2972. !     }
  2973. !     else
  2974. !     {
  2975. !         for (i = 0; i < size; ++i)
  2976. !         if (ml_append((linenr_T)(n + i), (char_u *)array[i],
  2977. !                 0, FALSE) == FAIL)
  2978. !         {
  2979. !             curbuf = savebuf;
  2980. !             free_array(array);
  2981. !             raise_vim_exn(_("cannot insert line"));
  2982. !         }
  2983. !         if (i > 0)
  2984. !         appended_lines_mark((linenr_T)n, (long)i);
  2985. !     }
  2986. !     free_array(array);
  2987. !     MZ_GC_UNREG();
  2988. !     curbuf = savebuf;
  2989. !     update_screen(VALID);
  2990. !     }
  2991.   
  2992. +     MZ_GC_UNREG();
  2993.       raise_if_error();
  2994.       return scheme_void;
  2995.   }
  2996.   
  2997.   /*
  2998.    * Predicates
  2999.    */
  3000. ***************
  3001. *** 2343,2383 ****
  3002.   /*
  3003.    * Convert an MzScheme string into a Vim line.
  3004.    *
  3005. !  * The result is in allocated memory. All internal nulls are replaced by
  3006. !  * newline characters. It is an error for the string to contain newline
  3007. !  * characters.
  3008.    *
  3009.    */
  3010.       static char *
  3011.   string_to_line(Scheme_Object *obj)
  3012.   {
  3013. !     char    *str;
  3014.       long    len;
  3015.       int        i;
  3016.   
  3017. !     str = scheme_display_to_string(obj, &len);
  3018.   
  3019.       /* Error checking: String must not contain newlines, as we
  3020.        * are replacing a single line, and we must replace it with
  3021.        * a single line.
  3022.        */
  3023. !     if (memchr(str, '\n', len))
  3024.       scheme_signal_error(_("string cannot contain newlines"));
  3025.   
  3026.       /* Create a copy of the string, with internal nulls replaced by
  3027.        * newline characters, as is the vim convention.
  3028.        */
  3029.       for (i = 0; i < len; ++i)
  3030.       {
  3031. !     if (str[i] == '\0')
  3032. !         str[i] = '\n';
  3033.       }
  3034.   
  3035. !     str[i] = '\0';
  3036.   
  3037. !     return str;
  3038.   }
  3039.   
  3040.   /*
  3041.    * Check to see whether a Vim error has been reported, or a keyboard
  3042.    * interrupt (from vim --> got_int) has been detected.
  3043. --- 2612,2784 ----
  3044.   /*
  3045.    * Convert an MzScheme string into a Vim line.
  3046.    *
  3047. !  * All internal nulls are replaced by newline characters.
  3048. !  * It is an error for the string to contain newline characters.
  3049.    *
  3050. +  * Returns pointer to Vim allocated memory
  3051.    */
  3052.       static char *
  3053.   string_to_line(Scheme_Object *obj)
  3054.   {
  3055. !     char    *scheme_str = NULL;
  3056. !     char    *vim_str = NULL;
  3057.       long    len;
  3058.       int        i;
  3059.   
  3060. !     scheme_str = scheme_display_to_string(obj, &len);
  3061.   
  3062.       /* Error checking: String must not contain newlines, as we
  3063.        * are replacing a single line, and we must replace it with
  3064.        * a single line.
  3065.        */
  3066. !     if (memchr(scheme_str, '\n', len))
  3067.       scheme_signal_error(_("string cannot contain newlines"));
  3068.   
  3069. +     vim_str = (char *)alloc(len + 1);
  3070.       /* Create a copy of the string, with internal nulls replaced by
  3071.        * newline characters, as is the vim convention.
  3072.        */
  3073.       for (i = 0; i < len; ++i)
  3074.       {
  3075. !     if (scheme_str[i] == '\0')
  3076. !         vim_str[i] = '\n';
  3077. !     else
  3078. !         vim_str[i] = scheme_str[i];
  3079.       }
  3080.   
  3081. !     vim_str[i] = '\0';
  3082.   
  3083. !     MZ_GC_CHECK();
  3084. !     return vim_str;
  3085.   }
  3086.   
  3087. + #ifdef FEAT_EVAL
  3088. + /*
  3089. +  * Convert Vim value into MzScheme, adopted from if_python.c
  3090. +  */
  3091. +     static Scheme_Object *
  3092. + vim_to_mzscheme(typval_T *vim_value, int depth, Scheme_Hash_Table *visited)
  3093. + {
  3094. +     Scheme_Object   *result = NULL;
  3095. +     int            new_value = TRUE;
  3096. +     MZ_GC_DECL_REG(1);
  3097. +     MZ_GC_VAR_IN_REG(0, result);
  3098. +     MZ_GC_REG();
  3099. +     /* Avoid infinite recursion */
  3100. +     if (depth > 100)
  3101. +     {
  3102. +     MZ_GC_UNREG();
  3103. +     return scheme_void;
  3104. +     }
  3105. +     /* Check if we run into a recursive loop.  The item must be in visited
  3106. +      * then and we can use it again.
  3107. +      */
  3108. +     result = scheme_hash_get(visited, (Scheme_Object *)vim_value);
  3109. +     MZ_GC_CHECK();
  3110. +     if (result != NULL) /* found, do nothing */
  3111. +     new_value = FALSE;
  3112. +     else if (vim_value->v_type == VAR_STRING)
  3113. +     {
  3114. +     result = scheme_make_string((char *)vim_value->vval.v_string);
  3115. +     MZ_GC_CHECK();
  3116. +     }
  3117. +     else if (vim_value->v_type == VAR_NUMBER)
  3118. +     {
  3119. +     result = scheme_make_integer((long)vim_value->vval.v_number);
  3120. +     MZ_GC_CHECK();
  3121. +     }
  3122. + # ifdef FEAT_FLOAT
  3123. +     else if (vim_value->v_type == VAR_FLOAT)
  3124. +     {
  3125. +     result = scheme_make_double((double)vim_value->vval.v_float);
  3126. +     MZ_GC_CHECK();
  3127. +     }
  3128. + # endif
  3129. +     else if (vim_value->v_type == VAR_LIST)
  3130. +     {
  3131. +     list_T        *list = vim_value->vval.v_list;
  3132. +     listitem_T    *curr;
  3133. +     if (list == NULL || list->lv_first == NULL)
  3134. +         result = scheme_null;
  3135. +     else
  3136. +     {
  3137. +         Scheme_Object   *obj = NULL;
  3138. +         MZ_GC_DECL_REG(1);
  3139. +         MZ_GC_VAR_IN_REG(0, obj);
  3140. +         MZ_GC_REG();
  3141. +         curr = list->lv_last;
  3142. +         obj = vim_to_mzscheme(&curr->li_tv, depth + 1, visited);
  3143. +         result = scheme_make_pair(obj, scheme_null);
  3144. +         MZ_GC_CHECK();
  3145. +         while (curr != list->lv_first)
  3146. +         {
  3147. +         curr = curr->li_prev;
  3148. +         obj = vim_to_mzscheme(&curr->li_tv, depth + 1, visited);
  3149. +         result = scheme_make_pair(obj, result);
  3150. +         MZ_GC_CHECK();
  3151. +         }
  3152. +     }
  3153. +     MZ_GC_UNREG();
  3154. +     }
  3155. +     else if (vim_value->v_type == VAR_DICT)
  3156. +     {
  3157. +     Scheme_Object      *key = NULL;
  3158. +     Scheme_Object      *obj = NULL;
  3159. +     MZ_GC_DECL_REG(2);
  3160. +     MZ_GC_VAR_IN_REG(0, key);
  3161. +     MZ_GC_VAR_IN_REG(1, obj);
  3162. +     MZ_GC_REG();
  3163. +     result = (Scheme_Object *)scheme_make_hash_table(SCHEME_hash_ptr);
  3164. +     MZ_GC_CHECK();
  3165. +     if (vim_value->vval.v_dict != NULL)
  3166. +     {
  3167. +         hashtab_T    *ht = &vim_value->vval.v_dict->dv_hashtab;
  3168. +         long_u    todo = ht->ht_used;
  3169. +         hashitem_T    *hi;
  3170. +         dictitem_T    *di;
  3171. +         for (hi = ht->ht_array; todo > 0; ++hi)
  3172. +         {
  3173. +         if (!HASHITEM_EMPTY(hi))
  3174. +         {
  3175. +             --todo;
  3176. +             di = dict_lookup(hi);
  3177. +             obj = vim_to_mzscheme(&di->di_tv, depth + 1, visited);
  3178. +             key = scheme_make_string((char *)hi->hi_key);
  3179. +             MZ_GC_CHECK();
  3180. +             scheme_hash_set((Scheme_Hash_Table *)result, key, obj);
  3181. +             MZ_GC_CHECK();
  3182. +         }
  3183. +         }
  3184. +     }
  3185. +     MZ_GC_UNREG();
  3186. +     }
  3187. +     else
  3188. +     {
  3189. +     result = scheme_void;
  3190. +     new_value = FALSE;
  3191. +     }
  3192. +     if (new_value)
  3193. +     {
  3194. +     scheme_hash_set(visited, (Scheme_Object *)vim_value, result);
  3195. +     MZ_GC_CHECK();
  3196. +     }
  3197. +     MZ_GC_UNREG();
  3198. +     return result;
  3199. + }
  3200. + #endif
  3201.   /*
  3202.    * Check to see whether a Vim error has been reported, or a keyboard
  3203.    * interrupt (from vim --> got_int) has been detected.
  3204. ***************
  3205. *** 2392,2441 ****
  3206.    * register Scheme exn:vim
  3207.    */
  3208.       static void
  3209. ! register_vim_exn(Scheme_Env *env)
  3210.   {
  3211. !     Scheme_Object   *exn_name = scheme_intern_symbol("exn:vim");
  3212.   
  3213.       if (vim_exn == NULL)
  3214.       vim_exn = scheme_make_struct_type(exn_name,
  3215. !         scheme_builtin_value("struct:exn"), NULL, 0, 0, NULL, NULL
  3216.   #if MZSCHEME_VERSION_MAJOR >= 299
  3217.           , NULL
  3218.   #endif
  3219.           );
  3220.   
  3221. -     if (vim_exn_values == NULL)
  3222. -     {
  3223. -     int    nc = 0;
  3224.   
  3225. !     Scheme_Object   **exn_names = scheme_make_struct_names(
  3226. !         exn_name, scheme_null, 0, &nc);
  3227. !     Scheme_Object   **exn_values = scheme_make_struct_values(
  3228. !         vim_exn, exn_names, nc, 0);
  3229. !     vim_exn_names = scheme_make_vector(nc, scheme_false);
  3230. !     vim_exn_values = scheme_make_vector(nc, scheme_false);
  3231. !     /* remember names and values */
  3232. !     mch_memmove(SCHEME_VEC_ELS(vim_exn_names), exn_names,
  3233. !         nc * sizeof(Scheme_Object *));
  3234. !     mch_memmove(SCHEME_VEC_ELS(vim_exn_values), exn_values,
  3235. !         nc * sizeof(Scheme_Object *));
  3236.       }
  3237. !     add_vim_exn(env);
  3238. ! }
  3239. ! /*
  3240. !  * Add stuff of exn:vim to env
  3241. !  */
  3242. !     static void
  3243. ! add_vim_exn(Scheme_Env *env)
  3244. ! {
  3245. !     int i;
  3246. !     for (i = 0; i < SCHEME_VEC_SIZE(vim_exn_values); i++)
  3247. !     scheme_add_global_symbol(SCHEME_VEC_ELS(vim_exn_names)[i],
  3248. !         SCHEME_VEC_ELS(vim_exn_values)[i], env);
  3249.   }
  3250.   
  3251.   /*
  3252. --- 2793,2851 ----
  3253.    * register Scheme exn:vim
  3254.    */
  3255.       static void
  3256. ! register_vim_exn(void)
  3257.   {
  3258. !     int    nc = 0;
  3259. !     int i;
  3260. !     Scheme_Object   *struct_exn = NULL;
  3261. !     Scheme_Object   *exn_name = NULL;
  3262. !     MZ_GC_DECL_REG(2);
  3263. !     MZ_GC_VAR_IN_REG(0, struct_exn);
  3264. !     MZ_GC_VAR_IN_REG(1, exn_name);
  3265. !     MZ_GC_REG();
  3266. !     exn_name = scheme_intern_symbol("exn:vim");
  3267. !     MZ_GC_CHECK();
  3268. !     struct_exn = scheme_builtin_value("struct:exn");
  3269. !     MZ_GC_CHECK();
  3270.   
  3271.       if (vim_exn == NULL)
  3272.       vim_exn = scheme_make_struct_type(exn_name,
  3273. !         struct_exn, NULL, 0, 0, NULL, NULL
  3274.   #if MZSCHEME_VERSION_MAJOR >= 299
  3275.           , NULL
  3276.   #endif
  3277.           );
  3278.   
  3279.   
  3280. !     {
  3281. !     Scheme_Object   **tmp = NULL;
  3282. !     Scheme_Object   *exn_names[5] = {NULL, NULL, NULL, NULL, NULL};
  3283. !     Scheme_Object   *exn_values[5] = {NULL, NULL, NULL, NULL, NULL};
  3284. !     MZ_GC_DECL_REG(6);
  3285. !     MZ_GC_ARRAY_VAR_IN_REG(0, exn_names, 5);
  3286. !     MZ_GC_ARRAY_VAR_IN_REG(3, exn_values, 5);
  3287. !     MZ_GC_REG();
  3288. !     tmp = scheme_make_struct_names(exn_name, scheme_null, 0, &nc);
  3289. !     assert(nc <= 5);
  3290. !     mch_memmove(exn_names, tmp, nc * sizeof(Scheme_Object *));
  3291. !     MZ_GC_CHECK();
  3292. !     tmp = scheme_make_struct_values(vim_exn, exn_names, nc, 0);
  3293. !     mch_memmove(exn_values, tmp, nc * sizeof(Scheme_Object *));
  3294. !     MZ_GC_CHECK();
  3295. !     for (i = 0; i < nc; i++)
  3296. !     {
  3297. !         scheme_add_global_symbol(exn_names[i],
  3298. !             exn_values[i], environment);
  3299. !         MZ_GC_CHECK();
  3300. !     }
  3301. !     MZ_GC_UNREG();
  3302.       }
  3303. !     MZ_GC_UNREG();
  3304.   }
  3305.   
  3306.   /*
  3307. ***************
  3308. *** 2444,2469 ****
  3309.       void
  3310.   raise_vim_exn(const char *add_info)
  3311.   {
  3312. !     Scheme_Object   *argv[2];
  3313. !     char_u        *fmt = _("Vim error: ~a");
  3314.   
  3315.       if (add_info != NULL)
  3316.       {
  3317. !     Scheme_Object   *info = scheme_make_string(add_info);
  3318. !     argv[0] = scheme_byte_string_to_char_string(scheme_make_string(
  3319. !         scheme_format(fmt, strlen(fmt), 1, &info, NULL)));
  3320.       SCHEME_SET_IMMUTABLE(argv[0]);
  3321.       }
  3322.       else
  3323.       argv[0] = scheme_make_string(_("Vim error"));
  3324.   
  3325.   #if MZSCHEME_VERSION_MAJOR < 360
  3326.       argv[1] = scheme_current_continuation_marks();
  3327.   #else
  3328.       argv[1] = scheme_current_continuation_marks(NULL);
  3329.   #endif
  3330.   
  3331. !     scheme_raise(scheme_make_struct_instance(vim_exn, 2, argv));
  3332.   }
  3333.   
  3334.       void
  3335. --- 2854,2907 ----
  3336.       void
  3337.   raise_vim_exn(const char *add_info)
  3338.   {
  3339. !     char        *fmt = _("Vim error: ~a");
  3340. !     Scheme_Object   *argv[2] = {NULL, NULL};
  3341. !     Scheme_Object   *exn = NULL;
  3342. !     MZ_GC_DECL_REG(4);
  3343. !     MZ_GC_ARRAY_VAR_IN_REG(0, argv, 2);
  3344. !     MZ_GC_VAR_IN_REG(3, exn);
  3345. !     MZ_GC_REG();
  3346.   
  3347.       if (add_info != NULL)
  3348.       {
  3349. !     char        *c_string = NULL;
  3350. !     Scheme_Object    *byte_string = NULL;
  3351. !     Scheme_Object   *info = NULL;
  3352. !     MZ_GC_DECL_REG(3);
  3353. !     MZ_GC_VAR_IN_REG(0, c_string);
  3354. !     MZ_GC_VAR_IN_REG(1, byte_string);
  3355. !     MZ_GC_VAR_IN_REG(2, info);
  3356. !     MZ_GC_REG();
  3357. !     info = scheme_make_string(add_info);
  3358. !     MZ_GC_CHECK();
  3359. !     c_string = scheme_format(fmt, STRLEN(fmt), 1, &info, NULL);
  3360. !     MZ_GC_CHECK();
  3361. !     byte_string = scheme_make_string(c_string);
  3362. !     MZ_GC_CHECK();
  3363. !     argv[0] = scheme_byte_string_to_char_string(byte_string);
  3364. !     MZ_GC_CHECK();
  3365.       SCHEME_SET_IMMUTABLE(argv[0]);
  3366. +     MZ_GC_UNREG();
  3367.       }
  3368.       else
  3369.       argv[0] = scheme_make_string(_("Vim error"));
  3370. +     MZ_GC_CHECK();
  3371.   
  3372.   #if MZSCHEME_VERSION_MAJOR < 360
  3373.       argv[1] = scheme_current_continuation_marks();
  3374. +     MZ_GC_CHECK();
  3375.   #else
  3376.       argv[1] = scheme_current_continuation_marks(NULL);
  3377. +     MZ_GC_CHECK();
  3378.   #endif
  3379.   
  3380. !     exn = scheme_make_struct_instance(vim_exn, 2, argv);
  3381. !     MZ_GC_CHECK();
  3382. !     scheme_raise(exn);
  3383. !     MZ_GC_UNREG();
  3384.   }
  3385.   
  3386.       void
  3387. ***************
  3388. *** 2570,2575 ****
  3389. --- 3008,3015 ----
  3390.           curwin->w_cursor.lnum = lo;
  3391.           check_cursor();
  3392.       }
  3393. +     else
  3394. +         check_cursor_col();
  3395.       changed_cline_bef_curs();
  3396.       }
  3397.       invalidate_botline();
  3398. ***************
  3399. *** 2595,2601 ****
  3400.       {mzscheme_open_buffer, "open-buff", 1, 1},
  3401.       {get_buffer_by_name, "get-buff-by-name", 1, 1},
  3402.       {get_buffer_by_num, "get-buff-by-num", 1, 1},
  3403. -     {get_buffer_namespace, "get-buff-namespace", 0, 1},
  3404.       /*
  3405.        * Window-related commands
  3406.        */
  3407. --- 3035,3040 ----
  3408. ***************
  3409. *** 2653,2675 ****
  3410.   }
  3411.   
  3412.       static void
  3413. ! make_modules(Scheme_Env *env)
  3414.   {
  3415. !     int        i;
  3416. !     Scheme_Env    *mod;
  3417. !     mod = scheme_primitive_module(scheme_intern_symbol("vimext"), env);
  3418.       /* all prims made closed so they can access their own names */
  3419. !     for (i = 0; i < sizeof(prims)/sizeof(prims[0]); i++)
  3420.       {
  3421.       Vim_Prim *prim = prims + i;
  3422. !     scheme_add_global(prim->name,
  3423. !         scheme_make_closed_prim_w_arity(prim->prim, prim, prim->name,
  3424. !             prim->mina, prim->maxa),
  3425. !         mod);
  3426.       }
  3427. -     scheme_add_global("global-namespace", (Scheme_Object *)environment, mod);
  3428.       scheme_finish_primitive_module(mod);
  3429.   }
  3430.   
  3431.   #ifdef HAVE_SANDBOX
  3432. --- 3092,3126 ----
  3433.   }
  3434.   
  3435.       static void
  3436. ! make_modules()
  3437.   {
  3438. !     int            i;
  3439. !     Scheme_Env        *mod = NULL;
  3440. !     Scheme_Object   *vimext_symbol = NULL;
  3441. !     Scheme_Object   *closed_prim = NULL;
  3442. !     MZ_GC_DECL_REG(3);
  3443. !     MZ_GC_VAR_IN_REG(0, mod);
  3444. !     MZ_GC_VAR_IN_REG(1, vimext_symbol);
  3445. !     MZ_GC_VAR_IN_REG(2, closed_prim);
  3446. !     MZ_GC_REG();
  3447. !     vimext_symbol = scheme_intern_symbol("vimext");
  3448. !     MZ_GC_CHECK();
  3449. !     mod = scheme_primitive_module(vimext_symbol, environment);
  3450. !     MZ_GC_CHECK();
  3451.       /* all prims made closed so they can access their own names */
  3452. !     for (i = 0; i < (int)(sizeof(prims)/sizeof(prims[0])); i++)
  3453.       {
  3454.       Vim_Prim *prim = prims + i;
  3455. !     closed_prim = scheme_make_closed_prim_w_arity(prim->prim, prim, prim->name,
  3456. !                 prim->mina, prim->maxa);
  3457. !     scheme_add_global(prim->name, closed_prim, mod);
  3458. !     MZ_GC_CHECK();
  3459.       }
  3460.       scheme_finish_primitive_module(mod);
  3461. +     MZ_GC_CHECK();
  3462. +     MZ_GC_UNREG();
  3463.   }
  3464.   
  3465.   #ifdef HAVE_SANDBOX
  3466. ***************
  3467. *** 2697,2717 ****
  3468. --- 3148,3172 ----
  3469.       {
  3470.           MZ_REGISTER_STATIC(M_write);
  3471.           M_write = scheme_intern_symbol("write");
  3472. +         MZ_GC_CHECK();
  3473.       }
  3474.       if (M_read == NULL)
  3475.       {
  3476.           MZ_REGISTER_STATIC(M_read);
  3477.           M_read = scheme_intern_symbol("read");
  3478. +         MZ_GC_CHECK();
  3479.       }
  3480.       if (M_execute == NULL)
  3481.       {
  3482.           MZ_REGISTER_STATIC(M_execute);
  3483.           M_execute = scheme_intern_symbol("execute");
  3484. +         MZ_GC_CHECK();
  3485.       }
  3486.       if (M_delete == NULL)
  3487.       {
  3488.           MZ_REGISTER_STATIC(M_delete);
  3489.           M_delete = scheme_intern_symbol("delete");
  3490. +         MZ_GC_CHECK();
  3491.       }
  3492.   
  3493.       while (!SCHEME_NULLP(requested_access))
  3494. *** ../vim-7.2.190/src/if_mzsch.h    2006-03-24 23:43:11.000000000 +0100
  3495. --- src/if_mzsch.h    2009-05-26 19:08:21.000000000 +0200
  3496. ***************
  3497. *** 11,16 ****
  3498. --- 11,17 ----
  3499.   
  3500.   /* #ifdef needed for "make depend" */
  3501.   #ifdef FEAT_MZSCHEME
  3502. + # include <schvers.h>
  3503.   # include <scheme.h>
  3504.   #endif
  3505.   
  3506. ***************
  3507. *** 46,49 ****
  3508. --- 47,77 ----
  3509.   # define scheme_byte_string_to_char_string(obj) (obj)
  3510.   #endif
  3511.   
  3512. + /* Precise GC macros */
  3513. + #ifndef MZ_GC_DECL_REG
  3514. + # define MZ_GC_DECL_REG(size)            /* empty */
  3515. + #endif
  3516. + #ifndef MZ_GC_VAR_IN_REG
  3517. + # define MZ_GC_VAR_IN_REG(x, v)          /* empty */
  3518. + #endif
  3519. + #ifndef MZ_GC_ARRAY_VAR_IN_REG
  3520. + # define MZ_GC_ARRAY_VAR_IN_REG(x, v, l) /* empty */
  3521. + #endif
  3522. + #ifndef MZ_GC_REG
  3523. + # define MZ_GC_REG()                     /* empty */
  3524. + #endif
  3525. + #ifndef MZ_GC_UNREG
  3526. + # define MZ_GC_UNREG()                   /* empty */
  3527. + #endif
  3528. + #ifdef MZSCHEME_FORCE_GC
  3529. + /*
  3530. +  * force garbage collection to check all references are registered
  3531. +  * seg faults will indicate not registered refs
  3532. +  */
  3533. + # define MZ_GC_CHECK() scheme_collect_garbage();
  3534. + #else
  3535. + # define MZ_GC_CHECK()            /* empty */
  3536. + #endif
  3537.   #endif /* _IF_MZSCH_H_ */
  3538. *** ../vim-7.2.190/src/main.c    2009-05-17 13:30:58.000000000 +0200
  3539. --- src/main.c    2009-05-26 19:09:01.000000000 +0200
  3540. ***************
  3541. *** 935,942 ****
  3542. --- 935,948 ----
  3543.   
  3544.       /*
  3545.        * Call the main command loop.  This never returns.
  3546. +      * For embedded MzScheme the main_loop will be called by Scheme
  3547. +      * for proper stack tracking
  3548.        */
  3549. + #ifndef FEAT_MZSCHEME
  3550.       main_loop(FALSE, FALSE);
  3551. + #else
  3552. +     mzscheme_main();
  3553. + #endif
  3554.   
  3555.       return 0;
  3556.   }
  3557. *** ../vim-7.2.190/src/proto/if_mzsch.pro    2004-07-12 17:51:52.000000000 +0200
  3558. --- src/proto/if_mzsch.pro    2009-05-26 19:09:55.000000000 +0200
  3559. ***************
  3560. *** 15,24 ****
  3561.   void *mzvim_eval_string __ARGS((char_u *str));
  3562.   struct Scheme_Object *mzvim_apply __ARGS((struct Scheme_Object *, int argc,
  3563.       struct Scheme_Object **));
  3564. ! int mzthreads_allowed (void);
  3565. ! #ifdef FEAT_GUI_KDE
  3566. ! void timer_proc (void);
  3567. ! void mzscheme_kde_start_timer (void);
  3568. ! void mzscheme_kde_stop_timer (void);
  3569. ! #endif
  3570.   /* vim: set ft=c : */
  3571. --- 15,20 ----
  3572.   void *mzvim_eval_string __ARGS((char_u *str));
  3573.   struct Scheme_Object *mzvim_apply __ARGS((struct Scheme_Object *, int argc,
  3574.       struct Scheme_Object **));
  3575. ! int mzthreads_allowed __ARGS((void));
  3576. ! void mzscheme_main __ARGS((void));
  3577.   /* vim: set ft=c : */
  3578. *** ../vim-7.2.190/src/version.c    2009-05-26 18:12:13.000000000 +0200
  3579. --- src/version.c    2009-05-26 22:52:53.000000000 +0200
  3580. ***************
  3581. *** 678,679 ****
  3582. --- 678,681 ----
  3583.   {   /* Add new patch number below this line */
  3584. + /**/
  3585. +     191,
  3586.   /**/
  3587.  
  3588. -- 
  3589. Scientists decoded the first message from an alien civilization:
  3590.         SIMPLY SEND 6 TIMES 10 TO THE 50 ATOMS OF HYDROGEN TO THE STAR
  3591. SYSTEM AT THE TOP OF THE LIST, CROSS OFF THAT STAR SYSTEM, THEN PUT
  3592. YOUR STAR SYSTEM AT THE BOTTOM OF THE LIST AND SEND IT TO 100 OTHER
  3593. STAR SYSTEMS.  WITHIN ONE TENTH GALACTIC ROTATION YOU WILL RECEIVE
  3594. ENOUGH HYDROGREN TO POWER YOUR CIVILIZATION UNTIL ENTROPY REACHES ITS
  3595. MAXIMUM!  IT REALLY WORKS!
  3596.  
  3597.  /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
  3598. ///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
  3599. \\\        download, build and distribute -- http://www.A-A-P.org        ///
  3600.  \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///
  3601.