Navigation Menu

Skip to content

Commit

Permalink
Minor cleanups
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Gurusamy Sarathy authored and Chip Salzenberg committed Apr 2, 1997
1 parent 4a6725a commit 6097944
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 28 deletions.
31 changes: 12 additions & 19 deletions mg.c
Expand Up @@ -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

Expand All @@ -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;
Expand All @@ -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) {
Expand All @@ -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;
}

Expand All @@ -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]);
Expand All @@ -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]);
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions mg.h
Expand Up @@ -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)
8 changes: 2 additions & 6 deletions perl.c
Expand Up @@ -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
Expand All @@ -2287,24 +2287,20 @@ 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 = '=';
}
#endif
#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))
Expand Down

0 comments on commit 6097944

Please sign in to comment.