3 * Copyright (c) 1991-1999, Larry Wall
5 * You may distribute under the terms of either the GNU General Public
6 * License or the Artistic License, as specified in the README file.
11 * "Sam sat on the ground and put his head in his hands. 'I wish I had never
12 * come here, and I don't want to see no more magic,' he said, and fell silent."
19 /* XXX If this causes problems, set i_unistd=undef in the hint file. */
24 #if defined(HAS_GETGROUPS) || defined(HAS_SETGROUPS)
30 static void restore_magic(pTHXo_ void *p);
31 static void unwind_handler_stack(pTHXo_ void *p);
34 * Use the "DESTRUCTOR" scope cleanup to reinstate magic.
42 /* MGS is typedef'ed to struct magic_state in perl.h */
45 S_save_magic(pTHX_ I32 mgs_ix, SV *sv)
49 assert(SvMAGICAL(sv));
51 SAVEDESTRUCTOR_X(restore_magic, (void*)mgs_ix);
53 mgs = SSPTR(mgs_ix, MGS*);
55 mgs->mgs_flags = SvMAGICAL(sv) | SvREADONLY(sv);
56 mgs->mgs_ss_ix = PL_savestack_ix; /* points after the saved destructor */
60 SvFLAGS(sv) |= (SvFLAGS(sv) & (SVp_IOK|SVp_NOK|SVp_POK)) >> PRIVSHIFT;
64 Perl_mg_magical(pTHX_ SV *sv)
67 for (mg = SvMAGIC(sv); mg; mg = mg->mg_moremagic) {
68 MGVTBL* vtbl = mg->mg_virtual;
70 if (vtbl->svt_get && !(mg->mg_flags & MGf_GSKIP))
74 if (!(SvFLAGS(sv) & (SVs_GMG|SVs_SMG)) || vtbl->svt_clear)
81 Perl_mg_get(pTHX_ SV *sv)
89 mgs_ix = SSNEW(sizeof(MGS));
90 save_magic(mgs_ix, sv);
93 while ((mg = *mgp) != 0) {
94 MGVTBL* vtbl = mg->mg_virtual;
95 if (!(mg->mg_flags & MGf_GSKIP) && vtbl && vtbl->svt_get) {
96 CALL_FPTR(vtbl->svt_get)(aTHX_ sv, mg);
97 /* Ignore this magic if it's been deleted */
98 if ((mg == (mgp_valid ? *mgp : SvMAGIC(sv))) &&
99 (mg->mg_flags & MGf_GSKIP))
100 (SSPTR(mgs_ix, MGS*))->mgs_flags = 0;
102 /* Advance to next magic (complicated by possible deletion) */
103 if (mg == (mgp_valid ? *mgp : SvMAGIC(sv))) {
104 mgp = &mg->mg_moremagic;
108 mgp = &SvMAGIC(sv); /* Re-establish pointer after sv_upgrade */
111 restore_magic(aTHXo_ (void*)mgs_ix);
116 Perl_mg_set(pTHX_ SV *sv)
123 mgs_ix = SSNEW(sizeof(MGS));
124 save_magic(mgs_ix, sv);
126 for (mg = SvMAGIC(sv); mg; mg = nextmg) {
127 MGVTBL* vtbl = mg->mg_virtual;
128 nextmg = mg->mg_moremagic; /* it may delete itself */
129 if (mg->mg_flags & MGf_GSKIP) {
130 mg->mg_flags &= ~MGf_GSKIP; /* setting requires another read */
131 (SSPTR(mgs_ix, MGS*))->mgs_flags = 0;
133 if (vtbl && vtbl->svt_set)
134 CALL_FPTR(vtbl->svt_set)(aTHX_ sv, mg);
137 restore_magic(aTHXo_ (void*)mgs_ix);
142 Perl_mg_length(pTHX_ SV *sv)
148 for (mg = SvMAGIC(sv); mg; mg = mg->mg_moremagic) {
149 MGVTBL* vtbl = mg->mg_virtual;
150 if (vtbl && vtbl->svt_len) {
153 mgs_ix = SSNEW(sizeof(MGS));
154 save_magic(mgs_ix, sv);
155 /* omit MGf_GSKIP -- not changed here */
156 len = CALL_FPTR(vtbl->svt_len)(aTHX_ sv, mg);
157 restore_magic(aTHXo_ (void*)mgs_ix);
162 junk = SvPV(sv, len);
167 Perl_mg_size(pTHX_ SV *sv)
172 for (mg = SvMAGIC(sv); mg; mg = mg->mg_moremagic) {
173 MGVTBL* vtbl = mg->mg_virtual;
174 if (vtbl && vtbl->svt_len) {
177 mgs_ix = SSNEW(sizeof(MGS));
178 save_magic(mgs_ix, sv);
179 /* omit MGf_GSKIP -- not changed here */
180 len = CALL_FPTR(vtbl->svt_len)(aTHX_ sv, mg);
181 restore_magic(aTHXo_ (void*)mgs_ix);
188 len = AvFILLp((AV *) sv); /* Fallback to non-tied array */
193 Perl_croak(aTHX_ "Size magic not implemented");
200 Perl_mg_clear(pTHX_ SV *sv)
205 mgs_ix = SSNEW(sizeof(MGS));
206 save_magic(mgs_ix, sv);
208 for (mg = SvMAGIC(sv); mg; mg = mg->mg_moremagic) {
209 MGVTBL* vtbl = mg->mg_virtual;
210 /* omit GSKIP -- never set here */
212 if (vtbl && vtbl->svt_clear)
213 CALL_FPTR(vtbl->svt_clear)(aTHX_ sv, mg);
216 restore_magic(aTHXo_ (void*)mgs_ix);
221 Perl_mg_find(pTHX_ SV *sv, int type)
224 for (mg = SvMAGIC(sv); mg; mg = mg->mg_moremagic) {
225 if (mg->mg_type == type)
232 Perl_mg_copy(pTHX_ SV *sv, SV *nsv, const char *key, I32 klen)
236 for (mg = SvMAGIC(sv); mg; mg = mg->mg_moremagic) {
237 if (isUPPER(mg->mg_type)) {
239 mg->mg_type == 'P' ? SvTIED_obj(sv, mg) : mg->mg_obj,
240 toLOWER(mg->mg_type), key, klen);
248 Perl_mg_free(pTHX_ SV *sv)
252 for (mg = SvMAGIC(sv); mg; mg = moremagic) {
253 MGVTBL* vtbl = mg->mg_virtual;
254 moremagic = mg->mg_moremagic;
255 if (vtbl && vtbl->svt_free)
256 CALL_FPTR(vtbl->svt_free)(aTHX_ sv, mg);
257 if (mg->mg_ptr && mg->mg_type != 'g')
259 Safefree(mg->mg_ptr);
260 else if (mg->mg_len == HEf_SVKEY)
261 SvREFCNT_dec((SV*)mg->mg_ptr);
262 if (mg->mg_flags & MGf_REFCOUNTED)
263 SvREFCNT_dec(mg->mg_obj);
270 #if !defined(NSIG) || defined(M_UNIX) || defined(M_XENIX)
275 Perl_magic_regdata_cnt(pTHX_ SV *sv, MAGIC *mg)
283 if (PL_curpm && (rx = PL_curpm->op_pmregexp)) {
284 if (mg->mg_obj) /* @+ */
287 return rx->lastparen;
294 Perl_magic_regdatum_get(pTHX_ SV *sv, MAGIC *mg)
303 if (PL_curpm && (rx = PL_curpm->op_pmregexp)) {
307 if (paren <= rx->nparens &&
308 (s = rx->startp[paren]) != -1 &&
309 (t = rx->endp[paren]) != -1)
311 if (mg->mg_obj) /* @+ */
322 Perl_magic_len(pTHX_ SV *sv, MAGIC *mg)
331 switch (*mg->mg_ptr) {
332 case '1': case '2': case '3': case '4':
333 case '5': case '6': case '7': case '8': case '9': case '&':
334 if (PL_curpm && (rx = PL_curpm->op_pmregexp)) {
337 paren = atoi(mg->mg_ptr);
339 if (paren <= rx->nparens &&
340 (s1 = rx->startp[paren]) != -1 &&
341 (t1 = rx->endp[paren]) != -1)
350 if (PL_curpm && (rx = PL_curpm->op_pmregexp)) {
351 paren = rx->lastparen;
357 if (PL_curpm && (rx = PL_curpm->op_pmregexp)) {
358 if (rx->startp[0] != -1) {
366 if (PL_curpm && (rx = PL_curpm->op_pmregexp)) {
367 if (rx->endp[0] != -1) {
368 i = rx->sublen - rx->endp[0];
375 return (STRLEN)PL_ofslen;
377 return (STRLEN)PL_orslen;
380 if (!SvPOK(sv) && SvNIOK(sv)) {
390 Perl_magic_get(pTHX_ SV *sv, MAGIC *mg)
399 switch (*mg->mg_ptr) {
400 case '\001': /* ^A */
401 sv_setsv(sv, PL_bodytarget);
403 case '\003': /* ^C */
404 sv_setiv(sv, (IV)PL_minus_c);
407 case '\004': /* ^D */
408 sv_setiv(sv, (IV)(PL_debug & 32767));
410 case '\005': /* ^E */
413 # include <descrip.h>
414 # include <starlet.h>
416 $DESCRIPTOR(msgdsc,msg);
417 sv_setnv(sv,(NV) vaxc$errno);
418 if (sys$getmsg(vaxc$errno,&msgdsc.dsc$w_length,&msgdsc,0,0) & 1)
419 sv_setpvn(sv,msgdsc.dsc$a_pointer,msgdsc.dsc$w_length);
425 if (!(_emx_env & 0x200)) { /* Under DOS */
426 sv_setnv(sv, (NV)errno);
427 sv_setpv(sv, errno ? Strerror(errno) : "");
429 if (errno != errno_isOS2) {
430 int tmp = _syserrno();
431 if (tmp) /* 2nd call to _syserrno() makes it 0 */
434 sv_setnv(sv, (NV)Perl_rc);
435 sv_setpv(sv, os2error(Perl_rc));
440 DWORD dwErr = GetLastError();
441 sv_setnv(sv, (NV)dwErr);
444 PerlProc_GetOSError(sv, dwErr);
451 sv_setnv(sv, (NV)errno);
452 sv_setpv(sv, errno ? Strerror(errno) : "");
456 SvNOK_on(sv); /* what a wonderful hack! */
458 case '\006': /* ^F */
459 sv_setiv(sv, (IV)PL_maxsysfd);
461 case '\010': /* ^H */
462 sv_setiv(sv, (IV)PL_hints);
464 case '\011': /* ^I */ /* NOT \t in EBCDIC */
466 sv_setpv(sv, PL_inplace);
468 sv_setsv(sv, &PL_sv_undef);
470 case '\017': /* ^O */
471 sv_setpv(sv, PL_osname);
473 case '\020': /* ^P */
474 sv_setiv(sv, (IV)PL_perldb);
476 case '\023': /* ^S */
479 if (PL_lex_state != LEX_NOTPARSING)
487 case '\024': /* ^T */
489 sv_setnv(sv, PL_basetime);
491 sv_setiv(sv, (IV)PL_basetime);
494 case '\027': /* ^W & $^Warnings*/
495 if (*(mg->mg_ptr+1) == '\0')
496 sv_setiv(sv, (IV)((PL_dowarn & G_WARN_ON) ? TRUE : FALSE));
497 else if (strEQ(mg->mg_ptr, "\027arnings")) {
498 if (PL_compiling.cop_warnings == WARN_NONE ||
499 PL_compiling.cop_warnings == WARN_STD)
501 sv_setpvn(sv, WARN_NONEstring, WARNsize) ;
503 else if (PL_compiling.cop_warnings == WARN_ALL) {
504 sv_setpvn(sv, WARN_ALLstring, WARNsize) ;
507 sv_setsv(sv, PL_compiling.cop_warnings);
511 case '1': case '2': case '3': case '4':
512 case '5': case '6': case '7': case '8': case '9': case '&':
513 if (PL_curpm && (rx = PL_curpm->op_pmregexp)) {
517 * Pre-threads, this was paren = atoi(GvENAME((GV*)mg->mg_obj));
518 * XXX Does the new way break anything?
520 paren = atoi(mg->mg_ptr);
522 if (paren <= rx->nparens &&
523 (s1 = rx->startp[paren]) != -1 &&
524 (t1 = rx->endp[paren]) != -1)
532 was_tainted = PL_tainted;
537 PL_tainted = (was_tainted || RX_MATCH_TAINTED(rx));
542 sv_setsv(sv,&PL_sv_undef);
545 if (PL_curpm && (rx = PL_curpm->op_pmregexp)) {
546 paren = rx->lastparen;
550 sv_setsv(sv,&PL_sv_undef);
553 if (PL_curpm && (rx = PL_curpm->op_pmregexp)) {
554 if ((s = rx->subbeg) && rx->startp[0] != -1) {
559 sv_setsv(sv,&PL_sv_undef);
562 if (PL_curpm && (rx = PL_curpm->op_pmregexp)) {
563 if (rx->subbeg && rx->endp[0] != -1) {
564 s = rx->subbeg + rx->endp[0];
565 i = rx->sublen - rx->endp[0];
569 sv_setsv(sv,&PL_sv_undef);
573 if (GvIO(PL_last_in_gv)) {
574 sv_setiv(sv, (IV)IoLINES(GvIO(PL_last_in_gv)));
580 sv_setiv(sv, (IV)STATUS_CURRENT);
581 #ifdef COMPLEX_STATUS
582 LvTARGOFF(sv) = PL_statusvalue;
583 LvTARGLEN(sv) = PL_statusvalue_vms;
588 s = IoTOP_NAME(GvIOp(PL_defoutgv));
592 sv_setpv(sv,GvENAME(PL_defoutgv));
597 s = IoFMT_NAME(GvIOp(PL_defoutgv));
599 s = GvENAME(PL_defoutgv);
604 sv_setiv(sv, (IV)IoPAGE_LEN(GvIOp(PL_defoutgv)));
607 sv_setiv(sv, (IV)IoLINES_LEFT(GvIOp(PL_defoutgv)));
610 sv_setiv(sv, (IV)IoPAGE(GvIOp(PL_defoutgv)));
618 WITH_THR(sv_setiv(sv, (IV)PL_curcop->cop_arybase));
621 sv_setiv(sv, (IV)(IoFLAGS(GvIOp(PL_defoutgv)) & IOf_FLUSH) != 0 );
624 sv_setpvn(sv,PL_ofs,PL_ofslen);
627 sv_setpvn(sv,PL_ors,PL_orslen);
630 sv_setpv(sv,PL_ofmt);
634 sv_setnv(sv, (NV)((errno == EVMSERR) ? vaxc$errno : errno));
635 sv_setpv(sv, errno ? Strerror(errno) : "");
638 int saveerrno = errno;
639 sv_setnv(sv, (NV)errno);
641 if (errno == errno_isOS2 || errno == errno_isOS2_set)
642 sv_setpv(sv, os2error(Perl_rc));
645 sv_setpv(sv, errno ? Strerror(errno) : "");
649 SvNOK_on(sv); /* what a wonderful hack! */
652 sv_setiv(sv, (IV)PL_uid);
655 sv_setiv(sv, (IV)PL_euid);
658 sv_setiv(sv, (IV)PL_gid);
659 Perl_sv_setpvf(aTHX_ sv, "%"Gid_t_f, PL_gid);
662 sv_setiv(sv, (IV)PL_egid);
663 Perl_sv_setpvf(aTHX_ sv, "%"Gid_t_f, PL_egid);
667 Groups_t gary[NGROUPS];
668 i = getgroups(NGROUPS,gary);
670 Perl_sv_catpvf(aTHX_ sv, " %"Gid_t_f, gary[i]);
673 SvIOK_on(sv); /* what a wonderful hack! */
681 sv_setsv(sv, thr->errsv);
683 #endif /* USE_THREADS */
689 Perl_magic_getuvar(pTHX_ SV *sv, MAGIC *mg)
691 struct ufuncs *uf = (struct ufuncs *)mg->mg_ptr;
693 if (uf && uf->uf_val)
694 (*uf->uf_val)(uf->uf_index, sv);
699 Perl_magic_setenv(pTHX_ SV *sv, MAGIC *mg)
710 #ifdef DYNAMIC_ENV_FETCH
711 /* We just undefd an environment var. Is a replacement */
712 /* waiting in the wings? */
715 if ((valp = hv_fetch(GvHVn(PL_envgv), ptr, klen, FALSE)))
716 s = SvPV(*valp, len);
720 #if !defined(OS2) && !defined(AMIGAOS) && !defined(WIN32) && !defined(MSDOS)
721 /* And you'll never guess what the dog had */
722 /* in its mouth... */
724 MgTAINTEDDIR_off(mg);
726 if (s && klen == 8 && strEQ(ptr, "DCL$PATH")) {
727 char pathbuf[256], eltbuf[256], *cp, *elt = s;
731 do { /* DCL$PATH may be a search list */
732 while (1) { /* as may dev portion of any element */
733 if ( ((cp = strchr(elt,'[')) || (cp = strchr(elt,'<'))) ) {
734 if ( *(cp+1) == '.' || *(cp+1) == '-' ||
735 cando_by_name(S_IWUSR,0,elt) ) {
740 if ((cp = strchr(elt, ':')) != Nullch)
742 if (my_trnlnm(elt, eltbuf, j++))
748 } while (my_trnlnm(s, pathbuf, i++) && (elt = pathbuf));
751 if (s && klen == 4 && strEQ(ptr,"PATH")) {
752 char *strend = s + len;
757 s = delimcpy(tmpbuf, tmpbuf + sizeof tmpbuf,
760 if (i >= sizeof tmpbuf /* too long -- assume the worst */
762 || (PerlLIO_stat(tmpbuf, &st) == 0 && (st.st_mode & 2)) ) {
769 #endif /* neither OS2 nor AMIGAOS nor WIN32 nor MSDOS */
775 Perl_magic_clearenv(pTHX_ SV *sv, MAGIC *mg)
778 my_setenv(MgPV(mg,n_a),Nullch);
783 Perl_magic_set_all_env(pTHX_ SV *sv, MAGIC *mg)
786 Perl_die(aTHX_ "Can't make list assignment to %%ENV on this system");
792 magic_clear_all_env(sv,mg);
793 hv_iterinit((HV*)sv);
794 while (entry = hv_iternext((HV*)sv)) {
796 my_setenv(hv_iterkey(entry, &keylen),
797 SvPV(hv_iterval((HV*)sv, entry), n_a));
805 Perl_magic_clear_all_env(pTHX_ SV *sv, MAGIC *mg)
808 Perl_die(aTHX_ "Can't make list assignment to %%ENV on this system");
811 char *envv = GetEnvironmentStrings();
815 char *end = strchr(cur,'=');
816 if (end && end != cur) {
818 my_setenv(cur,Nullch);
820 cur = end + strlen(end+1)+2;
822 else if ((len = strlen(cur)))
825 FreeEnvironmentStrings(envv);
829 for (i = 0; environ[i]; i++)
830 Safefree(environ[i]);
832 # ifndef PERL_USE_SAFE_PUTENV
835 if (environ == PL_origenviron)
836 environ = (char**)safesysmalloc(sizeof(char*));
838 for (i = 0; environ[i]; i++)
839 safesysfree(environ[i]);
840 # endif /* PERL_USE_SAFE_PUTENV */
851 Perl_magic_getsig(pTHX_ SV *sv, MAGIC *mg)
855 /* Are we fetching a signal entry? */
856 i = whichsig(MgPV(mg,n_a));
859 sv_setsv(sv,PL_psig_ptr[i]);
861 Sighandler_t sigstate = rsignal_state(i);
863 /* cache state so we don't fetch it again */
864 if(sigstate == SIG_IGN)
865 sv_setpv(sv,"IGNORE");
867 sv_setsv(sv,&PL_sv_undef);
868 PL_psig_ptr[i] = SvREFCNT_inc(sv);
875 Perl_magic_clearsig(pTHX_ SV *sv, MAGIC *mg)
879 /* Are we clearing a signal entry? */
880 i = whichsig(MgPV(mg,n_a));
883 SvREFCNT_dec(PL_psig_ptr[i]);
886 if(PL_psig_name[i]) {
887 SvREFCNT_dec(PL_psig_name[i]);
895 Perl_magic_setsig(pTHX_ SV *sv, MAGIC *mg)
905 if (strEQ(s,"__DIE__"))
907 else if (strEQ(s,"__WARN__"))
910 Perl_croak(aTHX_ "No such hook: %s", s);
918 i = whichsig(s); /* ...no, a brick */
920 if (ckWARN(WARN_SIGNAL) || strEQ(s,"ALARM"))
921 Perl_warner(aTHX_ WARN_SIGNAL, "No such signal: SIG%s", s);
924 SvREFCNT_dec(PL_psig_name[i]);
925 SvREFCNT_dec(PL_psig_ptr[i]);
926 PL_psig_ptr[i] = SvREFCNT_inc(sv);
927 SvTEMP_off(sv); /* Make sure it doesn't go away on us */
928 PL_psig_name[i] = newSVpvn(s, len);
929 SvREADONLY_on(PL_psig_name[i]);
931 if (SvTYPE(sv) == SVt_PVGV || SvROK(sv)) {
933 (void)rsignal(i, PL_sighandlerp);
935 *svp = SvREFCNT_inc(sv);
938 s = SvPV_force(sv,len);
939 if (strEQ(s,"IGNORE")) {
941 (void)rsignal(i, SIG_IGN);
945 else if (strEQ(s,"DEFAULT") || !*s) {
947 (void)rsignal(i, SIG_DFL);
953 * We should warn if HINT_STRICT_REFS, but without
954 * access to a known hint bit in a known OP, we can't
955 * tell whether HINT_STRICT_REFS is in force or not.
957 if (!strchr(s,':') && !strchr(s,'\''))
958 sv_insert(sv, 0, 0, "main::", 6);
960 (void)rsignal(i, PL_sighandlerp);
962 *svp = SvREFCNT_inc(sv);
968 Perl_magic_setisa(pTHX_ SV *sv, MAGIC *mg)
975 Perl_magic_setamagic(pTHX_ SV *sv, MAGIC *mg)
977 /* HV_badAMAGIC_on(Sv_STASH(sv)); */
978 PL_amagic_generation++;
984 Perl_magic_getnkeys(pTHX_ SV *sv, MAGIC *mg)
986 HV *hv = (HV*)LvTARG(sv);
991 (void) hv_iterinit(hv);
992 if (! SvTIED_mg((SV*)hv, 'P'))
996 while (entry = hv_iternext(hv)) {
1002 sv_setiv(sv, (IV)i);
1007 Perl_magic_setnkeys(pTHX_ SV *sv, MAGIC *mg)
1010 hv_ksplit((HV*)LvTARG(sv), SvIV(sv));
1015 /* caller is responsible for stack switching/cleanup */
1017 S_magic_methcall(pTHX_ SV *sv, MAGIC *mg, char *meth, I32 flags, int n, SV *val)
1023 PUSHs(SvTIED_obj(sv, mg));
1026 if (mg->mg_len >= 0)
1027 PUSHs(sv_2mortal(newSVpvn(mg->mg_ptr, mg->mg_len)));
1028 else if (mg->mg_len == HEf_SVKEY)
1029 PUSHs((SV*)mg->mg_ptr);
1031 else if (mg->mg_type == 'p') {
1032 PUSHs(sv_2mortal(newSViv(mg->mg_len)));
1040 return call_method(meth, flags);
1044 S_magic_methpack(pTHX_ SV *sv, MAGIC *mg, char *meth)
1050 PUSHSTACKi(PERLSI_MAGIC);
1052 if (magic_methcall(sv, mg, meth, G_SCALAR, 2, NULL)) {
1053 sv_setsv(sv, *PL_stack_sp--);
1063 Perl_magic_getpack(pTHX_ SV *sv, MAGIC *mg)
1065 magic_methpack(sv,mg,"FETCH");
1067 mg->mg_flags |= MGf_GSKIP;
1072 Perl_magic_setpack(pTHX_ SV *sv, MAGIC *mg)
1076 PUSHSTACKi(PERLSI_MAGIC);
1077 magic_methcall(sv, mg, "STORE", G_SCALAR|G_DISCARD, 3, sv);
1084 Perl_magic_clearpack(pTHX_ SV *sv, MAGIC *mg)
1086 return magic_methpack(sv,mg,"DELETE");
1091 Perl_magic_sizepack(pTHX_ SV *sv, MAGIC *mg)
1098 PUSHSTACKi(PERLSI_MAGIC);
1099 if (magic_methcall(sv, mg, "FETCHSIZE", G_SCALAR, 2, NULL)) {
1100 sv = *PL_stack_sp--;
1101 retval = (U32) SvIV(sv)-1;
1110 Perl_magic_wipepack(pTHX_ SV *sv, MAGIC *mg)
1115 PUSHSTACKi(PERLSI_MAGIC);
1117 XPUSHs(SvTIED_obj(sv, mg));
1119 call_method("CLEAR", G_SCALAR|G_DISCARD);
1126 Perl_magic_nextpack(pTHX_ SV *sv, MAGIC *mg, SV *key)
1129 const char *meth = SvOK(key) ? "NEXTKEY" : "FIRSTKEY";
1133 PUSHSTACKi(PERLSI_MAGIC);
1136 PUSHs(SvTIED_obj(sv, mg));
1141 if (call_method(meth, G_SCALAR))
1142 sv_setsv(key, *PL_stack_sp--);
1151 Perl_magic_existspack(pTHX_ SV *sv, MAGIC *mg)
1153 return magic_methpack(sv,mg,"EXISTS");
1157 Perl_magic_setdbline(pTHX_ SV *sv, MAGIC *mg)
1168 svp = av_fetch(GvAV(gv),
1169 atoi(MgPV(mg,n_a)), FALSE);
1170 if (svp && SvIOKp(*svp) && (o = (OP*)SvSTASH(*svp)))
1172 else if (ckWARN_d(WARN_INTERNAL))
1173 Perl_warner(aTHX_ WARN_INTERNAL, "Can't break at that line\n");
1178 Perl_magic_getarylen(pTHX_ SV *sv, MAGIC *mg)
1181 sv_setiv(sv, AvFILL((AV*)mg->mg_obj) + PL_curcop->cop_arybase);
1186 Perl_magic_setarylen(pTHX_ SV *sv, MAGIC *mg)
1189 av_fill((AV*)mg->mg_obj, SvIV(sv) - PL_curcop->cop_arybase);
1194 Perl_magic_getpos(pTHX_ SV *sv, MAGIC *mg)
1196 SV* lsv = LvTARG(sv);
1198 if (SvTYPE(lsv) >= SVt_PVMG && SvMAGIC(lsv)) {
1199 mg = mg_find(lsv, 'g');
1200 if (mg && mg->mg_len >= 0) {
1204 sv_pos_b2u(lsv, &i);
1205 sv_setiv(sv, i + PL_curcop->cop_arybase);
1214 Perl_magic_setpos(pTHX_ SV *sv, MAGIC *mg)
1216 SV* lsv = LvTARG(sv);
1224 if (SvTYPE(lsv) >= SVt_PVMG && SvMAGIC(lsv))
1225 mg = mg_find(lsv, 'g');
1229 sv_magic(lsv, (SV*)0, 'g', Nullch, 0);
1230 mg = mg_find(lsv, 'g');
1232 else if (!SvOK(sv)) {
1236 len = SvPOK(lsv) ? SvCUR(lsv) : sv_len(lsv);
1238 pos = SvIV(sv) - PL_curcop->cop_arybase;
1241 ulen = sv_len_utf8(lsv);
1258 sv_pos_u2b(lsv, &p, 0);
1263 mg->mg_flags &= ~MGf_MINMATCH;
1269 Perl_magic_getglob(pTHX_ SV *sv, MAGIC *mg)
1271 if (SvFAKE(sv)) { /* FAKE globs can get coerced */
1273 gv_efullname3(sv,((GV*)sv), "*");
1277 gv_efullname3(sv,((GV*)sv), "*"); /* a gv value, be nice */
1282 Perl_magic_setglob(pTHX_ SV *sv, MAGIC *mg)
1291 if (*s == '*' && s[1])
1293 gv = gv_fetchpv(s,TRUE, SVt_PVGV);
1298 GvGP(sv) = gp_ref(GvGP(gv));
1303 Perl_magic_getsubstr(pTHX_ SV *sv, MAGIC *mg)
1306 SV *lsv = LvTARG(sv);
1307 char *tmps = SvPV(lsv,len);
1308 I32 offs = LvTARGOFF(sv);
1309 I32 rem = LvTARGLEN(sv);
1313 if (rem + offs > len)
1315 sv_setpvn(sv, tmps + offs, (STRLEN)rem);
1320 Perl_magic_setsubstr(pTHX_ SV *sv, MAGIC *mg)
1323 char *tmps = SvPV(sv,len);
1324 sv_insert(LvTARG(sv),LvTARGOFF(sv),LvTARGLEN(sv), tmps, len);
1329 Perl_magic_gettaint(pTHX_ SV *sv, MAGIC *mg)
1332 TAINT_IF((mg->mg_len & 1) ||
1333 (mg->mg_len & 2) && mg->mg_obj == sv); /* kludge */
1338 Perl_magic_settaint(pTHX_ SV *sv, MAGIC *mg)
1341 if (PL_localizing) {
1342 if (PL_localizing == 1)
1347 else if (PL_tainted)
1355 Perl_magic_getvec(pTHX_ SV *sv, MAGIC *mg)
1357 SV *lsv = LvTARG(sv);
1364 sv_setuv(sv, do_vecget(lsv, LvTARGOFF(sv), LvTARGLEN(sv)));
1369 Perl_magic_setvec(pTHX_ SV *sv, MAGIC *mg)
1371 do_vecset(sv); /* XXX slurp this routine */
1376 Perl_magic_getdefelem(pTHX_ SV *sv, MAGIC *mg)
1379 if (LvTARGLEN(sv)) {
1381 SV *ahv = LvTARG(sv);
1382 if (SvTYPE(ahv) == SVt_PVHV) {
1383 HE *he = hv_fetch_ent((HV*)ahv, mg->mg_obj, FALSE, 0);
1388 SV **svp = avhv_fetch_ent((AV*)ahv, mg->mg_obj, FALSE, 0);
1394 AV* av = (AV*)LvTARG(sv);
1395 if ((I32)LvTARGOFF(sv) <= AvFILL(av))
1396 targ = AvARRAY(av)[LvTARGOFF(sv)];
1398 if (targ && targ != &PL_sv_undef) {
1399 dTHR; /* just for SvREFCNT_dec */
1400 /* somebody else defined it for us */
1401 SvREFCNT_dec(LvTARG(sv));
1402 LvTARG(sv) = SvREFCNT_inc(targ);
1404 SvREFCNT_dec(mg->mg_obj);
1405 mg->mg_obj = Nullsv;
1406 mg->mg_flags &= ~MGf_REFCOUNTED;
1411 sv_setsv(sv, targ ? targ : &PL_sv_undef);
1416 Perl_magic_setdefelem(pTHX_ SV *sv, MAGIC *mg)
1421 sv_setsv(LvTARG(sv), sv);
1422 SvSETMAGIC(LvTARG(sv));
1428 Perl_vivify_defelem(pTHX_ SV *sv)
1430 dTHR; /* just for SvREFCNT_inc and SvREFCNT_dec*/
1434 if (!LvTARGLEN(sv) || !(mg = mg_find(sv, 'y')))
1437 SV *ahv = LvTARG(sv);
1439 if (SvTYPE(ahv) == SVt_PVHV) {
1440 HE *he = hv_fetch_ent((HV*)ahv, mg->mg_obj, TRUE, 0);
1445 SV **svp = avhv_fetch_ent((AV*)ahv, mg->mg_obj, TRUE, 0);
1449 if (!value || value == &PL_sv_undef)
1450 Perl_croak(aTHX_ PL_no_helem, SvPV(mg->mg_obj, n_a));
1453 AV* av = (AV*)LvTARG(sv);
1454 if ((I32)LvTARGLEN(sv) < 0 && (I32)LvTARGOFF(sv) > AvFILL(av))
1455 LvTARG(sv) = Nullsv; /* array can't be extended */
1457 SV** svp = av_fetch(av, LvTARGOFF(sv), TRUE);
1458 if (!svp || (value = *svp) == &PL_sv_undef)
1459 Perl_croak(aTHX_ PL_no_aelem, (I32)LvTARGOFF(sv));
1462 (void)SvREFCNT_inc(value);
1463 SvREFCNT_dec(LvTARG(sv));
1466 SvREFCNT_dec(mg->mg_obj);
1467 mg->mg_obj = Nullsv;
1468 mg->mg_flags &= ~MGf_REFCOUNTED;
1472 Perl_magic_killbackrefs(pTHX_ SV *sv, MAGIC *mg)
1474 AV *av = (AV*)mg->mg_obj;
1475 SV **svp = AvARRAY(av);
1476 I32 i = AvFILLp(av);
1478 if (svp[i] && svp[i] != &PL_sv_undef) {
1479 if (!SvWEAKREF(svp[i]))
1480 Perl_croak(aTHX_ "panic: magic_killbackrefs");
1481 /* XXX Should we check that it hasn't changed? */
1484 SvWEAKREF_off(svp[i]);
1485 svp[i] = &PL_sv_undef;
1493 Perl_magic_setmglob(pTHX_ SV *sv, MAGIC *mg)
1501 Perl_magic_setbm(pTHX_ SV *sv, MAGIC *mg)
1503 sv_unmagic(sv, 'B');
1509 Perl_magic_setfm(pTHX_ SV *sv, MAGIC *mg)
1511 sv_unmagic(sv, 'f');
1517 Perl_magic_setuvar(pTHX_ SV *sv, MAGIC *mg)
1519 struct ufuncs *uf = (struct ufuncs *)mg->mg_ptr;
1521 if (uf && uf->uf_set)
1522 (*uf->uf_set)(uf->uf_index, sv);
1527 Perl_magic_freeregexp(pTHX_ SV *sv, MAGIC *mg)
1529 regexp *re = (regexp *)mg->mg_obj;
1534 #ifdef USE_LOCALE_COLLATE
1536 Perl_magic_setcollxfrm(pTHX_ SV *sv, MAGIC *mg)
1539 * RenE<eacute> Descartes said "I think not."
1540 * and vanished with a faint plop.
1543 Safefree(mg->mg_ptr);
1549 #endif /* USE_LOCALE_COLLATE */
1552 Perl_magic_set(pTHX_ SV *sv, MAGIC *mg)
1558 switch (*mg->mg_ptr) {
1559 case '\001': /* ^A */
1560 sv_setsv(PL_bodytarget, sv);
1562 case '\003': /* ^C */
1563 PL_minus_c = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
1566 case '\004': /* ^D */
1567 PL_debug = (SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv)) | 0x80000000;
1568 DEBUG_x(dump_all());
1570 case '\005': /* ^E */
1572 set_vaxc_errno(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv));
1575 SetLastError( SvIV(sv) );
1578 /* will anyone ever use this? */
1579 SETERRNO(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv), 4);
1584 case '\006': /* ^F */
1585 PL_maxsysfd = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
1587 case '\010': /* ^H */
1588 PL_hints = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
1590 case '\011': /* ^I */ /* NOT \t in EBCDIC */
1592 Safefree(PL_inplace);
1594 PL_inplace = savepv(SvPV(sv,len));
1596 PL_inplace = Nullch;
1598 case '\017': /* ^O */
1600 Safefree(PL_osname);
1602 PL_osname = savepv(SvPV(sv,len));
1606 case '\020': /* ^P */
1607 PL_perldb = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
1608 if (PL_perldb && !PL_DBsingle)
1611 case '\024': /* ^T */
1613 PL_basetime = (Time_t)(SvNOK(sv) ? SvNVX(sv) : sv_2nv(sv));
1615 PL_basetime = (Time_t)(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv));
1618 case '\027': /* ^W & $^Warnings */
1619 if (*(mg->mg_ptr+1) == '\0') {
1620 if ( ! (PL_dowarn & G_WARN_ALL_MASK)) {
1621 i = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
1622 PL_dowarn = (PL_dowarn & ~G_WARN_ON)
1623 | (i ? G_WARN_ON : G_WARN_OFF) ;
1626 else if (strEQ(mg->mg_ptr, "\027arnings")) {
1627 if ( ! (PL_dowarn & G_WARN_ALL_MASK)) {
1628 if (memEQ(SvPVX(sv), WARN_ALLstring, WARNsize)) {
1629 PL_compiling.cop_warnings = WARN_ALL;
1630 PL_dowarn |= G_WARN_ONCE ;
1632 else if (memEQ(SvPVX(sv), WARN_NONEstring, WARNsize))
1633 PL_compiling.cop_warnings = WARN_NONE;
1635 if (specialWARN(PL_compiling.cop_warnings))
1636 PL_compiling.cop_warnings = newSVsv(sv) ;
1638 sv_setsv(PL_compiling.cop_warnings, sv);
1639 if (isWARN_on(PL_compiling.cop_warnings, WARN_ONCE))
1640 PL_dowarn |= G_WARN_ONCE ;
1646 if (PL_localizing) {
1647 if (PL_localizing == 1)
1648 save_sptr((SV**)&PL_last_in_gv);
1650 else if (SvOK(sv) && GvIO(PL_last_in_gv))
1651 IoLINES(GvIOp(PL_last_in_gv)) = (long)SvIV(sv);
1654 Safefree(IoTOP_NAME(GvIOp(PL_defoutgv)));
1655 IoTOP_NAME(GvIOp(PL_defoutgv)) = s = savepv(SvPV(sv,len));
1656 IoTOP_GV(GvIOp(PL_defoutgv)) = gv_fetchpv(s,TRUE, SVt_PVIO);
1659 Safefree(IoFMT_NAME(GvIOp(PL_defoutgv)));
1660 IoFMT_NAME(GvIOp(PL_defoutgv)) = s = savepv(SvPV(sv,len));
1661 IoFMT_GV(GvIOp(PL_defoutgv)) = gv_fetchpv(s,TRUE, SVt_PVIO);
1664 IoPAGE_LEN(GvIOp(PL_defoutgv)) = (long)(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv));
1667 IoLINES_LEFT(GvIOp(PL_defoutgv)) = (long)(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv));
1668 if (IoLINES_LEFT(GvIOp(PL_defoutgv)) < 0L)
1669 IoLINES_LEFT(GvIOp(PL_defoutgv)) = 0L;
1672 IoPAGE(GvIOp(PL_defoutgv)) = (long)(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv));
1676 IO *io = GvIOp(PL_defoutgv);
1677 if ((SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv)) == 0)
1678 IoFLAGS(io) &= ~IOf_FLUSH;
1680 if (!(IoFLAGS(io) & IOf_FLUSH)) {
1681 PerlIO *ofp = IoOFP(io);
1683 (void)PerlIO_flush(ofp);
1684 IoFLAGS(io) |= IOf_FLUSH;
1690 i = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
1691 PL_multiline = (i != 0);
1694 SvREFCNT_dec(PL_nrs);
1695 PL_nrs = newSVsv(sv);
1696 SvREFCNT_dec(PL_rs);
1697 PL_rs = SvREFCNT_inc(PL_nrs);
1702 if (SvOK(sv) || SvGMAGICAL(sv)) {
1703 s = SvPV(sv,PL_orslen);
1704 PL_ors = savepvn(s,PL_orslen);
1714 PL_ofs = savepv(SvPV(sv, PL_ofslen));
1719 PL_ofmt = savepv(SvPV(sv,len));
1722 PL_compiling.cop_arybase = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
1725 #ifdef COMPLEX_STATUS
1726 if (PL_localizing == 2) {
1727 PL_statusvalue = LvTARGOFF(sv);
1728 PL_statusvalue_vms = LvTARGLEN(sv);
1732 #ifdef VMSISH_STATUS
1734 STATUS_NATIVE_SET((U32)(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv)));
1737 STATUS_POSIX_SET(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv));
1740 SETERRNO(SvIOK(sv) ? SvIVX(sv) : SvOK(sv) ? sv_2iv(sv) : 0,
1741 (SvIV(sv) == EVMSERR) ? 4 : vaxc$errno);
1744 PL_uid = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
1745 if (PL_delaymagic) {
1746 PL_delaymagic |= DM_RUID;
1747 break; /* don't do magic till later */
1750 (void)setruid((Uid_t)PL_uid);
1753 (void)setreuid((Uid_t)PL_uid, (Uid_t)-1);
1755 #ifdef HAS_SETRESUID
1756 (void)setresuid((Uid_t)PL_uid, (Uid_t)-1, (Uid_t)-1);
1758 if (PL_uid == PL_euid) /* special case $< = $> */
1759 (void)PerlProc_setuid(PL_uid);
1761 PL_uid = PerlProc_getuid();
1762 Perl_croak(aTHX_ "setruid() not implemented");
1767 PL_uid = PerlProc_getuid();
1768 PL_tainting |= (PL_uid && (PL_euid != PL_uid || PL_egid != PL_gid));
1771 PL_euid = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
1772 if (PL_delaymagic) {
1773 PL_delaymagic |= DM_EUID;
1774 break; /* don't do magic till later */
1777 (void)seteuid((Uid_t)PL_euid);
1780 (void)setreuid((Uid_t)-1, (Uid_t)PL_euid);
1782 #ifdef HAS_SETRESUID
1783 (void)setresuid((Uid_t)-1, (Uid_t)PL_euid, (Uid_t)-1);
1785 if (PL_euid == PL_uid) /* special case $> = $< */
1786 PerlProc_setuid(PL_euid);
1788 PL_euid = PerlProc_geteuid();
1789 Perl_croak(aTHX_ "seteuid() not implemented");
1794 PL_euid = PerlProc_geteuid();
1795 PL_tainting |= (PL_uid && (PL_euid != PL_uid || PL_egid != PL_gid));
1798 PL_gid = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
1799 if (PL_delaymagic) {
1800 PL_delaymagic |= DM_RGID;
1801 break; /* don't do magic till later */
1804 (void)setrgid((Gid_t)PL_gid);
1807 (void)setregid((Gid_t)PL_gid, (Gid_t)-1);
1809 #ifdef HAS_SETRESGID
1810 (void)setresgid((Gid_t)PL_gid, (Gid_t)-1, (Gid_t) 1);
1812 if (PL_gid == PL_egid) /* special case $( = $) */
1813 (void)PerlProc_setgid(PL_gid);
1815 PL_gid = PerlProc_getgid();
1816 Perl_croak(aTHX_ "setrgid() not implemented");
1821 PL_gid = PerlProc_getgid();
1822 PL_tainting |= (PL_uid && (PL_euid != PL_uid || PL_egid != PL_gid));
1825 #ifdef HAS_SETGROUPS
1827 char *p = SvPV(sv, len);
1828 Groups_t gary[NGROUPS];
1833 for (i = 0; i < NGROUPS; ++i) {
1834 while (*p && !isSPACE(*p))
1843 (void)setgroups(i, gary);
1845 #else /* HAS_SETGROUPS */
1846 PL_egid = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
1847 #endif /* HAS_SETGROUPS */
1848 if (PL_delaymagic) {
1849 PL_delaymagic |= DM_EGID;
1850 break; /* don't do magic till later */
1853 (void)setegid((Gid_t)PL_egid);
1856 (void)setregid((Gid_t)-1, (Gid_t)PL_egid);
1858 #ifdef HAS_SETRESGID
1859 (void)setresgid((Gid_t)-1, (Gid_t)PL_egid, (Gid_t)-1);
1861 if (PL_egid == PL_gid) /* special case $) = $( */
1862 (void)PerlProc_setgid(PL_egid);
1864 PL_egid = PerlProc_getegid();
1865 Perl_croak(aTHX_ "setegid() not implemented");
1870 PL_egid = PerlProc_getegid();
1871 PL_tainting |= (PL_uid && (PL_euid != PL_uid || PL_egid != PL_gid));
1874 PL_chopset = SvPV_force(sv,len);
1880 /* See if all the arguments are contiguous in memory */
1881 for (i = 1; i < PL_origargc; i++) {
1882 if (PL_origargv[i] == s + 1
1884 || PL_origargv[i] == s + 2
1889 s += strlen(s); /* this one is ok too */
1894 /* can grab env area too? */
1895 if (PL_origenviron && (PL_origenviron[0] == s + 1
1897 || (PL_origenviron[0] == s + 9 && (s += 8))
1900 my_setenv("NoNe SuCh", Nullch);
1901 /* force copy of environment */
1902 for (i = 0; PL_origenviron[i]; i++)
1903 if (PL_origenviron[i] == s + 1) {
1910 PL_origalen = s - PL_origargv[0];
1912 s = SvPV_force(sv,len);
1914 if (i >= PL_origalen) {
1916 /* don't allow system to limit $0 seen by script */
1917 /* SvCUR_set(sv, i); *SvEND(sv) = '\0'; */
1918 Copy(s, PL_origargv[0], i, char);
1919 s = PL_origargv[0]+i;
1923 Copy(s, PL_origargv[0], i, char);
1924 s = PL_origargv[0]+i;
1926 while (++i < PL_origalen)
1928 s = PL_origargv[0]+i;
1929 for (i = 1; i < PL_origargc; i++)
1930 PL_origargv[i] = Nullch;
1935 sv_setsv(thr->errsv, sv);
1937 #endif /* USE_THREADS */
1944 Perl_magic_mutexfree(pTHX_ SV *sv, MAGIC *mg)
1947 DEBUG_S(PerlIO_printf(Perl_debug_log,
1948 "0x%"UVxf": magic_mutexfree 0x%"UVxf"\n",
1949 PTR2UV(thr), PTR2UV(sv));)
1951 Perl_croak(aTHX_ "panic: magic_mutexfree");
1952 MUTEX_DESTROY(MgMUTEXP(mg));
1953 COND_DESTROY(MgCONDP(mg));
1956 #endif /* USE_THREADS */
1959 Perl_whichsig(pTHX_ char *sig)
1961 register char **sigv;
1963 for (sigv = PL_sig_name+1; *sigv; sigv++)
1964 if (strEQ(sig,*sigv))
1965 return PL_sig_num[sigv - PL_sig_name];
1967 if (strEQ(sig,"CHLD"))
1971 if (strEQ(sig,"CLD"))
1980 Perl_sighandler(int sig)
1986 SV *sv, *tSv = PL_Sv;
1990 I32 o_save_i = PL_savestack_ix, type;
1993 if (PL_savestack_ix + 15 <= PL_savestack_max)
1995 if (PL_markstack_ptr < PL_markstack_max - 2)
1997 if (PL_retstack_ix < PL_retstack_max - 2)
1999 if (PL_scopestack_ix < PL_scopestack_max - 3)
2002 if (!PL_psig_ptr[sig])
2003 Perl_die(aTHX_ "Signal SIG%s received, but no signal handler set.\n",
2006 /* Max number of items pushed there is 3*n or 4. We cannot fix
2007 infinity, so we fix 4 (in fact 5): */
2009 PL_savestack_ix += 5; /* Protect save in progress. */
2010 o_save_i = PL_savestack_ix;
2011 SAVEDESTRUCTOR_X(unwind_handler_stack, (void*)&flags);
2014 PL_markstack_ptr++; /* Protect mark. */
2017 PL_retstack[PL_retstack_ix] = NULL;
2020 PL_scopestack_ix += 1;
2021 /* sv_2cv is too complicated, try a simpler variant first: */
2022 if (!SvROK(PL_psig_ptr[sig]) || !(cv = (CV*)SvRV(PL_psig_ptr[sig]))
2023 || SvTYPE(cv) != SVt_PVCV)
2024 cv = sv_2cv(PL_psig_ptr[sig],&st,&gv,TRUE);
2026 if (!cv || !CvROOT(cv)) {
2027 if (ckWARN(WARN_SIGNAL))
2028 Perl_warner(aTHX_ WARN_SIGNAL, "SIG%s handler \"%s\" not defined.\n",
2029 PL_sig_name[sig], (gv ? GvENAME(gv)
2036 if(PL_psig_name[sig]) {
2037 sv = SvREFCNT_inc(PL_psig_name[sig]);
2041 sv = sv_newmortal();
2042 sv_setpv(sv,PL_sig_name[sig]);
2045 PUSHSTACKi(PERLSI_SIGNAL);
2050 call_sv((SV*)cv, G_DISCARD);
2055 PL_savestack_ix -= 8; /* Unprotect save in progress. */
2061 PL_scopestack_ix -= 1;
2064 PL_op = myop; /* Apparently not needed... */
2066 PL_Sv = tSv; /* Restore global temporaries. */
2077 restore_magic(pTHXo_ void *p)
2080 MGS* mgs = SSPTR((I32)p, MGS*);
2081 SV* sv = mgs->mgs_sv;
2086 if (SvTYPE(sv) >= SVt_PVMG && SvMAGIC(sv))
2089 SvFLAGS(sv) |= mgs->mgs_flags;
2093 SvFLAGS(sv) &= ~(SVf_IOK|SVf_NOK|SVf_POK);
2096 mgs->mgs_sv = NULL; /* mark the MGS structure as restored */
2098 /* If we're still on top of the stack, pop us off. (That condition
2099 * will be satisfied if restore_magic was called explicitly, but *not*
2100 * if it's being called via leave_scope.)
2101 * The reason for doing this is that otherwise, things like sv_2cv()
2102 * may leave alloc gunk on the savestack, and some code
2103 * (e.g. sighandler) doesn't expect that...
2105 if (PL_savestack_ix == mgs->mgs_ss_ix)
2107 I32 popval = SSPOPINT;
2108 assert(popval == SAVEt_DESTRUCTOR_X);
2109 PL_savestack_ix -= 2;
2111 assert(popval == SAVEt_ALLOC);
2113 PL_savestack_ix -= popval;
2119 unwind_handler_stack(pTHXo_ void *p)
2122 U32 flags = *(U32*)p;
2125 PL_savestack_ix -= 5; /* Unprotect save in progress. */
2126 /* cxstack_ix-- Not needed, die already unwound it. */
2128 SvREFCNT_dec(sig_sv);