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
8
votes
1 answer

Call a perl routine with parameters

I need to call a perl routine in my C program. The perl routine takes the following arguments: $a, $b, $c, where $a and $b are integers, $c is a string (may contain binary characters). According to perlcall, here are the means of making the call.…
packetie
  • 4,839
  • 8
  • 37
  • 72
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
1 answer

Making an old library work with Perl XS and PerlIO

I am rather an XS beginner and I am looking into changing an existing XS module which uses a 15+ year old underlying C library heavily (in fact the module is basically just glue to this library). The problem is that I would like to be able to use…
PLK
  • 389
  • 2
  • 13
8
votes
1 answer

Support autovivified filehandle as arguments to Perl XS routine

Question How can I support autovivified filehandle arguments in an XS function? I'm XS-wrapping a C function which returns a file descriptor, and I'd like to present that file descriptor as a perl filehandle argument in the manner of open(). …
pilcrow
  • 56,591
  • 13
  • 94
  • 135
7
votes
1 answer

perl xs - can't return a new custom c++ object from method call - returns scalar value instead

In my XS file I have: As my new method: matrix * matrix::new( size_t ncols, size_t nrows ) which returns a matrix object like it should and I can invoke methods. Then I have a method call which creates a new matrix object and is supposed to return…
user2074102
7
votes
3 answers

Perl newXS() with closure added

I want to embed Perl in a c++ application and am looking for a method to call into c++ from perl via newXS(). Apart from the function pointer I need the associate a custom pointer to the CV created by newXS(). The pointer contains a C++ context. I…
Konrad Eisele
  • 3,088
  • 20
  • 35
7
votes
1 answer

From Perl XS code, how do I recursively call myself?

I have a complex encoding function in Pure Perl which I am converting to XS in the hope of gaining a performance boost. The function I am converting to XS needs to recursively call itself. I can see how to use call_sv [thanks to "man perlcall"] to…
the.jxc
  • 3,373
  • 21
  • 21
7
votes
2 answers

Why is this XS code that returns a PerlIO* leaky?

I am trying to write some XS code that exposes pieces a library to Perl code as a stream interface that can be written to. The get_stream function below is supposed to be a constructor that prepares and returns a PerlIO object. I figured that I only…
hillu
  • 9,423
  • 4
  • 26
  • 30
7
votes
2 answers

C++ calling perl code - eval_sv not passing arguments to script

I have the below sample program which pushes the arguments to Perl stack and then calls "eval_sv". The sample perl statements get executed but i'm not able to retrieve the variables passed from C++ as Perl arguments. Please let me know what i am…
yogishaj
  • 705
  • 5
  • 17
7
votes
2 answers

How to manually install XS modules?

Correct me if i'm wrong, but XS and Dynaloader based modules are those who use C/C++ shared objects (.so) and which are not PP (Pure Perl)? Now assuming I have a machine, which does not have web-connectivity whatsoever (Solaris 10) and I want, for…
snoofkin
  • 8,725
  • 14
  • 49
  • 86
6
votes
2 answers

Data structure for unique element storage

I'm looking for a data structure which should preferably perform equal O(1)? for any number of elements when adding/removing/retrieving elements. Here are some additional guidelines, retrieving elements should not involve slow keys() elements must…
mpapec
  • 50,217
  • 8
  • 67
  • 127
6
votes
3 answers

Stopping Perl XS modules from silently falling back to pure-perl

It seems some (many?) modules on CPAN are partly implemented in C using XS, and can fall back to a pure-perl implementation if necessary. While this is smart, it can obviously hurt performance, and I would like to know it happens so I can fix the…
Øyvind Skaar
  • 2,278
  • 15
  • 15
6
votes
3 answers

Using 64 bits integers with Perl XS

I want to port a C function using 64 bits integers to Perl code. To do that, I use Perl XS. My problem is there are no 64 bits integers in Perl XS types (only U32, U16 and U8). So, what is the best way to use 64 bit integers in Perl XS code? Here is…
Tosh
  • 61
  • 1
6
votes
1 answer

Perl SV value from pointer without copy

How I could create SV value from null terminated string without copy? Like newSVpv(const char*, STRLEN) but without copy and with moving ownership to Perl (so Perl must release that string memory). I need this to avoid huge memory allocation and…
John Tracid
  • 3,836
  • 3
  • 22
  • 33
6
votes
2 answers

How do I build 32-bit XS modules for a 32-bit custom Perl on a 64-bit CentOS system?

I have a 64-bit CentOS 6 system running a custom-built version of Perl 5.12.5, that is build for 32-bits. (Alas, this is because we are using the same RPMs for 32-bit and 64-bit systems.) When I build XS modules (e.g. JSON::XS) on the server, it…
Rob
  • 781
  • 5
  • 19
1
2
3
8 9