the XS language that acts as a bridge between Perl and C
Questions tagged [perl-xs]
44 questions
17
votes
4 answers
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.

Chas. Owens
- 64,182
- 22
- 135
- 226
13
votes
1 answer
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…

Suroot
- 4,315
- 1
- 22
- 28
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
Extending Perl is breaking dynamic loading
I'm trying to compile an XS into perl [ed(ikegami): which is to say he's using ::MakeMaker's make perl to create a perl with a C vendor library statically linked in ] but when I do, the new version of perl does not support dynamic loading of…

Jonathan M
- 17,145
- 9
- 58
- 91
8
votes
2 answers
How can I call functions in a different C source file from a Perl XS module?
I am building an XS extension with Perl. I have two files:
A C header file (.h)
A C source file (.c)
Currently what i did is to put all the C file code before the Model= on the XS file and wrap the functions I want after the Model=.
The…

smith
- 3,232
- 26
- 55
8
votes
2 answers
Using Perl's ExtUtils::MakeMaker, how can I compile an executable using the same settings as my XS module?
Given a Perl XS module using a C library, assume there is a Makefile.PL that is set up correctly so that all header and library locations, compiler and linker flags etc work correctly.
Now, let's say I want to include a small C program with said XS…

Sinan Ünür
- 116,958
- 15
- 196
- 339
8
votes
1 answer
XS Memory leak in this code?
Unable to find where the memory leak is happening in this code.
Basically I want to write a XS wrapper for a C-function which returns a two-dimensional array.
C-function:
int CW_returnArray(double** arrayDouble, int* count)
{
int number = 10;
…

InnovWelt
- 660
- 1
- 8
- 21
8
votes
2 answers
Do I have to free a HV* created with newHV?
If I write some XS code with a hash that I never expect to return to perl, do I have to free it? If so, how?
The closest I've come up with is hv_undef, but that is only clearing out the contents of the hash, not the hash itself, from what I…

Eugene Marcotte
- 751
- 8
- 21
7
votes
3 answers
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…

Philip Potter
- 8,975
- 2
- 37
- 47
6
votes
2 answers
Why do I get "undefined reference" errors when I compile my XS with Perl 5.10?
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…

shergill
- 3,738
- 10
- 41
- 50
5
votes
1 answer
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…

Dummy00001
- 16,630
- 5
- 41
- 63
5
votes
1 answer
Is it possible to debug Perl that contains XS sections to see the program flow?
I have a project written in Perl with XS components written in C++. I am debugging with command like
perl -d perl_file.pl
How I can use the debugger to jump from Perl into those C++ files?

s_m
- 129
- 8
5
votes
1 answer
How to handle hash value type in Perl XS
I need to process hash value depends on value type. Here is code with problem:
I32 keys = hv_iterinit(hash);
for (I32 i = 0; i < keys; i++)
{
char *key = NULL;
I32 key_length = 0;
SV *value = hv_iternextsv(hash, &key, &key_length);
//…

John Tracid
- 3,836
- 3
- 22
- 33
4
votes
1 answer
How emulate &sname call from XS?
How to emulate z sub behavior within XS sub?
package XS;
sub hello {
print "ARGS: >>@_<<\n";
my $lvl;
while( my @frame = caller( $lvl++ ) ) {
print ">>@frame[0..4]<<\n";
}
}
sub z {
&hello;
}
In my .xs file I…

Eugen Konkov
- 22,193
- 17
- 108
- 158
4
votes
0 answers
Having multiple .xs files in one project
In my root XS file, I have an include of other XS file which I have to do in order to maintain a clean project structure:
MODULE = MyModule PACKAGE = MyPackage
# ...
INCLUDE: xs/MySubpackage.xs
Everything is working fine, except that I have…

vdudouyt
- 843
- 7
- 14