Questions tagged [xs]

XS is a language extension for Perl that can wrap a C library to make it a Perl library.

The documentation is available at http://perldoc.perl.org/perlxs.html.

The characters "xs" are also a commonly-used name for the XML Schema namespace. Questions about XML Schema should use .

130 questions
15
votes
1 answer

How to use B::Hooks to manipulate the perl parser

I'm looking to play with perl parser manipulation. It looks like the various B::Hooks modules are what people use. I was wondering: Best place to start for someone who has no XS experience (yet). Any relevant blog posts? How much work would be…
LLFourn
  • 173
  • 8
14
votes
3 answers

How can I use a C++ class from Perl?

I have a set of classes written in C++. What would be best way to call them from a Perl script? Thanks.
Sam Lee
  • 7,049
  • 10
  • 42
  • 47
14
votes
3 answers

How can I create a qr// in Perl 5.12 from C?

This has been working for me in 5.8 and 5.10, but in 5.12 my code creates this weird non-qr object: # running "print Dumper($regex)" $VAR1 = bless( do{\(my $o = '')}, 'Regexp' ); Whereas printing a qr// not created by my code looks like this: #…
kris
  • 23,024
  • 10
  • 70
  • 79
13
votes
2 answers

Perl XS and Inline::C

What's the difference between using XS and the Inline::C module? This was mentioned by someone in this question and has made me curious.
Nate Glenn
  • 6,455
  • 8
  • 52
  • 95
13
votes
1 answer

How do I trace through an XS .so file?

I have a small Perl program. The program loads a module. The module loads an .so file with XSLoader. This Perl runs on Linux and is built with gcc and -DDEBUGGING, and subsequently so is the .so file. I can recompile. When the Perl program is…
daxim
  • 39,270
  • 4
  • 65
  • 132
11
votes
2 answers

How to introspect regexes in the Perl API

I'm working on some code that needs to serialize Perl regexes, including any regex flags. Only a subset of flags are supported, so I need to detect when unsupported flags like /u are in the regex object. The current version of the code does…
friedo
  • 65,762
  • 16
  • 114
  • 184
10
votes
1 answer

Safely freeing resources in XS code (running destructors on scope exit)

I am writing an XS module. I allocate some resource (e.g. malloc() or SvREFCNT_inc()) then do some operations involving the Perl API, then free the resource. This is fine in normal C because C has no exceptions, but code using the Perl API may…
amon
  • 57,091
  • 2
  • 89
  • 149
10
votes
3 answers

Is there a way to access special tokens in perl from XS?

In perl special tokens like __PACKAGE__, __SUB__, __FILE__, __LINE__ exists and available from script. I may get value of __PACKAGE__ from XS as HvNAME( PL_currstash ), I suppose. But how to access others? Is there special interface to access all of…
Eugen Konkov
  • 22,193
  • 17
  • 108
  • 158
10
votes
2 answers

How can I pass an array to a C function in Perl XS?

How can I pass Perl array by reference to C XS module? my @array = ( 1..20 ); XSTEST::test_array_passing(\@array); What do I do in XS so it sees the array?
Avinash
  • 12,851
  • 32
  • 116
  • 186
9
votes
2 answers

Can I use a module, and later unload it shrinking the optree?

Disclaimer I'm not sure I'm using the right terms. It may not be the optree responsible for the bloat mentioned below: it may be the symbols loaded by DynaLoader that are not freed. Is it possible to use a module, like POSIX.pm, unload it and lessen…
Evan Carroll
  • 78,363
  • 46
  • 261
  • 468
9
votes
1 answer

perl xs - return perl array from c array

Using XS i am trying to pass values from a C array into a Perl array that can be used in the script. Here is the code from my xs file: AV * DoubleArray::getPerlArray() CODE: r = newAV(); for(size_t i=0; i < THIS->count; i++) { …
user2074102
9
votes
2 answers

Why include SvSETMAGIC() on output variables in an XSUB?

Reading the perlxs documentation, I came to the section on the OUTPUT keyword: xsubpp emits an automatic SvSETMAGIC() for all parameters in the OUTPUT section of the XSUB, except RETVAL. This is the usually desired behavior, as it takes care of…
Håkon Hægland
  • 39,012
  • 21
  • 81
  • 174
9
votes
2 answers

What is RMAGICAL?

I'm trying to understand some XS code that I inherited. I've been trying to add comments to a section that invokes Perl magic stuff, but I can't find any documentation to help me understand this line: SvRMAGICAL_off((SV *) myVar); What is RMAGICAL…
Nate Glenn
  • 6,455
  • 8
  • 52
  • 95
8
votes
1 answer

Perl XS unused variable 'Perl___notused' warnings

I am learning how to call C++ code from Perl and to start I am trying to create a basic C++ object from a Perl script. To do this, I started by executing the h2xs command: h2xs -A -nMyClass Then I added the following two arguments to the generated…
tjwrona1992
  • 8,614
  • 8
  • 35
  • 98
8
votes
1 answer

Why do XS subs use const char *?

A lot of Perl XS code uses const char * as the return value of an XS sub but never just char *. For example: const char * version(...) CODE: RETVAL = chromaprint_get_version(); OUTPUT: RETVAL code from xs-fun Can someone explain why…
David Farrell
  • 427
  • 6
  • 16
1
2 3
8 9