perl-xs

What is the modern way of creating an XS module from scratch?

I need to write an XS module for Perl. It is my understanding that h2xs is pretty much deprecated today, what is the preferred method for starting an XS module today? I looked at Module::Starter, but it only handles pure Perl modules. ...

Why do I get "undefined reference" errors when I compile my XS with Perl 5.10?

Hi I have a C++ object that I am converting to Perl using Perl XS. This process works fine with Perl 5.8.5 and 5.8.7. But as soon as I try to use Perl 5.10.0, I run into a lot of compile errors. Most of them are along these lines: undefined reference to 'PL_stack_max' undefined reference to 'PL_stack_sp' undefined reference to 'Perl_...

How do I write a Perl constructor in XS?

I am trying to write new XS module for Perl. I have tested by following XS module writing instruction and it is working fine. I am not able to understand how to I write new method for XS I have a package called Agent. I want to be able to something like this: my $agent_object = new Agent; ...

structure definition conflict between XS module and perl build

On OpenSolaris ($^O eq 'solaris', vers. 2.11), I'm trying to build an XS module which uses the XPGv4v2/Single Unix Spec. understanding of struct msghdr, specifically for "ancillary data" interrogation. However, the native perl (v5.8.4) was built without the requisite defines, and so the struct msghdr visible within my XS file is the old...

How can I tell if a C struct has a member in Perl XS?

Is there an ExtUtils::* or Module::Build (or other) analog to Ruby's mkmf.have_struct_member? I'd like to do something like (in the manner of a hints/ file): .... if struct_has_member("msghdr", "msg_accrights") { $self->{CCFLAGS} = join(' ', $self->{CCFLAGS}, "-DTRY_ACCRIGHTS_NOT_CMSG"); } ... Config.pm doesn't track the spec...

How can I uniquely identify all of the calls to a function?

I know that caller will give me the file name and line number where a function was called, but how can I get the character or byte offset? It is okay if I must drop down to XS for it (the function will probably wind up being XS anyway). What I am trying to do is uniquely identify all of the calls to a function, so, if there is a better...

What tools can help build an XS project?

I've recently started learning XS using perlxstut and the tutorial suggests that I create my module using the old h2xs tool to create an ExtUtils::MakeMaker-based project. However for pure Perl projects, h2xs/EUMM has long been disfavoured in favour of Module::Install, Module::Build or Dist::Zilla. Is there a more modern way of creating...

How can Perl's XSUB die?

I have written a Perl XS wrapper for a C library consisting of about ~80 functions. Right now my general strategy is to substitute the error from a C function with PL_sv_undef and the calling Perl code has to check explicitly whether the return is not undef. (For some C functions it is more complicated as I convert their output into a HV...

Calling C function from Perl within embedded C application

Ok, this is a very interesting question and there may not be any easy way to do this but figured I would throw this out there before deciding that modifying Perl is my underlying answer. So I've got a C application that calls Perl scripts in an embedded fashion. This all works fine and dandy and it's pretty awesome that I can pass info...