* Use the "DESTRUCTOR" scope cleanup to reinstate magic.
*/
+#ifdef PERL_OBJECT
+
+#define VTBL this->*vtbl
+
+#else
struct magic_state {
SV* mgs_sv;
U32 mgs_flags;
typedef struct magic_state MGS;
static void restore_magic _((void *p));
+#define VTBL *vtbl
-static void
-save_magic(mgs, sv)
-MGS* mgs;
-SV* sv;
+#endif
+
+STATIC void
+save_magic(MGS *mgs, SV *sv)
{
assert(SvMAGICAL(sv));
SvFLAGS(sv) |= (SvFLAGS(sv) & (SVp_IOK|SVp_NOK|SVp_POK)) >> PRIVSHIFT;
}
-static void
-restore_magic(p)
-void* p;
+STATIC void
+restore_magic(void *p)
{
MGS* mgs = (MGS*)p;
SV* sv = mgs->mgs_sv;
}
}
-
void
-mg_magical(sv)
-SV* sv;
+mg_magical(SV *sv)
{
MAGIC* mg;
for (mg = SvMAGIC(sv); mg; mg = mg->mg_moremagic) {
MGVTBL* vtbl = mg->mg_virtual;
if (vtbl) {
- if (vtbl->svt_get && !(mg->mg_flags & MGf_GSKIP))
+ if ((vtbl->svt_get != NULL) && !(mg->mg_flags & MGf_GSKIP))
SvGMAGICAL_on(sv);
if (vtbl->svt_set)
SvSMAGICAL_on(sv);
- if (!(SvFLAGS(sv) & (SVs_GMG|SVs_SMG)) || vtbl->svt_clear)
+ if (!(SvFLAGS(sv) & (SVs_GMG|SVs_SMG)) || (vtbl->svt_clear != NULL))
SvRMAGICAL_on(sv);
}
}
}
int
-mg_get(sv)
-SV* sv;
+mg_get(SV *sv)
{
MGS mgs;
MAGIC* mg;
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) && vtbl && (vtbl->svt_get != NULL)) {
+ (VTBL->svt_get)(sv, mg);
/* Ignore this magic if it's been deleted */
if ((mg == (mgp_valid ? *mgp : SvMAGIC(sv))) &&
(mg->mg_flags & MGf_GSKIP))
}
int
-mg_set(sv)
-SV* sv;
+mg_set(SV *sv)
{
MGS mgs;
MAGIC* mg;
mg->mg_flags &= ~MGf_GSKIP; /* setting requires another read */
mgs.mgs_flags = 0;
}
- if (vtbl && vtbl->svt_set)
- (*vtbl->svt_set)(sv, mg);
+ if (vtbl && (vtbl->svt_set != NULL))
+ (VTBL->svt_set)(sv, mg);
}
LEAVE;
}
U32
-mg_len(sv)
-SV* sv;
+mg_length(SV *sv)
{
MAGIC* mg;
char *junk;
for (mg = SvMAGIC(sv); mg; mg = mg->mg_moremagic) {
MGVTBL* vtbl = mg->mg_virtual;
- if (vtbl && vtbl->svt_len) {
+ if (vtbl && (vtbl->svt_len != NULL)) {
MGS mgs;
ENTER;
save_magic(&mgs, sv);
/* omit MGf_GSKIP -- not changed here */
- len = (*vtbl->svt_len)(sv, mg);
+ len = (VTBL->svt_len)(sv, mg);
LEAVE;
return len;
}
return len;
}
+I32
+mg_size(SV *sv)
+{
+ MAGIC* mg;
+ I32 len;
+
+ for (mg = SvMAGIC(sv); mg; mg = mg->mg_moremagic) {
+ MGVTBL* vtbl = mg->mg_virtual;
+ if (vtbl && (vtbl->svt_len != NULL)) {
+ MGS mgs;
+ ENTER;
+ /* omit MGf_GSKIP -- not changed here */
+ len = (VTBL->svt_len)(sv, mg);
+ LEAVE;
+ return len;
+ }
+ }
+
+ switch(SvTYPE(sv)) {
+ case SVt_PVAV:
+ len = AvFILLp((AV *) sv); /* Fallback to non-tied array */
+ return len;
+ case SVt_PVHV:
+ /* FIXME */
+ default:
+ croak("Size magic not implemented");
+ break;
+ }
+ return 0;
+}
+
int
-mg_clear(sv)
-SV* sv;
+mg_clear(SV *sv)
{
MGS mgs;
MAGIC* mg;
MGVTBL* vtbl = mg->mg_virtual;
/* omit GSKIP -- never set here */
- if (vtbl && vtbl->svt_clear)
- (*vtbl->svt_clear)(sv, mg);
+ if (vtbl && (vtbl->svt_clear != NULL))
+ (VTBL->svt_clear)(sv, mg);
}
LEAVE;
}
MAGIC*
-mg_find(sv, type)
-SV* sv;
-int type;
+mg_find(SV *sv, int type)
{
MAGIC* mg;
for (mg = SvMAGIC(sv); mg; mg = mg->mg_moremagic) {
}
int
-mg_copy(sv, nsv, key, klen)
-SV* sv;
-SV* nsv;
-char *key;
-I32 klen;
+mg_copy(SV *sv, SV *nsv, char *key, I32 klen)
{
int count = 0;
MAGIC* mg;
}
int
-mg_free(sv)
-SV* sv;
+mg_free(SV *sv)
{
MAGIC* mg;
MAGIC* moremagic;
for (mg = SvMAGIC(sv); mg; mg = moremagic) {
MGVTBL* vtbl = mg->mg_virtual;
moremagic = mg->mg_moremagic;
- if (vtbl && vtbl->svt_free)
- (*vtbl->svt_free)(sv, mg);
+ if (vtbl && (vtbl->svt_free != NULL))
+ (VTBL->svt_free)(sv, mg);
if (mg->mg_ptr && mg->mg_type != 'g')
if (mg->mg_len >= 0)
Safefree(mg->mg_ptr);
#endif
U32
-magic_len(sv, mg)
-SV *sv;
-MAGIC *mg;
+magic_len(SV *sv, MAGIC *mg)
{
+ dTHR;
register I32 paren;
register char *s;
register I32 i;
}
int
-magic_get(sv, mg)
-SV *sv;
-MAGIC *mg;
+magic_get(SV *sv, MAGIC *mg)
{
+ dTHR;
register I32 paren;
register char *s;
register I32 i;
}
#else
#ifdef OS2
- sv_setnv(sv, (double)Perl_rc);
- sv_setpv(sv, os2error(Perl_rc));
+ if (!(_emx_env & 0x200)) { /* Under DOS */
+ sv_setnv(sv, (double)errno);
+ sv_setpv(sv, errno ? Strerror(errno) : "");
+ } else {
+ if (errno != errno_isOS2)
+ Perl_rc = _syserrno();
+ sv_setnv(sv, (double)Perl_rc);
+ sv_setpv(sv, os2error(Perl_rc));
+ }
+#else
+#ifdef WIN32
+ {
+ DWORD dwErr = GetLastError();
+ sv_setnv(sv, (double)dwErr);
+ if (dwErr)
+ {
+#ifdef PERL_OBJECT
+ char *sMsg;
+ DWORD dwLen;
+ PerlProc_GetSysMsg(sMsg, dwLen, dwErr);
+ sv_setpvn(sv, sMsg, dwLen);
+ PerlProc_FreeBuf(sMsg);
+#else
+ win32_str_os_error(sv, dwErr);
+#endif
+ }
+ else
+ sv_setpv(sv, "");
+ SetLastError(dwErr);
+ }
#else
sv_setnv(sv, (double)errno);
sv_setpv(sv, errno ? Strerror(errno) : "");
#endif
#endif
+#endif
SvNOK_on(sv); /* what a wonderful hack! */
break;
case '\006': /* ^F */
case '\020': /* ^P */
sv_setiv(sv, (IV)perldb);
break;
+ case '\023': /* ^S */
+ {
+ dTHR;
+ if (lex_state != LEX_NOTPARSING)
+ SvOK_off(sv);
+ else if (in_eval)
+ sv_setiv(sv, 1);
+ else
+ sv_setiv(sv, 0);
+ }
+ break;
case '\024': /* ^T */
#ifdef BIG_TIME
sv_setnv(sv, basetime);
case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9': case '&':
if (curpm && (rx = curpm->op_pmregexp)) {
- paren = atoi(GvENAME((GV*)mg->mg_obj));
+ /*
+ * Pre-threads, this was paren = atoi(GvENAME((GV*)mg->mg_obj));
+ * XXX Does the new way break anything?
+ */
+ paren = atoi(mg->mg_ptr);
getparen:
if (paren <= rx->nparens &&
(s = rx->startp[paren]) &&
}
sv_setpvn(sv,s,i);
if (tainting)
- tainted = was_tainted || rx->exec_tainted;
+ tainted = was_tainted || RX_MATCH_TAINTED(rx);
break;
}
}
break;
case '0':
break;
+#ifdef USE_THREADS
+ case '@':
+ sv_setsv(sv, thr->errsv);
+ break;
+#endif /* USE_THREADS */
}
return 0;
}
int
-magic_getuvar(sv, mg)
-SV *sv;
-MAGIC *mg;
+magic_getuvar(SV *sv, MAGIC *mg)
{
struct ufuncs *uf = (struct ufuncs *)mg->mg_ptr;
}
int
-magic_setenv(sv,mg)
-SV* sv;
-MAGIC* mg;
+magic_setenv(SV *sv, MAGIC *mg)
{
register char *s;
char *ptr;
}
#endif
-#if !defined(OS2) && !defined(AMIGAOS) && !defined(_WIN32)
+#if !defined(OS2) && !defined(AMIGAOS) && !defined(WIN32) && !defined(MSDOS)
/* And you'll never guess what the dog had */
/* in its mouth... */
if (tainting) {
char *strend = s + len;
while (s < strend) {
+ char tmpbuf[256];
struct stat st;
- s = delimcpy(tokenbuf, tokenbuf + sizeof tokenbuf,
+ s = delimcpy(tmpbuf, tmpbuf + sizeof tmpbuf,
s, strend, ':', &i);
s++;
- if (i >= sizeof tokenbuf /* too long -- assume the worst */
- || *tokenbuf != '/'
- || (Stat(tokenbuf, &st) == 0 && (st.st_mode & 2)) ) {
+ if (i >= sizeof tmpbuf /* too long -- assume the worst */
+ || *tmpbuf != '/'
+ || (Stat(tmpbuf, &st) == 0 && (st.st_mode & 2)) ) {
MgTAINTEDDIR_on(mg);
return 0;
}
}
}
}
-#endif /* neither OS2 nor AMIGAOS nor _WIN32 */
+#endif /* neither OS2 nor AMIGAOS nor WIN32 nor MSDOS */
return 0;
}
int
-magic_clearenv(sv,mg)
-SV* sv;
-MAGIC* mg;
+magic_clearenv(SV *sv, MAGIC *mg)
{
my_setenv(MgPV(mg,na),Nullch);
return 0;
}
int
-magic_getsig(sv,mg)
-SV* sv;
-MAGIC* mg;
+magic_set_all_env(SV *sv, MAGIC *mg)
+{
+#if defined(VMS)
+ die("Can't make list assignment to %%ENV on this system");
+#else
+ dTHR;
+ if (localizing) {
+ HE* entry;
+ magic_clear_all_env(sv,mg);
+ hv_iterinit((HV*)sv);
+ while (entry = hv_iternext((HV*)sv)) {
+ I32 keylen;
+ my_setenv(hv_iterkey(entry, &keylen),
+ SvPV(hv_iterval((HV*)sv, entry), na));
+ }
+ }
+#endif
+ return 0;
+}
+
+int
+magic_clear_all_env(SV *sv, MAGIC *mg)
+{
+#if defined(VMS)
+ die("Can't make list assignment to %%ENV on this system");
+#else
+#ifdef WIN32
+ char *envv = GetEnvironmentStrings();
+ char *cur = envv;
+ STRLEN len;
+ while (*cur) {
+ char *end = strchr(cur,'=');
+ if (end && end != cur) {
+ *end = '\0';
+ my_setenv(cur,Nullch);
+ *end = '=';
+ cur += strlen(end+1)+1;
+ }
+ else if ((len = strlen(cur)))
+ cur += len+1;
+ }
+ FreeEnvironmentStrings(envv);
+#else
+ I32 i;
+
+ if (environ == origenviron)
+ New(901, environ, 1, char*);
+ else
+ for (i = 0; environ[i]; i++)
+ Safefree(environ[i]);
+ environ[0] = Nullch;
+
+#endif
+#endif
+ return 0;
+}
+
+int
+magic_getsig(SV *sv, MAGIC *mg)
{
I32 i;
/* Are we fetching a signal entry? */
if(psig_ptr[i])
sv_setsv(sv,psig_ptr[i]);
else {
- dTHR; /* just for SvREFCNT_inc */
Sighandler_t sigstate = rsignal_state(i);
/* cache state so we don't fetch it again */
return 0;
}
int
-magic_clearsig(sv,mg)
-SV* sv;
-MAGIC* mg;
+magic_clearsig(SV *sv, MAGIC *mg)
{
I32 i;
/* Are we clearing a signal entry? */
}
int
-magic_setsig(sv,mg)
-SV* sv;
-MAGIC* mg;
+magic_setsig(SV *sv, MAGIC *mg)
{
dTHR;
register char *s;
}
if (SvTYPE(sv) == SVt_PVGV || SvROK(sv)) {
if (i)
- (void)rsignal(i, sighandler);
+ (void)rsignal(i, sighandlerp);
else
*svp = SvREFCNT_inc(sv);
return 0;
if (!strchr(s,':') && !strchr(s,'\''))
sv_setpv(sv, form("main::%s", s));
if (i)
- (void)rsignal(i, sighandler);
+ (void)rsignal(i, sighandlerp);
else
*svp = SvREFCNT_inc(sv);
}
}
int
-magic_setisa(sv,mg)
-SV* sv;
-MAGIC* mg;
+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);
+
+ /* NOTE: No support for tied ISA */
+ for (fill = AvFILLp((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;
}
#ifdef OVERLOAD
int
-magic_setamagic(sv,mg)
-SV* sv;
-MAGIC* mg;
+magic_setamagic(SV *sv, MAGIC *mg)
{
/* HV_badAMAGIC_on(Sv_STASH(sv)); */
amagic_generation++;
#endif /* OVERLOAD */
int
-magic_setnkeys(sv,mg)
-SV* sv;
-MAGIC* mg;
+magic_setnkeys(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;
-MAGIC* mg;
-char *meth;
+STATIC int
+magic_methcall(MAGIC *mg, char *meth, I32 flags, int n, SV *val)
{
- dTHR;
dSP;
- ENTER;
- SAVETMPS;
PUSHMARK(sp);
- EXTEND(sp, 2);
+ EXTEND(sp, n);
PUSHs(mg->mg_obj);
- 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);
+ if (n > 1) {
+ 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)));
+ }
+ }
+ if (n > 2) {
+ PUSHs(val);
}
- else if (mg->mg_type == 'p')
- PUSHs(sv_2mortal(newSViv(mg->mg_len)));
PUTBACK;
- if (perl_call_method(meth, G_SCALAR))
+ return perl_call_method(meth, flags);
+}
+
+STATIC int
+magic_methpack(SV *sv, MAGIC *mg, char *meth)
+{
+ dSP;
+
+ ENTER;
+ SAVETMPS;
+
+ if (magic_methcall(mg, meth, G_SCALAR, 2, NULL)) {
sv_setsv(sv, *stack_sp--);
+ }
FREETMPS;
LEAVE;
}
int
-magic_getpack(sv,mg)
-SV* sv;
-MAGIC* mg;
+magic_getpack(SV *sv, MAGIC *mg)
{
magic_methpack(sv,mg,"FETCH");
if (mg->mg_ptr)
}
int
-magic_setpack(sv,mg)
-SV* sv;
-MAGIC* mg;
-{
- dTHR;
- dSP;
-
- PUSHMARK(sp);
- EXTEND(sp, 3);
- PUSHs(mg->mg_obj);
- 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);
- PUTBACK;
-
- perl_call_method("STORE", G_SCALAR|G_DISCARD);
-
+magic_setpack(SV *sv, MAGIC *mg)
+{
+ ENTER;
+ magic_methcall(mg, "STORE", G_SCALAR|G_DISCARD, 3, sv);
+ LEAVE;
return 0;
}
int
-magic_clearpack(sv,mg)
-SV* sv;
-MAGIC* mg;
+magic_clearpack(SV *sv, MAGIC *mg)
{
return magic_methpack(sv,mg,"DELETE");
}
-int magic_wipepack(sv,mg)
-SV* sv;
-MAGIC* mg;
-{
+
+U32
+magic_sizepack(SV *sv, MAGIC *mg)
+{
dTHR;
+ U32 retval = 0;
+
+ ENTER;
+ SAVETMPS;
+ if (magic_methcall(mg, "FETCHSIZE", G_SCALAR, 2, NULL)) {
+ sv = *stack_sp--;
+ retval = (U32) SvIV(sv)-1;
+ }
+ FREETMPS;
+ LEAVE;
+ return retval;
+}
+
+int magic_wipepack(SV *sv, MAGIC *mg)
+{
dSP;
PUSHMARK(sp);
XPUSHs(mg->mg_obj);
PUTBACK;
-
+ ENTER;
perl_call_method("CLEAR", G_SCALAR|G_DISCARD);
-
+ LEAVE;
return 0;
}
int
-magic_nextpack(sv,mg,key)
-SV* sv;
-MAGIC* mg;
-SV* key;
+magic_nextpack(SV *sv, MAGIC *mg, SV *key)
{
- dTHR;
dSP;
char *meth = SvOK(key) ? "NEXTKEY" : "FIRSTKEY";
}
int
-magic_existspack(sv,mg)
-SV* sv;
-MAGIC* mg;
+magic_existspack(SV *sv, MAGIC *mg)
{
return magic_methpack(sv,mg,"EXISTS");
}
int
-magic_setdbline(sv,mg)
-SV* sv;
-MAGIC* mg;
+magic_setdbline(SV *sv, MAGIC *mg)
{
dTHR;
OP *o;
}
int
-magic_getarylen(sv,mg)
-SV* sv;
-MAGIC* mg;
+magic_getarylen(SV *sv, MAGIC *mg)
{
dTHR;
sv_setiv(sv, AvFILL((AV*)mg->mg_obj) + curcop->cop_arybase);
}
int
-magic_setarylen(sv,mg)
-SV* sv;
-MAGIC* mg;
+magic_setarylen(SV *sv, MAGIC *mg)
{
dTHR;
av_fill((AV*)mg->mg_obj, SvIV(sv) - curcop->cop_arybase);
}
int
-magic_getpos(sv,mg)
-SV* sv;
-MAGIC* mg;
+magic_getpos(SV *sv, MAGIC *mg)
{
SV* lsv = LvTARG(sv);
}
int
-magic_setpos(sv,mg)
-SV* sv;
-MAGIC* mg;
+magic_setpos(SV *sv, MAGIC *mg)
{
SV* lsv = LvTARG(sv);
SSize_t pos;
}
int
-magic_getglob(sv,mg)
-SV* sv;
-MAGIC* mg;
+magic_getglob(SV *sv, MAGIC *mg)
{
if (SvFAKE(sv)) { /* FAKE globs can get coerced */
SvFAKE_off(sv);
}
int
-magic_setglob(sv,mg)
-SV* sv;
-MAGIC* mg;
+magic_setglob(SV *sv, MAGIC *mg)
{
register char *s;
GV* gv;
}
int
-magic_setsubstr(sv,mg)
-SV* sv;
-MAGIC* mg;
+magic_setsubstr(SV *sv, MAGIC *mg)
{
STRLEN len;
char *tmps = SvPV(sv,len);
}
int
-magic_gettaint(sv,mg)
-SV* sv;
-MAGIC* mg;
+magic_gettaint(SV *sv, MAGIC *mg)
{
+ dTHR;
TAINT_IF((mg->mg_len & 1) ||
(mg->mg_len & 2) && mg->mg_obj == sv); /* kludge */
return 0;
}
int
-magic_settaint(sv,mg)
-SV* sv;
-MAGIC* mg;
+magic_settaint(SV *sv, MAGIC *mg)
{
dTHR;
if (localizing) {
}
int
-magic_setvec(sv,mg)
-SV* sv;
-MAGIC* mg;
+magic_setvec(SV *sv, MAGIC *mg)
{
do_vecset(sv); /* XXX slurp this routine */
return 0;
}
int
-magic_getdefelem(sv,mg)
-SV* sv;
-MAGIC* mg;
+magic_getdefelem(SV *sv, MAGIC *mg)
{
SV *targ = Nullsv;
if (LvTARGLEN(sv)) {
targ = HeVAL(he);
}
else {
- AV* av = (AV*)LvTARG(sv);
+ AV* av = (AV*)LvTARG(sv);
if ((I32)LvTARGOFF(sv) <= AvFILL(av))
targ = AvARRAY(av)[LvTARGOFF(sv)];
}
}
int
-magic_setdefelem(sv,mg)
-SV* sv;
-MAGIC* mg;
+magic_setdefelem(SV *sv, MAGIC *mg)
{
if (LvTARGLEN(sv))
vivify_defelem(sv);
}
int
-magic_freedefelem(sv,mg)
-SV* sv;
-MAGIC* mg;
+magic_freedefelem(SV *sv, MAGIC *mg)
{
SvREFCNT_dec(LvTARG(sv));
return 0;
}
void
-vivify_defelem(sv)
-SV* sv;
+vivify_defelem(SV *sv)
{
dTHR; /* just for SvREFCNT_inc and SvREFCNT_dec*/
MAGIC* mg;
croak(no_aelem, (I32)LvTARGOFF(sv));
}
}
- SvREFCNT_inc(value);
+ (void)SvREFCNT_inc(value);
SvREFCNT_dec(LvTARG(sv));
LvTARG(sv) = value;
LvTARGLEN(sv) = 0;
}
int
-magic_setmglob(sv,mg)
-SV* sv;
-MAGIC* mg;
+magic_setmglob(SV *sv, MAGIC *mg)
{
mg->mg_len = -1;
SvSCREAM_off(sv);
}
int
-magic_setbm(sv,mg)
-SV* sv;
-MAGIC* mg;
+magic_setbm(SV *sv, MAGIC *mg)
{
sv_unmagic(sv, 'B');
SvVALID_off(sv);
}
int
-magic_setfm(sv,mg)
-SV* sv;
-MAGIC* mg;
+magic_setfm(SV *sv, MAGIC *mg)
{
sv_unmagic(sv, 'f');
SvCOMPILED_off(sv);
}
int
-magic_setuvar(sv,mg)
-SV* sv;
-MAGIC* mg;
+magic_setuvar(SV *sv, MAGIC *mg)
{
struct ufuncs *uf = (struct ufuncs *)mg->mg_ptr;
return 0;
}
+int
+magic_freeregexp(SV *sv, MAGIC *mg)
+{
+ regexp *re = (regexp *)mg->mg_obj;
+ ReREFCNT_dec(re);
+ return 0;
+}
+
#ifdef USE_LOCALE_COLLATE
int
-magic_setcollxfrm(sv,mg)
-SV* sv;
-MAGIC* mg;
+magic_setcollxfrm(SV *sv, MAGIC *mg)
{
/*
* René Descartes said "I think not."
#endif /* USE_LOCALE_COLLATE */
int
-magic_set(sv,mg)
-SV* sv;
-MAGIC* mg;
+magic_set(SV *sv, MAGIC *mg)
{
dTHR;
register char *s;
#ifdef VMS
set_vaxc_errno(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv));
#else
+#ifdef WIN32
+ SetLastError( SvIV(sv) );
+#else
/* will anyone ever use this? */
SETERRNO(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv), 4);
#endif
+#endif
break;
case '\006': /* ^F */
maxsysfd = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
osname = Nullch;
break;
case '\020': /* ^P */
- i = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
- if (i != perldb) {
- if (perldb)
- oldlastpm = curpm;
- else
- curpm = oldlastpm;
- }
- perldb = i;
+ perldb = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
break;
case '\024': /* ^T */
#ifdef BIG_TIME
(void)setresuid((Uid_t)uid, (Uid_t)-1, (Uid_t)-1);
#else
if (uid == euid) /* special case $< = $> */
- (void)setuid(uid);
+ (void)PerlProc_setuid(uid);
else {
- uid = (I32)getuid();
+ uid = (I32)PerlProc_getuid();
croak("setruid() not implemented");
}
#endif
#endif
#endif
- uid = (I32)getuid();
+ uid = (I32)PerlProc_getuid();
tainting |= (uid && (euid != uid || egid != gid));
break;
case '>':
(void)setresuid((Uid_t)-1, (Uid_t)euid, (Uid_t)-1);
#else
if (euid == uid) /* special case $> = $< */
- setuid(euid);
+ PerlProc_setuid(euid);
else {
- euid = (I32)geteuid();
+ euid = (I32)PerlProc_geteuid();
croak("seteuid() not implemented");
}
#endif
#endif
#endif
- euid = (I32)geteuid();
+ euid = (I32)PerlProc_geteuid();
tainting |= (uid && (euid != uid || egid != gid));
break;
case '(':
(void)setresgid((Gid_t)gid, (Gid_t)-1, (Gid_t) 1);
#else
if (gid == egid) /* special case $( = $) */
- (void)setgid(gid);
+ (void)PerlProc_setgid(gid);
else {
- gid = (I32)getgid();
+ gid = (I32)PerlProc_getgid();
croak("setrgid() not implemented");
}
#endif
#endif
#endif
- gid = (I32)getgid();
+ gid = (I32)PerlProc_getgid();
tainting |= (uid && (euid != uid || egid != gid));
break;
case ')':
(void)setresgid((Gid_t)-1, (Gid_t)egid, (Gid_t)-1);
#else
if (egid == gid) /* special case $) = $( */
- (void)setgid(egid);
+ (void)PerlProc_setgid(egid);
else {
- egid = (I32)getegid();
+ egid = (I32)PerlProc_getegid();
croak("setegid() not implemented");
}
#endif
#endif
#endif
- egid = (I32)getegid();
+ egid = (I32)PerlProc_getegid();
tainting |= (uid && (euid != uid || egid != gid));
break;
case ':':
s += strlen(s);
/* See if all the arguments are contiguous in memory */
for (i = 1; i < origargc; i++) {
- if (origargv[i] == s + 1)
+ if (origargv[i] == s + 1
+#ifdef OS2
+ || origargv[i] == s + 2
+#endif
+ )
s += strlen(++s); /* this one is ok too */
+ else
+ break;
}
/* can grab env area too? */
- if (origenviron && origenviron[0] == s + 1) {
- my_setenv("NoNeSuCh", Nullch);
+ if (origenviron && (origenviron[0] == s + 1
+#ifdef OS2
+ || (origenviron[0] == s + 9 && (s += 8))
+#endif
+ )) {
+ my_setenv("NoNe SuCh", Nullch);
/* force copy of environment */
for (i = 0; origenviron[i]; i++)
if (origenviron[i] == s + 1)
s += strlen(++s);
+ else
+ break;
}
origalen = s - origargv[0];
}
i = len;
if (i >= origalen) {
i = origalen;
- SvCUR_set(sv, i);
- *SvEND(sv) = '\0';
+ /* don't allow system to limit $0 seen by script */
+ /* SvCUR_set(sv, i); *SvEND(sv) = '\0'; */
Copy(s, origargv[0], i, char);
+ s = origargv[0]+i;
+ *s = '\0';
}
else {
Copy(s, origargv[0], i, char);
origargv[i] = Nullch;
}
break;
+#ifdef USE_THREADS
+ case '@':
+ sv_setsv(thr->errsv, sv);
+ break;
+#endif /* USE_THREADS */
}
return 0;
}
#ifdef USE_THREADS
int
-magic_mutexfree(sv, mg)
-SV *sv;
-MAGIC *mg;
+magic_mutexfree(SV *sv, MAGIC *mg)
{
dTHR;
DEBUG_L(PerlIO_printf(PerlIO_stderr(), "0x%lx: magic_mutexfree 0x%lx\n",
croak("panic: magic_mutexfree");
MUTEX_DESTROY(MgMUTEXP(mg));
COND_DESTROY(MgCONDP(mg));
+ SvREFCNT_dec(sv);
return 0;
}
#endif /* USE_THREADS */
I32
-whichsig(sig)
-char *sig;
+whichsig(char *sig)
{
register char **sigv;
return 0;
}
-Signal_t
-sighandler(sig)
-int sig;
+static SV* sig_sv;
+
+STATIC void
+unwind_handler_stack(void *p)
{
dTHR;
+ U32 flags = *(U32*)p;
+
+ if (flags & 1)
+ savestack_ix -= 5; /* Unprotect save in progress. */
+ /* cxstack_ix-- Not needed, die already unwound it. */
+ if (flags & 64)
+ SvREFCNT_dec(sig_sv);
+}
+
+Signal_t
+sighandler(int sig)
+{
dSP;
- GV *gv;
+ GV *gv = Nullgv;
HV *st;
- SV *sv;
- CV *cv;
+ SV *sv, *tSv = Sv;
+ CV *cv = Nullcv;
AV *oldstack;
-
+ OP *myop = op;
+ U32 flags = 0;
+ I32 o_save_i = savestack_ix, type;
+ PERL_CONTEXT *cx;
+ XPV *tXpv = Xpv;
+
+ if (savestack_ix + 15 <= savestack_max)
+ flags |= 1;
+ if (cxstack_ix < cxstack_max - 2)
+ flags |= 2;
+ if (markstack_ptr < markstack_max - 2)
+ flags |= 4;
+ if (retstack_ix < retstack_max - 2)
+ flags |= 8;
+ if (scopestack_ix < scopestack_max - 3)
+ flags |= 16;
+
+ if (flags & 2) { /* POPBLOCK may decrease cxstack too early. */
+ cxstack_ix++; /* Protect from overwrite. */
+ cx = &cxstack[cxstack_ix];
+ type = cx->cx_type; /* Can be during partial write. */
+ cx->cx_type = CXt_NULL; /* Make it safe for unwind. */
+ }
if (!psig_ptr[sig])
die("Signal SIG%s received, but no signal handler set.\n",
sig_name[sig]);
- cv = sv_2cv(psig_ptr[sig],&st,&gv,TRUE);
+ /* Max number of items pushed there is 3*n or 4. We cannot fix
+ infinity, so we fix 4 (in fact 5): */
+ if (flags & 1) {
+ savestack_ix += 5; /* Protect save in progress. */
+ o_save_i = savestack_ix;
+ SAVEDESTRUCTOR(unwind_handler_stack, (void*)&flags);
+ }
+ if (flags & 4)
+ markstack_ptr++; /* Protect mark. */
+ if (flags & 8) {
+ retstack_ix++;
+ retstack[retstack_ix] = NULL;
+ }
+ if (flags & 16)
+ scopestack_ix += 1;
+ /* sv_2cv is too complicated, try a simpler variant first: */
+ if (!SvROK(psig_ptr[sig]) || !(cv = (CV*)SvRV(psig_ptr[sig]))
+ || SvTYPE(cv) != SVt_PVCV)
+ cv = sv_2cv(psig_ptr[sig],&st,&gv,TRUE);
+
if (!cv || !CvROOT(cv)) {
if (dowarn)
warn("SIG%s handler \"%s\" not defined.\n",
- sig_name[sig], GvENAME(gv) );
- return;
+ sig_name[sig], (gv ? GvENAME(gv)
+ : ((cv && CvGV(cv))
+ ? GvENAME(CvGV(cv))
+ : "__ANON__")));
+ goto cleanup;
}
oldstack = curstack;
if (curstack != signalstack)
- AvFILL(signalstack) = 0;
+ AvFILLp(signalstack) = 0;
SWITCHSTACK(curstack, signalstack);
- if(psig_name[sig])
+ if(psig_name[sig]) {
sv = SvREFCNT_inc(psig_name[sig]);
- else {
+ flags |= 64;
+ sig_sv = sv;
+ } else {
sv = sv_newmortal();
sv_setpv(sv,sig_name[sig]);
}
perl_call_sv((SV*)cv, G_DISCARD);
SWITCHSTACK(signalstack, oldstack);
-
+cleanup:
+ if (flags & 1)
+ savestack_ix -= 8; /* Unprotect save in progress. */
+ if (flags & 2) {
+ cxstack[cxstack_ix].cx_type = type;
+ cxstack_ix -= 1;
+ }
+ if (flags & 4)
+ markstack_ptr--;
+ if (flags & 8)
+ retstack_ix--;
+ if (flags & 16)
+ scopestack_ix -= 1;
+ if (flags & 64)
+ SvREFCNT_dec(sv);
+ op = myop; /* Apparently not needed... */
+
+ Sv = tSv; /* Restore global temporaries. */
+ Xpv = tXpv;
return;
}
+
+