summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGurusamy Sarathy <gsar@engin.umich.edu>1997-04-03 19:56:57 -0500
committerChip Salzenberg <chip@atlantic.net>1997-04-03 10:03:25 +1200
commit609794497049cf42bdd2396c04cbb7728e10374d (patch)
tree2f2f153be578da8e2279e6e4d5750d1c828da117
parent4a6725af9146bd7faaa10aa5429ff009d393fd6d (diff)
downloadperl-609794497049cf42bdd2396c04cbb7728e10374d.tar.gz
Minor cleanups
This patch straightens out some code that used to be crooked, avoids redundant SV allocs/frees, and makes a macro more consistent. Nothing critical here. The changes in ENV_FETCH code are untested, so vox VMS populi invited. p5p-msgid: 199704040056.TAA22253@aatma.engin.umich.edu
-rw-r--r--mg.c31
-rw-r--r--mg.h6
-rw-r--r--perl.c8
3 files changed, 17 insertions, 28 deletions
diff --git a/mg.c b/mg.c
index 5b25c40d0c..b4b8e3e6cd 100644
--- a/mg.c
+++ b/mg.c
@@ -581,27 +581,20 @@ MAGIC* mg;
{
register char *s;
char *ptr;
- STRLEN len;
+ STRLEN len, klen;
I32 i;
s = SvPV(sv,len);
- ptr = MgPV(mg);
+ ptr = MgPV(mg,klen);
my_setenv(ptr, s);
#ifdef DYNAMIC_ENV_FETCH
/* We just undefd an environment var. Is a replacement */
/* waiting in the wings? */
if (!len) {
- HE *envhe;
- SV *keysv;
- if (mg->mg_len == HEf_SVKEY)
- keysv = (SV *)mg->mg_ptr;
- else
- keysv = newSVpv(mg->mg_ptr, mg->mg_len);
- if ((envhe = hv_fetch_ent(GvHVn(envgv), keysv, FALSE, 0)))
- s = SvPV(HeVAL(envhe), len);
- if (mg->mg_len != HEf_SVKEY)
- SvREFCNT_dec(keysv);
+ SV **valp;
+ if ((valp = hv_fetch(GvHVn(envgv), ptr, klen, FALSE)))
+ s = SvPV(*valp, len);
}
#endif
@@ -611,7 +604,7 @@ MAGIC* mg;
if (tainting) {
MgTAINTEDDIR_off(mg);
#ifdef VMS
- if (s && strnEQ(ptr, "DCL$PATH", 8)) {
+ if (s && klen == 8 && strEQ(ptr, "DCL$PATH")) {
char pathbuf[256], eltbuf[256], *cp, *elt = s;
struct stat sbuf;
int i = 0, j = 0;
@@ -636,7 +629,7 @@ MAGIC* mg;
} while (my_trnlnm(s, pathbuf, i++) && (elt = pathbuf));
}
#endif /* VMS */
- if (s && strEQ(ptr,"PATH")) {
+ if (s && klen == 4 && strEQ(ptr,"PATH")) {
char *strend = s + len;
while (s < strend) {
@@ -661,7 +654,7 @@ magic_clearenv(sv,mg)
SV* sv;
MAGIC* mg;
{
- my_setenv(MgPV(mg),Nullch);
+ my_setenv(MgPV(mg,na),Nullch);
return 0;
}
@@ -672,7 +665,7 @@ MAGIC* mg;
{
I32 i;
/* Are we fetching a signal entry? */
- i = whichsig(MgPV(mg));
+ i = whichsig(MgPV(mg,na));
if (i) {
if(psig_ptr[i])
sv_setsv(sv,psig_ptr[i]);
@@ -697,7 +690,7 @@ MAGIC* mg;
{
I32 i;
/* Are we clearing a signal entry? */
- i = whichsig(MgPV(mg));
+ i = whichsig(MgPV(mg,na));
if (i) {
if(psig_ptr[i]) {
SvREFCNT_dec(psig_ptr[i]);
@@ -720,7 +713,7 @@ MAGIC* mg;
I32 i;
SV** svp;
- s = MgPV(mg);
+ s = MgPV(mg,na);
if (*s == '_') {
if (strEQ(s,"__DIE__"))
svp = &diehook;
@@ -958,7 +951,7 @@ MAGIC* mg;
gv = DBline;
i = SvTRUE(sv);
svp = av_fetch(GvAV(gv),
- atoi(MgPV(mg)), FALSE);
+ atoi(MgPV(mg,na)), FALSE);
if (svp && SvIOKp(*svp) && (o = (OP*)SvSTASH(*svp)))
o->op_private = i;
else
diff --git a/mg.h b/mg.h
index c40a866795..c464746557 100644
--- a/mg.h
+++ b/mg.h
@@ -36,6 +36,6 @@ struct magic {
#define MgTAINTEDDIR_on(mg) (mg->mg_flags |= MGf_TAINTEDDIR)
#define MgTAINTEDDIR_off(mg) (mg->mg_flags &= ~MGf_TAINTEDDIR)
-#define MgPV(mg) ((mg)->mg_len == HEf_SVKEY) ? \
- SvPV((SV*)((mg)->mg_ptr),na) : \
- (mg)->mg_ptr
+#define MgPV(mg,lp) (((lp = (mg)->mg_len) == HEf_SVKEY) ? \
+ SvPV((SV*)((mg)->mg_ptr),lp) : \
+ (mg)->mg_ptr)
diff --git a/perl.c b/perl.c
index 9f06f13634..2b53a8114a 100644
--- a/perl.c
+++ b/perl.c
@@ -2278,7 +2278,7 @@ register char **env;
HV *hv;
GvMULTI_on(envgv);
hv = GvHVn(envgv);
- hv_clear(hv);
+ hv_magic(hv, envgv, 'E');
#ifndef VMS /* VMS doesn't have environ array */
/* Note that if the supplied env parameter is actually a copy
of the global environ then it may now point to free'd memory
@@ -2287,16 +2287,13 @@ register char **env;
*/
if (!env)
env = environ;
- if (env != environ) {
+ if (env != environ)
environ[0] = Nullch;
- hv_magic(hv, envgv, 'E');
- }
for (; *env; env++) {
if (!(s = strchr(*env,'=')))
continue;
*s++ = '\0';
sv = newSVpv(s--,0);
- sv_magic(sv, sv, 'e', *env, s - *env);
(void)hv_store(hv, *env, s - *env, sv, 0);
*s = '=';
}
@@ -2304,7 +2301,6 @@ register char **env;
#ifdef DYNAMIC_ENV_FETCH
HvNAME(hv) = savepv(ENV_HV_NAME);
#endif
- hv_magic(hv, envgv, 'E');
}
TAINT_NOT;
if (tmpgv = gv_fetchpv("$",TRUE, SVt_PV))