in reply to Packaging code using Inline::C with PAR

Is there an easy way to convert Inline::C code to XS?

If you run with the Inline::C Config option 'CLEAN_AFTER_BUILD => 0', then after compilation you can go into the build directory and grab the actual XS file that Inline::C auto-generated. You can then package that with an appropriate Makefile.PL, test suite, etc. into a normal cpan-type distro. You'll need to edit the 'MODULE' and 'PACKAGE' entries in the auto-generated XS file but, iirc, that's the only change you'll have to make.

Alternatively, you could try Inline::C2XS (which I wrote and put on CPAN). It works ok for me - but it's not exactly a great piece of work, and ymmv :-) The correct thing for Inline::C2XS would be to tap into the XS-generating code that Inline::C uses - but it doesn't do that. Anyway, here's the IdleTime.xs file that Inline::C2XS produces for me. (I believe it's correct.)
#include "EXTERN.h" #include "perl.h" #include "XSUB.h" #include <time.h> #include <stdio.h> #include <unistd.h> #include <X11/Xlib.h> #include <X11/Xutil.h> #include <X11/extensions/scrnsaver.h> int GetIdleTime () { time_t idle_time; static XScreenSaverInfo *mit_info; Display *display; int screen; mit_info = XScreenSaverAllocInfo(); if((display=XOpenDisplay(NULL)) == NULL) { return(-1); } screen = DefaultScreen(display); XScreenSaverQueryInfo(display, RootWindow(display,screen), mit +_info); XFree(mit_info); XCloseDisplay(display); idle_time = (mit_info->idle) / 1000; return idle_time; } MODULE = X11::IdleTime PACKAGE = X11::IdleTime PROTOTYPES: DISABLE int GetIdleTime ()

I couldn't quite make sense of the errors you reported - and don't have time to investigate. In the past I have used Inline::C and PAR. The Inline::C binaries need to be placed in a specifically-named location, and PAR mangles that location so that the files can't be found. The only way I ever got it to work was to include that "specifically-named" location as a separate folder alongside the PAR executable. I forget the details - it was something I did only as a "proof-of-concept" exercise. (There might well be a better solution.)

Cheers,
Rob

Replies are listed 'Best First'.
Re^2: Packaging code using Inline::C with PAR
by sgifford (Prior) on Sep 14, 2006 at 03:33 UTC
    Thanks syphilis, that worked great!

    It would be exremely useful to automate the whole process, so that CPAN modules could be written with Inline::C, then would be automatically translated to XS with Inline::C2XS during the build process. Inline::C is much easier to develop with, but XS is much easier to install. If a giant pile of time falls on my head, I'll have to start working on that... :)

      Hi sgifford,

      FYI, this node is where I got the idea for the InlineX::XS module from. It should do all of what you suggest and a little more.

      Steffen