How to convert port to C stream for FFI? (FILE*)

3 views
Skip to first unread message

David Banks

unread,
Dec 27, 2010, 6:03:31 PM12/27/10
to Mosh Developer Disscus
Hi all,

Sometimes I might want to use a function from the FFI that uses the C
stream I/O type (FILE*). Something like printf, fputs, or any
function from a third party library that uses that data type. Trouble
is, there is no 'file*' C type specifiable in the "c-function" syntax
exported by (mosh ffi). I could specify void* to bypass checks. But
then there's no way to convert a port I opened from Scheme using 'open-
input-file' to something that would be acceptable to a void*.

A possible workaround would perhaps be to open the stream using FFI
functions wrapping 'fopen' and the like, and pass this value around,
but this seems quite low level.

Is this a suitable feature request for the bug tracker, or am I
missing something?

Cheers,
David

higepon

unread,
Dec 27, 2010, 6:23:08 PM12/27/10
to mosh-develo...@googlegroups.com
Hi.

I think your workaround which wraps 'fopen' seems is the best way for now.

Since Scheme port is not implemented with FILE* but fd returned by
open or something alike,
we can't convert directory from port to FILE*.

If there were port->fd procedure, you can covert fd with fdopen using FFI.
But since Mosh should support Windows,
port->fd may be too low level.

> David

You can post any feature requests to
http://code.google.com/p/mosh-scheme/issues/list.

> Yuki

How do you think about this problem?

Cheers.
Taro Minowa(Higepon)

> --
> You received this message because you are subscribed to the Google Groups "Mosh Developer Disscus" group.
> To post to this group, send email to mosh-develo...@googlegroups.com.
> To unsubscribe from this group, send email to mosh-developer-di...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/mosh-developer-discuss?hl=en.
>
>

okuoku

unread,
Dec 28, 2010, 7:17:57 AM12/28/10
to mosh-develo...@googlegroups.com
oku

2010/12/28 higepon <hig...@gmail.com>:
- snip -


> If there were port->fd procedure, you can covert fd with fdopen using FFI.
> But since Mosh should support Windows,
> port->fd may be too low level.

- snip -


>> Yuki
>
> How do you think about this problem?

I have no objections to add port->fd into some platform specific library
(likely named (mosh ffi posix) or so.)

But there are some technical considerations when implement such procedure:
- How scheme-side port treated after port->fd?
- Allow textual-port?
- Allow standard ports(i.e. stdin/out/err)?

I think :
- port->fd should only allow "file backed" textual/binary port (ie.
other than standard or custom ports)
- scheme-side port should be closed after port->fd and require
explicit fd->port to re-gain scheme port access

higepon

unread,
Dec 28, 2010, 8:50:06 AM12/28/10
to mosh-develo...@googlegroups.com
Hi.

> - How scheme-side port treated after port->fd?

Like on Gauche, fd should be dup-ped.

> - Allow textual-port?

No. Just binary-port only.

> - Allow standard ports(i.e. stdin/out/err)?

May be yes (works for only POSIX)

> - port->fd should only allow "file backed" textual/binary port (ie.
> other than standard or custom ports)

Yeah. Socket port can be supported.

Added to this feature request to Issues.

Cheers.

Reply all
Reply to author
Forward
0 new messages