[Top][All Lists]

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

Re: Guile Ports and C Streams

From: Matt Wette
Subject: Re: Guile Ports and C Streams
Date: Fri, 14 Dec 2018 13:50:34 -0800
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1

On 12/14/18 1:47 PM, Matt Wette wrote:
On 12/14/18 12:30 PM, Marc Nieper-Wißkirchen wrote:


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)?


-- Marc

Could you track FILE's in your C code (via guile port->fdes and fdopen) and pass port->read_buf, write_buf (see port-internals.h) as an argument to setvbuf()?  A bit hackish but a start.  I'm not totally getting your use case for files, though.

But of course you need to check how the buffers are being used!  The above idea 
looks broken
to me now.  Maybe set zero-size buffers, but that will slow down your programs.

reply via email to

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