[racket-dev] Embedding racket in vim

From: Eric Dobson (eric.n.dobson at gmail.com)
Date: Sun Dec 16 17:44:18 EST 2012

Yes I was using the official source.

Here is the patch of my changes, some of which you may already have.

diff -r 52bfa939fc07 src/auto/configure
--- a/src/auto/configure Thu Dec 06 21:30:29 2012 +0100
+++ b/src/auto/configure Sun Dec 16 14:37:19 2012 -0800
@@ -4927,7 +4927,8 @@

   if test "X$vi_cv_path_mzscheme_pfx" != "X"; then
     if test "x$MACOSX" = "xyes"; then
-      MZSCHEME_LIBS="-framework PLT_MzScheme"
+      MZSCHEME_LIBS="-framework Racket"
+      MZSCHEME_CFLAGS="-DMZ_PRECISE_GC"
     elif test -f "${vi_cv_path_mzscheme_pfx}/lib/libmzscheme3m.a"; then
       MZSCHEME_LIBS="${vi_cv_path_mzscheme_pfx}/lib/libmzscheme3m.a"
       MZSCHEME_CFLAGS="-DMZ_PRECISE_GC"
@@ -4968,6 +4969,10 @@
       else
  if test -d $vi_cv_path_mzscheme_pfx/share/racket/collects; then
   SCHEME_COLLECTS=$vi_cv_path_mzscheme_pfx/share/racket/
+        else
+  if test -d $vi_cv_path_mzscheme_pfx/collects; then
+    SCHEME_COLLECTS=$vi_cv_path_mzscheme_pfx/
+  fi
  fi
       fi
     fi
diff -r 52bfa939fc07 src/if_mzsch.c
--- a/src/if_mzsch.c Thu Dec 06 21:30:29 2012 +0100
+++ b/src/if_mzsch.c Sun Dec 16 14:37:19 2012 -0800
@@ -183,6 +183,8 @@
 }
 static int buffer_fixup_proc(void *obj)
 {
+    vim_mz_buffer* buf = (vim_mz_buffer*) obj;
+    buf->buf->b_mzscheme_ref = GC_fixup_self(obj);
     return buffer_size_proc(obj);
 }
 static int window_size_proc(void *obj UNUSED)
@@ -195,6 +197,8 @@
 }
 static int window_fixup_proc(void *obj)
 {
+    vim_mz_window* win = (vim_mz_window*) obj;
+    win->win->w_mzscheme_ref = GC_fixup_self(obj);
     return window_size_proc(obj);
 }
 #endif
@@ -861,6 +865,12 @@
     scheme_set_stack_base(stack_base, 1);
 #endif

+#ifndef TRAMPOLINED_MZVIM_STARTUP
+    /* in newer versions of precise GC the initial env has been created */
+    environment = scheme_basic_env();
+#endif
+    MZ_GC_CHECK();
+
     MZ_REGISTER_STATIC(environment);
     MZ_REGISTER_STATIC(curout);
     MZ_REGISTER_STATIC(curerr);
@@ -869,10 +879,6 @@
     MZ_REGISTER_STATIC(exn_message);
     MZ_REGISTER_STATIC(vim_exn);

-#ifndef TRAMPOLINED_MZVIM_STARTUP
-    /* in newer versions of precise GC the initial env has been created */
-    environment = scheme_basic_env();
-#endif
     MZ_GC_CHECK();

 #ifdef INCLUDE_MZSCHEME_BASE
@@ -925,11 +931,7 @@
  MZ_GC_CHECK();
  coll_path = scheme_char_string_to_path(coll_char_string);
  MZ_GC_CHECK();
- coll_pair = scheme_make_pair(coll_path, scheme_null);
- MZ_GC_CHECK();
- config = scheme_config;
- MZ_GC_CHECK();
- scheme_set_param(config, MZCONFIG_COLLECTION_PATHS, coll_pair);
+        scheme_set_collects_path(coll_path);
  MZ_GC_CHECK();
  MZ_GC_UNREG();
     }
@@ -1016,10 +1018,10 @@
 #ifdef MZ_PRECISE_GC
     GC_register_traversers(mz_buffer_type,
     buffer_size_proc, buffer_mark_proc, buffer_fixup_proc,
-    TRUE, TRUE);
+    TRUE, FALSE);
     GC_register_traversers(mz_window_type,
     window_size_proc, window_mark_proc, window_fixup_proc,
-    TRUE, TRUE);
+    TRUE, FALSE);
 #endif

     make_modules();
@@ -1652,7 +1654,7 @@
     if (win->w_mzscheme_ref != NULL)
  return win->w_mzscheme_ref;

-    self = scheme_malloc_fail_ok(scheme_malloc, sizeof(vim_mz_window));
+    self = scheme_malloc_fail_ok(scheme_malloc_tagged,
sizeof(vim_mz_window));
     vim_memset(self, 0, sizeof(vim_mz_window));
     scheme_dont_gc_ptr(self); /* because win isn't visible to GC */
     MZ_GC_CHECK();
@@ -1977,7 +1979,7 @@
     if (buf->b_mzscheme_ref)
  return buf->b_mzscheme_ref;

-    self = scheme_malloc_fail_ok(scheme_malloc, sizeof(vim_mz_buffer));
+    self = scheme_malloc_fail_ok(scheme_malloc_tagged,
sizeof(vim_mz_buffer));
     vim_memset(self, 0, sizeof(vim_mz_buffer));
     scheme_dont_gc_ptr(self); /* because buf isn't visible to GC */
     MZ_GC_CHECK();
@@ -2298,8 +2300,8 @@
     MZ_GC_VAR_IN_REG(1, rest);
     MZ_GC_REG();

-    array = (char **)alloc(new_len * sizeof(char *));
-    vim_memset(array, 0, new_len * sizeof(char *));
+    array = (char **)alloc((new_len + 1) * sizeof(char *));
+    vim_memset(array, 0, (new_len + 1) * sizeof(char *));

     rest = line_list;
     for (i = 0; i < new_len; ++i)
@@ -2481,8 +2483,8 @@
  MZ_GC_VAR_IN_REG(1, rest);
  MZ_GC_REG();

- array = (char **)alloc(size * sizeof(char *));
- vim_memset(array, 0, size * sizeof(char *));
+ array = (char **)alloc((size + 1) * sizeof(char *));
+ vim_memset(array, 0, (size + 1) * sizeof(char *));

  rest = list;
  for (i = 0; i < size; ++i)



On Fri, Dec 14, 2012 at 9:05 AM, Sergey Khorev <sergey.khorev at gmail.com>wrote:

>
> On Fri, Dec 14, 2012 at 9:20 AM, Eric Dobson <eric.n.dobson at gmail.com>wrote:
>
>> I figured this out. It was that vim was not being compiled with the
>> precise garbage collection when racket was, and a couple of bugs on the vim
>> allocation of racket objects. I'll hopefully have a patch soon.
>>
>>
>
> Are you talking about official Vim source? For
> http://code.google.com/r/sergeykhorev-vim-mzscheme/source I reworked some
> memory allocation stuff so something must have changed in this regard :)
>
> _________________________
>   Racket Developers list:
>   http://lists.racket-lang.org/dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/dev/archive/attachments/20121216/1dfa95e6/attachment.html>

Posted on the dev mailing list.