Hi, Daniel Ridge <[EMAIL PROTECTED]> writes:
> I use mmap in guile via a very simple C module and I have a piece of > complicated Guile hackery that I would like to simplify. I'm hoping > someone will embarrass me with 3 rational lines to solve my problem. > > My problem is that I don't know how to manufacture a new Guile string > with a pre-existing pointer (returned by mmap) and a length that I > specify. Instead, I grab a string from Guile and whack its contents > and length with my own and then put back a reasonable value in a > guardian at GC time. First, you should really use 1.8, if that's possible. ;-) Then, turning arbitrary file contents into a string does not sound like a reasonable option: a file may contain non-printable characters or non-characters (in the Unicode sense). Thus, you may want to use octet vectors to represent arbitrary file contents, rather than strings. In 1.8, you would use SRFI-4 octet vectors to that end (passing the address returned by `mmap ()' to `scm_take_u8vector ()' and making the returned vector uncollectable so that `free ()' isn't eventually invoked on the `mmap' address). However, ports are generally more appropriate than vectors to handle arbitrarily large file contents. Thus, I would recommend using a regular file port and then using something like `uniform-array-read!' (in 1.8) to get part of the file contents into a vector. Note that the current implementation of file ports doesn't use `mmap ()' behind the scenes (but it could be changed to do so). Hope this helps, Ludovic. _______________________________________________ Guile-user mailing list [email protected] http://lists.gnu.org/mailman/listinfo/guile-user
