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

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

Thread Previous
Father Chrysostomos via RT
December 29, 2014 22:41
[perl #36051] LVALUE magic should know how to assign to globs
Message ID:
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.
> 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

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