ANN: pure-ffi 0.1

4 views
Skip to first unread message

Albert Graef

unread,
Jan 27, 2009, 1:18:03 AM1/27/09
to pure...@googlegroups.com
pure-ffi is a libffi interface for Pure, which extends and complements
the capabilities of Pure's built-in C interface ('extern' and friends).

The module allows you to interface between Pure and C functions (both
directions) without writing a single line of C code. In particular, you
can turn a Pure function into a C function pointer which can then be
passed as a callback to another C function. C structs are also fully
supported, including the ability to construct and inspect such values
and pass them (by value) to C functions in a type-safe manner.

More information here:
http://pure-lang.googlecode.com/svn/trunk/pure-ffi/README

Source tarball here:
http://pure-lang.googlecode.com/files/pure-ffi-0.1.tar.gz

libffi can be found here (but most gcc-based distros already have it):
http://sourceware.org/libffi/

I forgot to mention this in the README, but you'll need a fairly recent
svn version of Pure in order to use this, or you'll have to wait until
pure-0.17 comes out.

This is the very first release and I've only tested this on Linux so
far, so your bug reports are appreciated. ;-)

Enjoy!
Albert

PS1: Scott, you can find the quicksort example redone with libffi in the
examples subdir of the pure-ffi sources. I think that this should be
good enough to implement the callbacks needed by OpenGL, please let me
know if there's anything missing.

PS2: Eddie, you will probably find it useful that pure-ffi also enables
you to call C functions involving ISOC (or GSL) complex numbers being
passed by value; see the last example in the README.

PS3: Toni, I'm cc'ing you because I hope that you'll consider packaging
this as an addon module. It compiles without hitches on SUSE 11.1 (just
make && make install, no configure), the only dependencies are pure and
the libffi43 from OpenSUSE. It does require a fairly recent svn version
of Pure though, but this won't be problem when pure-0.17 comes out.

--
Dr. Albert Gr"af
Dept. of Music-Informatics, University of Mainz, Germany
Email: Dr.G...@t-online.de, a...@muwiinfa.geschichte.uni-mainz.de
WWW: http://www.musikinformatik.uni-mainz.de/ag

Albert Graef

unread,
Jan 27, 2009, 3:58:01 PM1/27/09
to pure...@googlegroups.com
> pure-ffi is a libffi interface for Pure, which extends and complements
> the capabilities of Pure's built-in C interface ('extern' and friends).

... and version 0.2 is out already. Some minor bugfixes, long double
support, and additional struct operations.

http://pure-lang.googlecode.com/files/pure-ffi-0.2.tar.gz

Albert

P.S.: Libor, I don't recall off hand whether your calendar script uses
some broken-down time functions. If so then you might want to take a
look at pure-ffi/examples/time.pure. Maybe it would be useful to adapt
some of the date/time routines in system.pure accordingly?

Albert Graef

unread,
Jan 28, 2009, 1:48:59 AM1/28/09
to pure...@googlegroups.com
I wrote:
> P.S.: Libor, I don't recall off hand whether your calendar script uses
> some broken-down time functions. If so then you might want to take a
> look at pure-ffi/examples/time.pure. Maybe it would be useful to adapt
> some of the date/time routines in system.pure accordingly?

Yes, I see that you're using gmtime in examples/libor/date.pure and have
to decode the information because the gmtime wrapper in system.pure
returns a string.

I think it would be more useful to have localtime and gmtime in
system.pure return the broken-down time representation as a pointer,
which could then either be passed to asctime or strftime to format it as
a string, or be decoded using the pure-ffi struct functions.

In fact, it might be useful to have pure-ffi included in the main
distribution.

Opinions?

Albert

Eddie Rucker

unread,
Jan 28, 2009, 6:57:27 AM1/28/09
to pure...@googlegroups.com
On Wed 28/01/09 12:48 AM , Albert Graef Dr.G...@t-online.de sent:

> In fact, it might be useful to have pure-ffi included in the main
> distribution.
>
> Opinions?

Include it in the main distribution because:
1. Just about every add-on module is going to need this anyway.
2. It is kind of odd to have most of the support for C built in but have a
separate library to deal with structs and some other pointer issues.

e.r.

Albert Graef

unread,
Jan 28, 2009, 5:41:26 PM1/28/09
to pure...@googlegroups.com
Eddie Rucker wrote:
> 2. It is kind of odd to have most of the support for C built in but have a
> separate library to deal with structs and some other pointer issues.

Well, the separate library is useful anyway because it offers a
lightweight capability to create both Pure-callable C functions and
C-callable Pure functions dynamically, without the need to generate and
compile any Pure or C code.

It's conveivable to also add the struct and C callback features to Pure
itself, but this would need additional declaration syntax for C struct
and function parameters. I'm not sure whether I want to pollute Pure
with that. ;-) And I'm not sure whether I want the core of the
interpreter to depend on libffi. It seems to be available for most
Unix-like systems, but AFAICT there are no ready-made Windows packages
so I'll first have to see whether I can get it to work there.

Eddie Rucker

unread,
Jan 28, 2009, 7:03:10 PM1/28/09
to pure...@googlegroups.com
On Wed, 2009-01-28 at 23:41 +0100, Albert Graef wrote:
> It's conveivable to also add the struct and C callback features to Pure
> itself, but this would need additional declaration syntax for C struct
> and function parameters. I'm not sure whether I want to pollute Pure
> with that. ;-) And I'm not sure whether I want the core of the
> interpreter to depend on libffi.

I didn't understand the issues and tradeoffs. Sorry.

> It seems to be available for most
> Unix-like systems, but AFAICT there are no ready-made Windows packages
> so I'll first have to see whether I can get it to work there.

I keep forgetting about Windoze ;-)
Probably because I sleep better at night when I don't have to deal with M$ stuff ;-)

e.r.

Albert Graef

unread,
Jan 28, 2009, 9:35:14 PM1/28/09
to pure...@googlegroups.com
I wrote:
> I think it would be more useful to have localtime and gmtime in
> system.pure return the broken-down time representation as a pointer,
> which could then either be passed to asctime or strftime to format it as
> a string, or be decoded using the pure-ffi struct functions.

In fact it's even simpler than that. Broken-down time is just a pointer
to a struct with nine ints, which can readily be translated to a matrix
using 'int_matrix 9', no libffi required.

Ok, I rewrote those now (r690). Your date script is already adapted
accordingly. The differences aren't big, see the ChangeLog for details.

As a pleasant side-effect, the time functions in system.pure now really
work the POSIX way. :)

Albert Graef

unread,
Jan 28, 2009, 9:51:57 PM1/28/09
to pure...@googlegroups.com
> Ok, I rewrote those now (r690). Your date script is already adapted
> accordingly. The differences aren't big, see the ChangeLog for details.

Gee, that is Libor's date.pure script of course. I shouldn't be talking
to myself late at night. :)

Reply all
Reply to author
Forward
0 new messages