Dan Sugalski <[EMAIL PROTECTED]> wrote:
> At 11:58 AM 8/1/00 -0500, Garrett Goebel wrote:
> >From: John Tobey [mailto:[EMAIL PROTECTED]]
> > >
> > > Since this issue mainly affects Windows users (I assume),
> >
> >Actually I've run across a couple people wanting this on unices.
>
> I want it on VMS, too.
Tell me whether C::DynaLib[1] passes the tests. It worked on
Alpha/DU. No VAX support, though.
> Creating an interface to a generic library without wrapper code
> would be a reasonably nifty thing. It'd take care of a good chunk of
> what Xs is used for. (We could reduce the average library interface
> module to a .PM file and a .DYNA_SPEC one, or something similar)
Problem: how to parse header files for type sizes, etc.
> >I guess I don't understand the pro's/con's of XS glue code
> >vs. something like FFI, Win32::API, or C::DynaLib. Can anyone
> >elaborate on this?
>
> I'd like to see this info as well. I'm contemplating something
> similar for the embedding interface for perl, so maybe we can
> dovetail the two together or something.
Well, since I wrote two[1][2] of the interfaces mentioned in the
subject line, I'll do the elaborating...
> >Whatever eventually replaces XS, I certainly hope that coding to it
> >feels more like Perl working with C, than mystic C macros working
> >with Perl.
>
> It'll probably be more like C calling into a nice, well-behaved
> library with a well-defined interface that hands around a lot of
> magic cookies.
Yes. One thing lacking in Perl 5 is an API that exposes the semantics
of Perl, the language, while meticulously hiding everything else.
This is what Pickle[2] intends to provide for Perl 5 and all future
Perls. Pickle is C++, but we should also have a C interface. Both
interfaces should come in bincompat and sourcecompat (i.e.,
inline/macroized) flavors.
(In my wilder moments, I foresee a grander role for Pickle in Perl 6's
development, but that is for another mail.)
C::DynaLib[1] is a Perl interface to C compiled code that works (more
or less) on IA32, SPARC, and Alpha machines. It uses DynaLoader to
load a library and lets you construct coderefs by giving a symbol name
and C<pack> codes for the function argument and return types. It also
has rudimentary callback support.
C::DynaLib is kind of lightweight and easy to use (when it works), but
I consider it a hack, do not use it myself, and would be happy to give
it to a new maintainer. I was inspired to write it, not out of need,
but because I had used a similar feature in Visual Basic and wanted
motivation for learning Perl's internals.
FFI[3] is a newer CPAN module by Paul Moore based on GNU Ffcall
("foreign function call"). Ffcall is much more ambitious than DynaLib
in the number of architectures supported and the completeness and
robustness of the implementation. Additionally, it supports
generating first-class closures as C function pointers. GNU Guile
(Scheme) has a good set of Ffcall bindings, I believe.
Ffcall is licenced under the self-propagating GPL. I don't know who
holds the copyright or whether they would consider making exceptions.
XS[4] is Perl's standard interface for calling external C code. Both
C::DynaLib and FFI are implemented in XS and augment it with support
for passing various types of arguments to C functions whose prototypes
are not known until run time (i.e., script-writing time).
If you know the function you want to call and have a working XS and C
compiler (typically because you built perl from source), then you can
write an XS module and use that instead of FFI or the like. This is
generally more robust and preferred, but it takes a bigger time
investment, especially with respect to learning the XS language and
the Perl API. Pickle aims to reduce this requirement substantially
for C++ programmers.
As for Win32::API, I don't know much about it. I've never used it,
but I think it is a set of XS modules that let Perl use the most
popular Windows API functions. The problem with this is that there
are just too many functions in too many Windows DLLs for XS coders to
keep up with, and end users who don't have compilers would like to
call the functions without waiting.
Hope this helps.
-John
[1] http://search.cpan.org/search?mode=module&query=C%3A%3ADynaLib
[2] http://search.cpan.org/search?dist=pickle
[3] http://search.cpan.org/search?mode=module&query=FFI
[4] http://search.cpan.org/search?mode=doc&query=perlxs
--
John Tobey, late nite hacker <[EMAIL PROTECTED]>
\\\ ///
]]] With enough bugs, all eyes are shallow. [[[
/// \\\