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

substr as parameter to a XS sub

Thread Next
From:
=?UTF-8?Q?Alberto_Sim=c3=b5es?=
Date:
July 3, 2016 20:45
Subject:
substr as parameter to a XS sub
Message ID:
e96d5dd9-ec75-e060-4184-18ef0792550c@alfarrabio.di.uminho.pt
Hi

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

the XS file looks like:

-----
void
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

-----
void
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.

Thanks
ambs




Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About