This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
hints fixups for PowerMAX (from Tom Horsley)
[perl5.git] / mg.c
CommitLineData
a0d0e21e 1/* mg.c
79072805 2 *
3818b22b 3 * Copyright (c) 1991-2000, Larry Wall
79072805
LW
4 *
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.
7 *
a0d0e21e
LW
8 */
9
10/*
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."
79072805
LW
13 */
14
15#include "EXTERN.h"
864dbfa3 16#define PERL_IN_MG_C
79072805
LW
17#include "perl.h"
18
e6d9441c 19/* XXX If this causes problems, set i_unistd=undef in the hint file. */
a0d0e21e
LW
20#ifdef I_UNISTD
21# include <unistd.h>
22#endif
a0d0e21e 23
5cd24f17 24#if defined(HAS_GETGROUPS) || defined(HAS_SETGROUPS)
188ea221
CS
25# ifndef NGROUPS
26# define NGROUPS 32
27# endif
28#endif
29
51371543
GS
30static void restore_magic(pTHXo_ void *p);
31static void unwind_handler_stack(pTHXo_ void *p);
32
c07a80fd
PP
33/*
34 * Use the "DESTRUCTOR" scope cleanup to reinstate magic.
35 */
36
37struct magic_state {
38 SV* mgs_sv;
39 U32 mgs_flags;
455ece5e 40 I32 mgs_ss_ix;
c07a80fd 41};
455ece5e 42/* MGS is typedef'ed to struct magic_state in perl.h */
76e3520e
GS
43
44STATIC void
cea2e8a9 45S_save_magic(pTHX_ I32 mgs_ix, SV *sv)
c07a80fd 46{
46124e9e 47 dTHR;
455ece5e 48 MGS* mgs;
c07a80fd
PP
49 assert(SvMAGICAL(sv));
50
c76ac1ee 51 SAVEDESTRUCTOR_X(restore_magic, (void*)mgs_ix);
455ece5e
AD
52
53 mgs = SSPTR(mgs_ix, MGS*);
c07a80fd
PP
54 mgs->mgs_sv = sv;
55 mgs->mgs_flags = SvMAGICAL(sv) | SvREADONLY(sv);
455ece5e 56 mgs->mgs_ss_ix = PL_savestack_ix; /* points after the saved destructor */
c07a80fd
PP
57
58 SvMAGICAL_off(sv);
59 SvREADONLY_off(sv);
60 SvFLAGS(sv) |= (SvFLAGS(sv) & (SVp_IOK|SVp_NOK|SVp_POK)) >> PRIVSHIFT;
c07a80fd
PP
61}
62
954c1994
GS
63/*
64=for apidoc mg_magical
65
66Turns on the magical status of an SV. See C<sv_magic>.
67
68=cut
69*/
70
8990e307 71void
864dbfa3 72Perl_mg_magical(pTHX_ SV *sv)
8990e307
LW
73{
74 MAGIC* mg;
75 for (mg = SvMAGIC(sv); mg; mg = mg->mg_moremagic) {
76 MGVTBL* vtbl = mg->mg_virtual;
77 if (vtbl) {
2b260de0 78 if (vtbl->svt_get && !(mg->mg_flags & MGf_GSKIP))
8990e307
LW
79 SvGMAGICAL_on(sv);
80 if (vtbl->svt_set)
81 SvSMAGICAL_on(sv);
2b260de0 82 if (!(SvFLAGS(sv) & (SVs_GMG|SVs_SMG)) || vtbl->svt_clear)
8990e307
LW
83 SvRMAGICAL_on(sv);
84 }
85 }
86}
87
954c1994
GS
88/*
89=for apidoc mg_get
90
91Do magic after a value is retrieved from the SV. See C<sv_magic>.
92
93=cut
94*/
95
79072805 96int
864dbfa3 97Perl_mg_get(pTHX_ SV *sv)
79072805 98{
46124e9e 99 dTHR;
455ece5e 100 I32 mgs_ix;
79072805 101 MAGIC* mg;
c6496cc7 102 MAGIC** mgp;
760ac839 103 int mgp_valid = 0;
463ee0b2 104
455ece5e
AD
105 mgs_ix = SSNEW(sizeof(MGS));
106 save_magic(mgs_ix, sv);
463ee0b2 107
c6496cc7
PP
108 mgp = &SvMAGIC(sv);
109 while ((mg = *mgp) != 0) {
79072805 110 MGVTBL* vtbl = mg->mg_virtual;
2b260de0 111 if (!(mg->mg_flags & MGf_GSKIP) && vtbl && vtbl->svt_get) {
316ad4fe 112 CALL_FPTR(vtbl->svt_get)(aTHX_ sv, mg);
c6496cc7 113 /* Ignore this magic if it's been deleted */
48e43a1c
CS
114 if ((mg == (mgp_valid ? *mgp : SvMAGIC(sv))) &&
115 (mg->mg_flags & MGf_GSKIP))
455ece5e 116 (SSPTR(mgs_ix, MGS*))->mgs_flags = 0;
a0d0e21e 117 }
c6496cc7 118 /* Advance to next magic (complicated by possible deletion) */
760ac839 119 if (mg == (mgp_valid ? *mgp : SvMAGIC(sv))) {
c6496cc7 120 mgp = &mg->mg_moremagic;
760ac839
LW
121 mgp_valid = 1;
122 }
123 else
124 mgp = &SvMAGIC(sv); /* Re-establish pointer after sv_upgrade */
79072805 125 }
463ee0b2 126
51371543 127 restore_magic(aTHXo_ (void*)mgs_ix);
79072805
LW
128 return 0;
129}
130
954c1994
GS
131/*
132=for apidoc mg_set
133
134Do magic after a value is assigned to the SV. See C<sv_magic>.
135
136=cut
137*/
138
79072805 139int
864dbfa3 140Perl_mg_set(pTHX_ SV *sv)
79072805 141{
46124e9e 142 dTHR;
455ece5e 143 I32 mgs_ix;
79072805 144 MAGIC* mg;
463ee0b2
LW
145 MAGIC* nextmg;
146
455ece5e
AD
147 mgs_ix = SSNEW(sizeof(MGS));
148 save_magic(mgs_ix, sv);
463ee0b2
LW
149
150 for (mg = SvMAGIC(sv); mg; mg = nextmg) {
79072805 151 MGVTBL* vtbl = mg->mg_virtual;
463ee0b2 152 nextmg = mg->mg_moremagic; /* it may delete itself */
a0d0e21e
LW
153 if (mg->mg_flags & MGf_GSKIP) {
154 mg->mg_flags &= ~MGf_GSKIP; /* setting requires another read */
455ece5e 155 (SSPTR(mgs_ix, MGS*))->mgs_flags = 0;
a0d0e21e 156 }
2b260de0 157 if (vtbl && vtbl->svt_set)
fc0dc3b3 158 CALL_FPTR(vtbl->svt_set)(aTHX_ sv, mg);
79072805 159 }
463ee0b2 160
51371543 161 restore_magic(aTHXo_ (void*)mgs_ix);
79072805
LW
162 return 0;
163}
164
954c1994
GS
165/*
166=for apidoc mg_length
167
168Report on the SV's length. See C<sv_magic>.
169
170=cut
171*/
172
79072805 173U32
864dbfa3 174Perl_mg_length(pTHX_ SV *sv)
79072805
LW
175{
176 MAGIC* mg;
748a9306 177 char *junk;
463ee0b2 178 STRLEN len;
463ee0b2 179
79072805
LW
180 for (mg = SvMAGIC(sv); mg; mg = mg->mg_moremagic) {
181 MGVTBL* vtbl = mg->mg_virtual;
2b260de0 182 if (vtbl && vtbl->svt_len) {
455ece5e 183 I32 mgs_ix;
48e43a1c 184
455ece5e
AD
185 mgs_ix = SSNEW(sizeof(MGS));
186 save_magic(mgs_ix, sv);
a0d0e21e 187 /* omit MGf_GSKIP -- not changed here */
fc0dc3b3 188 len = CALL_FPTR(vtbl->svt_len)(aTHX_ sv, mg);
51371543 189 restore_magic(aTHXo_ (void*)mgs_ix);
85e6fe83
LW
190 return len;
191 }
192 }
193
748a9306 194 junk = SvPV(sv, len);
463ee0b2 195 return len;
79072805
LW
196}
197
93965878 198I32
864dbfa3 199Perl_mg_size(pTHX_ SV *sv)
93965878
NIS
200{
201 MAGIC* mg;
202 I32 len;
203
204 for (mg = SvMAGIC(sv); mg; mg = mg->mg_moremagic) {
205 MGVTBL* vtbl = mg->mg_virtual;
2b260de0 206 if (vtbl && vtbl->svt_len) {
455ece5e
AD
207 I32 mgs_ix;
208
209 mgs_ix = SSNEW(sizeof(MGS));
210 save_magic(mgs_ix, sv);
93965878 211 /* omit MGf_GSKIP -- not changed here */
fc0dc3b3 212 len = CALL_FPTR(vtbl->svt_len)(aTHX_ sv, mg);
51371543 213 restore_magic(aTHXo_ (void*)mgs_ix);
93965878
NIS
214 return len;
215 }
216 }
217
218 switch(SvTYPE(sv)) {
219 case SVt_PVAV:
220 len = AvFILLp((AV *) sv); /* Fallback to non-tied array */
221 return len;
222 case SVt_PVHV:
223 /* FIXME */
224 default:
cea2e8a9 225 Perl_croak(aTHX_ "Size magic not implemented");
93965878
NIS
226 break;
227 }
228 return 0;
229}
230
954c1994
GS
231/*
232=for apidoc mg_clear
233
234Clear something magical that the SV represents. See C<sv_magic>.
235
236=cut
237*/
238
79072805 239int
864dbfa3 240Perl_mg_clear(pTHX_ SV *sv)
79072805 241{
455ece5e 242 I32 mgs_ix;
79072805 243 MAGIC* mg;
463ee0b2 244
455ece5e
AD
245 mgs_ix = SSNEW(sizeof(MGS));
246 save_magic(mgs_ix, sv);
463ee0b2 247
79072805
LW
248 for (mg = SvMAGIC(sv); mg; mg = mg->mg_moremagic) {
249 MGVTBL* vtbl = mg->mg_virtual;
a0d0e21e
LW
250 /* omit GSKIP -- never set here */
251
2b260de0 252 if (vtbl && vtbl->svt_clear)
fc0dc3b3 253 CALL_FPTR(vtbl->svt_clear)(aTHX_ sv, mg);
79072805 254 }
463ee0b2 255
51371543 256 restore_magic(aTHXo_ (void*)mgs_ix);
79072805
LW
257 return 0;
258}
259
954c1994
GS
260/*
261=for apidoc mg_find
262
263Finds the magic pointer for type matching the SV. See C<sv_magic>.
264
265=cut
266*/
267
93a17b20 268MAGIC*
864dbfa3 269Perl_mg_find(pTHX_ SV *sv, int type)
93a17b20
LW
270{
271 MAGIC* mg;
93a17b20
LW
272 for (mg = SvMAGIC(sv); mg; mg = mg->mg_moremagic) {
273 if (mg->mg_type == type)
274 return mg;
275 }
276 return 0;
277}
278
954c1994
GS
279/*
280=for apidoc mg_copy
281
282Copies the magic from one SV to another. See C<sv_magic>.
283
284=cut
285*/
286
79072805 287int
864dbfa3 288Perl_mg_copy(pTHX_ SV *sv, SV *nsv, const char *key, I32 klen)
79072805 289{
463ee0b2 290 int count = 0;
79072805 291 MAGIC* mg;
463ee0b2
LW
292 for (mg = SvMAGIC(sv); mg; mg = mg->mg_moremagic) {
293 if (isUPPER(mg->mg_type)) {
33c27489
GS
294 sv_magic(nsv,
295 mg->mg_type == 'P' ? SvTIED_obj(sv, mg) : mg->mg_obj,
296 toLOWER(mg->mg_type), key, klen);
463ee0b2 297 count++;
79072805 298 }
79072805 299 }
463ee0b2 300 return count;
79072805
LW
301}
302
954c1994
GS
303/*
304=for apidoc mg_free
305
306Free any magic storage used by the SV. See C<sv_magic>.
307
308=cut
309*/
310
79072805 311int
864dbfa3 312Perl_mg_free(pTHX_ SV *sv)
79072805
LW
313{
314 MAGIC* mg;
315 MAGIC* moremagic;
316 for (mg = SvMAGIC(sv); mg; mg = moremagic) {
317 MGVTBL* vtbl = mg->mg_virtual;
318 moremagic = mg->mg_moremagic;
2b260de0 319 if (vtbl && vtbl->svt_free)
fc0dc3b3 320 CALL_FPTR(vtbl->svt_free)(aTHX_ sv, mg);
93a17b20 321 if (mg->mg_ptr && mg->mg_type != 'g')
565764a8 322 if (mg->mg_len >= 0)
88e89b8a 323 Safefree(mg->mg_ptr);
565764a8 324 else if (mg->mg_len == HEf_SVKEY)
88e89b8a 325 SvREFCNT_dec((SV*)mg->mg_ptr);
85e6fe83 326 if (mg->mg_flags & MGf_REFCOUNTED)
8990e307 327 SvREFCNT_dec(mg->mg_obj);
79072805
LW
328 Safefree(mg);
329 }
330 SvMAGIC(sv) = 0;
331 return 0;
332}
333
334#if !defined(NSIG) || defined(M_UNIX) || defined(M_XENIX)
335#include <signal.h>
336#endif
337
942e002e 338U32
864dbfa3 339Perl_magic_regdata_cnt(pTHX_ SV *sv, MAGIC *mg)
6cef1e77
IZ
340{
341 dTHR;
6cef1e77 342 register REGEXP *rx;
6cef1e77 343
8f580fb8
IZ
344 if (PL_curpm && (rx = PL_curpm->op_pmregexp)) {
345 if (mg->mg_obj) /* @+ */
346 return rx->nparens;
347 else /* @- */
348 return rx->lastparen;
349 }
350
942e002e 351 return (U32)-1;
6cef1e77
IZ
352}
353
354int
864dbfa3 355Perl_magic_regdatum_get(pTHX_ SV *sv, MAGIC *mg)
6cef1e77
IZ
356{
357 dTHR;
358 register I32 paren;
cf93c79d 359 register I32 s;
6cef1e77
IZ
360 register I32 i;
361 register REGEXP *rx;
cf93c79d 362 I32 t;
6cef1e77
IZ
363
364 if (PL_curpm && (rx = PL_curpm->op_pmregexp)) {
365 paren = mg->mg_len;
366 if (paren < 0)
367 return 0;
368 if (paren <= rx->nparens &&
cf93c79d
IZ
369 (s = rx->startp[paren]) != -1 &&
370 (t = rx->endp[paren]) != -1)
6cef1e77
IZ
371 {
372 if (mg->mg_obj) /* @+ */
cf93c79d 373 i = t;
6cef1e77 374 else /* @- */
cf93c79d 375 i = s;
6cef1e77
IZ
376 sv_setiv(sv,i);
377 }
378 }
379 return 0;
380}
381
93a17b20 382U32
864dbfa3 383Perl_magic_len(pTHX_ SV *sv, MAGIC *mg)
93a17b20 384{
a863c7d1 385 dTHR;
93a17b20 386 register I32 paren;
93a17b20 387 register I32 i;
d9f97599 388 register REGEXP *rx;
93a17b20
LW
389
390 switch (*mg->mg_ptr) {
391 case '1': case '2': case '3': case '4':
392 case '5': case '6': case '7': case '8': case '9': case '&':
3280af22 393 if (PL_curpm && (rx = PL_curpm->op_pmregexp)) {
cf93c79d
IZ
394 I32 s1, t1;
395
93a17b20
LW
396 paren = atoi(mg->mg_ptr);
397 getparen:
d9f97599 398 if (paren <= rx->nparens &&
cf93c79d
IZ
399 (s1 = rx->startp[paren]) != -1 &&
400 (t1 = rx->endp[paren]) != -1)
bbce6d69 401 {
cf93c79d 402 i = t1 - s1;
71be2cbc 403 if (i >= 0)
93a17b20 404 return i;
93a17b20 405 }
93a17b20 406 }
748a9306 407 return 0;
93a17b20 408 case '+':
3280af22 409 if (PL_curpm && (rx = PL_curpm->op_pmregexp)) {
d9f97599 410 paren = rx->lastparen;
13f57bf8
CS
411 if (paren)
412 goto getparen;
93a17b20 413 }
748a9306 414 return 0;
93a17b20 415 case '`':
3280af22 416 if (PL_curpm && (rx = PL_curpm->op_pmregexp)) {
cf93c79d
IZ
417 if (rx->startp[0] != -1) {
418 i = rx->startp[0];
71be2cbc 419 if (i >= 0)
93a17b20 420 return i;
93a17b20 421 }
93a17b20 422 }
748a9306 423 return 0;
93a17b20 424 case '\'':
3280af22 425 if (PL_curpm && (rx = PL_curpm->op_pmregexp)) {
cf93c79d
IZ
426 if (rx->endp[0] != -1) {
427 i = rx->sublen - rx->endp[0];
13f57bf8 428 if (i >= 0)
5cd24f17 429 return i;
93a17b20 430 }
93a17b20 431 }
748a9306 432 return 0;
93a17b20 433 case ',':
3280af22 434 return (STRLEN)PL_ofslen;
93a17b20 435 case '\\':
3280af22 436 return (STRLEN)PL_orslen;
93a17b20
LW
437 }
438 magic_get(sv,mg);
2d8e6c8d
GS
439 if (!SvPOK(sv) && SvNIOK(sv)) {
440 STRLEN n_a;
441 sv_2pv(sv, &n_a);
442 }
93a17b20
LW
443 if (SvPOK(sv))
444 return SvCUR(sv);
445 return 0;
446}
447
79072805 448int
864dbfa3 449Perl_magic_get(pTHX_ SV *sv, MAGIC *mg)
79072805 450{
a863c7d1 451 dTHR;
79072805
LW
452 register I32 paren;
453 register char *s;
454 register I32 i;
d9f97599 455 register REGEXP *rx;
79072805
LW
456
457 switch (*mg->mg_ptr) {
748a9306 458 case '\001': /* ^A */
3280af22 459 sv_setsv(sv, PL_bodytarget);
748a9306 460 break;
49460fe6
NIS
461 case '\003': /* ^C */
462 sv_setiv(sv, (IV)PL_minus_c);
463 break;
464
79072805 465 case '\004': /* ^D */
3280af22 466 sv_setiv(sv, (IV)(PL_debug & 32767));
d056ab3f
GS
467#if defined(YYDEBUG) && defined(DEBUGGING)
468 PL_yydebug = (PL_debug & 1);
469#endif
79072805 470 break;
28f23441 471 case '\005': /* ^E */
cd39f2b6
JH
472#ifdef MACOS_TRADITIONAL
473 {
474 char msg[256];
475
476 sv_setnv(sv,(double)gLastMacOSErr);
477 sv_setpv(sv, gLastMacOSErr ? GetSysErrText(gLastMacOSErr, msg) : "");
478 }
479#else
28f23441
PP
480#ifdef VMS
481 {
482# include <descrip.h>
483# include <starlet.h>
484 char msg[255];
485 $DESCRIPTOR(msgdsc,msg);
65202027 486 sv_setnv(sv,(NV) vaxc$errno);
28f23441
PP
487 if (sys$getmsg(vaxc$errno,&msgdsc.dsc$w_length,&msgdsc,0,0) & 1)
488 sv_setpvn(sv,msgdsc.dsc$a_pointer,msgdsc.dsc$w_length);
489 else
490 sv_setpv(sv,"");
491 }
492#else
88e89b8a 493#ifdef OS2
fb73857a 494 if (!(_emx_env & 0x200)) { /* Under DOS */
65202027 495 sv_setnv(sv, (NV)errno);
fb73857a
PP
496 sv_setpv(sv, errno ? Strerror(errno) : "");
497 } else {
017f25f1
IZ
498 if (errno != errno_isOS2) {
499 int tmp = _syserrno();
500 if (tmp) /* 2nd call to _syserrno() makes it 0 */
501 Perl_rc = tmp;
502 }
65202027 503 sv_setnv(sv, (NV)Perl_rc);
fb73857a
PP
504 sv_setpv(sv, os2error(Perl_rc));
505 }
88e89b8a 506#else
22fae026
TM
507#ifdef WIN32
508 {
509 DWORD dwErr = GetLastError();
65202027 510 sv_setnv(sv, (NV)dwErr);
22fae026 511 if (dwErr)
76e3520e 512 {
0cb96387 513 PerlProc_GetOSError(sv, dwErr);
76e3520e 514 }
22fae026
TM
515 else
516 sv_setpv(sv, "");
517 SetLastError(dwErr);
518 }
519#else
65202027 520 sv_setnv(sv, (NV)errno);
28f23441
PP
521 sv_setpv(sv, errno ? Strerror(errno) : "");
522#endif
88e89b8a 523#endif
22fae026 524#endif
cd39f2b6 525#endif
946ec16e 526 SvNOK_on(sv); /* what a wonderful hack! */
28f23441 527 break;
79072805 528 case '\006': /* ^F */
3280af22 529 sv_setiv(sv, (IV)PL_maxsysfd);
79072805 530 break;
a0d0e21e 531 case '\010': /* ^H */
3280af22 532 sv_setiv(sv, (IV)PL_hints);
a0d0e21e 533 break;
9d116dd7 534 case '\011': /* ^I */ /* NOT \t in EBCDIC */
3280af22
NIS
535 if (PL_inplace)
536 sv_setpv(sv, PL_inplace);
79072805 537 else
3280af22 538 sv_setsv(sv, &PL_sv_undef);
79072805 539 break;
28f23441 540 case '\017': /* ^O */
3280af22 541 sv_setpv(sv, PL_osname);
28f23441 542 break;
79072805 543 case '\020': /* ^P */
3280af22 544 sv_setiv(sv, (IV)PL_perldb);
79072805 545 break;
fb73857a 546 case '\023': /* ^S */
d58bf5aa
MB
547 {
548 dTHR;
3280af22 549 if (PL_lex_state != LEX_NOTPARSING)
155aba94 550 (void)SvOK_off(sv);
3280af22 551 else if (PL_in_eval)
d58bf5aa
MB
552 sv_setiv(sv, 1);
553 else
554 sv_setiv(sv, 0);
555 }
fb73857a 556 break;
79072805 557 case '\024': /* ^T */
88e89b8a 558#ifdef BIG_TIME
6b88bc9c 559 sv_setnv(sv, PL_basetime);
88e89b8a 560#else
3280af22 561 sv_setiv(sv, (IV)PL_basetime);
88e89b8a 562#endif
79072805 563 break;
46487f74 564 case '\027': /* ^W & $^WARNING_BITS & ^WIDE_SYSTEM_CALLS */
4438c4b7
JH
565 if (*(mg->mg_ptr+1) == '\0')
566 sv_setiv(sv, (IV)((PL_dowarn & G_WARN_ON) ? TRUE : FALSE));
6a818117 567 else if (strEQ(mg->mg_ptr, "\027ARNING_BITS")) {
d3a7d8c7
GS
568 if (PL_compiling.cop_warnings == pWARN_NONE ||
569 PL_compiling.cop_warnings == pWARN_STD)
4438c4b7
JH
570 {
571 sv_setpvn(sv, WARN_NONEstring, WARNsize) ;
572 }
d3a7d8c7 573 else if (PL_compiling.cop_warnings == pWARN_ALL) {
4438c4b7
JH
574 sv_setpvn(sv, WARN_ALLstring, WARNsize) ;
575 }
576 else {
577 sv_setsv(sv, PL_compiling.cop_warnings);
578 }
d3a7d8c7 579 SvPOK_only(sv);
4438c4b7 580 }
46487f74
GS
581 else if (strEQ(mg->mg_ptr, "\027IDE_SYSTEM_CALLS"))
582 sv_setiv(sv, (IV)PL_widesyscalls);
79072805
LW
583 break;
584 case '1': case '2': case '3': case '4':
585 case '5': case '6': case '7': case '8': case '9': case '&':
3280af22 586 if (PL_curpm && (rx = PL_curpm->op_pmregexp)) {
cf93c79d
IZ
587 I32 s1, t1;
588
a863c7d1
MB
589 /*
590 * Pre-threads, this was paren = atoi(GvENAME((GV*)mg->mg_obj));
591 * XXX Does the new way break anything?
592 */
593 paren = atoi(mg->mg_ptr);
79072805 594 getparen:
d9f97599 595 if (paren <= rx->nparens &&
cf93c79d
IZ
596 (s1 = rx->startp[paren]) != -1 &&
597 (t1 = rx->endp[paren]) != -1)
bbce6d69 598 {
cf93c79d
IZ
599 i = t1 - s1;
600 s = rx->subbeg + s1;
13f57bf8 601 getrx:
748a9306 602 if (i >= 0) {
13f57bf8 603 bool was_tainted;
3280af22
NIS
604 if (PL_tainting) {
605 was_tainted = PL_tainted;
606 PL_tainted = FALSE;
13f57bf8 607 }
cf93c79d 608 sv_setpvn(sv, s, i);
7e2040f0
GS
609 if ((PL_curpm->op_pmdynflags & PMdf_UTF8) && !IN_BYTE)
610 SvUTF8_on(sv);
611 else
612 SvUTF8_off(sv);
3280af22
NIS
613 if (PL_tainting)
614 PL_tainted = (was_tainted || RX_MATCH_TAINTED(rx));
748a9306
LW
615 break;
616 }
79072805 617 }
79072805 618 }
3280af22 619 sv_setsv(sv,&PL_sv_undef);
79072805
LW
620 break;
621 case '+':
3280af22 622 if (PL_curpm && (rx = PL_curpm->op_pmregexp)) {
d9f97599 623 paren = rx->lastparen;
a0d0e21e
LW
624 if (paren)
625 goto getparen;
79072805 626 }
3280af22 627 sv_setsv(sv,&PL_sv_undef);
79072805
LW
628 break;
629 case '`':
3280af22 630 if (PL_curpm && (rx = PL_curpm->op_pmregexp)) {
cf93c79d
IZ
631 if ((s = rx->subbeg) && rx->startp[0] != -1) {
632 i = rx->startp[0];
13f57bf8 633 goto getrx;
79072805 634 }
79072805 635 }
3280af22 636 sv_setsv(sv,&PL_sv_undef);
79072805
LW
637 break;
638 case '\'':
3280af22 639 if (PL_curpm && (rx = PL_curpm->op_pmregexp)) {
cf93c79d
IZ
640 if (rx->subbeg && rx->endp[0] != -1) {
641 s = rx->subbeg + rx->endp[0];
642 i = rx->sublen - rx->endp[0];
13f57bf8 643 goto getrx;
79072805 644 }
79072805 645 }
3280af22 646 sv_setsv(sv,&PL_sv_undef);
79072805
LW
647 break;
648 case '.':
649#ifndef lint
3280af22
NIS
650 if (GvIO(PL_last_in_gv)) {
651 sv_setiv(sv, (IV)IoLINES(GvIO(PL_last_in_gv)));
79072805
LW
652 }
653#endif
654 break;
655 case '?':
809a5acc 656 {
809a5acc 657 sv_setiv(sv, (IV)STATUS_CURRENT);
ff0cee69 658#ifdef COMPLEX_STATUS
6b88bc9c
GS
659 LvTARGOFF(sv) = PL_statusvalue;
660 LvTARGLEN(sv) = PL_statusvalue_vms;
ff0cee69 661#endif
809a5acc 662 }
79072805
LW
663 break;
664 case '^':
3280af22 665 s = IoTOP_NAME(GvIOp(PL_defoutgv));
79072805
LW
666 if (s)
667 sv_setpv(sv,s);
668 else {
3280af22 669 sv_setpv(sv,GvENAME(PL_defoutgv));
79072805
LW
670 sv_catpv(sv,"_TOP");
671 }
672 break;
673 case '~':
3280af22 674 s = IoFMT_NAME(GvIOp(PL_defoutgv));
79072805 675 if (!s)
3280af22 676 s = GvENAME(PL_defoutgv);
79072805
LW
677 sv_setpv(sv,s);
678 break;
679#ifndef lint
680 case '=':
3280af22 681 sv_setiv(sv, (IV)IoPAGE_LEN(GvIOp(PL_defoutgv)));
79072805
LW
682 break;
683 case '-':
3280af22 684 sv_setiv(sv, (IV)IoLINES_LEFT(GvIOp(PL_defoutgv)));
79072805
LW
685 break;
686 case '%':
3280af22 687 sv_setiv(sv, (IV)IoPAGE(GvIOp(PL_defoutgv)));
79072805
LW
688 break;
689#endif
690 case ':':
691 break;
692 case '/':
693 break;
694 case '[':
3280af22 695 WITH_THR(sv_setiv(sv, (IV)PL_curcop->cop_arybase));
79072805
LW
696 break;
697 case '|':
3280af22 698 sv_setiv(sv, (IV)(IoFLAGS(GvIOp(PL_defoutgv)) & IOf_FLUSH) != 0 );
79072805
LW
699 break;
700 case ',':
3280af22 701 sv_setpvn(sv,PL_ofs,PL_ofslen);
79072805
LW
702 break;
703 case '\\':
3280af22 704 sv_setpvn(sv,PL_ors,PL_orslen);
79072805
LW
705 break;
706 case '#':
3280af22 707 sv_setpv(sv,PL_ofmt);
79072805
LW
708 break;
709 case '!':
a5f75d66 710#ifdef VMS
65202027 711 sv_setnv(sv, (NV)((errno == EVMSERR) ? vaxc$errno : errno));
88e89b8a 712 sv_setpv(sv, errno ? Strerror(errno) : "");
a5f75d66 713#else
88e89b8a
PP
714 {
715 int saveerrno = errno;
65202027 716 sv_setnv(sv, (NV)errno);
88e89b8a 717#ifdef OS2
ed344e4f
IZ
718 if (errno == errno_isOS2 || errno == errno_isOS2_set)
719 sv_setpv(sv, os2error(Perl_rc));
88e89b8a 720 else
a5f75d66 721#endif
2304df62 722 sv_setpv(sv, errno ? Strerror(errno) : "");
88e89b8a
PP
723 errno = saveerrno;
724 }
725#endif
946ec16e 726 SvNOK_on(sv); /* what a wonderful hack! */
79072805
LW
727 break;
728 case '<':
3280af22 729 sv_setiv(sv, (IV)PL_uid);
79072805
LW
730 break;
731 case '>':
3280af22 732 sv_setiv(sv, (IV)PL_euid);
79072805
LW
733 break;
734 case '(':
3280af22 735 sv_setiv(sv, (IV)PL_gid);
a52cb5f7 736#ifdef HAS_GETGROUPS
785fb66b 737 Perl_sv_setpvf(aTHX_ sv, "%"Gid_t_f, PL_gid);
a52cb5f7 738#endif
79072805
LW
739 goto add_groups;
740 case ')':
3280af22 741 sv_setiv(sv, (IV)PL_egid);
a52cb5f7 742#ifdef HAS_GETGROUPS
785fb66b 743 Perl_sv_setpvf(aTHX_ sv, "%"Gid_t_f, PL_egid);
a52cb5f7 744#endif
79072805 745 add_groups:
79072805 746#ifdef HAS_GETGROUPS
79072805 747 {
a0d0e21e 748 Groups_t gary[NGROUPS];
79072805 749 i = getgroups(NGROUPS,gary);
46fc3d4c 750 while (--i >= 0)
785fb66b 751 Perl_sv_catpvf(aTHX_ sv, " %"Gid_t_f, gary[i]);
79072805
LW
752 }
753#endif
155aba94 754 (void)SvIOK_on(sv); /* what a wonderful hack! */
79072805
LW
755 break;
756 case '*':
757 break;
cd39f2b6 758#ifndef MACOS_TRADITIONAL
79072805
LW
759 case '0':
760 break;
cd39f2b6 761#endif
a863c7d1
MB
762#ifdef USE_THREADS
763 case '@':
38a03e6e 764 sv_setsv(sv, thr->errsv);
a863c7d1
MB
765 break;
766#endif /* USE_THREADS */
79072805 767 }
a0d0e21e 768 return 0;
79072805
LW
769}
770
771int
864dbfa3 772Perl_magic_getuvar(pTHX_ SV *sv, MAGIC *mg)
79072805
LW
773{
774 struct ufuncs *uf = (struct ufuncs *)mg->mg_ptr;
775
776 if (uf && uf->uf_val)
777 (*uf->uf_val)(uf->uf_index, sv);
778 return 0;
779}
780
781int
864dbfa3 782Perl_magic_setenv(pTHX_ SV *sv, MAGIC *mg)
79072805
LW
783{
784 register char *s;
88e89b8a 785 char *ptr;
5aabfad6 786 STRLEN len, klen;
a0d0e21e 787 I32 i;
1e422769 788
a0d0e21e 789 s = SvPV(sv,len);
5aabfad6 790 ptr = MgPV(mg,klen);
88e89b8a 791 my_setenv(ptr, s);
1e422769 792
a0d0e21e
LW
793#ifdef DYNAMIC_ENV_FETCH
794 /* We just undefd an environment var. Is a replacement */
795 /* waiting in the wings? */
796 if (!len) {
5aabfad6 797 SV **valp;
6b88bc9c 798 if ((valp = hv_fetch(GvHVn(PL_envgv), ptr, klen, FALSE)))
5aabfad6 799 s = SvPV(*valp, len);
a0d0e21e
LW
800 }
801#endif
1e422769 802
39e571d4 803#if !defined(OS2) && !defined(AMIGAOS) && !defined(WIN32) && !defined(MSDOS)
79072805
LW
804 /* And you'll never guess what the dog had */
805 /* in its mouth... */
3280af22 806 if (PL_tainting) {
1e422769
PP
807 MgTAINTEDDIR_off(mg);
808#ifdef VMS
5aabfad6 809 if (s && klen == 8 && strEQ(ptr, "DCL$PATH")) {
1e422769
PP
810 char pathbuf[256], eltbuf[256], *cp, *elt = s;
811 struct stat sbuf;
812 int i = 0, j = 0;
813
814 do { /* DCL$PATH may be a search list */
815 while (1) { /* as may dev portion of any element */
816 if ( ((cp = strchr(elt,'[')) || (cp = strchr(elt,'<'))) ) {
817 if ( *(cp+1) == '.' || *(cp+1) == '-' ||
818 cando_by_name(S_IWUSR,0,elt) ) {
819 MgTAINTEDDIR_on(mg);
820 return 0;
821 }
822 }
823 if ((cp = strchr(elt, ':')) != Nullch)
824 *cp = '\0';
825 if (my_trnlnm(elt, eltbuf, j++))
826 elt = eltbuf;
827 else
828 break;
829 }
830 j = 0;
831 } while (my_trnlnm(s, pathbuf, i++) && (elt = pathbuf));
832 }
833#endif /* VMS */
5aabfad6 834 if (s && klen == 4 && strEQ(ptr,"PATH")) {
a0d0e21e 835 char *strend = s + len;
463ee0b2
LW
836
837 while (s < strend) {
96827780 838 char tmpbuf[256];
1e422769 839 struct stat st;
96827780 840 s = delimcpy(tmpbuf, tmpbuf + sizeof tmpbuf,
fc36a67e 841 s, strend, ':', &i);
463ee0b2 842 s++;
96827780
MB
843 if (i >= sizeof tmpbuf /* too long -- assume the worst */
844 || *tmpbuf != '/'
c6ed36e1 845 || (PerlLIO_stat(tmpbuf, &st) == 0 && (st.st_mode & 2)) ) {
8990e307 846 MgTAINTEDDIR_on(mg);
1e422769
PP
847 return 0;
848 }
463ee0b2 849 }
79072805
LW
850 }
851 }
39e571d4 852#endif /* neither OS2 nor AMIGAOS nor WIN32 nor MSDOS */
1e422769 853
79072805
LW
854 return 0;
855}
856
857int
864dbfa3 858Perl_magic_clearenv(pTHX_ SV *sv, MAGIC *mg)
85e6fe83 859{
2d8e6c8d
GS
860 STRLEN n_a;
861 my_setenv(MgPV(mg,n_a),Nullch);
85e6fe83
LW
862 return 0;
863}
864
88e89b8a 865int
864dbfa3 866Perl_magic_set_all_env(pTHX_ SV *sv, MAGIC *mg)
fb73857a
PP
867{
868#if defined(VMS)
cea2e8a9 869 Perl_die(aTHX_ "Can't make list assignment to %%ENV on this system");
fb73857a 870#else
d58bf5aa 871 dTHR;
3280af22 872 if (PL_localizing) {
fb73857a 873 HE* entry;
2d8e6c8d 874 STRLEN n_a;
fb73857a
PP
875 magic_clear_all_env(sv,mg);
876 hv_iterinit((HV*)sv);
155aba94 877 while ((entry = hv_iternext((HV*)sv))) {
fb73857a
PP
878 I32 keylen;
879 my_setenv(hv_iterkey(entry, &keylen),
2d8e6c8d 880 SvPV(hv_iterval((HV*)sv, entry), n_a));
fb73857a
PP
881 }
882 }
883#endif
884 return 0;
885}
886
887int
864dbfa3 888Perl_magic_clear_all_env(pTHX_ SV *sv, MAGIC *mg)
66b1d557 889{
3e3baf6d 890#if defined(VMS)
cea2e8a9 891 Perl_die(aTHX_ "Can't make list assignment to %%ENV on this system");
3e3baf6d 892#else
7766f137
GS
893# ifdef PERL_IMPLICIT_SYS
894 PerlEnv_clearenv();
895# else
896# ifdef WIN32
3e3baf6d
TB
897 char *envv = GetEnvironmentStrings();
898 char *cur = envv;
899 STRLEN len;
900 while (*cur) {
901 char *end = strchr(cur,'=');
902 if (end && end != cur) {
903 *end = '\0';
904 my_setenv(cur,Nullch);
905 *end = '=';
ac5c734f 906 cur = end + strlen(end+1)+2;
3e3baf6d
TB
907 }
908 else if ((len = strlen(cur)))
909 cur += len+1;
910 }
911 FreeEnvironmentStrings(envv);
7766f137 912# else
d308986b 913# ifdef __CYGWIN__
2c2d71f5
JH
914 I32 i;
915 for (i = 0; environ[i]; i++)
d702ae42 916 safesysfree(environ[i]);
7766f137
GS
917# else
918# ifndef PERL_USE_SAFE_PUTENV
66b1d557
HM
919 I32 i;
920
3280af22 921 if (environ == PL_origenviron)
f2517201 922 environ = (char**)safesysmalloc(sizeof(char*));
66b1d557
HM
923 else
924 for (i = 0; environ[i]; i++)
f2517201 925 safesysfree(environ[i]);
7766f137 926# endif /* PERL_USE_SAFE_PUTENV */
d308986b 927# endif /* __CYGWIN__ */
f2517201 928
66b1d557
HM
929 environ[0] = Nullch;
930
7766f137
GS
931# endif /* WIN32 */
932# endif /* PERL_IMPLICIT_SYS */
f2517201 933#endif /* VMS */
3e3baf6d 934 return 0;
66b1d557
HM
935}
936
937int
864dbfa3 938Perl_magic_getsig(pTHX_ SV *sv, MAGIC *mg)
88e89b8a
PP
939{
940 I32 i;
2d8e6c8d 941 STRLEN n_a;
88e89b8a 942 /* Are we fetching a signal entry? */
2d8e6c8d 943 i = whichsig(MgPV(mg,n_a));
88e89b8a 944 if (i) {
22c35a8c
GS
945 if(PL_psig_ptr[i])
946 sv_setsv(sv,PL_psig_ptr[i]);
88e89b8a 947 else {
ff68c719
PP
948 Sighandler_t sigstate = rsignal_state(i);
949
88e89b8a 950 /* cache state so we don't fetch it again */
ff68c719 951 if(sigstate == SIG_IGN)
88e89b8a
PP
952 sv_setpv(sv,"IGNORE");
953 else
3280af22 954 sv_setsv(sv,&PL_sv_undef);
22c35a8c 955 PL_psig_ptr[i] = SvREFCNT_inc(sv);
88e89b8a
PP
956 SvTEMP_off(sv);
957 }
958 }
959 return 0;
960}
961int
864dbfa3 962Perl_magic_clearsig(pTHX_ SV *sv, MAGIC *mg)
88e89b8a
PP
963{
964 I32 i;
2d8e6c8d 965 STRLEN n_a;
88e89b8a 966 /* Are we clearing a signal entry? */
2d8e6c8d 967 i = whichsig(MgPV(mg,n_a));
88e89b8a 968 if (i) {
22c35a8c
GS
969 if(PL_psig_ptr[i]) {
970 SvREFCNT_dec(PL_psig_ptr[i]);
971 PL_psig_ptr[i]=0;
88e89b8a 972 }
22c35a8c
GS
973 if(PL_psig_name[i]) {
974 SvREFCNT_dec(PL_psig_name[i]);
975 PL_psig_name[i]=0;
88e89b8a
PP
976 }
977 }
978 return 0;
979}
3d37d572 980
85e6fe83 981int
864dbfa3 982Perl_magic_setsig(pTHX_ SV *sv, MAGIC *mg)
79072805 983{
11343788 984 dTHR;
79072805
LW
985 register char *s;
986 I32 i;
748a9306 987 SV** svp;
e72dc28c 988 STRLEN len;
a0d0e21e 989
e72dc28c 990 s = MgPV(mg,len);
748a9306
LW
991 if (*s == '_') {
992 if (strEQ(s,"__DIE__"))
3280af22 993 svp = &PL_diehook;
748a9306 994 else if (strEQ(s,"__WARN__"))
3280af22 995 svp = &PL_warnhook;
748a9306 996 else
cea2e8a9 997 Perl_croak(aTHX_ "No such hook: %s", s);
748a9306 998 i = 0;
4633a7c4
LW
999 if (*svp) {
1000 SvREFCNT_dec(*svp);
1001 *svp = 0;
1002 }
748a9306
LW
1003 }
1004 else {
1005 i = whichsig(s); /* ...no, a brick */
1006 if (!i) {
e476b1b5 1007 if (ckWARN(WARN_SIGNAL))
cea2e8a9 1008 Perl_warner(aTHX_ WARN_SIGNAL, "No such signal: SIG%s", s);
748a9306
LW
1009 return 0;
1010 }
22c35a8c
GS
1011 SvREFCNT_dec(PL_psig_name[i]);
1012 SvREFCNT_dec(PL_psig_ptr[i]);
1013 PL_psig_ptr[i] = SvREFCNT_inc(sv);
88e89b8a 1014 SvTEMP_off(sv); /* Make sure it doesn't go away on us */
e72dc28c 1015 PL_psig_name[i] = newSVpvn(s, len);
22c35a8c 1016 SvREADONLY_on(PL_psig_name[i]);
748a9306 1017 }
a0d0e21e 1018 if (SvTYPE(sv) == SVt_PVGV || SvROK(sv)) {
748a9306 1019 if (i)
3280af22 1020 (void)rsignal(i, PL_sighandlerp);
748a9306
LW
1021 else
1022 *svp = SvREFCNT_inc(sv);
a0d0e21e
LW
1023 return 0;
1024 }
e72dc28c 1025 s = SvPV_force(sv,len);
748a9306
LW
1026 if (strEQ(s,"IGNORE")) {
1027 if (i)
ff68c719 1028 (void)rsignal(i, SIG_IGN);
748a9306
LW
1029 else
1030 *svp = 0;
1031 }
1032 else if (strEQ(s,"DEFAULT") || !*s) {
1033 if (i)
ff68c719 1034 (void)rsignal(i, SIG_DFL);
748a9306
LW
1035 else
1036 *svp = 0;
1037 }
79072805 1038 else {
5aabfad6
PP
1039 /*
1040 * We should warn if HINT_STRICT_REFS, but without
1041 * access to a known hint bit in a known OP, we can't
1042 * tell whether HINT_STRICT_REFS is in force or not.
1043 */
46fc3d4c 1044 if (!strchr(s,':') && !strchr(s,'\''))
e72dc28c 1045 sv_insert(sv, 0, 0, "main::", 6);
748a9306 1046 if (i)
3280af22 1047 (void)rsignal(i, PL_sighandlerp);
748a9306
LW
1048 else
1049 *svp = SvREFCNT_inc(sv);
79072805
LW
1050 }
1051 return 0;
1052}
1053
1054int
864dbfa3 1055Perl_magic_setisa(pTHX_ SV *sv, MAGIC *mg)
79072805 1056{
3280af22 1057 PL_sub_generation++;
463ee0b2
LW
1058 return 0;
1059}
1060
1061int
864dbfa3 1062Perl_magic_setamagic(pTHX_ SV *sv, MAGIC *mg)
463ee0b2 1063{
a0d0e21e 1064 /* HV_badAMAGIC_on(Sv_STASH(sv)); */
3280af22 1065 PL_amagic_generation++;
463ee0b2 1066
a0d0e21e
LW
1067 return 0;
1068}
463ee0b2 1069
946ec16e 1070int
864dbfa3 1071Perl_magic_getnkeys(pTHX_ SV *sv, MAGIC *mg)
6ff81951
GS
1072{
1073 HV *hv = (HV*)LvTARG(sv);
1074 HE *entry;
1075 I32 i = 0;
1076
1077 if (hv) {
1078 (void) hv_iterinit(hv);
33c27489 1079 if (! SvTIED_mg((SV*)hv, 'P'))
6ff81951
GS
1080 i = HvKEYS(hv);
1081 else {
1082 /*SUPPRESS 560*/
155aba94 1083 while ((entry = hv_iternext(hv))) {
6ff81951
GS
1084 i++;
1085 }
1086 }
1087 }
1088
1089 sv_setiv(sv, (IV)i);
1090 return 0;
1091}
1092
1093int
864dbfa3 1094Perl_magic_setnkeys(pTHX_ SV *sv, MAGIC *mg)
946ec16e
PP
1095{
1096 if (LvTARG(sv)) {
1097 hv_ksplit((HV*)LvTARG(sv), SvIV(sv));
946ec16e
PP
1098 }
1099 return 0;
93965878 1100}
946ec16e 1101
e336de0d 1102/* caller is responsible for stack switching/cleanup */
565764a8 1103STATIC int
cea2e8a9 1104S_magic_methcall(pTHX_ SV *sv, MAGIC *mg, char *meth, I32 flags, int n, SV *val)
a0d0e21e
LW
1105{
1106 dSP;
463ee0b2 1107
924508f0
GS
1108 PUSHMARK(SP);
1109 EXTEND(SP, n);
33c27489 1110 PUSHs(SvTIED_obj(sv, mg));
93965878
NIS
1111 if (n > 1) {
1112 if (mg->mg_ptr) {
565764a8 1113 if (mg->mg_len >= 0)
79cb57f6 1114 PUSHs(sv_2mortal(newSVpvn(mg->mg_ptr, mg->mg_len)));
565764a8 1115 else if (mg->mg_len == HEf_SVKEY)
93965878
NIS
1116 PUSHs((SV*)mg->mg_ptr);
1117 }
1118 else if (mg->mg_type == 'p') {
565764a8 1119 PUSHs(sv_2mortal(newSViv(mg->mg_len)));
93965878
NIS
1120 }
1121 }
1122 if (n > 2) {
1123 PUSHs(val);
88e89b8a 1124 }
463ee0b2
LW
1125 PUTBACK;
1126
864dbfa3 1127 return call_method(meth, flags);
946ec16e
PP
1128}
1129
76e3520e 1130STATIC int
cea2e8a9 1131S_magic_methpack(pTHX_ SV *sv, MAGIC *mg, char *meth)
a0d0e21e
LW
1132{
1133 dSP;
463ee0b2 1134
a0d0e21e
LW
1135 ENTER;
1136 SAVETMPS;
e788e7d3 1137 PUSHSTACKi(PERLSI_MAGIC);
463ee0b2 1138
33c27489 1139 if (magic_methcall(sv, mg, meth, G_SCALAR, 2, NULL)) {
3280af22 1140 sv_setsv(sv, *PL_stack_sp--);
93965878 1141 }
463ee0b2 1142
d3acc0f7 1143 POPSTACK;
a0d0e21e
LW
1144 FREETMPS;
1145 LEAVE;
1146 return 0;
1147}
463ee0b2 1148
a0d0e21e 1149int
864dbfa3 1150Perl_magic_getpack(pTHX_ SV *sv, MAGIC *mg)
a0d0e21e
LW
1151{
1152 magic_methpack(sv,mg,"FETCH");
1153 if (mg->mg_ptr)
1154 mg->mg_flags |= MGf_GSKIP;
463ee0b2
LW
1155 return 0;
1156}
1157
1158int
864dbfa3 1159Perl_magic_setpack(pTHX_ SV *sv, MAGIC *mg)
e336de0d
GS
1160{
1161 dSP;
a60c0954 1162 ENTER;
e788e7d3 1163 PUSHSTACKi(PERLSI_MAGIC);
33c27489 1164 magic_methcall(sv, mg, "STORE", G_SCALAR|G_DISCARD, 3, sv);
d3acc0f7 1165 POPSTACK;
a60c0954 1166 LEAVE;
463ee0b2
LW
1167 return 0;
1168}
1169
1170int
864dbfa3 1171Perl_magic_clearpack(pTHX_ SV *sv, MAGIC *mg)
463ee0b2 1172{
a0d0e21e
LW
1173 return magic_methpack(sv,mg,"DELETE");
1174}
463ee0b2 1175
93965878
NIS
1176
1177U32
864dbfa3 1178Perl_magic_sizepack(pTHX_ SV *sv, MAGIC *mg)
93965878 1179{
e336de0d 1180 dSP;
93965878
NIS
1181 U32 retval = 0;
1182
1183 ENTER;
1184 SAVETMPS;
e788e7d3 1185 PUSHSTACKi(PERLSI_MAGIC);
33c27489 1186 if (magic_methcall(sv, mg, "FETCHSIZE", G_SCALAR, 2, NULL)) {
3280af22 1187 sv = *PL_stack_sp--;
a60c0954 1188 retval = (U32) SvIV(sv)-1;
93965878 1189 }
d3acc0f7 1190 POPSTACK;
93965878
NIS
1191 FREETMPS;
1192 LEAVE;
1193 return retval;
1194}
1195
cea2e8a9
GS
1196int
1197Perl_magic_wipepack(pTHX_ SV *sv, MAGIC *mg)
a0d0e21e
LW
1198{
1199 dSP;
463ee0b2 1200
e336de0d 1201 ENTER;
e788e7d3 1202 PUSHSTACKi(PERLSI_MAGIC);
924508f0 1203 PUSHMARK(SP);
33c27489 1204 XPUSHs(SvTIED_obj(sv, mg));
463ee0b2 1205 PUTBACK;
864dbfa3 1206 call_method("CLEAR", G_SCALAR|G_DISCARD);
d3acc0f7 1207 POPSTACK;
a60c0954 1208 LEAVE;
463ee0b2
LW
1209 return 0;
1210}
1211
1212int
864dbfa3 1213Perl_magic_nextpack(pTHX_ SV *sv, MAGIC *mg, SV *key)
463ee0b2 1214{
463ee0b2 1215 dSP;
dff6d3cd 1216 const char *meth = SvOK(key) ? "NEXTKEY" : "FIRSTKEY";
463ee0b2
LW
1217
1218 ENTER;
a0d0e21e 1219 SAVETMPS;
e788e7d3 1220 PUSHSTACKi(PERLSI_MAGIC);
924508f0
GS
1221 PUSHMARK(SP);
1222 EXTEND(SP, 2);
33c27489 1223 PUSHs(SvTIED_obj(sv, mg));
463ee0b2
LW
1224 if (SvOK(key))
1225 PUSHs(key);
1226 PUTBACK;
1227
864dbfa3 1228 if (call_method(meth, G_SCALAR))
3280af22 1229 sv_setsv(key, *PL_stack_sp--);
463ee0b2 1230
d3acc0f7 1231 POPSTACK;
a0d0e21e
LW
1232 FREETMPS;
1233 LEAVE;
79072805
LW
1234 return 0;
1235}
1236
1237int
864dbfa3 1238Perl_magic_existspack(pTHX_ SV *sv, MAGIC *mg)
a0d0e21e
LW
1239{
1240 return magic_methpack(sv,mg,"EXISTS");
1241}
1242
1243int
864dbfa3 1244Perl_magic_setdbline(pTHX_ SV *sv, MAGIC *mg)
79072805 1245{
11343788 1246 dTHR;
79072805
LW
1247 OP *o;
1248 I32 i;
1249 GV* gv;
1250 SV** svp;
2d8e6c8d 1251 STRLEN n_a;
79072805 1252
3280af22 1253 gv = PL_DBline;
79072805 1254 i = SvTRUE(sv);
188ea221 1255 svp = av_fetch(GvAV(gv),
2d8e6c8d 1256 atoi(MgPV(mg,n_a)), FALSE);
57b2e452 1257 if (svp && SvIOKp(*svp) && (o = INT2PTR(OP*,SvIVX(*svp))))
93a17b20 1258 o->op_private = i;
0453d815
PM
1259 else if (ckWARN_d(WARN_INTERNAL))
1260 Perl_warner(aTHX_ WARN_INTERNAL, "Can't break at that line\n");
79072805
LW
1261 return 0;
1262}
1263
1264int
864dbfa3 1265Perl_magic_getarylen(pTHX_ SV *sv, MAGIC *mg)
79072805 1266{
0f15f207 1267 dTHR;
3280af22 1268 sv_setiv(sv, AvFILL((AV*)mg->mg_obj) + PL_curcop->cop_arybase);
79072805
LW
1269 return 0;
1270}
1271
1272int
864dbfa3 1273Perl_magic_setarylen(pTHX_ SV *sv, MAGIC *mg)
79072805 1274{
0f15f207 1275 dTHR;
3280af22 1276 av_fill((AV*)mg->mg_obj, SvIV(sv) - PL_curcop->cop_arybase);
a0d0e21e
LW
1277 return 0;
1278}
1279
1280int
864dbfa3 1281Perl_magic_getpos(pTHX_ SV *sv, MAGIC *mg)
a0d0e21e
LW
1282{
1283 SV* lsv = LvTARG(sv);
1284
1285 if (SvTYPE(lsv) >= SVt_PVMG && SvMAGIC(lsv)) {
1286 mg = mg_find(lsv, 'g');
565764a8 1287 if (mg && mg->mg_len >= 0) {
0f15f207 1288 dTHR;
a0ed51b3 1289 I32 i = mg->mg_len;
7e2040f0 1290 if (DO_UTF8(lsv))
a0ed51b3
LW
1291 sv_pos_b2u(lsv, &i);
1292 sv_setiv(sv, i + PL_curcop->cop_arybase);
a0d0e21e
LW
1293 return 0;
1294 }
1295 }
1296 (void)SvOK_off(sv);
1297 return 0;
1298}
1299
1300int
864dbfa3 1301Perl_magic_setpos(pTHX_ SV *sv, MAGIC *mg)
a0d0e21e
LW
1302{
1303 SV* lsv = LvTARG(sv);
1304 SSize_t pos;
1305 STRLEN len;
c00206c8 1306 STRLEN ulen = 0;
c485e607 1307 dTHR;
a0d0e21e
LW
1308
1309 mg = 0;
1310
1311 if (SvTYPE(lsv) >= SVt_PVMG && SvMAGIC(lsv))
1312 mg = mg_find(lsv, 'g');
1313 if (!mg) {
1314 if (!SvOK(sv))
1315 return 0;
1316 sv_magic(lsv, (SV*)0, 'g', Nullch, 0);
1317 mg = mg_find(lsv, 'g');
1318 }
1319 else if (!SvOK(sv)) {
565764a8 1320 mg->mg_len = -1;
a0d0e21e
LW
1321 return 0;
1322 }
1323 len = SvPOK(lsv) ? SvCUR(lsv) : sv_len(lsv);
1324
c485e607 1325 pos = SvIV(sv) - PL_curcop->cop_arybase;
a0ed51b3 1326
7e2040f0 1327 if (DO_UTF8(lsv)) {
a0ed51b3
LW
1328 ulen = sv_len_utf8(lsv);
1329 if (ulen)
1330 len = ulen;
a0ed51b3
LW
1331 }
1332
a0d0e21e
LW
1333 if (pos < 0) {
1334 pos += len;
1335 if (pos < 0)
1336 pos = 0;
1337 }
1338 else if (pos > len)
1339 pos = len;
a0ed51b3
LW
1340
1341 if (ulen) {
1342 I32 p = pos;
1343 sv_pos_u2b(lsv, &p, 0);
1344 pos = p;
1345 }
1346
565764a8 1347 mg->mg_len = pos;
71be2cbc 1348 mg->mg_flags &= ~MGf_MINMATCH;
a0d0e21e 1349
79072805
LW
1350 return 0;
1351}
1352
1353int
864dbfa3 1354Perl_magic_getglob(pTHX_ SV *sv, MAGIC *mg)
79072805 1355{
8646b087
PP
1356 if (SvFAKE(sv)) { /* FAKE globs can get coerced */
1357 SvFAKE_off(sv);
946ec16e 1358 gv_efullname3(sv,((GV*)sv), "*");
8646b087
PP
1359 SvFAKE_on(sv);
1360 }
1361 else
946ec16e 1362 gv_efullname3(sv,((GV*)sv), "*"); /* a gv value, be nice */
79072805
LW
1363 return 0;
1364}
1365
1366int
864dbfa3 1367Perl_magic_setglob(pTHX_ SV *sv, MAGIC *mg)
79072805
LW
1368{
1369 register char *s;
1370 GV* gv;
2d8e6c8d 1371 STRLEN n_a;
79072805
LW
1372
1373 if (!SvOK(sv))
1374 return 0;
2d8e6c8d 1375 s = SvPV(sv, n_a);
79072805
LW
1376 if (*s == '*' && s[1])
1377 s++;
85e6fe83 1378 gv = gv_fetchpv(s,TRUE, SVt_PVGV);
79072805
LW
1379 if (sv == (SV*)gv)
1380 return 0;
1381 if (GvGP(sv))
88e89b8a 1382 gp_free((GV*)sv);
79072805 1383 GvGP(sv) = gp_ref(GvGP(gv));
79072805
LW
1384 return 0;
1385}
1386
1387int
864dbfa3 1388Perl_magic_getsubstr(pTHX_ SV *sv, MAGIC *mg)
6ff81951
GS
1389{
1390 STRLEN len;
1391 SV *lsv = LvTARG(sv);
1392 char *tmps = SvPV(lsv,len);
1393 I32 offs = LvTARGOFF(sv);
1394 I32 rem = LvTARGLEN(sv);
1395
1396 if (offs > len)
1397 offs = len;
1398 if (rem + offs > len)
1399 rem = len - offs;
1400 sv_setpvn(sv, tmps + offs, (STRLEN)rem);
1401 return 0;
1402}
1403
1404int
864dbfa3 1405Perl_magic_setsubstr(pTHX_ SV *sv, MAGIC *mg)
79072805 1406{
8990e307
LW
1407 STRLEN len;
1408 char *tmps = SvPV(sv,len);
1409 sv_insert(LvTARG(sv),LvTARGOFF(sv),LvTARGLEN(sv), tmps, len);
79072805
LW
1410 return 0;
1411}
1412
1413int
864dbfa3 1414Perl_magic_gettaint(pTHX_ SV *sv, MAGIC *mg)
463ee0b2 1415{
a863c7d1 1416 dTHR;
565764a8 1417 TAINT_IF((mg->mg_len & 1) ||
155aba94 1418 ((mg->mg_len & 2) && mg->mg_obj == sv)); /* kludge */
463ee0b2
LW
1419 return 0;
1420}
1421
1422int
864dbfa3 1423Perl_magic_settaint(pTHX_ SV *sv, MAGIC *mg)
463ee0b2 1424{
11343788 1425 dTHR;
3280af22
NIS
1426 if (PL_localizing) {
1427 if (PL_localizing == 1)
565764a8 1428 mg->mg_len <<= 1;
748a9306 1429 else
565764a8 1430 mg->mg_len >>= 1;
a0d0e21e 1431 }
3280af22 1432 else if (PL_tainted)
565764a8 1433 mg->mg_len |= 1;
748a9306 1434 else
565764a8 1435 mg->mg_len &= ~1;
463ee0b2
LW
1436 return 0;
1437}
1438
1439int
864dbfa3 1440Perl_magic_getvec(pTHX_ SV *sv, MAGIC *mg)
6ff81951
GS
1441{
1442 SV *lsv = LvTARG(sv);
6ff81951
GS
1443
1444 if (!lsv) {
155aba94 1445 (void)SvOK_off(sv);
6ff81951
GS
1446 return 0;
1447 }
6ff81951 1448
81e118e0 1449 sv_setuv(sv, do_vecget(lsv, LvTARGOFF(sv), LvTARGLEN(sv)));
6ff81951
GS
1450 return 0;
1451}
1452
1453int
864dbfa3 1454Perl_magic_setvec(pTHX_ SV *sv, MAGIC *mg)
79072805
LW
1455{
1456 do_vecset(sv); /* XXX slurp this routine */
1457 return 0;
1458}
1459
1460int
864dbfa3 1461Perl_magic_getdefelem(pTHX_ SV *sv, MAGIC *mg)
5f05dabc 1462{
71be2cbc 1463 SV *targ = Nullsv;
5f05dabc 1464 if (LvTARGLEN(sv)) {
68dc0745 1465 if (mg->mg_obj) {
74e13ce4
GS
1466 SV *ahv = LvTARG(sv);
1467 if (SvTYPE(ahv) == SVt_PVHV) {
1468 HE *he = hv_fetch_ent((HV*)ahv, mg->mg_obj, FALSE, 0);
1469 if (he)
1470 targ = HeVAL(he);
1471 }
1472 else {
1473 SV **svp = avhv_fetch_ent((AV*)ahv, mg->mg_obj, FALSE, 0);
1474 if (svp)
1475 targ = *svp;
1476 }
68dc0745
PP
1477 }
1478 else {
3c78fafa 1479 AV* av = (AV*)LvTARG(sv);
68dc0745
PP
1480 if ((I32)LvTARGOFF(sv) <= AvFILL(av))
1481 targ = AvARRAY(av)[LvTARGOFF(sv)];
1482 }
3280af22 1483 if (targ && targ != &PL_sv_undef) {
e858de61 1484 dTHR; /* just for SvREFCNT_dec */
68dc0745
PP
1485 /* somebody else defined it for us */
1486 SvREFCNT_dec(LvTARG(sv));
1487 LvTARG(sv) = SvREFCNT_inc(targ);
1488 LvTARGLEN(sv) = 0;
1489 SvREFCNT_dec(mg->mg_obj);
1490 mg->mg_obj = Nullsv;
1491 mg->mg_flags &= ~MGf_REFCOUNTED;
1492 }
5f05dabc 1493 }
71be2cbc
PP
1494 else
1495 targ = LvTARG(sv);
3280af22 1496 sv_setsv(sv, targ ? targ : &PL_sv_undef);
71be2cbc
PP
1497 return 0;
1498}
1499
1500int
864dbfa3 1501Perl_magic_setdefelem(pTHX_ SV *sv, MAGIC *mg)
71be2cbc
PP
1502{
1503 if (LvTARGLEN(sv))
68dc0745
PP
1504 vivify_defelem(sv);
1505 if (LvTARG(sv)) {
5f05dabc 1506 sv_setsv(LvTARG(sv), sv);
68dc0745
PP
1507 SvSETMAGIC(LvTARG(sv));
1508 }
5f05dabc
PP
1509 return 0;
1510}
1511
71be2cbc 1512void
864dbfa3 1513Perl_vivify_defelem(pTHX_ SV *sv)
71be2cbc 1514{
e858de61 1515 dTHR; /* just for SvREFCNT_inc and SvREFCNT_dec*/
74e13ce4
GS
1516 MAGIC *mg;
1517 SV *value = Nullsv;
71be2cbc 1518
68dc0745 1519 if (!LvTARGLEN(sv) || !(mg = mg_find(sv, 'y')))
71be2cbc 1520 return;
68dc0745 1521 if (mg->mg_obj) {
74e13ce4 1522 SV *ahv = LvTARG(sv);
2d8e6c8d 1523 STRLEN n_a;
74e13ce4 1524 if (SvTYPE(ahv) == SVt_PVHV) {
af7f9c15 1525 HE *he = hv_fetch_ent((HV*)ahv, mg->mg_obj, TRUE, 0);
74e13ce4
GS
1526 if (he)
1527 value = HeVAL(he);
1528 }
1529 else {
af7f9c15 1530 SV **svp = avhv_fetch_ent((AV*)ahv, mg->mg_obj, TRUE, 0);
74e13ce4
GS
1531 if (svp)
1532 value = *svp;
1533 }
3280af22 1534 if (!value || value == &PL_sv_undef)
cea2e8a9 1535 Perl_croak(aTHX_ PL_no_helem, SvPV(mg->mg_obj, n_a));
71be2cbc 1536 }
68dc0745
PP
1537 else {
1538 AV* av = (AV*)LvTARG(sv);
5aabfad6 1539 if ((I32)LvTARGLEN(sv) < 0 && (I32)LvTARGOFF(sv) > AvFILL(av))
68dc0745
PP
1540 LvTARG(sv) = Nullsv; /* array can't be extended */
1541 else {
1542 SV** svp = av_fetch(av, LvTARGOFF(sv), TRUE);
3280af22 1543 if (!svp || (value = *svp) == &PL_sv_undef)
cea2e8a9 1544 Perl_croak(aTHX_ PL_no_aelem, (I32)LvTARGOFF(sv));
68dc0745
PP
1545 }
1546 }
3e3baf6d 1547 (void)SvREFCNT_inc(value);
68dc0745
PP
1548 SvREFCNT_dec(LvTARG(sv));
1549 LvTARG(sv) = value;
71be2cbc 1550 LvTARGLEN(sv) = 0;
68dc0745
PP
1551 SvREFCNT_dec(mg->mg_obj);
1552 mg->mg_obj = Nullsv;
1553 mg->mg_flags &= ~MGf_REFCOUNTED;
5f05dabc
PP
1554}
1555
1556int
864dbfa3 1557Perl_magic_killbackrefs(pTHX_ SV *sv, MAGIC *mg)
810b8aa5
GS
1558{
1559 AV *av = (AV*)mg->mg_obj;
1560 SV **svp = AvARRAY(av);
1561 I32 i = AvFILLp(av);
1562 while (i >= 0) {
1563 if (svp[i] && svp[i] != &PL_sv_undef) {
1564 if (!SvWEAKREF(svp[i]))
cea2e8a9 1565 Perl_croak(aTHX_ "panic: magic_killbackrefs");
810b8aa5
GS
1566 /* XXX Should we check that it hasn't changed? */
1567 SvRV(svp[i]) = 0;
155aba94 1568 (void)SvOK_off(svp[i]);
810b8aa5
GS
1569 SvWEAKREF_off(svp[i]);
1570 svp[i] = &PL_sv_undef;
1571 }
1572 i--;
1573 }
1574 return 0;
1575}
1576
1577int
864dbfa3 1578Perl_magic_setmglob(pTHX_ SV *sv, MAGIC *mg)
93a17b20 1579{
565764a8 1580 mg->mg_len = -1;
c6496cc7 1581 SvSCREAM_off(sv);
93a17b20
LW
1582 return 0;
1583}
1584
1585int
864dbfa3 1586Perl_magic_setbm(pTHX_ SV *sv, MAGIC *mg)
79072805 1587{
463ee0b2 1588 sv_unmagic(sv, 'B');
79072805
LW
1589 SvVALID_off(sv);
1590 return 0;
1591}
1592
1593int
864dbfa3 1594Perl_magic_setfm(pTHX_ SV *sv, MAGIC *mg)
55497cff
PP
1595{
1596 sv_unmagic(sv, 'f');
1597 SvCOMPILED_off(sv);
1598 return 0;
1599}
1600
1601int
864dbfa3 1602Perl_magic_setuvar(pTHX_ SV *sv, MAGIC *mg)
79072805
LW
1603{
1604 struct ufuncs *uf = (struct ufuncs *)mg->mg_ptr;
1605
1606 if (uf && uf->uf_set)
1607 (*uf->uf_set)(uf->uf_index, sv);
1608 return 0;
1609}
1610
c277df42 1611int
864dbfa3 1612Perl_magic_freeregexp(pTHX_ SV *sv, MAGIC *mg)
c277df42
IZ
1613{
1614 regexp *re = (regexp *)mg->mg_obj;
1615 ReREFCNT_dec(re);
1616 return 0;
1617}
1618
7a4c00b4 1619#ifdef USE_LOCALE_COLLATE
79072805 1620int
864dbfa3 1621Perl_magic_setcollxfrm(pTHX_ SV *sv, MAGIC *mg)
bbce6d69
PP
1622{
1623 /*
838b5b74 1624 * RenE<eacute> Descartes said "I think not."
bbce6d69
PP
1625 * and vanished with a faint plop.
1626 */
7a4c00b4
PP
1627 if (mg->mg_ptr) {
1628 Safefree(mg->mg_ptr);
1629 mg->mg_ptr = NULL;
565764a8 1630 mg->mg_len = -1;
7a4c00b4 1631 }
bbce6d69
PP
1632 return 0;
1633}
7a4c00b4 1634#endif /* USE_LOCALE_COLLATE */
bbce6d69
PP
1635
1636int
864dbfa3 1637Perl_magic_set(pTHX_ SV *sv, MAGIC *mg)
79072805 1638{
11343788 1639 dTHR;
79072805
LW
1640 register char *s;
1641 I32 i;
8990e307 1642 STRLEN len;
79072805 1643 switch (*mg->mg_ptr) {
748a9306 1644 case '\001': /* ^A */
3280af22 1645 sv_setsv(PL_bodytarget, sv);
748a9306 1646 break;
49460fe6
NIS
1647 case '\003': /* ^C */
1648 PL_minus_c = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
1649 break;
1650
79072805 1651 case '\004': /* ^D */
3280af22 1652 PL_debug = (SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv)) | 0x80000000;
79072805
LW
1653 DEBUG_x(dump_all());
1654 break;
28f23441 1655 case '\005': /* ^E */
cd39f2b6
JH
1656#ifdef MACOS_TRADITIONAL
1657 gLastMacOSErr = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
28f23441 1658#else
cd39f2b6
JH
1659# ifdef VMS
1660 set_vaxc_errno(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv));
048c1ddf 1661# else
cd39f2b6
JH
1662# ifdef WIN32
1663 SetLastError( SvIV(sv) );
1664# else
1665# ifndef OS2
f86702cc
PP
1666 /* will anyone ever use this? */
1667 SETERRNO(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv), 4);
cd39f2b6 1668# endif
048c1ddf
IZ
1669# endif
1670# endif
22fae026 1671#endif
28f23441 1672 break;
79072805 1673 case '\006': /* ^F */
3280af22 1674 PL_maxsysfd = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
79072805 1675 break;
a0d0e21e 1676 case '\010': /* ^H */
3280af22 1677 PL_hints = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
a0d0e21e 1678 break;
9d116dd7 1679 case '\011': /* ^I */ /* NOT \t in EBCDIC */
3280af22
NIS
1680 if (PL_inplace)
1681 Safefree(PL_inplace);
79072805 1682 if (SvOK(sv))
2d8e6c8d 1683 PL_inplace = savepv(SvPV(sv,len));
79072805 1684 else
3280af22 1685 PL_inplace = Nullch;
79072805 1686 break;
28f23441 1687 case '\017': /* ^O */
3280af22
NIS
1688 if (PL_osname)
1689 Safefree(PL_osname);
28f23441 1690 if (SvOK(sv))
2d8e6c8d 1691 PL_osname = savepv(SvPV(sv,len));
28f23441 1692 else
3280af22 1693 PL_osname = Nullch;
28f23441 1694 break;
79072805 1695 case '\020': /* ^P */
3280af22 1696 PL_perldb = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
1ee4443e
IZ
1697 if (PL_perldb && !PL_DBsingle)
1698 init_debugger();
79072805
LW
1699 break;
1700 case '\024': /* ^T */
88e89b8a 1701#ifdef BIG_TIME
6b88bc9c 1702 PL_basetime = (Time_t)(SvNOK(sv) ? SvNVX(sv) : sv_2nv(sv));
88e89b8a 1703#else
3280af22 1704 PL_basetime = (Time_t)(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv));
88e89b8a 1705#endif
79072805 1706 break;
46487f74 1707 case '\027': /* ^W & $^WARNING_BITS & ^WIDE_SYSTEM_CALLS */
4438c4b7
JH
1708 if (*(mg->mg_ptr+1) == '\0') {
1709 if ( ! (PL_dowarn & G_WARN_ALL_MASK)) {
1710 i = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
1711 PL_dowarn = (PL_dowarn & ~G_WARN_ON)
0453d815 1712 | (i ? G_WARN_ON : G_WARN_OFF) ;
4438c4b7 1713 }
599cee73 1714 }
6a818117 1715 else if (strEQ(mg->mg_ptr, "\027ARNING_BITS")) {
4438c4b7 1716 if ( ! (PL_dowarn & G_WARN_ALL_MASK)) {
d775746e
GS
1717 if (!SvPOK(sv) && PL_localizing) {
1718 sv_setpvn(sv, WARN_NONEstring, WARNsize);
d3a7d8c7 1719 PL_compiling.cop_warnings = pWARN_NONE;
d775746e
GS
1720 break;
1721 }
d3a7d8c7
GS
1722 if (isWARN_on(sv, WARN_ALL)) {
1723 PL_compiling.cop_warnings = pWARN_ALL;
4438c4b7
JH
1724 PL_dowarn |= G_WARN_ONCE ;
1725 }
d3a7d8c7 1726 else {
b5477537 1727 STRLEN len, i;
d3a7d8c7 1728 int accumulate = 0 ;
d3a7d8c7
GS
1729 char * ptr = (char*)SvPV(sv, len) ;
1730 for (i = 0 ; i < len ; ++i)
1731 accumulate += ptr[i] ;
1732 if (!accumulate)
1733 PL_compiling.cop_warnings = pWARN_NONE;
1734 else {
1735 if (specialWARN(PL_compiling.cop_warnings))
1736 PL_compiling.cop_warnings = newSVsv(sv) ;
1737 else
1738 sv_setsv(PL_compiling.cop_warnings, sv);
1739 if (isWARN_on(PL_compiling.cop_warnings, WARN_ONCE))
1740 PL_dowarn |= G_WARN_ONCE ;
1741 }
1742 }
4438c4b7 1743 }
971a9dd3 1744 }
46487f74
GS
1745 else if (strEQ(mg->mg_ptr, "\027IDE_SYSTEM_CALLS"))
1746 PL_widesyscalls = SvTRUE(sv);
79072805
LW
1747 break;
1748 case '.':
3280af22
NIS
1749 if (PL_localizing) {
1750 if (PL_localizing == 1)
7766f137 1751 SAVESPTR(PL_last_in_gv);
748a9306 1752 }
3280af22
NIS
1753 else if (SvOK(sv) && GvIO(PL_last_in_gv))
1754 IoLINES(GvIOp(PL_last_in_gv)) = (long)SvIV(sv);
79072805
LW
1755 break;
1756 case '^':
3280af22 1757 Safefree(IoTOP_NAME(GvIOp(PL_defoutgv)));
2d8e6c8d 1758 IoTOP_NAME(GvIOp(PL_defoutgv)) = s = savepv(SvPV(sv,len));
3280af22 1759 IoTOP_GV(GvIOp(PL_defoutgv)) = gv_fetchpv(s,TRUE, SVt_PVIO);
79072805
LW
1760 break;
1761 case '~':
3280af22 1762 Safefree(IoFMT_NAME(GvIOp(PL_defoutgv)));
2d8e6c8d 1763 IoFMT_NAME(GvIOp(PL_defoutgv)) = s = savepv(SvPV(sv,len));
3280af22 1764 IoFMT_GV(GvIOp(PL_defoutgv)) = gv_fetchpv(s,TRUE, SVt_PVIO);
79072805
LW
1765 break;
1766 case '=':
3280af22 1767 IoPAGE_LEN(GvIOp(PL_defoutgv)) = (long)(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv));
79072805
LW
1768 break;
1769 case '-':
3280af22
NIS
1770 IoLINES_LEFT(GvIOp(PL_defoutgv)) = (long)(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv));
1771 if (IoLINES_LEFT(GvIOp(PL_defoutgv)) < 0L)
1772 IoLINES_LEFT(GvIOp(PL_defoutgv)) = 0L;
79072805
LW
1773 break;
1774 case '%':
3280af22 1775 IoPAGE(GvIOp(PL_defoutgv)) = (long)(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv));
79072805
LW
1776 break;
1777 case '|':
4b65379b 1778 {
3280af22 1779 IO *io = GvIOp(PL_defoutgv);
4b65379b
CS
1780 if ((SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv)) == 0)
1781 IoFLAGS(io) &= ~IOf_FLUSH;
1782 else {
1783 if (!(IoFLAGS(io) & IOf_FLUSH)) {
1784 PerlIO *ofp = IoOFP(io);
1785 if (ofp)
1786 (void)PerlIO_flush(ofp);
1787 IoFLAGS(io) |= IOf_FLUSH;
1788 }
1789 }
79072805
LW
1790 }
1791 break;
1792 case '*':
463ee0b2 1793 i = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
3280af22 1794 PL_multiline = (i != 0);
79072805
LW
1795 break;
1796 case '/':
3280af22
NIS
1797 SvREFCNT_dec(PL_nrs);
1798 PL_nrs = newSVsv(sv);
1799 SvREFCNT_dec(PL_rs);
1800 PL_rs = SvREFCNT_inc(PL_nrs);
79072805
LW
1801 break;
1802 case '\\':
3280af22
NIS
1803 if (PL_ors)
1804 Safefree(PL_ors);
009c130f
GS
1805 if (SvOK(sv) || SvGMAGICAL(sv)) {
1806 s = SvPV(sv,PL_orslen);
1807 PL_ors = savepvn(s,PL_orslen);
1808 }
e3c19b7b 1809 else {
3280af22
NIS
1810 PL_ors = Nullch;
1811 PL_orslen = 0;
e3c19b7b 1812 }
79072805
LW
1813 break;
1814 case ',':
3280af22
NIS
1815 if (PL_ofs)
1816 Safefree(PL_ofs);
1817 PL_ofs = savepv(SvPV(sv, PL_ofslen));
79072805
LW
1818 break;
1819 case '#':
3280af22
NIS
1820 if (PL_ofmt)
1821 Safefree(PL_ofmt);
2d8e6c8d 1822 PL_ofmt = savepv(SvPV(sv,len));
79072805
LW
1823 break;
1824 case '[':
3280af22 1825 PL_compiling.cop_arybase = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
79072805
LW
1826 break;
1827 case '?':
ff0cee69 1828#ifdef COMPLEX_STATUS
6b88bc9c
GS
1829 if (PL_localizing == 2) {
1830 PL_statusvalue = LvTARGOFF(sv);
1831 PL_statusvalue_vms = LvTARGLEN(sv);
ff0cee69
PP
1832 }
1833 else
1834#endif
1835#ifdef VMSISH_STATUS
1836 if (VMSISH_STATUS)
1837 STATUS_NATIVE_SET((U32)(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv)));
1838 else
1839#endif
1840 STATUS_POSIX_SET(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv));
79072805
LW
1841 break;
1842 case '!':
78987ded 1843 SETERRNO(SvIOK(sv) ? SvIVX(sv) : SvOK(sv) ? sv_2iv(sv) : 0,
f86702cc 1844 (SvIV(sv) == EVMSERR) ? 4 : vaxc$errno);
79072805
LW
1845 break;
1846 case '<':
3280af22
NIS
1847 PL_uid = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
1848 if (PL_delaymagic) {
1849 PL_delaymagic |= DM_RUID;
79072805
LW
1850 break; /* don't do magic till later */
1851 }
1852#ifdef HAS_SETRUID
b28d0864 1853 (void)setruid((Uid_t)PL_uid);
79072805
LW
1854#else
1855#ifdef HAS_SETREUID
3280af22 1856 (void)setreuid((Uid_t)PL_uid, (Uid_t)-1);
748a9306 1857#else
85e6fe83 1858#ifdef HAS_SETRESUID
b28d0864 1859 (void)setresuid((Uid_t)PL_uid, (Uid_t)-1, (Uid_t)-1);
79072805 1860#else
b28d0864
NIS
1861 if (PL_uid == PL_euid) /* special case $< = $> */
1862 (void)PerlProc_setuid(PL_uid);
a0d0e21e 1863 else {
d8eceb89 1864 PL_uid = PerlProc_getuid();
cea2e8a9 1865 Perl_croak(aTHX_ "setruid() not implemented");
a0d0e21e 1866 }
79072805
LW
1867#endif
1868#endif
85e6fe83 1869#endif
d8eceb89 1870 PL_uid = PerlProc_getuid();
3280af22 1871 PL_tainting |= (PL_uid && (PL_euid != PL_uid || PL_egid != PL_gid));
79072805
LW
1872 break;
1873 case '>':
3280af22
NIS
1874 PL_euid = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
1875 if (PL_delaymagic) {
1876 PL_delaymagic |= DM_EUID;
79072805
LW
1877 break; /* don't do magic till later */
1878 }
1879#ifdef HAS_SETEUID
3280af22 1880 (void)seteuid((Uid_t)PL_euid);
79072805
LW
1881#else
1882#ifdef HAS_SETREUID
b28d0864 1883 (void)setreuid((Uid_t)-1, (Uid_t)PL_euid);
85e6fe83
LW
1884#else
1885#ifdef HAS_SETRESUID
6b88bc9c 1886 (void)setresuid((Uid_t)-1, (Uid_t)PL_euid, (Uid_t)-1);
79072805 1887#else
b28d0864
NIS
1888 if (PL_euid == PL_uid) /* special case $> = $< */
1889 PerlProc_setuid(PL_euid);
a0d0e21e 1890 else {
e8ee3774 1891 PL_euid = PerlProc_geteuid();
cea2e8a9 1892 Perl_croak(aTHX_ "seteuid() not implemented");
a0d0e21e 1893 }
79072805
LW
1894#endif
1895#endif
85e6fe83 1896#endif
d8eceb89 1897 PL_euid = PerlProc_geteuid();
3280af22 1898 PL_tainting |= (PL_uid && (PL_euid != PL_uid || PL_egid != PL_gid));
79072805
LW
1899 break;
1900 case '(':
3280af22
NIS
1901 PL_gid = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
1902 if (PL_delaymagic) {
1903 PL_delaymagic |= DM_RGID;
79072805
LW
1904 break; /* don't do magic till later */
1905 }
1906#ifdef HAS_SETRGID
b28d0864 1907 (void)setrgid((Gid_t)PL_gid);
79072805
LW
1908#else
1909#ifdef HAS_SETREGID
3280af22 1910 (void)setregid((Gid_t)PL_gid, (Gid_t)-1);
85e6fe83
LW
1911#else
1912#ifdef HAS_SETRESGID
b28d0864 1913 (void)setresgid((Gid_t)PL_gid, (Gid_t)-1, (Gid_t) 1);
79072805 1914#else
b28d0864
NIS
1915 if (PL_gid == PL_egid) /* special case $( = $) */
1916 (void)PerlProc_setgid(PL_gid);
748a9306 1917 else {
d8eceb89 1918 PL_gid = PerlProc_getgid();
cea2e8a9 1919 Perl_croak(aTHX_ "setrgid() not implemented");
748a9306 1920 }
79072805
LW
1921#endif
1922#endif
85e6fe83 1923#endif
d8eceb89 1924 PL_gid = PerlProc_getgid();
3280af22 1925 PL_tainting |= (PL_uid && (PL_euid != PL_uid || PL_egid != PL_gid));
79072805
LW
1926 break;
1927 case ')':
5cd24f17
PP
1928#ifdef HAS_SETGROUPS
1929 {
2d8e6c8d 1930 char *p = SvPV(sv, len);
5cd24f17
PP
1931 Groups_t gary[NGROUPS];
1932
5cd24f17
PP
1933 while (isSPACE(*p))
1934 ++p;
2d4389e4 1935 PL_egid = Atol(p);
5cd24f17
PP
1936 for (i = 0; i < NGROUPS; ++i) {
1937 while (*p && !isSPACE(*p))
1938 ++p;
1939 while (isSPACE(*p))
1940 ++p;
1941 if (!*p)
1942 break;
2d4389e4 1943 gary[i] = Atol(p);
5cd24f17 1944 }
8cc95fdb
PP
1945 if (i)
1946 (void)setgroups(i, gary);
5cd24f17
PP
1947 }
1948#else /* HAS_SETGROUPS */
b28d0864 1949 PL_egid = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
5cd24f17 1950#endif /* HAS_SETGROUPS */
3280af22
NIS
1951 if (PL_delaymagic) {
1952 PL_delaymagic |= DM_EGID;
79072805
LW
1953 break; /* don't do magic till later */
1954 }
1955#ifdef HAS_SETEGID
3280af22 1956 (void)setegid((Gid_t)PL_egid);
79072805
LW
1957#else
1958#ifdef HAS_SETREGID
b28d0864 1959 (void)setregid((Gid_t)-1, (Gid_t)PL_egid);
85e6fe83
LW
1960#else
1961#ifdef HAS_SETRESGID
b28d0864 1962 (void)setresgid((Gid_t)-1, (Gid_t)PL_egid, (Gid_t)-1);
79072805 1963#else
b28d0864
NIS
1964 if (PL_egid == PL_gid) /* special case $) = $( */
1965 (void)PerlProc_setgid(PL_egid);
748a9306 1966 else {
d8eceb89 1967 PL_egid = PerlProc_getegid();
cea2e8a9 1968 Perl_croak(aTHX_ "setegid() not implemented");
748a9306 1969 }
79072805
LW
1970#endif
1971#endif
85e6fe83 1972#endif
d8eceb89 1973 PL_egid = PerlProc_getegid();
3280af22 1974 PL_tainting |= (PL_uid && (PL_euid != PL_uid || PL_egid != PL_gid));
79072805
LW
1975 break;
1976 case ':':
2d8e6c8d 1977 PL_chopset = SvPV_force(sv,len);
79072805 1978 break;
cd39f2b6 1979#ifndef MACOS_TRADITIONAL
79072805 1980 case '0':
3280af22
NIS
1981 if (!PL_origalen) {
1982 s = PL_origargv[0];
79072805
LW
1983 s += strlen(s);
1984 /* See if all the arguments are contiguous in memory */
3280af22
NIS
1985 for (i = 1; i < PL_origargc; i++) {
1986 if (PL_origargv[i] == s + 1
fb73857a 1987#ifdef OS2
6b88bc9c 1988 || PL_origargv[i] == s + 2
fb73857a
PP
1989#endif
1990 )
379c4362
GS
1991 {
1992 ++s;
1993 s += strlen(s); /* this one is ok too */
1994 }
fb73857a
PP
1995 else
1996 break;
79072805 1997 }
bbce6d69 1998 /* can grab env area too? */
3280af22 1999 if (PL_origenviron && (PL_origenviron[0] == s + 1
fb73857a 2000#ifdef OS2
6b88bc9c 2001 || (PL_origenviron[0] == s + 9 && (s += 8))
fb73857a
PP
2002#endif
2003 )) {
66b1d557 2004 my_setenv("NoNe SuCh", Nullch);
79072805 2005 /* force copy of environment */
3280af22 2006 for (i = 0; PL_origenviron[i]; i++)
379c4362
GS
2007 if (PL_origenviron[i] == s + 1) {
2008 ++s;
2009 s += strlen(s);
2010 }
fb73857a
PP
2011 else
2012 break;
79072805 2013 }
3280af22 2014 PL_origalen = s - PL_origargv[0];
79072805 2015 }
a0d0e21e 2016 s = SvPV_force(sv,len);
8990e307 2017 i = len;
3280af22
NIS
2018 if (i >= PL_origalen) {
2019 i = PL_origalen;
fb73857a
PP
2020 /* don't allow system to limit $0 seen by script */
2021 /* SvCUR_set(sv, i); *SvEND(sv) = '\0'; */
3280af22
NIS
2022 Copy(s, PL_origargv[0], i, char);
2023 s = PL_origargv[0]+i;
fb73857a 2024 *s = '\0';
79072805
LW
2025 }
2026 else {
3280af22
NIS
2027 Copy(s, PL_origargv[0], i, char);
2028 s = PL_origargv[0]+i;
79072805 2029 *s++ = '\0';
3280af22 2030 while (++i < PL_origalen)
8990e307 2031 *s++ = ' ';
3280af22
NIS
2032 s = PL_origargv[0]+i;
2033 for (i = 1; i < PL_origargc; i++)
2034 PL_origargv[i] = Nullch;
79072805
LW
2035 }
2036 break;
cd39f2b6 2037#endif
a863c7d1
MB
2038#ifdef USE_THREADS
2039 case '@':
38a03e6e 2040 sv_setsv(thr->errsv, sv);
a863c7d1
MB
2041 break;
2042#endif /* USE_THREADS */
79072805
LW
2043 }
2044 return 0;
2045}
2046
f93b4edd
MB
2047#ifdef USE_THREADS
2048int
864dbfa3 2049Perl_magic_mutexfree(pTHX_ SV *sv, MAGIC *mg)
f93b4edd
MB
2050{
2051 dTHR;
b900a521
JH
2052 DEBUG_S(PerlIO_printf(Perl_debug_log,
2053 "0x%"UVxf": magic_mutexfree 0x%"UVxf"\n",
2054 PTR2UV(thr), PTR2UV(sv));)
f93b4edd 2055 if (MgOWNER(mg))
cea2e8a9 2056 Perl_croak(aTHX_ "panic: magic_mutexfree");
f93b4edd
MB
2057 MUTEX_DESTROY(MgMUTEXP(mg));
2058 COND_DESTROY(MgCONDP(mg));
2059 return 0;
2060}
2061#endif /* USE_THREADS */
2062
79072805 2063I32
864dbfa3 2064Perl_whichsig(pTHX_ char *sig)
79072805
LW
2065{
2066 register char **sigv;
2067
22c35a8c 2068 for (sigv = PL_sig_name+1; *sigv; sigv++)
79072805 2069 if (strEQ(sig,*sigv))
22c35a8c 2070 return PL_sig_num[sigv - PL_sig_name];
79072805
LW
2071#ifdef SIGCLD
2072 if (strEQ(sig,"CHLD"))
2073 return SIGCLD;
2074#endif
2075#ifdef SIGCHLD
2076 if (strEQ(sig,"CLD"))
2077 return SIGCHLD;
2078#endif
2079 return 0;
2080}
2081
84902520
TB
2082static SV* sig_sv;
2083
ecfc5424 2084Signal_t
cea2e8a9 2085Perl_sighandler(int sig)
79072805 2086{
cea2e8a9 2087 dTHX;
79072805 2088 dSP;
00d579c5 2089 GV *gv = Nullgv;
a0d0e21e 2090 HV *st;
3280af22 2091 SV *sv, *tSv = PL_Sv;
00d579c5 2092 CV *cv = Nullcv;
533c011a 2093 OP *myop = PL_op;
84902520 2094 U32 flags = 0;
155aba94 2095 I32 o_save_i = PL_savestack_ix;
3280af22 2096 XPV *tXpv = PL_Xpv;
84902520 2097
3280af22 2098 if (PL_savestack_ix + 15 <= PL_savestack_max)
84902520 2099 flags |= 1;
3280af22 2100 if (PL_markstack_ptr < PL_markstack_max - 2)
84902520 2101 flags |= 4;
3280af22 2102 if (PL_retstack_ix < PL_retstack_max - 2)
84902520 2103 flags |= 8;
3280af22 2104 if (PL_scopestack_ix < PL_scopestack_max - 3)
84902520
TB
2105 flags |= 16;
2106
22c35a8c 2107 if (!PL_psig_ptr[sig])
cea2e8a9 2108 Perl_die(aTHX_ "Signal SIG%s received, but no signal handler set.\n",
22c35a8c 2109 PL_sig_name[sig]);
ff0cee69 2110
84902520
TB
2111 /* Max number of items pushed there is 3*n or 4. We cannot fix
2112 infinity, so we fix 4 (in fact 5): */
2113 if (flags & 1) {
3280af22
NIS
2114 PL_savestack_ix += 5; /* Protect save in progress. */
2115 o_save_i = PL_savestack_ix;
c76ac1ee 2116 SAVEDESTRUCTOR_X(unwind_handler_stack, (void*)&flags);
84902520
TB
2117 }
2118 if (flags & 4)
3280af22 2119 PL_markstack_ptr++; /* Protect mark. */
84902520 2120 if (flags & 8) {
3280af22
NIS
2121 PL_retstack_ix++;
2122 PL_retstack[PL_retstack_ix] = NULL;
84902520
TB
2123 }
2124 if (flags & 16)
3280af22 2125 PL_scopestack_ix += 1;
84902520 2126 /* sv_2cv is too complicated, try a simpler variant first: */
22c35a8c 2127 if (!SvROK(PL_psig_ptr[sig]) || !(cv = (CV*)SvRV(PL_psig_ptr[sig]))
84902520 2128 || SvTYPE(cv) != SVt_PVCV)
22c35a8c 2129 cv = sv_2cv(PL_psig_ptr[sig],&st,&gv,TRUE);
84902520 2130
a0d0e21e 2131 if (!cv || !CvROOT(cv)) {
599cee73 2132 if (ckWARN(WARN_SIGNAL))
cea2e8a9 2133 Perl_warner(aTHX_ WARN_SIGNAL, "SIG%s handler \"%s\" not defined.\n",
22c35a8c 2134 PL_sig_name[sig], (gv ? GvENAME(gv)
00d579c5
GS
2135 : ((cv && CvGV(cv))
2136 ? GvENAME(CvGV(cv))
2137 : "__ANON__")));
2138 goto cleanup;
79072805
LW
2139 }
2140
22c35a8c
GS
2141 if(PL_psig_name[sig]) {
2142 sv = SvREFCNT_inc(PL_psig_name[sig]);
84902520
TB
2143 flags |= 64;
2144 sig_sv = sv;
2145 } else {
ff0cee69 2146 sv = sv_newmortal();
22c35a8c 2147 sv_setpv(sv,PL_sig_name[sig]);
88e89b8a 2148 }
e336de0d 2149
e788e7d3 2150 PUSHSTACKi(PERLSI_SIGNAL);
924508f0 2151 PUSHMARK(SP);
79072805 2152 PUSHs(sv);
79072805 2153 PUTBACK;
a0d0e21e 2154
864dbfa3 2155 call_sv((SV*)cv, G_DISCARD);
79072805 2156
d3acc0f7 2157 POPSTACK;
00d579c5 2158cleanup:
84902520 2159 if (flags & 1)
3280af22 2160 PL_savestack_ix -= 8; /* Unprotect save in progress. */
84902520 2161 if (flags & 4)
3280af22 2162 PL_markstack_ptr--;
84902520 2163 if (flags & 8)
3280af22 2164 PL_retstack_ix--;
84902520 2165 if (flags & 16)
3280af22 2166 PL_scopestack_ix -= 1;
84902520
TB
2167 if (flags & 64)
2168 SvREFCNT_dec(sv);
533c011a 2169 PL_op = myop; /* Apparently not needed... */
84902520 2170
3280af22
NIS
2171 PL_Sv = tSv; /* Restore global temporaries. */
2172 PL_Xpv = tXpv;
79072805
LW
2173 return;
2174}
4e35701f
NIS
2175
2176
51371543 2177#ifdef PERL_OBJECT
51371543
GS
2178#include "XSUB.h"
2179#endif
2180
2181static void
2182restore_magic(pTHXo_ void *p)
2183{
2184 dTHR;
48944bdf 2185 MGS* mgs = SSPTR(PTR2IV(p), MGS*);
51371543
GS
2186 SV* sv = mgs->mgs_sv;
2187
2188 if (!sv)
2189 return;
2190
2191 if (SvTYPE(sv) >= SVt_PVMG && SvMAGIC(sv))
2192 {
2193 if (mgs->mgs_flags)
2194 SvFLAGS(sv) |= mgs->mgs_flags;
2195 else
2196 mg_magical(sv);
2197 if (SvGMAGICAL(sv))
2198 SvFLAGS(sv) &= ~(SVf_IOK|SVf_NOK|SVf_POK);
2199 }
2200
2201 mgs->mgs_sv = NULL; /* mark the MGS structure as restored */
2202
2203 /* If we're still on top of the stack, pop us off. (That condition
2204 * will be satisfied if restore_magic was called explicitly, but *not*
2205 * if it's being called via leave_scope.)
2206 * The reason for doing this is that otherwise, things like sv_2cv()
2207 * may leave alloc gunk on the savestack, and some code
2208 * (e.g. sighandler) doesn't expect that...
2209 */
2210 if (PL_savestack_ix == mgs->mgs_ss_ix)
2211 {
2212 I32 popval = SSPOPINT;
c76ac1ee 2213 assert(popval == SAVEt_DESTRUCTOR_X);
51371543
GS
2214 PL_savestack_ix -= 2;
2215 popval = SSPOPINT;
2216 assert(popval == SAVEt_ALLOC);
2217 popval = SSPOPINT;
2218 PL_savestack_ix -= popval;
2219 }
2220
2221}
2222
2223static void
2224unwind_handler_stack(pTHXo_ void *p)
2225{
2226 dTHR;
2227 U32 flags = *(U32*)p;
2228
2229 if (flags & 1)
2230 PL_savestack_ix -= 5; /* Unprotect save in progress. */
2231 /* cxstack_ix-- Not needed, die already unwound it. */
2232 if (flags & 64)
2233 SvREFCNT_dec(sig_sv);
2234}