diff options
author | Malcolm Beattie <mbeattie@sable.ox.ac.uk> | 1997-11-18 16:41:27 +0000 |
---|---|---|
committer | Malcolm Beattie <mbeattie@sable.ox.ac.uk> | 1997-11-18 16:41:27 +0000 |
commit | a0231f0e83307f241a212cdcb7ecea46e3dbf08c (patch) | |
tree | 2b7a0ec62f30e08417b5651f253d7c42e4b399e2 /mg.c | |
parent | 3e72f5af0c78f5895c39dc48ea0378e4cba19b2c (diff) | |
download | perl-a0231f0e83307f241a212cdcb7ecea46e3dbf08c.tar.gz |
magic_setisa enhanced to update %FIELDS automatically when @ISA
is assigned to. Added tests to t/op/array.t. magic_setisa now
warns about including non-existent packages in @ISA when -w is on.
p4raw-id: //depot/perl@264
Diffstat (limited to 'mg.c')
-rw-r--r-- | mg.c | 47 |
1 files changed, 47 insertions, 0 deletions
@@ -838,7 +838,54 @@ magic_setsig(SV *sv, MAGIC *mg) int magic_setisa(SV *sv, MAGIC *mg) { + HV *stash; + SV **svp; + I32 fill; + HV *basefields = Nullhv; + GV **gvp; + GV *gv; + HE *he; + static char *FIELDS = "FIELDS"; + sub_generation++; + + if (mg->mg_type == 'i') + return 0; /* Ignore lower-case version of the magic */ + + stash = GvSTASH(mg->mg_obj); + svp = AvARRAY((AV*)sv); + + for (fill = AvFILL((AV*)sv); fill >= 0; fill--, svp++) { + HV *basestash = gv_stashsv(*svp, FALSE); + + if (!basestash) { + if (dowarn) + warn("No such package \"%_\" in @ISA assignment", *svp); + continue; + } + gvp = (GV**)hv_fetch(basestash, FIELDS, 6, FALSE); + if (gvp && *gvp && GvHV(*gvp)) { + if (basefields) + croak("Can't multiply inherit %%FIELDS"); + basefields = GvHV(*gvp); + } + } + + if (!basefields) + return 0; + + gv = (GV*)*hv_fetch(stash, FIELDS, 6, TRUE); + if (!isGV(gv)) + gv_init(gv, stash, FIELDS, 6, TRUE); + if (!GvHV(gv)) + GvHV(gv) = newHV(); + if (HvKEYS(GvHV(gv))) + croak("Inherited %%FIELDS can't override existing %%FIELDS"); + + hv_iterinit(GvHV(gv)); + while ((he = hv_iternext(basefields))) + hv_store(GvHV(gv), HeKEY(he), HeKLEN(he), HeVAL(he), HeHASH(he)); + return 0; } |