sgifford has asked for the wisdom of the Perl Monks concerning the following question:

I have a script which uses quite a few modules, including X11::IdleTime, which can detect idle time for X11 sessions. This module, in turn, uses Inline::C.

I'm trying to bundle my application up with PAR for easy distribution. I'm running the usual PAR commands, like:

pp -o hostloc hostloc.pl
but the resulting program doesn't work.

When I first ran it, I got this error:

The extension 'X11::IdleTime' is not properly installed in path: '/tmp/par-gifford/cache-e91f6197470cb6916bbd5973b10de787afb48eb7/inc +/lib' If this is a CPAN/distributed module, you may need to reinstall it on +your system. To allow Inline to compile the module in a temporary cache, simply rem +ove the Inline config option 'VERSION=' from the X11::IdleTime module. at -e line 874 INIT failed--call queue aborted at -e line 874, <DATA> line 1.
When I removed the VERSION= option from that module, I got this error instead:
Error. You have specified 'C' as an Inline programming language. I currently only know about the following languages: If you have installed a support module for this language, try deleting + the config file from the following Inline DIRECTORY, and run again: /home/gifford/src/HostLoc/_Inline at -e line 874 INIT failed--call queue aborted at -e line 874.

Is there any way to make PAR and Inline::C play nicely together?

I suspect I could solve the problem by rewriting X11::IdleTime in XS. Is there an easy way to convert Inline::C code to XS?

Thanks!

Replies are listed 'Best First'.
Re: Packaging code using Inline::C with PAR
by syphilis (Archbishop) on Sep 14, 2006 at 01:17 UTC
    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
      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