Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Wrapping a C shared library with Perl and XS

by syphilis (Chancellor)
on Mar 18, 2017 at 03:01 UTC ( #1185105=note: print w/replies, xml ) Need Help??


in reply to Wrapping a C shared library with Perl and XS

I can't immediately see how:

MODULE = Test  PACKAGE = main
transforms into
MODULE = XS::Wrap  PACKAGE = XS::Wrap.

Is that done by hand ?

I'd attack the problem using InlineX::C2XS, but few others seem to share my enthusiasm for that (with good reasons, no doubt).
That is, for me, one way is to cd to some directory and create ./src/Wrap.c, where that file contains your C code:
#include <stdio.h> #include <xswrap.h> void _arr (){ unsigned char* c_array = arr(); inline_stack_vars; inline_stack_reset; int i; for (i=0; i<3; i++){ inline_stack_push(sv_2mortal(newSViv(c_array[i]))); } inline_stack_done; }
Then create a ./XS-Wrap-0.42 source distro directory.
Then create a ./build_src.pl that contains:
use warnings; use strict; use InlineX::C2XS qw(c2xs); my $options = {WRITE_PM => 1, WRITE_MAKEFILE_PL => 1, VERSION => '0.42', MANIF => 1, T => 1, EXPORT_OK_ALL => 1, EXPORT_TAGS_ALL => 'all', }; c2xs('XS::Wrap', 'XS::Wrap', './XS-Wrap-0.42', $options);
Then run perl build_src.pl
Then modify the files generated in ./XS-Wrap-0.42 as needed.
This could all be further customised and further automated, as could your approach.

Cheers,
Rob

Replies are listed 'Best First'.
Re^2: Wrapping a C shared library with Perl and XS
by stevieb (Abbot) on Mar 18, 2017 at 03:07 UTC

    The hack from main to XS::Wrap was by hand within the XS file, yes.

    Tomorrow, I will review your feedback and play with it. Thanks as usual, syphilis.

    -stevieb

    update: I'm sure I've, in passing, had someone else point out to me how to modify these elements of the XS directives on the fly, but my searching of PM, the Internet and my scrambled brain couldn't pick up on it. That's essentially why my 'config' args to Inline look so ugly. I don't use it enough to remember :)

Re^2: Wrapping a C shared library with Perl and XS
by stevieb (Abbot) on Mar 18, 2017 at 03:19 UTC
    "I'd attack the problem using InlineX::C2XS, but few others seem to share my enthusiasm for that (with good reasons, no doubt)."

    Why is that?

      Why is that ?

      Dunno - but I think along the lines of too kludgy or over-documented or under-documented or poorly documented.
      It's also lacking some features - eg choice between DynaLoader/XSLoader, and the $VERSION construct might not be to everyone's liking. (Plus more.)

      It suits me fine, so I'm not too stressed about it.

      Cheers,
      Rob

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1185105]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (2)
As of 2017-09-23 02:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    During the recent solar eclipse, I:









    Results (270 votes). Check out past polls.

    Notices?