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

Re: substr as parameter to a XS sub

Thread Previous | Thread Next
From:
Tony Cook
Date:
July 4, 2016 08:56
Subject:
Re: substr as parameter to a XS sub
Message ID:
20160704085544.GJ29470@mars.tony.develop-help.com
On Mon, Jul 04, 2016 at 09:33:42AM +0100, Alberto Simões wrote:
> 
> >>
> >>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.
> >
> >The SvPV_nolen() in the standard typemap for T_PV should handle that
> >correctly.
> >
> >A non-default typemap that changes the mapping for char * or changes
> >T_PV could break it.
> >
> >If you have a more complete example please open a ticket.
> 
> Hi.
> 
> You just found the problem, I think. This is the typemap:
> 
> T_PV
> 	$var = (SvOK ($arg)) ? ($type) SvPV ($arg,PL_na) : NULL
> 
> and this is the comment from the original author:
> 
> # this is needed so we can pass 'undef' for the filename to
> # Text::BibTeX::Entry::parse and have it wind up as NULL
> # in bt_parse_entry()
> 
> Can you help me working a new typemap?

Something like:

T_PV
 	$var = (SvGETMAGIC($arg), SvOK ($arg)) ? ($type) SvPV_nomg_nolen($arg) : NULL

should work.

Use SvPV_nomg($arg, &PL_na) if you need to support perls older than 5.14.

Tony

Thread Previous | 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