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

Re: substr as parameter to a XS sub

Thread Previous | Thread Next
From:
Leon Timmermans
Date:
July 4, 2016 09:05
Subject:
Re: substr as parameter to a XS sub
Message ID:
CAHhgV8hvQzYrEDhtPJHYKk=qAW=6nz7=bS7acRivURFqx4dM4A@mail.gmail.com
On Mon, Jul 4, 2016 at 10:33 AM, Alberto Simões <
albie@alfarrabio.di.uminho.pt> 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?
>

You need to call get magic (SvGETMAGIC(sv)) before doing the SvOK. Though
in my personal opinion this is starting to look like abuse of typemaps; I
would suggest using SV* arguments instead.

Leon

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