develooper Front page | perl.perl5.porters | Postings from December 2014

[perl #36051] LVALUE magic should know how to assign to globs

Thread Previous
From:
Father Chrysostomos via RT
Date:
December 29, 2014 22:41
Subject:
[perl #36051] LVALUE magic should know how to assign to globs
Message ID:
rt-4.0.18-15012-1419892897-1356.36051-15-0@perl.org
On Mon Dec 29 13:57:37 2014, bulk88 wrote:
> I am currently rewriting Perl_gv_add_by_type but I see something
> strange
> in the existing code.
> 
> http://perl5.git.perl.org/perl.git/commitdiff/13be902cef8b01c085a6b8b1b59fa2754a10cdfb
> https://rt.perl.org/Ticket/Display.html?id=77362
> 
> So what is the sv_u of a PVLV? Why would a LV have a GP ptr?

If you assign a typeglob to a deferred element or to an element of a tied aggregate, then you get a PVLV that is a typeglob.

> I thought
> the sv_u of a PVLV was a PV buffer.

The sv_u of a PVLV may differ just as much as the sv_u of a PVMG.  It can hold an SV pointer if you assigned a reference to a PVLV.

Actually, it can differ more.  A PVLV can also be a REGEXP thingy (with sv_u pointing to the regexp struct) even though the internal type is SVt_PVLV, not SVt_REGEXP.  This is because PVLV needs to be able to hold any type of scalar.

> I have some old XS code to
> de-magic/vivify a hash slice, since otherwise I need to croak.
> 
> if (SvREADONLY(buffer)) {
>     croak(PL_no_modify);
> }
> if(SvTYPE(buffer) == SVt_PVLV && LvTYPE(buffer) == 'y'){
>     sv_setpv_mg(buffer, " ");
>     if(LvTARG(buffer)) buffer = LvTARG(buffer);
> }
> if (SvMAGICAL(buffer)) {
>     DumpSV(buffer);
>     croak("%s: magic scalar as buffer not supported.", cvname);
> }

I am confused as to why that code would be affected by the sv_u field of a PVLV.

-- 

Father Chrysostomos


---
via perlbug:  queue: perl5 status: resolved
https://rt.perl.org/Ticket/Display.html?id=36051

Thread Previous


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