guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Guile Ports and C Streams


From: Mike Gran
Subject: Re: Guile Ports and C Streams
Date: Fri, 14 Dec 2018 14:41:45 -0800
User-agent: Mutt/1.10.1 (2018-07-13)

On Fri, Dec 14, 2018 at 09:30:28PM +0100, Marc Nieper-Wi�kirchen wrote:
> Hi!
> 
> Hopefully someone can help me with a hint how to solve the following
> problem: I am developing a C extension for Guile. One C function I use
> expects a C stream (a FILE* object) as an argument.
> 
> On the Guile side, I have a Scheme port (of which I know that it is backed
> up by a Unix file and thus has a file descriptor. My problem is: What is
> the best way to translate the Scheme port to a C file?
> 
> The first idea I had was to use scm_fileno and fdopen and to use reference
> counting and finalizers for garbage collection and automatic closing of the
> C stream.
> 
> In general, the C stream will be buffered as will be the Scheme port.
> However, the two buffers won't know of each other by the above idea, which
> may lead to strange results.
> 
> So, is it possible to retrieve a FILE* object that is shared by the
> underlying Scheme port?
> 
> For example, is it possible to reconstruct/retrieve the C library's stderr
> from (current-error-port)?

I once did a similar thing for Guile-Ncurses, using the obscure C
library function 'fopencookie'.  fopencookie allows one to make a
custom back end to a FILE *.  I make a backend to a FILE * that called
Guile procedures for read, write, seek, and close.  It isn't exactly
what you are asking for, but, it might give you some ideas.

Check it out here.

http://git.savannah.gnu.org/cgit/guile-ncurses.git/tree/src/ncurses/curs_port.c

Good luck,

Mike Gran



reply via email to

[Prev in Thread] Current Thread [Next in Thread]