This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
avoid compiler warnings
[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")) {
4438c4b7
JH
568 if (PL_compiling.cop_warnings == WARN_NONE ||
569 PL_compiling.cop_warnings == WARN_STD)
570 {
571 sv_setpvn(sv, WARN_NONEstring, WARNsize) ;
572 }
573 else if (PL_compiling.cop_warnings == WARN_ALL) {
574 sv_setpvn(sv, WARN_ALLstring, WARNsize) ;
575 }
576 else {
577 sv_setsv(sv, PL_compiling.cop_warnings);
578 }
579 }
46487f74
GS
580 else if (strEQ(mg->mg_ptr, "\027IDE_SYSTEM_CALLS"))
581 sv_setiv(sv, (IV)PL_widesyscalls);
79072805
LW
582 break;
583 case '1': case '2': case '3': case '4':
584 case '5': case '6': case '7': case '8': case '9': case '&':
3280af22 585 if (PL_curpm && (rx = PL_curpm->op_pmregexp)) {
cf93c79d
IZ
586 I32 s1, t1;
587
a863c7d1
MB
588 /*
589 * Pre-threads, this was paren = atoi(GvENAME((GV*)mg->mg_obj));
590 * XXX Does the new way break anything?
591 */
592 paren = atoi(mg->mg_ptr);
79072805 593 getparen:
d9f97599 594 if (paren <= rx->nparens &&
cf93c79d
IZ
595 (s1 = rx->startp[paren]) != -1 &&
596 (t1 = rx->endp[paren]) != -1)
bbce6d69 597 {
cf93c79d
IZ
598 i = t1 - s1;
599 s = rx->subbeg + s1;
13f57bf8 600 getrx:
748a9306 601 if (i >= 0) {
13f57bf8 602 bool was_tainted;
3280af22
NIS
603 if (PL_tainting) {
604 was_tainted = PL_tainted;
605 PL_tainted = FALSE;
13f57bf8 606 }
cf93c79d 607 sv_setpvn(sv, s, i);
7e2040f0
GS
608 if ((PL_curpm->op_pmdynflags & PMdf_UTF8) && !IN_BYTE)
609 SvUTF8_on(sv);
610 else
611 SvUTF8_off(sv);
3280af22
NIS
612 if (PL_tainting)
613 PL_tainted = (was_tainted || RX_MATCH_TAINTED(rx));
748a9306
LW
614 break;
615 }
79072805 616 }
79072805 617 }
3280af22 618 sv_setsv(sv,&PL_sv_undef);
79072805
LW
619 break;
620 case '+':
3280af22 621 if (PL_curpm && (rx = PL_curpm->op_pmregexp)) {
d9f97599 622 paren = rx->lastparen;
a0d0e21e
LW
623 if (paren)
624 goto getparen;
79072805 625 }
3280af22 626 sv_setsv(sv,&PL_sv_undef);
79072805
LW
627 break;
628 case '`':
3280af22 629 if (PL_curpm && (rx = PL_curpm->op_pmregexp)) {
cf93c79d
IZ
630 if ((s = rx->subbeg) && rx->startp[0] != -1) {
631 i = rx->startp[0];
13f57bf8 632 goto getrx;
79072805 633 }
79072805 634 }
3280af22 635 sv_setsv(sv,&PL_sv_undef);
79072805
LW
636 break;
637 case '\'':
3280af22 638 if (PL_curpm && (rx = PL_curpm->op_pmregexp)) {
cf93c79d
IZ
639 if (rx->subbeg && rx->endp[0] != -1) {
640 s = rx->subbeg + rx->endp[0];
641 i = rx->sublen - rx->endp[0];
13f57bf8 642 goto getrx;
79072805 643 }
79072805 644 }
3280af22 645 sv_setsv(sv,&PL_sv_undef);
79072805
LW
646 break;
647 case '.':
648#ifndef lint
3280af22
NIS
649 if (GvIO(PL_last_in_gv)) {
650 sv_setiv(sv, (IV)IoLINES(GvIO(PL_last_in_gv)));
79072805
LW
651 }
652#endif
653 break;
654 case '?':
809a5acc 655 {
809a5acc 656 sv_setiv(sv, (IV)STATUS_CURRENT);
ff0cee69 657#ifdef COMPLEX_STATUS
6b88bc9c
GS
658 LvTARGOFF(sv) = PL_statusvalue;
659 LvTARGLEN(sv) = PL_statusvalue_vms;
ff0cee69 660#endif
809a5acc 661 }
79072805
LW
662 break;
663 case '^':
3280af22 664 s = IoTOP_NAME(GvIOp(PL_defoutgv));
79072805
LW
665 if (s)
666 sv_setpv(sv,s);
667 else {
3280af22 668 sv_setpv(sv,GvENAME(PL_defoutgv));
79072805
LW
669 sv_catpv(sv,"_TOP");
670 }
671 break;
672 case '~':
3280af22 673 s = IoFMT_NAME(GvIOp(PL_defoutgv));
79072805 674 if (!s)
3280af22 675 s = GvENAME(PL_defoutgv);
79072805
LW
676 sv_setpv(sv,s);
677 break;
678#ifndef lint
679 case '=':
3280af22 680 sv_setiv(sv, (IV)IoPAGE_LEN(GvIOp(PL_defoutgv)));
79072805
LW
681 break;
682 case '-':
3280af22 683 sv_setiv(sv, (IV)IoLINES_LEFT(GvIOp(PL_defoutgv)));
79072805
LW
684 break;
685 case '%':
3280af22 686 sv_setiv(sv, (IV)IoPAGE(GvIOp(PL_defoutgv)));
79072805
LW
687 break;
688#endif
689 case ':':
690 break;
691 case '/':
692 break;
693 case '[':
3280af22 694 WITH_THR(sv_setiv(sv, (IV)PL_curcop->cop_arybase));
79072805
LW
695 break;
696 case '|':
3280af22 697 sv_setiv(sv, (IV)(IoFLAGS(GvIOp(PL_defoutgv)) & IOf_FLUSH) != 0 );
79072805
LW
698 break;
699 case ',':
3280af22 700 sv_setpvn(sv,PL_ofs,PL_ofslen);
79072805
LW
701 break;
702 case '\\':
3280af22 703 sv_setpvn(sv,PL_ors,PL_orslen);
79072805
LW
704 break;
705 case '#':
3280af22 706 sv_setpv(sv,PL_ofmt);
79072805
LW
707 break;
708 case '!':
a5f75d66 709#ifdef VMS
65202027 710 sv_setnv(sv, (NV)((errno == EVMSERR) ? vaxc$errno : errno));
88e89b8a 711 sv_setpv(sv, errno ? Strerror(errno) : "");
a5f75d66 712#else
88e89b8a
PP
713 {
714 int saveerrno = errno;
65202027 715 sv_setnv(sv, (NV)errno);
88e89b8a 716#ifdef OS2
ed344e4f
IZ
717 if (errno == errno_isOS2 || errno == errno_isOS2_set)
718 sv_setpv(sv, os2error(Perl_rc));
88e89b8a 719 else
a5f75d66 720#endif
2304df62 721 sv_setpv(sv, errno ? Strerror(errno) : "");
88e89b8a
PP
722 errno = saveerrno;
723 }
724#endif
946ec16e 725 SvNOK_on(sv); /* what a wonderful hack! */
79072805
LW
726 break;
727 case '<':
3280af22 728 sv_setiv(sv, (IV)PL_uid);
79072805
LW
729 break;
730 case '>':
3280af22 731 sv_setiv(sv, (IV)PL_euid);
79072805
LW
732 break;
733 case '(':
3280af22 734 sv_setiv(sv, (IV)PL_gid);
a52cb5f7 735#ifdef HAS_GETGROUPS
785fb66b 736 Perl_sv_setpvf(aTHX_ sv, "%"Gid_t_f, PL_gid);
a52cb5f7 737#endif
79072805
LW
738 goto add_groups;
739 case ')':
3280af22 740 sv_setiv(sv, (IV)PL_egid);
a52cb5f7 741#ifdef HAS_GETGROUPS
785fb66b 742 Perl_sv_setpvf(aTHX_ sv, "%"Gid_t_f, PL_egid);
a52cb5f7 743#endif
79072805 744 add_groups:
79072805 745#ifdef HAS_GETGROUPS
79072805 746 {
a0d0e21e 747 Groups_t gary[NGROUPS];
79072805 748 i = getgroups(NGROUPS,gary);
46fc3d4c 749 while (--i >= 0)
785fb66b 750 Perl_sv_catpvf(aTHX_ sv, " %"Gid_t_f, gary[i]);
79072805
LW
751 }
752#endif
155aba94 753 (void)SvIOK_on(sv); /* what a wonderful hack! */
79072805
LW
754 break;
755 case '*':
756 break;
cd39f2b6 757#ifndef MACOS_TRADITIONAL
79072805
LW
758 case '0':
759 break;
cd39f2b6 760#endif
a863c7d1
MB
761#ifdef USE_THREADS
762 case '@':
38a03e6e 763 sv_setsv(sv, thr->errsv);
a863c7d1
MB
764 break;
765#endif /* USE_THREADS */
79072805 766 }
a0d0e21e 767 return 0;
79072805
LW
768}
769
770int
864dbfa3 771Perl_magic_getuvar(pTHX_ SV *sv, MAGIC *mg)
79072805
LW
772{
773 struct ufuncs *uf = (struct ufuncs *)mg->mg_ptr;
774
775 if (uf && uf->uf_val)
776 (*uf->uf_val)(uf->uf_index, sv);
777 return 0;
778}
779
780int
864dbfa3 781Perl_magic_setenv(pTHX_ SV *sv, MAGIC *mg)
79072805
LW
782{
783 register char *s;
88e89b8a 784 char *ptr;
5aabfad6 785 STRLEN len, klen;
a0d0e21e 786 I32 i;
1e422769 787
a0d0e21e 788 s = SvPV(sv,len);
5aabfad6 789 ptr = MgPV(mg,klen);
88e89b8a 790 my_setenv(ptr, s);
1e422769 791
a0d0e21e
LW
792#ifdef DYNAMIC_ENV_FETCH
793 /* We just undefd an environment var. Is a replacement */
794 /* waiting in the wings? */
795 if (!len) {
5aabfad6 796 SV **valp;
6b88bc9c 797 if ((valp = hv_fetch(GvHVn(PL_envgv), ptr, klen, FALSE)))
5aabfad6 798 s = SvPV(*valp, len);
a0d0e21e
LW
799 }
800#endif
1e422769 801
39e571d4 802#if !defined(OS2) && !defined(AMIGAOS) && !defined(WIN32) && !defined(MSDOS)
79072805
LW
803 /* And you'll never guess what the dog had */
804 /* in its mouth... */
3280af22 805 if (PL_tainting) {
1e422769
PP
806 MgTAINTEDDIR_off(mg);
807#ifdef VMS
5aabfad6 808 if (s && klen == 8 && strEQ(ptr, "DCL$PATH")) {
1e422769
PP
809 char pathbuf[256], eltbuf[256], *cp, *elt = s;
810 struct stat sbuf;
811 int i = 0, j = 0;
812
813 do { /* DCL$PATH may be a search list */
814 while (1) { /* as may dev portion of any element */
815 if ( ((cp = strchr(elt,'[')) || (cp = strchr(elt,'<'))) ) {
816 if ( *(cp+1) == '.' || *(cp+1) == '-' ||
817 cando_by_name(S_IWUSR,0,elt) ) {
818 MgTAINTEDDIR_on(mg);
819 return 0;
820 }
821 }
822 if ((cp = strchr(elt, ':')) != Nullch)
823 *cp = '\0';
824 if (my_trnlnm(elt, eltbuf, j++))
825 elt = eltbuf;
826 else
827 break;
828 }
829 j = 0;
830 } while (my_trnlnm(s, pathbuf, i++) && (elt = pathbuf));
831 }
832#endif /* VMS */
5aabfad6 833 if (s && klen == 4 && strEQ(ptr,"PATH")) {
a0d0e21e 834 char *strend = s + len;
463ee0b2
LW
835
836 while (s < strend) {
96827780 837 char tmpbuf[256];
1e422769 838 struct stat st;
96827780 839 s = delimcpy(tmpbuf, tmpbuf + sizeof tmpbuf,
fc36a67e 840 s, strend, ':', &i);
463ee0b2 841 s++;
96827780
MB
842 if (i >= sizeof tmpbuf /* too long -- assume the worst */
843 || *tmpbuf != '/'
c6ed36e1 844 || (PerlLIO_stat(tmpbuf, &st) == 0 && (st.st_mode & 2)) ) {
8990e307 845 MgTAINTEDDIR_on(mg);
1e422769
PP
846 return 0;
847 }
463ee0b2 848 }
79072805
LW
849 }
850 }
39e571d4 851#endif /* neither OS2 nor AMIGAOS nor WIN32 nor MSDOS */
1e422769 852
79072805
LW
853 return 0;
854}
855
856int
864dbfa3 857Perl_magic_clearenv(pTHX_ SV *sv, MAGIC *mg)
85e6fe83 858{
2d8e6c8d
GS
859 STRLEN n_a;
860 my_setenv(MgPV(mg,n_a),Nullch);
85e6fe83
LW
861 return 0;
862}
863
88e89b8a 864int
864dbfa3 865Perl_magic_set_all_env(pTHX_ SV *sv, MAGIC *mg)
fb73857a
PP
866{
867#if defined(VMS)
cea2e8a9 868 Perl_die(aTHX_ "Can't make list assignment to %%ENV on this system");
fb73857a 869#else
d58bf5aa 870 dTHR;
3280af22 871 if (PL_localizing) {
fb73857a 872 HE* entry;
2d8e6c8d 873 STRLEN n_a;
fb73857a
PP
874 magic_clear_all_env(sv,mg);
875 hv_iterinit((HV*)sv);
155aba94 876 while ((entry = hv_iternext((HV*)sv))) {
fb73857a
PP
877 I32 keylen;
878 my_setenv(hv_iterkey(entry, &keylen),
2d8e6c8d 879 SvPV(hv_iterval((HV*)sv, entry), n_a));
fb73857a
PP
880 }
881 }
882#endif
883 return 0;
884}
885
886int
864dbfa3 887Perl_magic_clear_all_env(pTHX_ SV *sv, MAGIC *mg)
66b1d557 888{
3e3baf6d 889#if defined(VMS)
cea2e8a9 890 Perl_die(aTHX_ "Can't make list assignment to %%ENV on this system");
3e3baf6d 891#else
7766f137
GS
892# ifdef PERL_IMPLICIT_SYS
893 PerlEnv_clearenv();
894# else
895# ifdef WIN32
3e3baf6d
TB
896 char *envv = GetEnvironmentStrings();
897 char *cur = envv;
898 STRLEN len;
899 while (*cur) {
900 char *end = strchr(cur,'=');
901 if (end && end != cur) {
902 *end = '\0';
903 my_setenv(cur,Nullch);
904 *end = '=';
ac5c734f 905 cur = end + strlen(end+1)+2;
3e3baf6d
TB
906 }
907 else if ((len = strlen(cur)))
908 cur += len+1;
909 }
910 FreeEnvironmentStrings(envv);
7766f137 911# else
d308986b 912# ifdef __CYGWIN__
2c2d71f5
JH
913 I32 i;
914 for (i = 0; environ[i]; i++)
d702ae42 915 safesysfree(environ[i]);
7766f137
GS
916# else
917# ifndef PERL_USE_SAFE_PUTENV
66b1d557
HM
918 I32 i;
919
3280af22 920 if (environ == PL_origenviron)
f2517201 921 environ = (char**)safesysmalloc(sizeof(char*));
66b1d557
HM
922 else
923 for (i = 0; environ[i]; i++)
f2517201 924 safesysfree(environ[i]);
7766f137 925# endif /* PERL_USE_SAFE_PUTENV */
d308986b 926# endif /* __CYGWIN__ */
f2517201 927
66b1d557
HM
928 environ[0] = Nullch;
929
7766f137
GS
930# endif /* WIN32 */
931# endif /* PERL_IMPLICIT_SYS */
f2517201 932#endif /* VMS */
3e3baf6d 933 return 0;
66b1d557
HM
934}
935
936int
864dbfa3 937Perl_magic_getsig(pTHX_ SV *sv, MAGIC *mg)
88e89b8a
PP
938{
939 I32 i;
2d8e6c8d 940 STRLEN n_a;
88e89b8a 941 /* Are we fetching a signal entry? */
2d8e6c8d 942 i = whichsig(MgPV(mg,n_a));
88e89b8a 943 if (i) {
22c35a8c
GS
944 if(PL_psig_ptr[i])
945 sv_setsv(sv,PL_psig_ptr[i]);
88e89b8a 946 else {
ff68c719
PP
947 Sighandler_t sigstate = rsignal_state(i);
948
88e89b8a 949 /* cache state so we don't fetch it again */
ff68c719 950 if(sigstate == SIG_IGN)
88e89b8a
PP
951 sv_setpv(sv,"IGNORE");
952 else
3280af22 953 sv_setsv(sv,&PL_sv_undef);
22c35a8c 954 PL_psig_ptr[i] = SvREFCNT_inc(sv);
88e89b8a
PP
955 SvTEMP_off(sv);
956 }
957 }
958 return 0;
959}
960int
864dbfa3 961Perl_magic_clearsig(pTHX_ SV *sv, MAGIC *mg)
88e89b8a
PP
962{
963 I32 i;
2d8e6c8d 964 STRLEN n_a;
88e89b8a 965 /* Are we clearing a signal entry? */
2d8e6c8d 966 i = whichsig(MgPV(mg,n_a));
88e89b8a 967 if (i) {
22c35a8c
GS
968 if(PL_psig_ptr[i]) {
969 SvREFCNT_dec(PL_psig_ptr[i]);
970 PL_psig_ptr[i]=0;
88e89b8a 971 }
22c35a8c
GS
972 if(PL_psig_name[i]) {
973 SvREFCNT_dec(PL_psig_name[i]);
974 PL_psig_name[i]=0;
88e89b8a
PP
975 }
976 }
977 return 0;
978}
3d37d572 979
85e6fe83 980int
864dbfa3 981Perl_magic_setsig(pTHX_ SV *sv, MAGIC *mg)
79072805 982{
11343788 983 dTHR;
79072805
LW
984 register char *s;
985 I32 i;
748a9306 986 SV** svp;
e72dc28c 987 STRLEN len;
a0d0e21e 988
e72dc28c 989 s = MgPV(mg,len);
748a9306
LW
990 if (*s == '_') {
991 if (strEQ(s,"__DIE__"))
3280af22 992 svp = &PL_diehook;
748a9306 993 else if (strEQ(s,"__WARN__"))
3280af22 994 svp = &PL_warnhook;
748a9306 995 else
cea2e8a9 996 Perl_croak(aTHX_ "No such hook: %s", s);
748a9306 997 i = 0;
4633a7c4
LW
998 if (*svp) {
999 SvREFCNT_dec(*svp);
1000 *svp = 0;
1001 }
748a9306
LW
1002 }
1003 else {
1004 i = whichsig(s); /* ...no, a brick */
1005 if (!i) {
e476b1b5 1006 if (ckWARN(WARN_SIGNAL))
cea2e8a9 1007 Perl_warner(aTHX_ WARN_SIGNAL, "No such signal: SIG%s", s);
748a9306
LW
1008 return 0;
1009 }
22c35a8c
GS
1010 SvREFCNT_dec(PL_psig_name[i]);
1011 SvREFCNT_dec(PL_psig_ptr[i]);
1012 PL_psig_ptr[i] = SvREFCNT_inc(sv);
88e89b8a 1013 SvTEMP_off(sv); /* Make sure it doesn't go away on us */
e72dc28c 1014 PL_psig_name[i] = newSVpvn(s, len);
22c35a8c 1015 SvREADONLY_on(PL_psig_name[i]);
748a9306 1016 }
a0d0e21e 1017 if (SvTYPE(sv) == SVt_PVGV || SvROK(sv)) {
748a9306 1018 if (i)
3280af22 1019 (void)rsignal(i, PL_sighandlerp);
748a9306
LW
1020 else
1021 *svp = SvREFCNT_inc(sv);
a0d0e21e
LW
1022 return 0;
1023 }
e72dc28c 1024 s = SvPV_force(sv,len);
748a9306
LW
1025 if (strEQ(s,"IGNORE")) {
1026 if (i)
ff68c719 1027 (void)rsignal(i, SIG_IGN);
748a9306
LW
1028 else
1029 *svp = 0;
1030 }
1031 else if (strEQ(s,"DEFAULT") || !*s) {
1032 if (i)
ff68c719 1033 (void)rsignal(i, SIG_DFL);
748a9306
LW
1034 else
1035 *svp = 0;
1036 }
79072805 1037 else {
5aabfad6
PP
1038 /*
1039 * We should warn if HINT_STRICT_REFS, but without
1040 * access to a known hint bit in a known OP, we can't
1041 * tell whether HINT_STRICT_REFS is in force or not.
1042 */
46fc3d4c 1043 if (!strchr(s,':') && !strchr(s,'\''))
e72dc28c 1044 sv_insert(sv, 0, 0, "main::", 6);
748a9306 1045 if (i)
3280af22 1046 (void)rsignal(i, PL_sighandlerp);
748a9306
LW
1047 else
1048 *svp = SvREFCNT_inc(sv);
79072805
LW
1049 }
1050 return 0;
1051}
1052
1053int
864dbfa3 1054Perl_magic_setisa(pTHX_ SV *sv, MAGIC *mg)
79072805 1055{
3280af22 1056 PL_sub_generation++;
463ee0b2
LW
1057 return 0;
1058}
1059
1060int
864dbfa3 1061Perl_magic_setamagic(pTHX_ SV *sv, MAGIC *mg)
463ee0b2 1062{
a0d0e21e 1063 /* HV_badAMAGIC_on(Sv_STASH(sv)); */
3280af22 1064 PL_amagic_generation++;
463ee0b2 1065
a0d0e21e
LW
1066 return 0;
1067}
463ee0b2 1068
946ec16e 1069int
864dbfa3 1070Perl_magic_getnkeys(pTHX_ SV *sv, MAGIC *mg)
6ff81951
GS
1071{
1072 HV *hv = (HV*)LvTARG(sv);
1073 HE *entry;
1074 I32 i = 0;
1075
1076 if (hv) {
1077 (void) hv_iterinit(hv);
33c27489 1078 if (! SvTIED_mg((SV*)hv, 'P'))
6ff81951
GS
1079 i = HvKEYS(hv);
1080 else {
1081 /*SUPPRESS 560*/
155aba94 1082 while ((entry = hv_iternext(hv))) {
6ff81951
GS
1083 i++;
1084 }
1085 }
1086 }
1087
1088 sv_setiv(sv, (IV)i);
1089 return 0;
1090}
1091
1092int
864dbfa3 1093Perl_magic_setnkeys(pTHX_ SV *sv, MAGIC *mg)
946ec16e
PP
1094{
1095 if (LvTARG(sv)) {
1096 hv_ksplit((HV*)LvTARG(sv), SvIV(sv));
946ec16e
PP
1097 }
1098 return 0;
93965878 1099}
946ec16e 1100
e336de0d 1101/* caller is responsible for stack switching/cleanup */
565764a8 1102STATIC int
cea2e8a9 1103S_magic_methcall(pTHX_ SV *sv, MAGIC *mg, char *meth, I32 flags, int n, SV *val)
a0d0e21e
LW
1104{
1105 dSP;
463ee0b2 1106
924508f0
GS
1107 PUSHMARK(SP);
1108 EXTEND(SP, n);
33c27489 1109 PUSHs(SvTIED_obj(sv, mg));
93965878
NIS
1110 if (n > 1) {
1111 if (mg->mg_ptr) {
565764a8 1112 if (mg->mg_len >= 0)
79cb57f6 1113 PUSHs(sv_2mortal(newSVpvn(mg->mg_ptr, mg->mg_len)));
565764a8 1114 else if (mg->mg_len == HEf_SVKEY)
93965878
NIS
1115 PUSHs((SV*)mg->mg_ptr);
1116 }
1117 else if (mg->mg_type == 'p') {
565764a8 1118 PUSHs(sv_2mortal(newSViv(mg->mg_len)));
93965878
NIS
1119 }
1120 }
1121 if (n > 2) {
1122 PUSHs(val);
88e89b8a 1123 }
463ee0b2
LW
1124 PUTBACK;
1125
864dbfa3 1126 return call_method(meth, flags);
946ec16e
PP
1127}
1128
76e3520e 1129STATIC int
cea2e8a9 1130S_magic_methpack(pTHX_ SV *sv, MAGIC *mg, char *meth)
a0d0e21e
LW
1131{
1132 dSP;
463ee0b2 1133
a0d0e21e
LW
1134 ENTER;
1135 SAVETMPS;
e788e7d3 1136 PUSHSTACKi(PERLSI_MAGIC);
463ee0b2 1137
33c27489 1138 if (magic_methcall(sv, mg, meth, G_SCALAR, 2, NULL)) {
3280af22 1139 sv_setsv(sv, *PL_stack_sp--);
93965878 1140 }
463ee0b2 1141
d3acc0f7 1142 POPSTACK;
a0d0e21e
LW
1143 FREETMPS;
1144 LEAVE;
1145 return 0;
1146}
463ee0b2 1147
a0d0e21e 1148int
864dbfa3 1149Perl_magic_getpack(pTHX_ SV *sv, MAGIC *mg)
a0d0e21e
LW
1150{
1151 magic_methpack(sv,mg,"FETCH");
1152 if (mg->mg_ptr)
1153 mg->mg_flags |= MGf_GSKIP;
463ee0b2
LW
1154 return 0;
1155}
1156
1157int
864dbfa3 1158Perl_magic_setpack(pTHX_ SV *sv, MAGIC *mg)
e336de0d
GS
1159{
1160 dSP;
a60c0954 1161 ENTER;
e788e7d3 1162 PUSHSTACKi(PERLSI_MAGIC);
33c27489 1163 magic_methcall(sv, mg, "STORE", G_SCALAR|G_DISCARD, 3, sv);
d3acc0f7 1164 POPSTACK;
a60c0954 1165 LEAVE;
463ee0b2
LW
1166 return 0;
1167}
1168
1169int
864dbfa3 1170Perl_magic_clearpack(pTHX_ SV *sv, MAGIC *mg)
463ee0b2 1171{
a0d0e21e
LW
1172 return magic_methpack(sv,mg,"DELETE");
1173}
463ee0b2 1174
93965878
NIS
1175
1176U32
864dbfa3 1177Perl_magic_sizepack(pTHX_ SV *sv, MAGIC *mg)
93965878 1178{
e336de0d 1179 dSP;
93965878
NIS
1180 U32 retval = 0;
1181
1182 ENTER;
1183 SAVETMPS;
e788e7d3 1184 PUSHSTACKi(PERLSI_MAGIC);
33c27489 1185 if (magic_methcall(sv, mg, "FETCHSIZE", G_SCALAR, 2, NULL)) {
3280af22 1186 sv = *PL_stack_sp--;
a60c0954 1187 retval = (U32) SvIV(sv)-1;
93965878 1188 }
d3acc0f7 1189 POPSTACK;
93965878
NIS
1190 FREETMPS;
1191 LEAVE;
1192 return retval;
1193}
1194
cea2e8a9
GS
1195int
1196Perl_magic_wipepack(pTHX_ SV *sv, MAGIC *mg)
a0d0e21e
LW
1197{
1198 dSP;
463ee0b2 1199
e336de0d 1200 ENTER;
e788e7d3 1201 PUSHSTACKi(PERLSI_MAGIC);
924508f0 1202 PUSHMARK(SP);
33c27489 1203 XPUSHs(SvTIED_obj(sv, mg));
463ee0b2 1204 PUTBACK;
864dbfa3 1205 call_method("CLEAR", G_SCALAR|G_DISCARD);
d3acc0f7 1206 POPSTACK;
a60c0954 1207 LEAVE;
463ee0b2
LW
1208 return 0;
1209}
1210
1211int
864dbfa3 1212Perl_magic_nextpack(pTHX_ SV *sv, MAGIC *mg, SV *key)
463ee0b2 1213{
463ee0b2 1214 dSP;
dff6d3cd 1215 const char *meth = SvOK(key) ? "NEXTKEY" : "FIRSTKEY";
463ee0b2
LW
1216
1217 ENTER;
a0d0e21e 1218 SAVETMPS;
e788e7d3 1219 PUSHSTACKi(PERLSI_MAGIC);
924508f0
GS
1220 PUSHMARK(SP);
1221 EXTEND(SP, 2);
33c27489 1222 PUSHs(SvTIED_obj(sv, mg));
463ee0b2
LW
1223 if (SvOK(key))
1224 PUSHs(key);
1225 PUTBACK;
1226
864dbfa3 1227 if (call_method(meth, G_SCALAR))
3280af22 1228 sv_setsv(key, *PL_stack_sp--);
463ee0b2 1229
d3acc0f7 1230 POPSTACK;
a0d0e21e
LW
1231 FREETMPS;
1232 LEAVE;
79072805
LW
1233 return 0;
1234}
1235
1236int
864dbfa3 1237Perl_magic_existspack(pTHX_ SV *sv, MAGIC *mg)
a0d0e21e
LW
1238{
1239 return magic_methpack(sv,mg,"EXISTS");
1240}
1241
1242int
864dbfa3 1243Perl_magic_setdbline(pTHX_ SV *sv, MAGIC *mg)
79072805 1244{
11343788 1245 dTHR;
79072805
LW
1246 OP *o;
1247 I32 i;
1248 GV* gv;
1249 SV** svp;
2d8e6c8d 1250 STRLEN n_a;
79072805 1251
3280af22 1252 gv = PL_DBline;
79072805 1253 i = SvTRUE(sv);
188ea221 1254 svp = av_fetch(GvAV(gv),
2d8e6c8d 1255 atoi(MgPV(mg,n_a)), FALSE);
57b2e452 1256 if (svp && SvIOKp(*svp) && (o = INT2PTR(OP*,SvIVX(*svp))))
93a17b20 1257 o->op_private = i;
0453d815
PM
1258 else if (ckWARN_d(WARN_INTERNAL))
1259 Perl_warner(aTHX_ WARN_INTERNAL, "Can't break at that line\n");
79072805
LW
1260 return 0;
1261}
1262
1263int
864dbfa3 1264Perl_magic_getarylen(pTHX_ SV *sv, MAGIC *mg)
79072805 1265{
0f15f207 1266 dTHR;
3280af22 1267 sv_setiv(sv, AvFILL((AV*)mg->mg_obj) + PL_curcop->cop_arybase);
79072805
LW
1268 return 0;
1269}
1270
1271int
864dbfa3 1272Perl_magic_setarylen(pTHX_ SV *sv, MAGIC *mg)
79072805 1273{
0f15f207 1274 dTHR;
3280af22 1275 av_fill((AV*)mg->mg_obj, SvIV(sv) - PL_curcop->cop_arybase);
a0d0e21e
LW
1276 return 0;
1277}
1278
1279int
864dbfa3 1280Perl_magic_getpos(pTHX_ SV *sv, MAGIC *mg)
a0d0e21e
LW
1281{
1282 SV* lsv = LvTARG(sv);
1283
1284 if (SvTYPE(lsv) >= SVt_PVMG && SvMAGIC(lsv)) {
1285 mg = mg_find(lsv, 'g');
565764a8 1286 if (mg && mg->mg_len >= 0) {
0f15f207 1287 dTHR;
a0ed51b3 1288 I32 i = mg->mg_len;
7e2040f0 1289 if (DO_UTF8(lsv))
a0ed51b3
LW
1290 sv_pos_b2u(lsv, &i);
1291 sv_setiv(sv, i + PL_curcop->cop_arybase);
a0d0e21e
LW
1292 return 0;
1293 }
1294 }
1295 (void)SvOK_off(sv);
1296 return 0;
1297}
1298
1299int
864dbfa3 1300Perl_magic_setpos(pTHX_ SV *sv, MAGIC *mg)
a0d0e21e
LW
1301{
1302 SV* lsv = LvTARG(sv);
1303 SSize_t pos;
1304 STRLEN len;
c00206c8 1305 STRLEN ulen = 0;
c485e607 1306 dTHR;
a0d0e21e
LW
1307
1308 mg = 0;
1309
1310 if (SvTYPE(lsv) >= SVt_PVMG && SvMAGIC(lsv))
1311 mg = mg_find(lsv, 'g');
1312 if (!mg) {
1313 if (!SvOK(sv))
1314 return 0;
1315 sv_magic(lsv, (SV*)0, 'g', Nullch, 0);
1316 mg = mg_find(lsv, 'g');
1317 }
1318 else if (!SvOK(sv)) {
565764a8 1319 mg->mg_len = -1;
a0d0e21e
LW
1320 return 0;
1321 }
1322 len = SvPOK(lsv) ? SvCUR(lsv) : sv_len(lsv);
1323
c485e607 1324 pos = SvIV(sv) - PL_curcop->cop_arybase;
a0ed51b3 1325
7e2040f0 1326 if (DO_UTF8(lsv)) {
a0ed51b3
LW
1327 ulen = sv_len_utf8(lsv);
1328 if (ulen)
1329 len = ulen;
a0ed51b3
LW
1330 }
1331
a0d0e21e
LW
1332 if (pos < 0) {
1333 pos += len;
1334 if (pos < 0)
1335 pos = 0;
1336 }
1337 else if (pos > len)
1338 pos = len;
a0ed51b3
LW
1339
1340 if (ulen) {
1341 I32 p = pos;
1342 sv_pos_u2b(lsv, &p, 0);
1343 pos = p;
1344 }
1345
565764a8 1346 mg->mg_len = pos;
71be2cbc 1347 mg->mg_flags &= ~MGf_MINMATCH;
a0d0e21e 1348
79072805
LW
1349 return 0;
1350}
1351
1352int
864dbfa3 1353Perl_magic_getglob(pTHX_ SV *sv, MAGIC *mg)
79072805 1354{
8646b087
PP
1355 if (SvFAKE(sv)) { /* FAKE globs can get coerced */
1356 SvFAKE_off(sv);
946ec16e 1357 gv_efullname3(sv,((GV*)sv), "*");
8646b087
PP
1358 SvFAKE_on(sv);
1359 }
1360 else
946ec16e 1361 gv_efullname3(sv,((GV*)sv), "*"); /* a gv value, be nice */
79072805
LW
1362 return 0;
1363}
1364
1365int
864dbfa3 1366Perl_magic_setglob(pTHX_ SV *sv, MAGIC *mg)
79072805
LW
1367{
1368 register char *s;
1369 GV* gv;
2d8e6c8d 1370 STRLEN n_a;
79072805
LW
1371
1372 if (!SvOK(sv))
1373 return 0;
2d8e6c8d 1374 s = SvPV(sv, n_a);
79072805
LW
1375 if (*s == '*' && s[1])
1376 s++;
85e6fe83 1377 gv = gv_fetchpv(s,TRUE, SVt_PVGV);
79072805
LW
1378 if (sv == (SV*)gv)
1379 return 0;
1380 if (GvGP(sv))
88e89b8a 1381 gp_free((GV*)sv);
79072805 1382 GvGP(sv) = gp_ref(GvGP(gv));
79072805
LW
1383 return 0;
1384}
1385
1386int
864dbfa3 1387Perl_magic_getsubstr(pTHX_ SV *sv, MAGIC *mg)
6ff81951
GS
1388{
1389 STRLEN len;
1390 SV *lsv = LvTARG(sv);
1391 char *tmps = SvPV(lsv,len);
1392 I32 offs = LvTARGOFF(sv);
1393 I32 rem = LvTARGLEN(sv);
1394
1395 if (offs > len)
1396 offs = len;
1397 if (rem + offs > len)
1398 rem = len - offs;
1399 sv_setpvn(sv, tmps + offs, (STRLEN)rem);
1400 return 0;
1401}
1402
1403int
864dbfa3 1404Perl_magic_setsubstr(pTHX_ SV *sv, MAGIC *mg)
79072805 1405{
8990e307
LW
1406 STRLEN len;
1407 char *tmps = SvPV(sv,len);
1408 sv_insert(LvTARG(sv),LvTARGOFF(sv),LvTARGLEN(sv), tmps, len);
79072805
LW
1409 return 0;
1410}
1411
1412int
864dbfa3 1413Perl_magic_gettaint(pTHX_ SV *sv, MAGIC *mg)
463ee0b2 1414{
a863c7d1 1415 dTHR;
565764a8 1416 TAINT_IF((mg->mg_len & 1) ||
155aba94 1417 ((mg->mg_len & 2) && mg->mg_obj == sv)); /* kludge */
463ee0b2
LW
1418 return 0;
1419}
1420
1421int
864dbfa3 1422Perl_magic_settaint(pTHX_ SV *sv, MAGIC *mg)
463ee0b2 1423{
11343788 1424 dTHR;
3280af22
NIS
1425 if (PL_localizing) {
1426 if (PL_localizing == 1)
565764a8 1427 mg->mg_len <<= 1;
748a9306 1428 else
565764a8 1429 mg->mg_len >>= 1;
a0d0e21e 1430 }
3280af22 1431 else if (PL_tainted)
565764a8 1432 mg->mg_len |= 1;
748a9306 1433 else
565764a8 1434 mg->mg_len &= ~1;
463ee0b2
LW
1435 return 0;
1436}
1437
1438int
864dbfa3 1439Perl_magic_getvec(pTHX_ SV *sv, MAGIC *mg)
6ff81951
GS
1440{
1441 SV *lsv = LvTARG(sv);
6ff81951
GS
1442
1443 if (!lsv) {
155aba94 1444 (void)SvOK_off(sv);
6ff81951
GS
1445 return 0;
1446 }
6ff81951 1447
81e118e0 1448 sv_setuv(sv, do_vecget(lsv, LvTARGOFF(sv), LvTARGLEN(sv)));
6ff81951
GS
1449 return 0;
1450}
1451
1452int
864dbfa3 1453Perl_magic_setvec(pTHX_ SV *sv, MAGIC *mg)
79072805
LW
1454{
1455 do_vecset(sv); /* XXX slurp this routine */
1456 return 0;
1457}
1458
1459int
864dbfa3 1460Perl_magic_getdefelem(pTHX_ SV *sv, MAGIC *mg)
5f05dabc 1461{
71be2cbc 1462 SV *targ = Nullsv;
5f05dabc 1463 if (LvTARGLEN(sv)) {
68dc0745 1464 if (mg->mg_obj) {
74e13ce4
GS
1465 SV *ahv = LvTARG(sv);
1466 if (SvTYPE(ahv) == SVt_PVHV) {
1467 HE *he = hv_fetch_ent((HV*)ahv, mg->mg_obj, FALSE, 0);
1468 if (he)
1469 targ = HeVAL(he);
1470 }
1471 else {
1472 SV **svp = avhv_fetch_ent((AV*)ahv, mg->mg_obj, FALSE, 0);
1473 if (svp)
1474 targ = *svp;
1475 }
68dc0745
PP
1476 }
1477 else {
3c78fafa 1478 AV* av = (AV*)LvTARG(sv);
68dc0745
PP
1479 if ((I32)LvTARGOFF(sv) <= AvFILL(av))
1480 targ = AvARRAY(av)[LvTARGOFF(sv)];
1481 }
3280af22 1482 if (targ && targ != &PL_sv_undef) {
e858de61 1483 dTHR; /* just for SvREFCNT_dec */
68dc0745
PP
1484 /* somebody else defined it for us */
1485 SvREFCNT_dec(LvTARG(sv));
1486 LvTARG(sv) = SvREFCNT_inc(targ);
1487 LvTARGLEN(sv) = 0;
1488 SvREFCNT_dec(mg->mg_obj);
1489 mg->mg_obj = Nullsv;
1490 mg->mg_flags &= ~MGf_REFCOUNTED;
1491 }
5f05dabc 1492 }
71be2cbc
PP
1493 else
1494 targ = LvTARG(sv);
3280af22 1495 sv_setsv(sv, targ ? targ : &PL_sv_undef);
71be2cbc
PP
1496 return 0;
1497}
1498
1499int
864dbfa3 1500Perl_magic_setdefelem(pTHX_ SV *sv, MAGIC *mg)
71be2cbc
PP
1501{
1502 if (LvTARGLEN(sv))
68dc0745
PP
1503 vivify_defelem(sv);
1504 if (LvTARG(sv)) {
5f05dabc 1505 sv_setsv(LvTARG(sv), sv);
68dc0745
PP
1506 SvSETMAGIC(LvTARG(sv));
1507 }
5f05dabc
PP
1508 return 0;
1509}
1510
71be2cbc 1511void
864dbfa3 1512Perl_vivify_defelem(pTHX_ SV *sv)
71be2cbc 1513{
e858de61 1514 dTHR; /* just for SvREFCNT_inc and SvREFCNT_dec*/
74e13ce4
GS
1515 MAGIC *mg;
1516 SV *value = Nullsv;
71be2cbc 1517
68dc0745 1518 if (!LvTARGLEN(sv) || !(mg = mg_find(sv, 'y')))
71be2cbc 1519 return;
68dc0745 1520 if (mg->mg_obj) {
74e13ce4 1521 SV *ahv = LvTARG(sv);
2d8e6c8d 1522 STRLEN n_a;
74e13ce4 1523 if (SvTYPE(ahv) == SVt_PVHV) {
af7f9c15 1524 HE *he = hv_fetch_ent((HV*)ahv, mg->mg_obj, TRUE, 0);
74e13ce4
GS
1525 if (he)
1526 value = HeVAL(he);
1527 }
1528 else {
af7f9c15 1529 SV **svp = avhv_fetch_ent((AV*)ahv, mg->mg_obj, TRUE, 0);
74e13ce4
GS
1530 if (svp)
1531 value = *svp;
1532 }
3280af22 1533 if (!value || value == &PL_sv_undef)
cea2e8a9 1534 Perl_croak(aTHX_ PL_no_helem, SvPV(mg->mg_obj, n_a));
71be2cbc 1535 }
68dc0745
PP
1536 else {
1537 AV* av = (AV*)LvTARG(sv);
5aabfad6 1538 if ((I32)LvTARGLEN(sv) < 0 && (I32)LvTARGOFF(sv) > AvFILL(av))
68dc0745
PP
1539 LvTARG(sv) = Nullsv; /* array can't be extended */
1540 else {
1541 SV** svp = av_fetch(av, LvTARGOFF(sv), TRUE);
3280af22 1542 if (!svp || (value = *svp) == &PL_sv_undef)
cea2e8a9 1543 Perl_croak(aTHX_ PL_no_aelem, (I32)LvTARGOFF(sv));
68dc0745
PP
1544 }
1545 }
3e3baf6d 1546 (void)SvREFCNT_inc(value);
68dc0745
PP
1547 SvREFCNT_dec(LvTARG(sv));
1548 LvTARG(sv) = value;
71be2cbc 1549 LvTARGLEN(sv) = 0;
68dc0745
PP
1550 SvREFCNT_dec(mg->mg_obj);
1551 mg->mg_obj = Nullsv;
1552 mg->mg_flags &= ~MGf_REFCOUNTED;
5f05dabc
PP
1553}
1554
1555int
864dbfa3 1556Perl_magic_killbackrefs(pTHX_ SV *sv, MAGIC *mg)
810b8aa5
GS
1557{
1558 AV *av = (AV*)mg->mg_obj;
1559 SV **svp = AvARRAY(av);
1560 I32 i = AvFILLp(av);
1561 while (i >= 0) {
1562 if (svp[i] && svp[i] != &PL_sv_undef) {
1563 if (!SvWEAKREF(svp[i]))
cea2e8a9 1564 Perl_croak(aTHX_ "panic: magic_killbackrefs");
810b8aa5
GS
1565 /* XXX Should we check that it hasn't changed? */
1566 SvRV(svp[i]) = 0;
155aba94 1567 (void)SvOK_off(svp[i]);
810b8aa5
GS
1568 SvWEAKREF_off(svp[i]);
1569 svp[i] = &PL_sv_undef;
1570 }
1571 i--;
1572 }
1573 return 0;
1574}
1575
1576int
864dbfa3 1577Perl_magic_setmglob(pTHX_ SV *sv, MAGIC *mg)
93a17b20 1578{
565764a8 1579 mg->mg_len = -1;
c6496cc7 1580 SvSCREAM_off(sv);
93a17b20
LW
1581 return 0;
1582}
1583
1584int
864dbfa3 1585Perl_magic_setbm(pTHX_ SV *sv, MAGIC *mg)
79072805 1586{
463ee0b2 1587 sv_unmagic(sv, 'B');
79072805
LW
1588 SvVALID_off(sv);
1589 return 0;
1590}
1591
1592int
864dbfa3 1593Perl_magic_setfm(pTHX_ SV *sv, MAGIC *mg)
55497cff
PP
1594{
1595 sv_unmagic(sv, 'f');
1596 SvCOMPILED_off(sv);
1597 return 0;
1598}
1599
1600int
864dbfa3 1601Perl_magic_setuvar(pTHX_ SV *sv, MAGIC *mg)
79072805
LW
1602{
1603 struct ufuncs *uf = (struct ufuncs *)mg->mg_ptr;
1604
1605 if (uf && uf->uf_set)
1606 (*uf->uf_set)(uf->uf_index, sv);
1607 return 0;
1608}
1609
c277df42 1610int
864dbfa3 1611Perl_magic_freeregexp(pTHX_ SV *sv, MAGIC *mg)
c277df42
IZ
1612{
1613 regexp *re = (regexp *)mg->mg_obj;
1614 ReREFCNT_dec(re);
1615 return 0;
1616}
1617
7a4c00b4 1618#ifdef USE_LOCALE_COLLATE
79072805 1619int
864dbfa3 1620Perl_magic_setcollxfrm(pTHX_ SV *sv, MAGIC *mg)
bbce6d69
PP
1621{
1622 /*
838b5b74 1623 * RenE<eacute> Descartes said "I think not."
bbce6d69
PP
1624 * and vanished with a faint plop.
1625 */
7a4c00b4
PP
1626 if (mg->mg_ptr) {
1627 Safefree(mg->mg_ptr);
1628 mg->mg_ptr = NULL;
565764a8 1629 mg->mg_len = -1;
7a4c00b4 1630 }
bbce6d69
PP
1631 return 0;
1632}
7a4c00b4 1633#endif /* USE_LOCALE_COLLATE */
bbce6d69
PP
1634
1635int
864dbfa3 1636Perl_magic_set(pTHX_ SV *sv, MAGIC *mg)
79072805 1637{
11343788 1638 dTHR;
79072805
LW
1639 register char *s;
1640 I32 i;
8990e307 1641 STRLEN len;
79072805 1642 switch (*mg->mg_ptr) {
748a9306 1643 case '\001': /* ^A */
3280af22 1644 sv_setsv(PL_bodytarget, sv);
748a9306 1645 break;
49460fe6
NIS
1646 case '\003': /* ^C */
1647 PL_minus_c = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
1648 break;
1649
79072805 1650 case '\004': /* ^D */
3280af22 1651 PL_debug = (SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv)) | 0x80000000;
79072805
LW
1652 DEBUG_x(dump_all());
1653 break;
28f23441 1654 case '\005': /* ^E */
cd39f2b6
JH
1655#ifdef MACOS_TRADITIONAL
1656 gLastMacOSErr = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
28f23441 1657#else
cd39f2b6
JH
1658# ifdef VMS
1659 set_vaxc_errno(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv));
048c1ddf 1660# else
cd39f2b6
JH
1661# ifdef WIN32
1662 SetLastError( SvIV(sv) );
1663# else
1664# ifndef OS2
f86702cc
PP
1665 /* will anyone ever use this? */
1666 SETERRNO(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv), 4);
cd39f2b6 1667# endif
048c1ddf
IZ
1668# endif
1669# endif
22fae026 1670#endif
28f23441 1671 break;
79072805 1672 case '\006': /* ^F */
3280af22 1673 PL_maxsysfd = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
79072805 1674 break;
a0d0e21e 1675 case '\010': /* ^H */
3280af22 1676 PL_hints = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
a0d0e21e 1677 break;
9d116dd7 1678 case '\011': /* ^I */ /* NOT \t in EBCDIC */
3280af22
NIS
1679 if (PL_inplace)
1680 Safefree(PL_inplace);
79072805 1681 if (SvOK(sv))
2d8e6c8d 1682 PL_inplace = savepv(SvPV(sv,len));
79072805 1683 else
3280af22 1684 PL_inplace = Nullch;
79072805 1685 break;
28f23441 1686 case '\017': /* ^O */
3280af22
NIS
1687 if (PL_osname)
1688 Safefree(PL_osname);
28f23441 1689 if (SvOK(sv))
2d8e6c8d 1690 PL_osname = savepv(SvPV(sv,len));
28f23441 1691 else
3280af22 1692 PL_osname = Nullch;
28f23441 1693 break;
79072805 1694 case '\020': /* ^P */
3280af22 1695 PL_perldb = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
1ee4443e
IZ
1696 if (PL_perldb && !PL_DBsingle)
1697 init_debugger();
79072805
LW
1698 break;
1699 case '\024': /* ^T */
88e89b8a 1700#ifdef BIG_TIME
6b88bc9c 1701 PL_basetime = (Time_t)(SvNOK(sv) ? SvNVX(sv) : sv_2nv(sv));
88e89b8a 1702#else
3280af22 1703 PL_basetime = (Time_t)(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv));
88e89b8a 1704#endif
79072805 1705 break;
46487f74 1706 case '\027': /* ^W & $^WARNING_BITS & ^WIDE_SYSTEM_CALLS */
4438c4b7
JH
1707 if (*(mg->mg_ptr+1) == '\0') {
1708 if ( ! (PL_dowarn & G_WARN_ALL_MASK)) {
1709 i = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
1710 PL_dowarn = (PL_dowarn & ~G_WARN_ON)
0453d815 1711 | (i ? G_WARN_ON : G_WARN_OFF) ;
4438c4b7 1712 }
599cee73 1713 }
6a818117 1714 else if (strEQ(mg->mg_ptr, "\027ARNING_BITS")) {
4438c4b7 1715 if ( ! (PL_dowarn & G_WARN_ALL_MASK)) {
d775746e
GS
1716 if (!SvPOK(sv) && PL_localizing) {
1717 sv_setpvn(sv, WARN_NONEstring, WARNsize);
1718 PL_compiling.cop_warnings = WARN_NONE;
1719 break;
1720 }
4438c4b7
JH
1721 if (memEQ(SvPVX(sv), WARN_ALLstring, WARNsize)) {
1722 PL_compiling.cop_warnings = WARN_ALL;
1723 PL_dowarn |= G_WARN_ONCE ;
1724 }
1725 else if (memEQ(SvPVX(sv), WARN_NONEstring, WARNsize))
1726 PL_compiling.cop_warnings = WARN_NONE;
1727 else {
1728 if (specialWARN(PL_compiling.cop_warnings))
1729 PL_compiling.cop_warnings = newSVsv(sv) ;
1730 else
1731 sv_setsv(PL_compiling.cop_warnings, sv);
1732 if (isWARN_on(PL_compiling.cop_warnings, WARN_ONCE))
1733 PL_dowarn |= G_WARN_ONCE ;
1734 }
1735 }
971a9dd3 1736 }
46487f74
GS
1737 else if (strEQ(mg->mg_ptr, "\027IDE_SYSTEM_CALLS"))
1738 PL_widesyscalls = SvTRUE(sv);
79072805
LW
1739 break;
1740 case '.':
3280af22
NIS
1741 if (PL_localizing) {
1742 if (PL_localizing == 1)
7766f137 1743 SAVESPTR(PL_last_in_gv);
748a9306 1744 }
3280af22
NIS
1745 else if (SvOK(sv) && GvIO(PL_last_in_gv))
1746 IoLINES(GvIOp(PL_last_in_gv)) = (long)SvIV(sv);
79072805
LW
1747 break;
1748 case '^':
3280af22 1749 Safefree(IoTOP_NAME(GvIOp(PL_defoutgv)));
2d8e6c8d 1750 IoTOP_NAME(GvIOp(PL_defoutgv)) = s = savepv(SvPV(sv,len));
3280af22 1751 IoTOP_GV(GvIOp(PL_defoutgv)) = gv_fetchpv(s,TRUE, SVt_PVIO);
79072805
LW
1752 break;
1753 case '~':
3280af22 1754 Safefree(IoFMT_NAME(GvIOp(PL_defoutgv)));
2d8e6c8d 1755 IoFMT_NAME(GvIOp(PL_defoutgv)) = s = savepv(SvPV(sv,len));
3280af22 1756 IoFMT_GV(GvIOp(PL_defoutgv)) = gv_fetchpv(s,TRUE, SVt_PVIO);
79072805
LW
1757 break;
1758 case '=':
3280af22 1759 IoPAGE_LEN(GvIOp(PL_defoutgv)) = (long)(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv));
79072805
LW
1760 break;
1761 case '-':
3280af22
NIS
1762 IoLINES_LEFT(GvIOp(PL_defoutgv)) = (long)(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv));
1763 if (IoLINES_LEFT(GvIOp(PL_defoutgv)) < 0L)
1764 IoLINES_LEFT(GvIOp(PL_defoutgv)) = 0L;
79072805
LW
1765 break;
1766 case '%':
3280af22 1767 IoPAGE(GvIOp(PL_defoutgv)) = (long)(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv));
79072805
LW
1768 break;
1769 case '|':
4b65379b 1770 {
3280af22 1771 IO *io = GvIOp(PL_defoutgv);
4b65379b
CS
1772 if ((SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv)) == 0)
1773 IoFLAGS(io) &= ~IOf_FLUSH;
1774 else {
1775 if (!(IoFLAGS(io) & IOf_FLUSH)) {
1776 PerlIO *ofp = IoOFP(io);
1777 if (ofp)
1778 (void)PerlIO_flush(ofp);
1779 IoFLAGS(io) |= IOf_FLUSH;
1780 }
1781 }
79072805
LW
1782 }
1783 break;
1784 case '*':
463ee0b2 1785 i = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
3280af22 1786 PL_multiline = (i != 0);
79072805
LW
1787 break;
1788 case '/':
3280af22
NIS
1789 SvREFCNT_dec(PL_nrs);
1790 PL_nrs = newSVsv(sv);
1791 SvREFCNT_dec(PL_rs);
1792 PL_rs = SvREFCNT_inc(PL_nrs);
79072805
LW
1793 break;
1794 case '\\':
3280af22
NIS
1795 if (PL_ors)
1796 Safefree(PL_ors);
009c130f
GS
1797 if (SvOK(sv) || SvGMAGICAL(sv)) {
1798 s = SvPV(sv,PL_orslen);
1799 PL_ors = savepvn(s,PL_orslen);
1800 }
e3c19b7b 1801 else {
3280af22
NIS
1802 PL_ors = Nullch;
1803 PL_orslen = 0;
e3c19b7b 1804 }
79072805
LW
1805 break;
1806 case ',':
3280af22
NIS
1807 if (PL_ofs)
1808 Safefree(PL_ofs);
1809 PL_ofs = savepv(SvPV(sv, PL_ofslen));
79072805
LW
1810 break;
1811 case '#':
3280af22
NIS
1812 if (PL_ofmt)
1813 Safefree(PL_ofmt);
2d8e6c8d 1814 PL_ofmt = savepv(SvPV(sv,len));
79072805
LW
1815 break;
1816 case '[':
3280af22 1817 PL_compiling.cop_arybase = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
79072805
LW
1818 break;
1819 case '?':
ff0cee69 1820#ifdef COMPLEX_STATUS
6b88bc9c
GS
1821 if (PL_localizing == 2) {
1822 PL_statusvalue = LvTARGOFF(sv);
1823 PL_statusvalue_vms = LvTARGLEN(sv);
ff0cee69
PP
1824 }
1825 else
1826#endif
1827#ifdef VMSISH_STATUS
1828 if (VMSISH_STATUS)
1829 STATUS_NATIVE_SET((U32)(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv)));
1830 else
1831#endif
1832 STATUS_POSIX_SET(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv));
79072805
LW
1833 break;
1834 case '!':
78987ded 1835 SETERRNO(SvIOK(sv) ? SvIVX(sv) : SvOK(sv) ? sv_2iv(sv) : 0,
f86702cc 1836 (SvIV(sv) == EVMSERR) ? 4 : vaxc$errno);
79072805
LW
1837 break;
1838 case '<':
3280af22
NIS
1839 PL_uid = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
1840 if (PL_delaymagic) {
1841 PL_delaymagic |= DM_RUID;
79072805
LW
1842 break; /* don't do magic till later */
1843 }
1844#ifdef HAS_SETRUID
b28d0864 1845 (void)setruid((Uid_t)PL_uid);
79072805
LW
1846#else
1847#ifdef HAS_SETREUID
3280af22 1848 (void)setreuid((Uid_t)PL_uid, (Uid_t)-1);
748a9306 1849#else
85e6fe83 1850#ifdef HAS_SETRESUID
b28d0864 1851 (void)setresuid((Uid_t)PL_uid, (Uid_t)-1, (Uid_t)-1);
79072805 1852#else
b28d0864
NIS
1853 if (PL_uid == PL_euid) /* special case $< = $> */
1854 (void)PerlProc_setuid(PL_uid);
a0d0e21e 1855 else {
d8eceb89 1856 PL_uid = PerlProc_getuid();
cea2e8a9 1857 Perl_croak(aTHX_ "setruid() not implemented");
a0d0e21e 1858 }
79072805
LW
1859#endif
1860#endif
85e6fe83 1861#endif
d8eceb89 1862 PL_uid = PerlProc_getuid();
3280af22 1863 PL_tainting |= (PL_uid && (PL_euid != PL_uid || PL_egid != PL_gid));
79072805
LW
1864 break;
1865 case '>':
3280af22
NIS
1866 PL_euid = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
1867 if (PL_delaymagic) {
1868 PL_delaymagic |= DM_EUID;
79072805
LW
1869 break; /* don't do magic till later */
1870 }
1871#ifdef HAS_SETEUID
3280af22 1872 (void)seteuid((Uid_t)PL_euid);
79072805
LW
1873#else
1874#ifdef HAS_SETREUID
b28d0864 1875 (void)setreuid((Uid_t)-1, (Uid_t)PL_euid);
85e6fe83
LW
1876#else
1877#ifdef HAS_SETRESUID
6b88bc9c 1878 (void)setresuid((Uid_t)-1, (Uid_t)PL_euid, (Uid_t)-1);
79072805 1879#else
b28d0864
NIS
1880 if (PL_euid == PL_uid) /* special case $> = $< */
1881 PerlProc_setuid(PL_euid);
a0d0e21e 1882 else {
e8ee3774 1883 PL_euid = PerlProc_geteuid();
cea2e8a9 1884 Perl_croak(aTHX_ "seteuid() not implemented");
a0d0e21e 1885 }
79072805
LW
1886#endif
1887#endif
85e6fe83 1888#endif
d8eceb89 1889 PL_euid = PerlProc_geteuid();
3280af22 1890 PL_tainting |= (PL_uid && (PL_euid != PL_uid || PL_egid != PL_gid));
79072805
LW
1891 break;
1892 case '(':
3280af22
NIS
1893 PL_gid = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
1894 if (PL_delaymagic) {
1895 PL_delaymagic |= DM_RGID;
79072805
LW
1896 break; /* don't do magic till later */
1897 }
1898#ifdef HAS_SETRGID
b28d0864 1899 (void)setrgid((Gid_t)PL_gid);
79072805
LW
1900#else
1901#ifdef HAS_SETREGID
3280af22 1902 (void)setregid((Gid_t)PL_gid, (Gid_t)-1);
85e6fe83
LW
1903#else
1904#ifdef HAS_SETRESGID
b28d0864 1905 (void)setresgid((Gid_t)PL_gid, (Gid_t)-1, (Gid_t) 1);
79072805 1906#else
b28d0864
NIS
1907 if (PL_gid == PL_egid) /* special case $( = $) */
1908 (void)PerlProc_setgid(PL_gid);
748a9306 1909 else {
d8eceb89 1910 PL_gid = PerlProc_getgid();
cea2e8a9 1911 Perl_croak(aTHX_ "setrgid() not implemented");
748a9306 1912 }
79072805
LW
1913#endif
1914#endif
85e6fe83 1915#endif
d8eceb89 1916 PL_gid = PerlProc_getgid();
3280af22 1917 PL_tainting |= (PL_uid && (PL_euid != PL_uid || PL_egid != PL_gid));
79072805
LW
1918 break;
1919 case ')':
5cd24f17
PP
1920#ifdef HAS_SETGROUPS
1921 {
2d8e6c8d 1922 char *p = SvPV(sv, len);
5cd24f17
PP
1923 Groups_t gary[NGROUPS];
1924
5cd24f17
PP
1925 while (isSPACE(*p))
1926 ++p;
2d4389e4 1927 PL_egid = Atol(p);
5cd24f17
PP
1928 for (i = 0; i < NGROUPS; ++i) {
1929 while (*p && !isSPACE(*p))
1930 ++p;
1931 while (isSPACE(*p))
1932 ++p;
1933 if (!*p)
1934 break;
2d4389e4 1935 gary[i] = Atol(p);
5cd24f17 1936 }
8cc95fdb
PP
1937 if (i)
1938 (void)setgroups(i, gary);
5cd24f17
PP
1939 }
1940#else /* HAS_SETGROUPS */
b28d0864 1941 PL_egid = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
5cd24f17 1942#endif /* HAS_SETGROUPS */
3280af22
NIS
1943 if (PL_delaymagic) {
1944 PL_delaymagic |= DM_EGID;
79072805
LW
1945 break; /* don't do magic till later */
1946 }
1947#ifdef HAS_SETEGID
3280af22 1948 (void)setegid((Gid_t)PL_egid);
79072805
LW
1949#else
1950#ifdef HAS_SETREGID
b28d0864 1951 (void)setregid((Gid_t)-1, (Gid_t)PL_egid);
85e6fe83
LW
1952#else
1953#ifdef HAS_SETRESGID
b28d0864 1954 (void)setresgid((Gid_t)-1, (Gid_t)PL_egid, (Gid_t)-1);
79072805 1955#else
b28d0864
NIS
1956 if (PL_egid == PL_gid) /* special case $) = $( */
1957 (void)PerlProc_setgid(PL_egid);
748a9306 1958 else {
d8eceb89 1959 PL_egid = PerlProc_getegid();
cea2e8a9 1960 Perl_croak(aTHX_ "setegid() not implemented");
748a9306 1961 }
79072805
LW
1962#endif
1963#endif
85e6fe83 1964#endif
d8eceb89 1965 PL_egid = PerlProc_getegid();
3280af22 1966 PL_tainting |= (PL_uid && (PL_euid != PL_uid || PL_egid != PL_gid));
79072805
LW
1967 break;
1968 case ':':
2d8e6c8d 1969 PL_chopset = SvPV_force(sv,len);
79072805 1970 break;
cd39f2b6 1971#ifndef MACOS_TRADITIONAL
79072805 1972 case '0':
3280af22
NIS
1973 if (!PL_origalen) {
1974 s = PL_origargv[0];
79072805
LW
1975 s += strlen(s);
1976 /* See if all the arguments are contiguous in memory */
3280af22
NIS
1977 for (i = 1; i < PL_origargc; i++) {
1978 if (PL_origargv[i] == s + 1
fb73857a 1979#ifdef OS2
6b88bc9c 1980 || PL_origargv[i] == s + 2
fb73857a
PP
1981#endif
1982 )
379c4362
GS
1983 {
1984 ++s;
1985 s += strlen(s); /* this one is ok too */
1986 }
fb73857a
PP
1987 else
1988 break;
79072805 1989 }
bbce6d69 1990 /* can grab env area too? */
3280af22 1991 if (PL_origenviron && (PL_origenviron[0] == s + 1
fb73857a 1992#ifdef OS2
6b88bc9c 1993 || (PL_origenviron[0] == s + 9 && (s += 8))
fb73857a
PP
1994#endif
1995 )) {
66b1d557 1996 my_setenv("NoNe SuCh", Nullch);
79072805 1997 /* force copy of environment */
3280af22 1998 for (i = 0; PL_origenviron[i]; i++)
379c4362
GS
1999 if (PL_origenviron[i] == s + 1) {
2000 ++s;
2001 s += strlen(s);
2002 }
fb73857a
PP
2003 else
2004 break;
79072805 2005 }
3280af22 2006 PL_origalen = s - PL_origargv[0];
79072805 2007 }
a0d0e21e 2008 s = SvPV_force(sv,len);
8990e307 2009 i = len;
3280af22
NIS
2010 if (i >= PL_origalen) {
2011 i = PL_origalen;
fb73857a
PP
2012 /* don't allow system to limit $0 seen by script */
2013 /* SvCUR_set(sv, i); *SvEND(sv) = '\0'; */
3280af22
NIS
2014 Copy(s, PL_origargv[0], i, char);
2015 s = PL_origargv[0]+i;
fb73857a 2016 *s = '\0';
79072805
LW
2017 }
2018 else {
3280af22
NIS
2019 Copy(s, PL_origargv[0], i, char);
2020 s = PL_origargv[0]+i;
79072805 2021 *s++ = '\0';
3280af22 2022 while (++i < PL_origalen)
8990e307 2023 *s++ = ' ';
3280af22
NIS
2024 s = PL_origargv[0]+i;
2025 for (i = 1; i < PL_origargc; i++)
2026 PL_origargv[i] = Nullch;
79072805
LW
2027 }
2028 break;
cd39f2b6 2029#endif
a863c7d1
MB
2030#ifdef USE_THREADS
2031 case '@':
38a03e6e 2032 sv_setsv(thr->errsv, sv);
a863c7d1
MB
2033 break;
2034#endif /* USE_THREADS */
79072805
LW
2035 }
2036 return 0;
2037}
2038
f93b4edd
MB
2039#ifdef USE_THREADS
2040int
864dbfa3 2041Perl_magic_mutexfree(pTHX_ SV *sv, MAGIC *mg)
f93b4edd
MB
2042{
2043 dTHR;
b900a521
JH
2044 DEBUG_S(PerlIO_printf(Perl_debug_log,
2045 "0x%"UVxf": magic_mutexfree 0x%"UVxf"\n",
2046 PTR2UV(thr), PTR2UV(sv));)
f93b4edd 2047 if (MgOWNER(mg))
cea2e8a9 2048 Perl_croak(aTHX_ "panic: magic_mutexfree");
f93b4edd
MB
2049 MUTEX_DESTROY(MgMUTEXP(mg));
2050 COND_DESTROY(MgCONDP(mg));
2051 return 0;
2052}
2053#endif /* USE_THREADS */
2054
79072805 2055I32
864dbfa3 2056Perl_whichsig(pTHX_ char *sig)
79072805
LW
2057{
2058 register char **sigv;
2059
22c35a8c 2060 for (sigv = PL_sig_name+1; *sigv; sigv++)
79072805 2061 if (strEQ(sig,*sigv))
22c35a8c 2062 return PL_sig_num[sigv - PL_sig_name];
79072805
LW
2063#ifdef SIGCLD
2064 if (strEQ(sig,"CHLD"))
2065 return SIGCLD;
2066#endif
2067#ifdef SIGCHLD
2068 if (strEQ(sig,"CLD"))
2069 return SIGCHLD;
2070#endif
2071 return 0;
2072}
2073
84902520
TB
2074static SV* sig_sv;
2075
ecfc5424 2076Signal_t
cea2e8a9 2077Perl_sighandler(int sig)
79072805 2078{
cea2e8a9 2079 dTHX;
79072805 2080 dSP;
00d579c5 2081 GV *gv = Nullgv;
a0d0e21e 2082 HV *st;
3280af22 2083 SV *sv, *tSv = PL_Sv;
00d579c5 2084 CV *cv = Nullcv;
533c011a 2085 OP *myop = PL_op;
84902520 2086 U32 flags = 0;
155aba94 2087 I32 o_save_i = PL_savestack_ix;
3280af22 2088 XPV *tXpv = PL_Xpv;
84902520 2089
3280af22 2090 if (PL_savestack_ix + 15 <= PL_savestack_max)
84902520 2091 flags |= 1;
3280af22 2092 if (PL_markstack_ptr < PL_markstack_max - 2)
84902520 2093 flags |= 4;
3280af22 2094 if (PL_retstack_ix < PL_retstack_max - 2)
84902520 2095 flags |= 8;
3280af22 2096 if (PL_scopestack_ix < PL_scopestack_max - 3)
84902520
TB
2097 flags |= 16;
2098
22c35a8c 2099 if (!PL_psig_ptr[sig])
cea2e8a9 2100 Perl_die(aTHX_ "Signal SIG%s received, but no signal handler set.\n",
22c35a8c 2101 PL_sig_name[sig]);
ff0cee69 2102
84902520
TB
2103 /* Max number of items pushed there is 3*n or 4. We cannot fix
2104 infinity, so we fix 4 (in fact 5): */
2105 if (flags & 1) {
3280af22
NIS
2106 PL_savestack_ix += 5; /* Protect save in progress. */
2107 o_save_i = PL_savestack_ix;
c76ac1ee 2108 SAVEDESTRUCTOR_X(unwind_handler_stack, (void*)&flags);
84902520
TB
2109 }
2110 if (flags & 4)
3280af22 2111 PL_markstack_ptr++; /* Protect mark. */
84902520 2112 if (flags & 8) {
3280af22
NIS
2113 PL_retstack_ix++;
2114 PL_retstack[PL_retstack_ix] = NULL;
84902520
TB
2115 }
2116 if (flags & 16)
3280af22 2117 PL_scopestack_ix += 1;
84902520 2118 /* sv_2cv is too complicated, try a simpler variant first: */
22c35a8c 2119 if (!SvROK(PL_psig_ptr[sig]) || !(cv = (CV*)SvRV(PL_psig_ptr[sig]))
84902520 2120 || SvTYPE(cv) != SVt_PVCV)
22c35a8c 2121 cv = sv_2cv(PL_psig_ptr[sig],&st,&gv,TRUE);
84902520 2122
a0d0e21e 2123 if (!cv || !CvROOT(cv)) {
599cee73 2124 if (ckWARN(WARN_SIGNAL))
cea2e8a9 2125 Perl_warner(aTHX_ WARN_SIGNAL, "SIG%s handler \"%s\" not defined.\n",
22c35a8c 2126 PL_sig_name[sig], (gv ? GvENAME(gv)
00d579c5
GS
2127 : ((cv && CvGV(cv))
2128 ? GvENAME(CvGV(cv))
2129 : "__ANON__")));
2130 goto cleanup;
79072805
LW
2131 }
2132
22c35a8c
GS
2133 if(PL_psig_name[sig]) {
2134 sv = SvREFCNT_inc(PL_psig_name[sig]);
84902520
TB
2135 flags |= 64;
2136 sig_sv = sv;
2137 } else {
ff0cee69 2138 sv = sv_newmortal();
22c35a8c 2139 sv_setpv(sv,PL_sig_name[sig]);
88e89b8a 2140 }
e336de0d 2141
e788e7d3 2142 PUSHSTACKi(PERLSI_SIGNAL);
924508f0 2143 PUSHMARK(SP);
79072805 2144 PUSHs(sv);
79072805 2145 PUTBACK;
a0d0e21e 2146
864dbfa3 2147 call_sv((SV*)cv, G_DISCARD);
79072805 2148
d3acc0f7 2149 POPSTACK;
00d579c5 2150cleanup:
84902520 2151 if (flags & 1)
3280af22 2152 PL_savestack_ix -= 8; /* Unprotect save in progress. */
84902520 2153 if (flags & 4)
3280af22 2154 PL_markstack_ptr--;
84902520 2155 if (flags & 8)
3280af22 2156 PL_retstack_ix--;
84902520 2157 if (flags & 16)
3280af22 2158 PL_scopestack_ix -= 1;
84902520
TB
2159 if (flags & 64)
2160 SvREFCNT_dec(sv);
533c011a 2161 PL_op = myop; /* Apparently not needed... */
84902520 2162
3280af22
NIS
2163 PL_Sv = tSv; /* Restore global temporaries. */
2164 PL_Xpv = tXpv;
79072805
LW
2165 return;
2166}
4e35701f
NIS
2167
2168
51371543 2169#ifdef PERL_OBJECT
51371543
GS
2170#include "XSUB.h"
2171#endif
2172
2173static void
2174restore_magic(pTHXo_ void *p)
2175{
2176 dTHR;
48944bdf 2177 MGS* mgs = SSPTR(PTR2IV(p), MGS*);
51371543
GS
2178 SV* sv = mgs->mgs_sv;
2179
2180 if (!sv)
2181 return;
2182
2183 if (SvTYPE(sv) >= SVt_PVMG && SvMAGIC(sv))
2184 {
2185 if (mgs->mgs_flags)
2186 SvFLAGS(sv) |= mgs->mgs_flags;
2187 else
2188 mg_magical(sv);
2189 if (SvGMAGICAL(sv))
2190 SvFLAGS(sv) &= ~(SVf_IOK|SVf_NOK|SVf_POK);
2191 }
2192
2193 mgs->mgs_sv = NULL; /* mark the MGS structure as restored */
2194
2195 /* If we're still on top of the stack, pop us off. (That condition
2196 * will be satisfied if restore_magic was called explicitly, but *not*
2197 * if it's being called via leave_scope.)
2198 * The reason for doing this is that otherwise, things like sv_2cv()
2199 * may leave alloc gunk on the savestack, and some code
2200 * (e.g. sighandler) doesn't expect that...
2201 */
2202 if (PL_savestack_ix == mgs->mgs_ss_ix)
2203 {
2204 I32 popval = SSPOPINT;
c76ac1ee 2205 assert(popval == SAVEt_DESTRUCTOR_X);
51371543
GS
2206 PL_savestack_ix -= 2;
2207 popval = SSPOPINT;
2208 assert(popval == SAVEt_ALLOC);
2209 popval = SSPOPINT;
2210 PL_savestack_ix -= popval;
2211 }
2212
2213}
2214
2215static void
2216unwind_handler_stack(pTHXo_ void *p)
2217{
2218 dTHR;
2219 U32 flags = *(U32*)p;
2220
2221 if (flags & 1)
2222 PL_savestack_ix -= 5; /* Unprotect save in progress. */
2223 /* cxstack_ix-- Not needed, die already unwound it. */
2224 if (flags & 64)
2225 SvREFCNT_dec(sig_sv);
2226}