Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: platform agnostic foreign function interface, necessary?, missing?

by Joost (Canon)
on Feb 19, 2009 at 13:32 UTC ( [id://745040]=note: print w/replies, xml ) Need Help??


in reply to platform agnostic foreign function interface, necessary?, missing?

P5NCI seems to be pretty much equivalent to ruby's FFI, though I haven't used either.

There are some issues with this kind of approach though, especially in a multi-platform environment. Mainly, it doesn't rely on a C compiler or any of the header files which is great if need to install it on a system for which you don't have a C compiler or header files but it also means you'll end up replicating the header files in the FFI code. And structures and function arguments tend to differ over different operating systems.

A simple example of this problem that I've ran into when using the CFFI system: the values of the RTLD_* constants (used as the MODE argument to dlopen) are different for at least Linux & BSD, but if you don't know that, the code will probably run but not do what you want on one of the systems. The suggested way to work around that is to parse the header files yourself - that is obviously not a very good way to go about things.

On the other hand, XS is really pretty good, as portable as C is (which is exactly the right amount of portable) and the only requirement is that you've got a decent C compiler + header files available. With strawberry perl, that should mean it's free for every major OS that perl runs on. Yes it's a bit more complicated, but not really that much. Get the book if you want to good introduction.

  • Comment on Re: platform agnostic foreign function interface, necessary?, missing?

Replies are listed 'Best First'.
Re^2: platform agnostic foreign function interface, necessary?, missing?
by jettero (Monsignor) on Feb 19, 2009 at 17:52 UTC
    For the record, I like XS and write in it fairly frequently. I'm mainly interested in reducing the number of esoteric things you have to learn to write extensions and I like the idea of not needing a compiler at all to write a new one. If some really good standard FFI was available on most perls, the CPAN install would be basically just copying the .pm to the right place and you're done. This would simplify the install of Gtk2 by quite a bit. It's notoriously difficult to compile on win32 because of the very short command line length restriction.

    I think the Ruby FFI optionally parses header files automatically, so it may get around some of the problems you're talking about here. On the other hand, it may make them worse, since you'd need to have the development versions of package libraries installed just to run things. Gross.

    -Paul

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://745040]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (5)
As of 2024-04-23 16:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found