develooper Front page | perl.perl5.porters | Postings from February 2004

Re: [possible PATCH] (was: Returning a typeglob from FETCH a tied hash - broken as of 5.8.1)

Thread Previous | Thread Next
From:
Dave Mitchell
Date:
February 13, 2004 15:15
Subject:
Re: [possible PATCH] (was: Returning a typeglob from FETCH a tied hash - broken as of 5.8.1)
Message ID:
20040213231553.GB5443@fdisolutions.com
On Fri, Feb 13, 2004 at 11:17:28AM +0100, Tassilo von Parseval wrote:
> > By making an LV struct a superset of GV, we *can* then do the upgrade.
> > Of course this breaks bincompat.
> 
> I think it breaks it only in a very subtle manner (although subtle might
> already be enough to call it a breaking).

Well, since a lot of the Svt_* constants have now changed their values,
I think bincompat is well and truely broken. Not that this is a fault,
it just means that it can't go in the 5.8.x branch.

I haven't had time to look at this properly yet (too busy strugging
with the Monster I have Created of moving Perl from byacc to bison),
but my initial impression is that it looks good. The reordering of the
type constants makes me twitchy, but I can't immediately think of any
bad effects of that.

Presumably the final patch will contain tests too? ;-)

Thanks for this,

Dave.

