Question related to the perl public API
Questions tagged [perlapi]
15 questions
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
9
votes
1 answer
How to find current package name from perl XS?
To get current context I find caller_cx function in perlapi. But there is no description for structure. In perl source code perl.h I can find only this typedef:
typedef struct context PERL_CONTEXT;
Is there examples how to use this struct returned…

Eugen Konkov
- 22,193
- 17
- 108
- 158
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
4
votes
1 answer
Perl API Inline C: How to get get a substr of a Perl byte string by reference without copying that string
Hello community I hope I can meet some byte string experts here.
I guess SvPVbyte comes into play, but how?
My problem.
I already sucessfully parse Perl array XYZ (within a hash of arrays) with example index 6789) within Inline:C with Perl:…

GoetzM
- 41
- 2
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
1 answer
Should I call SvREFCNT_dec() on a SV that is not going to be returned to Perl on the stack?
When calling a C function from Perl, for example using Inline::C:
use feature qw(say);
use strict;
use warnings;
use Inline C => './test.c';
say "Calling test()..";
test();
say "Finished.";
where test.c is:
void test()
{
SV *sv_variable =…

Håkon Hægland
- 39,012
- 21
- 81
- 174
4
votes
1 answer
Why callback is not called?
I have the example script from B::OPCheck module with modified PL_op_name to padsv
use B::Generate;
use B::OPCheck padsv => check => sub {
my $op = shift;
print "HERE";
};
my $x;
1;
But callback is not called.
When deparsing this program…

Eugen Konkov
- 22,193
- 17
- 108
- 158
3
votes
0 answers
Is it possible to know `XSUB` was called using `&sub`
When PP sub is called the CX for this sub is created.
By accessing this context by CxHASARGS(CX_CUR()) we can check this sub hasargs or not.
But for the XSUB context is not created, so we can not use this trick.
Is is possible to know XSUB was…

Eugen Konkov
- 22,193
- 17
- 108
- 158
2
votes
1 answer
What is the difference between `GvNAME` and `GvENAME`?
In perl sources GvNAME and GvENAME. Both return name for given gv. But second stands for effective name.
Dumping names I have not seen the difference.
May someone clear what is the difference and provide example which shows it?
UPD
Because this is…

Eugen Konkov
- 22,193
- 17
- 108
- 158
2
votes
1 answer
How to get access to current context from XS?
When a user calls XS from main:: package we can not use
caller_cx(0, NULL);
because there is no frames for main:: and for XSUB DOC
Note that XSUBs don't get a stack frame, so C will return information for the immediately-surrounding Perl code
How…

Eugen Konkov
- 22,193
- 17
- 108
- 158
1
vote
1 answer
How to set a Perl environment variable from an XSUB?
I am trying to set a Perl environment variable from an XSUB. I want it to take immediate effect before the XSUB exits. Here is my XS file, Module.xs:
#define PERL_NO_GET_CONTEXT
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
MODULE =…

Håkon Hægland
- 39,012
- 21
- 81
- 174
1
vote
1 answer
Unable to install Perlapi anymore?
I'm trying to follow the steps to fix Shutter's disabled edit button, and for that, you need to install libgoo-canvas-perl
I downloaded it, but when I install, I get:
libgoo-canvas-perl: Depends: perlapi-5.22.1 but it is not installable
What I can…

Lucius
- 1,246
- 1
- 8
- 21
1
vote
0 answers
How to use XSUBs from another module?
I am writing XS module. And want to reuse functions from another XS in Sub::Indentify.
In case of usual perl module I can do:
use Sub::Identify;
Sub::Identify::get_code_info( $code );
How do same thing from XS?
UPD
I want to call get_code_info as…

Eugen Konkov
- 22,193
- 17
- 108
- 158
0
votes
1 answer
The relationship between MULTIPLICITY and PERL_IMPLICIT_CONTEXT
What is the relationship between the Perl API macros MULTIPLICITY and PERL_IMPLICIT_CONTEXT?
According to perlguts:
One macro controls the major Perl build flavor: MULTIPLICITY. The
MULTIPLICITY build has a C structure that packages all the…

Håkon Hægland
- 39,012
- 21
- 81
- 174
0
votes
1 answer
Where I can find the types of op that are filtered by PL_check?
PL_check is a variable exposed by the Perl public API:
Array, indexed by opcode, of functions that will be called for the "check" phase of optree building during compilation of Perl code. For most (but not all) types of op, once the op has been…

Eugen Konkov
- 22,193
- 17
- 108
- 158