#include "EXTERN.h"
#include "perl.h"
-/* Omit -- it causes too much grief on mixed systems.
+/* XXX If this causes problems, set i_unistd=undef in the hint file. */
#ifdef I_UNISTD
# include <unistd.h>
#endif
-*/
+
+#ifdef HAS_GETGROUPS
+# ifndef NGROUPS
+# define NGROUPS 32
+# endif
+#endif
+
+/*
+ * Use the "DESTRUCTOR" scope cleanup to reinstate magic.
+ */
+
+struct magic_state {
+ SV* mgs_sv;
+ U32 mgs_flags;
+};
+typedef struct magic_state MGS;
+
+static void restore_magic _((void *p));
+
+static void
+save_magic(mgs, sv)
+MGS* mgs;
+SV* sv;
+{
+ assert(SvMAGICAL(sv));
+
+ mgs->mgs_sv = sv;
+ mgs->mgs_flags = SvMAGICAL(sv) | SvREADONLY(sv);
+ SAVEDESTRUCTOR(restore_magic, mgs);
+
+ SvMAGICAL_off(sv);
+ SvREADONLY_off(sv);
+ SvFLAGS(sv) |= (SvFLAGS(sv) & (SVp_IOK|SVp_NOK|SVp_POK)) >> PRIVSHIFT;
+}
+
+static void
+restore_magic(p)
+void* p;
+{
+ MGS* mgs = (MGS*)p;
+ SV* sv = mgs->mgs_sv;
+
+ if (SvTYPE(sv) >= SVt_PVMG && SvMAGIC(sv))
+ {
+ if (mgs->mgs_flags)
+ SvFLAGS(sv) |= mgs->mgs_flags;
+ else
+ mg_magical(sv);
+ if (SvGMAGICAL(sv))
+ SvFLAGS(sv) &= ~(SVf_IOK|SVf_NOK|SVf_POK);
+ }
+}
void
mg_get(sv)
SV* sv;
{
+ MGS mgs;
MAGIC* mg;
- U32 savemagic = SvMAGICAL(sv) | SvREADONLY(sv);
+ MAGIC** mgp;
+ int mgp_valid = 0;
- assert(SvGMAGICAL(sv));
- SvMAGICAL_off(sv);
- SvREADONLY_off(sv);
- SvFLAGS(sv) |= (SvFLAGS(sv) & (SVp_IOK|SVp_NOK|SVp_POK)) >> PRIVSHIFT;
+ ENTER;
+ save_magic(&mgs, sv);
- for (mg = SvMAGIC(sv); mg; mg = mg->mg_moremagic) {
+ mgp = &SvMAGIC(sv);
+ while ((mg = *mgp) != 0) {
MGVTBL* vtbl = mg->mg_virtual;
if (!(mg->mg_flags & MGf_GSKIP) && vtbl && vtbl->svt_get) {
(*vtbl->svt_get)(sv, mg);
- if (mg->mg_flags & MGf_GSKIP)
- savemagic = 0;
+ /* Ignore this magic if it's been deleted */
+ if ((mg == (mgp_valid ? *mgp : SvMAGIC(sv))) &&
+ (mg->mg_flags & MGf_GSKIP))
+ mgs.mgs_flags = 0;
}
+ /* Advance to next magic (complicated by possible deletion) */
+ if (mg == (mgp_valid ? *mgp : SvMAGIC(sv))) {
+ mgp = &mg->mg_moremagic;
+ mgp_valid = 1;
+ }
+ else
+ mgp = &SvMAGIC(sv); /* Re-establish pointer after sv_upgrade */
}
- if (savemagic)
- SvFLAGS(sv) |= savemagic;
- else
- mg_magical(sv);
- if (SvGMAGICAL(sv))
- SvFLAGS(sv) &= ~(SVf_IOK|SVf_NOK|SVf_POK);
-
+ LEAVE;
return 0;
}
mg_set(sv)
SV* sv;
{
+ MGS mgs;
MAGIC* mg;
MAGIC* nextmg;
- U32 savemagic = SvMAGICAL(sv);
- SvMAGICAL_off(sv);
- SvFLAGS(sv) |= (SvFLAGS(sv) & (SVp_IOK|SVp_NOK|SVp_POK)) >> PRIVSHIFT;
+ ENTER;
+ save_magic(&mgs, sv);
for (mg = SvMAGIC(sv); mg; mg = nextmg) {
MGVTBL* vtbl = mg->mg_virtual;
nextmg = mg->mg_moremagic; /* it may delete itself */
if (mg->mg_flags & MGf_GSKIP) {
mg->mg_flags &= ~MGf_GSKIP; /* setting requires another read */
- savemagic = 0;
+ mgs.mgs_flags = 0;
}
if (vtbl && vtbl->svt_set)
(*vtbl->svt_set)(sv, mg);
}
- if (SvMAGIC(sv)) {
- if (savemagic)
- SvFLAGS(sv) |= savemagic;
- else
- mg_magical(sv);
- if (SvGMAGICAL(sv))
- SvFLAGS(sv) &= ~(SVf_IOK|SVf_NOK|SVf_POK);
- }
-
+ LEAVE;
return 0;
}
for (mg = SvMAGIC(sv); mg; mg = mg->mg_moremagic) {
MGVTBL* vtbl = mg->mg_virtual;
if (vtbl && vtbl->svt_len) {
- U32 savemagic = SvMAGICAL(sv);
-
- SvMAGICAL_off(sv);
- SvFLAGS(sv) |= (SvFLAGS(sv)&(SVp_IOK|SVp_NOK|SVp_POK)) >> PRIVSHIFT;
+ MGS mgs;
+ ENTER;
+ save_magic(&mgs, sv);
/* omit MGf_GSKIP -- not changed here */
len = (*vtbl->svt_len)(sv, mg);
-
- SvFLAGS(sv) |= savemagic;
- if (SvGMAGICAL(sv))
- SvFLAGS(sv) &= ~(SVf_IOK|SVf_NOK|SVf_POK);
-
+ LEAVE;
return len;
}
}
mg_clear(sv)
SV* sv;
{
+ MGS mgs;
MAGIC* mg;
- U32 savemagic = SvMAGICAL(sv);
- SvMAGICAL_off(sv);
- SvFLAGS(sv) |= (SvFLAGS(sv) & (SVp_IOK|SVp_NOK|SVp_POK)) >> PRIVSHIFT;
+ ENTER;
+ save_magic(&mgs, sv);
for (mg = SvMAGIC(sv); mg; mg = mg->mg_moremagic) {
MGVTBL* vtbl = mg->mg_virtual;
(*vtbl->svt_clear)(sv, mg);
}
- SvFLAGS(sv) |= savemagic;
- if (SvGMAGICAL(sv))
- SvFLAGS(sv) &= ~(SVf_IOK|SVf_NOK|SVf_POK);
-
+ LEAVE;
return 0;
}
SV* sv;
SV* nsv;
char *key;
-STRLEN klen;
+I32 klen;
{
int count = 0;
MAGIC* mg;
if (vtbl && vtbl->svt_free)
(*vtbl->svt_free)(sv, mg);
if (mg->mg_ptr && mg->mg_type != 'g')
- Safefree(mg->mg_ptr);
+ if (mg->mg_len >= 0)
+ Safefree(mg->mg_ptr);
+ else if (mg->mg_len == HEf_SVKEY)
+ SvREFCNT_dec((SV*)mg->mg_ptr);
if (mg->mg_flags & MGf_REFCOUNTED)
SvREFCNT_dec(mg->mg_obj);
Safefree(mg);
register I32 paren;
register char *s;
register I32 i;
+ register REGEXP *rx;
char *t;
switch (*mg->mg_ptr) {
case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9': case '&':
- if (curpm) {
+ if (curpm && (rx = curpm->op_pmregexp)) {
paren = atoi(mg->mg_ptr);
getparen:
- if (curpm->op_pmregexp &&
- paren <= curpm->op_pmregexp->nparens &&
- (s = curpm->op_pmregexp->startp[paren]) &&
- (t = curpm->op_pmregexp->endp[paren]) ) {
+ if (paren <= rx->nparens &&
+ (s = rx->startp[paren]) &&
+ (t = rx->endp[paren]))
+ {
i = t - s;
if (i >= 0)
return i;
return 0;
break;
case '+':
- if (curpm) {
- paren = curpm->op_pmregexp->lastparen;
- if (!paren)
- return 0;
- goto getparen;
+ if (curpm && (rx = curpm->op_pmregexp)) {
+ paren = rx->lastparen;
+ if (paren)
+ goto getparen;
}
return 0;
break;
case '`':
- if (curpm) {
- if (curpm->op_pmregexp &&
- (s = curpm->op_pmregexp->subbeg) ) {
- i = curpm->op_pmregexp->startp[0] - s;
+ if (curpm && (rx = curpm->op_pmregexp)) {
+ if ((s = rx->subbeg) && rx->startp[0]) {
+ i = rx->startp[0] - s;
if (i >= 0)
return i;
}
}
return 0;
case '\'':
- if (curpm) {
- if (curpm->op_pmregexp &&
- (s = curpm->op_pmregexp->endp[0]) ) {
- return (STRLEN) (curpm->op_pmregexp->subend - s);
+ if (curpm && (rx = curpm->op_pmregexp)) {
+ if (rx->subend && (s = rx->endp[0])) {
+ i = rx->subend - s;
+ if (i >= 0)
+ return 0;
}
}
return 0;
register I32 paren;
register char *s;
register I32 i;
+ register REGEXP *rx;
char *t;
switch (*mg->mg_ptr) {
sv_setsv(sv, bodytarget);
break;
case '\004': /* ^D */
- sv_setiv(sv,(I32)(debug & 32767));
+ sv_setiv(sv, (IV)(debug & 32767));
+ break;
+ case '\005': /* ^E */
+#ifdef VMS
+ {
+# include <descrip.h>
+# include <starlet.h>
+ char msg[255];
+ $DESCRIPTOR(msgdsc,msg);
+ sv_setnv(sv,(double) vaxc$errno);
+ if (sys$getmsg(vaxc$errno,&msgdsc.dsc$w_length,&msgdsc,0,0) & 1)
+ sv_setpvn(sv,msgdsc.dsc$a_pointer,msgdsc.dsc$w_length);
+ else
+ sv_setpv(sv,"");
+ }
+#else
+#ifdef OS2
+ sv_setnv(sv, (double)Perl_rc);
+ sv_setpv(sv, os2error(Perl_rc));
+#else
+ sv_setnv(sv, (double)errno);
+ sv_setpv(sv, errno ? Strerror(errno) : "");
+#endif
+#endif
+ SvNOK_on(sv); /* what a wonderful hack! */
break;
case '\006': /* ^F */
- sv_setiv(sv,(I32)maxsysfd);
+ sv_setiv(sv, (IV)maxsysfd);
break;
case '\010': /* ^H */
- sv_setiv(sv,(I32)hints);
+ sv_setiv(sv, (IV)hints);
break;
case '\t': /* ^I */
if (inplace)
sv_setpv(sv, inplace);
else
- sv_setsv(sv,&sv_undef);
+ sv_setsv(sv, &sv_undef);
+ break;
+ case '\017': /* ^O */
+ sv_setpv(sv, osname);
break;
case '\020': /* ^P */
- sv_setiv(sv,(I32)perldb);
+ sv_setiv(sv, (IV)perldb);
break;
case '\024': /* ^T */
- sv_setiv(sv,(I32)basetime);
+#ifdef BIG_TIME
+ sv_setnv(sv, basetime);
+#else
+ sv_setiv(sv, (IV)basetime);
+#endif
break;
case '\027': /* ^W */
- sv_setiv(sv,(I32)dowarn);
+ sv_setiv(sv, (IV)dowarn);
break;
case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9': case '&':
- if (curpm) {
- paren = atoi(GvENAME(mg->mg_obj));
+ if (curpm && (rx = curpm->op_pmregexp)) {
+ paren = atoi(GvENAME((GV*)mg->mg_obj));
getparen:
- if (curpm->op_pmregexp &&
- paren <= curpm->op_pmregexp->nparens &&
- (s = curpm->op_pmregexp->startp[paren]) &&
- (t = curpm->op_pmregexp->endp[paren]) ) {
+ if (paren <= rx->nparens &&
+ (s = rx->startp[paren]) &&
+ (t = rx->endp[paren]))
+ {
i = t - s;
+ getrx:
if (i >= 0) {
- MAGIC *tmg;
+ bool was_tainted;
+ if (tainting) {
+ was_tainted = tainted;
+ tainted = FALSE;
+ }
sv_setpvn(sv,s,i);
- if (tainting && (tmg = mg_find(sv,'t')))
- tmg->mg_len = 0; /* guarantee $1 untainted */
+ if (tainting)
+ tainted = was_tainted || rx->exec_tainted;
break;
}
}
sv_setsv(sv,&sv_undef);
break;
case '+':
- if (curpm) {
- paren = curpm->op_pmregexp->lastparen;
+ if (curpm && (rx = curpm->op_pmregexp)) {
+ paren = rx->lastparen;
if (paren)
goto getparen;
}
sv_setsv(sv,&sv_undef);
break;
case '`':
- if (curpm) {
- if (curpm->op_pmregexp &&
- (s = curpm->op_pmregexp->subbeg) ) {
- i = curpm->op_pmregexp->startp[0] - s;
- if (i >= 0) {
- sv_setpvn(sv,s,i);
- break;
- }
+ if (curpm && (rx = curpm->op_pmregexp)) {
+ if ((s = rx->subbeg) && rx->startp[0]) {
+ i = rx->startp[0] - s;
+ goto getrx;
}
}
sv_setsv(sv,&sv_undef);
break;
case '\'':
- if (curpm) {
- if (curpm->op_pmregexp &&
- (s = curpm->op_pmregexp->endp[0]) ) {
- sv_setpvn(sv,s, curpm->op_pmregexp->subend - s);
- break;
+ if (curpm && (rx = curpm->op_pmregexp)) {
+ if (rx->subend && (s = rx->endp[0])) {
+ i = rx->subend - s;
+ goto getrx;
}
}
sv_setsv(sv,&sv_undef);
case '.':
#ifndef lint
if (GvIO(last_in_gv)) {
- sv_setiv(sv,(I32)IoLINES(GvIO(last_in_gv)));
+ sv_setiv(sv, (IV)IoLINES(GvIO(last_in_gv)));
}
#endif
break;
case '?':
- sv_setiv(sv,(I32)statusvalue);
+ sv_setiv(sv, (IV)STATUS_CURRENT);
+#ifdef COMPLEX_STATUS
+ LvTARGOFF(sv) = statusvalue;
+ LvTARGLEN(sv) = statusvalue_vms;
+#endif
break;
case '^':
s = IoTOP_NAME(GvIOp(defoutgv));
break;
#ifndef lint
case '=':
- sv_setiv(sv,(I32)IoPAGE_LEN(GvIOp(defoutgv)));
+ sv_setiv(sv, (IV)IoPAGE_LEN(GvIOp(defoutgv)));
break;
case '-':
- sv_setiv(sv,(I32)IoLINES_LEFT(GvIOp(defoutgv)));
+ sv_setiv(sv, (IV)IoLINES_LEFT(GvIOp(defoutgv)));
break;
case '%':
- sv_setiv(sv,(I32)IoPAGE(GvIOp(defoutgv)));
+ sv_setiv(sv, (IV)IoPAGE(GvIOp(defoutgv)));
break;
#endif
case ':':
case '/':
break;
case '[':
- sv_setiv(sv,(I32)curcop->cop_arybase);
+ sv_setiv(sv, (IV)curcop->cop_arybase);
break;
case '|':
- sv_setiv(sv, (IoFLAGS(GvIOp(defoutgv)) & IOf_FLUSH) != 0 );
+ sv_setiv(sv, (IV)(IoFLAGS(GvIOp(defoutgv)) & IOf_FLUSH) != 0 );
break;
case ',':
sv_setpvn(sv,ofs,ofslen);
sv_setpv(sv,ofmt);
break;
case '!':
- sv_setnv(sv,(double)errno);
+#ifdef VMS
+ sv_setnv(sv, (double)((errno == EVMSERR) ? vaxc$errno : errno));
+ sv_setpv(sv, errno ? Strerror(errno) : "");
+#else
+ {
+ int saveerrno = errno;
+ sv_setnv(sv, (double)errno);
+#ifdef OS2
+ if (errno == errno_isOS2) sv_setpv(sv, os2error(Perl_rc));
+ else
+#endif
sv_setpv(sv, errno ? Strerror(errno) : "");
+ errno = saveerrno;
+ }
+#endif
SvNOK_on(sv); /* what a wonderful hack! */
break;
case '<':
- sv_setiv(sv,(I32)uid);
+ sv_setiv(sv, (IV)uid);
break;
case '>':
- sv_setiv(sv,(I32)euid);
+ sv_setiv(sv, (IV)euid);
break;
case '(':
+ sv_setiv(sv, (IV)gid);
s = buf;
(void)sprintf(s,"%d",(int)gid);
goto add_groups;
case ')':
+ sv_setiv(sv, (IV)egid);
s = buf;
(void)sprintf(s,"%d",(int)egid);
add_groups:
while (*s) s++;
#ifdef HAS_GETGROUPS
-#ifndef NGROUPS
-#define NGROUPS 32
-#endif
{
Groups_t gary[NGROUPS];
i = getgroups(NGROUPS,gary);
while (--i >= 0) {
- (void)sprintf(s," %ld", (long)gary[i]);
+ (void)sprintf(s," %d", (int)gary[i]);
while (*s) s++;
}
}
#endif
sv_setpv(sv,buf);
+ SvIOK_on(sv); /* what a wonderful hack! */
break;
case '*':
break;
MAGIC* mg;
{
register char *s;
+ char *ptr;
STRLEN len;
I32 i;
s = SvPV(sv,len);
- my_setenv(mg->mg_ptr,s);
+ ptr = MgPV(mg);
+ my_setenv(ptr, s);
#ifdef DYNAMIC_ENV_FETCH
/* We just undefd an environment var. Is a replacement */
/* waiting in the wings? */
if (!len) {
- SV **envsvp;
- if (envsvp = hv_fetch(GvHVn(envgv),mg->mg_ptr,mg->mg_len,FALSE))
- s = SvPV(*envsvp,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);
}
#endif
/* And you'll never guess what the dog had */
/* in its mouth... */
if (tainting) {
- if (s && strEQ(mg->mg_ptr,"PATH")) {
+ if (s && strEQ(ptr,"PATH")) {
char *strend = s + len;
while (s < strend) {
SV* sv;
MAGIC* mg;
{
- my_setenv(mg->mg_ptr,Nullch);
+ my_setenv(MgPV(mg),Nullch);
return 0;
}
-#ifdef HAS_SIGACTION
-/* set up reliable signal() clone */
-
-typedef void (*Sigfunc) _((int));
-
-static
-Sigfunc rsignal(signo,handler)
-int signo;
-Sigfunc handler;
+int
+magic_getsig(sv,mg)
+SV* sv;
+MAGIC* mg;
{
- struct sigaction act,oact;
-
- act.sa_handler = handler;
- sigemptyset(&act.sa_mask);
- act.sa_flags = 0;
-#ifdef SIGALRM
- if (signo == SIGALRM) {
-#else
- if (0) {
-#endif
-#ifdef SA_INTERRUPT
- act.sa_flags |= SA_INTERRUPT; /* SunOS */
-#endif
- } else {
-#ifdef SA_RESTART
- act.sa_flags |= SA_RESTART; /* SVR4, 4.3+BSD */
-#endif
+ I32 i;
+ /* Are we fetching a signal entry? */
+ i = whichsig(MgPV(mg));
+ if (i) {
+ if(psig_ptr[i])
+ sv_setsv(sv,psig_ptr[i]);
+ else {
+ Sighandler_t sigstate = rsignal_state(i);
+
+ /* cache state so we don't fetch it again */
+ if(sigstate == SIG_IGN)
+ sv_setpv(sv,"IGNORE");
+ else
+ sv_setsv(sv,&sv_undef);
+ psig_ptr[i] = SvREFCNT_inc(sv);
+ SvTEMP_off(sv);
+ }
}
- if (sigaction(signo, &act, &oact) < 0)
- return(SIG_ERR);
- else
- return(oact.sa_handler);
+ return 0;
+}
+int
+magic_clearsig(sv,mg)
+SV* sv;
+MAGIC* mg;
+{
+ I32 i;
+ /* Are we clearing a signal entry? */
+ i = whichsig(MgPV(mg));
+ if (i) {
+ if(psig_ptr[i]) {
+ SvREFCNT_dec(psig_ptr[i]);
+ psig_ptr[i]=0;
+ }
+ if(psig_name[i]) {
+ SvREFCNT_dec(psig_name[i]);
+ psig_name[i]=0;
+ }
+ }
+ return 0;
}
-
-#else
-
-/* ah well, so much for reliability */
-
-#define rsignal(x,y) signal(x,y)
-
-#endif
-
int
magic_setsig(sv,mg)
I32 i;
SV** svp;
- s = mg->mg_ptr;
+ s = MgPV(mg);
if (*s == '_') {
if (strEQ(s,"__DIE__"))
svp = &diehook;
warn("No such signal: SIG%s", s);
return 0;
}
+ SvREFCNT_dec(psig_name[i]);
+ SvREFCNT_dec(psig_ptr[i]);
+ psig_ptr[i] = SvREFCNT_inc(sv);
+ SvTEMP_off(sv); /* Make sure it doesn't go away on us */
+ psig_name[i] = newSVpv(s, strlen(s));
+ SvREADONLY_on(psig_name[i]);
}
if (SvTYPE(sv) == SVt_PVGV || SvROK(sv)) {
if (i)
- (void)rsignal(i,sighandler);
+ (void)rsignal(i, sighandler);
else
*svp = SvREFCNT_inc(sv);
return 0;
s = SvPV_force(sv,na);
if (strEQ(s,"IGNORE")) {
if (i)
- (void)rsignal(i,SIG_IGN);
+ (void)rsignal(i, SIG_IGN);
else
*svp = 0;
}
else if (strEQ(s,"DEFAULT") || !*s) {
if (i)
- (void)rsignal(i,SIG_DFL);
+ (void)rsignal(i, SIG_DFL);
else
*svp = 0;
}
else {
+ if(hints & HINT_STRICT_REFS)
+ die(no_symref,s,"a subroutine");
if (!strchr(s,':') && !strchr(s,'\'')) {
sprintf(tokenbuf, "main::%s",s);
sv_setpv(sv,tokenbuf);
}
if (i)
- (void)rsignal(i,sighandler);
+ (void)rsignal(i, sighandler);
else
*svp = SvREFCNT_inc(sv);
}
}
#endif /* OVERLOAD */
+int
+magic_setnkeys(sv,mg)
+SV* sv;
+MAGIC* mg;
+{
+ if (LvTARG(sv)) {
+ hv_ksplit((HV*)LvTARG(sv), SvIV(sv));
+ LvTARG(sv) = Nullsv; /* Don't allow a ref to reassign this. */
+ }
+ return 0;
+}
+
static int
magic_methpack(sv,mg,meth)
SV* sv;
PUSHMARK(sp);
EXTEND(sp, 2);
PUSHs(mg->mg_obj);
- if (mg->mg_ptr)
- PUSHs(sv_2mortal(newSVpv(mg->mg_ptr, mg->mg_len)));
+ if (mg->mg_ptr) {
+ if (mg->mg_len >= 0)
+ PUSHs(sv_2mortal(newSVpv(mg->mg_ptr, mg->mg_len)));
+ else if (mg->mg_len == HEf_SVKEY)
+ PUSHs((SV*)mg->mg_ptr);
+ }
else if (mg->mg_type == 'p')
PUSHs(sv_2mortal(newSViv(mg->mg_len)));
PUTBACK;
PUSHMARK(sp);
EXTEND(sp, 3);
PUSHs(mg->mg_obj);
- if (mg->mg_ptr)
- PUSHs(sv_2mortal(newSVpv(mg->mg_ptr, mg->mg_len)));
+ if (mg->mg_ptr) {
+ if (mg->mg_len >= 0)
+ PUSHs(sv_2mortal(newSVpv(mg->mg_ptr, mg->mg_len)));
+ else if (mg->mg_len == HEf_SVKEY)
+ PUSHs((SV*)mg->mg_ptr);
+ }
else if (mg->mg_type == 'p')
PUSHs(sv_2mortal(newSViv(mg->mg_len)));
PUSHs(sv);
gv = DBline;
i = SvTRUE(sv);
- svp = av_fetch(GvAV(gv),atoi(mg->mg_ptr), FALSE);
+ svp = av_fetch(GvAV(gv),
+ atoi(MgPV(mg)), FALSE);
if (svp && SvIOKp(*svp) && (o = (OP*)SvSTASH(*svp)))
o->op_private = i;
else
else if (pos > len)
pos = len;
mg->mg_len = pos;
+ mg->mg_flags &= ~MGf_MINMATCH;
return 0;
}
SV* sv;
MAGIC* mg;
{
- gv_efullname(sv,((GV*)sv));/* a gv value, be nice */
+ if (SvFAKE(sv)) { /* FAKE globs can get coerced */
+ SvFAKE_off(sv);
+ gv_efullname3(sv,((GV*)sv), "*");
+ SvFAKE_on(sv);
+ }
+ else
+ gv_efullname3(sv,((GV*)sv), "*"); /* a gv value, be nice */
return 0;
}
if (sv == (SV*)gv)
return 0;
if (GvGP(sv))
- gp_free(sv);
+ gp_free((GV*)sv);
GvGP(sv) = gp_ref(GvGP(gv));
- if (!GvAV(gv))
- gv_AVadd(gv);
- if (!GvHV(gv))
- gv_HVadd(gv);
- if (!GvIOp(gv))
- GvIOp(gv) = newIO();
return 0;
}
SV* sv;
MAGIC* mg;
{
- if (mg->mg_len & 1)
- tainted = TRUE;
- else if (mg->mg_len & 2 && mg->mg_obj == sv) /* kludge */
- tainted = TRUE;
+ TAINT_IF((mg->mg_len & 1) ||
+ (mg->mg_len & 2) && mg->mg_obj == sv); /* kludge */
return 0;
}
}
int
+magic_getitervar(sv,mg)
+SV* sv;
+MAGIC* mg;
+{
+ SV *targ = Nullsv;
+ if (LvTARGLEN(sv)) {
+ AV* av = (AV*)LvTARG(sv);
+ if (LvTARGOFF(sv) <= AvFILL(av))
+ targ = AvARRAY(av)[LvTARGOFF(sv)];
+ }
+ else
+ targ = LvTARG(sv);
+ sv_setsv(sv, targ ? targ : &sv_undef);
+ return 0;
+}
+
+int
+magic_setitervar(sv,mg)
+SV* sv;
+MAGIC* mg;
+{
+ if (LvTARGLEN(sv))
+ vivify_itervar(sv);
+ if (LvTARG(sv))
+ sv_setsv(LvTARG(sv), sv);
+ return 0;
+}
+
+int
+magic_freeitervar(sv,mg)
+SV* sv;
+MAGIC* mg;
+{
+ SvREFCNT_dec(LvTARG(sv));
+ return 0;
+}
+
+void
+vivify_itervar(sv)
+SV* sv;
+{
+ AV* av;
+
+ if (!LvTARGLEN(sv))
+ return;
+ av = (AV*)LvTARG(sv);
+ if (LvTARGOFF(sv) <= AvFILL(av)) {
+ SV** svp = AvARRAY(av) + LvTARGOFF(sv);
+ LvTARG(sv) = newSVsv(*svp);
+ SvREFCNT_dec(*svp);
+ *svp = SvREFCNT_inc(LvTARG(sv));
+ }
+ else
+ LvTARG(sv) = Nullsv;
+ SvREFCNT_dec(av);
+ LvTARGLEN(sv) = 0;
+}
+
+int
magic_setmglob(sv,mg)
SV* sv;
MAGIC* mg;
{
mg->mg_len = -1;
+ SvSCREAM_off(sv);
return 0;
}
}
int
+magic_setfm(sv,mg)
+SV* sv;
+MAGIC* mg;
+{
+ sv_unmagic(sv, 'f');
+ SvCOMPILED_off(sv);
+ return 0;
+}
+
+int
magic_setuvar(sv,mg)
SV* sv;
MAGIC* mg;
return 0;
}
+#ifdef USE_LOCALE_COLLATE
+int
+magic_setcollxfrm(sv,mg)
+SV* sv;
+MAGIC* mg;
+{
+ /*
+ * René Descartes said "I think not."
+ * and vanished with a faint plop.
+ */
+ if (mg->mg_ptr) {
+ Safefree(mg->mg_ptr);
+ mg->mg_ptr = NULL;
+ mg->mg_len = -1;
+ }
+ return 0;
+}
+#endif /* USE_LOCALE_COLLATE */
+
int
magic_set(sv,mg)
SV* sv;
debug = (SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv)) | 0x80000000;
DEBUG_x(dump_all());
break;
+ case '\005': /* ^E */
+#ifdef VMS
+ set_vaxc_errno(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv));
+#else
+ /* will anyone ever use this? */
+ SETERRNO(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv), 4);
+#endif
+ break;
case '\006': /* ^F */
maxsysfd = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
break;
else
inplace = Nullch;
break;
+ case '\017': /* ^O */
+ if (osname)
+ Safefree(osname);
+ if (SvOK(sv))
+ osname = savepv(SvPV(sv,na));
+ else
+ osname = Nullch;
+ break;
case '\020': /* ^P */
i = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
if (i != perldb) {
perldb = i;
break;
case '\024': /* ^T */
+#ifdef BIG_TIME
+ basetime = (Time_t)(SvNOK(sv) ? SvNVX(sv) : sv_2nv(sv));
+#else
basetime = (Time_t)(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv));
+#endif
break;
case '\027': /* ^W */
dowarn = (bool)(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv));
if (localizing == 1)
save_sptr((SV**)&last_in_gv);
}
- else if (SvOK(sv))
+ else if (SvOK(sv) && GvIO(last_in_gv))
IoLINES(GvIOp(last_in_gv)) = (long)SvIV(sv);
break;
case '^':
multiline = (i != 0);
break;
case '/':
- if (SvOK(sv)) {
- nrs = rs = SvPV_force(sv,rslen);
- nrslen = rslen;
- if (rspara = !rslen) {
- nrs = rs = "\n\n";
- nrslen = rslen = 2;
- }
- nrschar = rschar = rs[rslen - 1];
- }
- else {
- nrschar = rschar = 0777; /* fake a non-existent char */
- nrslen = rslen = 1;
- }
+ SvREFCNT_dec(nrs);
+ nrs = newSVsv(sv);
+ SvREFCNT_dec(rs);
+ rs = SvREFCNT_inc(nrs);
break;
case '\\':
if (ors)
Safefree(ors);
- ors = savepv(SvPV(sv,orslen));
+ if (SvOK(sv) || SvGMAGICAL(sv))
+ ors = savepv(SvPV(sv,orslen));
+ else {
+ ors = Nullch;
+ orslen = 0;
+ }
break;
case ',':
if (ofs)
compiling.cop_arybase = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
break;
case '?':
- statusvalue = FIXSTATUS(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv));
+#ifdef COMPLEX_STATUS
+ if (localizing == 2) {
+ statusvalue = LvTARGOFF(sv);
+ statusvalue_vms = LvTARGLEN(sv);
+ }
+ else
+#endif
+#ifdef VMSISH_STATUS
+ if (VMSISH_STATUS)
+ STATUS_NATIVE_SET((U32)(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv)));
+ else
+#endif
+ STATUS_POSIX_SET(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv));
break;
case '!':
- SETERRNO(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv),SS$_ABORT); /* will anyone ever use this? */
+ SETERRNO(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv),
+ (SvIV(sv) == EVMSERR) ? 4 : vaxc$errno);
break;
case '<':
uid = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
if (origargv[i] == s + 1)
s += strlen(++s); /* this one is ok too */
}
- if (origenviron[0] == s + 1) { /* can grab env area too? */
+ /* can grab env area too? */
+ if (origenviron && origenviron[0] == s + 1) {
my_setenv("NoNeSuCh", Nullch);
/* force copy of environment */
for (i = 0; origenviron[i]; i++)
SV *sv;
CV *cv;
AV *oldstack;
- char *signame;
-#ifdef OS2 /* or anybody else who requires SIG_ACK */
- signal(sig, SIG_ACK);
-#endif
+ if (!psig_ptr[sig])
+ die("Signal SIG%s received, but no signal handler set.\n",
+ sig_name[sig]);
- signame = sig_name[sig];
- cv = sv_2cv(*hv_fetch(GvHVn(siggv),signame,strlen(signame),
- TRUE),
- &st, &gv, TRUE);
- if (!cv || !CvROOT(cv) &&
- *signame == 'C' && instr(signame,"LD")) {
-
- if (signame[1] == 'H')
- cv = sv_2cv(*hv_fetch(GvHVn(siggv),"CLD",3,TRUE),
- &st, &gv, TRUE);
- else
- cv = sv_2cv(*hv_fetch(GvHVn(siggv),"CHLD",4,TRUE),
- &st, &gv, TRUE);
- /* gag */
- }
+ cv = sv_2cv(psig_ptr[sig],&st,&gv,TRUE);
if (!cv || !CvROOT(cv)) {
if (dowarn)
warn("SIG%s handler \"%s\" not defined.\n",
- signame, GvENAME(gv) );
+ sig_name[sig], GvENAME(gv) );
return;
}
- oldstack = stack;
- if (stack != signalstack)
+ oldstack = curstack;
+ if (curstack != signalstack)
AvFILL(signalstack) = 0;
- SWITCHSTACK(stack, signalstack);
+ SWITCHSTACK(curstack, signalstack);
- sv = sv_newmortal();
- sv_setpv(sv,signame);
+ if(psig_name[sig])
+ sv = SvREFCNT_inc(psig_name[sig]);
+ else {
+ sv = sv_newmortal();
+ sv_setpv(sv,sig_name[sig]);
+ }
PUSHMARK(sp);
PUSHs(sv);
PUTBACK;