[plt-scheme] Questions about modules, compilation, namespaces, planet and ffi

From: Eli Barzilay (eli at barzilay.org)
Date: Thu Apr 28 01:15:22 EDT 2005

On Apr 28, Bruno Deferrari wrote:
> * The question about PLaneT:
>   Is there a way to download the packages at planet.plt-scheme.org
>   without using require?? because I don't have access to internet at
>   home.  I can download them from a cybercafe, but I don't know
>   where they are.

Use the `planet' command line tool.

> * The first question about ffi:
>   On the (_fun ...) syntax, the (:post ...) goes before the second
>   -> , or after it?? (my guess is that it goes before)

The _fun form generates a wrapper function that is responsible for the
extra work like dereferencing pointers etc.  For this, it uses the
given syntax pieces to create the result -- and `post:' code happens
after the foreign call -- an expression after a second `->' gets
evaluated to return a result so it is evaluated after everything is
done, after all `post:' expressions.

> * The second question about the ffi:
>   I started playing with the new ffi (Im trying to interface
>   mzscheme with the EFL (www.enlightenment.org), but I'm confused
>   about something.  Here, for example:
> ; Original C function prototype
> ; char    **eet_list  (Eet_File *ef, char *glob, int *count_ret);
> ; Scheme ffi declaration (defeet is similar to defxmms from "xmmsctrl.ss")
> (defeet eet-list : _EetFile _string (r_count : (_ptr o _sint))
> 		   -> (r_ret : (_list o _string r_count)))
>   Here, the array of strings should be freed, but the string pointers it
>   contains shouldn't.
>   How does the ffi know what to do???, or how do I specify it???

There is no way for the interface to read the library's mind and know
what needs to be freed -- so you must do it yourself.  Usually it's
not an issue because when you use `malloc' you do it through the GC
(by default) so there's no need to free anything.  If the library
mallocs stuff that you should free, then the GC wouldn't see it so
you'll need to use `free'.  The above definition wouldn't work because
the returned vector will be converted to a list but you won't have
access to the original pointer after that happens.  So the best
solution would probably be to write a custom type similar to `_list'
that frees the pointer when its done converting it to a list.

> * The question about modules, compilation and namespaces:
>   I'm using plt-299.100 , some days ago, I downloaded mreddesigner
>   (http://mreddesigner.lozi.org), and after fixing it, so it works on 299.100
>   I compiled the files to .zos, but now, it doesn't work right.
>   (it works fine, if I don't compile it)
>   To run it, i do "mred -r main.scm", where main.scm is:
> (require (lib "mred.ss" "mred")
> 	 ;...otherlibs...
> 	 )
> (require "mreddesigner.ss") ; This starts mreddesigner
>   And "mreddesigner.ss" looks like this:
> (module mreddesigner mzscheme
>   (load/use-compiled "some-file.ss")
>   ; ... more files
> )
> [...]

I don't know about mreddesigner, but using `load' in a module is
almost guaranteed to be wrong.

          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                  http://www.barzilay.org/                 Maze is Life!

Posted on the users mailing list.