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 */
411 #ifdef MACOS_TRADITIONAL
415 sv_setnv(sv,(double)gLastMacOSErr);
416 sv_setpv(sv, gLastMacOSErr ? GetSysErrText(gLastMacOSErr, msg) : "");
421 # include <descrip.h>
422 # include <starlet.h>
424 $DESCRIPTOR(msgdsc,msg);
425 sv_setnv(sv,(NV) vaxc$errno);
426 if (sys$getmsg(vaxc$errno,&msgdsc.dsc$w_length,&msgdsc,0,0) & 1)
427 sv_setpvn(sv,msgdsc.dsc$a_pointer,msgdsc.dsc$w_length);
433 if (!(_emx_env & 0x200)) { /* Under DOS */
434 sv_setnv(sv, (NV)errno);
435 sv_setpv(sv, errno ? Strerror(errno) : "");
437 if (errno != errno_isOS2) {
438 int tmp = _syserrno();
439 if (tmp) /* 2nd call to _syserrno() makes it 0 */
442 sv_setnv(sv, (NV)Perl_rc);
443 sv_setpv(sv, os2error(Perl_rc));
448 DWORD dwErr = GetLastError();
449 sv_setnv(sv, (NV)dwErr);
452 PerlProc_GetOSError(sv, dwErr);
459 sv_setnv(sv, (NV)errno);
460 sv_setpv(sv, errno ? Strerror(errno) : "");
465 SvNOK_on(sv); /* what a wonderful hack! */
467 case '\006': /* ^F */
468 sv_setiv(sv, (IV)PL_maxsysfd);
470 case '\010': /* ^H */
471 sv_setiv(sv, (IV)PL_hints);
473 case '\011': /* ^I */ /* NOT \t in EBCDIC */
475 sv_setpv(sv, PL_inplace);
477 sv_setsv(sv, &PL_sv_undef);
479 case '\017': /* ^O */
480 sv_setpv(sv, PL_osname);
482 case '\020': /* ^P */
483 sv_setiv(sv, (IV)PL_perldb);
485 case '\023': /* ^S */
488 if (PL_lex_state != LEX_NOTPARSING)
496 case '\024': /* ^T */
498 sv_setnv(sv, PL_basetime);
500 sv_setiv(sv, (IV)PL_basetime);
503 case '\027': /* ^W & $^Warnings*/
504 if (*(mg->mg_ptr+1) == '\0')
505 sv_setiv(sv, (IV)((PL_dowarn & G_WARN_ON) ? TRUE : FALSE));
506 else if (strEQ(mg->mg_ptr, "\027arnings")) {
507 if (PL_compiling.cop_warnings == WARN_NONE ||
508 PL_compiling.cop_warnings == WARN_STD)
510 sv_setpvn(sv, WARN_NONEstring, WARNsize) ;
512 else if (PL_compiling.cop_warnings == WARN_ALL) {
513 sv_setpvn(sv, WARN_ALLstring, WARNsize) ;
516 sv_setsv(sv, PL_compiling.cop_warnings);
520 case '1': case '2': case '3': case '4':
521 case '5': case '6': case '7': case '8': case '9': case '&':
522 if (PL_curpm && (rx = PL_curpm->op_pmregexp)) {
526 * Pre-threads, this was paren = atoi(GvENAME((GV*)mg->mg_obj));
527 * XXX Does the new way break anything?
529 paren = atoi(mg->mg_ptr);
531 if (paren <= rx->nparens &&
532 (s1 = rx->startp[paren]) != -1 &&
533 (t1 = rx->endp[paren]) != -1)
541 was_tainted = PL_tainted;
546 PL_tainted = (was_tainted || RX_MATCH_TAINTED(rx));
551 sv_setsv(sv,&PL_sv_undef);
554 if (PL_curpm && (rx = PL_curpm->op_pmregexp)) {
555 paren = rx->lastparen;
559 sv_setsv(sv,&PL_sv_undef);
562 if (PL_curpm && (rx = PL_curpm->op_pmregexp)) {
563 if ((s = rx->subbeg) && rx->startp[0] != -1) {
568 sv_setsv(sv,&PL_sv_undef);
571 if (PL_curpm && (rx = PL_curpm->op_pmregexp)) {
572 if (rx->subbeg && rx->endp[0] != -1) {
573 s = rx->subbeg + rx->endp[0];
574 i = rx->sublen - rx->endp[0];
578 sv_setsv(sv,&PL_sv_undef);
582 if (GvIO(PL_last_in_gv)) {
583 sv_setiv(sv, (IV)IoLINES(GvIO(PL_last_in_gv)));
589 sv_setiv(sv, (IV)STATUS_CURRENT);
590 #ifdef COMPLEX_STATUS
591 LvTARGOFF(sv) = PL_statusvalue;
592 LvTARGLEN(sv) = PL_statusvalue_vms;
597 s = IoTOP_NAME(GvIOp(PL_defoutgv));
601 sv_setpv(sv,GvENAME(PL_defoutgv));
606 s = IoFMT_NAME(GvIOp(PL_defoutgv));
608 s = GvENAME(PL_defoutgv);
613 sv_setiv(sv, (IV)IoPAGE_LEN(GvIOp(PL_defoutgv)));
616 sv_setiv(sv, (IV)IoLINES_LEFT(GvIOp(PL_defoutgv)));
619 sv_setiv(sv, (IV)IoPAGE(GvIOp(PL_defoutgv)));
627 WITH_THR(sv_setiv(sv, (IV)PL_curcop->cop_arybase));
630 sv_setiv(sv, (IV)(IoFLAGS(GvIOp(PL_defoutgv)) & IOf_FLUSH) != 0 );
633 sv_setpvn(sv,PL_ofs,PL_ofslen);
636 sv_setpvn(sv,PL_ors,PL_orslen);
639 sv_setpv(sv,PL_ofmt);
643 sv_setnv(sv, (NV)((errno == EVMSERR) ? vaxc$errno : errno));
644 sv_setpv(sv, errno ? Strerror(errno) : "");
647 int saveerrno = errno;
648 sv_setnv(sv, (NV)errno);
650 if (errno == errno_isOS2 || errno == errno_isOS2_set)
651 sv_setpv(sv, os2error(Perl_rc));
654 sv_setpv(sv, errno ? Strerror(errno) : "");
658 SvNOK_on(sv); /* what a wonderful hack! */
661 sv_setiv(sv, (IV)PL_uid);
664 sv_setiv(sv, (IV)PL_euid);
667 sv_setiv(sv, (IV)PL_gid);
669 Perl_sv_setpvf(aTHX_ sv, "%"Gid_t_f, PL_gid);
673 sv_setiv(sv, (IV)PL_egid);
675 Perl_sv_setpvf(aTHX_ sv, "%"Gid_t_f, PL_egid);
680 Groups_t gary[NGROUPS];
681 i = getgroups(NGROUPS,gary);
683 Perl_sv_catpvf(aTHX_ sv, " %"Gid_t_f, gary[i]);
686 SvIOK_on(sv); /* what a wonderful hack! */
690 #ifndef MACOS_TRADITIONAL
696 sv_setsv(sv, thr->errsv);
698 #endif /* USE_THREADS */
704 Perl_magic_getuvar(pTHX_ SV *sv, MAGIC *mg)
706 struct ufuncs *uf = (struct ufuncs *)mg->mg_ptr;
708 if (uf && uf->uf_val)
709 (*uf->uf_val)(uf->uf_index, sv);
714 Perl_magic_setenv(pTHX_ SV *sv, MAGIC *mg)
725 #ifdef DYNAMIC_ENV_FETCH
726 /* We just undefd an environment var. Is a replacement */
727 /* waiting in the wings? */
730 if ((valp = hv_fetch(GvHVn(PL_envgv), ptr, klen, FALSE)))
731 s = SvPV(*valp, len);
735 #if !defined(OS2) && !defined(AMIGAOS) && !defined(WIN32) && !defined(MSDOS)
736 /* And you'll never guess what the dog had */
737 /* in its mouth... */
739 MgTAINTEDDIR_off(mg);
741 if (s && klen == 8 && strEQ(ptr, "DCL$PATH")) {
742 char pathbuf[256], eltbuf[256], *cp, *elt = s;
746 do { /* DCL$PATH may be a search list */
747 while (1) { /* as may dev portion of any element */
748 if ( ((cp = strchr(elt,'[')) || (cp = strchr(elt,'<'))) ) {
749 if ( *(cp+1) == '.' || *(cp+1) == '-' ||
750 cando_by_name(S_IWUSR,0,elt) ) {
755 if ((cp = strchr(elt, ':')) != Nullch)
757 if (my_trnlnm(elt, eltbuf, j++))
763 } while (my_trnlnm(s, pathbuf, i++) && (elt = pathbuf));
766 if (s && klen == 4 && strEQ(ptr,"PATH")) {
767 char *strend = s + len;
772 s = delimcpy(tmpbuf, tmpbuf + sizeof tmpbuf,
775 if (i >= sizeof tmpbuf /* too long -- assume the worst */
777 || (PerlLIO_stat(tmpbuf, &st) == 0 && (st.st_mode & 2)) ) {
784 #endif /* neither OS2 nor AMIGAOS nor WIN32 nor MSDOS */
790 Perl_magic_clearenv(pTHX_ SV *sv, MAGIC *mg)
793 my_setenv(MgPV(mg,n_a),Nullch);
798 Perl_magic_set_all_env(pTHX_ SV *sv, MAGIC *mg)
801 Perl_die(aTHX_ "Can't make list assignment to %%ENV on this system");
807 magic_clear_all_env(sv,mg);
808 hv_iterinit((HV*)sv);
809 while (entry = hv_iternext((HV*)sv)) {
811 my_setenv(hv_iterkey(entry, &keylen),
812 SvPV(hv_iterval((HV*)sv, entry), n_a));
820 Perl_magic_clear_all_env(pTHX_ SV *sv, MAGIC *mg)
823 Perl_die(aTHX_ "Can't make list assignment to %%ENV on this system");
826 char *envv = GetEnvironmentStrings();
830 char *end = strchr(cur,'=');
831 if (end && end != cur) {
833 my_setenv(cur,Nullch);
835 cur = end + strlen(end+1)+2;
837 else if ((len = strlen(cur)))
840 FreeEnvironmentStrings(envv);
844 for (i = 0; environ[i]; i++)
845 Safefree(environ[i]);
847 # ifndef PERL_USE_SAFE_PUTENV
850 if (environ == PL_origenviron)
851 environ = (char**)safesysmalloc(sizeof(char*));
853 for (i = 0; environ[i]; i++)
854 safesysfree(environ[i]);
855 # endif /* PERL_USE_SAFE_PUTENV */
866 Perl_magic_getsig(pTHX_ SV *sv, MAGIC *mg)
870 /* Are we fetching a signal entry? */
871 i = whichsig(MgPV(mg,n_a));
874 sv_setsv(sv,PL_psig_ptr[i]);
876 Sighandler_t sigstate = rsignal_state(i);
878 /* cache state so we don't fetch it again */
879 if(sigstate == SIG_IGN)
880 sv_setpv(sv,"IGNORE");
882 sv_setsv(sv,&PL_sv_undef);
883 PL_psig_ptr[i] = SvREFCNT_inc(sv);
890 Perl_magic_clearsig(pTHX_ SV *sv, MAGIC *mg)
894 /* Are we clearing a signal entry? */
895 i = whichsig(MgPV(mg,n_a));
898 SvREFCNT_dec(PL_psig_ptr[i]);
901 if(PL_psig_name[i]) {
902 SvREFCNT_dec(PL_psig_name[i]);
910 Perl_magic_setsig(pTHX_ SV *sv, MAGIC *mg)
920 if (strEQ(s,"__DIE__"))
922 else if (strEQ(s,"__WARN__"))
925 Perl_croak(aTHX_ "No such hook: %s", s);
933 i = whichsig(s); /* ...no, a brick */
935 if (ckWARN(WARN_SIGNAL) || strEQ(s,"ALARM"))
936 Perl_warner(aTHX_ WARN_SIGNAL, "No such signal: SIG%s", s);
939 SvREFCNT_dec(PL_psig_name[i]);
940 SvREFCNT_dec(PL_psig_ptr[i]);
941 PL_psig_ptr[i] = SvREFCNT_inc(sv);
942 SvTEMP_off(sv); /* Make sure it doesn't go away on us */
943 PL_psig_name[i] = newSVpvn(s, len);
944 SvREADONLY_on(PL_psig_name[i]);
946 if (SvTYPE(sv) == SVt_PVGV || SvROK(sv)) {
948 (void)rsignal(i, PL_sighandlerp);
950 *svp = SvREFCNT_inc(sv);
953 s = SvPV_force(sv,len);
954 if (strEQ(s,"IGNORE")) {
956 (void)rsignal(i, SIG_IGN);
960 else if (strEQ(s,"DEFAULT") || !*s) {
962 (void)rsignal(i, SIG_DFL);
968 * We should warn if HINT_STRICT_REFS, but without
969 * access to a known hint bit in a known OP, we can't
970 * tell whether HINT_STRICT_REFS is in force or not.
972 if (!strchr(s,':') && !strchr(s,'\''))
973 sv_insert(sv, 0, 0, "main::", 6);
975 (void)rsignal(i, PL_sighandlerp);
977 *svp = SvREFCNT_inc(sv);
983 Perl_magic_setisa(pTHX_ SV *sv, MAGIC *mg)
990 Perl_magic_setamagic(pTHX_ SV *sv, MAGIC *mg)
992 /* HV_badAMAGIC_on(Sv_STASH(sv)); */
993 PL_amagic_generation++;
999 Perl_magic_getnkeys(pTHX_ SV *sv, MAGIC *mg)
1001 HV *hv = (HV*)LvTARG(sv);
1006 (void) hv_iterinit(hv);
1007 if (! SvTIED_mg((SV*)hv, 'P'))
1011 while (entry = hv_iternext(hv)) {
1017 sv_setiv(sv, (IV)i);
1022 Perl_magic_setnkeys(pTHX_ SV *sv, MAGIC *mg)
1025 hv_ksplit((HV*)LvTARG(sv), SvIV(sv));
1030 /* caller is responsible for stack switching/cleanup */
1032 S_magic_methcall(pTHX_ SV *sv, MAGIC *mg, char *meth, I32 flags, int n, SV *val)
1038 PUSHs(SvTIED_obj(sv, mg));
1041 if (mg->mg_len >= 0)
1042 PUSHs(sv_2mortal(newSVpvn(mg->mg_ptr, mg->mg_len)));
1043 else if (mg->mg_len == HEf_SVKEY)
1044 PUSHs((SV*)mg->mg_ptr);
1046 else if (mg->mg_type == 'p') {
1047 PUSHs(sv_2mortal(newSViv(mg->mg_len)));
1055 return call_method(meth, flags);
1059 S_magic_methpack(pTHX_ SV *sv, MAGIC *mg, char *meth)
1065 PUSHSTACKi(PERLSI_MAGIC);
1067 if (magic_methcall(sv, mg, meth, G_SCALAR, 2, NULL)) {
1068 sv_setsv(sv, *PL_stack_sp--);
1078 Perl_magic_getpack(pTHX_ SV *sv, MAGIC *mg)
1080 magic_methpack(sv,mg,"FETCH");
1082 mg->mg_flags |= MGf_GSKIP;
1087 Perl_magic_setpack(pTHX_ SV *sv, MAGIC *mg)
1091 PUSHSTACKi(PERLSI_MAGIC);
1092 magic_methcall(sv, mg, "STORE", G_SCALAR|G_DISCARD, 3, sv);
1099 Perl_magic_clearpack(pTHX_ SV *sv, MAGIC *mg)
1101 return magic_methpack(sv,mg,"DELETE");
1106 Perl_magic_sizepack(pTHX_ SV *sv, MAGIC *mg)
1113 PUSHSTACKi(PERLSI_MAGIC);
1114 if (magic_methcall(sv, mg, "FETCHSIZE", G_SCALAR, 2, NULL)) {
1115 sv = *PL_stack_sp--;
1116 retval = (U32) SvIV(sv)-1;
1125 Perl_magic_wipepack(pTHX_ SV *sv, MAGIC *mg)
1130 PUSHSTACKi(PERLSI_MAGIC);
1132 XPUSHs(SvTIED_obj(sv, mg));
1134 call_method("CLEAR", G_SCALAR|G_DISCARD);
1141 Perl_magic_nextpack(pTHX_ SV *sv, MAGIC *mg, SV *key)
1144 const char *meth = SvOK(key) ? "NEXTKEY" : "FIRSTKEY";
1148 PUSHSTACKi(PERLSI_MAGIC);
1151 PUSHs(SvTIED_obj(sv, mg));
1156 if (call_method(meth, G_SCALAR))
1157 sv_setsv(key, *PL_stack_sp--);
1166 Perl_magic_existspack(pTHX_ SV *sv, MAGIC *mg)
1168 return magic_methpack(sv,mg,"EXISTS");
1172 Perl_magic_setdbline(pTHX_ SV *sv, MAGIC *mg)
1183 svp = av_fetch(GvAV(gv),
1184 atoi(MgPV(mg,n_a)), FALSE);
1185 if (svp && SvIOKp(*svp) && (o = (OP*)SvSTASH(*svp)))
1187 else if (ckWARN_d(WARN_INTERNAL))
1188 Perl_warner(aTHX_ WARN_INTERNAL, "Can't break at that line\n");
1193 Perl_magic_getarylen(pTHX_ SV *sv, MAGIC *mg)
1196 sv_setiv(sv, AvFILL((AV*)mg->mg_obj) + PL_curcop->cop_arybase);
1201 Perl_magic_setarylen(pTHX_ SV *sv, MAGIC *mg)
1204 av_fill((AV*)mg->mg_obj, SvIV(sv) - PL_curcop->cop_arybase);
1209 Perl_magic_getpos(pTHX_ SV *sv, MAGIC *mg)
1211 SV* lsv = LvTARG(sv);
1213 if (SvTYPE(lsv) >= SVt_PVMG && SvMAGIC(lsv)) {
1214 mg = mg_find(lsv, 'g');
1215 if (mg && mg->mg_len >= 0) {
1219 sv_pos_b2u(lsv, &i);
1220 sv_setiv(sv, i + PL_curcop->cop_arybase);
1229 Perl_magic_setpos(pTHX_ SV *sv, MAGIC *mg)
1231 SV* lsv = LvTARG(sv);
1239 if (SvTYPE(lsv) >= SVt_PVMG && SvMAGIC(lsv))
1240 mg = mg_find(lsv, 'g');
1244 sv_magic(lsv, (SV*)0, 'g', Nullch, 0);
1245 mg = mg_find(lsv, 'g');
1247 else if (!SvOK(sv)) {
1251 len = SvPOK(lsv) ? SvCUR(lsv) : sv_len(lsv);
1253 pos = SvIV(sv) - PL_curcop->cop_arybase;
1256 ulen = sv_len_utf8(lsv);
1273 sv_pos_u2b(lsv, &p, 0);
1278 mg->mg_flags &= ~MGf_MINMATCH;
1284 Perl_magic_getglob(pTHX_ SV *sv, MAGIC *mg)
1286 if (SvFAKE(sv)) { /* FAKE globs can get coerced */
1288 gv_efullname3(sv,((GV*)sv), "*");
1292 gv_efullname3(sv,((GV*)sv), "*"); /* a gv value, be nice */
1297 Perl_magic_setglob(pTHX_ SV *sv, MAGIC *mg)
1306 if (*s == '*' && s[1])
1308 gv = gv_fetchpv(s,TRUE, SVt_PVGV);
1313 GvGP(sv) = gp_ref(GvGP(gv));
1318 Perl_magic_getsubstr(pTHX_ SV *sv, MAGIC *mg)
1321 SV *lsv = LvTARG(sv);
1322 char *tmps = SvPV(lsv,len);
1323 I32 offs = LvTARGOFF(sv);
1324 I32 rem = LvTARGLEN(sv);
1328 if (rem + offs > len)
1330 sv_setpvn(sv, tmps + offs, (STRLEN)rem);
1335 Perl_magic_setsubstr(pTHX_ SV *sv, MAGIC *mg)
1338 char *tmps = SvPV(sv,len);
1339 sv_insert(LvTARG(sv),LvTARGOFF(sv),LvTARGLEN(sv), tmps, len);
1344 Perl_magic_gettaint(pTHX_ SV *sv, MAGIC *mg)
1347 TAINT_IF((mg->mg_len & 1) ||
1348 (mg->mg_len & 2) && mg->mg_obj == sv); /* kludge */
1353 Perl_magic_settaint(pTHX_ SV *sv, MAGIC *mg)
1356 if (PL_localizing) {
1357 if (PL_localizing == 1)
1362 else if (PL_tainted)
1370 Perl_magic_getvec(pTHX_ SV *sv, MAGIC *mg)
1372 SV *lsv = LvTARG(sv);
1379 sv_setuv(sv, do_vecget(lsv, LvTARGOFF(sv), LvTARGLEN(sv)));
1384 Perl_magic_setvec(pTHX_ SV *sv, MAGIC *mg)
1386 do_vecset(sv); /* XXX slurp this routine */
1391 Perl_magic_getdefelem(pTHX_ SV *sv, MAGIC *mg)
1394 if (LvTARGLEN(sv)) {
1396 SV *ahv = LvTARG(sv);
1397 if (SvTYPE(ahv) == SVt_PVHV) {
1398 HE *he = hv_fetch_ent((HV*)ahv, mg->mg_obj, FALSE, 0);
1403 SV **svp = avhv_fetch_ent((AV*)ahv, mg->mg_obj, FALSE, 0);
1409 AV* av = (AV*)LvTARG(sv);
1410 if ((I32)LvTARGOFF(sv) <= AvFILL(av))
1411 targ = AvARRAY(av)[LvTARGOFF(sv)];
1413 if (targ && targ != &PL_sv_undef) {
1414 dTHR; /* just for SvREFCNT_dec */
1415 /* somebody else defined it for us */
1416 SvREFCNT_dec(LvTARG(sv));
1417 LvTARG(sv) = SvREFCNT_inc(targ);
1419 SvREFCNT_dec(mg->mg_obj);
1420 mg->mg_obj = Nullsv;
1421 mg->mg_flags &= ~MGf_REFCOUNTED;
1426 sv_setsv(sv, targ ? targ : &PL_sv_undef);
1431 Perl_magic_setdefelem(pTHX_ SV *sv, MAGIC *mg)
1436 sv_setsv(LvTARG(sv), sv);
1437 SvSETMAGIC(LvTARG(sv));
1443 Perl_vivify_defelem(pTHX_ SV *sv)
1445 dTHR; /* just for SvREFCNT_inc and SvREFCNT_dec*/
1449 if (!LvTARGLEN(sv) || !(mg = mg_find(sv, 'y')))
1452 SV *ahv = LvTARG(sv);
1454 if (SvTYPE(ahv) == SVt_PVHV) {
1455 HE *he = hv_fetch_ent((HV*)ahv, mg->mg_obj, TRUE, 0);
1460 SV **svp = avhv_fetch_ent((AV*)ahv, mg->mg_obj, TRUE, 0);
1464 if (!value || value == &PL_sv_undef)
1465 Perl_croak(aTHX_ PL_no_helem, SvPV(mg->mg_obj, n_a));
1468 AV* av = (AV*)LvTARG(sv);
1469 if ((I32)LvTARGLEN(sv) < 0 && (I32)LvTARGOFF(sv) > AvFILL(av))
1470 LvTARG(sv) = Nullsv; /* array can't be extended */
1472 SV** svp = av_fetch(av, LvTARGOFF(sv), TRUE);
1473 if (!svp || (value = *svp) == &PL_sv_undef)
1474 Perl_croak(aTHX_ PL_no_aelem, (I32)LvTARGOFF(sv));
1477 (void)SvREFCNT_inc(value);
1478 SvREFCNT_dec(LvTARG(sv));
1481 SvREFCNT_dec(mg->mg_obj);
1482 mg->mg_obj = Nullsv;
1483 mg->mg_flags &= ~MGf_REFCOUNTED;
1487 Perl_magic_killbackrefs(pTHX_ SV *sv, MAGIC *mg)
1489 AV *av = (AV*)mg->mg_obj;
1490 SV **svp = AvARRAY(av);
1491 I32 i = AvFILLp(av);
1493 if (svp[i] && svp[i] != &PL_sv_undef) {
1494 if (!SvWEAKREF(svp[i]))
1495 Perl_croak(aTHX_ "panic: magic_killbackrefs");
1496 /* XXX Should we check that it hasn't changed? */
1499 SvWEAKREF_off(svp[i]);
1500 svp[i] = &PL_sv_undef;
1508 Perl_magic_setmglob(pTHX_ SV *sv, MAGIC *mg)
1516 Perl_magic_setbm(pTHX_ SV *sv, MAGIC *mg)
1518 sv_unmagic(sv, 'B');
1524 Perl_magic_setfm(pTHX_ SV *sv, MAGIC *mg)
1526 sv_unmagic(sv, 'f');
1532 Perl_magic_setuvar(pTHX_ SV *sv, MAGIC *mg)
1534 struct ufuncs *uf = (struct ufuncs *)mg->mg_ptr;
1536 if (uf && uf->uf_set)
1537 (*uf->uf_set)(uf->uf_index, sv);
1542 Perl_magic_freeregexp(pTHX_ SV *sv, MAGIC *mg)
1544 regexp *re = (regexp *)mg->mg_obj;
1549 #ifdef USE_LOCALE_COLLATE
1551 Perl_magic_setcollxfrm(pTHX_ SV *sv, MAGIC *mg)
1554 * RenE<eacute> Descartes said "I think not."
1555 * and vanished with a faint plop.
1558 Safefree(mg->mg_ptr);
1564 #endif /* USE_LOCALE_COLLATE */
1567 Perl_magic_set(pTHX_ SV *sv, MAGIC *mg)
1573 switch (*mg->mg_ptr) {
1574 case '\001': /* ^A */
1575 sv_setsv(PL_bodytarget, sv);
1577 case '\003': /* ^C */
1578 PL_minus_c = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
1581 case '\004': /* ^D */
1582 PL_debug = (SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv)) | 0x80000000;
1583 DEBUG_x(dump_all());
1585 case '\005': /* ^E */
1586 #ifdef MACOS_TRADITIONAL
1587 gLastMacOSErr = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
1590 set_vaxc_errno(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv));
1593 SetLastError( SvIV(sv) );
1596 /* will anyone ever use this? */
1597 SETERRNO(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv), 4);
1603 case '\006': /* ^F */
1604 PL_maxsysfd = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
1606 case '\010': /* ^H */
1607 PL_hints = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
1609 case '\011': /* ^I */ /* NOT \t in EBCDIC */
1611 Safefree(PL_inplace);
1613 PL_inplace = savepv(SvPV(sv,len));
1615 PL_inplace = Nullch;
1617 case '\017': /* ^O */
1619 Safefree(PL_osname);
1621 PL_osname = savepv(SvPV(sv,len));
1625 case '\020': /* ^P */
1626 PL_perldb = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
1627 if (PL_perldb && !PL_DBsingle)
1630 case '\024': /* ^T */
1632 PL_basetime = (Time_t)(SvNOK(sv) ? SvNVX(sv) : sv_2nv(sv));
1634 PL_basetime = (Time_t)(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv));
1637 case '\027': /* ^W & $^Warnings */
1638 if (*(mg->mg_ptr+1) == '\0') {
1639 if ( ! (PL_dowarn & G_WARN_ALL_MASK)) {
1640 i = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
1641 PL_dowarn = (PL_dowarn & ~G_WARN_ON)
1642 | (i ? G_WARN_ON : G_WARN_OFF) ;
1645 else if (strEQ(mg->mg_ptr, "\027arnings")) {
1646 if ( ! (PL_dowarn & G_WARN_ALL_MASK)) {
1647 if (memEQ(SvPVX(sv), WARN_ALLstring, WARNsize)) {
1648 PL_compiling.cop_warnings = WARN_ALL;
1649 PL_dowarn |= G_WARN_ONCE ;
1651 else if (memEQ(SvPVX(sv), WARN_NONEstring, WARNsize))
1652 PL_compiling.cop_warnings = WARN_NONE;
1654 if (specialWARN(PL_compiling.cop_warnings))
1655 PL_compiling.cop_warnings = newSVsv(sv) ;
1657 sv_setsv(PL_compiling.cop_warnings, sv);
1658 if (isWARN_on(PL_compiling.cop_warnings, WARN_ONCE))
1659 PL_dowarn |= G_WARN_ONCE ;
1665 if (PL_localizing) {
1666 if (PL_localizing == 1)
1667 save_sptr((SV**)&PL_last_in_gv);
1669 else if (SvOK(sv) && GvIO(PL_last_in_gv))
1670 IoLINES(GvIOp(PL_last_in_gv)) = (long)SvIV(sv);
1673 Safefree(IoTOP_NAME(GvIOp(PL_defoutgv)));
1674 IoTOP_NAME(GvIOp(PL_defoutgv)) = s = savepv(SvPV(sv,len));
1675 IoTOP_GV(GvIOp(PL_defoutgv)) = gv_fetchpv(s,TRUE, SVt_PVIO);
1678 Safefree(IoFMT_NAME(GvIOp(PL_defoutgv)));
1679 IoFMT_NAME(GvIOp(PL_defoutgv)) = s = savepv(SvPV(sv,len));
1680 IoFMT_GV(GvIOp(PL_defoutgv)) = gv_fetchpv(s,TRUE, SVt_PVIO);
1683 IoPAGE_LEN(GvIOp(PL_defoutgv)) = (long)(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv));
1686 IoLINES_LEFT(GvIOp(PL_defoutgv)) = (long)(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv));
1687 if (IoLINES_LEFT(GvIOp(PL_defoutgv)) < 0L)
1688 IoLINES_LEFT(GvIOp(PL_defoutgv)) = 0L;
1691 IoPAGE(GvIOp(PL_defoutgv)) = (long)(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv));
1695 IO *io = GvIOp(PL_defoutgv);
1696 if ((SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv)) == 0)
1697 IoFLAGS(io) &= ~IOf_FLUSH;
1699 if (!(IoFLAGS(io) & IOf_FLUSH)) {
1700 PerlIO *ofp = IoOFP(io);
1702 (void)PerlIO_flush(ofp);
1703 IoFLAGS(io) |= IOf_FLUSH;
1709 i = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
1710 PL_multiline = (i != 0);
1713 SvREFCNT_dec(PL_nrs);
1714 PL_nrs = newSVsv(sv);
1715 SvREFCNT_dec(PL_rs);
1716 PL_rs = SvREFCNT_inc(PL_nrs);
1721 if (SvOK(sv) || SvGMAGICAL(sv)) {
1722 s = SvPV(sv,PL_orslen);
1723 PL_ors = savepvn(s,PL_orslen);
1733 PL_ofs = savepv(SvPV(sv, PL_ofslen));
1738 PL_ofmt = savepv(SvPV(sv,len));
1741 PL_compiling.cop_arybase = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
1744 #ifdef COMPLEX_STATUS
1745 if (PL_localizing == 2) {
1746 PL_statusvalue = LvTARGOFF(sv);
1747 PL_statusvalue_vms = LvTARGLEN(sv);
1751 #ifdef VMSISH_STATUS
1753 STATUS_NATIVE_SET((U32)(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv)));
1756 STATUS_POSIX_SET(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv));
1759 SETERRNO(SvIOK(sv) ? SvIVX(sv) : SvOK(sv) ? sv_2iv(sv) : 0,
1760 (SvIV(sv) == EVMSERR) ? 4 : vaxc$errno);
1763 PL_uid = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
1764 if (PL_delaymagic) {
1765 PL_delaymagic |= DM_RUID;
1766 break; /* don't do magic till later */
1769 (void)setruid((Uid_t)PL_uid);
1772 (void)setreuid((Uid_t)PL_uid, (Uid_t)-1);
1774 #ifdef HAS_SETRESUID
1775 (void)setresuid((Uid_t)PL_uid, (Uid_t)-1, (Uid_t)-1);
1777 if (PL_uid == PL_euid) /* special case $< = $> */
1778 (void)PerlProc_setuid(PL_uid);
1780 PL_uid = PerlProc_getuid();
1781 Perl_croak(aTHX_ "setruid() not implemented");
1786 PL_uid = PerlProc_getuid();
1787 PL_tainting |= (PL_uid && (PL_euid != PL_uid || PL_egid != PL_gid));
1790 PL_euid = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
1791 if (PL_delaymagic) {
1792 PL_delaymagic |= DM_EUID;
1793 break; /* don't do magic till later */
1796 (void)seteuid((Uid_t)PL_euid);
1799 (void)setreuid((Uid_t)-1, (Uid_t)PL_euid);
1801 #ifdef HAS_SETRESUID
1802 (void)setresuid((Uid_t)-1, (Uid_t)PL_euid, (Uid_t)-1);
1804 if (PL_euid == PL_uid) /* special case $> = $< */
1805 PerlProc_setuid(PL_euid);
1807 PL_euid = PerlProc_geteuid();
1808 Perl_croak(aTHX_ "seteuid() not implemented");
1813 PL_euid = PerlProc_geteuid();
1814 PL_tainting |= (PL_uid && (PL_euid != PL_uid || PL_egid != PL_gid));
1817 PL_gid = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
1818 if (PL_delaymagic) {
1819 PL_delaymagic |= DM_RGID;
1820 break; /* don't do magic till later */
1823 (void)setrgid((Gid_t)PL_gid);
1826 (void)setregid((Gid_t)PL_gid, (Gid_t)-1);
1828 #ifdef HAS_SETRESGID
1829 (void)setresgid((Gid_t)PL_gid, (Gid_t)-1, (Gid_t) 1);
1831 if (PL_gid == PL_egid) /* special case $( = $) */
1832 (void)PerlProc_setgid(PL_gid);
1834 PL_gid = PerlProc_getgid();
1835 Perl_croak(aTHX_ "setrgid() not implemented");
1840 PL_gid = PerlProc_getgid();
1841 PL_tainting |= (PL_uid && (PL_euid != PL_uid || PL_egid != PL_gid));
1844 #ifdef HAS_SETGROUPS
1846 char *p = SvPV(sv, len);
1847 Groups_t gary[NGROUPS];
1852 for (i = 0; i < NGROUPS; ++i) {
1853 while (*p && !isSPACE(*p))
1862 (void)setgroups(i, gary);
1864 #else /* HAS_SETGROUPS */
1865 PL_egid = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
1866 #endif /* HAS_SETGROUPS */
1867 if (PL_delaymagic) {
1868 PL_delaymagic |= DM_EGID;
1869 break; /* don't do magic till later */
1872 (void)setegid((Gid_t)PL_egid);
1875 (void)setregid((Gid_t)-1, (Gid_t)PL_egid);
1877 #ifdef HAS_SETRESGID
1878 (void)setresgid((Gid_t)-1, (Gid_t)PL_egid, (Gid_t)-1);
1880 if (PL_egid == PL_gid) /* special case $) = $( */
1881 (void)PerlProc_setgid(PL_egid);
1883 PL_egid = PerlProc_getegid();
1884 Perl_croak(aTHX_ "setegid() not implemented");
1889 PL_egid = PerlProc_getegid();
1890 PL_tainting |= (PL_uid && (PL_euid != PL_uid || PL_egid != PL_gid));
1893 PL_chopset = SvPV_force(sv,len);
1895 #ifndef MACOS_TRADITIONAL
1900 /* See if all the arguments are contiguous in memory */
1901 for (i = 1; i < PL_origargc; i++) {
1902 if (PL_origargv[i] == s + 1
1904 || PL_origargv[i] == s + 2
1909 s += strlen(s); /* this one is ok too */
1914 /* can grab env area too? */
1915 if (PL_origenviron && (PL_origenviron[0] == s + 1
1917 || (PL_origenviron[0] == s + 9 && (s += 8))
1920 my_setenv("NoNe SuCh", Nullch);
1921 /* force copy of environment */
1922 for (i = 0; PL_origenviron[i]; i++)
1923 if (PL_origenviron[i] == s + 1) {
1930 PL_origalen = s - PL_origargv[0];
1932 s = SvPV_force(sv,len);
1934 if (i >= PL_origalen) {
1936 /* don't allow system to limit $0 seen by script */
1937 /* SvCUR_set(sv, i); *SvEND(sv) = '\0'; */
1938 Copy(s, PL_origargv[0], i, char);
1939 s = PL_origargv[0]+i;
1943 Copy(s, PL_origargv[0], i, char);
1944 s = PL_origargv[0]+i;
1946 while (++i < PL_origalen)
1948 s = PL_origargv[0]+i;
1949 for (i = 1; i < PL_origargc; i++)
1950 PL_origargv[i] = Nullch;
1956 sv_setsv(thr->errsv, sv);
1958 #endif /* USE_THREADS */
1965 Perl_magic_mutexfree(pTHX_ SV *sv, MAGIC *mg)
1968 DEBUG_S(PerlIO_printf(Perl_debug_log,
1969 "0x%"UVxf": magic_mutexfree 0x%"UVxf"\n",
1970 PTR2UV(thr), PTR2UV(sv));)
1972 Perl_croak(aTHX_ "panic: magic_mutexfree");
1973 MUTEX_DESTROY(MgMUTEXP(mg));
1974 COND_DESTROY(MgCONDP(mg));
1977 #endif /* USE_THREADS */
1980 Perl_whichsig(pTHX_ char *sig)
1982 register char **sigv;
1984 for (sigv = PL_sig_name+1; *sigv; sigv++)
1985 if (strEQ(sig,*sigv))
1986 return PL_sig_num[sigv - PL_sig_name];
1988 if (strEQ(sig,"CHLD"))
1992 if (strEQ(sig,"CLD"))
2001 Perl_sighandler(int sig)
2007 SV *sv, *tSv = PL_Sv;
2011 I32 o_save_i = PL_savestack_ix, type;
2014 if (PL_savestack_ix + 15 <= PL_savestack_max)
2016 if (PL_markstack_ptr < PL_markstack_max - 2)
2018 if (PL_retstack_ix < PL_retstack_max - 2)
2020 if (PL_scopestack_ix < PL_scopestack_max - 3)
2023 if (!PL_psig_ptr[sig])
2024 Perl_die(aTHX_ "Signal SIG%s received, but no signal handler set.\n",
2027 /* Max number of items pushed there is 3*n or 4. We cannot fix
2028 infinity, so we fix 4 (in fact 5): */
2030 PL_savestack_ix += 5; /* Protect save in progress. */
2031 o_save_i = PL_savestack_ix;
2032 SAVEDESTRUCTOR_X(unwind_handler_stack, (void*)&flags);
2035 PL_markstack_ptr++; /* Protect mark. */
2038 PL_retstack[PL_retstack_ix] = NULL;
2041 PL_scopestack_ix += 1;
2042 /* sv_2cv is too complicated, try a simpler variant first: */
2043 if (!SvROK(PL_psig_ptr[sig]) || !(cv = (CV*)SvRV(PL_psig_ptr[sig]))
2044 || SvTYPE(cv) != SVt_PVCV)
2045 cv = sv_2cv(PL_psig_ptr[sig],&st,&gv,TRUE);
2047 if (!cv || !CvROOT(cv)) {
2048 if (ckWARN(WARN_SIGNAL))
2049 Perl_warner(aTHX_ WARN_SIGNAL, "SIG%s handler \"%s\" not defined.\n",
2050 PL_sig_name[sig], (gv ? GvENAME(gv)
2057 if(PL_psig_name[sig]) {
2058 sv = SvREFCNT_inc(PL_psig_name[sig]);
2062 sv = sv_newmortal();
2063 sv_setpv(sv,PL_sig_name[sig]);
2066 PUSHSTACKi(PERLSI_SIGNAL);
2071 call_sv((SV*)cv, G_DISCARD);
2076 PL_savestack_ix -= 8; /* Unprotect save in progress. */
2082 PL_scopestack_ix -= 1;
2085 PL_op = myop; /* Apparently not needed... */
2087 PL_Sv = tSv; /* Restore global temporaries. */
2098 restore_magic(pTHXo_ void *p)
2101 MGS* mgs = SSPTR((I32)p, MGS*);
2102 SV* sv = mgs->mgs_sv;
2107 if (SvTYPE(sv) >= SVt_PVMG && SvMAGIC(sv))
2110 SvFLAGS(sv) |= mgs->mgs_flags;
2114 SvFLAGS(sv) &= ~(SVf_IOK|SVf_NOK|SVf_POK);
2117 mgs->mgs_sv = NULL; /* mark the MGS structure as restored */
2119 /* If we're still on top of the stack, pop us off. (That condition
2120 * will be satisfied if restore_magic was called explicitly, but *not*
2121 * if it's being called via leave_scope.)
2122 * The reason for doing this is that otherwise, things like sv_2cv()
2123 * may leave alloc gunk on the savestack, and some code
2124 * (e.g. sighandler) doesn't expect that...
2126 if (PL_savestack_ix == mgs->mgs_ss_ix)
2128 I32 popval = SSPOPINT;
2129 assert(popval == SAVEt_DESTRUCTOR_X);
2130 PL_savestack_ix -= 2;
2132 assert(popval == SAVEt_ALLOC);
2134 PL_savestack_ix -= popval;
2140 unwind_handler_stack(pTHXo_ void *p)
2143 U32 flags = *(U32*)p;
2146 PL_savestack_ix -= 5; /* Unprotect save in progress. */
2147 /* cxstack_ix-- Not needed, die already unwound it. */
2149 SvREFCNT_dec(sig_sv);