summaryrefslogtreecommitdiff
path: root/gv.c
diff options
context:
space:
mode:
authorPerl 5 Porters <perl5-porters@africa.nicoh.com>1997-03-01 18:40:49 +1200
committerChip Salzenberg <chip@atlantic.net>1997-03-01 18:40:49 +1200
commit9607fc9c489d4095e3baa795d7ead7acba96137d (patch)
tree2dfac2b59f20ce6d1dccd5bbdf9343c30dae8992 /gv.c
parent92112241d1458d5df77a0d57b4e82dca2637735a (diff)
downloadperl-9607fc9c489d4095e3baa795d7ead7acba96137d.tar.gz
[inseparable changes from match from perl-5.003_91 to perl-5.003_92]
CORE LANGUAGE CHANGES Subject: Strictly follow lexical context of C<eval ''> and nested subs From: Chip Salzenberg <chip@perl.com> Files: op.c Subject: Make ::SUPER and UNIVERSAL work together From: Chip Salzenberg <chip@perl.com> Files: gv.c pod/perlguts.pod CORE PORTABILITY Subject: OS/2 patches Date: Wed, 5 Mar 1997 22:08:43 -0500 (EST) From: Ilya Zakharevich <ilya@math.ohio-state.edu> Files: hints/os2.sh lib/ExtUtils/MakeMaker.pm t/op/taint.t Msg-ID: 199703060308.WAA22211@monk.mps.ohio-state.edu (applied based on p5p patch as commit eda4d5189d403b15f244b4696a710fb91d15053e) Subject: VMS patches Date: Wed, 05 Mar 1997 23:10:24 -0500 (EST) From: Charles Bailey <bailey@HMIVAX.HUMGEN.UPENN.EDU> Files: lib/ExtUtils/MM_VMS.pm lib/ExtUtils/Manifest.pm perlsdio.h t/op/runlevel.t t/op/taint.t vms/descrip.mms vms/perly_c.vms vms/sockadapt.c vms/sockadapt.h vms/vms_yfix.pl private-msgid: 01IG5SQE4A6U00661G@hmivax.humgen.upenn.edu DOCUMENTATION Subject: Add taint checks and srand to perldelta Date: Sun, 2 Mar 1997 11:56:08 -0800 (PST) From: Tom Phoenix <rootbeer@teleport.com> Files: pod/perldelta.pod Msg-ID: Pine.GSO.3.95q.970302115355.23058D-100000@kelly.teleport.com (applied based on p5p patch as commit b28e0bc0aa3232e18d1bacb3efcbfb755ad100e0) Subject: Don't call FileHandle 'deprecated' From: Chip Salzenberg <chip@perl.com> Files: pod/perldelta.pod Subject: Improve sample module header Date: Sat, 01 Mar 1997 10:32:31 -0700 From: Tom Christiansen <tchrist@jhereg.perl.com> Files: pod/perlmod.pod Msg-ID: 199703011732.KAA14693@jhereg.perl.com (applied based on p5p patch as commit 3e1e15658152387f41e00ded4796cede4e1e10d3) Subject: Update list of CPAN sites Date: Sun, 2 Mar 1997 16:54:22 +0200 (EET) From: Jarkko Hietaniemi <jhi@iki.fi> Files: pod/perlmod.pod Msg-ID: 199703021454.QAA07446@alpha.hut.fi (applied based on p5p patch as commit 9423903e60e6c92c1893f5f4cab2476f403f8a4b) Subject: Enhance description of 'server error' Date: Tue, 4 Feb 1997 21:03:23 +0200 (EET) From: Jarkko Hietaniemi <jhi@cc.hut.fi> Files: pod/perldiag.pod private-msgid: 199702041903.VAA16070@alpha.hut.fi Subject: Regularize format of E-Mail addresses in *.pod From: Chip Salzenberg <chip@perl.com> Files: pod/*.pod LIBRARY AND EXTENSIONS Subject: Use IV instead of double for tms structure members From: Chip Salzenberg <chip@perl.com> Files: ext/POSIX/POSIX.xs OTHER CORE CHANGES Subject: Make sure $^X is tainted when ARG_ZERO_IS_SCRIPT From: Chip Salzenberg <chip@perl.com> Files: toke.c Subject: Clarify '-T too late' error From: Chip Salzenberg <chip@perl.com> Files: perl.c pod/perldiag.pod Subject: Warn when redefining or undefining a constant sub From: Chip Salzenberg <chip@perl.com> Files: pod/perldiag.pod pp.c sv.c Subject: Don't generate spurious 'not imported' warning From: Chip Salzenberg <chip@perl.com> Files: gv.c t/pragma/strict-vars pod/perldiag.pod Subject: Clarify message re: @host in string From: Chip Salzenberg <chip@perl.com> Files: pod/perldiag.pod pod/perltrap.pod toke.c Subject: Disconnect refs that are targets of pp_readline From: Chip Salzenberg <chip@perl.com> Files: pp_hot.c Subject: Fix typo in test of HvFILL() From: Chip Salzenberg <chip@perl.com> Files: op.c Subject: Allow for pad name array to be shorter than pad array From: Chip Salzenberg <chip@perl.com> Files: op.c Subject: Eliminate format-string type warnings Date: Mon, 3 Mar 1997 10:15:11 +0100 (MET) From: Hallvard B Furuseth <h.b.furuseth@usit.uio.no> Files: doio.c ext/POSIX/POSIX.xs gv.c hints/dec_osf.sh pp.c pp_ctl.c pp_hot.c run.c sv.c x2p/a2py.c private-msgid: 199703030915.KAA11634@bombur2.uio.no Subject: Update copyright dates From: Chip Salzenberg <chip@perl.com> Files: *.[hc] x2p/*.[hc] win32/EXTERN.h vms/vmsish.h vms/vms.c TESTS Subject: Smarter t/op/taint.t Date: Mon, 3 Mar 1997 10:31:54 -0800 (PST) From: Tom Phoenix <rootbeer@teleport.com> Files: t/op/taint.t private-msgid: Pine.GSO.3.95q.970303103047.24000A-100000@kelly.teleport.com Subject: Fix taint test for systems without csh From: Chip Salzenberg <chip@perl.com> Files: t/op/taint.t
Diffstat (limited to 'gv.c')
-rw-r--r--gv.c114
1 files changed, 56 insertions, 58 deletions
diff --git a/gv.c b/gv.c
index 67b2600bfe..cc520d6247 100644
--- a/gv.c
+++ b/gv.c
@@ -1,6 +1,6 @@
/* gv.c
*
- * Copyright (c) 1991-1994, Larry Wall
+ * Copyright (c) 1991-1997, Larry Wall
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
@@ -131,7 +131,6 @@ I32 level;
GV* topgv;
GV* gv;
GV** gvp;
- HV* lastchance;
CV* cv;
if (!stash)
@@ -159,8 +158,33 @@ I32 level;
}
}
- gvp = (GV**)hv_fetch(stash,"ISA",3,FALSE);
- if (gvp && (gv = *gvp) != (GV*)&sv_undef && (av = GvAV(gv))) {
+ gvp = (GV**)hv_fetch(stash, "ISA", 3, FALSE);
+ av = (gvp && (gv = *gvp) && gv != (GV*)&sv_undef) ? GvAV(gv) : Nullav;
+
+ /* create @.*::SUPER::ISA on demand */
+ if (!av) {
+ char* packname = HvNAME(stash);
+ STRLEN packlen = strlen(packname);
+
+ if (packlen >= 7 && strEQ(packname + packlen - 7, "::SUPER")) {
+ HV* basestash;
+
+ packlen -= 7;
+ basestash = gv_stashpvn(packname, packlen, TRUE);
+ gvp = (GV**)hv_fetch(basestash, "ISA", 3, FALSE);
+ if (gvp && (gv = *gvp) != (GV*)&sv_undef && (av = GvAV(gv))) {
+ gvp = (GV**)hv_fetch(stash, "ISA", 3, TRUE);
+ if (!gvp || !(gv = *gvp))
+ croak("Cannot create %s::ISA", HvNAME(stash));
+ if (SvTYPE(gv) != SVt_PVGV)
+ gv_init(gv, stash, "ISA", 3, TRUE);
+ SvREFCNT_dec(GvAV(gv));
+ GvAV(gv) = (AV*)SvREFCNT_inc(av);
+ }
+ }
+ }
+
+ if (av) {
SV** svp = AvARRAY(av);
I32 items = AvFILL(av) + 1;
while (items--) {
@@ -179,7 +203,11 @@ I32 level;
}
}
+ /* if at top level, try UNIVERSAL */
+
if (level == 0 || level == -1) {
+ HV* lastchance;
+
if (lastchance = gv_stashpvn("UNIVERSAL", 9, FALSE)) {
if (gv = gv_fetchmeth(lastchance, name, len,
(level >= 0) ? level + 1 : level - 1)) {
@@ -209,67 +237,29 @@ char* name;
GV* gv;
for (nend = name; *nend; nend++) {
- if (*nend == ':' || *nend == '\'')
+ if (*nend == '\'')
nsplit = nend;
+ else if (*nend == ':' && *(nend + 1) == ':')
+ nsplit = ++nend;
}
if (nsplit) {
- char ch;
char *origname = name;
name = nsplit + 1;
- ch = *nsplit;
if (*nsplit == ':')
--nsplit;
- *nsplit = '\0';
- if (strEQ(origname,"SUPER")) {
- /* Degenerate case ->SUPER::method should really lookup in original stash */
- SV *tmpstr = sv_2mortal(newSVpv(HvNAME(curcop->cop_stash),0));
+ if ((nsplit - origname) == 5 && strnEQ(origname, "SUPER", 5)) {
+ /* ->SUPER::method should really be looked up in original stash */
+ SV *tmpstr = sv_2mortal(newSVpv(HvNAME(curcop->cop_stash), 0));
sv_catpvn(tmpstr, "::SUPER", 7);
- stash = gv_stashpvn(SvPVX(tmpstr),SvCUR(tmpstr),TRUE);
- *nsplit = ch;
- DEBUG_o( deb("Treating %s as %s::%s\n",origname,HvNAME(stash),name) );
- } else {
- stash = gv_stashpvn(origname, nsplit - origname, TRUE);
- *nsplit = ch;
+ stash = gv_stashpvn(SvPVX(tmpstr), SvCUR(tmpstr), TRUE);
+ DEBUG_o( deb("Treating %s as %s::%s\n",
+ origname, HvNAME(stash), name) );
}
- }
- gv = gv_fetchmeth(stash, name, nend - name, 0);
-
- if (!gv) {
- /* Failed obvious case - look for SUPER as last element of stash's name */
- char *packname = HvNAME(stash);
- STRLEN len = strlen(packname);
- if (len >= 7 && strEQ(packname+len-7,"::SUPER")) {
- /* Now look for @.*::SUPER::ISA */
- GV** gvp = (GV**)hv_fetch(stash,"ISA",3,FALSE);
- len -= 7;
- if (!gvp || (gv = *gvp) == (GV*)&sv_undef || !GvAV(gv)) {
- /* No @ISA in package ending in ::SUPER - drop suffix
- and see if there is an @ISA there
- */
- HV *basestash;
- char ch = packname[len];
- AV *av;
- packname[len] = '\0';
- basestash = gv_stashpvn(packname, len, TRUE);
- packname[len] = ch;
- gvp = (GV**)hv_fetch(basestash,"ISA",3,FALSE);
- if (gvp && (gv = *gvp) != (GV*)&sv_undef && (av = GvAV(gv))) {
- /* Okay found @ISA after dropping the SUPER, alias it */
- SV *tmpstr = sv_2mortal(newSVpv(HvNAME(stash),0));
- sv_catpvn(tmpstr, "::ISA", 5);
- gv = gv_fetchpv(SvPV(tmpstr,na),TRUE,SVt_PVGV);
- if (gv) {
- GvAV(gv) = (AV*)SvREFCNT_inc(av);
- /* ... and re-try lookup */
- gv = gv_fetchmeth(stash, name, nend - name, 0);
- } else {
- croak("Cannot create %s::ISA",HvNAME(stash));
- }
- }
- }
- }
+ else
+ stash = gv_stashpvn(origname, nsplit - origname, TRUE);
}
+ gv = gv_fetchmeth(stash, name, nend - name, 0);
if (!gv) {
if (strEQ(name,"import"))
gv = (GV*)&sv_yes;
@@ -383,7 +373,7 @@ I32 sv_type;
I32 len;
register char *namend;
HV *stash = 0;
- bool global = FALSE;
+ U32 add_gvflags = 0;
char *tmpbuf;
if (*name == '*' && isALPHA(name[1])) /* accidental stringify on a GV? */
@@ -441,6 +431,8 @@ I32 sv_type;
if (!stash) {
if (isIDFIRST(*name)) {
+ bool global = FALSE;
+
if (isUPPER(*name)) {
if (*name > 'I') {
if (*name == 'S' && (
@@ -465,6 +457,7 @@ I32 sv_type;
}
else if (*name == '_' && !name[1])
global = TRUE;
+
if (global)
stash = defstash;
else if ((COP*)curcop == &compiling) {
@@ -511,6 +504,10 @@ I32 sv_type;
warn("Global symbol \"%s\" requires explicit package name", name);
++error_count;
stash = curstash ? curstash : defstash; /* avoid core dumps */
+ add_gvflags = ((sv_type == SVt_PV) ? GVf_IMPORTED_SV
+ : (sv_type == SVt_PVAV) ? GVf_IMPORTED_AV
+ : (sv_type == SVt_PVHV) ? GVf_IMPORTED_HV
+ : 0);
}
else
return Nullgv;
@@ -537,6 +534,7 @@ I32 sv_type;
warn("Had to create %s unexpectedly", nambeg);
gv_init(gv, stash, name, len, add & 2);
gv_init_sv(gv, sv_type);
+ GvFLAGS(gv) |= add_gvflags;
/* set up magic where warranted */
switch (*name) {
@@ -997,13 +995,13 @@ HV* stash;
{
int filled = 0;
int i;
- char *cp;
+ const char *cp;
SV* sv = NULL;
SV** svp;
/* Work with "fallback" key, which we assume to be first in AMG_names */
- if ( cp = (char *)AMG_names[0] ) {
+ if ( cp = AMG_names[0] ) {
/* Try to find via inheritance. */
gv = gv_fetchmeth(stash, "()", 2, -1); /* A cookie: "()". */
if (gv) sv = GvSV(gv);
@@ -1015,7 +1013,7 @@ HV* stash;
for (i = 1; i < NofAMmeth; i++) {
cv = 0;
- cp = (char *)AMG_names[i];
+ cp = AMG_names[i];
*buf = '('; /* A cookie: "(". */
strcpy(buf + 1, cp);