in reply to Re^3: perl XS - passing array to C and getting it back
in thread perl XS - passing array to C and getting it back

Assume I am really really (!!!) dumb. I can't use inline at all. It has to be perl XSUB which calls C function and pass it an array. can it be done?
  • Comment on Re^4: perl XS - passing array to C and getting it back

Replies are listed 'Best First'.
Re^5: perl XS - passing array to C and getting it back
by Corion (Patriarch) on Mar 29, 2016 at 13:20 UTC

    The easy approach is to install and use Inline::C to generate the XS scaffolding for your code. After that, you throw away Inline::C and only use its output.

    If you don't know how to install Inline::C, the easy approach is outlined in the following steps:

    1. Install local::lib (because you don't want to pollute the system Perl)
    2. Set your environment variables like local::lib proposes
    3. Download cpanm from http://cpanmin.us
    4. Run the following command:
      cpanm Inline::C

    You now have Inline::C and its prerequisites installed in a local directory and can use Inline::C to generate much of the XS code for you.

Re^5: perl XS - passing array to C and getting it back
by BrowserUk (Patriarch) on Mar 29, 2016 at 13:35 UTC
    I can't use inline at all.

    That's why I posted the .xs file generated by Inline::C. You'll need to grab Inline.h from the package and then the XS code I posted should compile directly.

    Of course, if you can compile XS code, there is no rational reason why you cannot use Inline::C; but if you prefer not to that's your choice.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
    In the absence of evidence, opinion is indistinguishable from prejudice.
Re^5: perl XS - passing array to C and getting it back
by Tux (Canon) on Mar 29, 2016 at 13:56 UTC

    If you take the path of real XS code, be sure to use Devel::PPPort from the start. It'll save you a lot of headaches later.

    Then read the docs (twice):

    $ perldoc perlxs $ perldoc perlxstut $ perldoc perlxstypemap

    Enjoy, Have FUN! H.Merijn