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