develooper Front page | perl.perl5.porters | Postings from July 2016

substr as parameter to a XS sub

Thread Next
Alberto Simões
July 3, 2016 20:45
substr as parameter to a XS sub
Message ID:

I have a module that has ties to a C library.

the XS file looks like:

bt_add_macro_text (macro, text, filename=NULL, line=0)
     char * macro
     char * text
     char * filename
     int    line

the C code in the library is like

bt_add_macro_text (char * macro, char * text, char * filename, int line)

So everything looks good.

If I call this function as

    my $string = "january";
    bt_add_macro_text( substr($string, 0, 3), $string);

I get a segmentation fault, because first parameter is 0x000000

but if I do

    my $string = "january";
    my $abb = substr($string, 0, 3);
    bt_add_macro_text( $abb, $string);

everything works well.

Is this a bug, or something I am doing incorrectly?
I imagine this happens becuse substr can be used as an lvalue, but I am 
not 100% sure.


Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About