Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Wrapping a C shared library with Perl and XS

by syphilis (Archbishop)
on Mar 18, 2017 at 03:01 UTC ( [id://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 (Canon) 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 (Canon) 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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1185105]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2024-03-29 00:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found