I just did expand XPVLV to
> contain the five additionals xgv_ fields from an XPVGV. The only two
> modules I had to change were B (it relies on the ordering of 'svtype' in
> sv.h) and Devel::Peek. Those are modules that deal with the internals of
> perl so breaking them looks tolerable.
> 
> The others should remain compatible as I understand it.
> 
> Anyway, please review the attached patch (I hope I didn't forget any
> patched file; so it's not to be applied yet). It finally allows
> 
>     $_[0] = *FOO;
> 
> and thus also fixes the issues with tied variables en-passant. The
> problem I see with it is that things such as
> 
>     if (SvTYPE(sv) <= SVt_PVLV) {
>         SvPVX(sv) = ...;
>         ...
>     }
> 
> can break because now an XPVAV and XPVHV are also smaller than an XPVLV
> but don't contain an IV or PV slot. That means there are some new
> special cases that need to be dealt with thusly (see the new dump.c for
> example):
> 
>     if (SvTYPE(sv) <= SVt_PVLV 
>         && SvTYPE(sv) != SVt_PVAV 
>         && SvTYPE(sv) != SVt_PVHV) 
> 
> Tassilo
> -- 
> $_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
> pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
> $_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval

> --- sv.h~	2004-02-13 09:15:10.000000000 +0100
> +++ sv.h	2004-02-13 11:04:55.000000000 +0100
> @@ -53,11 +53,11 @@ typedef enum {
>  	SVt_PVNV,	/* 6 */
>  	SVt_PVMG,	/* 7 */
>  	SVt_PVBM,	/* 8 */
> -	SVt_PVLV,	/* 9 */
> -	SVt_PVAV,	/* 10 */
> -	SVt_PVHV,	/* 11 */
> -	SVt_PVCV,	/* 12 */
> -	SVt_PVGV,	/* 13 */
> +	SVt_PVAV,	/* 9 */
> +	SVt_PVHV,	/* 10 */
> +	SVt_PVCV,	/* 11 */
> +	SVt_PVGV,	/* 12 */
> +	SVt_PVLV,	/* 13 */
>  	SVt_PVFM,	/* 14 */
>  	SVt_PVIO	/* 15 */
>  } svtype;
> @@ -271,6 +271,13 @@ struct xpvlv {
>      NV    	xnv_nv;		/* numeric value, if any */
>      MAGIC*	xmg_magic;	/* linked list of magicalness */
>      HV*		xmg_stash;	/* class package */
> +   
> +    /* a full glob fits into this */
> +    GP*		xgv_gp;
> +    char*	xgv_name;
> +    STRLEN	xgv_namelen;
> +    HV*		xgv_stash;
> +    U8		xgv_flags;
>  
>      STRLEN	xlv_targoff;
>      STRLEN	xlv_targlen;
> --- sv.c~	2004-02-13 09:16:34.000000000 +0100
> +++ sv.c	2004-02-13 10:16:33.000000000 +0100
> @@ -1455,6 +1455,11 @@ Perl_sv_upgrade(pTHX_ register SV *sv, U
>  	LvTARGLEN(sv)	= 0;
>  	LvTARG(sv)	= 0;
>  	LvTYPE(sv)	= 0;
> +	GvGP(sv)	= 0;
> +	GvNAME(sv)	= 0;
> +	GvNAMELEN(sv)	= 0;
> +	GvSTASH(sv)	= 0;
> +	GvFLAGS(sv)	= 0;
>  	break;
>      case SVt_PVAV:
>  	SvANY(sv) = new_XPVAV();
> @@ -3783,6 +3788,7 @@ Perl_sv_setsv_flags(pTHX_ SV *dstr, regi
>  	    if (dtype != SVt_PVGV) {
>  		char *name = GvNAME(sstr);
>  		STRLEN len = GvNAMELEN(sstr);
> +        if (dtype != SVt_PVLV)
>  		sv_upgrade(dstr, SVt_PVGV);
>  		sv_magic(dstr, dstr, PERL_MAGIC_glob, Nullch, 0);
>  		GvSTASH(dstr) = (HV*)SvREFCNT_inc(GvSTASH(sstr));
> --- dump.c~	2004-02-13 09:18:37.000000000 +0100
> +++ dump.c	2004-02-13 11:03:34.000000000 +0100
> @@ -1034,7 +1034,7 @@ Perl_do_sv_dump(pTHX_ I32 level, PerlIO 
>  	if (HvHASKFLAGS(sv))	sv_catpv(d, "HASKFLAGS,");
>  	if (HvREHASH(sv))	sv_catpv(d, "REHASH,");
>  	break;
> -    case SVt_PVGV:
> +    case SVt_PVGV: case SVt_PVLV:
>  	if (GvINTRO(sv))	sv_catpv(d, "INTRO,");
>  	if (GvMULTI(sv))	sv_catpv(d, "MULTI,");
>  	if (GvUNIQUE(sv))       sv_catpv(d, "UNIQUE,");
> @@ -1170,7 +1170,7 @@ Perl_do_sv_dump(pTHX_ I32 level, PerlIO 
>  	SvREFCNT_dec(d);
>  	return;
>      }
> -    if (type <= SVt_PVLV) {
> +    if (type <= SVt_PVLV && type != SVt_PVAV && type != SVt_PVHV && type != SVt_PVCV && type != SVt_PVGV) {
>  	if (SvPVX(sv)) {
>  	    Perl_dump_indent(aTHX_ level, file,"  PV = 0x%"UVxf" ", PTR2UV(SvPVX(sv)));
>  	    if (SvOOK(sv))
> @@ -1200,6 +1200,25 @@ Perl_do_sv_dump(pTHX_ I32 level, PerlIO 
>  	if (LvTYPE(sv) != 't' && LvTYPE(sv) != 'T')
>  	    do_sv_dump(level+1, file, LvTARG(sv), nest+1, maxnest,
>  		    dumpops, pvlim);
> +	Perl_dump_indent(aTHX_ level, file, "  NAME = \"%s\"\n", GvNAME(sv));
> +	Perl_dump_indent(aTHX_ level, file, "  NAMELEN = %"IVdf"\n", (IV)GvNAMELEN(sv));
> +	do_hv_dump (level, file, "  GvSTASH", GvSTASH(sv));
> +	Perl_dump_indent(aTHX_ level, file, "  GP = 0x%"UVxf"\n", PTR2UV(GvGP(sv)));
> +	if (!GvGP(sv))
> +	    break;
> +	Perl_dump_indent(aTHX_ level, file, "    SV = 0x%"UVxf"\n", PTR2UV(GvSV(sv)));
> +	Perl_dump_indent(aTHX_ level, file, "    REFCNT = %"IVdf"\n", (IV)GvREFCNT(sv));
> +	Perl_dump_indent(aTHX_ level, file, "    IO = 0x%"UVxf"\n", PTR2UV(GvIOp(sv)));
> +	Perl_dump_indent(aTHX_ level, file, "    FORM = 0x%"UVxf"  \n", PTR2UV(GvFORM(sv)));
> +	Perl_dump_indent(aTHX_ level, file, "    AV = 0x%"UVxf"\n", PTR2UV(GvAV(sv)));
> +	Perl_dump_indent(aTHX_ level, file, "    HV = 0x%"UVxf"\n", PTR2UV(GvHV(sv)));
> +	Perl_dump_indent(aTHX_ level, file, "    CV = 0x%"UVxf"\n", PTR2UV(GvCV(sv)));
> +	Perl_dump_indent(aTHX_ level, file, "    CVGEN = 0x%"UVxf"\n", (UV)GvCVGEN(sv));
> +	Perl_dump_indent(aTHX_ level, file, "    GPFLAGS = 0x%"UVxf"\n", (UV)GvGPFLAGS(sv));
> +	Perl_dump_indent(aTHX_ level, file, "    LINE = %"IVdf"\n", (IV)GvLINE(sv));
> +	Perl_dump_indent(aTHX_ level, file, "    FILE = \"%s\"\n", GvFILE(sv));
> +	Perl_dump_indent(aTHX_ level, file, "    FLAGS = 0x%"UVxf"\n", (UV)GvFLAGS(sv));
> +	do_gv_dump (level, file, "    EGV", GvEGV(sv));
>  	break;
>      case SVt_PVAV:
>  	Perl_dump_indent(aTHX_ level, file, "  ARRAY = 0x%"UVxf, PTR2UV(AvARRAY(sv)));
> --- ext/B/B.xs~	2004-02-13 11:08:43.000000000 +0100
> +++ ext/B/B.xs	2004-02-13 10:20:15.000000000 +0100
> @@ -29,11 +29,11 @@ static char *svclassnames[] = {
>      "B::PVNV",
>      "B::PVMG",
>      "B::BM",
> -    "B::PVLV",
>      "B::AV",
>      "B::HV",
>      "B::CV",
>      "B::GV",
> +    "B::PVLV",
>      "B::FM",
>      "B::IO",
>  };


-- 
Justice is when you get what you deserve.
Law is when you get what you pay for.

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