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

What does flag `pIOK` mean?

When dumping perl SV with Devel::Peek I can see: SV = IV(0x1c13168) at 0x1c13178 REFCNT = 1 FLAGS = (IOK,pIOK) IV = 2 But can not find the description what pIOK mean. I tried to look it at Devel::Peek, perlapi , perlguts, perlxs ... In…
Eugen Konkov
  • 22,193
  • 17
  • 108
  • 158
5
votes
3 answers

How can I build a Perl hash in C code?

I wish to embed a C code in Perl. In this C code I want to read a huge file into memory, make some changes and build a hash (a custom one). I wish to make this hash accessible from my Perl code. Is it possible? How can I reach the goal?
magda muskala
  • 81
  • 1
  • 4
5
votes
1 answer

Perl XS: Memory management

I am absolutely new to Perl XS. My simple testfunction gets a string and appends something. In Perl is is a scalar-string in and one out. In the function I have a malloc. Whats the correct way to free the mem? SV *foo (str) SV *str CODE: …
chris01
  • 10,921
  • 9
  • 54
  • 93
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
2 answers

How to store null in Perl hash

I want to use Perl hash in my C code (XS) as a set, so I only need to keep keys in hash. Is it possible to store something like null or another constant value to avoid creating unnecessary value? Something like this: int add_value(HV *hash, SV…
John Tracid
  • 3,836
  • 3
  • 22
  • 33
5
votes
1 answer

What's the difference between sv_catpv() and sv_catpvs()?

According to perlapi, sv_catpv() works as follows: Concatenates the NUL-terminated string onto the end of the string which is in the SV. If the SV has the UTF-8 status set, then the bytes appended should be valid UTF-8. Handles 'get' magic, but not…
DarkMorford
  • 505
  • 1
  • 4
  • 12
5
votes
3 answers

How do I conditionally compile C code snippets to my Perl module?

I have a module that will target several different operating systems and configurations. Sometimes, some C code can make this module's task a little easier, so I have some C functions that I would like to bind the code. I don't have to bind the C…
mob
  • 117,087
  • 18
  • 149
  • 283
5
votes
3 answers

What does the DumpXS in Perl's Data::Dumper do?

I have gone through the source code of Data::Dumper. In this package I didn't understand what's going on with DumpXS. What is the use of this DumpXS? I have searched about this and I read that, it is equal to the Dump function and it is faster than…
kiruthika
  • 2,155
  • 7
  • 26
  • 33
5
votes
2 answers

Registering multiple Perl sub references for a C library in XS

Both perlcall (in the "Strategies for storing Callback Context Information" section) and Extending and Embedding Perl (in the "Callback" section) lists 3 different ways to handle calling Perl sub routines from XS/C: Immediately: XS calls Deferred:…
Adam Flott
  • 487
  • 3
  • 8
5
votes
4 answers

Creating Threaded callbacks in XS

EDIT: I have created a ticket for this which has data on an alternative to this way of doing things. I have updated the code in an attempt to use MY_CXT's callback as gcxt was not storing across threads. However this segfaults at ENTER. #include…
kthakore
  • 1,566
  • 3
  • 17
  • 32
5
votes
2 answers

Perl XS and C++ passing pointer to buffer

I know almost no C++ so that's not helping, and my XS isn't much better. I'm creating an XS interface for a C++ library and I have almost all my methods working except one. The method in Perl should look like this: $return_data = $obj->readPath(…
user1446426
  • 685
  • 1
  • 7
  • 11
4
votes
2 answers

Determing line number and file name of the perl file from within C++

I am working with Perl embedded in our application. We have installed quite a few C++ functions that are called from within Perl. One of them is a logging function. I would like to add the file name and line number of the Perl file that called…
Toblakai
  • 193
  • 1
  • 1
  • 8
4
votes
2 answers

Returning a Perl hash with XS (Error: 'void' not in typemap)

I'm trying to add a call to the Perl bindings for Augeas (Config::Augeas). I would like this new call to return a Perl hash. I wrote this: void aug_span(aug, path); Config_Augeas*…
raphink
  • 3,625
  • 1
  • 28
  • 39
4
votes
1 answer

How do you check to see if an object overloads an operator in XS?

If my XS function has been passed an SV containing a blessed object, how can I check to see if that object overloads a particular Perl operator? For example, overloading "". One way I can think of would be to loop through its class and all parent…
tobyink
  • 13,478
  • 1
  • 23
  • 35
4
votes
2 answers

printf format specifiers for Perl API types

Are there macros that provide the correct printf format specifiers for IV, UV, STRLEN, Size_t and SSize_t? None are listed in perlapi. C provides macros for the format specifiers for the types provided by stdint.h, such as uint32_t. #include…
ikegami
  • 367,544
  • 15
  • 269
  • 518
1 2
3
8 9