| 1 |
root |
1.1 |
/* mg.c |
| 2 |
|
|
* |
| 3 |
|
|
* Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, |
| 4 |
|
|
* 2000, 2001, 2002, 2003, 2004, 2005 by Larry Wall and others |
| 5 |
|
|
* |
| 6 |
|
|
* You may distribute under the terms of either the GNU General Public |
| 7 |
|
|
* License or the Artistic License, as specified in the README file. |
| 8 |
|
|
* |
| 9 |
|
|
*/ |
| 10 |
|
|
|
| 11 |
|
|
/* |
| 12 |
|
|
* "Sam sat on the ground and put his head in his hands. 'I wish I had never |
| 13 |
|
|
* come here, and I don't want to see no more magic,' he said, and fell silent." |
| 14 |
|
|
*/ |
| 15 |
|
|
|
| 16 |
|
|
/* |
| 17 |
|
|
=head1 Magical Functions |
| 18 |
|
|
|
| 19 |
|
|
"Magic" is special data attached to SV structures in order to give them |
| 20 |
|
|
"magical" properties. When any Perl code tries to read from, or assign to, |
| 21 |
|
|
an SV marked as magical, it calls the 'get' or 'set' function associated |
| 22 |
|
|
with that SV's magic. A get is called prior to reading an SV, in order to |
| 23 |
|
|
give it a chance to update its internal value (get on $. writes the line |
| 24 |
|
|
number of the last read filehandle into to the SV's IV slot), while |
| 25 |
|
|
set is called after an SV has been written to, in order to allow it to make |
| 26 |
|
|
use of its changed value (set on $/ copies the SV's new value to the |
| 27 |
|
|
PL_rs global variable). |
| 28 |
|
|
|
| 29 |
|
|
Magic is implemented as a linked list of MAGIC structures attached to the |
| 30 |
|
|
SV. Each MAGIC struct holds the type of the magic, a pointer to an array |
| 31 |
|
|
of functions that implement the get(), set(), length() etc functions, |
| 32 |
|
|
plus space for some flags and pointers. For example, a tied variable has |
| 33 |
|
|
a MAGIC structure that contains a pointer to the object associated with the |
| 34 |
|
|
tie. |
| 35 |
|
|
|
| 36 |
|
|
*/ |
| 37 |
|
|
|
| 38 |
|
|
#include "EXTERN.h" |
| 39 |
|
|
#define PERL_IN_MG_C |
| 40 |
|
|
#include "perl.h" |
| 41 |
|
|
|
| 42 |
|
|
#if defined(HAS_GETGROUPS) || defined(HAS_SETGROUPS) |
| 43 |
|
|
# ifndef NGROUPS |
| 44 |
|
|
# define NGROUPS 32 |
| 45 |
|
|
# endif |
| 46 |
|
|
# ifdef I_GRP |
| 47 |
|
|
# include <grp.h> |
| 48 |
|
|
# endif |
| 49 |
|
|
#endif |
| 50 |
|
|
|
| 51 |
|
|
#ifdef __hpux |
| 52 |
|
|
# include <sys/pstat.h> |
| 53 |
|
|
#endif |
| 54 |
|
|
|
| 55 |
|
|
Signal_t Perl_csighandler(int sig); |
| 56 |
|
|
|
| 57 |
|
|
/* if you only have signal() and it resets on each signal, FAKE_PERSISTENT_SIGNAL_HANDLERS fixes */ |
| 58 |
|
|
#if !defined(HAS_SIGACTION) && defined(VMS) |
| 59 |
|
|
# define FAKE_PERSISTENT_SIGNAL_HANDLERS |
| 60 |
|
|
#endif |
| 61 |
|
|
/* if we're doing kill() with sys$sigprc on VMS, FAKE_DEFAULT_SIGNAL_HANDLERS */ |
| 62 |
|
|
#if defined(KILL_BY_SIGPRC) |
| 63 |
|
|
# define FAKE_DEFAULT_SIGNAL_HANDLERS |
| 64 |
|
|
#endif |
| 65 |
|
|
|
| 66 |
|
|
static void restore_magic(pTHX_ void *p); |
| 67 |
|
|
static void unwind_handler_stack(pTHX_ void *p); |
| 68 |
|
|
|
| 69 |
|
|
#ifdef __Lynx__ |
| 70 |
|
|
/* Missing protos on LynxOS */ |
| 71 |
|
|
void setruid(uid_t id); |
| 72 |
|
|
void seteuid(uid_t id); |
| 73 |
|
|
void setrgid(uid_t id); |
| 74 |
|
|
void setegid(uid_t id); |
| 75 |
|
|
#endif |
| 76 |
|
|
|
| 77 |
|
|
/* |
| 78 |
|
|
* Use the "DESTRUCTOR" scope cleanup to reinstate magic. |
| 79 |
|
|
*/ |
| 80 |
|
|
|
| 81 |
|
|
struct magic_state { |
| 82 |
|
|
SV* mgs_sv; |
| 83 |
|
|
U32 mgs_flags; |
| 84 |
|
|
I32 mgs_ss_ix; |
| 85 |
|
|
}; |
| 86 |
|
|
/* MGS is typedef'ed to struct magic_state in perl.h */ |
| 87 |
|
|
|
| 88 |
|
|
STATIC void |
| 89 |
|
|
S_save_magic(pTHX_ I32 mgs_ix, SV *sv) |
| 90 |
|
|
{ |
| 91 |
|
|
MGS* mgs; |
| 92 |
|
|
assert(SvMAGICAL(sv)); |
| 93 |
|
|
|
| 94 |
|
|
SAVEDESTRUCTOR_X(restore_magic, INT2PTR(void*, (IV)mgs_ix)); |
| 95 |
|
|
|
| 96 |
|
|
mgs = SSPTR(mgs_ix, MGS*); |
| 97 |
|
|
mgs->mgs_sv = sv; |
| 98 |
|
|
mgs->mgs_flags = SvMAGICAL(sv) | SvREADONLY(sv); |
| 99 |
|
|
mgs->mgs_ss_ix = PL_savestack_ix; /* points after the saved destructor */ |
| 100 |
|
|
|
| 101 |
|
|
SvMAGICAL_off(sv); |
| 102 |
|
|
SvREADONLY_off(sv); |
| 103 |
|
|
SvFLAGS(sv) |= (SvFLAGS(sv) & (SVp_NOK|SVp_POK)) >> PRIVSHIFT; |
| 104 |
|
|
} |
| 105 |
|
|
|
| 106 |
|
|
/* |
| 107 |
|
|
=for apidoc mg_magical |
| 108 |
|
|
|
| 109 |
|
|
Turns on the magical status of an SV. See C<sv_magic>. |
| 110 |
|
|
|
| 111 |
|
|
=cut |
| 112 |
|
|
*/ |
| 113 |
|
|
|
| 114 |
|
|
void |
| 115 |
|
|
Perl_mg_magical(pTHX_ SV *sv) |
| 116 |
|
|
{ |
| 117 |
|
|
MAGIC* mg; |
| 118 |
|
|
for (mg = SvMAGIC(sv); mg; mg = mg->mg_moremagic) { |
| 119 |
|
|
MGVTBL* vtbl = mg->mg_virtual; |
| 120 |
|
|
if (vtbl) { |
| 121 |
|
|
if (vtbl->svt_get && !(mg->mg_flags & MGf_GSKIP)) |
| 122 |
|
|
SvGMAGICAL_on(sv); |
| 123 |
|
|
if (vtbl->svt_set) |
| 124 |
|
|
SvSMAGICAL_on(sv); |
| 125 |
|
|
if (!(SvFLAGS(sv) & (SVs_GMG|SVs_SMG)) || vtbl->svt_clear) |
| 126 |
|
|
SvRMAGICAL_on(sv); |
| 127 |
|
|
} |
| 128 |
|
|
} |
| 129 |
|
|
} |
| 130 |
|
|
|
| 131 |
|
|
/* |
| 132 |
|
|
=for apidoc mg_get |
| 133 |
|
|
|
| 134 |
|
|
Do magic after a value is retrieved from the SV. See C<sv_magic>. |
| 135 |
|
|
|
| 136 |
|
|
=cut |
| 137 |
|
|
*/ |
| 138 |
|
|
|
| 139 |
|
|
int |
| 140 |
|
|
Perl_mg_get(pTHX_ SV *sv) |
| 141 |
|
|
{ |
| 142 |
|
|
int have_new = 0; |
| 143 |
|
|
MAGIC *newmg, *head, *cur, *mg; |
| 144 |
|
|
I32 mgs_ix = SSNEW(sizeof(MGS)); |
| 145 |
|
|
int was_temp = SvTEMP(sv); |
| 146 |
|
|
/* guard against sv having being freed midway by holding a private |
| 147 |
|
|
reference. */ |
| 148 |
|
|
|
| 149 |
|
|
/* sv_2mortal has this side effect of turning on the TEMP flag, which can |
| 150 |
|
|
cause the SV's buffer to get stolen (and maybe other stuff). |
| 151 |
|
|
So restore it. |
| 152 |
|
|
*/ |
| 153 |
|
|
sv_2mortal(SvREFCNT_inc(sv)); |
| 154 |
|
|
if (!was_temp) { |
| 155 |
|
|
SvTEMP_off(sv); |
| 156 |
|
|
} |
| 157 |
|
|
|
| 158 |
|
|
save_magic(mgs_ix, sv); |
| 159 |
|
|
|
| 160 |
|
|
/* We must call svt_get(sv, mg) for each valid entry in the linked |
| 161 |
|
|
list of magic. svt_get() may delete the current entry, add new |
| 162 |
|
|
magic to the head of the list, or upgrade the SV. AMS 20010810 */ |
| 163 |
|
|
|
| 164 |
|
|
newmg = cur = head = mg = SvMAGIC(sv); |
| 165 |
|
|
while (mg) { |
| 166 |
|
|
MGVTBL *vtbl = mg->mg_virtual; |
| 167 |
|
|
|
| 168 |
|
|
if (!(mg->mg_flags & MGf_GSKIP) && vtbl && vtbl->svt_get) { |
| 169 |
|
|
CALL_FPTR(vtbl->svt_get)(aTHX_ sv, mg); |
| 170 |
|
|
|
| 171 |
|
|
/* guard against magic having been deleted - eg FETCH calling |
| 172 |
|
|
* untie */ |
| 173 |
|
|
if (!SvMAGIC(sv)) |
| 174 |
|
|
break; |
| 175 |
|
|
|
| 176 |
|
|
/* Don't restore the flags for this entry if it was deleted. */ |
| 177 |
|
|
if (mg->mg_flags & MGf_GSKIP) |
| 178 |
|
|
(SSPTR(mgs_ix, MGS *))->mgs_flags = 0; |
| 179 |
|
|
} |
| 180 |
|
|
|
| 181 |
|
|
mg = mg->mg_moremagic; |
| 182 |
|
|
|
| 183 |
|
|
if (have_new) { |
| 184 |
|
|
/* Have we finished with the new entries we saw? Start again |
| 185 |
|
|
where we left off (unless there are more new entries). */ |
| 186 |
|
|
if (mg == head) { |
| 187 |
|
|
have_new = 0; |
| 188 |
|
|
mg = cur; |
| 189 |
|
|
head = newmg; |
| 190 |
|
|
} |
| 191 |
|
|
} |
| 192 |
|
|
|
| 193 |
|
|
/* Were any new entries added? */ |
| 194 |
|
|
if (!have_new && (newmg = SvMAGIC(sv)) != head) { |
| 195 |
|
|
have_new = 1; |
| 196 |
|
|
cur = mg; |
| 197 |
|
|
mg = newmg; |
| 198 |
|
|
} |
| 199 |
|
|
} |
| 200 |
|
|
|
| 201 |
|
|
restore_magic(aTHX_ INT2PTR(void *, (IV)mgs_ix)); |
| 202 |
|
|
|
| 203 |
|
|
if (SvREFCNT(sv) == 1) { |
| 204 |
|
|
/* We hold the last reference to this SV, which implies that the |
| 205 |
|
|
SV was deleted as a side effect of the routines we called. */ |
| 206 |
|
|
SvOK_off(sv); |
| 207 |
|
|
} |
| 208 |
|
|
return 0; |
| 209 |
|
|
} |
| 210 |
|
|
|
| 211 |
|
|
/* |
| 212 |
|
|
=for apidoc mg_set |
| 213 |
|
|
|
| 214 |
|
|
Do magic after a value is assigned to the SV. See C<sv_magic>. |
| 215 |
|
|
|
| 216 |
|
|
=cut |
| 217 |
|
|
*/ |
| 218 |
|
|
|
| 219 |
|
|
int |
| 220 |
|
|
Perl_mg_set(pTHX_ SV *sv) |
| 221 |
|
|
{ |
| 222 |
|
|
I32 mgs_ix; |
| 223 |
|
|
MAGIC* mg; |
| 224 |
|
|
MAGIC* nextmg; |
| 225 |
|
|
|
| 226 |
|
|
mgs_ix = SSNEW(sizeof(MGS)); |
| 227 |
|
|
save_magic(mgs_ix, sv); |
| 228 |
|
|
|
| 229 |
|
|
for (mg = SvMAGIC(sv); mg; mg = nextmg) { |
| 230 |
|
|
MGVTBL* vtbl = mg->mg_virtual; |
| 231 |
|
|
nextmg = mg->mg_moremagic; /* it may delete itself */ |
| 232 |
|
|
if (mg->mg_flags & MGf_GSKIP) { |
| 233 |
|
|
mg->mg_flags &= ~MGf_GSKIP; /* setting requires another read */ |
| 234 |
|
|
(SSPTR(mgs_ix, MGS*))->mgs_flags = 0; |
| 235 |
|
|
} |
| 236 |
|
|
if (vtbl && vtbl->svt_set) |
| 237 |
|
|
CALL_FPTR(vtbl->svt_set)(aTHX_ sv, mg); |
| 238 |
|
|
} |
| 239 |
|
|
|
| 240 |
|
|
restore_magic(aTHX_ INT2PTR(void*, (IV)mgs_ix)); |
| 241 |
|
|
return 0; |
| 242 |
|
|
} |
| 243 |
|
|
|
| 244 |
|
|
/* |
| 245 |
|
|
=for apidoc mg_length |
| 246 |
|
|
|
| 247 |
|
|
Report on the SV's length. See C<sv_magic>. |
| 248 |
|
|
|
| 249 |
|
|
=cut |
| 250 |
|
|
*/ |
| 251 |
|
|
|
| 252 |
|
|
U32 |
| 253 |
|
|
Perl_mg_length(pTHX_ SV *sv) |
| 254 |
|
|
{ |
| 255 |
|
|
MAGIC* mg; |
| 256 |
|
|
STRLEN len; |
| 257 |
|
|
|
| 258 |
|
|
for (mg = SvMAGIC(sv); mg; mg = mg->mg_moremagic) { |
| 259 |
|
|
MGVTBL* vtbl = mg->mg_virtual; |
| 260 |
|
|
if (vtbl && vtbl->svt_len) { |
| 261 |
|
|
I32 mgs_ix; |
| 262 |
|
|
|
| 263 |
|
|
mgs_ix = SSNEW(sizeof(MGS)); |
| 264 |
|
|
save_magic(mgs_ix, sv); |
| 265 |
|
|
/* omit MGf_GSKIP -- not changed here */ |
| 266 |
|
|
len = CALL_FPTR(vtbl->svt_len)(aTHX_ sv, mg); |
| 267 |
|
|
restore_magic(aTHX_ INT2PTR(void*, (IV)mgs_ix)); |
| 268 |
|
|
return len; |
| 269 |
|
|
} |
| 270 |
|
|
} |
| 271 |
|
|
|
| 272 |
|
|
if (DO_UTF8(sv)) |
| 273 |
|
|
{ |
| 274 |
|
|
U8 *s = (U8*)SvPV(sv, len); |
| 275 |
|
|
len = Perl_utf8_length(aTHX_ s, s + len); |
| 276 |
|
|
} |
| 277 |
|
|
else |
| 278 |
|
|
(void)SvPV(sv, len); |
| 279 |
|
|
return len; |
| 280 |
|
|
} |
| 281 |
|
|
|
| 282 |
|
|
I32 |
| 283 |
|
|
Perl_mg_size(pTHX_ SV *sv) |
| 284 |
|
|
{ |
| 285 |
|
|
MAGIC* mg; |
| 286 |
|
|
I32 len; |
| 287 |
|
|
|
| 288 |
|
|
for (mg = SvMAGIC(sv); mg; mg = mg->mg_moremagic) { |
| 289 |
|
|
MGVTBL* vtbl = mg->mg_virtual; |
| 290 |
|
|
if (vtbl && vtbl->svt_len) { |
| 291 |
|
|
I32 mgs_ix; |
| 292 |
|
|
|
| 293 |
|
|
mgs_ix = SSNEW(sizeof(MGS)); |
| 294 |
|
|
save_magic(mgs_ix, sv); |
| 295 |
|
|
/* omit MGf_GSKIP -- not changed here */ |
| 296 |
|
|
len = CALL_FPTR(vtbl->svt_len)(aTHX_ sv, mg); |
| 297 |
|
|
restore_magic(aTHX_ INT2PTR(void*, (IV)mgs_ix)); |
| 298 |
|
|
return len; |
| 299 |
|
|
} |
| 300 |
|
|
} |
| 301 |
|
|
|
| 302 |
|
|
switch(SvTYPE(sv)) { |
| 303 |
|
|
case SVt_PVAV: |
| 304 |
|
|
len = AvFILLp((AV *) sv); /* Fallback to non-tied array */ |
| 305 |
|
|
return len; |
| 306 |
|
|
case SVt_PVHV: |
| 307 |
|
|
/* FIXME */ |
| 308 |
|
|
default: |
| 309 |
|
|
Perl_croak(aTHX_ "Size magic not implemented"); |
| 310 |
|
|
break; |
| 311 |
|
|
} |
| 312 |
|
|
return 0; |
| 313 |
|
|
} |
| 314 |
|
|
|
| 315 |
|
|
/* |
| 316 |
|
|
=for apidoc mg_clear |
| 317 |
|
|
|
| 318 |
|
|
Clear something magical that the SV represents. See C<sv_magic>. |
| 319 |
|
|
|
| 320 |
|
|
=cut |
| 321 |
|
|
*/ |
| 322 |
|
|
|
| 323 |
|
|
int |
| 324 |
|
|
Perl_mg_clear(pTHX_ SV *sv) |
| 325 |
|
|
{ |
| 326 |
|
|
I32 mgs_ix; |
| 327 |
|
|
MAGIC* mg; |
| 328 |
|
|
|
| 329 |
|
|
mgs_ix = SSNEW(sizeof(MGS)); |
| 330 |
|
|
save_magic(mgs_ix, sv); |
| 331 |
|
|
|
| 332 |
|
|
for (mg = SvMAGIC(sv); mg; mg = mg->mg_moremagic) { |
| 333 |
|
|
MGVTBL* vtbl = mg->mg_virtual; |
| 334 |
|
|
/* omit GSKIP -- never set here */ |
| 335 |
|
|
|
| 336 |
|
|
if (vtbl && vtbl->svt_clear) |
| 337 |
|
|
CALL_FPTR(vtbl->svt_clear)(aTHX_ sv, mg); |
| 338 |
|
|
} |
| 339 |
|
|
|
| 340 |
|
|
restore_magic(aTHX_ INT2PTR(void*, (IV)mgs_ix)); |
| 341 |
|
|
return 0; |
| 342 |
|
|
} |
| 343 |
|
|
|
| 344 |
|
|
/* |
| 345 |
|
|
=for apidoc mg_find |
| 346 |
|
|
|
| 347 |
|
|
Finds the magic pointer for type matching the SV. See C<sv_magic>. |
| 348 |
|
|
|
| 349 |
|
|
=cut |
| 350 |
|
|
*/ |
| 351 |
|
|
|
| 352 |
|
|
MAGIC* |
| 353 |
|
|
Perl_mg_find(pTHX_ SV *sv, int type) |
| 354 |
|
|
{ |
| 355 |
|
|
MAGIC* mg; |
| 356 |
|
|
if (!sv) |
| 357 |
|
|
return 0; |
| 358 |
|
|
for (mg = SvMAGIC(sv); mg; mg = mg->mg_moremagic) { |
| 359 |
|
|
if (mg->mg_type == type) |
| 360 |
|
|
return mg; |
| 361 |
|
|
} |
| 362 |
|
|
return 0; |
| 363 |
|
|
} |
| 364 |
|
|
|
| 365 |
|
|
/* |
| 366 |
|
|
=for apidoc mg_copy |
| 367 |
|
|
|
| 368 |
|
|
Copies the magic from one SV to another. See C<sv_magic>. |
| 369 |
|
|
|
| 370 |
|
|
=cut |
| 371 |
|
|
*/ |
| 372 |
|
|
|
| 373 |
|
|
int |
| 374 |
|
|
Perl_mg_copy(pTHX_ SV *sv, SV *nsv, const char *key, I32 klen) |
| 375 |
|
|
{ |
| 376 |
|
|
int count = 0; |
| 377 |
|
|
MAGIC* mg; |
| 378 |
|
|
for (mg = SvMAGIC(sv); mg; mg = mg->mg_moremagic) { |
| 379 |
|
|
MGVTBL* vtbl = mg->mg_virtual; |
| 380 |
|
|
if ((mg->mg_flags & MGf_COPY) && vtbl->svt_copy){ |
| 381 |
|
|
count += CALL_FPTR(vtbl->svt_copy)(aTHX_ sv, mg, nsv, key, klen); |
| 382 |
|
|
} |
| 383 |
|
|
else if (isUPPER(mg->mg_type)) { |
| 384 |
|
|
sv_magic(nsv, |
| 385 |
|
|
mg->mg_type == PERL_MAGIC_tied ? SvTIED_obj(sv, mg) : |
| 386 |
|
|
(mg->mg_type == PERL_MAGIC_regdata && mg->mg_obj) |
| 387 |
|
|
? sv : mg->mg_obj, |
| 388 |
|
|
toLOWER(mg->mg_type), key, klen); |
| 389 |
|
|
count++; |
| 390 |
|
|
} |
| 391 |
|
|
} |
| 392 |
|
|
return count; |
| 393 |
|
|
} |
| 394 |
|
|
|
| 395 |
|
|
/* |
| 396 |
|
|
=for apidoc mg_free |
| 397 |
|
|
|
| 398 |
|
|
Free any magic storage used by the SV. See C<sv_magic>. |
| 399 |
|
|
|
| 400 |
|
|
=cut |
| 401 |
|
|
*/ |
| 402 |
|
|
|
| 403 |
|
|
int |
| 404 |
|
|
Perl_mg_free(pTHX_ SV *sv) |
| 405 |
|
|
{ |
| 406 |
|
|
MAGIC* mg; |
| 407 |
|
|
MAGIC* moremagic; |
| 408 |
|
|
for (mg = SvMAGIC(sv); mg; mg = moremagic) { |
| 409 |
|
|
MGVTBL* vtbl = mg->mg_virtual; |
| 410 |
|
|
moremagic = mg->mg_moremagic; |
| 411 |
|
|
if (vtbl && vtbl->svt_free) |
| 412 |
|
|
CALL_FPTR(vtbl->svt_free)(aTHX_ sv, mg); |
| 413 |
|
|
if (mg->mg_ptr && mg->mg_type != PERL_MAGIC_regex_global) { |
| 414 |
|
|
if (mg->mg_len > 0 || mg->mg_type == PERL_MAGIC_utf8) |
| 415 |
|
|
Safefree(mg->mg_ptr); |
| 416 |
|
|
else if (mg->mg_len == HEf_SVKEY) |
| 417 |
|
|
SvREFCNT_dec((SV*)mg->mg_ptr); |
| 418 |
|
|
} |
| 419 |
|
|
if (mg->mg_flags & MGf_REFCOUNTED) |
| 420 |
|
|
SvREFCNT_dec(mg->mg_obj); |
| 421 |
|
|
Safefree(mg); |
| 422 |
|
|
} |
| 423 |
|
|
SvMAGIC(sv) = 0; |
| 424 |
|
|
return 0; |
| 425 |
|
|
} |
| 426 |
|
|
|
| 427 |
|
|
#include <signal.h> |
| 428 |
|
|
|
| 429 |
|
|
U32 |
| 430 |
|
|
Perl_magic_regdata_cnt(pTHX_ SV *sv, MAGIC *mg) |
| 431 |
|
|
{ |
| 432 |
|
|
register REGEXP *rx; |
| 433 |
|
|
|
| 434 |
|
|
if (PL_curpm && (rx = PM_GETRE(PL_curpm))) { |
| 435 |
|
|
if (mg->mg_obj) /* @+ */ |
| 436 |
|
|
return rx->nparens; |
| 437 |
|
|
else /* @- */ |
| 438 |
|
|
return rx->lastparen; |
| 439 |
|
|
} |
| 440 |
|
|
|
| 441 |
|
|
return (U32)-1; |
| 442 |
|
|
} |
| 443 |
|
|
|
| 444 |
|
|
int |
| 445 |
|
|
Perl_magic_regdatum_get(pTHX_ SV *sv, MAGIC *mg) |
| 446 |
|
|
{ |
| 447 |
|
|
register I32 paren; |
| 448 |
|
|
register I32 s; |
| 449 |
|
|
register I32 i; |
| 450 |
|
|
register REGEXP *rx; |
| 451 |
|
|
I32 t; |
| 452 |
|
|
|
| 453 |
|
|
if (PL_curpm && (rx = PM_GETRE(PL_curpm))) { |
| 454 |
|
|
paren = mg->mg_len; |
| 455 |
|
|
if (paren < 0) |
| 456 |
|
|
return 0; |
| 457 |
|
|
if (paren <= (I32)rx->nparens && |
| 458 |
|
|
(s = rx->startp[paren]) != -1 && |
| 459 |
|
|
(t = rx->endp[paren]) != -1) |
| 460 |
|
|
{ |
| 461 |
|
|
if (mg->mg_obj) /* @+ */ |
| 462 |
|
|
i = t; |
| 463 |
|
|
else /* @- */ |
| 464 |
|
|
i = s; |
| 465 |
|
|
|
| 466 |
|
|
if (i > 0 && RX_MATCH_UTF8(rx)) { |
| 467 |
|
|
char *b = rx->subbeg; |
| 468 |
|
|
if (b) |
| 469 |
|
|
i = Perl_utf8_length(aTHX_ (U8*)b, (U8*)(b+i)); |
| 470 |
|
|
} |
| 471 |
|
|
|
| 472 |
|
|
sv_setiv(sv, i); |
| 473 |
|
|
} |
| 474 |
|
|
} |
| 475 |
|
|
return 0; |
| 476 |
|
|
} |
| 477 |
|
|
|
| 478 |
|
|
int |
| 479 |
|
|
Perl_magic_regdatum_set(pTHX_ SV *sv, MAGIC *mg) |
| 480 |
|
|
{ |
| 481 |
|
|
Perl_croak(aTHX_ PL_no_modify); |
| 482 |
|
|
/* NOT REACHED */ |
| 483 |
|
|
return 0; |
| 484 |
|
|
} |
| 485 |
|
|
|
| 486 |
|
|
U32 |
| 487 |
|
|
Perl_magic_len(pTHX_ SV *sv, MAGIC *mg) |
| 488 |
|
|
{ |
| 489 |
|
|
register I32 paren; |
| 490 |
|
|
register I32 i; |
| 491 |
|
|
register REGEXP *rx; |
| 492 |
|
|
I32 s1, t1; |
| 493 |
|
|
|
| 494 |
|
|
switch (*mg->mg_ptr) { |
| 495 |
|
|
case '1': case '2': case '3': case '4': |
| 496 |
|
|
case '5': case '6': case '7': case '8': case '9': case '&': |
| 497 |
|
|
if (PL_curpm && (rx = PM_GETRE(PL_curpm))) { |
| 498 |
|
|
|
| 499 |
|
|
paren = atoi(mg->mg_ptr); /* $& is in [0] */ |
| 500 |
|
|
getparen: |
| 501 |
|
|
if (paren <= (I32)rx->nparens && |
| 502 |
|
|
(s1 = rx->startp[paren]) != -1 && |
| 503 |
|
|
(t1 = rx->endp[paren]) != -1) |
| 504 |
|
|
{ |
| 505 |
|
|
i = t1 - s1; |
| 506 |
|
|
getlen: |
| 507 |
|
|
if (i > 0 && RX_MATCH_UTF8(rx)) { |
| 508 |
|
|
char *s = rx->subbeg + s1; |
| 509 |
|
|
char *send = rx->subbeg + t1; |
| 510 |
|
|
|
| 511 |
|
|
i = t1 - s1; |
| 512 |
|
|
if (is_utf8_string((U8*)s, i)) |
| 513 |
|
|
i = Perl_utf8_length(aTHX_ (U8*)s, (U8*)send); |
| 514 |
|
|
} |
| 515 |
|
|
if (i < 0) |
| 516 |
|
|
Perl_croak(aTHX_ "panic: magic_len: %"IVdf, (IV)i); |
| 517 |
|
|
return i; |
| 518 |
|
|
} |
| 519 |
|
|
else { |
| 520 |
|
|
if (ckWARN(WARN_UNINITIALIZED)) |
| 521 |
|
|
report_uninit(); |
| 522 |
|
|
} |
| 523 |
|
|
} |
| 524 |
|
|
else { |
| 525 |
|
|
if (ckWARN(WARN_UNINITIALIZED)) |
| 526 |
|
|
report_uninit(); |
| 527 |
|
|
} |
| 528 |
|
|
return 0; |
| 529 |
|
|
case '+': |
| 530 |
|
|
if (PL_curpm && (rx = PM_GETRE(PL_curpm))) { |
| 531 |
|
|
paren = rx->lastparen; |
| 532 |
|
|
if (paren) |
| 533 |
|
|
goto getparen; |
| 534 |
|
|
} |
| 535 |
|
|
return 0; |
| 536 |
|
|
case '\016': /* ^N */ |
| 537 |
|
|
if (PL_curpm && (rx = PM_GETRE(PL_curpm))) { |
| 538 |
|
|
paren = rx->lastcloseparen; |
| 539 |
|
|
if (paren) |
| 540 |
|
|
goto getparen; |
| 541 |
|
|
} |
| 542 |
|
|
return 0; |
| 543 |
|
|
case '`': |
| 544 |
|
|
if (PL_curpm && (rx = PM_GETRE(PL_curpm))) { |
| 545 |
|
|
if (rx->startp[0] != -1) { |
| 546 |
|
|
i = rx->startp[0]; |
| 547 |
|
|
if (i > 0) { |
| 548 |
|
|
s1 = 0; |
| 549 |
|
|
t1 = i; |
| 550 |
|
|
goto getlen; |
| 551 |
|
|
} |
| 552 |
|
|
} |
| 553 |
|
|
} |
| 554 |
|
|
return 0; |
| 555 |
|
|
case '\'': |
| 556 |
|
|
if (PL_curpm && (rx = PM_GETRE(PL_curpm))) { |
| 557 |
|
|
if (rx->endp[0] != -1) { |
| 558 |
|
|
i = rx->sublen - rx->endp[0]; |
| 559 |
|
|
if (i > 0) { |
| 560 |
|
|
s1 = rx->endp[0]; |
| 561 |
|
|
t1 = rx->sublen; |
| 562 |
|
|
goto getlen; |
| 563 |
|
|
} |
| 564 |
|
|
} |
| 565 |
|
|
} |
| 566 |
|
|
return 0; |
| 567 |
|
|
} |
| 568 |
|
|
magic_get(sv,mg); |
| 569 |
|
|
if (!SvPOK(sv) && SvNIOK(sv)) { |
| 570 |
|
|
STRLEN n_a; |
| 571 |
|
|
sv_2pv(sv, &n_a); |
| 572 |
|
|
} |
| 573 |
|
|
if (SvPOK(sv)) |
| 574 |
|
|
return SvCUR(sv); |
| 575 |
|
|
return 0; |
| 576 |
|
|
} |
| 577 |
|
|
|
| 578 |
|
|
int |
| 579 |
|
|
Perl_magic_get(pTHX_ SV *sv, MAGIC *mg) |
| 580 |
|
|
{ |
| 581 |
|
|
register I32 paren; |
| 582 |
|
|
register char *s = NULL; |
| 583 |
|
|
register I32 i; |
| 584 |
|
|
register REGEXP *rx; |
| 585 |
|
|
|
| 586 |
|
|
switch (*mg->mg_ptr) { |
| 587 |
|
|
case '\001': /* ^A */ |
| 588 |
|
|
sv_setsv(sv, PL_bodytarget); |
| 589 |
|
|
break; |
| 590 |
|
|
case '\003': /* ^C */ |
| 591 |
|
|
sv_setiv(sv, (IV)PL_minus_c); |
| 592 |
|
|
break; |
| 593 |
|
|
|
| 594 |
|
|
case '\004': /* ^D */ |
| 595 |
|
|
sv_setiv(sv, (IV)(PL_debug & DEBUG_MASK)); |
| 596 |
|
|
#if defined(YYDEBUG) && defined(DEBUGGING) |
| 597 |
|
|
PL_yydebug = DEBUG_p_TEST; |
| 598 |
|
|
#endif |
| 599 |
|
|
break; |
| 600 |
|
|
case '\005': /* ^E */ |
| 601 |
|
|
if (*(mg->mg_ptr+1) == '\0') { |
| 602 |
|
|
#ifdef MACOS_TRADITIONAL |
| 603 |
|
|
{ |
| 604 |
|
|
char msg[256]; |
| 605 |
|
|
|
| 606 |
|
|
sv_setnv(sv,(double)gMacPerl_OSErr); |
| 607 |
|
|
sv_setpv(sv, gMacPerl_OSErr ? GetSysErrText(gMacPerl_OSErr, msg) : ""); |
| 608 |
|
|
} |
| 609 |
|
|
#else |
| 610 |
|
|
#ifdef VMS |
| 611 |
|
|
{ |
| 612 |
|
|
# include <descrip.h> |
| 613 |
|
|
# include <starlet.h> |
| 614 |
|
|
char msg[255]; |
| 615 |
|
|
$DESCRIPTOR(msgdsc,msg); |
| 616 |
|
|
sv_setnv(sv,(NV) vaxc$errno); |
| 617 |
|
|
if (sys$getmsg(vaxc$errno,&msgdsc.dsc$w_length,&msgdsc,0,0) & 1) |
| 618 |
|
|
sv_setpvn(sv,msgdsc.dsc$a_pointer,msgdsc.dsc$w_length); |
| 619 |
|
|
else |
| 620 |
|
|
sv_setpv(sv,""); |
| 621 |
|
|
} |
| 622 |
|
|
#else |
| 623 |
|
|
#ifdef OS2 |
| 624 |
|
|
if (!(_emx_env & 0x200)) { /* Under DOS */ |
| 625 |
|
|
sv_setnv(sv, (NV)errno); |
| 626 |
|
|
sv_setpv(sv, errno ? Strerror(errno) : ""); |
| 627 |
|
|
} else { |
| 628 |
|
|
if (errno != errno_isOS2) { |
| 629 |
|
|
int tmp = _syserrno(); |
| 630 |
|
|
if (tmp) /* 2nd call to _syserrno() makes it 0 */ |
| 631 |
|
|
Perl_rc = tmp; |
| 632 |
|
|
} |
| 633 |
|
|
sv_setnv(sv, (NV)Perl_rc); |
| 634 |
|
|
sv_setpv(sv, os2error(Perl_rc)); |
| 635 |
|
|
} |
| 636 |
|
|
#else |
| 637 |
|
|
#ifdef WIN32 |
| 638 |
|
|
{ |
| 639 |
|
|
DWORD dwErr = GetLastError(); |
| 640 |
|
|
sv_setnv(sv, (NV)dwErr); |
| 641 |
|
|
if (dwErr) |
| 642 |
|
|
{ |
| 643 |
|
|
PerlProc_GetOSError(sv, dwErr); |
| 644 |
|
|
} |
| 645 |
|
|
else |
| 646 |
|
|
sv_setpv(sv, ""); |
| 647 |
|
|
SetLastError(dwErr); |
| 648 |
|
|
} |
| 649 |
|
|
#else |
| 650 |
|
|
{ |
| 651 |
|
|
int saveerrno = errno; |
| 652 |
|
|
sv_setnv(sv, (NV)errno); |
| 653 |
|
|
sv_setpv(sv, errno ? Strerror(errno) : ""); |
| 654 |
|
|
errno = saveerrno; |
| 655 |
|
|
} |
| 656 |
|
|
#endif |
| 657 |
|
|
#endif |
| 658 |
|
|
#endif |
| 659 |
|
|
#endif |
| 660 |
|
|
SvNOK_on(sv); /* what a wonderful hack! */ |
| 661 |
|
|
} |
| 662 |
|
|
else if (strEQ(mg->mg_ptr+1, "NCODING")) |
| 663 |
|
|
sv_setsv(sv, PL_encoding); |
| 664 |
|
|
break; |
| 665 |
|
|
case '\006': /* ^F */ |
| 666 |
|
|
sv_setiv(sv, (IV)PL_maxsysfd); |
| 667 |
|
|
break; |
| 668 |
|
|
case '\010': /* ^H */ |
| 669 |
|
|
sv_setiv(sv, (IV)PL_hints); |
| 670 |
|
|
break; |
| 671 |
|
|
case '\011': /* ^I */ /* NOT \t in EBCDIC */ |
| 672 |
|
|
if (PL_inplace) |
| 673 |
|
|
sv_setpv(sv, PL_inplace); |
| 674 |
|
|
else |
| 675 |
|
|
sv_setsv(sv, &PL_sv_undef); |
| 676 |
|
|
break; |
| 677 |
|
|
case '\017': /* ^O & ^OPEN */ |
| 678 |
|
|
if (*(mg->mg_ptr+1) == '\0') { |
| 679 |
|
|
sv_setpv(sv, PL_osname); |
| 680 |
|
|
SvTAINTED_off(sv); |
| 681 |
|
|
} |
| 682 |
|
|
else if (strEQ(mg->mg_ptr, "\017PEN")) { |
| 683 |
|
|
if (!PL_compiling.cop_io) |
| 684 |
|
|
sv_setsv(sv, &PL_sv_undef); |
| 685 |
|
|
else { |
| 686 |
|
|
sv_setsv(sv, PL_compiling.cop_io); |
| 687 |
|
|
} |
| 688 |
|
|
} |
| 689 |
|
|
break; |
| 690 |
|
|
case '\020': /* ^P */ |
| 691 |
|
|
sv_setiv(sv, (IV)PL_perldb); |
| 692 |
|
|
break; |
| 693 |
|
|
case '\023': /* ^S */ |
| 694 |
|
|
if (*(mg->mg_ptr+1) == '\0') { |
| 695 |
|
|
if (PL_lex_state != LEX_NOTPARSING) |
| 696 |
|
|
SvOK_off(sv); |
| 697 |
|
|
else if (PL_in_eval) |
| 698 |
|
|
sv_setiv(sv, PL_in_eval & ~(EVAL_INREQUIRE)); |
| 699 |
|
|
else |
| 700 |
|
|
sv_setiv(sv, 0); |
| 701 |
|
|
} |
| 702 |
|
|
break; |
| 703 |
|
|
case '\024': /* ^T */ |
| 704 |
|
|
if (*(mg->mg_ptr+1) == '\0') { |
| 705 |
|
|
#ifdef BIG_TIME |
| 706 |
|
|
sv_setnv(sv, PL_basetime); |
| 707 |
|
|
#else |
| 708 |
|
|
sv_setiv(sv, (IV)PL_basetime); |
| 709 |
|
|
#endif |
| 710 |
|
|
} |
| 711 |
|
|
else if (strEQ(mg->mg_ptr, "\024AINT")) |
| 712 |
|
|
sv_setiv(sv, PL_tainting |
| 713 |
|
|
? (PL_taint_warn || PL_unsafe ? -1 : 1) |
| 714 |
|
|
: 0); |
| 715 |
|
|
break; |
| 716 |
|
|
case '\025': /* $^UNICODE, $^UTF8LOCALE */ |
| 717 |
|
|
if (strEQ(mg->mg_ptr, "\025NICODE")) |
| 718 |
|
|
sv_setuv(sv, (UV) PL_unicode); |
| 719 |
|
|
else if (strEQ(mg->mg_ptr, "\025TF8LOCALE")) |
| 720 |
|
|
sv_setuv(sv, (UV) PL_utf8locale); |
| 721 |
|
|
break; |
| 722 |
|
|
case '\027': /* ^W & $^WARNING_BITS */ |
| 723 |
|
|
if (*(mg->mg_ptr+1) == '\0') |
| 724 |
|
|
sv_setiv(sv, (IV)((PL_dowarn & G_WARN_ON) ? TRUE : FALSE)); |
| 725 |
|
|
else if (strEQ(mg->mg_ptr+1, "ARNING_BITS")) { |
| 726 |
|
|
if (PL_compiling.cop_warnings == pWARN_NONE || |
| 727 |
|
|
PL_compiling.cop_warnings == pWARN_STD) |
| 728 |
|
|
{ |
| 729 |
|
|
sv_setpvn(sv, WARN_NONEstring, WARNsize) ; |
| 730 |
|
|
} |
| 731 |
|
|
else if (PL_compiling.cop_warnings == pWARN_ALL) { |
| 732 |
|
|
/* Get the bit mask for $warnings::Bits{all}, because |
| 733 |
|
|
* it could have been extended by warnings::register */ |
| 734 |
|
|
SV **bits_all; |
| 735 |
|
|
HV *bits=get_hv("warnings::Bits", FALSE); |
| 736 |
|
|
if (bits && (bits_all=hv_fetch(bits, "all", 3, FALSE))) { |
| 737 |
|
|
sv_setsv(sv, *bits_all); |
| 738 |
|
|
} |
| 739 |
|
|
else { |
| 740 |
|
|
sv_setpvn(sv, WARN_ALLstring, WARNsize) ; |
| 741 |
|
|
} |
| 742 |
|
|
} |
| 743 |
|
|
else { |
| 744 |
|
|
sv_setsv(sv, PL_compiling.cop_warnings); |
| 745 |
|
|
} |
| 746 |
|
|
SvPOK_only(sv); |
| 747 |
|
|
} |
| 748 |
|
|
break; |
| 749 |
|
|
case '1': case '2': case '3': case '4': |
| 750 |
|
|
case '5': case '6': case '7': case '8': case '9': case '&': |
| 751 |
|
|
if (PL_curpm && (rx = PM_GETRE(PL_curpm))) { |
| 752 |
|
|
I32 s1, t1; |
| 753 |
|
|
|
| 754 |
|
|
/* |
| 755 |
|
|
* Pre-threads, this was paren = atoi(GvENAME((GV*)mg->mg_obj)); |
| 756 |
|
|
* XXX Does the new way break anything? |
| 757 |
|
|
*/ |
| 758 |
|
|
paren = atoi(mg->mg_ptr); /* $& is in [0] */ |
| 759 |
|
|
getparen: |
| 760 |
|
|
if (paren <= (I32)rx->nparens && |
| 761 |
|
|
(s1 = rx->startp[paren]) != -1 && |
| 762 |
|
|
(t1 = rx->endp[paren]) != -1) |
| 763 |
|
|
{ |
| 764 |
|
|
i = t1 - s1; |
| 765 |
|
|
s = rx->subbeg + s1; |
| 766 |
|
|
if (!rx->subbeg) |
| 767 |
|
|
break; |
| 768 |
|
|
|
| 769 |
|
|
getrx: |
| 770 |
|
|
if (i >= 0) { |
| 771 |
|
|
sv_setpvn(sv, s, i); |
| 772 |
|
|
if (RX_MATCH_UTF8(rx) && is_utf8_string((U8*)s, i)) |
| 773 |
|
|
SvUTF8_on(sv); |
| 774 |
|
|
else |
| 775 |
|
|
SvUTF8_off(sv); |
| 776 |
|
|
if (PL_tainting) { |
| 777 |
|
|
if (RX_MATCH_TAINTED(rx)) { |
| 778 |
|
|
MAGIC* mg = SvMAGIC(sv); |
| 779 |
|
|
MAGIC* mgt; |
| 780 |
|
|
PL_tainted = 1; |
| 781 |
|
|
SvMAGIC(sv) = mg->mg_moremagic; |
| 782 |
|
|
SvTAINT(sv); |
| 783 |
|
|
if ((mgt = SvMAGIC(sv))) { |
| 784 |
|
|
mg->mg_moremagic = mgt; |
| 785 |
|
|
SvMAGIC(sv) = mg; |
| 786 |
|
|
} |
| 787 |
|
|
} else |
| 788 |
|
|
SvTAINTED_off(sv); |
| 789 |
|
|
} |
| 790 |
|
|
break; |
| 791 |
|
|
} |
| 792 |
|
|
} |
| 793 |
|
|
} |
| 794 |
|
|
sv_setsv(sv,&PL_sv_undef); |
| 795 |
|
|
break; |
| 796 |
|
|
case '+': |
| 797 |
|
|
if (PL_curpm && (rx = PM_GETRE(PL_curpm))) { |
| 798 |
|
|
paren = rx->lastparen; |
| 799 |
|
|
if (paren) |
| 800 |
|
|
goto getparen; |
| 801 |
|
|
} |
| 802 |
|
|
sv_setsv(sv,&PL_sv_undef); |
| 803 |
|
|
break; |
| 804 |
|
|
case '\016': /* ^N */ |
| 805 |
|
|
if (PL_curpm && (rx = PM_GETRE(PL_curpm))) { |
| 806 |
|
|
paren = rx->lastcloseparen; |
| 807 |
|
|
if (paren) |
| 808 |
|
|
goto getparen; |
| 809 |
|
|
} |
| 810 |
|
|
sv_setsv(sv,&PL_sv_undef); |
| 811 |
|
|
break; |
| 812 |
|
|
case '`': |
| 813 |
|
|
if (PL_curpm && (rx = PM_GETRE(PL_curpm))) { |
| 814 |
|
|
if ((s = rx->subbeg) && rx->startp[0] != -1) { |
| 815 |
|
|
i = rx->startp[0]; |
| 816 |
|
|
goto getrx; |
| 817 |
|
|
} |
| 818 |
|
|
} |
| 819 |
|
|
sv_setsv(sv,&PL_sv_undef); |
| 820 |
|
|
break; |
| 821 |
|
|
case '\'': |
| 822 |
|
|
if (PL_curpm && (rx = PM_GETRE(PL_curpm))) { |
| 823 |
|
|
if (rx->subbeg && rx->endp[0] != -1) { |
| 824 |
|
|
s = rx->subbeg + rx->endp[0]; |
| 825 |
|
|
i = rx->sublen - rx->endp[0]; |
| 826 |
|
|
goto getrx; |
| 827 |
|
|
} |
| 828 |
|
|
} |
| 829 |
|
|
sv_setsv(sv,&PL_sv_undef); |
| 830 |
|
|
break; |
| 831 |
|
|
case '.': |
| 832 |
|
|
#ifndef lint |
| 833 |
|
|
if (GvIO(PL_last_in_gv)) { |
| 834 |
|
|
sv_setiv(sv, (IV)IoLINES(GvIOp(PL_last_in_gv))); |
| 835 |
|
|
} |
| 836 |
|
|
#endif |
| 837 |
|
|
break; |
| 838 |
|
|
case '?': |
| 839 |
|
|
{ |
| 840 |
|
|
sv_setiv(sv, (IV)STATUS_CURRENT); |
| 841 |
|
|
#ifdef COMPLEX_STATUS |
| 842 |
|
|
LvTARGOFF(sv) = PL_statusvalue; |
| 843 |
|
|
LvTARGLEN(sv) = PL_statusvalue_vms; |
| 844 |
|
|
#endif |
| 845 |
|
|
} |
| 846 |
|
|
break; |
| 847 |
|
|
case '^': |
| 848 |
|
|
if (GvIOp(PL_defoutgv)) |
| 849 |
|
|
s = IoTOP_NAME(GvIOp(PL_defoutgv)); |
| 850 |
|
|
if (s) |
| 851 |
|
|
sv_setpv(sv,s); |
| 852 |
|
|
else { |
| 853 |
|
|
sv_setpv(sv,GvENAME(PL_defoutgv)); |
| 854 |
|
|
sv_catpv(sv,"_TOP"); |
| 855 |
|
|
} |
| 856 |
|
|
break; |
| 857 |
|
|
case '~': |
| 858 |
|
|
if (GvIOp(PL_defoutgv)) |
| 859 |
|
|
s = IoFMT_NAME(GvIOp(PL_defoutgv)); |
| 860 |
|
|
if (!s) |
| 861 |
|
|
s = GvENAME(PL_defoutgv); |
| 862 |
|
|
sv_setpv(sv,s); |
| 863 |
|
|
break; |
| 864 |
|
|
#ifndef lint |
| 865 |
|
|
case '=': |
| 866 |
|
|
if (GvIOp(PL_defoutgv)) |
| 867 |
|
|
sv_setiv(sv, (IV)IoPAGE_LEN(GvIOp(PL_defoutgv))); |
| 868 |
|
|
break; |
| 869 |
|
|
case '-': |
| 870 |
|
|
if (GvIOp(PL_defoutgv)) |
| 871 |
|
|
sv_setiv(sv, (IV)IoLINES_LEFT(GvIOp(PL_defoutgv))); |
| 872 |
|
|
break; |
| 873 |
|
|
case '%': |
| 874 |
|
|
if (GvIOp(PL_defoutgv)) |
| 875 |
|
|
sv_setiv(sv, (IV)IoPAGE(GvIOp(PL_defoutgv))); |
| 876 |
|
|
break; |
| 877 |
|
|
#endif |
| 878 |
|
|
case ':': |
| 879 |
|
|
break; |
| 880 |
|
|
case '/': |
| 881 |
|
|
break; |
| 882 |
|
|
case '[': |
| 883 |
|
|
WITH_THR(sv_setiv(sv, (IV)PL_curcop->cop_arybase)); |
| 884 |
|
|
break; |
| 885 |
|
|
case '|': |
| 886 |
|
|
if (GvIOp(PL_defoutgv)) |
| 887 |
|
|
sv_setiv(sv, (IV)(IoFLAGS(GvIOp(PL_defoutgv)) & IOf_FLUSH) != 0 ); |
| 888 |
|
|
break; |
| 889 |
|
|
case ',': |
| 890 |
|
|
break; |
| 891 |
|
|
case '\\': |
| 892 |
|
|
if (PL_ors_sv) |
| 893 |
|
|
sv_copypv(sv, PL_ors_sv); |
| 894 |
|
|
break; |
| 895 |
|
|
case '#': |
| 896 |
|
|
sv_setpv(sv,PL_ofmt); |
| 897 |
|
|
break; |
| 898 |
|
|
case '!': |
| 899 |
|
|
#ifdef VMS |
| 900 |
|
|
sv_setnv(sv, (NV)((errno == EVMSERR) ? vaxc$errno : errno)); |
| 901 |
|
|
sv_setpv(sv, errno ? Strerror(errno) : ""); |
| 902 |
|
|
#else |
| 903 |
|
|
{ |
| 904 |
|
|
int saveerrno = errno; |
| 905 |
|
|
sv_setnv(sv, (NV)errno); |
| 906 |
|
|
#ifdef OS2 |
| 907 |
|
|
if (errno == errno_isOS2 || errno == errno_isOS2_set) |
| 908 |
|
|
sv_setpv(sv, os2error(Perl_rc)); |
| 909 |
|
|
else |
| 910 |
|
|
#endif |
| 911 |
|
|
sv_setpv(sv, errno ? Strerror(errno) : ""); |
| 912 |
|
|
errno = saveerrno; |
| 913 |
|
|
} |
| 914 |
|
|
#endif |
| 915 |
|
|
SvNOK_on(sv); /* what a wonderful hack! */ |
| 916 |
|
|
break; |
| 917 |
|
|
case '<': |
| 918 |
|
|
sv_setiv(sv, (IV)PL_uid); |
| 919 |
|
|
break; |
| 920 |
|
|
case '>': |
| 921 |
|
|
sv_setiv(sv, (IV)PL_euid); |
| 922 |
|
|
break; |
| 923 |
|
|
case '(': |
| 924 |
|
|
sv_setiv(sv, (IV)PL_gid); |
| 925 |
|
|
#ifdef HAS_GETGROUPS |
| 926 |
|
|
Perl_sv_setpvf(aTHX_ sv, "%"Gid_t_f, PL_gid); |
| 927 |
|
|
#endif |
| 928 |
|
|
goto add_groups; |
| 929 |
|
|
case ')': |
| 930 |
|
|
sv_setiv(sv, (IV)PL_egid); |
| 931 |
|
|
#ifdef HAS_GETGROUPS |
| 932 |
|
|
Perl_sv_setpvf(aTHX_ sv, "%"Gid_t_f, PL_egid); |
| 933 |
|
|
#endif |
| 934 |
|
|
add_groups: |
| 935 |
|
|
#ifdef HAS_GETGROUPS |
| 936 |
|
|
{ |
| 937 |
|
|
Groups_t gary[NGROUPS]; |
| 938 |
|
|
i = getgroups(NGROUPS,gary); |
| 939 |
|
|
while (--i >= 0) |
| 940 |
|
|
Perl_sv_catpvf(aTHX_ sv, " %"Gid_t_f, gary[i]); |
| 941 |
|
|
} |
| 942 |
|
|
#endif |
| 943 |
|
|
(void)SvIOK_on(sv); /* what a wonderful hack! */ |
| 944 |
|
|
break; |
| 945 |
|
|
case '*': |
| 946 |
|
|
break; |
| 947 |
|
|
#ifndef MACOS_TRADITIONAL |
| 948 |
|
|
case '0': |
| 949 |
|
|
break; |
| 950 |
|
|
#endif |
| 951 |
|
|
#ifdef USE_5005THREADS |
| 952 |
|
|
case '@': |
| 953 |
|
|
sv_setsv(sv, thr->errsv); |
| 954 |
|
|
break; |
| 955 |
|
|
#endif /* USE_5005THREADS */ |
| 956 |
|
|
} |
| 957 |
|
|
return 0; |
| 958 |
|
|
} |
| 959 |
|
|
|
| 960 |
|
|
int |
| 961 |
|
|
Perl_magic_getuvar(pTHX_ SV *sv, MAGIC *mg) |
| 962 |
|
|
{ |
| 963 |
|
|
struct ufuncs *uf = (struct ufuncs *)mg->mg_ptr; |
| 964 |
|
|
|
| 965 |
|
|
if (uf && uf->uf_val) |
| 966 |
|
|
(*uf->uf_val)(aTHX_ uf->uf_index, sv); |
| 967 |
|
|
return 0; |
| 968 |
|
|
} |
| 969 |
|
|
|
| 970 |
|
|
int |
| 971 |
|
|
Perl_magic_setenv(pTHX_ SV *sv, MAGIC *mg) |
| 972 |
|
|
{ |
| 973 |
|
|
register char *s; |
| 974 |
|
|
char *ptr; |
| 975 |
|
|
STRLEN len, klen; |
| 976 |
|
|
|
| 977 |
|
|
s = SvPV(sv,len); |
| 978 |
|
|
ptr = MgPV(mg,klen); |
| 979 |
|
|
my_setenv(ptr, s); |
| 980 |
|
|
|
| 981 |
|
|
#ifdef DYNAMIC_ENV_FETCH |
| 982 |
|
|
/* We just undefd an environment var. Is a replacement */ |
| 983 |
|
|
/* waiting in the wings? */ |
| 984 |
|
|
if (!len) { |
| 985 |
|
|
SV **valp; |
| 986 |
|
|
if ((valp = hv_fetch(GvHVn(PL_envgv), ptr, klen, FALSE))) |
| 987 |
|
|
s = SvPV(*valp, len); |
| 988 |
|
|
} |
| 989 |
|
|
#endif |
| 990 |
|
|
|
| 991 |
|
|
#if !defined(OS2) && !defined(AMIGAOS) && !defined(WIN32) && !defined(MSDOS) |
| 992 |
|
|
/* And you'll never guess what the dog had */ |
| 993 |
|
|
/* in its mouth... */ |
| 994 |
|
|
if (PL_tainting) { |
| 995 |
|
|
MgTAINTEDDIR_off(mg); |
| 996 |
|
|
#ifdef VMS |
| 997 |
|
|
if (s && klen == 8 && strEQ(ptr, "DCL$PATH")) { |
| 998 |
|
|
char pathbuf[256], eltbuf[256], *cp, *elt = s; |
| 999 |
|
|
Stat_t sbuf; |
| 1000 |
|
|
int i = 0, j = 0; |
| 1001 |
|
|
|
| 1002 |
|
|
do { /* DCL$PATH may be a search list */ |
| 1003 |
|
|
while (1) { /* as may dev portion of any element */ |
| 1004 |
|
|
if ( ((cp = strchr(elt,'[')) || (cp = strchr(elt,'<'))) ) { |
| 1005 |
|
|
if ( *(cp+1) == '.' || *(cp+1) == '-' || |
| 1006 |
|
|
cando_by_name(S_IWUSR,0,elt) ) { |
| 1007 |
|
|
MgTAINTEDDIR_on(mg); |
| 1008 |
|
|
return 0; |
| 1009 |
|
|
} |
| 1010 |
|
|
} |
| 1011 |
|
|
if ((cp = strchr(elt, ':')) != Nullch) |
| 1012 |
|
|
*cp = '\0'; |
| 1013 |
|
|
if (my_trnlnm(elt, eltbuf, j++)) |
| 1014 |
|
|
elt = eltbuf; |
| 1015 |
|
|
else |
| 1016 |
|
|
break; |
| 1017 |
|
|
} |
| 1018 |
|
|
j = 0; |
| 1019 |
|
|
} while (my_trnlnm(s, pathbuf, i++) && (elt = pathbuf)); |
| 1020 |
|
|
} |
| 1021 |
|
|
#endif /* VMS */ |
| 1022 |
|
|
if (s && klen == 4 && strEQ(ptr,"PATH")) { |
| 1023 |
|
|
char *strend = s + len; |
| 1024 |
|
|
|
| 1025 |
|
|
while (s < strend) { |
| 1026 |
|
|
char tmpbuf[256]; |
| 1027 |
|
|
Stat_t st; |
| 1028 |
|
|
I32 i; |
| 1029 |
|
|
s = delimcpy(tmpbuf, tmpbuf + sizeof tmpbuf, |
| 1030 |
|
|
s, strend, ':', &i); |
| 1031 |
|
|
s++; |
| 1032 |
|
|
if (i >= sizeof tmpbuf /* too long -- assume the worst */ |
| 1033 |
|
|
|| *tmpbuf != '/' |
| 1034 |
|
|
|| (PerlLIO_stat(tmpbuf, &st) == 0 && (st.st_mode & 2)) ) { |
| 1035 |
|
|
MgTAINTEDDIR_on(mg); |
| 1036 |
|
|
return 0; |
| 1037 |
|
|
} |
| 1038 |
|
|
} |
| 1039 |
|
|
} |
| 1040 |
|
|
} |
| 1041 |
|
|
#endif /* neither OS2 nor AMIGAOS nor WIN32 nor MSDOS */ |
| 1042 |
|
|
|
| 1043 |
|
|
return 0; |
| 1044 |
|
|
} |
| 1045 |
|
|
|
| 1046 |
|
|
int |
| 1047 |
|
|
Perl_magic_clearenv(pTHX_ SV *sv, MAGIC *mg) |
| 1048 |
|
|
{ |
| 1049 |
|
|
STRLEN n_a; |
| 1050 |
|
|
my_setenv(MgPV(mg,n_a),Nullch); |
| 1051 |
|
|
return 0; |
| 1052 |
|
|
} |
| 1053 |
|
|
|
| 1054 |
|
|
int |
| 1055 |
|
|
Perl_magic_set_all_env(pTHX_ SV *sv, MAGIC *mg) |
| 1056 |
|
|
{ |
| 1057 |
|
|
#if defined(VMS) |
| 1058 |
|
|
Perl_die(aTHX_ "Can't make list assignment to %%ENV on this system"); |
| 1059 |
|
|
#else |
| 1060 |
|
|
if (PL_localizing) { |
| 1061 |
|
|
HE* entry; |
| 1062 |
|
|
STRLEN n_a; |
| 1063 |
|
|
magic_clear_all_env(sv,mg); |
| 1064 |
|
|
hv_iterinit((HV*)sv); |
| 1065 |
|
|
while ((entry = hv_iternext((HV*)sv))) { |
| 1066 |
|
|
I32 keylen; |
| 1067 |
|
|
my_setenv(hv_iterkey(entry, &keylen), |
| 1068 |
|
|
SvPV(hv_iterval((HV*)sv, entry), n_a)); |
| 1069 |
|
|
} |
| 1070 |
|
|
} |
| 1071 |
|
|
#endif |
| 1072 |
|
|
return 0; |
| 1073 |
|
|
} |
| 1074 |
|
|
|
| 1075 |
|
|
int |
| 1076 |
|
|
Perl_magic_clear_all_env(pTHX_ SV *sv, MAGIC *mg) |
| 1077 |
|
|
{ |
| 1078 |
|
|
#ifndef PERL_MICRO |
| 1079 |
|
|
#if defined(VMS) || defined(EPOC) |
| 1080 |
|
|
Perl_die(aTHX_ "Can't make list assignment to %%ENV on this system"); |
| 1081 |
|
|
#else |
| 1082 |
|
|
# if defined(PERL_IMPLICIT_SYS) || defined(WIN32) |
| 1083 |
|
|
PerlEnv_clearenv(); |
| 1084 |
|
|
# else |
| 1085 |
|
|
# ifdef USE_ENVIRON_ARRAY |
| 1086 |
|
|
# if defined(USE_ITHREADS) |
| 1087 |
|
|
/* only the parent thread can clobber the process environment */ |
| 1088 |
|
|
if (PL_curinterp == aTHX) |
| 1089 |
|
|
# endif |
| 1090 |
|
|
{ |
| 1091 |
|
|
# ifndef PERL_USE_SAFE_PUTENV |
| 1092 |
|
|
if (!PL_use_safe_putenv) { |
| 1093 |
|
|
I32 i; |
| 1094 |
|
|
|
| 1095 |
|
|
if (environ == PL_origenviron) |
| 1096 |
|
|
environ = (char**)safesysmalloc(sizeof(char*)); |
| 1097 |
|
|
else |
| 1098 |
|
|
for (i = 0; environ[i]; i++) |
| 1099 |
|
|
safesysfree(environ[i]); |
| 1100 |
|
|
} |
| 1101 |
|
|
# endif /* PERL_USE_SAFE_PUTENV */ |
| 1102 |
|
|
|
| 1103 |
|
|
environ[0] = Nullch; |
| 1104 |
|
|
} |
| 1105 |
|
|
# endif /* USE_ENVIRON_ARRAY */ |
| 1106 |
|
|
# endif /* PERL_IMPLICIT_SYS || WIN32 */ |
| 1107 |
|
|
#endif /* VMS || EPOC */ |
| 1108 |
|
|
#endif /* !PERL_MICRO */ |
| 1109 |
|
|
return 0; |
| 1110 |
|
|
} |
| 1111 |
|
|
|
| 1112 |
|
|
#if defined(FAKE_PERSISTENT_SIGNAL_HANDLERS)||defined(FAKE_DEFAULT_SIGNAL_HANDLERS) |
| 1113 |
|
|
static int sig_handlers_initted = 0; |
| 1114 |
|
|
#endif |
| 1115 |
|
|
#ifdef FAKE_PERSISTENT_SIGNAL_HANDLERS |
| 1116 |
|
|
static int sig_ignoring[SIG_SIZE]; /* which signals we are ignoring */ |
| 1117 |
|
|
#endif |
| 1118 |
|
|
#ifdef FAKE_DEFAULT_SIGNAL_HANDLERS |
| 1119 |
|
|
static int sig_defaulting[SIG_SIZE]; |
| 1120 |
|
|
#endif |
| 1121 |
|
|
|
| 1122 |
|
|
#ifndef PERL_MICRO |
| 1123 |
|
|
#ifdef HAS_SIGPROCMASK |
| 1124 |
|
|
static void |
| 1125 |
|
|
restore_sigmask(pTHX_ SV *save_sv) |
| 1126 |
|
|
{ |
| 1127 |
|
|
sigset_t *ossetp = (sigset_t *) SvPV_nolen( save_sv ); |
| 1128 |
|
|
(void)sigprocmask(SIG_SETMASK, ossetp, (sigset_t *)0); |
| 1129 |
|
|
} |
| 1130 |
|
|
#endif |
| 1131 |
|
|
int |
| 1132 |
|
|
Perl_magic_getsig(pTHX_ SV *sv, MAGIC *mg) |
| 1133 |
|
|
{ |
| 1134 |
|
|
I32 i; |
| 1135 |
|
|
STRLEN n_a; |
| 1136 |
|
|
/* Are we fetching a signal entry? */ |
| 1137 |
|
|
i = whichsig(MgPV(mg,n_a)); |
| 1138 |
|
|
if (i > 0) { |
| 1139 |
|
|
if(PL_psig_ptr[i]) |
| 1140 |
|
|
sv_setsv(sv,PL_psig_ptr[i]); |
| 1141 |
|
|
else { |
| 1142 |
|
|
Sighandler_t sigstate; |
| 1143 |
|
|
sigstate = rsignal_state(i); |
| 1144 |
|
|
#ifdef FAKE_PERSISTENT_SIGNAL_HANDLERS |
| 1145 |
|
|
if (sig_handlers_initted && sig_ignoring[i]) sigstate = SIG_IGN; |
| 1146 |
|
|
#endif |
| 1147 |
|
|
#ifdef FAKE_DEFAULT_SIGNAL_HANDLERS |
| 1148 |
|
|
if (sig_handlers_initted && sig_defaulting[i]) sigstate = SIG_DFL; |
| 1149 |
|
|
#endif |
| 1150 |
|
|
/* cache state so we don't fetch it again */ |
| 1151 |
|
|
if(sigstate == SIG_IGN) |
| 1152 |
|
|
sv_setpv(sv,"IGNORE"); |
| 1153 |
|
|
else |
| 1154 |
|
|
sv_setsv(sv,&PL_sv_undef); |
| 1155 |
|
|
PL_psig_ptr[i] = SvREFCNT_inc(sv); |
| 1156 |
|
|
SvTEMP_off(sv); |
| 1157 |
|
|
} |
| 1158 |
|
|
} |
| 1159 |
|
|
return 0; |
| 1160 |
|
|
} |
| 1161 |
|
|
int |
| 1162 |
|
|
Perl_magic_clearsig(pTHX_ SV *sv, MAGIC *mg) |
| 1163 |
|
|
{ |
| 1164 |
|
|
/* XXX Some of this code was copied from Perl_magic_setsig. A little |
| 1165 |
|
|
* refactoring might be in order. |
| 1166 |
|
|
*/ |
| 1167 |
|
|
register char *s; |
| 1168 |
|
|
STRLEN n_a; |
| 1169 |
|
|
SV* to_dec; |
| 1170 |
|
|
s = MgPV(mg,n_a); |
| 1171 |
|
|
if (*s == '_') { |
| 1172 |
|
|
SV** svp; |
| 1173 |
|
|
if (strEQ(s,"__DIE__")) |
| 1174 |
|
|
svp = &PL_diehook; |
| 1175 |
|
|
else if (strEQ(s,"__WARN__")) |
| 1176 |
|
|
svp = &PL_warnhook; |
| 1177 |
|
|
else |
| 1178 |
|
|
Perl_croak(aTHX_ "No such hook: %s", s); |
| 1179 |
|
|
if (*svp) { |
| 1180 |
|
|
to_dec = *svp; |
| 1181 |
|
|
*svp = 0; |
| 1182 |
|
|
SvREFCNT_dec(to_dec); |
| 1183 |
|
|
} |
| 1184 |
|
|
} |
| 1185 |
|
|
else { |
| 1186 |
|
|
I32 i; |
| 1187 |
|
|
/* Are we clearing a signal entry? */ |
| 1188 |
|
|
i = whichsig(s); |
| 1189 |
|
|
if (i > 0) { |
| 1190 |
|
|
#ifdef HAS_SIGPROCMASK |
| 1191 |
|
|
sigset_t set, save; |
| 1192 |
|
|
SV* save_sv; |
| 1193 |
|
|
/* Avoid having the signal arrive at a bad time, if possible. */ |
| 1194 |
|
|
sigemptyset(&set); |
| 1195 |
|
|
sigaddset(&set,i); |
| 1196 |
|
|
sigprocmask(SIG_BLOCK, &set, &save); |
| 1197 |
|
|
ENTER; |
| 1198 |
|
|
save_sv = newSVpv((char *)(&save), sizeof(sigset_t)); |
| 1199 |
|
|
SAVEFREESV(save_sv); |
| 1200 |
|
|
SAVEDESTRUCTOR_X(restore_sigmask, save_sv); |
| 1201 |
|
|
#endif |
| 1202 |
|
|
PERL_ASYNC_CHECK(); |
| 1203 |
|
|
#if defined(FAKE_PERSISTENT_SIGNAL_HANDLERS) || defined(FAKE_DEFAULT_SIGNAL_HANDLERS) |
| 1204 |
|
|
if (!sig_handlers_initted) Perl_csighandler_init(); |
| 1205 |
|
|
#endif |
| 1206 |
|
|
#ifdef FAKE_DEFAULT_SIGNAL_HANDLERS |
| 1207 |
|
|
sig_defaulting[i] = 1; |
| 1208 |
|
|
(void)rsignal(i, PL_csighandlerp); |
| 1209 |
|
|
#else |
| 1210 |
|
|
(void)rsignal(i, SIG_DFL); |
| 1211 |
|
|
#endif |
| 1212 |
|
|
if(PL_psig_name[i]) { |
| 1213 |
|
|
SvREFCNT_dec(PL_psig_name[i]); |
| 1214 |
|
|
PL_psig_name[i]=0; |
| 1215 |
|
|
} |
| 1216 |
|
|
if(PL_psig_ptr[i]) { |
| 1217 |
|
|
to_dec=PL_psig_ptr[i]; |
| 1218 |
|
|
PL_psig_ptr[i]=0; |
| 1219 |
|
|
LEAVE; |
| 1220 |
|
|
SvREFCNT_dec(to_dec); |
| 1221 |
|
|
} |
| 1222 |
|
|
else |
| 1223 |
|
|
LEAVE; |
| 1224 |
|
|
} |
| 1225 |
|
|
} |
| 1226 |
|
|
return 0; |
| 1227 |
|
|
} |
| 1228 |
|
|
|
| 1229 |
|
|
void |
| 1230 |
|
|
Perl_raise_signal(pTHX_ int sig) |
| 1231 |
|
|
{ |
| 1232 |
|
|
/* Set a flag to say this signal is pending */ |
| 1233 |
|
|
PL_psig_pend[sig]++; |
| 1234 |
|
|
/* And one to say _a_ signal is pending */ |
| 1235 |
|
|
PL_sig_pending = 1; |
| 1236 |
|
|
} |
| 1237 |
|
|
|
| 1238 |
|
|
Signal_t |
| 1239 |
|
|
Perl_csighandler(int sig) |
| 1240 |
|
|
{ |
| 1241 |
|
|
#ifdef PERL_GET_SIG_CONTEXT |
| 1242 |
|
|
dTHXa(PERL_GET_SIG_CONTEXT); |
| 1243 |
|
|
#else |
| 1244 |
|
|
dTHX; |
| 1245 |
|
|
#endif |
| 1246 |
|
|
#ifdef FAKE_PERSISTENT_SIGNAL_HANDLERS |
| 1247 |
|
|
(void) rsignal(sig, PL_csighandlerp); |
| 1248 |
|
|
if (sig_ignoring[sig]) return; |
| 1249 |
|
|
#endif |
| 1250 |
|
|
#ifdef FAKE_DEFAULT_SIGNAL_HANDLERS |
| 1251 |
|
|
if (sig_defaulting[sig]) |
| 1252 |
|
|
#ifdef KILL_BY_SIGPRC |
| 1253 |
|
|
exit((Perl_sig_to_vmscondition(sig)&STS$M_COND_ID)|STS$K_SEVERE|STS$M_INHIB_MSG); |
| 1254 |
|
|
#else |
| 1255 |
|
|
exit(1); |
| 1256 |
|
|
#endif |
| 1257 |
|
|
#endif |
| 1258 |
|
|
if (PL_signals & PERL_SIGNALS_UNSAFE_FLAG) |
| 1259 |
|
|
/* Call the perl level handler now-- |
| 1260 |
|
|
* with risk we may be in malloc() etc. */ |
| 1261 |
|
|
(*PL_sighandlerp)(sig); |
| 1262 |
|
|
else |
| 1263 |
|
|
Perl_raise_signal(aTHX_ sig); |
| 1264 |
|
|
} |
| 1265 |
|
|
|
| 1266 |
|
|
#if defined(FAKE_PERSISTENT_SIGNAL_HANDLERS) || defined(FAKE_DEFAULT_SIGNAL_HANDLERS) |
| 1267 |
|
|
void |
| 1268 |
|
|
Perl_csighandler_init(void) |
| 1269 |
|
|
{ |
| 1270 |
|
|
int sig; |
| 1271 |
|
|
if (sig_handlers_initted) return; |
| 1272 |
|
|
|
| 1273 |
|
|
for (sig = 1; sig < SIG_SIZE; sig++) { |
| 1274 |
|
|
#ifdef FAKE_DEFAULT_SIGNAL_HANDLERS |
| 1275 |
|
|
dTHX; |
| 1276 |
|
|
sig_defaulting[sig] = 1; |
| 1277 |
|
|
(void) rsignal(sig, PL_csighandlerp); |
| 1278 |
|
|
#endif |
| 1279 |
|
|
#ifdef FAKE_PERSISTENT_SIGNAL_HANDLERS |
| 1280 |
|
|
sig_ignoring[sig] = 0; |
| 1281 |
|
|
#endif |
| 1282 |
|
|
} |
| 1283 |
|
|
sig_handlers_initted = 1; |
| 1284 |
|
|
} |
| 1285 |
|
|
#endif |
| 1286 |
|
|
|
| 1287 |
|
|
void |
| 1288 |
|
|
Perl_despatch_signals(pTHX) |
| 1289 |
|
|
{ |
| 1290 |
|
|
int sig; |
| 1291 |
|
|
PL_sig_pending = 0; |
| 1292 |
|
|
for (sig = 1; sig < SIG_SIZE; sig++) { |
| 1293 |
|
|
if (PL_psig_pend[sig]) { |
| 1294 |
|
|
PERL_BLOCKSIG_ADD(set, sig); |
| 1295 |
|
|
PL_psig_pend[sig] = 0; |
| 1296 |
|
|
PERL_BLOCKSIG_BLOCK(set); |
| 1297 |
|
|
(*PL_sighandlerp)(sig); |
| 1298 |
|
|
PERL_BLOCKSIG_UNBLOCK(set); |
| 1299 |
|
|
} |
| 1300 |
|
|
} |
| 1301 |
|
|
} |
| 1302 |
|
|
|
| 1303 |
|
|
int |
| 1304 |
|
|
Perl_magic_setsig(pTHX_ SV *sv, MAGIC *mg) |
| 1305 |
|
|
{ |
| 1306 |
|
|
register char *s; |
| 1307 |
|
|
I32 i; |
| 1308 |
|
|
SV** svp = 0; |
| 1309 |
|
|
/* Need to be careful with SvREFCNT_dec(), because that can have side |
| 1310 |
|
|
* effects (due to closures). We must make sure that the new disposition |
| 1311 |
|
|
* is in place before it is called. |
| 1312 |
|
|
*/ |
| 1313 |
|
|
SV* to_dec = 0; |
| 1314 |
|
|
STRLEN len; |
| 1315 |
|
|
#ifdef HAS_SIGPROCMASK |
| 1316 |
|
|
sigset_t set, save; |
| 1317 |
|
|
SV* save_sv; |
| 1318 |
|
|
#endif |
| 1319 |
|
|
|
| 1320 |
|
|
s = MgPV(mg,len); |
| 1321 |
|
|
if (*s == '_') { |
| 1322 |
|
|
if (strEQ(s,"__DIE__")) |
| 1323 |
|
|
svp = &PL_diehook; |
| 1324 |
|
|
else if (strEQ(s,"__WARN__")) |
| 1325 |
|
|
svp = &PL_warnhook; |
| 1326 |
|
|
else |
| 1327 |
|
|
Perl_croak(aTHX_ "No such hook: %s", s); |
| 1328 |
|
|
i = 0; |
| 1329 |
|
|
if (*svp) { |
| 1330 |
|
|
to_dec = *svp; |
| 1331 |
|
|
*svp = 0; |
| 1332 |
|
|
} |
| 1333 |
|
|
} |
| 1334 |
|
|
else { |
| 1335 |
|
|
i = whichsig(s); /* ...no, a brick */ |
| 1336 |
|
|
if (i < 0) { |
| 1337 |
|
|
if (ckWARN(WARN_SIGNAL)) |
| 1338 |
|
|
Perl_warner(aTHX_ packWARN(WARN_SIGNAL), "No such signal: SIG%s", s); |
| 1339 |
|
|
return 0; |
| 1340 |
|
|
} |
| 1341 |
|
|
#ifdef HAS_SIGPROCMASK |
| 1342 |
|
|
/* Avoid having the signal arrive at a bad time, if possible. */ |
| 1343 |
|
|
sigemptyset(&set); |
| 1344 |
|
|
sigaddset(&set,i); |
| 1345 |
|
|
sigprocmask(SIG_BLOCK, &set, &save); |
| 1346 |
|
|
ENTER; |
| 1347 |
|
|
save_sv = newSVpv((char *)(&save), sizeof(sigset_t)); |
| 1348 |
|
|
SAVEFREESV(save_sv); |
| 1349 |
|
|
SAVEDESTRUCTOR_X(restore_sigmask, save_sv); |
| 1350 |
|
|
#endif |
| 1351 |
|
|
PERL_ASYNC_CHECK(); |
| 1352 |
|
|
#if defined(FAKE_PERSISTENT_SIGNAL_HANDLERS) || defined(FAKE_DEFAULT_SIGNAL_HANDLERS) |
| 1353 |
|
|
if (!sig_handlers_initted) Perl_csighandler_init(); |
| 1354 |
|
|
#endif |
| 1355 |
|
|
#ifdef FAKE_PERSISTENT_SIGNAL_HANDLERS |
| 1356 |
|
|
sig_ignoring[i] = 0; |
| 1357 |
|
|
#endif |
| 1358 |
|
|
#ifdef FAKE_DEFAULT_SIGNAL_HANDLERS |
| 1359 |
|
|
sig_defaulting[i] = 0; |
| 1360 |
|
|
#endif |
| 1361 |
|
|
SvREFCNT_dec(PL_psig_name[i]); |
| 1362 |
|
|
to_dec = PL_psig_ptr[i]; |
| 1363 |
|
|
PL_psig_ptr[i] = SvREFCNT_inc(sv); |
| 1364 |
|
|
SvTEMP_off(sv); /* Make sure it doesn't go away on us */ |
| 1365 |
|
|
PL_psig_name[i] = newSVpvn(s, len); |
| 1366 |
|
|
SvREADONLY_on(PL_psig_name[i]); |
| 1367 |
|
|
} |
| 1368 |
|
|
if (SvTYPE(sv) == SVt_PVGV || SvROK(sv)) { |
| 1369 |
|
|
if (i) { |
| 1370 |
|
|
(void)rsignal(i, PL_csighandlerp); |
| 1371 |
|
|
#ifdef HAS_SIGPROCMASK |
| 1372 |
|
|
LEAVE; |
| 1373 |
|
|
#endif |
| 1374 |
|
|
} |
| 1375 |
|
|
else |
| 1376 |
|
|
*svp = SvREFCNT_inc(sv); |
| 1377 |
|
|
if(to_dec) |
| 1378 |
|
|
SvREFCNT_dec(to_dec); |
| 1379 |
|
|
return 0; |
| 1380 |
|
|
} |
| 1381 |
|
|
s = SvPV_force(sv,len); |
| 1382 |
|
|
if (strEQ(s,"IGNORE")) { |
| 1383 |
|
|
if (i) { |
| 1384 |
|
|
#ifdef FAKE_PERSISTENT_SIGNAL_HANDLERS |
| 1385 |
|
|
sig_ignoring[i] = 1; |
| 1386 |
|
|
(void)rsignal(i, PL_csighandlerp); |
| 1387 |
|
|
#else |
| 1388 |
|
|
(void)rsignal(i, SIG_IGN); |
| 1389 |
|
|
#endif |
| 1390 |
|
|
} |
| 1391 |
|
|
} |
| 1392 |
|
|
else if (strEQ(s,"DEFAULT") || !*s) { |
| 1393 |
|
|
if (i) |
| 1394 |
|
|
#ifdef FAKE_DEFAULT_SIGNAL_HANDLERS |
| 1395 |
|
|
{ |
| 1396 |
|
|
sig_defaulting[i] = 1; |
| 1397 |
|
|
(void)rsignal(i, PL_csighandlerp); |
| 1398 |
|
|
} |
| 1399 |
|
|
#else |
| 1400 |
|
|
(void)rsignal(i, SIG_DFL); |
| 1401 |
|
|
#endif |
| 1402 |
|
|
} |
| 1403 |
|
|
else { |
| 1404 |
|
|
/* |
| 1405 |
|
|
* We should warn if HINT_STRICT_REFS, but without |
| 1406 |
|
|
* access to a known hint bit in a known OP, we can't |
| 1407 |
|
|
* tell whether HINT_STRICT_REFS is in force or not. |
| 1408 |
|
|
*/ |
| 1409 |
|
|
if (!strchr(s,':') && !strchr(s,'\'')) |
| 1410 |
|
|
sv_insert(sv, 0, 0, "main::", 6); |
| 1411 |
|
|
if (i) |
| 1412 |
|
|
(void)rsignal(i, PL_csighandlerp); |
| 1413 |
|
|
else |
| 1414 |
|
|
*svp = SvREFCNT_inc(sv); |
| 1415 |
|
|
} |
| 1416 |
|
|
#ifdef HAS_SIGPROCMASK |
| 1417 |
|
|
if(i) |
| 1418 |
|
|
LEAVE; |
| 1419 |
|
|
#endif |
| 1420 |
|
|
if(to_dec) |
| 1421 |
|
|
SvREFCNT_dec(to_dec); |
| 1422 |
|
|
return 0; |
| 1423 |
|
|
} |
| 1424 |
|
|
#endif /* !PERL_MICRO */ |
| 1425 |
|
|
|
| 1426 |
|
|
int |
| 1427 |
|
|
Perl_magic_setisa(pTHX_ SV *sv, MAGIC *mg) |
| 1428 |
|
|
{ |
| 1429 |
|
|
PL_sub_generation++; |
| 1430 |
|
|
return 0; |
| 1431 |
|
|
} |
| 1432 |
|
|
|
| 1433 |
|
|
int |
| 1434 |
|
|
Perl_magic_setamagic(pTHX_ SV *sv, MAGIC *mg) |
| 1435 |
|
|
{ |
| 1436 |
|
|
/* HV_badAMAGIC_on(Sv_STASH(sv)); */ |
| 1437 |
|
|
PL_amagic_generation++; |
| 1438 |
|
|
|
| 1439 |
|
|
return 0; |
| 1440 |
|
|
} |
| 1441 |
|
|
|
| 1442 |
|
|
int |
| 1443 |
|
|
Perl_magic_getnkeys(pTHX_ SV *sv, MAGIC *mg) |
| 1444 |
|
|
{ |
| 1445 |
|
|
HV *hv = (HV*)LvTARG(sv); |
| 1446 |
|
|
I32 i = 0; |
| 1447 |
|
|
|
| 1448 |
|
|
if (hv) { |
| 1449 |
|
|
(void) hv_iterinit(hv); |
| 1450 |
|
|
if (! SvTIED_mg((SV*)hv, PERL_MAGIC_tied)) |
| 1451 |
|
|
i = HvKEYS(hv); |
| 1452 |
|
|
else { |
| 1453 |
|
|
while (hv_iternext(hv)) |
| 1454 |
|
|
i++; |
| 1455 |
|
|
} |
| 1456 |
|
|
} |
| 1457 |
|
|
|
| 1458 |
|
|
sv_setiv(sv, (IV)i); |
| 1459 |
|
|
return 0; |
| 1460 |
|
|
} |
| 1461 |
|
|
|
| 1462 |
|
|
int |
| 1463 |
|
|
Perl_magic_setnkeys(pTHX_ SV *sv, MAGIC *mg) |
| 1464 |
|
|
{ |
| 1465 |
|
|
if (LvTARG(sv)) { |
| 1466 |
|
|
hv_ksplit((HV*)LvTARG(sv), SvIV(sv)); |
| 1467 |
|
|
} |
| 1468 |
|
|
return 0; |
| 1469 |
|
|
} |
| 1470 |
|
|
|
| 1471 |
|
|
/* caller is responsible for stack switching/cleanup */ |
| 1472 |
|
|
STATIC int |
| 1473 |
|
|
S_magic_methcall(pTHX_ SV *sv, MAGIC *mg, char *meth, I32 flags, int n, SV *val) |
| 1474 |
|
|
{ |
| 1475 |
|
|
dSP; |
| 1476 |
|
|
|
| 1477 |
|
|
PUSHMARK(SP); |
| 1478 |
|
|
EXTEND(SP, n); |
| 1479 |
|
|
PUSHs(SvTIED_obj(sv, mg)); |
| 1480 |
|
|
if (n > 1) { |
| 1481 |
|
|
if (mg->mg_ptr) { |
| 1482 |
|
|
if (mg->mg_len >= 0) |
| 1483 |
|
|
PUSHs(sv_2mortal(newSVpvn(mg->mg_ptr, mg->mg_len))); |
| 1484 |
|
|
else if (mg->mg_len == HEf_SVKEY) |
| 1485 |
|
|
PUSHs((SV*)mg->mg_ptr); |
| 1486 |
|
|
} |
| 1487 |
|
|
else if (mg->mg_type == PERL_MAGIC_tiedelem) { |
| 1488 |
|
|
PUSHs(sv_2mortal(newSViv(mg->mg_len))); |
| 1489 |
|
|
} |
| 1490 |
|
|
} |
| 1491 |
|
|
if (n > 2) { |
| 1492 |
|
|
PUSHs(val); |
| 1493 |
|
|
} |
| 1494 |
|
|
PUTBACK; |
| 1495 |
|
|
|
| 1496 |
|
|
return call_method(meth, flags); |
| 1497 |
|
|
} |
| 1498 |
|
|
|
| 1499 |
|
|
STATIC int |
| 1500 |
|
|
S_magic_methpack(pTHX_ SV *sv, MAGIC *mg, char *meth) |
| 1501 |
|
|
{ |
| 1502 |
|
|
dSP; |
| 1503 |
|
|
|
| 1504 |
|
|
ENTER; |
| 1505 |
|
|
SAVETMPS; |
| 1506 |
|
|
PUSHSTACKi(PERLSI_MAGIC); |
| 1507 |
|
|
|
| 1508 |
|
|
if (magic_methcall(sv, mg, meth, G_SCALAR, 2, NULL)) { |
| 1509 |
|
|
sv_setsv(sv, *PL_stack_sp--); |
| 1510 |
|
|
} |
| 1511 |
|
|
|
| 1512 |
|
|
POPSTACK; |
| 1513 |
|
|
FREETMPS; |
| 1514 |
|
|
LEAVE; |
| 1515 |
|
|
return 0; |
| 1516 |
|
|
} |
| 1517 |
|
|
|
| 1518 |
|
|
int |
| 1519 |
|
|
Perl_magic_getpack(pTHX_ SV *sv, MAGIC *mg) |
| 1520 |
|
|
{ |
| 1521 |
|
|
if (mg->mg_ptr) |
| 1522 |
|
|
mg->mg_flags |= MGf_GSKIP; |
| 1523 |
|
|
magic_methpack(sv,mg,"FETCH"); |
| 1524 |
|
|
return 0; |
| 1525 |
|
|
} |
| 1526 |
|
|
|
| 1527 |
|
|
int |
| 1528 |
|
|
Perl_magic_setpack(pTHX_ SV *sv, MAGIC *mg) |
| 1529 |
|
|
{ |
| 1530 |
|
|
dSP; |
| 1531 |
|
|
ENTER; |
| 1532 |
|
|
PUSHSTACKi(PERLSI_MAGIC); |
| 1533 |
|
|
magic_methcall(sv, mg, "STORE", G_SCALAR|G_DISCARD, 3, sv); |
| 1534 |
|
|
POPSTACK; |
| 1535 |
|
|
LEAVE; |
| 1536 |
|
|
return 0; |
| 1537 |
|
|
} |
| 1538 |
|
|
|
| 1539 |
|
|
int |
| 1540 |
|
|
Perl_magic_clearpack(pTHX_ SV *sv, MAGIC *mg) |
| 1541 |
|
|
{ |
| 1542 |
|
|
return magic_methpack(sv,mg,"DELETE"); |
| 1543 |
|
|
} |
| 1544 |
|
|
|
| 1545 |
|
|
|
| 1546 |
|
|
U32 |
| 1547 |
|
|
Perl_magic_sizepack(pTHX_ SV *sv, MAGIC *mg) |
| 1548 |
|
|
{ |
| 1549 |
|
|
dSP; |
| 1550 |
|
|
U32 retval = 0; |
| 1551 |
|
|
|
| 1552 |
|
|
ENTER; |
| 1553 |
|
|
SAVETMPS; |
| 1554 |
|
|
PUSHSTACKi(PERLSI_MAGIC); |
| 1555 |
|
|
if (magic_methcall(sv, mg, "FETCHSIZE", G_SCALAR, 2, NULL)) { |
| 1556 |
|
|
sv = *PL_stack_sp--; |
| 1557 |
|
|
retval = (U32) SvIV(sv)-1; |
| 1558 |
|
|
} |
| 1559 |
|
|
POPSTACK; |
| 1560 |
|
|
FREETMPS; |
| 1561 |
|
|
LEAVE; |
| 1562 |
|
|
return retval; |
| 1563 |
|
|
} |
| 1564 |
|
|
|
| 1565 |
|
|
int |
| 1566 |
|
|
Perl_magic_wipepack(pTHX_ SV *sv, MAGIC *mg) |
| 1567 |
|
|
{ |
| 1568 |
|
|
dSP; |
| 1569 |
|
|
|
| 1570 |
|
|
ENTER; |
| 1571 |
|
|
PUSHSTACKi(PERLSI_MAGIC); |
| 1572 |
|
|
PUSHMARK(SP); |
| 1573 |
|
|
XPUSHs(SvTIED_obj(sv, mg)); |
| 1574 |
|
|
PUTBACK; |
| 1575 |
|
|
call_method("CLEAR", G_SCALAR|G_DISCARD); |
| 1576 |
|
|
POPSTACK; |
| 1577 |
|
|
LEAVE; |
| 1578 |
|
|
|
| 1579 |
|
|
return 0; |
| 1580 |
|
|
} |
| 1581 |
|
|
|
| 1582 |
|
|
int |
| 1583 |
|
|
Perl_magic_nextpack(pTHX_ SV *sv, MAGIC *mg, SV *key) |
| 1584 |
|
|
{ |
| 1585 |
|
|
dSP; |
| 1586 |
|
|
const char *meth = SvOK(key) ? "NEXTKEY" : "FIRSTKEY"; |
| 1587 |
|
|
|
| 1588 |
|
|
ENTER; |
| 1589 |
|
|
SAVETMPS; |
| 1590 |
|
|
PUSHSTACKi(PERLSI_MAGIC); |
| 1591 |
|
|
PUSHMARK(SP); |
| 1592 |
|
|
EXTEND(SP, 2); |
| 1593 |
|
|
PUSHs(SvTIED_obj(sv, mg)); |
| 1594 |
|
|
if (SvOK(key)) |
| 1595 |
|
|
PUSHs(key); |
| 1596 |
|
|
PUTBACK; |
| 1597 |
|
|
|
| 1598 |
|
|
if (call_method(meth, G_SCALAR)) |
| 1599 |
|
|
sv_setsv(key, *PL_stack_sp--); |
| 1600 |
|
|
|
| 1601 |
|
|
POPSTACK; |
| 1602 |
|
|
FREETMPS; |
| 1603 |
|
|
LEAVE; |
| 1604 |
|
|
return 0; |
| 1605 |
|
|
} |
| 1606 |
|
|
|
| 1607 |
|
|
int |
| 1608 |
|
|
Perl_magic_existspack(pTHX_ SV *sv, MAGIC *mg) |
| 1609 |
|
|
{ |
| 1610 |
|
|
return magic_methpack(sv,mg,"EXISTS"); |
| 1611 |
|
|
} |
| 1612 |
|
|
|
| 1613 |
|
|
SV * |
| 1614 |
|
|
Perl_magic_scalarpack(pTHX_ HV *hv, MAGIC *mg) |
| 1615 |
|
|
{ |
| 1616 |
|
|
dSP; |
| 1617 |
|
|
SV *retval = &PL_sv_undef; |
| 1618 |
|
|
SV *tied = SvTIED_obj((SV*)hv, mg); |
| 1619 |
|
|
HV *pkg = SvSTASH((SV*)SvRV(tied)); |
| 1620 |
|
|
|
| 1621 |
|
|
if (!gv_fetchmethod_autoload(pkg, "SCALAR", FALSE)) { |
| 1622 |
|
|
SV *key; |
| 1623 |
|
|
if (HvEITER(hv)) |
| 1624 |
|
|
/* we are in an iteration so the hash cannot be empty */ |
| 1625 |
|
|
return &PL_sv_yes; |
| 1626 |
|
|
/* no xhv_eiter so now use FIRSTKEY */ |
| 1627 |
|
|
key = sv_newmortal(); |
| 1628 |
|
|
magic_nextpack((SV*)hv, mg, key); |
| 1629 |
|
|
HvEITER(hv) = NULL; /* need to reset iterator */ |
| 1630 |
|
|
return SvOK(key) ? &PL_sv_yes : &PL_sv_no; |
| 1631 |
|
|
} |
| 1632 |
|
|
|
| 1633 |
|
|
/* there is a SCALAR method that we can call */ |
| 1634 |
|
|
ENTER; |
| 1635 |
|
|
PUSHSTACKi(PERLSI_MAGIC); |
| 1636 |
|
|
PUSHMARK(SP); |
| 1637 |
|
|
EXTEND(SP, 1); |
| 1638 |
|
|
PUSHs(tied); |
| 1639 |
|
|
PUTBACK; |
| 1640 |
|
|
|
| 1641 |
|
|
if (call_method("SCALAR", G_SCALAR)) |
| 1642 |
|
|
retval = *PL_stack_sp--; |
| 1643 |
|
|
POPSTACK; |
| 1644 |
|
|
LEAVE; |
| 1645 |
|
|
return retval; |
| 1646 |
|
|
} |
| 1647 |
|
|
|
| 1648 |
|
|
int |
| 1649 |
|
|
Perl_magic_setdbline(pTHX_ SV *sv, MAGIC *mg) |
| 1650 |
|
|
{ |
| 1651 |
|
|
OP *o; |
| 1652 |
|
|
I32 i; |
| 1653 |
|
|
GV* gv; |
| 1654 |
|
|
SV** svp; |
| 1655 |
|
|
STRLEN n_a; |
| 1656 |
|
|
|
| 1657 |
|
|
gv = PL_DBline; |
| 1658 |
|
|
i = SvTRUE(sv); |
| 1659 |
|
|
svp = av_fetch(GvAV(gv), |
| 1660 |
|
|
atoi(MgPV(mg,n_a)), FALSE); |
| 1661 |
|
|
if (svp && SvIOKp(*svp) && (o = INT2PTR(OP*,SvIVX(*svp)))) { |
| 1662 |
|
|
/* set or clear breakpoint in the relevant control op */ |
| 1663 |
|
|
if (i) |
| 1664 |
|
|
o->op_flags |= OPf_SPECIAL; |
| 1665 |
|
|
else |
| 1666 |
|
|
o->op_flags &= ~OPf_SPECIAL; |
| 1667 |
|
|
} |
| 1668 |
|
|
return 0; |
| 1669 |
|
|
} |
| 1670 |
|
|
|
| 1671 |
|
|
int |
| 1672 |
|
|
Perl_magic_getarylen(pTHX_ SV *sv, MAGIC *mg) |
| 1673 |
|
|
{ |
| 1674 |
|
|
sv_setiv(sv, AvFILL((AV*)mg->mg_obj) + PL_curcop->cop_arybase); |
| 1675 |
|
|
return 0; |
| 1676 |
|
|
} |
| 1677 |
|
|
|
| 1678 |
|
|
int |
| 1679 |
|
|
Perl_magic_setarylen(pTHX_ SV *sv, MAGIC *mg) |
| 1680 |
|
|
{ |
| 1681 |
|
|
av_fill((AV*)mg->mg_obj, SvIV(sv) - PL_curcop->cop_arybase); |
| 1682 |
|
|
return 0; |
| 1683 |
|
|
} |
| 1684 |
|
|
|
| 1685 |
|
|
int |
| 1686 |
|
|
Perl_magic_getpos(pTHX_ SV *sv, MAGIC *mg) |
| 1687 |
|
|
{ |
| 1688 |
|
|
SV* lsv = LvTARG(sv); |
| 1689 |
|
|
|
| 1690 |
|
|
if (SvTYPE(lsv) >= SVt_PVMG && SvMAGIC(lsv)) { |
| 1691 |
|
|
mg = mg_find(lsv, PERL_MAGIC_regex_global); |
| 1692 |
|
|
if (mg && mg->mg_len >= 0) { |
| 1693 |
|
|
I32 i = mg->mg_len; |
| 1694 |
|
|
if (DO_UTF8(lsv)) |
| 1695 |
|
|
sv_pos_b2u(lsv, &i); |
| 1696 |
|
|
sv_setiv(sv, i + PL_curcop->cop_arybase); |
| 1697 |
|
|
return 0; |
| 1698 |
|
|
} |
| 1699 |
|
|
} |
| 1700 |
|
|
SvOK_off(sv); |
| 1701 |
|
|
return 0; |
| 1702 |
|
|
} |
| 1703 |
|
|
|
| 1704 |
|
|
int |
| 1705 |
|
|
Perl_magic_setpos(pTHX_ SV *sv, MAGIC *mg) |
| 1706 |
|
|
{ |
| 1707 |
|
|
SV* lsv = LvTARG(sv); |
| 1708 |
|
|
SSize_t pos; |
| 1709 |
|
|
STRLEN len; |
| 1710 |
|
|
STRLEN ulen = 0; |
| 1711 |
|
|
|
| 1712 |
|
|
mg = 0; |
| 1713 |
|
|
|
| 1714 |
|
|
if (SvTYPE(lsv) >= SVt_PVMG && SvMAGIC(lsv)) |
| 1715 |
|
|
mg = mg_find(lsv, PERL_MAGIC_regex_global); |
| 1716 |
|
|
if (!mg) { |
| 1717 |
|
|
if (!SvOK(sv)) |
| 1718 |
|
|
return 0; |
| 1719 |
|
|
sv_magic(lsv, (SV*)0, PERL_MAGIC_regex_global, Nullch, 0); |
| 1720 |
|
|
mg = mg_find(lsv, PERL_MAGIC_regex_global); |
| 1721 |
|
|
} |
| 1722 |
|
|
else if (!SvOK(sv)) { |
| 1723 |
|
|
mg->mg_len = -1; |
| 1724 |
|
|
return 0; |
| 1725 |
|
|
} |
| 1726 |
|
|
len = SvPOK(lsv) ? SvCUR(lsv) : sv_len(lsv); |
| 1727 |
|
|
|
| 1728 |
|
|
pos = SvIV(sv) - PL_curcop->cop_arybase; |
| 1729 |
|
|
|
| 1730 |
|
|
if (DO_UTF8(lsv)) { |
| 1731 |
|
|
ulen = sv_len_utf8(lsv); |
| 1732 |
|
|
if (ulen) |
| 1733 |
|
|
len = ulen; |
| 1734 |
|
|
} |
| 1735 |
|
|
|
| 1736 |
|
|
if (pos < 0) { |
| 1737 |
|
|
pos += len; |
| 1738 |
|
|
if (pos < 0) |
| 1739 |
|
|
pos = 0; |
| 1740 |
|
|
} |
| 1741 |
|
|
else if (pos > (SSize_t)len) |
| 1742 |
|
|
pos = len; |
| 1743 |
|
|
|
| 1744 |
|
|
if (ulen) { |
| 1745 |
|
|
I32 p = pos; |
| 1746 |
|
|
sv_pos_u2b(lsv, &p, 0); |
| 1747 |
|
|
pos = p; |
| 1748 |
|
|
} |
| 1749 |
|
|
|
| 1750 |
|
|
mg->mg_len = pos; |
| 1751 |
|
|
mg->mg_flags &= ~MGf_MINMATCH; |
| 1752 |
|
|
|
| 1753 |
|
|
return 0; |
| 1754 |
|
|
} |
| 1755 |
|
|
|
| 1756 |
|
|
int |
| 1757 |
|
|
Perl_magic_getglob(pTHX_ SV *sv, MAGIC *mg) |
| 1758 |
|
|
{ |
| 1759 |
|
|
if (SvFAKE(sv)) { /* FAKE globs can get coerced */ |
| 1760 |
|
|
SvFAKE_off(sv); |
| 1761 |
|
|
gv_efullname3(sv,((GV*)sv), "*"); |
| 1762 |
|
|
SvFAKE_on(sv); |
| 1763 |
|
|
} |
| 1764 |
|
|
else |
| 1765 |
|
|
gv_efullname3(sv,((GV*)sv), "*"); /* a gv value, be nice */ |
| 1766 |
|
|
return 0; |
| 1767 |
|
|
} |
| 1768 |
|
|
|
| 1769 |
|
|
int |
| 1770 |
|
|
Perl_magic_setglob(pTHX_ SV *sv, MAGIC *mg) |
| 1771 |
|
|
{ |
| 1772 |
|
|
register char *s; |
| 1773 |
|
|
GV* gv; |
| 1774 |
|
|
STRLEN n_a; |
| 1775 |
|
|
|
| 1776 |
|
|
if (!SvOK(sv)) |
| 1777 |
|
|
return 0; |
| 1778 |
|
|
s = SvPV(sv, n_a); |
| 1779 |
|
|
if (*s == '*' && s[1]) |
| 1780 |
|
|
s++; |
| 1781 |
|
|
gv = gv_fetchpv(s,TRUE, SVt_PVGV); |
| 1782 |
|
|
if (sv == (SV*)gv) |
| 1783 |
|
|
return 0; |
| 1784 |
|
|
if (GvGP(sv)) |
| 1785 |
|
|
gp_free((GV*)sv); |
| 1786 |
|
|
GvGP(sv) = gp_ref(GvGP(gv)); |
| 1787 |
|
|
return 0; |
| 1788 |
|
|
} |
| 1789 |
|
|
|
| 1790 |
|
|
int |
| 1791 |
|
|
Perl_magic_getsubstr(pTHX_ SV *sv, MAGIC *mg) |
| 1792 |
|
|
{ |
| 1793 |
|
|
STRLEN len; |
| 1794 |
|
|
SV *lsv = LvTARG(sv); |
| 1795 |
|
|
char *tmps = SvPV(lsv,len); |
| 1796 |
|
|
I32 offs = LvTARGOFF(sv); |
| 1797 |
|
|
I32 rem = LvTARGLEN(sv); |
| 1798 |
|
|
|
| 1799 |
|
|
if (SvUTF8(lsv)) |
| 1800 |
|
|
sv_pos_u2b(lsv, &offs, &rem); |
| 1801 |
|
|
if (offs > (I32)len) |
| 1802 |
|
|
offs = len; |
| 1803 |
|
|
if (rem + offs > (I32)len) |
| 1804 |
|
|
rem = len - offs; |
| 1805 |
|
|
sv_setpvn(sv, tmps + offs, (STRLEN)rem); |
| 1806 |
|
|
if (SvUTF8(lsv)) |
| 1807 |
|
|
SvUTF8_on(sv); |
| 1808 |
|
|
return 0; |
| 1809 |
|
|
} |
| 1810 |
|
|
|
| 1811 |
|
|
int |
| 1812 |
|
|
Perl_magic_setsubstr(pTHX_ SV *sv, MAGIC *mg) |
| 1813 |
|
|
{ |
| 1814 |
|
|
STRLEN len; |
| 1815 |
|
|
char *tmps = SvPV(sv, len); |
| 1816 |
|
|
SV *lsv = LvTARG(sv); |
| 1817 |
|
|
I32 lvoff = LvTARGOFF(sv); |
| 1818 |
|
|
I32 lvlen = LvTARGLEN(sv); |
| 1819 |
|
|
|
| 1820 |
|
|
if (DO_UTF8(sv)) { |
| 1821 |
|
|
sv_utf8_upgrade(lsv); |
| 1822 |
|
|
sv_pos_u2b(lsv, &lvoff, &lvlen); |
| 1823 |
|
|
sv_insert(lsv, lvoff, lvlen, tmps, len); |
| 1824 |
|
|
SvUTF8_on(lsv); |
| 1825 |
|
|
} |
| 1826 |
|
|
else if (lsv && SvUTF8(lsv)) { |
| 1827 |
|
|
sv_pos_u2b(lsv, &lvoff, &lvlen); |
| 1828 |
|
|
tmps = (char*)bytes_to_utf8((U8*)tmps, &len); |
| 1829 |
|
|
sv_insert(lsv, lvoff, lvlen, tmps, len); |
| 1830 |
|
|
Safefree(tmps); |
| 1831 |
|
|
} |
| 1832 |
|
|
else |
| 1833 |
|
|
sv_insert(lsv, lvoff, lvlen, tmps, len); |
| 1834 |
|
|
|
| 1835 |
|
|
return 0; |
| 1836 |
|
|
} |
| 1837 |
|
|
|
| 1838 |
|
|
int |
| 1839 |
|
|
Perl_magic_gettaint(pTHX_ SV *sv, MAGIC *mg) |
| 1840 |
|
|
{ |
| 1841 |
|
|
TAINT_IF((mg->mg_len & 1) || |
| 1842 |
|
|
((mg->mg_len & 2) && mg->mg_obj == sv)); /* kludge */ |
| 1843 |
|
|
return 0; |
| 1844 |
|
|
} |
| 1845 |
|
|
|
| 1846 |
|
|
int |
| 1847 |
|
|
Perl_magic_settaint(pTHX_ SV *sv, MAGIC *mg) |
| 1848 |
|
|
{ |
| 1849 |
|
|
if (PL_localizing) { |
| 1850 |
|
|
if (PL_localizing == 1) |
| 1851 |
|
|
mg->mg_len <<= 1; |
| 1852 |
|
|
else |
| 1853 |
|
|
mg->mg_len >>= 1; |
| 1854 |
|
|
} |
| 1855 |
|
|
else if (PL_tainted) |
| 1856 |
|
|
mg->mg_len |= 1; |
| 1857 |
|
|
else |
| 1858 |
|
|
mg->mg_len &= ~1; |
| 1859 |
|
|
return 0; |
| 1860 |
|
|
} |
| 1861 |
|
|
|
| 1862 |
|
|
int |
| 1863 |
|
|
Perl_magic_getvec(pTHX_ SV *sv, MAGIC *mg) |
| 1864 |
|
|
{ |
| 1865 |
|
|
SV *lsv = LvTARG(sv); |
| 1866 |
|
|
|
| 1867 |
|
|
if (!lsv) { |
| 1868 |
|
|
SvOK_off(sv); |
| 1869 |
|
|
return 0; |
| 1870 |
|
|
} |
| 1871 |
|
|
|
| 1872 |
|
|
sv_setuv(sv, do_vecget(lsv, LvTARGOFF(sv), LvTARGLEN(sv))); |
| 1873 |
|
|
return 0; |
| 1874 |
|
|
} |
| 1875 |
|
|
|
| 1876 |
|
|
int |
| 1877 |
|
|
Perl_magic_setvec(pTHX_ SV *sv, MAGIC *mg) |
| 1878 |
|
|
{ |
| 1879 |
|
|
do_vecset(sv); /* XXX slurp this routine */ |
| 1880 |
|
|
return 0; |
| 1881 |
|
|
} |
| 1882 |
|
|
|
| 1883 |
|
|
int |
| 1884 |
|
|
Perl_magic_getdefelem(pTHX_ SV *sv, MAGIC *mg) |
| 1885 |
|
|
{ |
| 1886 |
|
|
SV *targ = Nullsv; |
| 1887 |
|
|
if (LvTARGLEN(sv)) { |
| 1888 |
|
|
if (mg->mg_obj) { |
| 1889 |
|
|
SV *ahv = LvTARG(sv); |
| 1890 |
|
|
if (SvTYPE(ahv) == SVt_PVHV) { |
| 1891 |
|
|
HE *he = hv_fetch_ent((HV*)ahv, mg->mg_obj, FALSE, 0); |
| 1892 |
|
|
if (he) |
| 1893 |
|
|
targ = HeVAL(he); |
| 1894 |
|
|
} |
| 1895 |
|
|
else { |
| 1896 |
|
|
SV **svp = avhv_fetch_ent((AV*)ahv, mg->mg_obj, FALSE, 0); |
| 1897 |
|
|
if (svp) |
| 1898 |
|
|
targ = *svp; |
| 1899 |
|
|
} |
| 1900 |
|
|
} |
| 1901 |
|
|
else { |
| 1902 |
|
|
AV* av = (AV*)LvTARG(sv); |
| 1903 |
|
|
if ((I32)LvTARGOFF(sv) <= AvFILL(av)) |
| 1904 |
|
|
targ = AvARRAY(av)[LvTARGOFF(sv)]; |
| 1905 |
|
|
} |
| 1906 |
|
|
if (targ && targ != &PL_sv_undef) { |
| 1907 |
|
|
/* somebody else defined it for us */ |
| 1908 |
|
|
SvREFCNT_dec(LvTARG(sv)); |
| 1909 |
|
|
LvTARG(sv) = SvREFCNT_inc(targ); |
| 1910 |
|
|
LvTARGLEN(sv) = 0; |
| 1911 |
|
|
SvREFCNT_dec(mg->mg_obj); |
| 1912 |
|
|
mg->mg_obj = Nullsv; |
| 1913 |
|
|
mg->mg_flags &= ~MGf_REFCOUNTED; |
| 1914 |
|
|
} |
| 1915 |
|
|
} |
| 1916 |
|
|
else |
| 1917 |
|
|
targ = LvTARG(sv); |
| 1918 |
|
|
sv_setsv(sv, targ ? targ : &PL_sv_undef); |
| 1919 |
|
|
return 0; |
| 1920 |
|
|
} |
| 1921 |
|
|
|
| 1922 |
|
|
int |
| 1923 |
|
|
Perl_magic_setdefelem(pTHX_ SV *sv, MAGIC *mg) |
| 1924 |
|
|
{ |
| 1925 |
|
|
if (LvTARGLEN(sv)) |
| 1926 |
|
|
vivify_defelem(sv); |
| 1927 |
|
|
if (LvTARG(sv)) { |
| 1928 |
|
|
sv_setsv(LvTARG(sv), sv); |
| 1929 |
|
|
SvSETMAGIC(LvTARG(sv)); |
| 1930 |
|
|
} |
| 1931 |
|
|
return 0; |
| 1932 |
|
|
} |
| 1933 |
|
|
|
| 1934 |
|
|
void |
| 1935 |
|
|
Perl_vivify_defelem(pTHX_ SV *sv) |
| 1936 |
|
|
{ |
| 1937 |
|
|
MAGIC *mg; |
| 1938 |
|
|
SV *value = Nullsv; |
| 1939 |
|
|
|
| 1940 |
|
|
if (!LvTARGLEN(sv) || !(mg = mg_find(sv, PERL_MAGIC_defelem))) |
| 1941 |
|
|
return; |
| 1942 |
|
|
if (mg->mg_obj) { |
| 1943 |
|
|
SV *ahv = LvTARG(sv); |
| 1944 |
|
|
STRLEN n_a; |
| 1945 |
|
|
if (SvTYPE(ahv) == SVt_PVHV) { |
| 1946 |
|
|
HE *he = hv_fetch_ent((HV*)ahv, mg->mg_obj, TRUE, 0); |
| 1947 |
|
|
if (he) |
| 1948 |
|
|
value = HeVAL(he); |
| 1949 |
|
|
} |
| 1950 |
|
|
else { |
| 1951 |
|
|
SV **svp = avhv_fetch_ent((AV*)ahv, mg->mg_obj, TRUE, 0); |
| 1952 |
|
|
if (svp) |
| 1953 |
|
|
value = *svp; |
| 1954 |
|
|
} |
| 1955 |
|
|
if (!value || value == &PL_sv_undef) |
| 1956 |
|
|
Perl_croak(aTHX_ PL_no_helem, SvPV(mg->mg_obj, n_a)); |
| 1957 |
|
|
} |
| 1958 |
|
|
else { |
| 1959 |
|
|
AV* av = (AV*)LvTARG(sv); |
| 1960 |
|
|
if ((I32)LvTARGLEN(sv) < 0 && (I32)LvTARGOFF(sv) > AvFILL(av)) |
| 1961 |
|
|
LvTARG(sv) = Nullsv; /* array can't be extended */ |
| 1962 |
|
|
else { |
| 1963 |
|
|
SV** svp = av_fetch(av, LvTARGOFF(sv), TRUE); |
| 1964 |
|
|
if (!svp || (value = *svp) == &PL_sv_undef) |
| 1965 |
|
|
Perl_croak(aTHX_ PL_no_aelem, (I32)LvTARGOFF(sv)); |
| 1966 |
|
|
} |
| 1967 |
|
|
} |
| 1968 |
|
|
(void)SvREFCNT_inc(value); |
| 1969 |
|
|
SvREFCNT_dec(LvTARG(sv)); |
| 1970 |
|
|
LvTARG(sv) = value; |
| 1971 |
|
|
LvTARGLEN(sv) = 0; |
| 1972 |
|
|
SvREFCNT_dec(mg->mg_obj); |
| 1973 |
|
|
mg->mg_obj = Nullsv; |
| 1974 |
|
|
mg->mg_flags &= ~MGf_REFCOUNTED; |
| 1975 |
|
|
} |
| 1976 |
|
|
|
| 1977 |
|
|
int |
| 1978 |
|
|
Perl_magic_killbackrefs(pTHX_ SV *sv, MAGIC *mg) |
| 1979 |
|
|
{ |
| 1980 |
|
|
AV *av = (AV*)mg->mg_obj; |
| 1981 |
|
|
SV **svp = AvARRAY(av); |
| 1982 |
|
|
I32 i = AvFILLp(av); |
| 1983 |
|
|
while (i >= 0) { |
| 1984 |
|
|
if (svp[i]) { |
| 1985 |
|
|
if (!SvWEAKREF(svp[i])) |
| 1986 |
|
|
Perl_croak(aTHX_ "panic: magic_killbackrefs"); |
| 1987 |
|
|
/* XXX Should we check that it hasn't changed? */ |
| 1988 |
|
|
SvRV(svp[i]) = 0; |
| 1989 |
|
|
SvOK_off(svp[i]); |
| 1990 |
|
|
SvWEAKREF_off(svp[i]); |
| 1991 |
|
|
svp[i] = Nullsv; |
| 1992 |
|
|
} |
| 1993 |
|
|
i--; |
| 1994 |
|
|
} |
| 1995 |
|
|
SvREFCNT_dec(av); /* remove extra count added by sv_add_backref() */ |
| 1996 |
|
|
return 0; |
| 1997 |
|
|
} |
| 1998 |
|
|
|
| 1999 |
|
|
int |
| 2000 |
|
|
Perl_magic_setmglob(pTHX_ SV *sv, MAGIC *mg) |
| 2001 |
|
|
{ |
| 2002 |
|
|
mg->mg_len = -1; |
| 2003 |
|
|
SvSCREAM_off(sv); |
| 2004 |
|
|
return 0; |
| 2005 |
|
|
} |
| 2006 |
|
|
|
| 2007 |
|
|
int |
| 2008 |
|
|
Perl_magic_setbm(pTHX_ SV *sv, MAGIC *mg) |
| 2009 |
|
|
{ |
| 2010 |
|
|
sv_unmagic(sv, PERL_MAGIC_bm); |
| 2011 |
|
|
SvVALID_off(sv); |
| 2012 |
|
|
return 0; |
| 2013 |
|
|
} |
| 2014 |
|
|
|
| 2015 |
|
|
int |
| 2016 |
|
|
Perl_magic_setfm(pTHX_ SV *sv, MAGIC *mg) |
| 2017 |
|
|
{ |
| 2018 |
|
|
sv_unmagic(sv, PERL_MAGIC_fm); |
| 2019 |
|
|
SvCOMPILED_off(sv); |
| 2020 |
|
|
return 0; |
| 2021 |
|
|
} |
| 2022 |
|
|
|
| 2023 |
|
|
int |
| 2024 |
|
|
Perl_magic_setuvar(pTHX_ SV *sv, MAGIC *mg) |
| 2025 |
|
|
{ |
| 2026 |
|
|
struct ufuncs *uf = (struct ufuncs *)mg->mg_ptr; |
| 2027 |
|
|
|
| 2028 |
|
|
if (uf && uf->uf_set) |
| 2029 |
|
|
(*uf->uf_set)(aTHX_ uf->uf_index, sv); |
| 2030 |
|
|
return 0; |
| 2031 |
|
|
} |
| 2032 |
|
|
|
| 2033 |
|
|
int |
| 2034 |
|
|
Perl_magic_setregexp(pTHX_ SV *sv, MAGIC *mg) |
| 2035 |
|
|
{ |
| 2036 |
|
|
sv_unmagic(sv, PERL_MAGIC_qr); |
| 2037 |
|
|
return 0; |
| 2038 |
|
|
} |
| 2039 |
|
|
|
| 2040 |
|
|
int |
| 2041 |
|
|
Perl_magic_freeregexp(pTHX_ SV *sv, MAGIC *mg) |
| 2042 |
|
|
{ |
| 2043 |
|
|
regexp *re = (regexp *)mg->mg_obj; |
| 2044 |
|
|
ReREFCNT_dec(re); |
| 2045 |
|
|
return 0; |
| 2046 |
|
|
} |
| 2047 |
|
|
|
| 2048 |
|
|
#ifdef USE_LOCALE_COLLATE |
| 2049 |
|
|
int |
| 2050 |
|
|
Perl_magic_setcollxfrm(pTHX_ SV *sv, MAGIC *mg) |
| 2051 |
|
|
{ |
| 2052 |
|
|
/* |
| 2053 |
|
|
* RenE<eacute> Descartes said "I think not." |
| 2054 |
|
|
* and vanished with a faint plop. |
| 2055 |
|
|
*/ |
| 2056 |
|
|
if (mg->mg_ptr) { |
| 2057 |
|
|
Safefree(mg->mg_ptr); |
| 2058 |
|
|
mg->mg_ptr = NULL; |
| 2059 |
|
|
mg->mg_len = -1; |
| 2060 |
|
|
} |
| 2061 |
|
|
return 0; |
| 2062 |
|
|
} |
| 2063 |
|
|
#endif /* USE_LOCALE_COLLATE */ |
| 2064 |
|
|
|
| 2065 |
|
|
/* Just clear the UTF-8 cache data. */ |
| 2066 |
|
|
int |
| 2067 |
|
|
Perl_magic_setutf8(pTHX_ SV *sv, MAGIC *mg) |
| 2068 |
|
|
{ |
| 2069 |
|
|
Safefree(mg->mg_ptr); /* The mg_ptr holds the pos cache. */ |
| 2070 |
|
|
mg->mg_ptr = 0; |
| 2071 |
|
|
mg->mg_len = -1; /* The mg_len holds the len cache. */ |
| 2072 |
|
|
return 0; |
| 2073 |
|
|
} |
| 2074 |
|
|
|
| 2075 |
|
|
int |
| 2076 |
|
|
Perl_magic_set(pTHX_ SV *sv, MAGIC *mg) |
| 2077 |
|
|
{ |
| 2078 |
|
|
register char *s; |
| 2079 |
|
|
I32 i; |
| 2080 |
|
|
STRLEN len; |
| 2081 |
|
|
switch (*mg->mg_ptr) { |
| 2082 |
|
|
case '\001': /* ^A */ |
| 2083 |
|
|
sv_setsv(PL_bodytarget, sv); |
| 2084 |
|
|
break; |
| 2085 |
|
|
case '\003': /* ^C */ |
| 2086 |
|
|
PL_minus_c = (bool)(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv)); |
| 2087 |
|
|
break; |
| 2088 |
|
|
|
| 2089 |
|
|
case '\004': /* ^D */ |
| 2090 |
|
|
#ifdef DEBUGGING |
| 2091 |
|
|
s = SvPV_nolen(sv); |
| 2092 |
|
|
PL_debug = get_debug_opts_flags(&s, 0) | DEBUG_TOP_FLAG; |
| 2093 |
|
|
DEBUG_x(dump_all()); |
| 2094 |
|
|
#else |
| 2095 |
|
|
PL_debug = (SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv)) | DEBUG_TOP_FLAG; |
| 2096 |
|
|
#endif |
| 2097 |
|
|
break; |
| 2098 |
|
|
case '\005': /* ^E */ |
| 2099 |
|
|
if (*(mg->mg_ptr+1) == '\0') { |
| 2100 |
|
|
#ifdef MACOS_TRADITIONAL |
| 2101 |
|
|
gMacPerl_OSErr = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv); |
| 2102 |
|
|
#else |
| 2103 |
|
|
# ifdef VMS |
| 2104 |
|
|
set_vaxc_errno(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv)); |
| 2105 |
|
|
# else |
| 2106 |
|
|
# ifdef WIN32 |
| 2107 |
|
|
SetLastError( SvIV(sv) ); |
| 2108 |
|
|
# else |
| 2109 |
|
|
# ifdef OS2 |
| 2110 |
|
|
os2_setsyserrno(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv)); |
| 2111 |
|
|
# else |
| 2112 |
|
|
/* will anyone ever use this? */ |
| 2113 |
|
|
SETERRNO(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv), 4); |
| 2114 |
|
|
# endif |
| 2115 |
|
|
# endif |
| 2116 |
|
|
# endif |
| 2117 |
|
|
#endif |
| 2118 |
|
|
} |
| 2119 |
|
|
else if (strEQ(mg->mg_ptr+1, "NCODING")) { |
| 2120 |
|
|
if (PL_encoding) |
| 2121 |
|
|
SvREFCNT_dec(PL_encoding); |
| 2122 |
|
|
if (SvOK(sv) || SvGMAGICAL(sv)) { |
| 2123 |
|
|
PL_encoding = newSVsv(sv); |
| 2124 |
|
|
} |
| 2125 |
|
|
else { |
| 2126 |
|
|
PL_encoding = Nullsv; |
| 2127 |
|
|
} |
| 2128 |
|
|
} |
| 2129 |
|
|
break; |
| 2130 |
|
|
case '\006': /* ^F */ |
| 2131 |
|
|
PL_maxsysfd = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv); |
| 2132 |
|
|
break; |
| 2133 |
|
|
case '\010': /* ^H */ |
| 2134 |
|
|
PL_hints = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv); |
| 2135 |
|
|
break; |
| 2136 |
|
|
case '\011': /* ^I */ /* NOT \t in EBCDIC */ |
| 2137 |
|
|
if (PL_inplace) |
| 2138 |
|
|
Safefree(PL_inplace); |
| 2139 |
|
|
if (SvOK(sv)) |
| 2140 |
|
|
PL_inplace = savesvpv(sv); |
| 2141 |
|
|
else |
| 2142 |
|
|
PL_inplace = Nullch; |
| 2143 |
|
|
break; |
| 2144 |
|
|
case '\017': /* ^O */ |
| 2145 |
|
|
if (*(mg->mg_ptr+1) == '\0') { |
| 2146 |
|
|
if (PL_osname) { |
| 2147 |
|
|
Safefree(PL_osname); |
| 2148 |
|
|
PL_osname = Nullch; |
| 2149 |
|
|
} |
| 2150 |
|
|
if (SvOK(sv)) { |
| 2151 |
|
|
TAINT_PROPER("assigning to $^O"); |
| 2152 |
|
|
PL_osname = savesvpv(sv); |
| 2153 |
|
|
} |
| 2154 |
|
|
} |
| 2155 |
|
|
else if (strEQ(mg->mg_ptr, "\017PEN")) { |
| 2156 |
|
|
if (!PL_compiling.cop_io) |
| 2157 |
|
|
PL_compiling.cop_io = newSVsv(sv); |
| 2158 |
|
|
else |
| 2159 |
|
|
sv_setsv(PL_compiling.cop_io,sv); |
| 2160 |
|
|
} |
| 2161 |
|
|
break; |
| 2162 |
|
|
case '\020': /* ^P */ |
| 2163 |
|
|
PL_perldb = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv); |
| 2164 |
|
|
if (PL_perldb && !PL_DBsingle) |
| 2165 |
|
|
init_debugger(); |
| 2166 |
|
|
break; |
| 2167 |
|
|
case '\024': /* ^T */ |
| 2168 |
|
|
#ifdef BIG_TIME |
| 2169 |
|
|
PL_basetime = (Time_t)(SvNOK(sv) ? SvNVX(sv) : sv_2nv(sv)); |
| 2170 |
|
|
#else |
| 2171 |
|
|
PL_basetime = (Time_t)(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv)); |
| 2172 |
|
|
#endif |
| 2173 |
|
|
break; |
| 2174 |
|
|
case '\027': /* ^W & $^WARNING_BITS */ |
| 2175 |
|
|
if (*(mg->mg_ptr+1) == '\0') { |
| 2176 |
|
|
if ( ! (PL_dowarn & G_WARN_ALL_MASK)) { |
| 2177 |
|
|
i = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv); |
| 2178 |
|
|
PL_dowarn = (PL_dowarn & ~G_WARN_ON) |
| 2179 |
|
|
| (i ? G_WARN_ON : G_WARN_OFF) ; |
| 2180 |
|
|
} |
| 2181 |
|
|
} |
| 2182 |
|
|
else if (strEQ(mg->mg_ptr+1, "ARNING_BITS")) { |
| 2183 |
|
|
if ( ! (PL_dowarn & G_WARN_ALL_MASK)) { |
| 2184 |
|
|
if (!SvPOK(sv) && PL_localizing) { |
| 2185 |
|
|
sv_setpvn(sv, WARN_NONEstring, WARNsize); |
| 2186 |
|
|
PL_compiling.cop_warnings = pWARN_NONE; |
| 2187 |
|
|
break; |
| 2188 |
|
|
} |
| 2189 |
|
|
{ |
| 2190 |
|
|
STRLEN len, i; |
| 2191 |
|
|
int accumulate = 0 ; |
| 2192 |
|
|
int any_fatals = 0 ; |
| 2193 |
|
|
char * ptr = (char*)SvPV(sv, len) ; |
| 2194 |
|
|
for (i = 0 ; i < len ; ++i) { |
| 2195 |
|
|
accumulate |= ptr[i] ; |
| 2196 |
|
|
any_fatals |= (ptr[i] & 0xAA) ; |
| 2197 |
|
|
} |
| 2198 |
|
|
if (!accumulate) |
| 2199 |
|
|
PL_compiling.cop_warnings = pWARN_NONE; |
| 2200 |
|
|
else if (isWARN_on(sv, WARN_ALL) && !any_fatals) { |
| 2201 |
|
|
PL_compiling.cop_warnings = pWARN_ALL; |
| 2202 |
|
|
PL_dowarn |= G_WARN_ONCE ; |
| 2203 |
|
|
} |
| 2204 |
|
|
else { |
| 2205 |
|
|
if (specialWARN(PL_compiling.cop_warnings)) |
| 2206 |
|
|
PL_compiling.cop_warnings = newSVsv(sv) ; |
| 2207 |
|
|
else |
| 2208 |
|
|
sv_setsv(PL_compiling.cop_warnings, sv); |
| 2209 |
|
|
if (isWARN_on(PL_compiling.cop_warnings, WARN_ONCE)) |
| 2210 |
|
|
PL_dowarn |= G_WARN_ONCE ; |
| 2211 |
|
|
} |
| 2212 |
|
|
|
| 2213 |
|
|
} |
| 2214 |
|
|
} |
| 2215 |
|
|
} |
| 2216 |
|
|
break; |
| 2217 |
|
|
case '.': |
| 2218 |
|
|
if (PL_localizing) { |
| 2219 |
|
|
if (PL_localizing == 1) |
| 2220 |
|
|
SAVESPTR(PL_last_in_gv); |
| 2221 |
|
|
} |
| 2222 |
|
|
else if (SvOK(sv) && GvIO(PL_last_in_gv)) |
| 2223 |
|
|
IoLINES(GvIOp(PL_last_in_gv)) = SvIV(sv); |
| 2224 |
|
|
break; |
| 2225 |
|
|
case '^': |
| 2226 |
|
|
Safefree(IoTOP_NAME(GvIOp(PL_defoutgv))); |
| 2227 |
|
|
IoTOP_NAME(GvIOp(PL_defoutgv)) = s = savesvpv(sv); |
| 2228 |
|
|
IoTOP_GV(GvIOp(PL_defoutgv)) = gv_fetchpv(s,TRUE, SVt_PVIO); |
| 2229 |
|
|
break; |
| 2230 |
|
|
case '~': |
| 2231 |
|
|
Safefree(IoFMT_NAME(GvIOp(PL_defoutgv))); |
| 2232 |
|
|
IoFMT_NAME(GvIOp(PL_defoutgv)) = s = savesvpv(sv); |
| 2233 |
|
|
IoFMT_GV(GvIOp(PL_defoutgv)) = gv_fetchpv(s,TRUE, SVt_PVIO); |
| 2234 |
|
|
break; |
| 2235 |
|
|
case '=': |
| 2236 |
|
|
IoPAGE_LEN(GvIOp(PL_defoutgv)) = (SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv)); |
| 2237 |
|
|
break; |
| 2238 |
|
|
case '-': |
| 2239 |
|
|
IoLINES_LEFT(GvIOp(PL_defoutgv)) = (SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv)); |
| 2240 |
|
|
if (IoLINES_LEFT(GvIOp(PL_defoutgv)) < 0L) |
| 2241 |
|
|
IoLINES_LEFT(GvIOp(PL_defoutgv)) = 0L; |
| 2242 |
|
|
break; |
| 2243 |
|
|
case '%': |
| 2244 |
|
|
IoPAGE(GvIOp(PL_defoutgv)) = (SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv)); |
| 2245 |
|
|
break; |
| 2246 |
|
|
case '|': |
| 2247 |
|
|
{ |
| 2248 |
|
|
IO *io = GvIOp(PL_defoutgv); |
| 2249 |
|
|
if(!io) |
| 2250 |
|
|
break; |
| 2251 |
|
|
if ((SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv)) == 0) |
| 2252 |
|
|
IoFLAGS(io) &= ~IOf_FLUSH; |
| 2253 |
|
|
else { |
| 2254 |
|
|
if (!(IoFLAGS(io) & IOf_FLUSH)) { |
| 2255 |
|
|
PerlIO *ofp = IoOFP(io); |
| 2256 |
|
|
if (ofp) |
| 2257 |
|
|
(void)PerlIO_flush(ofp); |
| 2258 |
|
|
IoFLAGS(io) |= IOf_FLUSH; |
| 2259 |
|
|
} |
| 2260 |
|
|
} |
| 2261 |
|
|
} |
| 2262 |
|
|
break; |
| 2263 |
|
|
case '*': |
| 2264 |
|
|
i = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv); |
| 2265 |
|
|
PL_multiline = (i != 0); |
| 2266 |
|
|
break; |
| 2267 |
|
|
case '/': |
| 2268 |
|
|
SvREFCNT_dec(PL_rs); |
| 2269 |
|
|
PL_rs = newSVsv(sv); |
| 2270 |
|
|
break; |
| 2271 |
|
|
case '\\': |
| 2272 |
|
|
if (PL_ors_sv) |
| 2273 |
|
|
SvREFCNT_dec(PL_ors_sv); |
| 2274 |
|
|
if (SvOK(sv) || SvGMAGICAL(sv)) { |
| 2275 |
|
|
PL_ors_sv = newSVsv(sv); |
| 2276 |
|
|
} |
| 2277 |
|
|
else { |
| 2278 |
|
|
PL_ors_sv = Nullsv; |
| 2279 |
|
|
} |
| 2280 |
|
|
break; |
| 2281 |
|
|
case ',': |
| 2282 |
|
|
if (PL_ofs_sv) |
| 2283 |
|
|
SvREFCNT_dec(PL_ofs_sv); |
| 2284 |
|
|
if (SvOK(sv) || SvGMAGICAL(sv)) { |
| 2285 |
|
|
PL_ofs_sv = newSVsv(sv); |
| 2286 |
|
|
} |
| 2287 |
|
|
else { |
| 2288 |
|
|
PL_ofs_sv = Nullsv; |
| 2289 |
|
|
} |
| 2290 |
|
|
break; |
| 2291 |
|
|
case '#': |
| 2292 |
|
|
if (PL_ofmt) |
| 2293 |
|
|
Safefree(PL_ofmt); |
| 2294 |
|
|
PL_ofmt = savesvpv(sv); |
| 2295 |
|
|
break; |
| 2296 |
|
|
case '[': |
| 2297 |
|
|
PL_compiling.cop_arybase = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv); |
| 2298 |
|
|
break; |
| 2299 |
|
|
case '?': |
| 2300 |
|
|
#ifdef COMPLEX_STATUS |
| 2301 |
|
|
if (PL_localizing == 2) { |
| 2302 |
|
|
PL_statusvalue = LvTARGOFF(sv); |
| 2303 |
|
|
PL_statusvalue_vms = LvTARGLEN(sv); |
| 2304 |
|
|
} |
| 2305 |
|
|
else |
| 2306 |
|
|
#endif |
| 2307 |
|
|
#ifdef VMSISH_STATUS |
| 2308 |
|
|
if (VMSISH_STATUS) |
| 2309 |
|
|
STATUS_NATIVE_SET((U32)(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv))); |
| 2310 |
|
|
else |
| 2311 |
|
|
#endif |
| 2312 |
|
|
STATUS_POSIX_SET(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv)); |
| 2313 |
|
|
break; |
| 2314 |
|
|
case '!': |
| 2315 |
|
|
{ |
| 2316 |
|
|
#ifdef VMS |
| 2317 |
|
|
# define PERL_VMS_BANG vaxc$errno |
| 2318 |
|
|
#else |
| 2319 |
|
|
# define PERL_VMS_BANG 0 |
| 2320 |
|
|
#endif |
| 2321 |
|
|
SETERRNO(SvIOK(sv) ? SvIVX(sv) : SvOK(sv) ? sv_2iv(sv) : 0, |
| 2322 |
|
|
(SvIV(sv) == EVMSERR) ? 4 : PERL_VMS_BANG); |
| 2323 |
|
|
} |
| 2324 |
|
|
break; |
| 2325 |
|
|
case '<': |
| 2326 |
|
|
PL_uid = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv); |
| 2327 |
|
|
if (PL_delaymagic) { |
| 2328 |
|
|
PL_delaymagic |= DM_RUID; |
| 2329 |
|
|
break; /* don't do magic till later */ |
| 2330 |
|
|
} |
| 2331 |
|
|
#ifdef HAS_SETRUID |
| 2332 |
|
|
(void)setruid((Uid_t)PL_uid); |
| 2333 |
|
|
#else |
| 2334 |
|
|
#ifdef HAS_SETREUID |
| 2335 |
|
|
(void)setreuid((Uid_t)PL_uid, (Uid_t)-1); |
| 2336 |
|
|
#else |
| 2337 |
|
|
#ifdef HAS_SETRESUID |
| 2338 |
|
|
(void)setresuid((Uid_t)PL_uid, (Uid_t)-1, (Uid_t)-1); |
| 2339 |
|
|
#else |
| 2340 |
|
|
if (PL_uid == PL_euid) { /* special case $< = $> */ |
| 2341 |
|
|
#ifdef PERL_DARWIN |
| 2342 |
|
|
/* workaround for Darwin's setuid peculiarity, cf [perl #24122] */ |
| 2343 |
|
|
if (PL_uid != 0 && PerlProc_getuid() == 0) |
| 2344 |
|
|
(void)PerlProc_setuid(0); |
| 2345 |
|
|
#endif |
| 2346 |
|
|
(void)PerlProc_setuid(PL_uid); |
| 2347 |
|
|
} else { |
| 2348 |
|
|
PL_uid = PerlProc_getuid(); |
| 2349 |
|
|
Perl_croak(aTHX_ "setruid() not implemented"); |
| 2350 |
|
|
} |
| 2351 |
|
|
#endif |
| 2352 |
|
|
#endif |
| 2353 |
|
|
#endif |
| 2354 |
|
|
PL_uid = PerlProc_getuid(); |
| 2355 |
|
|
PL_tainting |= (PL_uid && (PL_euid != PL_uid || PL_egid != PL_gid)); |
| 2356 |
|
|
break; |
| 2357 |
|
|
case '>': |
| 2358 |
|
|
PL_euid = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv); |
| 2359 |
|
|
if (PL_delaymagic) { |
| 2360 |
|
|
PL_delaymagic |= DM_EUID; |
| 2361 |
|
|
break; /* don't do magic till later */ |
| 2362 |
|
|
} |
| 2363 |
|
|
#ifdef HAS_SETEUID |
| 2364 |
|
|
(void)seteuid((Uid_t)PL_euid); |
| 2365 |
|
|
#else |
| 2366 |
|
|
#ifdef HAS_SETREUID |
| 2367 |
|
|
(void)setreuid((Uid_t)-1, (Uid_t)PL_euid); |
| 2368 |
|
|
#else |
| 2369 |
|
|
#ifdef HAS_SETRESUID |
| 2370 |
|
|
(void)setresuid((Uid_t)-1, (Uid_t)PL_euid, (Uid_t)-1); |
| 2371 |
|
|
#else |
| 2372 |
|
|
if (PL_euid == PL_uid) /* special case $> = $< */ |
| 2373 |
|
|
PerlProc_setuid(PL_euid); |
| 2374 |
|
|
else { |
| 2375 |
|
|
PL_euid = PerlProc_geteuid(); |
| 2376 |
|
|
Perl_croak(aTHX_ "seteuid() not implemented"); |
| 2377 |
|
|
} |
| 2378 |
|
|
#endif |
| 2379 |
|
|
#endif |
| 2380 |
|
|
#endif |
| 2381 |
|
|
PL_euid = PerlProc_geteuid(); |
| 2382 |
|
|
PL_tainting |= (PL_uid && (PL_euid != PL_uid || PL_egid != PL_gid)); |
| 2383 |
|
|
break; |
| 2384 |
|
|
case '(': |
| 2385 |
|
|
PL_gid = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv); |
| 2386 |
|
|
if (PL_delaymagic) { |
| 2387 |
|
|
PL_delaymagic |= DM_RGID; |
| 2388 |
|
|
break; /* don't do magic till later */ |
| 2389 |
|
|
} |
| 2390 |
|
|
#ifdef HAS_SETRGID |
| 2391 |
|
|
(void)setrgid((Gid_t)PL_gid); |
| 2392 |
|
|
#else |
| 2393 |
|
|
#ifdef HAS_SETREGID |
| 2394 |
|
|
(void)setregid((Gid_t)PL_gid, (Gid_t)-1); |
| 2395 |
|
|
#else |
| 2396 |
|
|
#ifdef HAS_SETRESGID |
| 2397 |
|
|
(void)setresgid((Gid_t)PL_gid, (Gid_t)-1, (Gid_t) 1); |
| 2398 |
|
|
#else |
| 2399 |
|
|
if (PL_gid == PL_egid) /* special case $( = $) */ |
| 2400 |
|
|
(void)PerlProc_setgid(PL_gid); |
| 2401 |
|
|
else { |
| 2402 |
|
|
PL_gid = PerlProc_getgid(); |
| 2403 |
|
|
Perl_croak(aTHX_ "setrgid() not implemented"); |
| 2404 |
|
|
} |
| 2405 |
|
|
#endif |
| 2406 |
|
|
#endif |
| 2407 |
|
|
#endif |
| 2408 |
|
|
PL_gid = PerlProc_getgid(); |
| 2409 |
|
|
PL_tainting |= (PL_uid && (PL_euid != PL_uid || PL_egid != PL_gid)); |
| 2410 |
|
|
break; |
| 2411 |
|
|
case ')': |
| 2412 |
|
|
#ifdef HAS_SETGROUPS |
| 2413 |
|
|
{ |
| 2414 |
|
|
char *p = SvPV(sv, len); |
| 2415 |
|
|
Groups_t gary[NGROUPS]; |
| 2416 |
|
|
|
| 2417 |
|
|
while (isSPACE(*p)) |
| 2418 |
|
|
++p; |
| 2419 |
|
|
PL_egid = Atol(p); |
| 2420 |
|
|
for (i = 0; i < NGROUPS; ++i) { |
| 2421 |
|
|
while (*p && !isSPACE(*p)) |
| 2422 |
|
|
++p; |
| 2423 |
|
|
while (isSPACE(*p)) |
| 2424 |
|
|
++p; |
| 2425 |
|
|
if (!*p) |
| 2426 |
|
|
break; |
| 2427 |
|
|
gary[i] = Atol(p); |
| 2428 |
|
|
} |
| 2429 |
|
|
if (i) |
| 2430 |
|
|
(void)setgroups(i, gary); |
| 2431 |
|
|
} |
| 2432 |
|
|
#else /* HAS_SETGROUPS */ |
| 2433 |
|
|
PL_egid = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv); |
| 2434 |
|
|
#endif /* HAS_SETGROUPS */ |
| 2435 |
|
|
if (PL_delaymagic) { |
| 2436 |
|
|
PL_delaymagic |= DM_EGID; |
| 2437 |
|
|
break; /* don't do magic till later */ |
| 2438 |
|
|
} |
| 2439 |
|
|
#ifdef HAS_SETEGID |
| 2440 |
|
|
(void)setegid((Gid_t)PL_egid); |
| 2441 |
|
|
#else |
| 2442 |
|
|
#ifdef HAS_SETREGID |
| 2443 |
|
|
(void)setregid((Gid_t)-1, (Gid_t)PL_egid); |
| 2444 |
|
|
#else |
| 2445 |
|
|
#ifdef HAS_SETRESGID |
| 2446 |
|
|
(void)setresgid((Gid_t)-1, (Gid_t)PL_egid, (Gid_t)-1); |
| 2447 |
|
|
#else |
| 2448 |
|
|
if (PL_egid == PL_gid) /* special case $) = $( */ |
| 2449 |
|
|
(void)PerlProc_setgid(PL_egid); |
| 2450 |
|
|
else { |
| 2451 |
|
|
PL_egid = PerlProc_getegid(); |
| 2452 |
|
|
Perl_croak(aTHX_ "setegid() not implemented"); |
| 2453 |
|
|
} |
| 2454 |
|
|
#endif |
| 2455 |
|
|
#endif |
| 2456 |
|
|
#endif |
| 2457 |
|
|
PL_egid = PerlProc_getegid(); |
| 2458 |
|
|
PL_tainting |= (PL_uid && (PL_euid != PL_uid || PL_egid != PL_gid)); |
| 2459 |
|
|
break; |
| 2460 |
|
|
case ':': |
| 2461 |
|
|
PL_chopset = SvPV_force(sv,len); |
| 2462 |
|
|
break; |
| 2463 |
|
|
#ifndef MACOS_TRADITIONAL |
| 2464 |
|
|
case '0': |
| 2465 |
|
|
LOCK_DOLLARZERO_MUTEX; |
| 2466 |
|
|
#ifdef HAS_SETPROCTITLE |
| 2467 |
|
|
/* The BSDs don't show the argv[] in ps(1) output, they |
| 2468 |
|
|
* show a string from the process struct and provide |
| 2469 |
|
|
* the setproctitle() routine to manipulate that. */ |
| 2470 |
|
|
{ |
| 2471 |
|
|
s = SvPV(sv, len); |
| 2472 |
|
|
# if __FreeBSD_version > 410001 |
| 2473 |
|
|
/* The leading "-" removes the "perl: " prefix, |
| 2474 |
|
|
* but not the "(perl) suffix from the ps(1) |
| 2475 |
|
|
* output, because that's what ps(1) shows if the |
| 2476 |
|
|
* argv[] is modified. */ |
| 2477 |
|
|
setproctitle("-%s", s); |
| 2478 |
|
|
# else /* old FreeBSDs, NetBSD, OpenBSD, anyBSD */ |
| 2479 |
|
|
/* This doesn't really work if you assume that |
| 2480 |
|
|
* $0 = 'foobar'; will wipe out 'perl' from the $0 |
| 2481 |
|
|
* because in ps(1) output the result will be like |
| 2482 |
|
|
* sprintf("perl: %s (perl)", s) |
| 2483 |
|
|
* I guess this is a security feature: |
| 2484 |
|
|
* one (a user process) cannot get rid of the original name. |
| 2485 |
|
|
* --jhi */ |
| 2486 |
|
|
setproctitle("%s", s); |
| 2487 |
|
|
# endif |
| 2488 |
|
|
} |
| 2489 |
|
|
#endif |
| 2490 |
|
|
#if defined(__hpux) && defined(PSTAT_SETCMD) |
| 2491 |
|
|
{ |
| 2492 |
|
|
union pstun un; |
| 2493 |
|
|
s = SvPV(sv, len); |
| 2494 |
|
|
un.pst_command = s; |
| 2495 |
|
|
pstat(PSTAT_SETCMD, un, len, 0, 0); |
| 2496 |
|
|
} |
| 2497 |
|
|
#endif |
| 2498 |
|
|
/* PL_origalen is set in perl_parse(). */ |
| 2499 |
|
|
s = SvPV_force(sv,len); |
| 2500 |
|
|
if (len >= (STRLEN)PL_origalen) { |
| 2501 |
|
|
/* Longer than original, will be truncated. */ |
| 2502 |
|
|
Copy(s, PL_origargv[0], PL_origalen, char); |
| 2503 |
|
|
PL_origargv[0][PL_origalen - 1] = 0; |
| 2504 |
|
|
} |
| 2505 |
|
|
else { |
| 2506 |
|
|
/* Shorter than original, will be padded. */ |
| 2507 |
|
|
Copy(s, PL_origargv[0], len, char); |
| 2508 |
|
|
PL_origargv[0][len] = 0; |
| 2509 |
|
|
memset(PL_origargv[0] + len + 1, |
| 2510 |
|
|
/* Is the space counterintuitive? Yes. |
| 2511 |
|
|
* (You were expecting \0?) |
| 2512 |
|
|
* Does it work? Seems to. (In Linux 2.4.20 at least.) |
| 2513 |
|
|
* --jhi */ |
| 2514 |
|
|
(int)' ', |
| 2515 |
|
|
PL_origalen - len - 1); |
| 2516 |
|
|
for (i = 1; i < PL_origargc; i++) |
| 2517 |
|
|
PL_origargv[i] = 0; |
| 2518 |
|
|
} |
| 2519 |
|
|
UNLOCK_DOLLARZERO_MUTEX; |
| 2520 |
|
|
break; |
| 2521 |
|
|
#endif |
| 2522 |
|
|
#ifdef USE_5005THREADS |
| 2523 |
|
|
case '@': |
| 2524 |
|
|
sv_setsv(thr->errsv, sv); |
| 2525 |
|
|
break; |
| 2526 |
|
|
#endif /* USE_5005THREADS */ |
| 2527 |
|
|
} |
| 2528 |
|
|
return 0; |
| 2529 |
|
|
} |
| 2530 |
|
|
|
| 2531 |
|
|
#ifdef USE_5005THREADS |
| 2532 |
|
|
int |
| 2533 |
|
|
Perl_magic_mutexfree(pTHX_ SV *sv, MAGIC *mg) |
| 2534 |
|
|
{ |
| 2535 |
|
|
DEBUG_S(PerlIO_printf(Perl_debug_log, |
| 2536 |
|
|
"0x%"UVxf": magic_mutexfree 0x%"UVxf"\n", |
| 2537 |
|
|
PTR2UV(thr), PTR2UV(sv))); |
| 2538 |
|
|
if (MgOWNER(mg)) |
| 2539 |
|
|
Perl_croak(aTHX_ "panic: magic_mutexfree"); |
| 2540 |
|
|
MUTEX_DESTROY(MgMUTEXP(mg)); |
| 2541 |
|
|
COND_DESTROY(MgCONDP(mg)); |
| 2542 |
|
|
return 0; |
| 2543 |
|
|
} |
| 2544 |
|
|
#endif /* USE_5005THREADS */ |
| 2545 |
|
|
|
| 2546 |
|
|
I32 |
| 2547 |
|
|
Perl_whichsig(pTHX_ char *sig) |
| 2548 |
|
|
{ |
| 2549 |
|
|
register char **sigv; |
| 2550 |
|
|
|
| 2551 |
|
|
for (sigv = PL_sig_name; *sigv; sigv++) |
| 2552 |
|
|
if (strEQ(sig,*sigv)) |
| 2553 |
|
|
return PL_sig_num[sigv - PL_sig_name]; |
| 2554 |
|
|
#ifdef SIGCLD |
| 2555 |
|
|
if (strEQ(sig,"CHLD")) |
| 2556 |
|
|
return SIGCLD; |
| 2557 |
|
|
#endif |
| 2558 |
|
|
#ifdef SIGCHLD |
| 2559 |
|
|
if (strEQ(sig,"CLD")) |
| 2560 |
|
|
return SIGCHLD; |
| 2561 |
|
|
#endif |
| 2562 |
|
|
return -1; |
| 2563 |
|
|
} |
| 2564 |
|
|
|
| 2565 |
|
|
#if !defined(PERL_IMPLICIT_CONTEXT) |
| 2566 |
|
|
static SV* sig_sv; |
| 2567 |
|
|
#endif |
| 2568 |
|
|
|
| 2569 |
|
|
Signal_t |
| 2570 |
|
|
Perl_sighandler(int sig) |
| 2571 |
|
|
{ |
| 2572 |
|
|
#ifdef PERL_GET_SIG_CONTEXT |
| 2573 |
|
|
dTHXa(PERL_GET_SIG_CONTEXT); |
| 2574 |
|
|
#else |
| 2575 |
|
|
dTHX; |
| 2576 |
|
|
#endif |
| 2577 |
|
|
dSP; |
| 2578 |
|
|
GV *gv = Nullgv; |
| 2579 |
|
|
HV *st; |
| 2580 |
|
|
SV *sv = Nullsv, *tSv = PL_Sv; |
| 2581 |
|
|
CV *cv = Nullcv; |
| 2582 |
|
|
OP *myop = PL_op; |
| 2583 |
|
|
U32 flags = 0; |
| 2584 |
|
|
XPV *tXpv = PL_Xpv; |
| 2585 |
|
|
|
| 2586 |
|
|
if (PL_savestack_ix + 15 <= PL_savestack_max) |
| 2587 |
|
|
flags |= 1; |
| 2588 |
|
|
if (PL_markstack_ptr < PL_markstack_max - 2) |
| 2589 |
|
|
flags |= 4; |
| 2590 |
|
|
if (PL_retstack_ix < PL_retstack_max - 2) |
| 2591 |
|
|
flags |= 8; |
| 2592 |
|
|
if (PL_scopestack_ix < PL_scopestack_max - 3) |
| 2593 |
|
|
flags |= 16; |
| 2594 |
|
|
|
| 2595 |
|
|
if (!PL_psig_ptr[sig]) { |
| 2596 |
|
|
PerlIO_printf(Perl_error_log, "Signal SIG%s received, but no signal handler set.\n", |
| 2597 |
|
|
PL_sig_name[sig]); |
| 2598 |
|
|
exit(sig); |
| 2599 |
|
|
} |
| 2600 |
|
|
|
| 2601 |
|
|
/* Max number of items pushed there is 3*n or 4. We cannot fix |
| 2602 |
|
|
infinity, so we fix 4 (in fact 5): */ |
| 2603 |
|
|
if (flags & 1) { |
| 2604 |
|
|
PL_savestack_ix += 5; /* Protect save in progress. */ |
| 2605 |
|
|
SAVEDESTRUCTOR_X(unwind_handler_stack, (void*)&flags); |
| 2606 |
|
|
} |
| 2607 |
|
|
if (flags & 4) |
| 2608 |
|
|
PL_markstack_ptr++; /* Protect mark. */ |
| 2609 |
|
|
if (flags & 8) { |
| 2610 |
|
|
PL_retstack_ix++; |
| 2611 |
|
|
PL_retstack[PL_retstack_ix] = NULL; |
| 2612 |
|
|
} |
| 2613 |
|
|
if (flags & 16) |
| 2614 |
|
|
PL_scopestack_ix += 1; |
| 2615 |
|
|
/* sv_2cv is too complicated, try a simpler variant first: */ |
| 2616 |
|
|
if (!SvROK(PL_psig_ptr[sig]) || !(cv = (CV*)SvRV(PL_psig_ptr[sig])) |
| 2617 |
|
|
|| SvTYPE(cv) != SVt_PVCV) |
| 2618 |
|
|
cv = sv_2cv(PL_psig_ptr[sig],&st,&gv,TRUE); |
| 2619 |
|
|
|
| 2620 |
|
|
if (!cv || !CvROOT(cv)) { |
| 2621 |
|
|
if (ckWARN(WARN_SIGNAL)) |
| 2622 |
|
|
Perl_warner(aTHX_ packWARN(WARN_SIGNAL), "SIG%s handler \"%s\" not defined.\n", |
| 2623 |
|
|
PL_sig_name[sig], (gv ? GvENAME(gv) |
| 2624 |
|
|
: ((cv && CvGV(cv)) |
| 2625 |
|
|
? GvENAME(CvGV(cv)) |
| 2626 |
|
|
: "__ANON__"))); |
| 2627 |
|
|
goto cleanup; |
| 2628 |
|
|
} |
| 2629 |
|
|
|
| 2630 |
|
|
if(PL_psig_name[sig]) { |
| 2631 |
|
|
sv = SvREFCNT_inc(PL_psig_name[sig]); |
| 2632 |
|
|
flags |= 64; |
| 2633 |
|
|
#if !defined(PERL_IMPLICIT_CONTEXT) |
| 2634 |
|
|
sig_sv = sv; |
| 2635 |
|
|
#endif |
| 2636 |
|
|
} else { |
| 2637 |
|
|
sv = sv_newmortal(); |
| 2638 |
|
|
sv_setpv(sv,PL_sig_name[sig]); |
| 2639 |
|
|
} |
| 2640 |
|
|
|
| 2641 |
|
|
PUSHSTACKi(PERLSI_SIGNAL); |
| 2642 |
|
|
PUSHMARK(SP); |
| 2643 |
|
|
PUSHs(sv); |
| 2644 |
|
|
PUTBACK; |
| 2645 |
|
|
|
| 2646 |
|
|
call_sv((SV*)cv, G_DISCARD|G_EVAL); |
| 2647 |
|
|
|
| 2648 |
|
|
POPSTACK; |
| 2649 |
|
|
if (SvTRUE(ERRSV)) { |
| 2650 |
|
|
#ifndef PERL_MICRO |
| 2651 |
|
|
#ifdef HAS_SIGPROCMASK |
| 2652 |
|
|
/* Handler "died", for example to get out of a restart-able read(). |
| 2653 |
|
|
* Before we re-do that on its behalf re-enable the signal which was |
| 2654 |
|
|
* blocked by the system when we entered. |
| 2655 |
|
|
*/ |
| 2656 |
|
|
sigset_t set; |
| 2657 |
|
|
sigemptyset(&set); |
| 2658 |
|
|
sigaddset(&set,sig); |
| 2659 |
|
|
sigprocmask(SIG_UNBLOCK, &set, NULL); |
| 2660 |
|
|
#else |
| 2661 |
|
|
/* Not clear if this will work */ |
| 2662 |
|
|
(void)rsignal(sig, SIG_IGN); |
| 2663 |
|
|
(void)rsignal(sig, PL_csighandlerp); |
| 2664 |
|
|
#endif |
| 2665 |
|
|
#endif /* !PERL_MICRO */ |
| 2666 |
|
|
DieNull; |
| 2667 |
|
|
} |
| 2668 |
|
|
cleanup: |
| 2669 |
|
|
if (flags & 1) |
| 2670 |
|
|
PL_savestack_ix -= 8; /* Unprotect save in progress. */ |
| 2671 |
|
|
if (flags & 4) |
| 2672 |
|
|
PL_markstack_ptr--; |
| 2673 |
|
|
if (flags & 8) |
| 2674 |
|
|
PL_retstack_ix--; |
| 2675 |
|
|
if (flags & 16) |
| 2676 |
|
|
PL_scopestack_ix -= 1; |
| 2677 |
|
|
if (flags & 64) |
| 2678 |
|
|
SvREFCNT_dec(sv); |
| 2679 |
|
|
PL_op = myop; /* Apparently not needed... */ |
| 2680 |
|
|
|
| 2681 |
|
|
PL_Sv = tSv; /* Restore global temporaries. */ |
| 2682 |
|
|
PL_Xpv = tXpv; |
| 2683 |
|
|
return; |
| 2684 |
|
|
} |
| 2685 |
|
|
|
| 2686 |
|
|
|
| 2687 |
|
|
static void |
| 2688 |
|
|
restore_magic(pTHX_ void *p) |
| 2689 |
|
|
{ |
| 2690 |
|
|
MGS* mgs = SSPTR(PTR2IV(p), MGS*); |
| 2691 |
|
|
SV* sv = mgs->mgs_sv; |
| 2692 |
|
|
|
| 2693 |
|
|
if (!sv) |
| 2694 |
|
|
return; |
| 2695 |
|
|
|
| 2696 |
|
|
if (SvTYPE(sv) >= SVt_PVMG && SvMAGIC(sv)) |
| 2697 |
|
|
{ |
| 2698 |
|
|
if (mgs->mgs_flags) |
| 2699 |
|
|
SvFLAGS(sv) |= mgs->mgs_flags; |
| 2700 |
|
|
else |
| 2701 |
|
|
mg_magical(sv); |
| 2702 |
|
|
if (SvGMAGICAL(sv)) |
| 2703 |
|
|
SvFLAGS(sv) &= ~(SVf_IOK|SVf_NOK|SVf_POK); |
| 2704 |
|
|
} |
| 2705 |
|
|
|
| 2706 |
|
|
mgs->mgs_sv = NULL; /* mark the MGS structure as restored */ |
| 2707 |
|
|
|
| 2708 |
|
|
/* If we're still on top of the stack, pop us off. (That condition |
| 2709 |
|
|
* will be satisfied if restore_magic was called explicitly, but *not* |
| 2710 |
|
|
* if it's being called via leave_scope.) |
| 2711 |
|
|
* The reason for doing this is that otherwise, things like sv_2cv() |
| 2712 |
|
|
* may leave alloc gunk on the savestack, and some code |
| 2713 |
|
|
* (e.g. sighandler) doesn't expect that... |
| 2714 |
|
|
*/ |
| 2715 |
|
|
if (PL_savestack_ix == mgs->mgs_ss_ix) |
| 2716 |
|
|
{ |
| 2717 |
|
|
I32 popval = SSPOPINT; |
| 2718 |
|
|
assert(popval == SAVEt_DESTRUCTOR_X); |
| 2719 |
|
|
PL_savestack_ix -= 2; |
| 2720 |
|
|
popval = SSPOPINT; |
| 2721 |
|
|
assert(popval == SAVEt_ALLOC); |
| 2722 |
|
|
popval = SSPOPINT; |
| 2723 |
|
|
PL_savestack_ix -= popval; |
| 2724 |
|
|
} |
| 2725 |
|
|
|
| 2726 |
|
|
} |
| 2727 |
|
|
|
| 2728 |
|
|
static void |
| 2729 |
|
|
unwind_handler_stack(pTHX_ void *p) |
| 2730 |
|
|
{ |
| 2731 |
|
|
U32 flags = *(U32*)p; |
| 2732 |
|
|
|
| 2733 |
|
|
if (flags & 1) |
| 2734 |
|
|
PL_savestack_ix -= 5; /* Unprotect save in progress. */ |
| 2735 |
|
|
/* cxstack_ix-- Not needed, die already unwound it. */ |
| 2736 |
|
|
#if !defined(PERL_IMPLICIT_CONTEXT) |
| 2737 |
|
|
if (flags & 64) |
| 2738 |
|
|
SvREFCNT_dec(sig_sv); |
| 2739 |
|
|
#endif |
| 2740 |
|
|
} |
| 2741 |
|
|
|
| 2742 |
|
|
|