| 1 |
root |
1.1 |
/* pp.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 |
|
|
* "It's a big house this, and very peculiar. Always a bit more to discover, |
| 13 |
|
|
* and no knowing what you'll find around a corner. And Elves, sir!" --Samwise |
| 14 |
|
|
*/ |
| 15 |
|
|
|
| 16 |
|
|
/* This file contains general pp ("push/pop") functions that execute the |
| 17 |
|
|
* opcodes that make up a perl program. A typical pp function expects to |
| 18 |
|
|
* find its arguments on the stack, and usually pushes its results onto |
| 19 |
|
|
* the stack, hence the 'pp' terminology. Each OP structure contains |
| 20 |
|
|
* a pointer to the relevant pp_foo() function. |
| 21 |
|
|
*/ |
| 22 |
|
|
|
| 23 |
|
|
#include "EXTERN.h" |
| 24 |
|
|
#define PERL_IN_PP_C |
| 25 |
|
|
#include "perl.h" |
| 26 |
|
|
#include "keywords.h" |
| 27 |
|
|
|
| 28 |
|
|
#include "reentr.h" |
| 29 |
|
|
|
| 30 |
|
|
/* XXX I can't imagine anyone who doesn't have this actually _needs_ |
| 31 |
|
|
it, since pid_t is an integral type. |
| 32 |
|
|
--AD 2/20/1998 |
| 33 |
|
|
*/ |
| 34 |
|
|
#ifdef NEED_GETPID_PROTO |
| 35 |
|
|
extern Pid_t getpid (void); |
| 36 |
|
|
#endif |
| 37 |
|
|
|
| 38 |
|
|
/* variations on pp_null */ |
| 39 |
|
|
|
| 40 |
|
|
PP(pp_stub) |
| 41 |
|
|
{ |
| 42 |
|
|
dSP; |
| 43 |
|
|
if (GIMME_V == G_SCALAR) |
| 44 |
|
|
XPUSHs(&PL_sv_undef); |
| 45 |
|
|
RETURN; |
| 46 |
|
|
} |
| 47 |
|
|
|
| 48 |
|
|
PP(pp_scalar) |
| 49 |
|
|
{ |
| 50 |
|
|
return NORMAL; |
| 51 |
|
|
} |
| 52 |
|
|
|
| 53 |
|
|
/* Pushy stuff. */ |
| 54 |
|
|
|
| 55 |
|
|
PP(pp_padav) |
| 56 |
|
|
{ |
| 57 |
|
|
dSP; dTARGET; |
| 58 |
|
|
I32 gimme; |
| 59 |
|
|
if (PL_op->op_private & OPpLVAL_INTRO) |
| 60 |
|
|
SAVECLEARSV(PAD_SVl(PL_op->op_targ)); |
| 61 |
|
|
EXTEND(SP, 1); |
| 62 |
|
|
if (PL_op->op_flags & OPf_REF) { |
| 63 |
|
|
PUSHs(TARG); |
| 64 |
|
|
RETURN; |
| 65 |
|
|
} else if (LVRET) { |
| 66 |
|
|
if (GIMME == G_SCALAR) |
| 67 |
|
|
Perl_croak(aTHX_ "Can't return array to lvalue scalar context"); |
| 68 |
|
|
PUSHs(TARG); |
| 69 |
|
|
RETURN; |
| 70 |
|
|
} |
| 71 |
|
|
gimme = GIMME_V; |
| 72 |
|
|
if (gimme == G_ARRAY) { |
| 73 |
|
|
I32 maxarg = AvFILL((AV*)TARG) + 1; |
| 74 |
|
|
EXTEND(SP, maxarg); |
| 75 |
|
|
if (SvMAGICAL(TARG)) { |
| 76 |
|
|
U32 i; |
| 77 |
|
|
for (i=0; i < (U32)maxarg; i++) { |
| 78 |
|
|
SV **svp = av_fetch((AV*)TARG, i, FALSE); |
| 79 |
|
|
SP[i+1] = (svp) ? *svp : &PL_sv_undef; |
| 80 |
|
|
} |
| 81 |
|
|
} |
| 82 |
|
|
else { |
| 83 |
|
|
Copy(AvARRAY((AV*)TARG), SP+1, maxarg, SV*); |
| 84 |
|
|
} |
| 85 |
|
|
SP += maxarg; |
| 86 |
|
|
} |
| 87 |
|
|
else if (gimme == G_SCALAR) { |
| 88 |
|
|
SV* sv = sv_newmortal(); |
| 89 |
|
|
I32 maxarg = AvFILL((AV*)TARG) + 1; |
| 90 |
|
|
sv_setiv(sv, maxarg); |
| 91 |
|
|
PUSHs(sv); |
| 92 |
|
|
} |
| 93 |
|
|
RETURN; |
| 94 |
|
|
} |
| 95 |
|
|
|
| 96 |
|
|
PP(pp_padhv) |
| 97 |
|
|
{ |
| 98 |
|
|
dSP; dTARGET; |
| 99 |
|
|
I32 gimme; |
| 100 |
|
|
|
| 101 |
|
|
XPUSHs(TARG); |
| 102 |
|
|
if (PL_op->op_private & OPpLVAL_INTRO) |
| 103 |
|
|
SAVECLEARSV(PAD_SVl(PL_op->op_targ)); |
| 104 |
|
|
if (PL_op->op_flags & OPf_REF) |
| 105 |
|
|
RETURN; |
| 106 |
|
|
else if (LVRET) { |
| 107 |
|
|
if (GIMME == G_SCALAR) |
| 108 |
|
|
Perl_croak(aTHX_ "Can't return hash to lvalue scalar context"); |
| 109 |
|
|
RETURN; |
| 110 |
|
|
} |
| 111 |
|
|
gimme = GIMME_V; |
| 112 |
|
|
if (gimme == G_ARRAY) { |
| 113 |
|
|
RETURNOP(do_kv()); |
| 114 |
|
|
} |
| 115 |
|
|
else if (gimme == G_SCALAR) { |
| 116 |
|
|
SV* sv = Perl_hv_scalar(aTHX_ (HV*)TARG); |
| 117 |
|
|
SETs(sv); |
| 118 |
|
|
} |
| 119 |
|
|
RETURN; |
| 120 |
|
|
} |
| 121 |
|
|
|
| 122 |
|
|
PP(pp_padany) |
| 123 |
|
|
{ |
| 124 |
|
|
DIE(aTHX_ "NOT IMPL LINE %d",__LINE__); |
| 125 |
|
|
} |
| 126 |
|
|
|
| 127 |
|
|
/* Translations. */ |
| 128 |
|
|
|
| 129 |
|
|
PP(pp_rv2gv) |
| 130 |
|
|
{ |
| 131 |
|
|
dSP; dTOPss; |
| 132 |
|
|
|
| 133 |
|
|
if (SvROK(sv)) { |
| 134 |
|
|
wasref: |
| 135 |
|
|
tryAMAGICunDEREF(to_gv); |
| 136 |
|
|
|
| 137 |
|
|
sv = SvRV(sv); |
| 138 |
|
|
if (SvTYPE(sv) == SVt_PVIO) { |
| 139 |
|
|
GV *gv = (GV*) sv_newmortal(); |
| 140 |
|
|
gv_init(gv, 0, "", 0, 0); |
| 141 |
|
|
GvIOp(gv) = (IO *)sv; |
| 142 |
|
|
(void)SvREFCNT_inc(sv); |
| 143 |
|
|
sv = (SV*) gv; |
| 144 |
|
|
} |
| 145 |
|
|
else if (SvTYPE(sv) != SVt_PVGV) |
| 146 |
|
|
DIE(aTHX_ "Not a GLOB reference"); |
| 147 |
|
|
} |
| 148 |
|
|
else { |
| 149 |
|
|
if (SvTYPE(sv) != SVt_PVGV) { |
| 150 |
|
|
char *sym; |
| 151 |
|
|
STRLEN len; |
| 152 |
|
|
|
| 153 |
|
|
if (SvGMAGICAL(sv)) { |
| 154 |
|
|
mg_get(sv); |
| 155 |
|
|
if (SvROK(sv)) |
| 156 |
|
|
goto wasref; |
| 157 |
|
|
} |
| 158 |
|
|
if (!SvOK(sv) && sv != &PL_sv_undef) { |
| 159 |
|
|
/* If this is a 'my' scalar and flag is set then vivify |
| 160 |
|
|
* NI-S 1999/05/07 |
| 161 |
|
|
*/ |
| 162 |
|
|
if (SvREADONLY(sv)) |
| 163 |
|
|
Perl_croak(aTHX_ PL_no_modify); |
| 164 |
|
|
if (PL_op->op_private & OPpDEREF) { |
| 165 |
|
|
char *name; |
| 166 |
|
|
GV *gv; |
| 167 |
|
|
if (cUNOP->op_targ) { |
| 168 |
|
|
STRLEN len; |
| 169 |
|
|
SV *namesv = PAD_SV(cUNOP->op_targ); |
| 170 |
|
|
name = SvPV(namesv, len); |
| 171 |
|
|
gv = (GV*)NEWSV(0,0); |
| 172 |
|
|
gv_init(gv, CopSTASH(PL_curcop), name, len, 0); |
| 173 |
|
|
} |
| 174 |
|
|
else { |
| 175 |
|
|
name = CopSTASHPV(PL_curcop); |
| 176 |
|
|
gv = newGVgen(name); |
| 177 |
|
|
} |
| 178 |
|
|
if (SvTYPE(sv) < SVt_RV) |
| 179 |
|
|
sv_upgrade(sv, SVt_RV); |
| 180 |
|
|
if (SvPVX(sv)) { |
| 181 |
|
|
SvOOK_off(sv); /* backoff */ |
| 182 |
|
|
if (SvLEN(sv)) |
| 183 |
|
|
Safefree(SvPVX(sv)); |
| 184 |
|
|
SvLEN(sv)=SvCUR(sv)=0; |
| 185 |
|
|
} |
| 186 |
|
|
SvRV(sv) = (SV*)gv; |
| 187 |
|
|
SvROK_on(sv); |
| 188 |
|
|
SvSETMAGIC(sv); |
| 189 |
|
|
goto wasref; |
| 190 |
|
|
} |
| 191 |
|
|
if (PL_op->op_flags & OPf_REF || |
| 192 |
|
|
PL_op->op_private & HINT_STRICT_REFS) |
| 193 |
|
|
DIE(aTHX_ PL_no_usym, "a symbol"); |
| 194 |
|
|
if (ckWARN(WARN_UNINITIALIZED)) |
| 195 |
|
|
report_uninit(); |
| 196 |
|
|
RETSETUNDEF; |
| 197 |
|
|
} |
| 198 |
|
|
sym = SvPV(sv,len); |
| 199 |
|
|
if ((PL_op->op_flags & OPf_SPECIAL) && |
| 200 |
|
|
!(PL_op->op_flags & OPf_MOD)) |
| 201 |
|
|
{ |
| 202 |
|
|
sv = (SV*)gv_fetchpv(sym, FALSE, SVt_PVGV); |
| 203 |
|
|
if (!sv |
| 204 |
|
|
&& (!is_gv_magical(sym,len,0) |
| 205 |
|
|
|| !(sv = (SV*)gv_fetchpv(sym, TRUE, SVt_PVGV)))) |
| 206 |
|
|
{ |
| 207 |
|
|
RETSETUNDEF; |
| 208 |
|
|
} |
| 209 |
|
|
} |
| 210 |
|
|
else { |
| 211 |
|
|
if (PL_op->op_private & HINT_STRICT_REFS) |
| 212 |
|
|
DIE(aTHX_ PL_no_symref, sym, "a symbol"); |
| 213 |
|
|
sv = (SV*)gv_fetchpv(sym, TRUE, SVt_PVGV); |
| 214 |
|
|
} |
| 215 |
|
|
} |
| 216 |
|
|
} |
| 217 |
|
|
if (PL_op->op_private & OPpLVAL_INTRO) |
| 218 |
|
|
save_gp((GV*)sv, !(PL_op->op_flags & OPf_SPECIAL)); |
| 219 |
|
|
SETs(sv); |
| 220 |
|
|
RETURN; |
| 221 |
|
|
} |
| 222 |
|
|
|
| 223 |
|
|
PP(pp_rv2sv) |
| 224 |
|
|
{ |
| 225 |
|
|
GV *gv = Nullgv; |
| 226 |
|
|
dSP; dTOPss; |
| 227 |
|
|
|
| 228 |
|
|
if (SvROK(sv)) { |
| 229 |
|
|
wasref: |
| 230 |
|
|
tryAMAGICunDEREF(to_sv); |
| 231 |
|
|
|
| 232 |
|
|
sv = SvRV(sv); |
| 233 |
|
|
switch (SvTYPE(sv)) { |
| 234 |
|
|
case SVt_PVAV: |
| 235 |
|
|
case SVt_PVHV: |
| 236 |
|
|
case SVt_PVCV: |
| 237 |
|
|
DIE(aTHX_ "Not a SCALAR reference"); |
| 238 |
|
|
} |
| 239 |
|
|
} |
| 240 |
|
|
else { |
| 241 |
|
|
char *sym; |
| 242 |
|
|
STRLEN len; |
| 243 |
|
|
gv = (GV*)sv; |
| 244 |
|
|
|
| 245 |
|
|
if (SvTYPE(gv) != SVt_PVGV) { |
| 246 |
|
|
if (SvGMAGICAL(sv)) { |
| 247 |
|
|
mg_get(sv); |
| 248 |
|
|
if (SvROK(sv)) |
| 249 |
|
|
goto wasref; |
| 250 |
|
|
} |
| 251 |
|
|
if (!SvOK(sv)) { |
| 252 |
|
|
if (PL_op->op_flags & OPf_REF || |
| 253 |
|
|
PL_op->op_private & HINT_STRICT_REFS) |
| 254 |
|
|
DIE(aTHX_ PL_no_usym, "a SCALAR"); |
| 255 |
|
|
if (ckWARN(WARN_UNINITIALIZED)) |
| 256 |
|
|
report_uninit(); |
| 257 |
|
|
RETSETUNDEF; |
| 258 |
|
|
} |
| 259 |
|
|
sym = SvPV(sv, len); |
| 260 |
|
|
if ((PL_op->op_flags & OPf_SPECIAL) && |
| 261 |
|
|
!(PL_op->op_flags & OPf_MOD)) |
| 262 |
|
|
{ |
| 263 |
|
|
gv = (GV*)gv_fetchpv(sym, FALSE, SVt_PV); |
| 264 |
|
|
if (!gv |
| 265 |
|
|
&& (!is_gv_magical(sym,len,0) |
| 266 |
|
|
|| !(gv = (GV*)gv_fetchpv(sym, TRUE, SVt_PV)))) |
| 267 |
|
|
{ |
| 268 |
|
|
RETSETUNDEF; |
| 269 |
|
|
} |
| 270 |
|
|
} |
| 271 |
|
|
else { |
| 272 |
|
|
if (PL_op->op_private & HINT_STRICT_REFS) |
| 273 |
|
|
DIE(aTHX_ PL_no_symref, sym, "a SCALAR"); |
| 274 |
|
|
gv = (GV*)gv_fetchpv(sym, TRUE, SVt_PV); |
| 275 |
|
|
} |
| 276 |
|
|
} |
| 277 |
|
|
sv = GvSV(gv); |
| 278 |
|
|
} |
| 279 |
|
|
if (PL_op->op_flags & OPf_MOD) { |
| 280 |
|
|
if (PL_op->op_private & OPpLVAL_INTRO) { |
| 281 |
|
|
if (cUNOP->op_first->op_type == OP_NULL) |
| 282 |
|
|
sv = save_scalar((GV*)TOPs); |
| 283 |
|
|
else if (gv) |
| 284 |
|
|
sv = save_scalar(gv); |
| 285 |
|
|
else |
| 286 |
|
|
Perl_croak(aTHX_ PL_no_localize_ref); |
| 287 |
|
|
} |
| 288 |
|
|
else if (PL_op->op_private & OPpDEREF) |
| 289 |
|
|
vivify_ref(sv, PL_op->op_private & OPpDEREF); |
| 290 |
|
|
} |
| 291 |
|
|
SETs(sv); |
| 292 |
|
|
RETURN; |
| 293 |
|
|
} |
| 294 |
|
|
|
| 295 |
|
|
PP(pp_av2arylen) |
| 296 |
|
|
{ |
| 297 |
|
|
dSP; |
| 298 |
|
|
AV *av = (AV*)TOPs; |
| 299 |
|
|
SV *sv = AvARYLEN(av); |
| 300 |
|
|
if (!sv) { |
| 301 |
|
|
AvARYLEN(av) = sv = NEWSV(0,0); |
| 302 |
|
|
sv_upgrade(sv, SVt_IV); |
| 303 |
|
|
sv_magic(sv, (SV*)av, PERL_MAGIC_arylen, Nullch, 0); |
| 304 |
|
|
} |
| 305 |
|
|
SETs(sv); |
| 306 |
|
|
RETURN; |
| 307 |
|
|
} |
| 308 |
|
|
|
| 309 |
|
|
PP(pp_pos) |
| 310 |
|
|
{ |
| 311 |
|
|
dSP; dTARGET; dPOPss; |
| 312 |
|
|
|
| 313 |
|
|
if (PL_op->op_flags & OPf_MOD || LVRET) { |
| 314 |
|
|
if (SvTYPE(TARG) < SVt_PVLV) { |
| 315 |
|
|
sv_upgrade(TARG, SVt_PVLV); |
| 316 |
|
|
sv_magic(TARG, Nullsv, PERL_MAGIC_pos, Nullch, 0); |
| 317 |
|
|
} |
| 318 |
|
|
|
| 319 |
|
|
LvTYPE(TARG) = '.'; |
| 320 |
|
|
if (LvTARG(TARG) != sv) { |
| 321 |
|
|
if (LvTARG(TARG)) |
| 322 |
|
|
SvREFCNT_dec(LvTARG(TARG)); |
| 323 |
|
|
LvTARG(TARG) = SvREFCNT_inc(sv); |
| 324 |
|
|
} |
| 325 |
|
|
PUSHs(TARG); /* no SvSETMAGIC */ |
| 326 |
|
|
RETURN; |
| 327 |
|
|
} |
| 328 |
|
|
else { |
| 329 |
|
|
MAGIC* mg; |
| 330 |
|
|
|
| 331 |
|
|
if (SvTYPE(sv) >= SVt_PVMG && SvMAGIC(sv)) { |
| 332 |
|
|
mg = mg_find(sv, PERL_MAGIC_regex_global); |
| 333 |
|
|
if (mg && mg->mg_len >= 0) { |
| 334 |
|
|
I32 i = mg->mg_len; |
| 335 |
|
|
if (DO_UTF8(sv)) |
| 336 |
|
|
sv_pos_b2u(sv, &i); |
| 337 |
|
|
PUSHi(i + PL_curcop->cop_arybase); |
| 338 |
|
|
RETURN; |
| 339 |
|
|
} |
| 340 |
|
|
} |
| 341 |
|
|
RETPUSHUNDEF; |
| 342 |
|
|
} |
| 343 |
|
|
} |
| 344 |
|
|
|
| 345 |
|
|
PP(pp_rv2cv) |
| 346 |
|
|
{ |
| 347 |
|
|
dSP; |
| 348 |
|
|
GV *gv; |
| 349 |
|
|
HV *stash; |
| 350 |
|
|
|
| 351 |
|
|
/* We usually try to add a non-existent subroutine in case of AUTOLOAD. */ |
| 352 |
|
|
/* (But not in defined().) */ |
| 353 |
|
|
CV *cv = sv_2cv(TOPs, &stash, &gv, !(PL_op->op_flags & OPf_SPECIAL)); |
| 354 |
|
|
if (cv) { |
| 355 |
|
|
if (CvCLONE(cv)) |
| 356 |
|
|
cv = (CV*)sv_2mortal((SV*)cv_clone(cv)); |
| 357 |
|
|
if ((PL_op->op_private & OPpLVAL_INTRO)) { |
| 358 |
|
|
if (gv && GvCV(gv) == cv && (gv = gv_autoload4(GvSTASH(gv), GvNAME(gv), GvNAMELEN(gv), FALSE))) |
| 359 |
|
|
cv = GvCV(gv); |
| 360 |
|
|
if (!CvLVALUE(cv)) |
| 361 |
|
|
DIE(aTHX_ "Can't modify non-lvalue subroutine call"); |
| 362 |
|
|
} |
| 363 |
|
|
} |
| 364 |
|
|
else |
| 365 |
|
|
cv = (CV*)&PL_sv_undef; |
| 366 |
|
|
SETs((SV*)cv); |
| 367 |
|
|
RETURN; |
| 368 |
|
|
} |
| 369 |
|
|
|
| 370 |
|
|
PP(pp_prototype) |
| 371 |
|
|
{ |
| 372 |
|
|
dSP; |
| 373 |
|
|
CV *cv; |
| 374 |
|
|
HV *stash; |
| 375 |
|
|
GV *gv; |
| 376 |
|
|
SV *ret; |
| 377 |
|
|
|
| 378 |
|
|
ret = &PL_sv_undef; |
| 379 |
|
|
if (SvPOK(TOPs) && SvCUR(TOPs) >= 7) { |
| 380 |
|
|
char *s = SvPVX(TOPs); |
| 381 |
|
|
if (strnEQ(s, "CORE::", 6)) { |
| 382 |
|
|
int code; |
| 383 |
|
|
|
| 384 |
|
|
code = keyword(s + 6, SvCUR(TOPs) - 6); |
| 385 |
|
|
if (code < 0) { /* Overridable. */ |
| 386 |
|
|
#define MAX_ARGS_OP ((sizeof(I32) - 1) * 2) |
| 387 |
|
|
int i = 0, n = 0, seen_question = 0; |
| 388 |
|
|
I32 oa; |
| 389 |
|
|
char str[ MAX_ARGS_OP * 2 + 2 ]; /* One ';', one '\0' */ |
| 390 |
|
|
|
| 391 |
|
|
if (code == -KEY_chop || code == -KEY_chomp) |
| 392 |
|
|
goto set; |
| 393 |
|
|
while (i < MAXO) { /* The slow way. */ |
| 394 |
|
|
if (strEQ(s + 6, PL_op_name[i]) |
| 395 |
|
|
|| strEQ(s + 6, PL_op_desc[i])) |
| 396 |
|
|
{ |
| 397 |
|
|
goto found; |
| 398 |
|
|
} |
| 399 |
|
|
i++; |
| 400 |
|
|
} |
| 401 |
|
|
goto nonesuch; /* Should not happen... */ |
| 402 |
|
|
found: |
| 403 |
|
|
oa = PL_opargs[i] >> OASHIFT; |
| 404 |
|
|
while (oa) { |
| 405 |
|
|
if (oa & OA_OPTIONAL && !seen_question) { |
| 406 |
|
|
seen_question = 1; |
| 407 |
|
|
str[n++] = ';'; |
| 408 |
|
|
} |
| 409 |
|
|
else if (n && str[0] == ';' && seen_question) |
| 410 |
|
|
goto set; /* XXXX system, exec */ |
| 411 |
|
|
if ((oa & (OA_OPTIONAL - 1)) >= OA_AVREF |
| 412 |
|
|
&& (oa & (OA_OPTIONAL - 1)) <= OA_SCALARREF |
| 413 |
|
|
/* But globs are already references (kinda) */ |
| 414 |
|
|
&& (oa & (OA_OPTIONAL - 1)) != OA_FILEREF |
| 415 |
|
|
) { |
| 416 |
|
|
str[n++] = '\\'; |
| 417 |
|
|
} |
| 418 |
|
|
str[n++] = ("?$@@%&*$")[oa & (OA_OPTIONAL - 1)]; |
| 419 |
|
|
oa = oa >> 4; |
| 420 |
|
|
} |
| 421 |
|
|
str[n++] = '\0'; |
| 422 |
|
|
ret = sv_2mortal(newSVpvn(str, n - 1)); |
| 423 |
|
|
} |
| 424 |
|
|
else if (code) /* Non-Overridable */ |
| 425 |
|
|
goto set; |
| 426 |
|
|
else { /* None such */ |
| 427 |
|
|
nonesuch: |
| 428 |
|
|
DIE(aTHX_ "Can't find an opnumber for \"%s\"", s+6); |
| 429 |
|
|
} |
| 430 |
|
|
} |
| 431 |
|
|
} |
| 432 |
|
|
cv = sv_2cv(TOPs, &stash, &gv, FALSE); |
| 433 |
|
|
if (cv && SvPOK(cv)) |
| 434 |
|
|
ret = sv_2mortal(newSVpvn(SvPVX(cv), SvCUR(cv))); |
| 435 |
|
|
set: |
| 436 |
|
|
SETs(ret); |
| 437 |
|
|
RETURN; |
| 438 |
|
|
} |
| 439 |
|
|
|
| 440 |
|
|
PP(pp_anoncode) |
| 441 |
|
|
{ |
| 442 |
|
|
dSP; |
| 443 |
|
|
CV* cv = (CV*)PAD_SV(PL_op->op_targ); |
| 444 |
|
|
if (CvCLONE(cv)) |
| 445 |
|
|
cv = (CV*)sv_2mortal((SV*)cv_clone(cv)); |
| 446 |
|
|
EXTEND(SP,1); |
| 447 |
|
|
PUSHs((SV*)cv); |
| 448 |
|
|
RETURN; |
| 449 |
|
|
} |
| 450 |
|
|
|
| 451 |
|
|
PP(pp_srefgen) |
| 452 |
|
|
{ |
| 453 |
|
|
dSP; |
| 454 |
|
|
*SP = refto(*SP); |
| 455 |
|
|
RETURN; |
| 456 |
|
|
} |
| 457 |
|
|
|
| 458 |
|
|
PP(pp_refgen) |
| 459 |
|
|
{ |
| 460 |
|
|
dSP; dMARK; |
| 461 |
|
|
if (GIMME != G_ARRAY) { |
| 462 |
|
|
if (++MARK <= SP) |
| 463 |
|
|
*MARK = *SP; |
| 464 |
|
|
else |
| 465 |
|
|
*MARK = &PL_sv_undef; |
| 466 |
|
|
*MARK = refto(*MARK); |
| 467 |
|
|
SP = MARK; |
| 468 |
|
|
RETURN; |
| 469 |
|
|
} |
| 470 |
|
|
EXTEND_MORTAL(SP - MARK); |
| 471 |
|
|
while (++MARK <= SP) |
| 472 |
|
|
*MARK = refto(*MARK); |
| 473 |
|
|
RETURN; |
| 474 |
|
|
} |
| 475 |
|
|
|
| 476 |
|
|
STATIC SV* |
| 477 |
|
|
S_refto(pTHX_ SV *sv) |
| 478 |
|
|
{ |
| 479 |
|
|
SV* rv; |
| 480 |
|
|
|
| 481 |
|
|
if (SvTYPE(sv) == SVt_PVLV && LvTYPE(sv) == 'y') { |
| 482 |
|
|
if (LvTARGLEN(sv)) |
| 483 |
|
|
vivify_defelem(sv); |
| 484 |
|
|
if (!(sv = LvTARG(sv))) |
| 485 |
|
|
sv = &PL_sv_undef; |
| 486 |
|
|
else |
| 487 |
|
|
(void)SvREFCNT_inc(sv); |
| 488 |
|
|
} |
| 489 |
|
|
else if (SvTYPE(sv) == SVt_PVAV) { |
| 490 |
|
|
if (!AvREAL((AV*)sv) && AvREIFY((AV*)sv)) |
| 491 |
|
|
av_reify((AV*)sv); |
| 492 |
|
|
SvTEMP_off(sv); |
| 493 |
|
|
(void)SvREFCNT_inc(sv); |
| 494 |
|
|
} |
| 495 |
|
|
else if (SvPADTMP(sv) && !IS_PADGV(sv)) |
| 496 |
|
|
sv = newSVsv(sv); |
| 497 |
|
|
else { |
| 498 |
|
|
SvTEMP_off(sv); |
| 499 |
|
|
(void)SvREFCNT_inc(sv); |
| 500 |
|
|
} |
| 501 |
|
|
rv = sv_newmortal(); |
| 502 |
|
|
sv_upgrade(rv, SVt_RV); |
| 503 |
|
|
SvRV(rv) = sv; |
| 504 |
|
|
SvROK_on(rv); |
| 505 |
|
|
return rv; |
| 506 |
|
|
} |
| 507 |
|
|
|
| 508 |
|
|
PP(pp_ref) |
| 509 |
|
|
{ |
| 510 |
|
|
dSP; dTARGET; |
| 511 |
|
|
SV *sv; |
| 512 |
|
|
char *pv; |
| 513 |
|
|
|
| 514 |
|
|
sv = POPs; |
| 515 |
|
|
|
| 516 |
|
|
if (sv && SvGMAGICAL(sv)) |
| 517 |
|
|
mg_get(sv); |
| 518 |
|
|
|
| 519 |
|
|
if (!sv || !SvROK(sv)) |
| 520 |
|
|
RETPUSHNO; |
| 521 |
|
|
|
| 522 |
|
|
sv = SvRV(sv); |
| 523 |
|
|
pv = sv_reftype(sv,TRUE); |
| 524 |
|
|
PUSHp(pv, strlen(pv)); |
| 525 |
|
|
RETURN; |
| 526 |
|
|
} |
| 527 |
|
|
|
| 528 |
|
|
PP(pp_bless) |
| 529 |
|
|
{ |
| 530 |
|
|
dSP; |
| 531 |
|
|
HV *stash; |
| 532 |
|
|
|
| 533 |
|
|
if (MAXARG == 1) |
| 534 |
|
|
stash = CopSTASH(PL_curcop); |
| 535 |
|
|
else { |
| 536 |
|
|
SV *ssv = POPs; |
| 537 |
|
|
STRLEN len; |
| 538 |
|
|
char *ptr; |
| 539 |
|
|
|
| 540 |
|
|
if (ssv && !SvGMAGICAL(ssv) && !SvAMAGIC(ssv) && SvROK(ssv)) |
| 541 |
|
|
Perl_croak(aTHX_ "Attempt to bless into a reference"); |
| 542 |
|
|
ptr = SvPV(ssv,len); |
| 543 |
|
|
if (ckWARN(WARN_MISC) && len == 0) |
| 544 |
|
|
Perl_warner(aTHX_ packWARN(WARN_MISC), |
| 545 |
|
|
"Explicit blessing to '' (assuming package main)"); |
| 546 |
|
|
stash = gv_stashpvn(ptr, len, TRUE); |
| 547 |
|
|
} |
| 548 |
|
|
|
| 549 |
|
|
(void)sv_bless(TOPs, stash); |
| 550 |
|
|
RETURN; |
| 551 |
|
|
} |
| 552 |
|
|
|
| 553 |
|
|
PP(pp_gelem) |
| 554 |
|
|
{ |
| 555 |
|
|
GV *gv; |
| 556 |
|
|
SV *sv; |
| 557 |
|
|
SV *tmpRef; |
| 558 |
|
|
char *elem; |
| 559 |
|
|
dSP; |
| 560 |
|
|
STRLEN n_a; |
| 561 |
|
|
|
| 562 |
|
|
sv = POPs; |
| 563 |
|
|
elem = SvPV(sv, n_a); |
| 564 |
|
|
gv = (GV*)POPs; |
| 565 |
|
|
tmpRef = Nullsv; |
| 566 |
|
|
sv = Nullsv; |
| 567 |
|
|
if (elem) { |
| 568 |
|
|
/* elem will always be NUL terminated. */ |
| 569 |
|
|
const char *elem2 = elem + 1; |
| 570 |
|
|
switch (*elem) { |
| 571 |
|
|
case 'A': |
| 572 |
|
|
if (strEQ(elem2, "RRAY")) |
| 573 |
|
|
tmpRef = (SV*)GvAV(gv); |
| 574 |
|
|
break; |
| 575 |
|
|
case 'C': |
| 576 |
|
|
if (strEQ(elem2, "ODE")) |
| 577 |
|
|
tmpRef = (SV*)GvCVu(gv); |
| 578 |
|
|
break; |
| 579 |
|
|
case 'F': |
| 580 |
|
|
if (strEQ(elem2, "ILEHANDLE")) { |
| 581 |
|
|
/* finally deprecated in 5.8.0 */ |
| 582 |
|
|
deprecate("*glob{FILEHANDLE}"); |
| 583 |
|
|
tmpRef = (SV*)GvIOp(gv); |
| 584 |
|
|
} |
| 585 |
|
|
else |
| 586 |
|
|
if (strEQ(elem2, "ORMAT")) |
| 587 |
|
|
tmpRef = (SV*)GvFORM(gv); |
| 588 |
|
|
break; |
| 589 |
|
|
case 'G': |
| 590 |
|
|
if (strEQ(elem2, "LOB")) |
| 591 |
|
|
tmpRef = (SV*)gv; |
| 592 |
|
|
break; |
| 593 |
|
|
case 'H': |
| 594 |
|
|
if (strEQ(elem2, "ASH")) |
| 595 |
|
|
tmpRef = (SV*)GvHV(gv); |
| 596 |
|
|
break; |
| 597 |
|
|
case 'I': |
| 598 |
|
|
if (*elem2 == 'O' && !elem[2]) |
| 599 |
|
|
tmpRef = (SV*)GvIOp(gv); |
| 600 |
|
|
break; |
| 601 |
|
|
case 'N': |
| 602 |
|
|
if (strEQ(elem2, "AME")) |
| 603 |
|
|
sv = newSVpvn(GvNAME(gv), GvNAMELEN(gv)); |
| 604 |
|
|
break; |
| 605 |
|
|
case 'P': |
| 606 |
|
|
if (strEQ(elem2, "ACKAGE")) { |
| 607 |
|
|
char *name = HvNAME(GvSTASH(gv)); |
| 608 |
|
|
sv = newSVpv(name ? name : "__ANON__", 0); |
| 609 |
|
|
} |
| 610 |
|
|
break; |
| 611 |
|
|
case 'S': |
| 612 |
|
|
if (strEQ(elem2, "CALAR")) |
| 613 |
|
|
tmpRef = GvSV(gv); |
| 614 |
|
|
break; |
| 615 |
|
|
} |
| 616 |
|
|
} |
| 617 |
|
|
if (tmpRef) |
| 618 |
|
|
sv = newRV(tmpRef); |
| 619 |
|
|
if (sv) |
| 620 |
|
|
sv_2mortal(sv); |
| 621 |
|
|
else |
| 622 |
|
|
sv = &PL_sv_undef; |
| 623 |
|
|
XPUSHs(sv); |
| 624 |
|
|
RETURN; |
| 625 |
|
|
} |
| 626 |
|
|
|
| 627 |
|
|
/* Pattern matching */ |
| 628 |
|
|
|
| 629 |
|
|
PP(pp_study) |
| 630 |
|
|
{ |
| 631 |
|
|
dSP; dPOPss; |
| 632 |
|
|
register unsigned char *s; |
| 633 |
|
|
register I32 pos; |
| 634 |
|
|
register I32 ch; |
| 635 |
|
|
register I32 *sfirst; |
| 636 |
|
|
register I32 *snext; |
| 637 |
|
|
STRLEN len; |
| 638 |
|
|
|
| 639 |
|
|
if (sv == PL_lastscream) { |
| 640 |
|
|
if (SvSCREAM(sv)) |
| 641 |
|
|
RETPUSHYES; |
| 642 |
|
|
} |
| 643 |
|
|
else { |
| 644 |
|
|
if (PL_lastscream) { |
| 645 |
|
|
SvSCREAM_off(PL_lastscream); |
| 646 |
|
|
SvREFCNT_dec(PL_lastscream); |
| 647 |
|
|
} |
| 648 |
|
|
PL_lastscream = SvREFCNT_inc(sv); |
| 649 |
|
|
} |
| 650 |
|
|
|
| 651 |
|
|
s = (unsigned char*)(SvPV(sv, len)); |
| 652 |
|
|
pos = len; |
| 653 |
|
|
if (pos <= 0) |
| 654 |
|
|
RETPUSHNO; |
| 655 |
|
|
if (pos > PL_maxscream) { |
| 656 |
|
|
if (PL_maxscream < 0) { |
| 657 |
|
|
PL_maxscream = pos + 80; |
| 658 |
|
|
New(301, PL_screamfirst, 256, I32); |
| 659 |
|
|
New(302, PL_screamnext, PL_maxscream, I32); |
| 660 |
|
|
} |
| 661 |
|
|
else { |
| 662 |
|
|
PL_maxscream = pos + pos / 4; |
| 663 |
|
|
Renew(PL_screamnext, PL_maxscream, I32); |
| 664 |
|
|
} |
| 665 |
|
|
} |
| 666 |
|
|
|
| 667 |
|
|
sfirst = PL_screamfirst; |
| 668 |
|
|
snext = PL_screamnext; |
| 669 |
|
|
|
| 670 |
|
|
if (!sfirst || !snext) |
| 671 |
|
|
DIE(aTHX_ "do_study: out of memory"); |
| 672 |
|
|
|
| 673 |
|
|
for (ch = 256; ch; --ch) |
| 674 |
|
|
*sfirst++ = -1; |
| 675 |
|
|
sfirst -= 256; |
| 676 |
|
|
|
| 677 |
|
|
while (--pos >= 0) { |
| 678 |
|
|
ch = s[pos]; |
| 679 |
|
|
if (sfirst[ch] >= 0) |
| 680 |
|
|
snext[pos] = sfirst[ch] - pos; |
| 681 |
|
|
else |
| 682 |
|
|
snext[pos] = -pos; |
| 683 |
|
|
sfirst[ch] = pos; |
| 684 |
|
|
} |
| 685 |
|
|
|
| 686 |
|
|
SvSCREAM_on(sv); |
| 687 |
|
|
/* piggyback on m//g magic */ |
| 688 |
|
|
sv_magic(sv, Nullsv, PERL_MAGIC_regex_global, Nullch, 0); |
| 689 |
|
|
RETPUSHYES; |
| 690 |
|
|
} |
| 691 |
|
|
|
| 692 |
|
|
PP(pp_trans) |
| 693 |
|
|
{ |
| 694 |
|
|
dSP; dTARG; |
| 695 |
|
|
SV *sv; |
| 696 |
|
|
|
| 697 |
|
|
if (PL_op->op_flags & OPf_STACKED) |
| 698 |
|
|
sv = POPs; |
| 699 |
|
|
else { |
| 700 |
|
|
sv = DEFSV; |
| 701 |
|
|
EXTEND(SP,1); |
| 702 |
|
|
} |
| 703 |
|
|
TARG = sv_newmortal(); |
| 704 |
|
|
PUSHi(do_trans(sv)); |
| 705 |
|
|
RETURN; |
| 706 |
|
|
} |
| 707 |
|
|
|
| 708 |
|
|
/* Lvalue operators. */ |
| 709 |
|
|
|
| 710 |
|
|
PP(pp_schop) |
| 711 |
|
|
{ |
| 712 |
|
|
dSP; dTARGET; |
| 713 |
|
|
do_chop(TARG, TOPs); |
| 714 |
|
|
SETTARG; |
| 715 |
|
|
RETURN; |
| 716 |
|
|
} |
| 717 |
|
|
|
| 718 |
|
|
PP(pp_chop) |
| 719 |
|
|
{ |
| 720 |
|
|
dSP; dMARK; dTARGET; dORIGMARK; |
| 721 |
|
|
while (MARK < SP) |
| 722 |
|
|
do_chop(TARG, *++MARK); |
| 723 |
|
|
SP = ORIGMARK; |
| 724 |
|
|
PUSHTARG; |
| 725 |
|
|
RETURN; |
| 726 |
|
|
} |
| 727 |
|
|
|
| 728 |
|
|
PP(pp_schomp) |
| 729 |
|
|
{ |
| 730 |
|
|
dSP; dTARGET; |
| 731 |
|
|
SETi(do_chomp(TOPs)); |
| 732 |
|
|
RETURN; |
| 733 |
|
|
} |
| 734 |
|
|
|
| 735 |
|
|
PP(pp_chomp) |
| 736 |
|
|
{ |
| 737 |
|
|
dSP; dMARK; dTARGET; |
| 738 |
|
|
register I32 count = 0; |
| 739 |
|
|
|
| 740 |
|
|
while (SP > MARK) |
| 741 |
|
|
count += do_chomp(POPs); |
| 742 |
|
|
PUSHi(count); |
| 743 |
|
|
RETURN; |
| 744 |
|
|
} |
| 745 |
|
|
|
| 746 |
|
|
PP(pp_defined) |
| 747 |
|
|
{ |
| 748 |
|
|
dSP; |
| 749 |
|
|
register SV* sv; |
| 750 |
|
|
|
| 751 |
|
|
sv = POPs; |
| 752 |
|
|
if (!sv || !SvANY(sv)) |
| 753 |
|
|
RETPUSHNO; |
| 754 |
|
|
switch (SvTYPE(sv)) { |
| 755 |
|
|
case SVt_PVAV: |
| 756 |
|
|
if (AvMAX(sv) >= 0 || SvGMAGICAL(sv) |
| 757 |
|
|
|| (SvRMAGICAL(sv) && mg_find(sv, PERL_MAGIC_tied))) |
| 758 |
|
|
RETPUSHYES; |
| 759 |
|
|
break; |
| 760 |
|
|
case SVt_PVHV: |
| 761 |
|
|
if (HvARRAY(sv) || SvGMAGICAL(sv) |
| 762 |
|
|
|| (SvRMAGICAL(sv) && mg_find(sv, PERL_MAGIC_tied))) |
| 763 |
|
|
RETPUSHYES; |
| 764 |
|
|
break; |
| 765 |
|
|
case SVt_PVCV: |
| 766 |
|
|
if (CvROOT(sv) || CvXSUB(sv)) |
| 767 |
|
|
RETPUSHYES; |
| 768 |
|
|
break; |
| 769 |
|
|
default: |
| 770 |
|
|
if (SvGMAGICAL(sv)) |
| 771 |
|
|
mg_get(sv); |
| 772 |
|
|
if (SvOK(sv)) |
| 773 |
|
|
RETPUSHYES; |
| 774 |
|
|
} |
| 775 |
|
|
RETPUSHNO; |
| 776 |
|
|
} |
| 777 |
|
|
|
| 778 |
|
|
PP(pp_undef) |
| 779 |
|
|
{ |
| 780 |
|
|
dSP; |
| 781 |
|
|
SV *sv; |
| 782 |
|
|
|
| 783 |
|
|
if (!PL_op->op_private) { |
| 784 |
|
|
EXTEND(SP, 1); |
| 785 |
|
|
RETPUSHUNDEF; |
| 786 |
|
|
} |
| 787 |
|
|
|
| 788 |
|
|
sv = POPs; |
| 789 |
|
|
if (!sv) |
| 790 |
|
|
RETPUSHUNDEF; |
| 791 |
|
|
|
| 792 |
|
|
if (SvTHINKFIRST(sv)) |
| 793 |
|
|
sv_force_normal(sv); |
| 794 |
|
|
|
| 795 |
|
|
switch (SvTYPE(sv)) { |
| 796 |
|
|
case SVt_NULL: |
| 797 |
|
|
break; |
| 798 |
|
|
case SVt_PVAV: |
| 799 |
|
|
av_undef((AV*)sv); |
| 800 |
|
|
break; |
| 801 |
|
|
case SVt_PVHV: |
| 802 |
|
|
hv_undef((HV*)sv); |
| 803 |
|
|
break; |
| 804 |
|
|
case SVt_PVCV: |
| 805 |
|
|
if (ckWARN(WARN_MISC) && cv_const_sv((CV*)sv)) |
| 806 |
|
|
Perl_warner(aTHX_ packWARN(WARN_MISC), "Constant subroutine %s undefined", |
| 807 |
|
|
CvANON((CV*)sv) ? "(anonymous)" : GvENAME(CvGV((CV*)sv))); |
| 808 |
|
|
/* FALL THROUGH */ |
| 809 |
|
|
case SVt_PVFM: |
| 810 |
|
|
{ |
| 811 |
|
|
/* let user-undef'd sub keep its identity */ |
| 812 |
|
|
GV* gv = CvGV((CV*)sv); |
| 813 |
|
|
cv_undef((CV*)sv); |
| 814 |
|
|
CvGV((CV*)sv) = gv; |
| 815 |
|
|
} |
| 816 |
|
|
break; |
| 817 |
|
|
case SVt_PVGV: |
| 818 |
|
|
if (SvFAKE(sv)) |
| 819 |
|
|
SvSetMagicSV(sv, &PL_sv_undef); |
| 820 |
|
|
else { |
| 821 |
|
|
GP *gp; |
| 822 |
|
|
gp_free((GV*)sv); |
| 823 |
|
|
Newz(602, gp, 1, GP); |
| 824 |
|
|
GvGP(sv) = gp_ref(gp); |
| 825 |
|
|
GvSV(sv) = NEWSV(72,0); |
| 826 |
|
|
GvLINE(sv) = CopLINE(PL_curcop); |
| 827 |
|
|
GvEGV(sv) = (GV*)sv; |
| 828 |
|
|
GvMULTI_on(sv); |
| 829 |
|
|
} |
| 830 |
|
|
break; |
| 831 |
|
|
default: |
| 832 |
|
|
if (SvTYPE(sv) >= SVt_PV && SvPVX(sv) && SvLEN(sv)) { |
| 833 |
|
|
SvOOK_off(sv); |
| 834 |
|
|
Safefree(SvPVX(sv)); |
| 835 |
|
|
SvPV_set(sv, Nullch); |
| 836 |
|
|
SvLEN_set(sv, 0); |
| 837 |
|
|
} |
| 838 |
|
|
SvOK_off(sv); |
| 839 |
|
|
SvSETMAGIC(sv); |
| 840 |
|
|
} |
| 841 |
|
|
|
| 842 |
|
|
RETPUSHUNDEF; |
| 843 |
|
|
} |
| 844 |
|
|
|
| 845 |
|
|
PP(pp_predec) |
| 846 |
|
|
{ |
| 847 |
|
|
dSP; |
| 848 |
|
|
if (SvTYPE(TOPs) > SVt_PVLV) |
| 849 |
|
|
DIE(aTHX_ PL_no_modify); |
| 850 |
|
|
if (!SvREADONLY(TOPs) && SvIOK_notUV(TOPs) && !SvNOK(TOPs) && !SvPOK(TOPs) |
| 851 |
|
|
&& SvIVX(TOPs) != IV_MIN) |
| 852 |
|
|
{ |
| 853 |
|
|
--SvIVX(TOPs); |
| 854 |
|
|
SvFLAGS(TOPs) &= ~(SVp_NOK|SVp_POK); |
| 855 |
|
|
} |
| 856 |
|
|
else |
| 857 |
|
|
sv_dec(TOPs); |
| 858 |
|
|
SvSETMAGIC(TOPs); |
| 859 |
|
|
return NORMAL; |
| 860 |
|
|
} |
| 861 |
|
|
|
| 862 |
|
|
PP(pp_postinc) |
| 863 |
|
|
{ |
| 864 |
|
|
dSP; dTARGET; |
| 865 |
|
|
if (SvTYPE(TOPs) > SVt_PVLV) |
| 866 |
|
|
DIE(aTHX_ PL_no_modify); |
| 867 |
|
|
sv_setsv(TARG, TOPs); |
| 868 |
|
|
if (!SvREADONLY(TOPs) && SvIOK_notUV(TOPs) && !SvNOK(TOPs) && !SvPOK(TOPs) |
| 869 |
|
|
&& SvIVX(TOPs) != IV_MAX) |
| 870 |
|
|
{ |
| 871 |
|
|
++SvIVX(TOPs); |
| 872 |
|
|
SvFLAGS(TOPs) &= ~(SVp_NOK|SVp_POK); |
| 873 |
|
|
} |
| 874 |
|
|
else |
| 875 |
|
|
sv_inc(TOPs); |
| 876 |
|
|
SvSETMAGIC(TOPs); |
| 877 |
|
|
/* special case for undef: see thread at 2003-03/msg00536.html in archive */ |
| 878 |
|
|
if (!SvOK(TARG)) |
| 879 |
|
|
sv_setiv(TARG, 0); |
| 880 |
|
|
SETs(TARG); |
| 881 |
|
|
return NORMAL; |
| 882 |
|
|
} |
| 883 |
|
|
|
| 884 |
|
|
PP(pp_postdec) |
| 885 |
|
|
{ |
| 886 |
|
|
dSP; dTARGET; |
| 887 |
|
|
if (SvTYPE(TOPs) > SVt_PVLV) |
| 888 |
|
|
DIE(aTHX_ PL_no_modify); |
| 889 |
|
|
sv_setsv(TARG, TOPs); |
| 890 |
|
|
if (!SvREADONLY(TOPs) && SvIOK_notUV(TOPs) && !SvNOK(TOPs) && !SvPOK(TOPs) |
| 891 |
|
|
&& SvIVX(TOPs) != IV_MIN) |
| 892 |
|
|
{ |
| 893 |
|
|
--SvIVX(TOPs); |
| 894 |
|
|
SvFLAGS(TOPs) &= ~(SVp_NOK|SVp_POK); |
| 895 |
|
|
} |
| 896 |
|
|
else |
| 897 |
|
|
sv_dec(TOPs); |
| 898 |
|
|
SvSETMAGIC(TOPs); |
| 899 |
|
|
SETs(TARG); |
| 900 |
|
|
return NORMAL; |
| 901 |
|
|
} |
| 902 |
|
|
|
| 903 |
|
|
/* Ordinary operators. */ |
| 904 |
|
|
|
| 905 |
|
|
PP(pp_pow) |
| 906 |
|
|
{ |
| 907 |
|
|
dSP; dATARGET; |
| 908 |
|
|
#ifdef PERL_PRESERVE_IVUV |
| 909 |
|
|
bool is_int = 0; |
| 910 |
|
|
#endif |
| 911 |
|
|
tryAMAGICbin(pow,opASSIGN); |
| 912 |
|
|
#ifdef PERL_PRESERVE_IVUV |
| 913 |
|
|
/* For integer to integer power, we do the calculation by hand wherever |
| 914 |
|
|
we're sure it is safe; otherwise we call pow() and try to convert to |
| 915 |
|
|
integer afterwards. */ |
| 916 |
|
|
{ |
| 917 |
|
|
SvIV_please(TOPm1s); |
| 918 |
|
|
if (SvIOK(TOPm1s)) { |
| 919 |
|
|
bool baseuok = SvUOK(TOPm1s); |
| 920 |
|
|
UV baseuv; |
| 921 |
|
|
|
| 922 |
|
|
if (baseuok) { |
| 923 |
|
|
baseuv = SvUVX(TOPm1s); |
| 924 |
|
|
} else { |
| 925 |
|
|
IV iv = SvIVX(TOPm1s); |
| 926 |
|
|
if (iv >= 0) { |
| 927 |
|
|
baseuv = iv; |
| 928 |
|
|
baseuok = TRUE; /* effectively it's a UV now */ |
| 929 |
|
|
} else { |
| 930 |
|
|
baseuv = -iv; /* abs, baseuok == false records sign */ |
| 931 |
|
|
} |
| 932 |
|
|
} |
| 933 |
|
|
SvIV_please(TOPs); |
| 934 |
|
|
if (SvIOK(TOPs)) { |
| 935 |
|
|
UV power; |
| 936 |
|
|
|
| 937 |
|
|
if (SvUOK(TOPs)) { |
| 938 |
|
|
power = SvUVX(TOPs); |
| 939 |
|
|
} else { |
| 940 |
|
|
IV iv = SvIVX(TOPs); |
| 941 |
|
|
if (iv >= 0) { |
| 942 |
|
|
power = iv; |
| 943 |
|
|
} else { |
| 944 |
|
|
goto float_it; /* Can't do negative powers this way. */ |
| 945 |
|
|
} |
| 946 |
|
|
} |
| 947 |
|
|
/* now we have integer ** positive integer. */ |
| 948 |
|
|
is_int = 1; |
| 949 |
|
|
|
| 950 |
|
|
/* foo & (foo - 1) is zero only for a power of 2. */ |
| 951 |
|
|
if (!(baseuv & (baseuv - 1))) { |
| 952 |
|
|
/* We are raising power-of-2 to a positive integer. |
| 953 |
|
|
The logic here will work for any base (even non-integer |
| 954 |
|
|
bases) but it can be less accurate than |
| 955 |
|
|
pow (base,power) or exp (power * log (base)) when the |
| 956 |
|
|
intermediate values start to spill out of the mantissa. |
| 957 |
|
|
With powers of 2 we know this can't happen. |
| 958 |
|
|
And powers of 2 are the favourite thing for perl |
| 959 |
|
|
programmers to notice ** not doing what they mean. */ |
| 960 |
|
|
NV result = 1.0; |
| 961 |
|
|
NV base = baseuok ? baseuv : -(NV)baseuv; |
| 962 |
|
|
int n = 0; |
| 963 |
|
|
|
| 964 |
|
|
for (; power; base *= base, n++) { |
| 965 |
|
|
/* Do I look like I trust gcc with long longs here? |
| 966 |
|
|
Do I hell. */ |
| 967 |
|
|
UV bit = (UV)1 << (UV)n; |
| 968 |
|
|
if (power & bit) { |
| 969 |
|
|
result *= base; |
| 970 |
|
|
/* Only bother to clear the bit if it is set. */ |
| 971 |
|
|
power -= bit; |
| 972 |
|
|
/* Avoid squaring base again if we're done. */ |
| 973 |
|
|
if (power == 0) break; |
| 974 |
|
|
} |
| 975 |
|
|
} |
| 976 |
|
|
SP--; |
| 977 |
|
|
SETn( result ); |
| 978 |
|
|
SvIV_please(TOPs); |
| 979 |
|
|
RETURN; |
| 980 |
|
|
} else { |
| 981 |
|
|
register unsigned int highbit = 8 * sizeof(UV); |
| 982 |
|
|
register unsigned int lowbit = 0; |
| 983 |
|
|
register unsigned int diff; |
| 984 |
|
|
bool odd_power = (bool)(power & 1); |
| 985 |
|
|
while ((diff = (highbit - lowbit) >> 1)) { |
| 986 |
|
|
if (baseuv & ~((1 << (lowbit + diff)) - 1)) |
| 987 |
|
|
lowbit += diff; |
| 988 |
|
|
else |
| 989 |
|
|
highbit -= diff; |
| 990 |
|
|
} |
| 991 |
|
|
/* we now have baseuv < 2 ** highbit */ |
| 992 |
|
|
if (power * highbit <= 8 * sizeof(UV)) { |
| 993 |
|
|
/* result will definitely fit in UV, so use UV math |
| 994 |
|
|
on same algorithm as above */ |
| 995 |
|
|
register UV result = 1; |
| 996 |
|
|
register UV base = baseuv; |
| 997 |
|
|
register int n = 0; |
| 998 |
|
|
for (; power; base *= base, n++) { |
| 999 |
|
|
register UV bit = (UV)1 << (UV)n; |
| 1000 |
|
|
if (power & bit) { |
| 1001 |
|
|
result *= base; |
| 1002 |
|
|
power -= bit; |
| 1003 |
|
|
if (power == 0) break; |
| 1004 |
|
|
} |
| 1005 |
|
|
} |
| 1006 |
|
|
SP--; |
| 1007 |
|
|
if (baseuok || !odd_power) |
| 1008 |
|
|
/* answer is positive */ |
| 1009 |
|
|
SETu( result ); |
| 1010 |
|
|
else if (result <= (UV)IV_MAX) |
| 1011 |
|
|
/* answer negative, fits in IV */ |
| 1012 |
|
|
SETi( -(IV)result ); |
| 1013 |
|
|
else if (result == (UV)IV_MIN) |
| 1014 |
|
|
/* 2's complement assumption: special case IV_MIN */ |
| 1015 |
|
|
SETi( IV_MIN ); |
| 1016 |
|
|
else |
| 1017 |
|
|
/* answer negative, doesn't fit */ |
| 1018 |
|
|
SETn( -(NV)result ); |
| 1019 |
|
|
RETURN; |
| 1020 |
|
|
} |
| 1021 |
|
|
} |
| 1022 |
|
|
} |
| 1023 |
|
|
} |
| 1024 |
|
|
} |
| 1025 |
|
|
float_it: |
| 1026 |
|
|
#endif |
| 1027 |
|
|
{ |
| 1028 |
|
|
dPOPTOPnnrl; |
| 1029 |
|
|
SETn( Perl_pow( left, right) ); |
| 1030 |
|
|
#ifdef PERL_PRESERVE_IVUV |
| 1031 |
|
|
if (is_int) |
| 1032 |
|
|
SvIV_please(TOPs); |
| 1033 |
|
|
#endif |
| 1034 |
|
|
RETURN; |
| 1035 |
|
|
} |
| 1036 |
|
|
} |
| 1037 |
|
|
|
| 1038 |
|
|
PP(pp_multiply) |
| 1039 |
|
|
{ |
| 1040 |
|
|
dSP; dATARGET; tryAMAGICbin(mult,opASSIGN); |
| 1041 |
|
|
#ifdef PERL_PRESERVE_IVUV |
| 1042 |
|
|
SvIV_please(TOPs); |
| 1043 |
|
|
if (SvIOK(TOPs)) { |
| 1044 |
|
|
/* Unless the left argument is integer in range we are going to have to |
| 1045 |
|
|
use NV maths. Hence only attempt to coerce the right argument if |
| 1046 |
|
|
we know the left is integer. */ |
| 1047 |
|
|
/* Left operand is defined, so is it IV? */ |
| 1048 |
|
|
SvIV_please(TOPm1s); |
| 1049 |
|
|
if (SvIOK(TOPm1s)) { |
| 1050 |
|
|
bool auvok = SvUOK(TOPm1s); |
| 1051 |
|
|
bool buvok = SvUOK(TOPs); |
| 1052 |
|
|
const UV topmask = (~ (UV)0) << (4 * sizeof (UV)); |
| 1053 |
|
|
const UV botmask = ~((~ (UV)0) << (4 * sizeof (UV))); |
| 1054 |
|
|
UV alow; |
| 1055 |
|
|
UV ahigh; |
| 1056 |
|
|
UV blow; |
| 1057 |
|
|
UV bhigh; |
| 1058 |
|
|
|
| 1059 |
|
|
if (auvok) { |
| 1060 |
|
|
alow = SvUVX(TOPm1s); |
| 1061 |
|
|
} else { |
| 1062 |
|
|
IV aiv = SvIVX(TOPm1s); |
| 1063 |
|
|
if (aiv >= 0) { |
| 1064 |
|
|
alow = aiv; |
| 1065 |
|
|
auvok = TRUE; /* effectively it's a UV now */ |
| 1066 |
|
|
} else { |
| 1067 |
|
|
alow = -aiv; /* abs, auvok == false records sign */ |
| 1068 |
|
|
} |
| 1069 |
|
|
} |
| 1070 |
|
|
if (buvok) { |
| 1071 |
|
|
blow = SvUVX(TOPs); |
| 1072 |
|
|
} else { |
| 1073 |
|
|
IV biv = SvIVX(TOPs); |
| 1074 |
|
|
if (biv >= 0) { |
| 1075 |
|
|
blow = biv; |
| 1076 |
|
|
buvok = TRUE; /* effectively it's a UV now */ |
| 1077 |
|
|
} else { |
| 1078 |
|
|
blow = -biv; /* abs, buvok == false records sign */ |
| 1079 |
|
|
} |
| 1080 |
|
|
} |
| 1081 |
|
|
|
| 1082 |
|
|
/* If this does sign extension on unsigned it's time for plan B */ |
| 1083 |
|
|
ahigh = alow >> (4 * sizeof (UV)); |
| 1084 |
|
|
alow &= botmask; |
| 1085 |
|
|
bhigh = blow >> (4 * sizeof (UV)); |
| 1086 |
|
|
blow &= botmask; |
| 1087 |
|
|
if (ahigh && bhigh) { |
| 1088 |
|
|
/* eg 32 bit is at least 0x10000 * 0x10000 == 0x100000000 |
| 1089 |
|
|
which is overflow. Drop to NVs below. */ |
| 1090 |
|
|
} else if (!ahigh && !bhigh) { |
| 1091 |
|
|
/* eg 32 bit is at most 0xFFFF * 0xFFFF == 0xFFFE0001 |
| 1092 |
|
|
so the unsigned multiply cannot overflow. */ |
| 1093 |
|
|
UV product = alow * blow; |
| 1094 |
|
|
if (auvok == buvok) { |
| 1095 |
|
|
/* -ve * -ve or +ve * +ve gives a +ve result. */ |
| 1096 |
|
|
SP--; |
| 1097 |
|
|
SETu( product ); |
| 1098 |
|
|
RETURN; |
| 1099 |
|
|
} else if (product <= (UV)IV_MIN) { |
| 1100 |
|
|
/* 2s complement assumption that (UV)-IV_MIN is correct. */ |
| 1101 |
|
|
/* -ve result, which could overflow an IV */ |
| 1102 |
|
|
SP--; |
| 1103 |
|
|
SETi( -(IV)product ); |
| 1104 |
|
|
RETURN; |
| 1105 |
|
|
} /* else drop to NVs below. */ |
| 1106 |
|
|
} else { |
| 1107 |
|
|
/* One operand is large, 1 small */ |
| 1108 |
|
|
UV product_middle; |
| 1109 |
|
|
if (bhigh) { |
| 1110 |
|
|
/* swap the operands */ |
| 1111 |
|
|
ahigh = bhigh; |
| 1112 |
|
|
bhigh = blow; /* bhigh now the temp var for the swap */ |
| 1113 |
|
|
blow = alow; |
| 1114 |
|
|
alow = bhigh; |
| 1115 |
|
|
} |
| 1116 |
|
|
/* now, ((ahigh * blow) << half_UV_len) + (alow * blow) |
| 1117 |
|
|
multiplies can't overflow. shift can, add can, -ve can. */ |
| 1118 |
|
|
product_middle = ahigh * blow; |
| 1119 |
|
|
if (!(product_middle & topmask)) { |
| 1120 |
|
|
/* OK, (ahigh * blow) won't lose bits when we shift it. */ |
| 1121 |
|
|
UV product_low; |
| 1122 |
|
|
product_middle <<= (4 * sizeof (UV)); |
| 1123 |
|
|
product_low = alow * blow; |
| 1124 |
|
|
|
| 1125 |
|
|
/* as for pp_add, UV + something mustn't get smaller. |
| 1126 |
|
|
IIRC ANSI mandates this wrapping *behaviour* for |
| 1127 |
|
|
unsigned whatever the actual representation*/ |
| 1128 |
|
|
product_low += product_middle; |
| 1129 |
|
|
if (product_low >= product_middle) { |
| 1130 |
|
|
/* didn't overflow */ |
| 1131 |
|
|
if (auvok == buvok) { |
| 1132 |
|
|
/* -ve * -ve or +ve * +ve gives a +ve result. */ |
| 1133 |
|
|
SP--; |
| 1134 |
|
|
SETu( product_low ); |
| 1135 |
|
|
RETURN; |
| 1136 |
|
|
} else if (product_low <= (UV)IV_MIN) { |
| 1137 |
|
|
/* 2s complement assumption again */ |
| 1138 |
|
|
/* -ve result, which could overflow an IV */ |
| 1139 |
|
|
SP--; |
| 1140 |
|
|
SETi( -(IV)product_low ); |
| 1141 |
|
|
RETURN; |
| 1142 |
|
|
} /* else drop to NVs below. */ |
| 1143 |
|
|
} |
| 1144 |
|
|
} /* product_middle too large */ |
| 1145 |
|
|
} /* ahigh && bhigh */ |
| 1146 |
|
|
} /* SvIOK(TOPm1s) */ |
| 1147 |
|
|
} /* SvIOK(TOPs) */ |
| 1148 |
|
|
#endif |
| 1149 |
|
|
{ |
| 1150 |
|
|
dPOPTOPnnrl; |
| 1151 |
|
|
SETn( left * right ); |
| 1152 |
|
|
RETURN; |
| 1153 |
|
|
} |
| 1154 |
|
|
} |
| 1155 |
|
|
|
| 1156 |
|
|
PP(pp_divide) |
| 1157 |
|
|
{ |
| 1158 |
|
|
dSP; dATARGET; tryAMAGICbin(div,opASSIGN); |
| 1159 |
|
|
/* Only try to do UV divide first |
| 1160 |
|
|
if ((SLOPPYDIVIDE is true) or |
| 1161 |
|
|
(PERL_PRESERVE_IVUV is true and one or both SV is a UV too large |
| 1162 |
|
|
to preserve)) |
| 1163 |
|
|
The assumption is that it is better to use floating point divide |
| 1164 |
|
|
whenever possible, only doing integer divide first if we can't be sure. |
| 1165 |
|
|
If NV_PRESERVES_UV is true then we know at compile time that no UV |
| 1166 |
|
|
can be too large to preserve, so don't need to compile the code to |
| 1167 |
|
|
test the size of UVs. */ |
| 1168 |
|
|
|
| 1169 |
|
|
#ifdef SLOPPYDIVIDE |
| 1170 |
|
|
# define PERL_TRY_UV_DIVIDE |
| 1171 |
|
|
/* ensure that 20./5. == 4. */ |
| 1172 |
|
|
#else |
| 1173 |
|
|
# ifdef PERL_PRESERVE_IVUV |
| 1174 |
|
|
# ifndef NV_PRESERVES_UV |
| 1175 |
|
|
# define PERL_TRY_UV_DIVIDE |
| 1176 |
|
|
# endif |
| 1177 |
|
|
# endif |
| 1178 |
|
|
#endif |
| 1179 |
|
|
|
| 1180 |
|
|
#ifdef PERL_TRY_UV_DIVIDE |
| 1181 |
|
|
SvIV_please(TOPs); |
| 1182 |
|
|
if (SvIOK(TOPs)) { |
| 1183 |
|
|
SvIV_please(TOPm1s); |
| 1184 |
|
|
if (SvIOK(TOPm1s)) { |
| 1185 |
|
|
bool left_non_neg = SvUOK(TOPm1s); |
| 1186 |
|
|
bool right_non_neg = SvUOK(TOPs); |
| 1187 |
|
|
UV left; |
| 1188 |
|
|
UV right; |
| 1189 |
|
|
|
| 1190 |
|
|
if (right_non_neg) { |
| 1191 |
|
|
right = SvUVX(TOPs); |
| 1192 |
|
|
} |
| 1193 |
|
|
else { |
| 1194 |
|
|
IV biv = SvIVX(TOPs); |
| 1195 |
|
|
if (biv >= 0) { |
| 1196 |
|
|
right = biv; |
| 1197 |
|
|
right_non_neg = TRUE; /* effectively it's a UV now */ |
| 1198 |
|
|
} |
| 1199 |
|
|
else { |
| 1200 |
|
|
right = -biv; |
| 1201 |
|
|
} |
| 1202 |
|
|
} |
| 1203 |
|
|
/* historically undef()/0 gives a "Use of uninitialized value" |
| 1204 |
|
|
warning before dieing, hence this test goes here. |
| 1205 |
|
|
If it were immediately before the second SvIV_please, then |
| 1206 |
|
|
DIE() would be invoked before left was even inspected, so |
| 1207 |
|
|
no inpsection would give no warning. */ |
| 1208 |
|
|
if (right == 0) |
| 1209 |
|
|
DIE(aTHX_ "Illegal division by zero"); |
| 1210 |
|
|
|
| 1211 |
|
|
if (left_non_neg) { |
| 1212 |
|
|
left = SvUVX(TOPm1s); |
| 1213 |
|
|
} |
| 1214 |
|
|
else { |
| 1215 |
|
|
IV aiv = SvIVX(TOPm1s); |
| 1216 |
|
|
if (aiv >= 0) { |
| 1217 |
|
|
left = aiv; |
| 1218 |
|
|
left_non_neg = TRUE; /* effectively it's a UV now */ |
| 1219 |
|
|
} |
| 1220 |
|
|
else { |
| 1221 |
|
|
left = -aiv; |
| 1222 |
|
|
} |
| 1223 |
|
|
} |
| 1224 |
|
|
|
| 1225 |
|
|
if (left >= right |
| 1226 |
|
|
#ifdef SLOPPYDIVIDE |
| 1227 |
|
|
/* For sloppy divide we always attempt integer division. */ |
| 1228 |
|
|
#else |
| 1229 |
|
|
/* Otherwise we only attempt it if either or both operands |
| 1230 |
|
|
would not be preserved by an NV. If both fit in NVs |
| 1231 |
|
|
we fall through to the NV divide code below. However, |
| 1232 |
|
|
as left >= right to ensure integer result here, we know that |
| 1233 |
|
|
we can skip the test on the right operand - right big |
| 1234 |
|
|
enough not to be preserved can't get here unless left is |
| 1235 |
|
|
also too big. */ |
| 1236 |
|
|
|
| 1237 |
|
|
&& (left > ((UV)1 << NV_PRESERVES_UV_BITS)) |
| 1238 |
|
|
#endif |
| 1239 |
|
|
) { |
| 1240 |
|
|
/* Integer division can't overflow, but it can be imprecise. */ |
| 1241 |
|
|
UV result = left / right; |
| 1242 |
|
|
if (result * right == left) { |
| 1243 |
|
|
SP--; /* result is valid */ |
| 1244 |
|
|
if (left_non_neg == right_non_neg) { |
| 1245 |
|
|
/* signs identical, result is positive. */ |
| 1246 |
|
|
SETu( result ); |
| 1247 |
|
|
RETURN; |
| 1248 |
|
|
} |
| 1249 |
|
|
/* 2s complement assumption */ |
| 1250 |
|
|
if (result <= (UV)IV_MIN) |
| 1251 |
|
|
SETi( -(IV)result ); |
| 1252 |
|
|
else { |
| 1253 |
|
|
/* It's exact but too negative for IV. */ |
| 1254 |
|
|
SETn( -(NV)result ); |
| 1255 |
|
|
} |
| 1256 |
|
|
RETURN; |
| 1257 |
|
|
} /* tried integer divide but it was not an integer result */ |
| 1258 |
|
|
} /* else (PERL_ABS(result) < 1.0) or (both UVs in range for NV) */ |
| 1259 |
|
|
} /* left wasn't SvIOK */ |
| 1260 |
|
|
} /* right wasn't SvIOK */ |
| 1261 |
|
|
#endif /* PERL_TRY_UV_DIVIDE */ |
| 1262 |
|
|
{ |
| 1263 |
|
|
dPOPPOPnnrl; |
| 1264 |
|
|
if (right == 0.0) |
| 1265 |
|
|
DIE(aTHX_ "Illegal division by zero"); |
| 1266 |
|
|
PUSHn( left / right ); |
| 1267 |
|
|
RETURN; |
| 1268 |
|
|
} |
| 1269 |
|
|
} |
| 1270 |
|
|
|
| 1271 |
|
|
PP(pp_modulo) |
| 1272 |
|
|
{ |
| 1273 |
|
|
dSP; dATARGET; tryAMAGICbin(modulo,opASSIGN); |
| 1274 |
|
|
{ |
| 1275 |
|
|
UV left = 0; |
| 1276 |
|
|
UV right = 0; |
| 1277 |
|
|
bool left_neg = FALSE; |
| 1278 |
|
|
bool right_neg = FALSE; |
| 1279 |
|
|
bool use_double = FALSE; |
| 1280 |
|
|
bool dright_valid = FALSE; |
| 1281 |
|
|
NV dright = 0.0; |
| 1282 |
|
|
NV dleft = 0.0; |
| 1283 |
|
|
|
| 1284 |
|
|
SvIV_please(TOPs); |
| 1285 |
|
|
if (SvIOK(TOPs)) { |
| 1286 |
|
|
right_neg = !SvUOK(TOPs); |
| 1287 |
|
|
if (!right_neg) { |
| 1288 |
|
|
right = SvUVX(POPs); |
| 1289 |
|
|
} else { |
| 1290 |
|
|
IV biv = SvIVX(POPs); |
| 1291 |
|
|
if (biv >= 0) { |
| 1292 |
|
|
right = biv; |
| 1293 |
|
|
right_neg = FALSE; /* effectively it's a UV now */ |
| 1294 |
|
|
} else { |
| 1295 |
|
|
right = -biv; |
| 1296 |
|
|
} |
| 1297 |
|
|
} |
| 1298 |
|
|
} |
| 1299 |
|
|
else { |
| 1300 |
|
|
dright = POPn; |
| 1301 |
|
|
right_neg = dright < 0; |
| 1302 |
|
|
if (right_neg) |
| 1303 |
|
|
dright = -dright; |
| 1304 |
|
|
if (dright < UV_MAX_P1) { |
| 1305 |
|
|
right = U_V(dright); |
| 1306 |
|
|
dright_valid = TRUE; /* In case we need to use double below. */ |
| 1307 |
|
|
} else { |
| 1308 |
|
|
use_double = TRUE; |
| 1309 |
|
|
} |
| 1310 |
|
|
} |
| 1311 |
|
|
|
| 1312 |
|
|
/* At this point use_double is only true if right is out of range for |
| 1313 |
|
|
a UV. In range NV has been rounded down to nearest UV and |
| 1314 |
|
|
use_double false. */ |
| 1315 |
|
|
SvIV_please(TOPs); |
| 1316 |
|
|
if (!use_double && SvIOK(TOPs)) { |
| 1317 |
|
|
if (SvIOK(TOPs)) { |
| 1318 |
|
|
left_neg = !SvUOK(TOPs); |
| 1319 |
|
|
if (!left_neg) { |
| 1320 |
|
|
left = SvUVX(POPs); |
| 1321 |
|
|
} else { |
| 1322 |
|
|
IV aiv = SvIVX(POPs); |
| 1323 |
|
|
if (aiv >= 0) { |
| 1324 |
|
|
left = aiv; |
| 1325 |
|
|
left_neg = FALSE; /* effectively it's a UV now */ |
| 1326 |
|
|
} else { |
| 1327 |
|
|
left = -aiv; |
| 1328 |
|
|
} |
| 1329 |
|
|
} |
| 1330 |
|
|
} |
| 1331 |
|
|
} |
| 1332 |
|
|
else { |
| 1333 |
|
|
dleft = POPn; |
| 1334 |
|
|
left_neg = dleft < 0; |
| 1335 |
|
|
if (left_neg) |
| 1336 |
|
|
dleft = -dleft; |
| 1337 |
|
|
|
| 1338 |
|
|
/* This should be exactly the 5.6 behaviour - if left and right are |
| 1339 |
|
|
both in range for UV then use U_V() rather than floor. */ |
| 1340 |
|
|
if (!use_double) { |
| 1341 |
|
|
if (dleft < UV_MAX_P1) { |
| 1342 |
|
|
/* right was in range, so is dleft, so use UVs not double. |
| 1343 |
|
|
*/ |
| 1344 |
|
|
left = U_V(dleft); |
| 1345 |
|
|
} |
| 1346 |
|
|
/* left is out of range for UV, right was in range, so promote |
| 1347 |
|
|
right (back) to double. */ |
| 1348 |
|
|
else { |
| 1349 |
|
|
/* The +0.5 is used in 5.6 even though it is not strictly |
| 1350 |
|
|
consistent with the implicit +0 floor in the U_V() |
| 1351 |
|
|
inside the #if 1. */ |
| 1352 |
|
|
dleft = Perl_floor(dleft + 0.5); |
| 1353 |
|
|
use_double = TRUE; |
| 1354 |
|
|
if (dright_valid) |
| 1355 |
|
|
dright = Perl_floor(dright + 0.5); |
| 1356 |
|
|
else |
| 1357 |
|
|
dright = right; |
| 1358 |
|
|
} |
| 1359 |
|
|
} |
| 1360 |
|
|
} |
| 1361 |
|
|
if (use_double) { |
| 1362 |
|
|
NV dans; |
| 1363 |
|
|
|
| 1364 |
|
|
if (!dright) |
| 1365 |
|
|
DIE(aTHX_ "Illegal modulus zero"); |
| 1366 |
|
|
|
| 1367 |
|
|
dans = Perl_fmod(dleft, dright); |
| 1368 |
|
|
if ((left_neg != right_neg) && dans) |
| 1369 |
|
|
dans = dright - dans; |
| 1370 |
|
|
if (right_neg) |
| 1371 |
|
|
dans = -dans; |
| 1372 |
|
|
sv_setnv(TARG, dans); |
| 1373 |
|
|
} |
| 1374 |
|
|
else { |
| 1375 |
|
|
UV ans; |
| 1376 |
|
|
|
| 1377 |
|
|
if (!right) |
| 1378 |
|
|
DIE(aTHX_ "Illegal modulus zero"); |
| 1379 |
|
|
|
| 1380 |
|
|
ans = left % right; |
| 1381 |
|
|
if ((left_neg != right_neg) && ans) |
| 1382 |
|
|
ans = right - ans; |
| 1383 |
|
|
if (right_neg) { |
| 1384 |
|
|
/* XXX may warn: unary minus operator applied to unsigned type */ |
| 1385 |
|
|
/* could change -foo to be (~foo)+1 instead */ |
| 1386 |
|
|
if (ans <= ~((UV)IV_MAX)+1) |
| 1387 |
|
|
sv_setiv(TARG, ~ans+1); |
| 1388 |
|
|
else |
| 1389 |
|
|
sv_setnv(TARG, -(NV)ans); |
| 1390 |
|
|
} |
| 1391 |
|
|
else |
| 1392 |
|
|
sv_setuv(TARG, ans); |
| 1393 |
|
|
} |
| 1394 |
|
|
PUSHTARG; |
| 1395 |
|
|
RETURN; |
| 1396 |
|
|
} |
| 1397 |
|
|
} |
| 1398 |
|
|
|
| 1399 |
|
|
PP(pp_repeat) |
| 1400 |
|
|
{ |
| 1401 |
|
|
dSP; dATARGET; tryAMAGICbin(repeat,opASSIGN); |
| 1402 |
|
|
{ |
| 1403 |
|
|
register IV count; |
| 1404 |
|
|
dPOPss; |
| 1405 |
|
|
if (SvGMAGICAL(sv)) |
| 1406 |
|
|
mg_get(sv); |
| 1407 |
|
|
if (SvIOKp(sv)) { |
| 1408 |
|
|
if (SvUOK(sv)) { |
| 1409 |
|
|
UV uv = SvUV(sv); |
| 1410 |
|
|
if (uv > IV_MAX) |
| 1411 |
|
|
count = IV_MAX; /* The best we can do? */ |
| 1412 |
|
|
else |
| 1413 |
|
|
count = uv; |
| 1414 |
|
|
} else { |
| 1415 |
|
|
IV iv = SvIV(sv); |
| 1416 |
|
|
if (iv < 0) |
| 1417 |
|
|
count = 0; |
| 1418 |
|
|
else |
| 1419 |
|
|
count = iv; |
| 1420 |
|
|
} |
| 1421 |
|
|
} |
| 1422 |
|
|
else if (SvNOKp(sv)) { |
| 1423 |
|
|
NV nv = SvNV(sv); |
| 1424 |
|
|
if (nv < 0.0) |
| 1425 |
|
|
count = 0; |
| 1426 |
|
|
else |
| 1427 |
|
|
count = (IV)nv; |
| 1428 |
|
|
} |
| 1429 |
|
|
else |
| 1430 |
|
|
count = SvIVx(sv); |
| 1431 |
|
|
if (GIMME == G_ARRAY && PL_op->op_private & OPpREPEAT_DOLIST) { |
| 1432 |
|
|
dMARK; |
| 1433 |
|
|
I32 items = SP - MARK; |
| 1434 |
|
|
I32 max; |
| 1435 |
|
|
static const char oom_list_extend[] = |
| 1436 |
|
|
"Out of memory during list extend"; |
| 1437 |
|
|
|
| 1438 |
|
|
max = items * count; |
| 1439 |
|
|
MEM_WRAP_CHECK_1(max, SV*, oom_list_extend); |
| 1440 |
|
|
/* Did the max computation overflow? */ |
| 1441 |
|
|
if (items > 0 && max > 0 && (max < items || max < count)) |
| 1442 |
|
|
Perl_croak(aTHX_ oom_list_extend); |
| 1443 |
|
|
MEXTEND(MARK, max); |
| 1444 |
|
|
if (count > 1) { |
| 1445 |
|
|
while (SP > MARK) { |
| 1446 |
|
|
#if 0 |
| 1447 |
|
|
/* This code was intended to fix 20010809.028: |
| 1448 |
|
|
|
| 1449 |
|
|
$x = 'abcd'; |
| 1450 |
|
|
for (($x =~ /./g) x 2) { |
| 1451 |
|
|
print chop; # "abcdabcd" expected as output. |
| 1452 |
|
|
} |
| 1453 |
|
|
|
| 1454 |
|
|
* but that change (#11635) broke this code: |
| 1455 |
|
|
|
| 1456 |
|
|
$x = [("foo")x2]; # only one "foo" ended up in the anonlist. |
| 1457 |
|
|
|
| 1458 |
|
|
* I can't think of a better fix that doesn't introduce |
| 1459 |
|
|
* an efficiency hit by copying the SVs. The stack isn't |
| 1460 |
|
|
* refcounted, and mortalisation obviously doesn't |
| 1461 |
|
|
* Do The Right Thing when the stack has more than |
| 1462 |
|
|
* one pointer to the same mortal value. |
| 1463 |
|
|
* .robin. |
| 1464 |
|
|
*/ |
| 1465 |
|
|
if (*SP) { |
| 1466 |
|
|
*SP = sv_2mortal(newSVsv(*SP)); |
| 1467 |
|
|
SvREADONLY_on(*SP); |
| 1468 |
|
|
} |
| 1469 |
|
|
#else |
| 1470 |
|
|
if (*SP) |
| 1471 |
|
|
SvTEMP_off((*SP)); |
| 1472 |
|
|
#endif |
| 1473 |
|
|
SP--; |
| 1474 |
|
|
} |
| 1475 |
|
|
MARK++; |
| 1476 |
|
|
repeatcpy((char*)(MARK + items), (char*)MARK, |
| 1477 |
|
|
items * sizeof(SV*), count - 1); |
| 1478 |
|
|
SP += max; |
| 1479 |
|
|
} |
| 1480 |
|
|
else if (count <= 0) |
| 1481 |
|
|
SP -= items; |
| 1482 |
|
|
} |
| 1483 |
|
|
else { /* Note: mark already snarfed by pp_list */ |
| 1484 |
|
|
SV *tmpstr = POPs; |
| 1485 |
|
|
STRLEN len; |
| 1486 |
|
|
bool isutf; |
| 1487 |
|
|
static const char oom_string_extend[] = |
| 1488 |
|
|
"Out of memory during string extend"; |
| 1489 |
|
|
|
| 1490 |
|
|
SvSetSV(TARG, tmpstr); |
| 1491 |
|
|
SvPV_force(TARG, len); |
| 1492 |
|
|
isutf = DO_UTF8(TARG); |
| 1493 |
|
|
if (count != 1) { |
| 1494 |
|
|
if (count < 1) |
| 1495 |
|
|
SvCUR_set(TARG, 0); |
| 1496 |
|
|
else { |
| 1497 |
|
|
STRLEN max = (UV)count * len; |
| 1498 |
|
|
if (len > ((MEM_SIZE)~0)/count) |
| 1499 |
|
|
Perl_croak(aTHX_ oom_string_extend); |
| 1500 |
|
|
MEM_WRAP_CHECK_1(max, char, oom_string_extend); |
| 1501 |
|
|
SvGROW(TARG, max + 1); |
| 1502 |
|
|
repeatcpy(SvPVX(TARG) + len, SvPVX(TARG), len, count - 1); |
| 1503 |
|
|
SvCUR(TARG) *= count; |
| 1504 |
|
|
} |
| 1505 |
|
|
*SvEND(TARG) = '\0'; |
| 1506 |
|
|
} |
| 1507 |
|
|
if (isutf) |
| 1508 |
|
|
(void)SvPOK_only_UTF8(TARG); |
| 1509 |
|
|
else |
| 1510 |
|
|
(void)SvPOK_only(TARG); |
| 1511 |
|
|
|
| 1512 |
|
|
if (PL_op->op_private & OPpREPEAT_DOLIST) { |
| 1513 |
|
|
/* The parser saw this as a list repeat, and there |
| 1514 |
|
|
are probably several items on the stack. But we're |
| 1515 |
|
|
in scalar context, and there's no pp_list to save us |
| 1516 |
|
|
now. So drop the rest of the items -- robin@kitsite.com |
| 1517 |
|
|
*/ |
| 1518 |
|
|
dMARK; |
| 1519 |
|
|
SP = MARK; |
| 1520 |
|
|
} |
| 1521 |
|
|
PUSHTARG; |
| 1522 |
|
|
} |
| 1523 |
|
|
RETURN; |
| 1524 |
|
|
} |
| 1525 |
|
|
} |
| 1526 |
|
|
|
| 1527 |
|
|
PP(pp_subtract) |
| 1528 |
|
|
{ |
| 1529 |
|
|
dSP; dATARGET; bool useleft; tryAMAGICbin(subtr,opASSIGN); |
| 1530 |
|
|
useleft = USE_LEFT(TOPm1s); |
| 1531 |
|
|
#ifdef PERL_PRESERVE_IVUV |
| 1532 |
|
|
/* See comments in pp_add (in pp_hot.c) about Overflow, and how |
| 1533 |
|
|
"bad things" happen if you rely on signed integers wrapping. */ |
| 1534 |
|
|
SvIV_please(TOPs); |
| 1535 |
|
|
if (SvIOK(TOPs)) { |
| 1536 |
|
|
/* Unless the left argument is integer in range we are going to have to |
| 1537 |
|
|
use NV maths. Hence only attempt to coerce the right argument if |
| 1538 |
|
|
we know the left is integer. */ |
| 1539 |
|
|
register UV auv = 0; |
| 1540 |
|
|
bool auvok = FALSE; |
| 1541 |
|
|
bool a_valid = 0; |
| 1542 |
|
|
|
| 1543 |
|
|
if (!useleft) { |
| 1544 |
|
|
auv = 0; |
| 1545 |
|
|
a_valid = auvok = 1; |
| 1546 |
|
|
/* left operand is undef, treat as zero. */ |
| 1547 |
|
|
} else { |
| 1548 |
|
|
/* Left operand is defined, so is it IV? */ |
| 1549 |
|
|
SvIV_please(TOPm1s); |
| 1550 |
|
|
if (SvIOK(TOPm1s)) { |
| 1551 |
|
|
if ((auvok = SvUOK(TOPm1s))) |
| 1552 |
|
|
auv = SvUVX(TOPm1s); |
| 1553 |
|
|
else { |
| 1554 |
|
|
register IV aiv = SvIVX(TOPm1s); |
| 1555 |
|
|
if (aiv >= 0) { |
| 1556 |
|
|
auv = aiv; |
| 1557 |
|
|
auvok = 1; /* Now acting as a sign flag. */ |
| 1558 |
|
|
} else { /* 2s complement assumption for IV_MIN */ |
| 1559 |
|
|
auv = (UV)-aiv; |
| 1560 |
|
|
} |
| 1561 |
|
|
} |
| 1562 |
|
|
a_valid = 1; |
| 1563 |
|
|
} |
| 1564 |
|
|
} |
| 1565 |
|
|
if (a_valid) { |
| 1566 |
|
|
bool result_good = 0; |
| 1567 |
|
|
UV result; |
| 1568 |
|
|
register UV buv; |
| 1569 |
|
|
bool buvok = SvUOK(TOPs); |
| 1570 |
|
|
|
| 1571 |
|
|
if (buvok) |
| 1572 |
|
|
buv = SvUVX(TOPs); |
| 1573 |
|
|
else { |
| 1574 |
|
|
register IV biv = SvIVX(TOPs); |
| 1575 |
|
|
if (biv >= 0) { |
| 1576 |
|
|
buv = biv; |
| 1577 |
|
|
buvok = 1; |
| 1578 |
|
|
} else |
| 1579 |
|
|
buv = (UV)-biv; |
| 1580 |
|
|
} |
| 1581 |
|
|
/* ?uvok if value is >= 0. basically, flagged as UV if it's +ve, |
| 1582 |
|
|
else "IV" now, independent of how it came in. |
| 1583 |
|
|
if a, b represents positive, A, B negative, a maps to -A etc |
| 1584 |
|
|
a - b => (a - b) |
| 1585 |
|
|
A - b => -(a + b) |
| 1586 |
|
|
a - B => (a + b) |
| 1587 |
|
|
A - B => -(a - b) |
| 1588 |
|
|
all UV maths. negate result if A negative. |
| 1589 |
|
|
subtract if signs same, add if signs differ. */ |
| 1590 |
|
|
|
| 1591 |
|
|
if (auvok ^ buvok) { |
| 1592 |
|
|
/* Signs differ. */ |
| 1593 |
|
|
result = auv + buv; |
| 1594 |
|
|
if (result >= auv) |
| 1595 |
|
|
result_good = 1; |
| 1596 |
|
|
} else { |
| 1597 |
|
|
/* Signs same */ |
| 1598 |
|
|
if (auv >= buv) { |
| 1599 |
|
|
result = auv - buv; |
| 1600 |
|
|
/* Must get smaller */ |
| 1601 |
|
|
if (result <= auv) |
| 1602 |
|
|
result_good = 1; |
| 1603 |
|
|
} else { |
| 1604 |
|
|
result = buv - auv; |
| 1605 |
|
|
if (result <= buv) { |
| 1606 |
|
|
/* result really should be -(auv-buv). as its negation |
| 1607 |
|
|
of true value, need to swap our result flag */ |
| 1608 |
|
|
auvok = !auvok; |
| 1609 |
|
|
result_good = 1; |
| 1610 |
|
|
} |
| 1611 |
|
|
} |
| 1612 |
|
|
} |
| 1613 |
|
|
if (result_good) { |
| 1614 |
|
|
SP--; |
| 1615 |
|
|
if (auvok) |
| 1616 |
|
|
SETu( result ); |
| 1617 |
|
|
else { |
| 1618 |
|
|
/* Negate result */ |
| 1619 |
|
|
if (result <= (UV)IV_MIN) |
| 1620 |
|
|
SETi( -(IV)result ); |
| 1621 |
|
|
else { |
| 1622 |
|
|
/* result valid, but out of range for IV. */ |
| 1623 |
|
|
SETn( -(NV)result ); |
| 1624 |
|
|
} |
| 1625 |
|
|
} |
| 1626 |
|
|
RETURN; |
| 1627 |
|
|
} /* Overflow, drop through to NVs. */ |
| 1628 |
|
|
} |
| 1629 |
|
|
} |
| 1630 |
|
|
#endif |
| 1631 |
|
|
useleft = USE_LEFT(TOPm1s); |
| 1632 |
|
|
{ |
| 1633 |
|
|
dPOPnv; |
| 1634 |
|
|
if (!useleft) { |
| 1635 |
|
|
/* left operand is undef, treat as zero - value */ |
| 1636 |
|
|
SETn(-value); |
| 1637 |
|
|
RETURN; |
| 1638 |
|
|
} |
| 1639 |
|
|
SETn( TOPn - value ); |
| 1640 |
|
|
RETURN; |
| 1641 |
|
|
} |
| 1642 |
|
|
} |
| 1643 |
|
|
|
| 1644 |
|
|
PP(pp_left_shift) |
| 1645 |
|
|
{ |
| 1646 |
|
|
dSP; dATARGET; tryAMAGICbin(lshift,opASSIGN); |
| 1647 |
|
|
{ |
| 1648 |
|
|
IV shift = POPi; |
| 1649 |
|
|
if (PL_op->op_private & HINT_INTEGER) { |
| 1650 |
|
|
IV i = TOPi; |
| 1651 |
|
|
SETi(i << shift); |
| 1652 |
|
|
} |
| 1653 |
|
|
else { |
| 1654 |
|
|
UV u = TOPu; |
| 1655 |
|
|
SETu(u << shift); |
| 1656 |
|
|
} |
| 1657 |
|
|
RETURN; |
| 1658 |
|
|
} |
| 1659 |
|
|
} |
| 1660 |
|
|
|
| 1661 |
|
|
PP(pp_right_shift) |
| 1662 |
|
|
{ |
| 1663 |
|
|
dSP; dATARGET; tryAMAGICbin(rshift,opASSIGN); |
| 1664 |
|
|
{ |
| 1665 |
|
|
IV shift = POPi; |
| 1666 |
|
|
if (PL_op->op_private & HINT_INTEGER) { |
| 1667 |
|
|
IV i = TOPi; |
| 1668 |
|
|
SETi(i >> shift); |
| 1669 |
|
|
} |
| 1670 |
|
|
else { |
| 1671 |
|
|
UV u = TOPu; |
| 1672 |
|
|
SETu(u >> shift); |
| 1673 |
|
|
} |
| 1674 |
|
|
RETURN; |
| 1675 |
|
|
} |
| 1676 |
|
|
} |
| 1677 |
|
|
|
| 1678 |
|
|
PP(pp_lt) |
| 1679 |
|
|
{ |
| 1680 |
|
|
dSP; tryAMAGICbinSET(lt,0); |
| 1681 |
|
|
#ifdef PERL_PRESERVE_IVUV |
| 1682 |
|
|
SvIV_please(TOPs); |
| 1683 |
|
|
if (SvIOK(TOPs)) { |
| 1684 |
|
|
SvIV_please(TOPm1s); |
| 1685 |
|
|
if (SvIOK(TOPm1s)) { |
| 1686 |
|
|
bool auvok = SvUOK(TOPm1s); |
| 1687 |
|
|
bool buvok = SvUOK(TOPs); |
| 1688 |
|
|
|
| 1689 |
|
|
if (!auvok && !buvok) { /* ## IV < IV ## */ |
| 1690 |
|
|
IV aiv = SvIVX(TOPm1s); |
| 1691 |
|
|
IV biv = SvIVX(TOPs); |
| 1692 |
|
|
|
| 1693 |
|
|
SP--; |
| 1694 |
|
|
SETs(boolSV(aiv < biv)); |
| 1695 |
|
|
RETURN; |
| 1696 |
|
|
} |
| 1697 |
|
|
if (auvok && buvok) { /* ## UV < UV ## */ |
| 1698 |
|
|
UV auv = SvUVX(TOPm1s); |
| 1699 |
|
|
UV buv = SvUVX(TOPs); |
| 1700 |
|
|
|
| 1701 |
|
|
SP--; |
| 1702 |
|
|
SETs(boolSV(auv < buv)); |
| 1703 |
|
|
RETURN; |
| 1704 |
|
|
} |
| 1705 |
|
|
if (auvok) { /* ## UV < IV ## */ |
| 1706 |
|
|
UV auv; |
| 1707 |
|
|
IV biv; |
| 1708 |
|
|
|
| 1709 |
|
|
biv = SvIVX(TOPs); |
| 1710 |
|
|
SP--; |
| 1711 |
|
|
if (biv < 0) { |
| 1712 |
|
|
/* As (a) is a UV, it's >=0, so it cannot be < */ |
| 1713 |
|
|
SETs(&PL_sv_no); |
| 1714 |
|
|
RETURN; |
| 1715 |
|
|
} |
| 1716 |
|
|
auv = SvUVX(TOPs); |
| 1717 |
|
|
SETs(boolSV(auv < (UV)biv)); |
| 1718 |
|
|
RETURN; |
| 1719 |
|
|
} |
| 1720 |
|
|
{ /* ## IV < UV ## */ |
| 1721 |
|
|
IV aiv; |
| 1722 |
|
|
UV buv; |
| 1723 |
|
|
|
| 1724 |
|
|
aiv = SvIVX(TOPm1s); |
| 1725 |
|
|
if (aiv < 0) { |
| 1726 |
|
|
/* As (b) is a UV, it's >=0, so it must be < */ |
| 1727 |
|
|
SP--; |
| 1728 |
|
|
SETs(&PL_sv_yes); |
| 1729 |
|
|
RETURN; |
| 1730 |
|
|
} |
| 1731 |
|
|
buv = SvUVX(TOPs); |
| 1732 |
|
|
SP--; |
| 1733 |
|
|
SETs(boolSV((UV)aiv < buv)); |
| 1734 |
|
|
RETURN; |
| 1735 |
|
|
} |
| 1736 |
|
|
} |
| 1737 |
|
|
} |
| 1738 |
|
|
#endif |
| 1739 |
|
|
#ifndef NV_PRESERVES_UV |
| 1740 |
|
|
#ifdef PERL_PRESERVE_IVUV |
| 1741 |
|
|
else |
| 1742 |
|
|
#endif |
| 1743 |
|
|
if (SvROK(TOPs) && !SvAMAGIC(TOPs) && SvROK(TOPm1s) && !SvAMAGIC(TOPm1s)) { |
| 1744 |
|
|
SP--; |
| 1745 |
|
|
SETs(boolSV(SvRV(TOPs) < SvRV(TOPp1s))); |
| 1746 |
|
|
RETURN; |
| 1747 |
|
|
} |
| 1748 |
|
|
#endif |
| 1749 |
|
|
{ |
| 1750 |
|
|
dPOPnv; |
| 1751 |
|
|
SETs(boolSV(TOPn < value)); |
| 1752 |
|
|
RETURN; |
| 1753 |
|
|
} |
| 1754 |
|
|
} |
| 1755 |
|
|
|
| 1756 |
|
|
PP(pp_gt) |
| 1757 |
|
|
{ |
| 1758 |
|
|
dSP; tryAMAGICbinSET(gt,0); |
| 1759 |
|
|
#ifdef PERL_PRESERVE_IVUV |
| 1760 |
|
|
SvIV_please(TOPs); |
| 1761 |
|
|
if (SvIOK(TOPs)) { |
| 1762 |
|
|
SvIV_please(TOPm1s); |
| 1763 |
|
|
if (SvIOK(TOPm1s)) { |
| 1764 |
|
|
bool auvok = SvUOK(TOPm1s); |
| 1765 |
|
|
bool buvok = SvUOK(TOPs); |
| 1766 |
|
|
|
| 1767 |
|
|
if (!auvok && !buvok) { /* ## IV > IV ## */ |
| 1768 |
|
|
IV aiv = SvIVX(TOPm1s); |
| 1769 |
|
|
IV biv = SvIVX(TOPs); |
| 1770 |
|
|
|
| 1771 |
|
|
SP--; |
| 1772 |
|
|
SETs(boolSV(aiv > biv)); |
| 1773 |
|
|
RETURN; |
| 1774 |
|
|
} |
| 1775 |
|
|
if (auvok && buvok) { /* ## UV > UV ## */ |
| 1776 |
|
|
UV auv = SvUVX(TOPm1s); |
| 1777 |
|
|
UV buv = SvUVX(TOPs); |
| 1778 |
|
|
|
| 1779 |
|
|
SP--; |
| 1780 |
|
|
SETs(boolSV(auv > buv)); |
| 1781 |
|
|
RETURN; |
| 1782 |
|
|
} |
| 1783 |
|
|
if (auvok) { /* ## UV > IV ## */ |
| 1784 |
|
|
UV auv; |
| 1785 |
|
|
IV biv; |
| 1786 |
|
|
|
| 1787 |
|
|
biv = SvIVX(TOPs); |
| 1788 |
|
|
SP--; |
| 1789 |
|
|
if (biv < 0) { |
| 1790 |
|
|
/* As (a) is a UV, it's >=0, so it must be > */ |
| 1791 |
|
|
SETs(&PL_sv_yes); |
| 1792 |
|
|
RETURN; |
| 1793 |
|
|
} |
| 1794 |
|
|
auv = SvUVX(TOPs); |
| 1795 |
|
|
SETs(boolSV(auv > (UV)biv)); |
| 1796 |
|
|
RETURN; |
| 1797 |
|
|
} |
| 1798 |
|
|
{ /* ## IV > UV ## */ |
| 1799 |
|
|
IV aiv; |
| 1800 |
|
|
UV buv; |
| 1801 |
|
|
|
| 1802 |
|
|
aiv = SvIVX(TOPm1s); |
| 1803 |
|
|
if (aiv < 0) { |
| 1804 |
|
|
/* As (b) is a UV, it's >=0, so it cannot be > */ |
| 1805 |
|
|
SP--; |
| 1806 |
|
|
SETs(&PL_sv_no); |
| 1807 |
|
|
RETURN; |
| 1808 |
|
|
} |
| 1809 |
|
|
buv = SvUVX(TOPs); |
| 1810 |
|
|
SP--; |
| 1811 |
|
|
SETs(boolSV((UV)aiv > buv)); |
| 1812 |
|
|
RETURN; |
| 1813 |
|
|
} |
| 1814 |
|
|
} |
| 1815 |
|
|
} |
| 1816 |
|
|
#endif |
| 1817 |
|
|
#ifndef NV_PRESERVES_UV |
| 1818 |
|
|
#ifdef PERL_PRESERVE_IVUV |
| 1819 |
|
|
else |
| 1820 |
|
|
#endif |
| 1821 |
|
|
if (SvROK(TOPs) && !SvAMAGIC(TOPs) && SvROK(TOPm1s) && !SvAMAGIC(TOPm1s)) { |
| 1822 |
|
|
SP--; |
| 1823 |
|
|
SETs(boolSV(SvRV(TOPs) > SvRV(TOPp1s))); |
| 1824 |
|
|
RETURN; |
| 1825 |
|
|
} |
| 1826 |
|
|
#endif |
| 1827 |
|
|
{ |
| 1828 |
|
|
dPOPnv; |
| 1829 |
|
|
SETs(boolSV(TOPn > value)); |
| 1830 |
|
|
RETURN; |
| 1831 |
|
|
} |
| 1832 |
|
|
} |
| 1833 |
|
|
|
| 1834 |
|
|
PP(pp_le) |
| 1835 |
|
|
{ |
| 1836 |
|
|
dSP; tryAMAGICbinSET(le,0); |
| 1837 |
|
|
#ifdef PERL_PRESERVE_IVUV |
| 1838 |
|
|
SvIV_please(TOPs); |
| 1839 |
|
|
if (SvIOK(TOPs)) { |
| 1840 |
|
|
SvIV_please(TOPm1s); |
| 1841 |
|
|
if (SvIOK(TOPm1s)) { |
| 1842 |
|
|
bool auvok = SvUOK(TOPm1s); |
| 1843 |
|
|
bool buvok = SvUOK(TOPs); |
| 1844 |
|
|
|
| 1845 |
|
|
if (!auvok && !buvok) { /* ## IV <= IV ## */ |
| 1846 |
|
|
IV aiv = SvIVX(TOPm1s); |
| 1847 |
|
|
IV biv = SvIVX(TOPs); |
| 1848 |
|
|
|
| 1849 |
|
|
SP--; |
| 1850 |
|
|
SETs(boolSV(aiv <= biv)); |
| 1851 |
|
|
RETURN; |
| 1852 |
|
|
} |
| 1853 |
|
|
if (auvok && buvok) { /* ## UV <= UV ## */ |
| 1854 |
|
|
UV auv = SvUVX(TOPm1s); |
| 1855 |
|
|
UV buv = SvUVX(TOPs); |
| 1856 |
|
|
|
| 1857 |
|
|
SP--; |
| 1858 |
|
|
SETs(boolSV(auv <= buv)); |
| 1859 |
|
|
RETURN; |
| 1860 |
|
|
} |
| 1861 |
|
|
if (auvok) { /* ## UV <= IV ## */ |
| 1862 |
|
|
UV auv; |
| 1863 |
|
|
IV biv; |
| 1864 |
|
|
|
| 1865 |
|
|
biv = SvIVX(TOPs); |
| 1866 |
|
|
SP--; |
| 1867 |
|
|
if (biv < 0) { |
| 1868 |
|
|
/* As (a) is a UV, it's >=0, so a cannot be <= */ |
| 1869 |
|
|
SETs(&PL_sv_no); |
| 1870 |
|
|
RETURN; |
| 1871 |
|
|
} |
| 1872 |
|
|
auv = SvUVX(TOPs); |
| 1873 |
|
|
SETs(boolSV(auv <= (UV)biv)); |
| 1874 |
|
|
RETURN; |
| 1875 |
|
|
} |
| 1876 |
|
|
{ /* ## IV <= UV ## */ |
| 1877 |
|
|
IV aiv; |
| 1878 |
|
|
UV buv; |
| 1879 |
|
|
|
| 1880 |
|
|
aiv = SvIVX(TOPm1s); |
| 1881 |
|
|
if (aiv < 0) { |
| 1882 |
|
|
/* As (b) is a UV, it's >=0, so a must be <= */ |
| 1883 |
|
|
SP--; |
| 1884 |
|
|
SETs(&PL_sv_yes); |
| 1885 |
|
|
RETURN; |
| 1886 |
|
|
} |
| 1887 |
|
|
buv = SvUVX(TOPs); |
| 1888 |
|
|
SP--; |
| 1889 |
|
|
SETs(boolSV((UV)aiv <= buv)); |
| 1890 |
|
|
RETURN; |
| 1891 |
|
|
} |
| 1892 |
|
|
} |
| 1893 |
|
|
} |
| 1894 |
|
|
#endif |
| 1895 |
|
|
#ifndef NV_PRESERVES_UV |
| 1896 |
|
|
#ifdef PERL_PRESERVE_IVUV |
| 1897 |
|
|
else |
| 1898 |
|
|
#endif |
| 1899 |
|
|
if (SvROK(TOPs) && !SvAMAGIC(TOPs) && SvROK(TOPm1s) && !SvAMAGIC(TOPm1s)) { |
| 1900 |
|
|
SP--; |
| 1901 |
|
|
SETs(boolSV(SvRV(TOPs) <= SvRV(TOPp1s))); |
| 1902 |
|
|
RETURN; |
| 1903 |
|
|
} |
| 1904 |
|
|
#endif |
| 1905 |
|
|
{ |
| 1906 |
|
|
dPOPnv; |
| 1907 |
|
|
SETs(boolSV(TOPn <= value)); |
| 1908 |
|
|
RETURN; |
| 1909 |
|
|
} |
| 1910 |
|
|
} |
| 1911 |
|
|
|
| 1912 |
|
|
PP(pp_ge) |
| 1913 |
|
|
{ |
| 1914 |
|
|
dSP; tryAMAGICbinSET(ge,0); |
| 1915 |
|
|
#ifdef PERL_PRESERVE_IVUV |
| 1916 |
|
|
SvIV_please(TOPs); |
| 1917 |
|
|
if (SvIOK(TOPs)) { |
| 1918 |
|
|
SvIV_please(TOPm1s); |
| 1919 |
|
|
if (SvIOK(TOPm1s)) { |
| 1920 |
|
|
bool auvok = SvUOK(TOPm1s); |
| 1921 |
|
|
bool buvok = SvUOK(TOPs); |
| 1922 |
|
|
|
| 1923 |
|
|
if (!auvok && !buvok) { /* ## IV >= IV ## */ |
| 1924 |
|
|
IV aiv = SvIVX(TOPm1s); |
| 1925 |
|
|
IV biv = SvIVX(TOPs); |
| 1926 |
|
|
|
| 1927 |
|
|
SP--; |
| 1928 |
|
|
SETs(boolSV(aiv >= biv)); |
| 1929 |
|
|
RETURN; |
| 1930 |
|
|
} |
| 1931 |
|
|
if (auvok && buvok) { /* ## UV >= UV ## */ |
| 1932 |
|
|
UV auv = SvUVX(TOPm1s); |
| 1933 |
|
|
UV buv = SvUVX(TOPs); |
| 1934 |
|
|
|
| 1935 |
|
|
SP--; |
| 1936 |
|
|
SETs(boolSV(auv >= buv)); |
| 1937 |
|
|
RETURN; |
| 1938 |
|
|
} |
| 1939 |
|
|
if (auvok) { /* ## UV >= IV ## */ |
| 1940 |
|
|
UV auv; |
| 1941 |
|
|
IV biv; |
| 1942 |
|
|
|
| 1943 |
|
|
biv = SvIVX(TOPs); |
| 1944 |
|
|
SP--; |
| 1945 |
|
|
if (biv < 0) { |
| 1946 |
|
|
/* As (a) is a UV, it's >=0, so it must be >= */ |
| 1947 |
|
|
SETs(&PL_sv_yes); |
| 1948 |
|
|
RETURN; |
| 1949 |
|
|
} |
| 1950 |
|
|
auv = SvUVX(TOPs); |
| 1951 |
|
|
SETs(boolSV(auv >= (UV)biv)); |
| 1952 |
|
|
RETURN; |
| 1953 |
|
|
} |
| 1954 |
|
|
{ /* ## IV >= UV ## */ |
| 1955 |
|
|
IV aiv; |
| 1956 |
|
|
UV buv; |
| 1957 |
|
|
|
| 1958 |
|
|
aiv = SvIVX(TOPm1s); |
| 1959 |
|
|
if (aiv < 0) { |
| 1960 |
|
|
/* As (b) is a UV, it's >=0, so a cannot be >= */ |
| 1961 |
|
|
SP--; |
| 1962 |
|
|
SETs(&PL_sv_no); |
| 1963 |
|
|
RETURN; |
| 1964 |
|
|
} |
| 1965 |
|
|
buv = SvUVX(TOPs); |
| 1966 |
|
|
SP--; |
| 1967 |
|
|
SETs(boolSV((UV)aiv >= buv)); |
| 1968 |
|
|
RETURN; |
| 1969 |
|
|
} |
| 1970 |
|
|
} |
| 1971 |
|
|
} |
| 1972 |
|
|
#endif |
| 1973 |
|
|
#ifndef NV_PRESERVES_UV |
| 1974 |
|
|
#ifdef PERL_PRESERVE_IVUV |
| 1975 |
|
|
else |
| 1976 |
|
|
#endif |
| 1977 |
|
|
if (SvROK(TOPs) && !SvAMAGIC(TOPs) && SvROK(TOPm1s) && !SvAMAGIC(TOPm1s)) { |
| 1978 |
|
|
SP--; |
| 1979 |
|
|
SETs(boolSV(SvRV(TOPs) >= SvRV(TOPp1s))); |
| 1980 |
|
|
RETURN; |
| 1981 |
|
|
} |
| 1982 |
|
|
#endif |
| 1983 |
|
|
{ |
| 1984 |
|
|
dPOPnv; |
| 1985 |
|
|
SETs(boolSV(TOPn >= value)); |
| 1986 |
|
|
RETURN; |
| 1987 |
|
|
} |
| 1988 |
|
|
} |
| 1989 |
|
|
|
| 1990 |
|
|
PP(pp_ne) |
| 1991 |
|
|
{ |
| 1992 |
|
|
dSP; tryAMAGICbinSET(ne,0); |
| 1993 |
|
|
#ifndef NV_PRESERVES_UV |
| 1994 |
|
|
if (SvROK(TOPs) && !SvAMAGIC(TOPs) && SvROK(TOPm1s) && !SvAMAGIC(TOPm1s)) { |
| 1995 |
|
|
SP--; |
| 1996 |
|
|
SETs(boolSV(SvRV(TOPs) != SvRV(TOPp1s))); |
| 1997 |
|
|
RETURN; |
| 1998 |
|
|
} |
| 1999 |
|
|
#endif |
| 2000 |
|
|
#ifdef PERL_PRESERVE_IVUV |
| 2001 |
|
|
SvIV_please(TOPs); |
| 2002 |
|
|
if (SvIOK(TOPs)) { |
| 2003 |
|
|
SvIV_please(TOPm1s); |
| 2004 |
|
|
if (SvIOK(TOPm1s)) { |
| 2005 |
|
|
bool auvok = SvUOK(TOPm1s); |
| 2006 |
|
|
bool buvok = SvUOK(TOPs); |
| 2007 |
|
|
|
| 2008 |
|
|
if (auvok == buvok) { /* ## IV == IV or UV == UV ## */ |
| 2009 |
|
|
/* Casting IV to UV before comparison isn't going to matter |
| 2010 |
|
|
on 2s complement. On 1s complement or sign&magnitude |
| 2011 |
|
|
(if we have any of them) it could make negative zero |
| 2012 |
|
|
differ from normal zero. As I understand it. (Need to |
| 2013 |
|
|
check - is negative zero implementation defined behaviour |
| 2014 |
|
|
anyway?). NWC */ |
| 2015 |
|
|
UV buv = SvUVX(POPs); |
| 2016 |
|
|
UV auv = SvUVX(TOPs); |
| 2017 |
|
|
|
| 2018 |
|
|
SETs(boolSV(auv != buv)); |
| 2019 |
|
|
RETURN; |
| 2020 |
|
|
} |
| 2021 |
|
|
{ /* ## Mixed IV,UV ## */ |
| 2022 |
|
|
IV iv; |
| 2023 |
|
|
UV uv; |
| 2024 |
|
|
|
| 2025 |
|
|
/* != is commutative so swap if needed (save code) */ |
| 2026 |
|
|
if (auvok) { |
| 2027 |
|
|
/* swap. top of stack (b) is the iv */ |
| 2028 |
|
|
iv = SvIVX(TOPs); |
| 2029 |
|
|
SP--; |
| 2030 |
|
|
if (iv < 0) { |
| 2031 |
|
|
/* As (a) is a UV, it's >0, so it cannot be == */ |
| 2032 |
|
|
SETs(&PL_sv_yes); |
| 2033 |
|
|
RETURN; |
| 2034 |
|
|
} |
| 2035 |
|
|
uv = SvUVX(TOPs); |
| 2036 |
|
|
} else { |
| 2037 |
|
|
iv = SvIVX(TOPm1s); |
| 2038 |
|
|
SP--; |
| 2039 |
|
|
if (iv < 0) { |
| 2040 |
|
|
/* As (b) is a UV, it's >0, so it cannot be == */ |
| 2041 |
|
|
SETs(&PL_sv_yes); |
| 2042 |
|
|
RETURN; |
| 2043 |
|
|
} |
| 2044 |
|
|
uv = SvUVX(*(SP+1)); /* Do I want TOPp1s() ? */ |
| 2045 |
|
|
} |
| 2046 |
|
|
SETs(boolSV((UV)iv != uv)); |
| 2047 |
|
|
RETURN; |
| 2048 |
|
|
} |
| 2049 |
|
|
} |
| 2050 |
|
|
} |
| 2051 |
|
|
#endif |
| 2052 |
|
|
{ |
| 2053 |
|
|
dPOPnv; |
| 2054 |
|
|
SETs(boolSV(TOPn != value)); |
| 2055 |
|
|
RETURN; |
| 2056 |
|
|
} |
| 2057 |
|
|
} |
| 2058 |
|
|
|
| 2059 |
|
|
PP(pp_ncmp) |
| 2060 |
|
|
{ |
| 2061 |
|
|
dSP; dTARGET; tryAMAGICbin(ncmp,0); |
| 2062 |
|
|
#ifndef NV_PRESERVES_UV |
| 2063 |
|
|
if (SvROK(TOPs) && !SvAMAGIC(TOPs) && SvROK(TOPm1s) && !SvAMAGIC(TOPm1s)) { |
| 2064 |
|
|
UV right = PTR2UV(SvRV(POPs)); |
| 2065 |
|
|
UV left = PTR2UV(SvRV(TOPs)); |
| 2066 |
|
|
SETi((left > right) - (left < right)); |
| 2067 |
|
|
RETURN; |
| 2068 |
|
|
} |
| 2069 |
|
|
#endif |
| 2070 |
|
|
#ifdef PERL_PRESERVE_IVUV |
| 2071 |
|
|
/* Fortunately it seems NaN isn't IOK */ |
| 2072 |
|
|
SvIV_please(TOPs); |
| 2073 |
|
|
if (SvIOK(TOPs)) { |
| 2074 |
|
|
SvIV_please(TOPm1s); |
| 2075 |
|
|
if (SvIOK(TOPm1s)) { |
| 2076 |
|
|
bool leftuvok = SvUOK(TOPm1s); |
| 2077 |
|
|
bool rightuvok = SvUOK(TOPs); |
| 2078 |
|
|
I32 value; |
| 2079 |
|
|
if (!leftuvok && !rightuvok) { /* ## IV <=> IV ## */ |
| 2080 |
|
|
IV leftiv = SvIVX(TOPm1s); |
| 2081 |
|
|
IV rightiv = SvIVX(TOPs); |
| 2082 |
|
|
|
| 2083 |
|
|
if (leftiv > rightiv) |
| 2084 |
|
|
value = 1; |
| 2085 |
|
|
else if (leftiv < rightiv) |
| 2086 |
|
|
value = -1; |
| 2087 |
|
|
else |
| 2088 |
|
|
value = 0; |
| 2089 |
|
|
} else if (leftuvok && rightuvok) { /* ## UV <=> UV ## */ |
| 2090 |
|
|
UV leftuv = SvUVX(TOPm1s); |
| 2091 |
|
|
UV rightuv = SvUVX(TOPs); |
| 2092 |
|
|
|
| 2093 |
|
|
if (leftuv > rightuv) |
| 2094 |
|
|
value = 1; |
| 2095 |
|
|
else if (leftuv < rightuv) |
| 2096 |
|
|
value = -1; |
| 2097 |
|
|
else |
| 2098 |
|
|
value = 0; |
| 2099 |
|
|
} else if (leftuvok) { /* ## UV <=> IV ## */ |
| 2100 |
|
|
UV leftuv; |
| 2101 |
|
|
IV rightiv; |
| 2102 |
|
|
|
| 2103 |
|
|
rightiv = SvIVX(TOPs); |
| 2104 |
|
|
if (rightiv < 0) { |
| 2105 |
|
|
/* As (a) is a UV, it's >=0, so it cannot be < */ |
| 2106 |
|
|
value = 1; |
| 2107 |
|
|
} else { |
| 2108 |
|
|
leftuv = SvUVX(TOPm1s); |
| 2109 |
|
|
if (leftuv > (UV)rightiv) { |
| 2110 |
|
|
value = 1; |
| 2111 |
|
|
} else if (leftuv < (UV)rightiv) { |
| 2112 |
|
|
value = -1; |
| 2113 |
|
|
} else { |
| 2114 |
|
|
value = 0; |
| 2115 |
|
|
} |
| 2116 |
|
|
} |
| 2117 |
|
|
} else { /* ## IV <=> UV ## */ |
| 2118 |
|
|
IV leftiv; |
| 2119 |
|
|
UV rightuv; |
| 2120 |
|
|
|
| 2121 |
|
|
leftiv = SvIVX(TOPm1s); |
| 2122 |
|
|
if (leftiv < 0) { |
| 2123 |
|
|
/* As (b) is a UV, it's >=0, so it must be < */ |
| 2124 |
|
|
value = -1; |
| 2125 |
|
|
} else { |
| 2126 |
|
|
rightuv = SvUVX(TOPs); |
| 2127 |
|
|
if ((UV)leftiv > rightuv) { |
| 2128 |
|
|
value = 1; |
| 2129 |
|
|
} else if ((UV)leftiv < rightuv) { |
| 2130 |
|
|
value = -1; |
| 2131 |
|
|
} else { |
| 2132 |
|
|
value = 0; |
| 2133 |
|
|
} |
| 2134 |
|
|
} |
| 2135 |
|
|
} |
| 2136 |
|
|
SP--; |
| 2137 |
|
|
SETi(value); |
| 2138 |
|
|
RETURN; |
| 2139 |
|
|
} |
| 2140 |
|
|
} |
| 2141 |
|
|
#endif |
| 2142 |
|
|
{ |
| 2143 |
|
|
dPOPTOPnnrl; |
| 2144 |
|
|
I32 value; |
| 2145 |
|
|
|
| 2146 |
|
|
#ifdef Perl_isnan |
| 2147 |
|
|
if (Perl_isnan(left) || Perl_isnan(right)) { |
| 2148 |
|
|
SETs(&PL_sv_undef); |
| 2149 |
|
|
RETURN; |
| 2150 |
|
|
} |
| 2151 |
|
|
value = (left > right) - (left < right); |
| 2152 |
|
|
#else |
| 2153 |
|
|
if (left == right) |
| 2154 |
|
|
value = 0; |
| 2155 |
|
|
else if (left < right) |
| 2156 |
|
|
value = -1; |
| 2157 |
|
|
else if (left > right) |
| 2158 |
|
|
value = 1; |
| 2159 |
|
|
else { |
| 2160 |
|
|
SETs(&PL_sv_undef); |
| 2161 |
|
|
RETURN; |
| 2162 |
|
|
} |
| 2163 |
|
|
#endif |
| 2164 |
|
|
SETi(value); |
| 2165 |
|
|
RETURN; |
| 2166 |
|
|
} |
| 2167 |
|
|
} |
| 2168 |
|
|
|
| 2169 |
|
|
PP(pp_slt) |
| 2170 |
|
|
{ |
| 2171 |
|
|
dSP; tryAMAGICbinSET(slt,0); |
| 2172 |
|
|
{ |
| 2173 |
|
|
dPOPTOPssrl; |
| 2174 |
|
|
int cmp = (IN_LOCALE_RUNTIME |
| 2175 |
|
|
? sv_cmp_locale(left, right) |
| 2176 |
|
|
: sv_cmp(left, right)); |
| 2177 |
|
|
SETs(boolSV(cmp < 0)); |
| 2178 |
|
|
RETURN; |
| 2179 |
|
|
} |
| 2180 |
|
|
} |
| 2181 |
|
|
|
| 2182 |
|
|
PP(pp_sgt) |
| 2183 |
|
|
{ |
| 2184 |
|
|
dSP; tryAMAGICbinSET(sgt,0); |
| 2185 |
|
|
{ |
| 2186 |
|
|
dPOPTOPssrl; |
| 2187 |
|
|
int cmp = (IN_LOCALE_RUNTIME |
| 2188 |
|
|
? sv_cmp_locale(left, right) |
| 2189 |
|
|
: sv_cmp(left, right)); |
| 2190 |
|
|
SETs(boolSV(cmp > 0)); |
| 2191 |
|
|
RETURN; |
| 2192 |
|
|
} |
| 2193 |
|
|
} |
| 2194 |
|
|
|
| 2195 |
|
|
PP(pp_sle) |
| 2196 |
|
|
{ |
| 2197 |
|
|
dSP; tryAMAGICbinSET(sle,0); |
| 2198 |
|
|
{ |
| 2199 |
|
|
dPOPTOPssrl; |
| 2200 |
|
|
int cmp = (IN_LOCALE_RUNTIME |
| 2201 |
|
|
? sv_cmp_locale(left, right) |
| 2202 |
|
|
: sv_cmp(left, right)); |
| 2203 |
|
|
SETs(boolSV(cmp <= 0)); |
| 2204 |
|
|
RETURN; |
| 2205 |
|
|
} |
| 2206 |
|
|
} |
| 2207 |
|
|
|
| 2208 |
|
|
PP(pp_sge) |
| 2209 |
|
|
{ |
| 2210 |
|
|
dSP; tryAMAGICbinSET(sge,0); |
| 2211 |
|
|
{ |
| 2212 |
|
|
dPOPTOPssrl; |
| 2213 |
|
|
int cmp = (IN_LOCALE_RUNTIME |
| 2214 |
|
|
? sv_cmp_locale(left, right) |
| 2215 |
|
|
: sv_cmp(left, right)); |
| 2216 |
|
|
SETs(boolSV(cmp >= 0)); |
| 2217 |
|
|
RETURN; |
| 2218 |
|
|
} |
| 2219 |
|
|
} |
| 2220 |
|
|
|
| 2221 |
|
|
PP(pp_seq) |
| 2222 |
|
|
{ |
| 2223 |
|
|
dSP; tryAMAGICbinSET(seq,0); |
| 2224 |
|
|
{ |
| 2225 |
|
|
dPOPTOPssrl; |
| 2226 |
|
|
SETs(boolSV(sv_eq(left, right))); |
| 2227 |
|
|
RETURN; |
| 2228 |
|
|
} |
| 2229 |
|
|
} |
| 2230 |
|
|
|
| 2231 |
|
|
PP(pp_sne) |
| 2232 |
|
|
{ |
| 2233 |
|
|
dSP; tryAMAGICbinSET(sne,0); |
| 2234 |
|
|
{ |
| 2235 |
|
|
dPOPTOPssrl; |
| 2236 |
|
|
SETs(boolSV(!sv_eq(left, right))); |
| 2237 |
|
|
RETURN; |
| 2238 |
|
|
} |
| 2239 |
|
|
} |
| 2240 |
|
|
|
| 2241 |
|
|
PP(pp_scmp) |
| 2242 |
|
|
{ |
| 2243 |
|
|
dSP; dTARGET; tryAMAGICbin(scmp,0); |
| 2244 |
|
|
{ |
| 2245 |
|
|
dPOPTOPssrl; |
| 2246 |
|
|
int cmp = (IN_LOCALE_RUNTIME |
| 2247 |
|
|
? sv_cmp_locale(left, right) |
| 2248 |
|
|
: sv_cmp(left, right)); |
| 2249 |
|
|
SETi( cmp ); |
| 2250 |
|
|
RETURN; |
| 2251 |
|
|
} |
| 2252 |
|
|
} |
| 2253 |
|
|
|
| 2254 |
|
|
PP(pp_bit_and) |
| 2255 |
|
|
{ |
| 2256 |
|
|
dSP; dATARGET; tryAMAGICbin(band,opASSIGN); |
| 2257 |
|
|
{ |
| 2258 |
|
|
dPOPTOPssrl; |
| 2259 |
|
|
if (SvNIOKp(left) || SvNIOKp(right)) { |
| 2260 |
|
|
if (PL_op->op_private & HINT_INTEGER) { |
| 2261 |
|
|
IV i = SvIV(left) & SvIV(right); |
| 2262 |
|
|
SETi(i); |
| 2263 |
|
|
} |
| 2264 |
|
|
else { |
| 2265 |
|
|
UV u = SvUV(left) & SvUV(right); |
| 2266 |
|
|
SETu(u); |
| 2267 |
|
|
} |
| 2268 |
|
|
} |
| 2269 |
|
|
else { |
| 2270 |
|
|
do_vop(PL_op->op_type, TARG, left, right); |
| 2271 |
|
|
SETTARG; |
| 2272 |
|
|
} |
| 2273 |
|
|
RETURN; |
| 2274 |
|
|
} |
| 2275 |
|
|
} |
| 2276 |
|
|
|
| 2277 |
|
|
PP(pp_bit_xor) |
| 2278 |
|
|
{ |
| 2279 |
|
|
dSP; dATARGET; tryAMAGICbin(bxor,opASSIGN); |
| 2280 |
|
|
{ |
| 2281 |
|
|
dPOPTOPssrl; |
| 2282 |
|
|
if (SvNIOKp(left) || SvNIOKp(right)) { |
| 2283 |
|
|
if (PL_op->op_private & HINT_INTEGER) { |
| 2284 |
|
|
IV i = (USE_LEFT(left) ? SvIV(left) : 0) ^ SvIV(right); |
| 2285 |
|
|
SETi(i); |
| 2286 |
|
|
} |
| 2287 |
|
|
else { |
| 2288 |
|
|
UV u = (USE_LEFT(left) ? SvUV(left) : 0) ^ SvUV(right); |
| 2289 |
|
|
SETu(u); |
| 2290 |
|
|
} |
| 2291 |
|
|
} |
| 2292 |
|
|
else { |
| 2293 |
|
|
do_vop(PL_op->op_type, TARG, left, right); |
| 2294 |
|
|
SETTARG; |
| 2295 |
|
|
} |
| 2296 |
|
|
RETURN; |
| 2297 |
|
|
} |
| 2298 |
|
|
} |
| 2299 |
|
|
|
| 2300 |
|
|
PP(pp_bit_or) |
| 2301 |
|
|
{ |
| 2302 |
|
|
dSP; dATARGET; tryAMAGICbin(bor,opASSIGN); |
| 2303 |
|
|
{ |
| 2304 |
|
|
dPOPTOPssrl; |
| 2305 |
|
|
if (SvNIOKp(left) || SvNIOKp(right)) { |
| 2306 |
|
|
if (PL_op->op_private & HINT_INTEGER) { |
| 2307 |
|
|
IV i = (USE_LEFT(left) ? SvIV(left) : 0) | SvIV(right); |
| 2308 |
|
|
SETi(i); |
| 2309 |
|
|
} |
| 2310 |
|
|
else { |
| 2311 |
|
|
UV u = (USE_LEFT(left) ? SvUV(left) : 0) | SvUV(right); |
| 2312 |
|
|
SETu(u); |
| 2313 |
|
|
} |
| 2314 |
|
|
} |
| 2315 |
|
|
else { |
| 2316 |
|
|
do_vop(PL_op->op_type, TARG, left, right); |
| 2317 |
|
|
SETTARG; |
| 2318 |
|
|
} |
| 2319 |
|
|
RETURN; |
| 2320 |
|
|
} |
| 2321 |
|
|
} |
| 2322 |
|
|
|
| 2323 |
|
|
PP(pp_negate) |
| 2324 |
|
|
{ |
| 2325 |
|
|
dSP; dTARGET; tryAMAGICun(neg); |
| 2326 |
|
|
{ |
| 2327 |
|
|
dTOPss; |
| 2328 |
|
|
int flags = SvFLAGS(sv); |
| 2329 |
|
|
if (SvGMAGICAL(sv)) |
| 2330 |
|
|
mg_get(sv); |
| 2331 |
|
|
if ((flags & SVf_IOK) || ((flags & (SVp_IOK | SVp_NOK)) == SVp_IOK)) { |
| 2332 |
|
|
/* It's publicly an integer, or privately an integer-not-float */ |
| 2333 |
|
|
oops_its_an_int: |
| 2334 |
|
|
if (SvIsUV(sv)) { |
| 2335 |
|
|
if (SvIVX(sv) == IV_MIN) { |
| 2336 |
|
|
/* 2s complement assumption. */ |
| 2337 |
|
|
SETi(SvIVX(sv)); /* special case: -((UV)IV_MAX+1) == IV_MIN */ |
| 2338 |
|
|
RETURN; |
| 2339 |
|
|
} |
| 2340 |
|
|
else if (SvUVX(sv) <= IV_MAX) { |
| 2341 |
|
|
SETi(-SvIVX(sv)); |
| 2342 |
|
|
RETURN; |
| 2343 |
|
|
} |
| 2344 |
|
|
} |
| 2345 |
|
|
else if (SvIVX(sv) != IV_MIN) { |
| 2346 |
|
|
SETi(-SvIVX(sv)); |
| 2347 |
|
|
RETURN; |
| 2348 |
|
|
} |
| 2349 |
|
|
#ifdef PERL_PRESERVE_IVUV |
| 2350 |
|
|
else { |
| 2351 |
|
|
SETu((UV)IV_MIN); |
| 2352 |
|
|
RETURN; |
| 2353 |
|
|
} |
| 2354 |
|
|
#endif |
| 2355 |
|
|
} |
| 2356 |
|
|
if (SvNIOKp(sv)) |
| 2357 |
|
|
SETn(-SvNV(sv)); |
| 2358 |
|
|
else if (SvPOKp(sv)) { |
| 2359 |
|
|
STRLEN len; |
| 2360 |
|
|
char *s = SvPV(sv, len); |
| 2361 |
|
|
if (isIDFIRST(*s)) { |
| 2362 |
|
|
sv_setpvn(TARG, "-", 1); |
| 2363 |
|
|
sv_catsv(TARG, sv); |
| 2364 |
|
|
} |
| 2365 |
|
|
else if (*s == '+' || *s == '-') { |
| 2366 |
|
|
sv_setsv(TARG, sv); |
| 2367 |
|
|
*SvPV_force(TARG, len) = *s == '-' ? '+' : '-'; |
| 2368 |
|
|
} |
| 2369 |
|
|
else if (DO_UTF8(sv)) { |
| 2370 |
|
|
SvIV_please(sv); |
| 2371 |
|
|
if (SvIOK(sv)) |
| 2372 |
|
|
goto oops_its_an_int; |
| 2373 |
|
|
if (SvNOK(sv)) |
| 2374 |
|
|
sv_setnv(TARG, -SvNV(sv)); |
| 2375 |
|
|
else { |
| 2376 |
|
|
sv_setpvn(TARG, "-", 1); |
| 2377 |
|
|
sv_catsv(TARG, sv); |
| 2378 |
|
|
} |
| 2379 |
|
|
} |
| 2380 |
|
|
else { |
| 2381 |
|
|
SvIV_please(sv); |
| 2382 |
|
|
if (SvIOK(sv)) |
| 2383 |
|
|
goto oops_its_an_int; |
| 2384 |
|
|
sv_setnv(TARG, -SvNV(sv)); |
| 2385 |
|
|
} |
| 2386 |
|
|
SETTARG; |
| 2387 |
|
|
} |
| 2388 |
|
|
else |
| 2389 |
|
|
SETn(-SvNV(sv)); |
| 2390 |
|
|
} |
| 2391 |
|
|
RETURN; |
| 2392 |
|
|
} |
| 2393 |
|
|
|
| 2394 |
|
|
PP(pp_not) |
| 2395 |
|
|
{ |
| 2396 |
|
|
dSP; tryAMAGICunSET(not); |
| 2397 |
|
|
*PL_stack_sp = boolSV(!SvTRUE(*PL_stack_sp)); |
| 2398 |
|
|
return NORMAL; |
| 2399 |
|
|
} |
| 2400 |
|
|
|
| 2401 |
|
|
PP(pp_complement) |
| 2402 |
|
|
{ |
| 2403 |
|
|
dSP; dTARGET; tryAMAGICun(compl); |
| 2404 |
|
|
{ |
| 2405 |
|
|
dTOPss; |
| 2406 |
|
|
if (SvNIOKp(sv)) { |
| 2407 |
|
|
if (PL_op->op_private & HINT_INTEGER) { |
| 2408 |
|
|
IV i = ~SvIV(sv); |
| 2409 |
|
|
SETi(i); |
| 2410 |
|
|
} |
| 2411 |
|
|
else { |
| 2412 |
|
|
UV u = ~SvUV(sv); |
| 2413 |
|
|
SETu(u); |
| 2414 |
|
|
} |
| 2415 |
|
|
} |
| 2416 |
|
|
else { |
| 2417 |
|
|
register U8 *tmps; |
| 2418 |
|
|
register I32 anum; |
| 2419 |
|
|
STRLEN len; |
| 2420 |
|
|
|
| 2421 |
|
|
(void)SvPV_nomg(sv,len); /* force check for uninit var */ |
| 2422 |
|
|
SvSetSV(TARG, sv); |
| 2423 |
|
|
tmps = (U8*)SvPV_force(TARG, len); |
| 2424 |
|
|
anum = len; |
| 2425 |
|
|
if (SvUTF8(TARG)) { |
| 2426 |
|
|
/* Calculate exact length, let's not estimate. */ |
| 2427 |
|
|
STRLEN targlen = 0; |
| 2428 |
|
|
U8 *result; |
| 2429 |
|
|
U8 *send; |
| 2430 |
|
|
STRLEN l; |
| 2431 |
|
|
UV nchar = 0; |
| 2432 |
|
|
UV nwide = 0; |
| 2433 |
|
|
|
| 2434 |
|
|
send = tmps + len; |
| 2435 |
|
|
while (tmps < send) { |
| 2436 |
|
|
UV c = utf8n_to_uvchr(tmps, send-tmps, &l, UTF8_ALLOW_ANYUV); |
| 2437 |
|
|
tmps += UTF8SKIP(tmps); |
| 2438 |
|
|
targlen += UNISKIP(~c); |
| 2439 |
|
|
nchar++; |
| 2440 |
|
|
if (c > 0xff) |
| 2441 |
|
|
nwide++; |
| 2442 |
|
|
} |
| 2443 |
|
|
|
| 2444 |
|
|
/* Now rewind strings and write them. */ |
| 2445 |
|
|
tmps -= len; |
| 2446 |
|
|
|
| 2447 |
|
|
if (nwide) { |
| 2448 |
|
|
Newz(0, result, targlen + 1, U8); |
| 2449 |
|
|
while (tmps < send) { |
| 2450 |
|
|
UV c = utf8n_to_uvchr(tmps, send-tmps, &l, UTF8_ALLOW_ANYUV); |
| 2451 |
|
|
tmps += UTF8SKIP(tmps); |
| 2452 |
|
|
result = uvchr_to_utf8_flags(result, ~c, UNICODE_ALLOW_ANY); |
| 2453 |
|
|
} |
| 2454 |
|
|
*result = '\0'; |
| 2455 |
|
|
result -= targlen; |
| 2456 |
|
|
sv_setpvn(TARG, (char*)result, targlen); |
| 2457 |
|
|
SvUTF8_on(TARG); |
| 2458 |
|
|
} |
| 2459 |
|
|
else { |
| 2460 |
|
|
Newz(0, result, nchar + 1, U8); |
| 2461 |
|
|
while (tmps < send) { |
| 2462 |
|
|
U8 c = (U8)utf8n_to_uvchr(tmps, 0, &l, UTF8_ALLOW_ANY); |
| 2463 |
|
|
tmps += UTF8SKIP(tmps); |
| 2464 |
|
|
*result++ = ~c; |
| 2465 |
|
|
} |
| 2466 |
|
|
*result = '\0'; |
| 2467 |
|
|
result -= nchar; |
| 2468 |
|
|
sv_setpvn(TARG, (char*)result, nchar); |
| 2469 |
|
|
SvUTF8_off(TARG); |
| 2470 |
|
|
} |
| 2471 |
|
|
Safefree(result); |
| 2472 |
|
|
SETs(TARG); |
| 2473 |
|
|
RETURN; |
| 2474 |
|
|
} |
| 2475 |
|
|
#ifdef LIBERAL |
| 2476 |
|
|
{ |
| 2477 |
|
|
register long *tmpl; |
| 2478 |
|
|
for ( ; anum && (unsigned long)tmps % sizeof(long); anum--, tmps++) |
| 2479 |
|
|
*tmps = ~*tmps; |
| 2480 |
|
|
tmpl = (long*)tmps; |
| 2481 |
|
|
for ( ; anum >= sizeof(long); anum -= sizeof(long), tmpl++) |
| 2482 |
|
|
*tmpl = ~*tmpl; |
| 2483 |
|
|
tmps = (U8*)tmpl; |
| 2484 |
|
|
} |
| 2485 |
|
|
#endif |
| 2486 |
|
|
for ( ; anum > 0; anum--, tmps++) |
| 2487 |
|
|
*tmps = ~*tmps; |
| 2488 |
|
|
|
| 2489 |
|
|
SETs(TARG); |
| 2490 |
|
|
} |
| 2491 |
|
|
RETURN; |
| 2492 |
|
|
} |
| 2493 |
|
|
} |
| 2494 |
|
|
|
| 2495 |
|
|
/* integer versions of some of the above */ |
| 2496 |
|
|
|
| 2497 |
|
|
PP(pp_i_multiply) |
| 2498 |
|
|
{ |
| 2499 |
|
|
dSP; dATARGET; tryAMAGICbin(mult,opASSIGN); |
| 2500 |
|
|
{ |
| 2501 |
|
|
dPOPTOPiirl; |
| 2502 |
|
|
SETi( left * right ); |
| 2503 |
|
|
RETURN; |
| 2504 |
|
|
} |
| 2505 |
|
|
} |
| 2506 |
|
|
|
| 2507 |
|
|
PP(pp_i_divide) |
| 2508 |
|
|
{ |
| 2509 |
|
|
dSP; dATARGET; tryAMAGICbin(div,opASSIGN); |
| 2510 |
|
|
{ |
| 2511 |
|
|
dPOPiv; |
| 2512 |
|
|
if (value == 0) |
| 2513 |
|
|
DIE(aTHX_ "Illegal division by zero"); |
| 2514 |
|
|
value = POPi / value; |
| 2515 |
|
|
PUSHi( value ); |
| 2516 |
|
|
RETURN; |
| 2517 |
|
|
} |
| 2518 |
|
|
} |
| 2519 |
|
|
|
| 2520 |
|
|
STATIC |
| 2521 |
|
|
PP(pp_i_modulo_0) |
| 2522 |
|
|
{ |
| 2523 |
|
|
/* This is the vanilla old i_modulo. */ |
| 2524 |
|
|
dSP; dATARGET; tryAMAGICbin(modulo,opASSIGN); |
| 2525 |
|
|
{ |
| 2526 |
|
|
dPOPTOPiirl; |
| 2527 |
|
|
if (!right) |
| 2528 |
|
|
DIE(aTHX_ "Illegal modulus zero"); |
| 2529 |
|
|
SETi( left % right ); |
| 2530 |
|
|
RETURN; |
| 2531 |
|
|
} |
| 2532 |
|
|
} |
| 2533 |
|
|
|
| 2534 |
|
|
#if defined(__GLIBC__) && IVSIZE == 8 |
| 2535 |
|
|
STATIC |
| 2536 |
|
|
PP(pp_i_modulo_1) |
| 2537 |
|
|
{ |
| 2538 |
|
|
/* This is the i_modulo with the workaround for the _moddi3 bug |
| 2539 |
|
|
* in (at least) glibc 2.2.5 (the PERL_ABS() the workaround). |
| 2540 |
|
|
* See below for pp_i_modulo. */ |
| 2541 |
|
|
dSP; dATARGET; tryAMAGICbin(modulo,opASSIGN); |
| 2542 |
|
|
{ |
| 2543 |
|
|
dPOPTOPiirl; |
| 2544 |
|
|
if (!right) |
| 2545 |
|
|
DIE(aTHX_ "Illegal modulus zero"); |
| 2546 |
|
|
SETi( left % PERL_ABS(right) ); |
| 2547 |
|
|
RETURN; |
| 2548 |
|
|
} |
| 2549 |
|
|
} |
| 2550 |
|
|
#endif |
| 2551 |
|
|
|
| 2552 |
|
|
PP(pp_i_modulo) |
| 2553 |
|
|
{ |
| 2554 |
|
|
dSP; dATARGET; tryAMAGICbin(modulo,opASSIGN); |
| 2555 |
|
|
{ |
| 2556 |
|
|
dPOPTOPiirl; |
| 2557 |
|
|
if (!right) |
| 2558 |
|
|
DIE(aTHX_ "Illegal modulus zero"); |
| 2559 |
|
|
/* The assumption is to use hereafter the old vanilla version... */ |
| 2560 |
|
|
PL_op->op_ppaddr = |
| 2561 |
|
|
PL_ppaddr[OP_I_MODULO] = |
| 2562 |
|
|
&Perl_pp_i_modulo_0; |
| 2563 |
|
|
/* .. but if we have glibc, we might have a buggy _moddi3 |
| 2564 |
|
|
* (at least glicb 2.2.5 is known to have this bug), in other |
| 2565 |
|
|
* words our integer modulus with negative quad as the second |
| 2566 |
|
|
* argument might be broken. Test for this and re-patch the |
| 2567 |
|
|
* opcode dispatch table if that is the case, remembering to |
| 2568 |
|
|
* also apply the workaround so that this first round works |
| 2569 |
|
|
* right, too. See [perl #9402] for more information. */ |
| 2570 |
|
|
#if defined(__GLIBC__) && IVSIZE == 8 |
| 2571 |
|
|
{ |
| 2572 |
|
|
IV l = 3; |
| 2573 |
|
|
IV r = -10; |
| 2574 |
|
|
/* Cannot do this check with inlined IV constants since |
| 2575 |
|
|
* that seems to work correctly even with the buggy glibc. */ |
| 2576 |
|
|
if (l % r == -3) { |
| 2577 |
|
|
/* Yikes, we have the bug. |
| 2578 |
|
|
* Patch in the workaround version. */ |
| 2579 |
|
|
PL_op->op_ppaddr = |
| 2580 |
|
|
PL_ppaddr[OP_I_MODULO] = |
| 2581 |
|
|
&Perl_pp_i_modulo_1; |
| 2582 |
|
|
/* Make certain we work right this time, too. */ |
| 2583 |
|
|
right = PERL_ABS(right); |
| 2584 |
|
|
} |
| 2585 |
|
|
} |
| 2586 |
|
|
#endif |
| 2587 |
|
|
SETi( left % right ); |
| 2588 |
|
|
RETURN; |
| 2589 |
|
|
} |
| 2590 |
|
|
} |
| 2591 |
|
|
|
| 2592 |
|
|
PP(pp_i_add) |
| 2593 |
|
|
{ |
| 2594 |
|
|
dSP; dATARGET; tryAMAGICbin(add,opASSIGN); |
| 2595 |
|
|
{ |
| 2596 |
|
|
dPOPTOPiirl_ul; |
| 2597 |
|
|
SETi( left + right ); |
| 2598 |
|
|
RETURN; |
| 2599 |
|
|
} |
| 2600 |
|
|
} |
| 2601 |
|
|
|
| 2602 |
|
|
PP(pp_i_subtract) |
| 2603 |
|
|
{ |
| 2604 |
|
|
dSP; dATARGET; tryAMAGICbin(subtr,opASSIGN); |
| 2605 |
|
|
{ |
| 2606 |
|
|
dPOPTOPiirl_ul; |
| 2607 |
|
|
SETi( left - right ); |
| 2608 |
|
|
RETURN; |
| 2609 |
|
|
} |
| 2610 |
|
|
} |
| 2611 |
|
|
|
| 2612 |
|
|
PP(pp_i_lt) |
| 2613 |
|
|
{ |
| 2614 |
|
|
dSP; tryAMAGICbinSET(lt,0); |
| 2615 |
|
|
{ |
| 2616 |
|
|
dPOPTOPiirl; |
| 2617 |
|
|
SETs(boolSV(left < right)); |
| 2618 |
|
|
RETURN; |
| 2619 |
|
|
} |
| 2620 |
|
|
} |
| 2621 |
|
|
|
| 2622 |
|
|
PP(pp_i_gt) |
| 2623 |
|
|
{ |
| 2624 |
|
|
dSP; tryAMAGICbinSET(gt,0); |
| 2625 |
|
|
{ |
| 2626 |
|
|
dPOPTOPiirl; |
| 2627 |
|
|
SETs(boolSV(left > right)); |
| 2628 |
|
|
RETURN; |
| 2629 |
|
|
} |
| 2630 |
|
|
} |
| 2631 |
|
|
|
| 2632 |
|
|
PP(pp_i_le) |
| 2633 |
|
|
{ |
| 2634 |
|
|
dSP; tryAMAGICbinSET(le,0); |
| 2635 |
|
|
{ |
| 2636 |
|
|
dPOPTOPiirl; |
| 2637 |
|
|
SETs(boolSV(left <= right)); |
| 2638 |
|
|
RETURN; |
| 2639 |
|
|
} |
| 2640 |
|
|
} |
| 2641 |
|
|
|
| 2642 |
|
|
PP(pp_i_ge) |
| 2643 |
|
|
{ |
| 2644 |
|
|
dSP; tryAMAGICbinSET(ge,0); |
| 2645 |
|
|
{ |
| 2646 |
|
|
dPOPTOPiirl; |
| 2647 |
|
|
SETs(boolSV(left >= right)); |
| 2648 |
|
|
RETURN; |
| 2649 |
|
|
} |
| 2650 |
|
|
} |
| 2651 |
|
|
|
| 2652 |
|
|
PP(pp_i_eq) |
| 2653 |
|
|
{ |
| 2654 |
|
|
dSP; tryAMAGICbinSET(eq,0); |
| 2655 |
|
|
{ |
| 2656 |
|
|
dPOPTOPiirl; |
| 2657 |
|
|
SETs(boolSV(left == right)); |
| 2658 |
|
|
RETURN; |
| 2659 |
|
|
} |
| 2660 |
|
|
} |
| 2661 |
|
|
|
| 2662 |
|
|
PP(pp_i_ne) |
| 2663 |
|
|
{ |
| 2664 |
|
|
dSP; tryAMAGICbinSET(ne,0); |
| 2665 |
|
|
{ |
| 2666 |
|
|
dPOPTOPiirl; |
| 2667 |
|
|
SETs(boolSV(left != right)); |
| 2668 |
|
|
RETURN; |
| 2669 |
|
|
} |
| 2670 |
|
|
} |
| 2671 |
|
|
|
| 2672 |
|
|
PP(pp_i_ncmp) |
| 2673 |
|
|
{ |
| 2674 |
|
|
dSP; dTARGET; tryAMAGICbin(ncmp,0); |
| 2675 |
|
|
{ |
| 2676 |
|
|
dPOPTOPiirl; |
| 2677 |
|
|
I32 value; |
| 2678 |
|
|
|
| 2679 |
|
|
if (left > right) |
| 2680 |
|
|
value = 1; |
| 2681 |
|
|
else if (left < right) |
| 2682 |
|
|
value = -1; |
| 2683 |
|
|
else |
| 2684 |
|
|
value = 0; |
| 2685 |
|
|
SETi(value); |
| 2686 |
|
|
RETURN; |
| 2687 |
|
|
} |
| 2688 |
|
|
} |
| 2689 |
|
|
|
| 2690 |
|
|
PP(pp_i_negate) |
| 2691 |
|
|
{ |
| 2692 |
|
|
dSP; dTARGET; tryAMAGICun(neg); |
| 2693 |
|
|
SETi(-TOPi); |
| 2694 |
|
|
RETURN; |
| 2695 |
|
|
} |
| 2696 |
|
|
|
| 2697 |
|
|
/* High falutin' math. */ |
| 2698 |
|
|
|
| 2699 |
|
|
PP(pp_atan2) |
| 2700 |
|
|
{ |
| 2701 |
|
|
dSP; dTARGET; tryAMAGICbin(atan2,0); |
| 2702 |
|
|
{ |
| 2703 |
|
|
dPOPTOPnnrl; |
| 2704 |
|
|
SETn(Perl_atan2(left, right)); |
| 2705 |
|
|
RETURN; |
| 2706 |
|
|
} |
| 2707 |
|
|
} |
| 2708 |
|
|
|
| 2709 |
|
|
PP(pp_sin) |
| 2710 |
|
|
{ |
| 2711 |
|
|
dSP; dTARGET; tryAMAGICun(sin); |
| 2712 |
|
|
{ |
| 2713 |
|
|
NV value; |
| 2714 |
|
|
value = POPn; |
| 2715 |
|
|
value = Perl_sin(value); |
| 2716 |
|
|
XPUSHn(value); |
| 2717 |
|
|
RETURN; |
| 2718 |
|
|
} |
| 2719 |
|
|
} |
| 2720 |
|
|
|
| 2721 |
|
|
PP(pp_cos) |
| 2722 |
|
|
{ |
| 2723 |
|
|
dSP; dTARGET; tryAMAGICun(cos); |
| 2724 |
|
|
{ |
| 2725 |
|
|
NV value; |
| 2726 |
|
|
value = POPn; |
| 2727 |
|
|
value = Perl_cos(value); |
| 2728 |
|
|
XPUSHn(value); |
| 2729 |
|
|
RETURN; |
| 2730 |
|
|
} |
| 2731 |
|
|
} |
| 2732 |
|
|
|
| 2733 |
|
|
/* Support Configure command-line overrides for rand() functions. |
| 2734 |
|
|
After 5.005, perhaps we should replace this by Configure support |
| 2735 |
|
|
for drand48(), random(), or rand(). For 5.005, though, maintain |
| 2736 |
|
|
compatibility by calling rand() but allow the user to override it. |
| 2737 |
|
|
See INSTALL for details. --Andy Dougherty 15 July 1998 |
| 2738 |
|
|
*/ |
| 2739 |
|
|
/* Now it's after 5.005, and Configure supports drand48() and random(), |
| 2740 |
|
|
in addition to rand(). So the overrides should not be needed any more. |
| 2741 |
|
|
--Jarkko Hietaniemi 27 September 1998 |
| 2742 |
|
|
*/ |
| 2743 |
|
|
|
| 2744 |
|
|
#ifndef HAS_DRAND48_PROTO |
| 2745 |
|
|
extern double drand48 (void); |
| 2746 |
|
|
#endif |
| 2747 |
|
|
|
| 2748 |
|
|
PP(pp_rand) |
| 2749 |
|
|
{ |
| 2750 |
|
|
dSP; dTARGET; |
| 2751 |
|
|
NV value; |
| 2752 |
|
|
if (MAXARG < 1) |
| 2753 |
|
|
value = 1.0; |
| 2754 |
|
|
else |
| 2755 |
|
|
value = POPn; |
| 2756 |
|
|
if (value == 0.0) |
| 2757 |
|
|
value = 1.0; |
| 2758 |
|
|
if (!PL_srand_called) { |
| 2759 |
|
|
(void)seedDrand01((Rand_seed_t)seed()); |
| 2760 |
|
|
PL_srand_called = TRUE; |
| 2761 |
|
|
} |
| 2762 |
|
|
value *= Drand01(); |
| 2763 |
|
|
XPUSHn(value); |
| 2764 |
|
|
RETURN; |
| 2765 |
|
|
} |
| 2766 |
|
|
|
| 2767 |
|
|
PP(pp_srand) |
| 2768 |
|
|
{ |
| 2769 |
|
|
dSP; |
| 2770 |
|
|
UV anum; |
| 2771 |
|
|
if (MAXARG < 1) |
| 2772 |
|
|
anum = seed(); |
| 2773 |
|
|
else |
| 2774 |
|
|
anum = POPu; |
| 2775 |
|
|
(void)seedDrand01((Rand_seed_t)anum); |
| 2776 |
|
|
PL_srand_called = TRUE; |
| 2777 |
|
|
EXTEND(SP, 1); |
| 2778 |
|
|
RETPUSHYES; |
| 2779 |
|
|
} |
| 2780 |
|
|
|
| 2781 |
|
|
PP(pp_exp) |
| 2782 |
|
|
{ |
| 2783 |
|
|
dSP; dTARGET; tryAMAGICun(exp); |
| 2784 |
|
|
{ |
| 2785 |
|
|
NV value; |
| 2786 |
|
|
value = POPn; |
| 2787 |
|
|
value = Perl_exp(value); |
| 2788 |
|
|
XPUSHn(value); |
| 2789 |
|
|
RETURN; |
| 2790 |
|
|
} |
| 2791 |
|
|
} |
| 2792 |
|
|
|
| 2793 |
|
|
PP(pp_log) |
| 2794 |
|
|
{ |
| 2795 |
|
|
dSP; dTARGET; tryAMAGICun(log); |
| 2796 |
|
|
{ |
| 2797 |
|
|
NV value; |
| 2798 |
|
|
value = POPn; |
| 2799 |
|
|
if (value <= 0.0) { |
| 2800 |
|
|
SET_NUMERIC_STANDARD(); |
| 2801 |
|
|
DIE(aTHX_ "Can't take log of %"NVgf, value); |
| 2802 |
|
|
} |
| 2803 |
|
|
value = Perl_log(value); |
| 2804 |
|
|
XPUSHn(value); |
| 2805 |
|
|
RETURN; |
| 2806 |
|
|
} |
| 2807 |
|
|
} |
| 2808 |
|
|
|
| 2809 |
|
|
PP(pp_sqrt) |
| 2810 |
|
|
{ |
| 2811 |
|
|
dSP; dTARGET; tryAMAGICun(sqrt); |
| 2812 |
|
|
{ |
| 2813 |
|
|
NV value; |
| 2814 |
|
|
value = POPn; |
| 2815 |
|
|
if (value < 0.0) { |
| 2816 |
|
|
SET_NUMERIC_STANDARD(); |
| 2817 |
|
|
DIE(aTHX_ "Can't take sqrt of %"NVgf, value); |
| 2818 |
|
|
} |
| 2819 |
|
|
value = Perl_sqrt(value); |
| 2820 |
|
|
XPUSHn(value); |
| 2821 |
|
|
RETURN; |
| 2822 |
|
|
} |
| 2823 |
|
|
} |
| 2824 |
|
|
|
| 2825 |
|
|
PP(pp_int) |
| 2826 |
|
|
{ |
| 2827 |
|
|
dSP; dTARGET; tryAMAGICun(int); |
| 2828 |
|
|
{ |
| 2829 |
|
|
NV value; |
| 2830 |
|
|
IV iv = TOPi; /* attempt to convert to IV if possible. */ |
| 2831 |
|
|
/* XXX it's arguable that compiler casting to IV might be subtly |
| 2832 |
|
|
different from modf (for numbers inside (IV_MIN,UV_MAX)) in which |
| 2833 |
|
|
else preferring IV has introduced a subtle behaviour change bug. OTOH |
| 2834 |
|
|
relying on floating point to be accurate is a bug. */ |
| 2835 |
|
|
|
| 2836 |
|
|
if (!SvOK(TOPs)) |
| 2837 |
|
|
SETu(0); |
| 2838 |
|
|
else if (SvIOK(TOPs)) { |
| 2839 |
|
|
if (SvIsUV(TOPs)) { |
| 2840 |
|
|
UV uv = TOPu; |
| 2841 |
|
|
SETu(uv); |
| 2842 |
|
|
} else |
| 2843 |
|
|
SETi(iv); |
| 2844 |
|
|
} else { |
| 2845 |
|
|
value = TOPn; |
| 2846 |
|
|
if (value >= 0.0) { |
| 2847 |
|
|
if (value < (NV)UV_MAX + 0.5) { |
| 2848 |
|
|
SETu(U_V(value)); |
| 2849 |
|
|
} else { |
| 2850 |
|
|
SETn(Perl_floor(value)); |
| 2851 |
|
|
} |
| 2852 |
|
|
} |
| 2853 |
|
|
else { |
| 2854 |
|
|
if (value > (NV)IV_MIN - 0.5) { |
| 2855 |
|
|
SETi(I_V(value)); |
| 2856 |
|
|
} else { |
| 2857 |
|
|
SETn(Perl_ceil(value)); |
| 2858 |
|
|
} |
| 2859 |
|
|
} |
| 2860 |
|
|
} |
| 2861 |
|
|
} |
| 2862 |
|
|
RETURN; |
| 2863 |
|
|
} |
| 2864 |
|
|
|
| 2865 |
|
|
PP(pp_abs) |
| 2866 |
|
|
{ |
| 2867 |
|
|
dSP; dTARGET; tryAMAGICun(abs); |
| 2868 |
|
|
{ |
| 2869 |
|
|
/* This will cache the NV value if string isn't actually integer */ |
| 2870 |
|
|
IV iv = TOPi; |
| 2871 |
|
|
|
| 2872 |
|
|
if (!SvOK(TOPs)) |
| 2873 |
|
|
SETu(0); |
| 2874 |
|
|
else if (SvIOK(TOPs)) { |
| 2875 |
|
|
/* IVX is precise */ |
| 2876 |
|
|
if (SvIsUV(TOPs)) { |
| 2877 |
|
|
SETu(TOPu); /* force it to be numeric only */ |
| 2878 |
|
|
} else { |
| 2879 |
|
|
if (iv >= 0) { |
| 2880 |
|
|
SETi(iv); |
| 2881 |
|
|
} else { |
| 2882 |
|
|
if (iv != IV_MIN) { |
| 2883 |
|
|
SETi(-iv); |
| 2884 |
|
|
} else { |
| 2885 |
|
|
/* 2s complement assumption. Also, not really needed as |
| 2886 |
|
|
IV_MIN and -IV_MIN should both be %100...00 and NV-able */ |
| 2887 |
|
|
SETu(IV_MIN); |
| 2888 |
|
|
} |
| 2889 |
|
|
} |
| 2890 |
|
|
} |
| 2891 |
|
|
} else{ |
| 2892 |
|
|
NV value = TOPn; |
| 2893 |
|
|
if (value < 0.0) |
| 2894 |
|
|
value = -value; |
| 2895 |
|
|
SETn(value); |
| 2896 |
|
|
} |
| 2897 |
|
|
} |
| 2898 |
|
|
RETURN; |
| 2899 |
|
|
} |
| 2900 |
|
|
|
| 2901 |
|
|
|
| 2902 |
|
|
PP(pp_hex) |
| 2903 |
|
|
{ |
| 2904 |
|
|
dSP; dTARGET; |
| 2905 |
|
|
char *tmps; |
| 2906 |
|
|
I32 flags = PERL_SCAN_ALLOW_UNDERSCORES; |
| 2907 |
|
|
STRLEN len; |
| 2908 |
|
|
NV result_nv; |
| 2909 |
|
|
UV result_uv; |
| 2910 |
|
|
SV* sv = POPs; |
| 2911 |
|
|
|
| 2912 |
|
|
tmps = (SvPVx(sv, len)); |
| 2913 |
|
|
if (DO_UTF8(sv)) { |
| 2914 |
|
|
/* If Unicode, try to downgrade |
| 2915 |
|
|
* If not possible, croak. */ |
| 2916 |
|
|
SV* tsv = sv_2mortal(newSVsv(sv)); |
| 2917 |
|
|
|
| 2918 |
|
|
SvUTF8_on(tsv); |
| 2919 |
|
|
sv_utf8_downgrade(tsv, FALSE); |
| 2920 |
|
|
tmps = SvPVX(tsv); |
| 2921 |
|
|
} |
| 2922 |
|
|
result_uv = grok_hex (tmps, &len, &flags, &result_nv); |
| 2923 |
|
|
if (flags & PERL_SCAN_GREATER_THAN_UV_MAX) { |
| 2924 |
|
|
XPUSHn(result_nv); |
| 2925 |
|
|
} |
| 2926 |
|
|
else { |
| 2927 |
|
|
XPUSHu(result_uv); |
| 2928 |
|
|
} |
| 2929 |
|
|
RETURN; |
| 2930 |
|
|
} |
| 2931 |
|
|
|
| 2932 |
|
|
PP(pp_oct) |
| 2933 |
|
|
{ |
| 2934 |
|
|
dSP; dTARGET; |
| 2935 |
|
|
char *tmps; |
| 2936 |
|
|
I32 flags = PERL_SCAN_ALLOW_UNDERSCORES; |
| 2937 |
|
|
STRLEN len; |
| 2938 |
|
|
NV result_nv; |
| 2939 |
|
|
UV result_uv; |
| 2940 |
|
|
SV* sv = POPs; |
| 2941 |
|
|
|
| 2942 |
|
|
tmps = (SvPVx(sv, len)); |
| 2943 |
|
|
if (DO_UTF8(sv)) { |
| 2944 |
|
|
/* If Unicode, try to downgrade |
| 2945 |
|
|
* If not possible, croak. */ |
| 2946 |
|
|
SV* tsv = sv_2mortal(newSVsv(sv)); |
| 2947 |
|
|
|
| 2948 |
|
|
SvUTF8_on(tsv); |
| 2949 |
|
|
sv_utf8_downgrade(tsv, FALSE); |
| 2950 |
|
|
tmps = SvPVX(tsv); |
| 2951 |
|
|
} |
| 2952 |
|
|
while (*tmps && len && isSPACE(*tmps)) |
| 2953 |
|
|
tmps++, len--; |
| 2954 |
|
|
if (*tmps == '0') |
| 2955 |
|
|
tmps++, len--; |
| 2956 |
|
|
if (*tmps == 'x') |
| 2957 |
|
|
result_uv = grok_hex (tmps, &len, &flags, &result_nv); |
| 2958 |
|
|
else if (*tmps == 'b') |
| 2959 |
|
|
result_uv = grok_bin (tmps, &len, &flags, &result_nv); |
| 2960 |
|
|
else |
| 2961 |
|
|
result_uv = grok_oct (tmps, &len, &flags, &result_nv); |
| 2962 |
|
|
|
| 2963 |
|
|
if (flags & PERL_SCAN_GREATER_THAN_UV_MAX) { |
| 2964 |
|
|
XPUSHn(result_nv); |
| 2965 |
|
|
} |
| 2966 |
|
|
else { |
| 2967 |
|
|
XPUSHu(result_uv); |
| 2968 |
|
|
} |
| 2969 |
|
|
RETURN; |
| 2970 |
|
|
} |
| 2971 |
|
|
|
| 2972 |
|
|
/* String stuff. */ |
| 2973 |
|
|
|
| 2974 |
|
|
PP(pp_length) |
| 2975 |
|
|
{ |
| 2976 |
|
|
dSP; dTARGET; |
| 2977 |
|
|
SV *sv = TOPs; |
| 2978 |
|
|
|
| 2979 |
|
|
if (DO_UTF8(sv)) |
| 2980 |
|
|
SETi(sv_len_utf8(sv)); |
| 2981 |
|
|
else |
| 2982 |
|
|
SETi(sv_len(sv)); |
| 2983 |
|
|
RETURN; |
| 2984 |
|
|
} |
| 2985 |
|
|
|
| 2986 |
|
|
PP(pp_substr) |
| 2987 |
|
|
{ |
| 2988 |
|
|
dSP; dTARGET; |
| 2989 |
|
|
SV *sv; |
| 2990 |
|
|
I32 len = 0; |
| 2991 |
|
|
STRLEN curlen; |
| 2992 |
|
|
STRLEN utf8_curlen; |
| 2993 |
|
|
I32 pos; |
| 2994 |
|
|
I32 rem; |
| 2995 |
|
|
I32 fail; |
| 2996 |
|
|
I32 lvalue = PL_op->op_flags & OPf_MOD || LVRET; |
| 2997 |
|
|
char *tmps; |
| 2998 |
|
|
I32 arybase = PL_curcop->cop_arybase; |
| 2999 |
|
|
SV *repl_sv = NULL; |
| 3000 |
|
|
char *repl = 0; |
| 3001 |
|
|
STRLEN repl_len; |
| 3002 |
|
|
int num_args = PL_op->op_private & 7; |
| 3003 |
|
|
bool repl_need_utf8_upgrade = FALSE; |
| 3004 |
|
|
bool repl_is_utf8 = FALSE; |
| 3005 |
|
|
|
| 3006 |
|
|
SvTAINTED_off(TARG); /* decontaminate */ |
| 3007 |
|
|
SvUTF8_off(TARG); /* decontaminate */ |
| 3008 |
|
|
if (num_args > 2) { |
| 3009 |
|
|
if (num_args > 3) { |
| 3010 |
|
|
repl_sv = POPs; |
| 3011 |
|
|
repl = SvPV(repl_sv, repl_len); |
| 3012 |
|
|
repl_is_utf8 = DO_UTF8(repl_sv) && SvCUR(repl_sv); |
| 3013 |
|
|
} |
| 3014 |
|
|
len = POPi; |
| 3015 |
|
|
} |
| 3016 |
|
|
pos = POPi; |
| 3017 |
|
|
sv = POPs; |
| 3018 |
|
|
PUTBACK; |
| 3019 |
|
|
if (repl_sv) { |
| 3020 |
|
|
if (repl_is_utf8) { |
| 3021 |
|
|
if (!DO_UTF8(sv)) |
| 3022 |
|
|
sv_utf8_upgrade(sv); |
| 3023 |
|
|
} |
| 3024 |
|
|
else if (DO_UTF8(sv)) |
| 3025 |
|
|
repl_need_utf8_upgrade = TRUE; |
| 3026 |
|
|
} |
| 3027 |
|
|
tmps = SvPV(sv, curlen); |
| 3028 |
|
|
if (DO_UTF8(sv)) { |
| 3029 |
|
|
utf8_curlen = sv_len_utf8(sv); |
| 3030 |
|
|
if (utf8_curlen == curlen) |
| 3031 |
|
|
utf8_curlen = 0; |
| 3032 |
|
|
else |
| 3033 |
|
|
curlen = utf8_curlen; |
| 3034 |
|
|
} |
| 3035 |
|
|
else |
| 3036 |
|
|
utf8_curlen = 0; |
| 3037 |
|
|
|
| 3038 |
|
|
if (pos >= arybase) { |
| 3039 |
|
|
pos -= arybase; |
| 3040 |
|
|
rem = curlen-pos; |
| 3041 |
|
|
fail = rem; |
| 3042 |
|
|
if (num_args > 2) { |
| 3043 |
|
|
if (len < 0) { |
| 3044 |
|
|
rem += len; |
| 3045 |
|
|
if (rem < 0) |
| 3046 |
|
|
rem = 0; |
| 3047 |
|
|
} |
| 3048 |
|
|
else if (rem > len) |
| 3049 |
|
|
rem = len; |
| 3050 |
|
|
} |
| 3051 |
|
|
} |
| 3052 |
|
|
else { |
| 3053 |
|
|
pos += curlen; |
| 3054 |
|
|
if (num_args < 3) |
| 3055 |
|
|
rem = curlen; |
| 3056 |
|
|
else if (len >= 0) { |
| 3057 |
|
|
rem = pos+len; |
| 3058 |
|
|
if (rem > (I32)curlen) |
| 3059 |
|
|
rem = curlen; |
| 3060 |
|
|
} |
| 3061 |
|
|
else { |
| 3062 |
|
|
rem = curlen+len; |
| 3063 |
|
|
if (rem < pos) |
| 3064 |
|
|
rem = pos; |
| 3065 |
|
|
} |
| 3066 |
|
|
if (pos < 0) |
| 3067 |
|
|
pos = 0; |
| 3068 |
|
|
fail = rem; |
| 3069 |
|
|
rem -= pos; |
| 3070 |
|
|
} |
| 3071 |
|
|
if (fail < 0) { |
| 3072 |
|
|
if (lvalue || repl) |
| 3073 |
|
|
Perl_croak(aTHX_ "substr outside of string"); |
| 3074 |
|
|
if (ckWARN(WARN_SUBSTR)) |
| 3075 |
|
|
Perl_warner(aTHX_ packWARN(WARN_SUBSTR), "substr outside of string"); |
| 3076 |
|
|
RETPUSHUNDEF; |
| 3077 |
|
|
} |
| 3078 |
|
|
else { |
| 3079 |
|
|
I32 upos = pos; |
| 3080 |
|
|
I32 urem = rem; |
| 3081 |
|
|
if (utf8_curlen) |
| 3082 |
|
|
sv_pos_u2b(sv, &pos, &rem); |
| 3083 |
|
|
tmps += pos; |
| 3084 |
|
|
/* we either return a PV or an LV. If the TARG hasn't been used |
| 3085 |
|
|
* before, or is of that type, reuse it; otherwise use a mortal |
| 3086 |
|
|
* instead. Note that LVs can have an extended lifetime, so also |
| 3087 |
|
|
* dont reuse if refcount > 1 (bug #20933) */ |
| 3088 |
|
|
if (SvTYPE(TARG) > SVt_NULL) { |
| 3089 |
|
|
if ( (SvTYPE(TARG) == SVt_PVLV) |
| 3090 |
|
|
? (!lvalue || SvREFCNT(TARG) > 1) |
| 3091 |
|
|
: lvalue) |
| 3092 |
|
|
{ |
| 3093 |
|
|
TARG = sv_newmortal(); |
| 3094 |
|
|
} |
| 3095 |
|
|
} |
| 3096 |
|
|
|
| 3097 |
|
|
sv_setpvn(TARG, tmps, rem); |
| 3098 |
|
|
#ifdef USE_LOCALE_COLLATE |
| 3099 |
|
|
sv_unmagic(TARG, PERL_MAGIC_collxfrm); |
| 3100 |
|
|
#endif |
| 3101 |
|
|
if (utf8_curlen) |
| 3102 |
|
|
SvUTF8_on(TARG); |
| 3103 |
|
|
if (repl) { |
| 3104 |
|
|
SV* repl_sv_copy = NULL; |
| 3105 |
|
|
|
| 3106 |
|
|
if (repl_need_utf8_upgrade) { |
| 3107 |
|
|
repl_sv_copy = newSVsv(repl_sv); |
| 3108 |
|
|
sv_utf8_upgrade(repl_sv_copy); |
| 3109 |
|
|
repl = SvPV(repl_sv_copy, repl_len); |
| 3110 |
|
|
repl_is_utf8 = DO_UTF8(repl_sv_copy) && SvCUR(sv); |
| 3111 |
|
|
} |
| 3112 |
|
|
sv_insert(sv, pos, rem, repl, repl_len); |
| 3113 |
|
|
if (repl_is_utf8) |
| 3114 |
|
|
SvUTF8_on(sv); |
| 3115 |
|
|
if (repl_sv_copy) |
| 3116 |
|
|
SvREFCNT_dec(repl_sv_copy); |
| 3117 |
|
|
} |
| 3118 |
|
|
else if (lvalue) { /* it's an lvalue! */ |
| 3119 |
|
|
if (!SvGMAGICAL(sv)) { |
| 3120 |
|
|
if (SvROK(sv)) { |
| 3121 |
|
|
STRLEN n_a; |
| 3122 |
|
|
SvPV_force(sv,n_a); |
| 3123 |
|
|
if (ckWARN(WARN_SUBSTR)) |
| 3124 |
|
|
Perl_warner(aTHX_ packWARN(WARN_SUBSTR), |
| 3125 |
|
|
"Attempt to use reference as lvalue in substr"); |
| 3126 |
|
|
} |
| 3127 |
|
|
if (SvOK(sv)) /* is it defined ? */ |
| 3128 |
|
|
(void)SvPOK_only_UTF8(sv); |
| 3129 |
|
|
else |
| 3130 |
|
|
sv_setpvn(sv,"",0); /* avoid lexical reincarnation */ |
| 3131 |
|
|
} |
| 3132 |
|
|
|
| 3133 |
|
|
if (SvTYPE(TARG) < SVt_PVLV) { |
| 3134 |
|
|
sv_upgrade(TARG, SVt_PVLV); |
| 3135 |
|
|
sv_magic(TARG, Nullsv, PERL_MAGIC_substr, Nullch, 0); |
| 3136 |
|
|
} |
| 3137 |
|
|
else |
| 3138 |
|
|
SvOK_off(TARG); |
| 3139 |
|
|
|
| 3140 |
|
|
LvTYPE(TARG) = 'x'; |
| 3141 |
|
|
if (LvTARG(TARG) != sv) { |
| 3142 |
|
|
if (LvTARG(TARG)) |
| 3143 |
|
|
SvREFCNT_dec(LvTARG(TARG)); |
| 3144 |
|
|
LvTARG(TARG) = SvREFCNT_inc(sv); |
| 3145 |
|
|
} |
| 3146 |
|
|
LvTARGOFF(TARG) = upos; |
| 3147 |
|
|
LvTARGLEN(TARG) = urem; |
| 3148 |
|
|
} |
| 3149 |
|
|
} |
| 3150 |
|
|
SPAGAIN; |
| 3151 |
|
|
PUSHs(TARG); /* avoid SvSETMAGIC here */ |
| 3152 |
|
|
RETURN; |
| 3153 |
|
|
} |
| 3154 |
|
|
|
| 3155 |
|
|
PP(pp_vec) |
| 3156 |
|
|
{ |
| 3157 |
|
|
dSP; dTARGET; |
| 3158 |
|
|
register IV size = POPi; |
| 3159 |
|
|
register IV offset = POPi; |
| 3160 |
|
|
register SV *src = POPs; |
| 3161 |
|
|
I32 lvalue = PL_op->op_flags & OPf_MOD || LVRET; |
| 3162 |
|
|
|
| 3163 |
|
|
SvTAINTED_off(TARG); /* decontaminate */ |
| 3164 |
|
|
if (lvalue) { /* it's an lvalue! */ |
| 3165 |
|
|
if (SvREFCNT(TARG) > 1) /* don't share the TARG (#20933) */ |
| 3166 |
|
|
TARG = sv_newmortal(); |
| 3167 |
|
|
if (SvTYPE(TARG) < SVt_PVLV) { |
| 3168 |
|
|
sv_upgrade(TARG, SVt_PVLV); |
| 3169 |
|
|
sv_magic(TARG, Nullsv, PERL_MAGIC_vec, Nullch, 0); |
| 3170 |
|
|
} |
| 3171 |
|
|
LvTYPE(TARG) = 'v'; |
| 3172 |
|
|
if (LvTARG(TARG) != src) { |
| 3173 |
|
|
if (LvTARG(TARG)) |
| 3174 |
|
|
SvREFCNT_dec(LvTARG(TARG)); |
| 3175 |
|
|
LvTARG(TARG) = SvREFCNT_inc(src); |
| 3176 |
|
|
} |
| 3177 |
|
|
LvTARGOFF(TARG) = offset; |
| 3178 |
|
|
LvTARGLEN(TARG) = size; |
| 3179 |
|
|
} |
| 3180 |
|
|
|
| 3181 |
|
|
sv_setuv(TARG, do_vecget(src, offset, size)); |
| 3182 |
|
|
PUSHs(TARG); |
| 3183 |
|
|
RETURN; |
| 3184 |
|
|
} |
| 3185 |
|
|
|
| 3186 |
|
|
PP(pp_index) |
| 3187 |
|
|
{ |
| 3188 |
|
|
dSP; dTARGET; |
| 3189 |
|
|
SV *big; |
| 3190 |
|
|
SV *little; |
| 3191 |
|
|
SV *temp = Nullsv; |
| 3192 |
|
|
I32 offset; |
| 3193 |
|
|
I32 retval; |
| 3194 |
|
|
char *tmps; |
| 3195 |
|
|
char *tmps2; |
| 3196 |
|
|
STRLEN biglen; |
| 3197 |
|
|
I32 arybase = PL_curcop->cop_arybase; |
| 3198 |
|
|
int big_utf8; |
| 3199 |
|
|
int little_utf8; |
| 3200 |
|
|
|
| 3201 |
|
|
if (MAXARG < 3) |
| 3202 |
|
|
offset = 0; |
| 3203 |
|
|
else |
| 3204 |
|
|
offset = POPi - arybase; |
| 3205 |
|
|
little = POPs; |
| 3206 |
|
|
big = POPs; |
| 3207 |
|
|
big_utf8 = DO_UTF8(big); |
| 3208 |
|
|
little_utf8 = DO_UTF8(little); |
| 3209 |
|
|
if (big_utf8 ^ little_utf8) { |
| 3210 |
|
|
/* One needs to be upgraded. */ |
| 3211 |
|
|
SV *bytes = little_utf8 ? big : little; |
| 3212 |
|
|
STRLEN len; |
| 3213 |
|
|
char *p = SvPV(bytes, len); |
| 3214 |
|
|
|
| 3215 |
|
|
temp = newSVpvn(p, len); |
| 3216 |
|
|
|
| 3217 |
|
|
if (PL_encoding) { |
| 3218 |
|
|
sv_recode_to_utf8(temp, PL_encoding); |
| 3219 |
|
|
} else { |
| 3220 |
|
|
sv_utf8_upgrade(temp); |
| 3221 |
|
|
} |
| 3222 |
|
|
if (little_utf8) { |
| 3223 |
|
|
big = temp; |
| 3224 |
|
|
big_utf8 = TRUE; |
| 3225 |
|
|
} else { |
| 3226 |
|
|
little = temp; |
| 3227 |
|
|
} |
| 3228 |
|
|
} |
| 3229 |
|
|
if (big_utf8 && offset > 0) |
| 3230 |
|
|
sv_pos_u2b(big, &offset, 0); |
| 3231 |
|
|
tmps = SvPV(big, biglen); |
| 3232 |
|
|
if (offset < 0) |
| 3233 |
|
|
offset = 0; |
| 3234 |
|
|
else if (offset > (I32)biglen) |
| 3235 |
|
|
offset = biglen; |
| 3236 |
|
|
if (!(tmps2 = fbm_instr((unsigned char*)tmps + offset, |
| 3237 |
|
|
(unsigned char*)tmps + biglen, little, 0))) |
| 3238 |
|
|
retval = -1; |
| 3239 |
|
|
else |
| 3240 |
|
|
retval = tmps2 - tmps; |
| 3241 |
|
|
if (retval > 0 && big_utf8) |
| 3242 |
|
|
sv_pos_b2u(big, &retval); |
| 3243 |
|
|
if (temp) |
| 3244 |
|
|
SvREFCNT_dec(temp); |
| 3245 |
|
|
PUSHi(retval + arybase); |
| 3246 |
|
|
RETURN; |
| 3247 |
|
|
} |
| 3248 |
|
|
|
| 3249 |
|
|
PP(pp_rindex) |
| 3250 |
|
|
{ |
| 3251 |
|
|
dSP; dTARGET; |
| 3252 |
|
|
SV *big; |
| 3253 |
|
|
SV *little; |
| 3254 |
|
|
SV *temp = Nullsv; |
| 3255 |
|
|
STRLEN blen; |
| 3256 |
|
|
STRLEN llen; |
| 3257 |
|
|
I32 offset; |
| 3258 |
|
|
I32 retval; |
| 3259 |
|
|
char *tmps; |
| 3260 |
|
|
char *tmps2; |
| 3261 |
|
|
I32 arybase = PL_curcop->cop_arybase; |
| 3262 |
|
|
int big_utf8; |
| 3263 |
|
|
int little_utf8; |
| 3264 |
|
|
|
| 3265 |
|
|
if (MAXARG >= 3) |
| 3266 |
|
|
offset = POPi; |
| 3267 |
|
|
little = POPs; |
| 3268 |
|
|
big = POPs; |
| 3269 |
|
|
big_utf8 = DO_UTF8(big); |
| 3270 |
|
|
little_utf8 = DO_UTF8(little); |
| 3271 |
|
|
if (big_utf8 ^ little_utf8) { |
| 3272 |
|
|
/* One needs to be upgraded. */ |
| 3273 |
|
|
SV *bytes = little_utf8 ? big : little; |
| 3274 |
|
|
STRLEN len; |
| 3275 |
|
|
char *p = SvPV(bytes, len); |
| 3276 |
|
|
|
| 3277 |
|
|
temp = newSVpvn(p, len); |
| 3278 |
|
|
|
| 3279 |
|
|
if (PL_encoding) { |
| 3280 |
|
|
sv_recode_to_utf8(temp, PL_encoding); |
| 3281 |
|
|
} else { |
| 3282 |
|
|
sv_utf8_upgrade(temp); |
| 3283 |
|
|
} |
| 3284 |
|
|
if (little_utf8) { |
| 3285 |
|
|
big = temp; |
| 3286 |
|
|
big_utf8 = TRUE; |
| 3287 |
|
|
} else { |
| 3288 |
|
|
little = temp; |
| 3289 |
|
|
} |
| 3290 |
|
|
} |
| 3291 |
|
|
tmps2 = SvPV(little, llen); |
| 3292 |
|
|
tmps = SvPV(big, blen); |
| 3293 |
|
|
|
| 3294 |
|
|
if (MAXARG < 3) |
| 3295 |
|
|
offset = blen; |
| 3296 |
|
|
else { |
| 3297 |
|
|
if (offset > 0 && big_utf8) |
| 3298 |
|
|
sv_pos_u2b(big, &offset, 0); |
| 3299 |
|
|
offset = offset - arybase + llen; |
| 3300 |
|
|
} |
| 3301 |
|
|
if (offset < 0) |
| 3302 |
|
|
offset = 0; |
| 3303 |
|
|
else if (offset > (I32)blen) |
| 3304 |
|
|
offset = blen; |
| 3305 |
|
|
if (!(tmps2 = rninstr(tmps, tmps + offset, |
| 3306 |
|
|
tmps2, tmps2 + llen))) |
| 3307 |
|
|
retval = -1; |
| 3308 |
|
|
else |
| 3309 |
|
|
retval = tmps2 - tmps; |
| 3310 |
|
|
if (retval > 0 && big_utf8) |
| 3311 |
|
|
sv_pos_b2u(big, &retval); |
| 3312 |
|
|
if (temp) |
| 3313 |
|
|
SvREFCNT_dec(temp); |
| 3314 |
|
|
PUSHi(retval + arybase); |
| 3315 |
|
|
RETURN; |
| 3316 |
|
|
} |
| 3317 |
|
|
|
| 3318 |
|
|
PP(pp_sprintf) |
| 3319 |
|
|
{ |
| 3320 |
|
|
dSP; dMARK; dORIGMARK; dTARGET; |
| 3321 |
|
|
do_sprintf(TARG, SP-MARK, MARK+1); |
| 3322 |
|
|
TAINT_IF(SvTAINTED(TARG)); |
| 3323 |
|
|
if (DO_UTF8(*(MARK+1))) |
| 3324 |
|
|
SvUTF8_on(TARG); |
| 3325 |
|
|
SP = ORIGMARK; |
| 3326 |
|
|
PUSHTARG; |
| 3327 |
|
|
RETURN; |
| 3328 |
|
|
} |
| 3329 |
|
|
|
| 3330 |
|
|
PP(pp_ord) |
| 3331 |
|
|
{ |
| 3332 |
|
|
dSP; dTARGET; |
| 3333 |
|
|
SV *argsv = POPs; |
| 3334 |
|
|
STRLEN len; |
| 3335 |
|
|
U8 *s = (U8*)SvPVx(argsv, len); |
| 3336 |
|
|
SV *tmpsv; |
| 3337 |
|
|
|
| 3338 |
|
|
if (PL_encoding && SvPOK(argsv) && !DO_UTF8(argsv)) { |
| 3339 |
|
|
tmpsv = sv_2mortal(newSVsv(argsv)); |
| 3340 |
|
|
s = (U8*)sv_recode_to_utf8(tmpsv, PL_encoding); |
| 3341 |
|
|
argsv = tmpsv; |
| 3342 |
|
|
} |
| 3343 |
|
|
|
| 3344 |
|
|
XPUSHu(DO_UTF8(argsv) ? |
| 3345 |
|
|
utf8n_to_uvchr(s, UTF8_MAXBYTES, 0, UTF8_ALLOW_ANYUV) : |
| 3346 |
|
|
(*s & 0xff)); |
| 3347 |
|
|
|
| 3348 |
|
|
RETURN; |
| 3349 |
|
|
} |
| 3350 |
|
|
|
| 3351 |
|
|
PP(pp_chr) |
| 3352 |
|
|
{ |
| 3353 |
|
|
dSP; dTARGET; |
| 3354 |
|
|
char *tmps; |
| 3355 |
|
|
UV value = POPu; |
| 3356 |
|
|
|
| 3357 |
|
|
(void)SvUPGRADE(TARG,SVt_PV); |
| 3358 |
|
|
|
| 3359 |
|
|
if (value > 255 && !IN_BYTES) { |
| 3360 |
|
|
SvGROW(TARG, (STRLEN)UNISKIP(value)+1); |
| 3361 |
|
|
tmps = (char*)uvchr_to_utf8_flags((U8*)SvPVX(TARG), value, 0); |
| 3362 |
|
|
SvCUR_set(TARG, tmps - SvPVX(TARG)); |
| 3363 |
|
|
*tmps = '\0'; |
| 3364 |
|
|
(void)SvPOK_only(TARG); |
| 3365 |
|
|
SvUTF8_on(TARG); |
| 3366 |
|
|
XPUSHs(TARG); |
| 3367 |
|
|
RETURN; |
| 3368 |
|
|
} |
| 3369 |
|
|
|
| 3370 |
|
|
SvGROW(TARG,2); |
| 3371 |
|
|
SvCUR_set(TARG, 1); |
| 3372 |
|
|
tmps = SvPVX(TARG); |
| 3373 |
|
|
*tmps++ = (char)value; |
| 3374 |
|
|
*tmps = '\0'; |
| 3375 |
|
|
(void)SvPOK_only(TARG); |
| 3376 |
|
|
if (PL_encoding && !IN_BYTES) { |
| 3377 |
|
|
sv_recode_to_utf8(TARG, PL_encoding); |
| 3378 |
|
|
tmps = SvPVX(TARG); |
| 3379 |
|
|
if (SvCUR(TARG) == 0 || !is_utf8_string((U8*)tmps, SvCUR(TARG)) || |
| 3380 |
|
|
memEQ(tmps, "\xef\xbf\xbd\0", 4)) { |
| 3381 |
|
|
SvGROW(TARG, 3); |
| 3382 |
|
|
tmps = SvPVX(TARG); |
| 3383 |
|
|
SvCUR_set(TARG, 2); |
| 3384 |
|
|
*tmps++ = (U8)UTF8_EIGHT_BIT_HI(value); |
| 3385 |
|
|
*tmps++ = (U8)UTF8_EIGHT_BIT_LO(value); |
| 3386 |
|
|
*tmps = '\0'; |
| 3387 |
|
|
SvUTF8_on(TARG); |
| 3388 |
|
|
} |
| 3389 |
|
|
} |
| 3390 |
|
|
XPUSHs(TARG); |
| 3391 |
|
|
RETURN; |
| 3392 |
|
|
} |
| 3393 |
|
|
|
| 3394 |
|
|
PP(pp_crypt) |
| 3395 |
|
|
{ |
| 3396 |
|
|
dSP; dTARGET; |
| 3397 |
|
|
#ifdef HAS_CRYPT |
| 3398 |
|
|
dPOPTOPssrl; |
| 3399 |
|
|
STRLEN n_a; |
| 3400 |
|
|
STRLEN len; |
| 3401 |
|
|
char *tmps = SvPV(left, len); |
| 3402 |
|
|
|
| 3403 |
|
|
if (DO_UTF8(left)) { |
| 3404 |
|
|
/* If Unicode, try to downgrade. |
| 3405 |
|
|
* If not possible, croak. |
| 3406 |
|
|
* Yes, we made this up. */ |
| 3407 |
|
|
SV* tsv = sv_2mortal(newSVsv(left)); |
| 3408 |
|
|
|
| 3409 |
|
|
SvUTF8_on(tsv); |
| 3410 |
|
|
sv_utf8_downgrade(tsv, FALSE); |
| 3411 |
|
|
tmps = SvPVX(tsv); |
| 3412 |
|
|
} |
| 3413 |
|
|
# ifdef USE_ITHREADS |
| 3414 |
|
|
# ifdef HAS_CRYPT_R |
| 3415 |
|
|
if (!PL_reentrant_buffer->_crypt_struct_buffer) { |
| 3416 |
|
|
/* This should be threadsafe because in ithreads there is only |
| 3417 |
|
|
* one thread per interpreter. If this would not be true, |
| 3418 |
|
|
* we would need a mutex to protect this malloc. */ |
| 3419 |
|
|
PL_reentrant_buffer->_crypt_struct_buffer = |
| 3420 |
|
|
(struct crypt_data *)safemalloc(sizeof(struct crypt_data)); |
| 3421 |
|
|
#if defined(__GLIBC__) || defined(__EMX__) |
| 3422 |
|
|
if (PL_reentrant_buffer->_crypt_struct_buffer) { |
| 3423 |
|
|
PL_reentrant_buffer->_crypt_struct_buffer->initialized = 0; |
| 3424 |
|
|
/* work around glibc-2.2.5 bug */ |
| 3425 |
|
|
PL_reentrant_buffer->_crypt_struct_buffer->current_saltbits = 0; |
| 3426 |
|
|
} |
| 3427 |
|
|
#endif |
| 3428 |
|
|
} |
| 3429 |
|
|
# endif /* HAS_CRYPT_R */ |
| 3430 |
|
|
# endif /* USE_ITHREADS */ |
| 3431 |
|
|
# ifdef FCRYPT |
| 3432 |
|
|
sv_setpv(TARG, fcrypt(tmps, SvPV(right, n_a))); |
| 3433 |
|
|
# else |
| 3434 |
|
|
sv_setpv(TARG, PerlProc_crypt(tmps, SvPV(right, n_a))); |
| 3435 |
|
|
# endif |
| 3436 |
|
|
SETs(TARG); |
| 3437 |
|
|
RETURN; |
| 3438 |
|
|
#else |
| 3439 |
|
|
DIE(aTHX_ |
| 3440 |
|
|
"The crypt() function is unimplemented due to excessive paranoia."); |
| 3441 |
|
|
#endif |
| 3442 |
|
|
} |
| 3443 |
|
|
|
| 3444 |
|
|
PP(pp_ucfirst) |
| 3445 |
|
|
{ |
| 3446 |
|
|
dSP; |
| 3447 |
|
|
SV *sv = TOPs; |
| 3448 |
|
|
register U8 *s; |
| 3449 |
|
|
STRLEN slen; |
| 3450 |
|
|
|
| 3451 |
|
|
SvGETMAGIC(sv); |
| 3452 |
|
|
if (DO_UTF8(sv) && |
| 3453 |
|
|
(s = (U8*)SvPV_nomg(sv, slen)) && slen && |
| 3454 |
|
|
UTF8_IS_START(*s)) { |
| 3455 |
|
|
U8 tmpbuf[UTF8_MAXBYTES_CASE+1]; |
| 3456 |
|
|
STRLEN ulen; |
| 3457 |
|
|
STRLEN tculen; |
| 3458 |
|
|
|
| 3459 |
|
|
utf8_to_uvchr(s, &ulen); |
| 3460 |
|
|
toTITLE_utf8(s, tmpbuf, &tculen); |
| 3461 |
|
|
utf8_to_uvchr(tmpbuf, 0); |
| 3462 |
|
|
|
| 3463 |
|
|
if (!SvPADTMP(sv) || SvREADONLY(sv)) { |
| 3464 |
|
|
dTARGET; |
| 3465 |
|
|
/* slen is the byte length of the whole SV. |
| 3466 |
|
|
* ulen is the byte length of the original Unicode character |
| 3467 |
|
|
* stored as UTF-8 at s. |
| 3468 |
|
|
* tculen is the byte length of the freshly titlecased |
| 3469 |
|
|
* Unicode character stored as UTF-8 at tmpbuf. |
| 3470 |
|
|
* We first set the result to be the titlecased character, |
| 3471 |
|
|
* and then append the rest of the SV data. */ |
| 3472 |
|
|
sv_setpvn(TARG, (char*)tmpbuf, tculen); |
| 3473 |
|
|
if (slen > ulen) |
| 3474 |
|
|
sv_catpvn(TARG, (char*)(s + ulen), slen - ulen); |
| 3475 |
|
|
SvUTF8_on(TARG); |
| 3476 |
|
|
SETs(TARG); |
| 3477 |
|
|
} |
| 3478 |
|
|
else { |
| 3479 |
|
|
s = (U8*)SvPV_force_nomg(sv, slen); |
| 3480 |
|
|
Copy(tmpbuf, s, tculen, U8); |
| 3481 |
|
|
} |
| 3482 |
|
|
} |
| 3483 |
|
|
else { |
| 3484 |
|
|
if (!SvPADTMP(sv) || SvREADONLY(sv)) { |
| 3485 |
|
|
dTARGET; |
| 3486 |
|
|
SvUTF8_off(TARG); /* decontaminate */ |
| 3487 |
|
|
sv_setsv_nomg(TARG, sv); |
| 3488 |
|
|
sv = TARG; |
| 3489 |
|
|
SETs(sv); |
| 3490 |
|
|
} |
| 3491 |
|
|
s = (U8*)SvPV_force_nomg(sv, slen); |
| 3492 |
|
|
if (*s) { |
| 3493 |
|
|
if (IN_LOCALE_RUNTIME) { |
| 3494 |
|
|
TAINT; |
| 3495 |
|
|
SvTAINTED_on(sv); |
| 3496 |
|
|
*s = toUPPER_LC(*s); |
| 3497 |
|
|
} |
| 3498 |
|
|
else |
| 3499 |
|
|
*s = toUPPER(*s); |
| 3500 |
|
|
} |
| 3501 |
|
|
} |
| 3502 |
|
|
SvSETMAGIC(sv); |
| 3503 |
|
|
RETURN; |
| 3504 |
|
|
} |
| 3505 |
|
|
|
| 3506 |
|
|
PP(pp_lcfirst) |
| 3507 |
|
|
{ |
| 3508 |
|
|
dSP; |
| 3509 |
|
|
SV *sv = TOPs; |
| 3510 |
|
|
register U8 *s; |
| 3511 |
|
|
STRLEN slen; |
| 3512 |
|
|
|
| 3513 |
|
|
SvGETMAGIC(sv); |
| 3514 |
|
|
if (DO_UTF8(sv) && |
| 3515 |
|
|
(s = (U8*)SvPV_nomg(sv, slen)) && slen && |
| 3516 |
|
|
UTF8_IS_START(*s)) { |
| 3517 |
|
|
STRLEN ulen; |
| 3518 |
|
|
U8 tmpbuf[UTF8_MAXBYTES_CASE+1]; |
| 3519 |
|
|
U8 *tend; |
| 3520 |
|
|
UV uv; |
| 3521 |
|
|
|
| 3522 |
|
|
toLOWER_utf8(s, tmpbuf, &ulen); |
| 3523 |
|
|
uv = utf8_to_uvchr(tmpbuf, 0); |
| 3524 |
|
|
tend = uvchr_to_utf8(tmpbuf, uv); |
| 3525 |
|
|
|
| 3526 |
|
|
if (!SvPADTMP(sv) || (STRLEN)(tend - tmpbuf) != ulen || SvREADONLY(sv)) { |
| 3527 |
|
|
dTARGET; |
| 3528 |
|
|
sv_setpvn(TARG, (char*)tmpbuf, tend - tmpbuf); |
| 3529 |
|
|
if (slen > ulen) |
| 3530 |
|
|
sv_catpvn(TARG, (char*)(s + ulen), slen - ulen); |
| 3531 |
|
|
SvUTF8_on(TARG); |
| 3532 |
|
|
SETs(TARG); |
| 3533 |
|
|
} |
| 3534 |
|
|
else { |
| 3535 |
|
|
s = (U8*)SvPV_force_nomg(sv, slen); |
| 3536 |
|
|
Copy(tmpbuf, s, ulen, U8); |
| 3537 |
|
|
} |
| 3538 |
|
|
} |
| 3539 |
|
|
else { |
| 3540 |
|
|
if (!SvPADTMP(sv) || SvREADONLY(sv)) { |
| 3541 |
|
|
dTARGET; |
| 3542 |
|
|
SvUTF8_off(TARG); /* decontaminate */ |
| 3543 |
|
|
sv_setsv_nomg(TARG, sv); |
| 3544 |
|
|
sv = TARG; |
| 3545 |
|
|
SETs(sv); |
| 3546 |
|
|
} |
| 3547 |
|
|
s = (U8*)SvPV_force_nomg(sv, slen); |
| 3548 |
|
|
if (*s) { |
| 3549 |
|
|
if (IN_LOCALE_RUNTIME) { |
| 3550 |
|
|
TAINT; |
| 3551 |
|
|
SvTAINTED_on(sv); |
| 3552 |
|
|
*s = toLOWER_LC(*s); |
| 3553 |
|
|
} |
| 3554 |
|
|
else |
| 3555 |
|
|
*s = toLOWER(*s); |
| 3556 |
|
|
} |
| 3557 |
|
|
} |
| 3558 |
|
|
SvSETMAGIC(sv); |
| 3559 |
|
|
RETURN; |
| 3560 |
|
|
} |
| 3561 |
|
|
|
| 3562 |
|
|
PP(pp_uc) |
| 3563 |
|
|
{ |
| 3564 |
|
|
dSP; |
| 3565 |
|
|
SV *sv = TOPs; |
| 3566 |
|
|
register U8 *s; |
| 3567 |
|
|
STRLEN len; |
| 3568 |
|
|
|
| 3569 |
|
|
SvGETMAGIC(sv); |
| 3570 |
|
|
if (DO_UTF8(sv)) { |
| 3571 |
|
|
dTARGET; |
| 3572 |
|
|
STRLEN ulen; |
| 3573 |
|
|
register U8 *d; |
| 3574 |
|
|
U8 *send; |
| 3575 |
|
|
U8 tmpbuf[UTF8_MAXBYTES+1]; |
| 3576 |
|
|
|
| 3577 |
|
|
s = (U8*)SvPV_nomg(sv,len); |
| 3578 |
|
|
if (!len) { |
| 3579 |
|
|
SvUTF8_off(TARG); /* decontaminate */ |
| 3580 |
|
|
sv_setpvn(TARG, "", 0); |
| 3581 |
|
|
SETs(TARG); |
| 3582 |
|
|
} |
| 3583 |
|
|
else { |
| 3584 |
|
|
STRLEN min = len + 1; |
| 3585 |
|
|
|
| 3586 |
|
|
(void)SvUPGRADE(TARG, SVt_PV); |
| 3587 |
|
|
SvGROW(TARG, min); |
| 3588 |
|
|
(void)SvPOK_only(TARG); |
| 3589 |
|
|
d = (U8*)SvPVX(TARG); |
| 3590 |
|
|
send = s + len; |
| 3591 |
|
|
while (s < send) { |
| 3592 |
|
|
STRLEN u = UTF8SKIP(s); |
| 3593 |
|
|
|
| 3594 |
|
|
toUPPER_utf8(s, tmpbuf, &ulen); |
| 3595 |
|
|
if (ulen > u && (SvLEN(TARG) < (min += ulen - u))) { |
| 3596 |
|
|
/* If the eventually required minimum size outgrows |
| 3597 |
|
|
* the available space, we need to grow. */ |
| 3598 |
|
|
UV o = d - (U8*)SvPVX(TARG); |
| 3599 |
|
|
|
| 3600 |
|
|
/* If someone uppercases one million U+03B0s we |
| 3601 |
|
|
* SvGROW() one million times. Or we could try |
| 3602 |
|
|
* guessing how much to allocate without allocating |
| 3603 |
|
|
* too much. Such is life. */ |
| 3604 |
|
|
SvGROW(TARG, min); |
| 3605 |
|
|
d = (U8*)SvPVX(TARG) + o; |
| 3606 |
|
|
} |
| 3607 |
|
|
Copy(tmpbuf, d, ulen, U8); |
| 3608 |
|
|
d += ulen; |
| 3609 |
|
|
s += u; |
| 3610 |
|
|
} |
| 3611 |
|
|
*d = '\0'; |
| 3612 |
|
|
SvUTF8_on(TARG); |
| 3613 |
|
|
SvCUR_set(TARG, d - (U8*)SvPVX(TARG)); |
| 3614 |
|
|
SETs(TARG); |
| 3615 |
|
|
} |
| 3616 |
|
|
} |
| 3617 |
|
|
else { |
| 3618 |
|
|
if (!SvPADTMP(sv) || SvREADONLY(sv)) { |
| 3619 |
|
|
dTARGET; |
| 3620 |
|
|
SvUTF8_off(TARG); /* decontaminate */ |
| 3621 |
|
|
sv_setsv_nomg(TARG, sv); |
| 3622 |
|
|
sv = TARG; |
| 3623 |
|
|
SETs(sv); |
| 3624 |
|
|
} |
| 3625 |
|
|
s = (U8*)SvPV_force_nomg(sv, len); |
| 3626 |
|
|
if (len) { |
| 3627 |
|
|
register U8 *send = s + len; |
| 3628 |
|
|
|
| 3629 |
|
|
if (IN_LOCALE_RUNTIME) { |
| 3630 |
|
|
TAINT; |
| 3631 |
|
|
SvTAINTED_on(sv); |
| 3632 |
|
|
for (; s < send; s++) |
| 3633 |
|
|
*s = toUPPER_LC(*s); |
| 3634 |
|
|
} |
| 3635 |
|
|
else { |
| 3636 |
|
|
for (; s < send; s++) |
| 3637 |
|
|
*s = toUPPER(*s); |
| 3638 |
|
|
} |
| 3639 |
|
|
} |
| 3640 |
|
|
} |
| 3641 |
|
|
SvSETMAGIC(sv); |
| 3642 |
|
|
RETURN; |
| 3643 |
|
|
} |
| 3644 |
|
|
|
| 3645 |
|
|
PP(pp_lc) |
| 3646 |
|
|
{ |
| 3647 |
|
|
dSP; |
| 3648 |
|
|
SV *sv = TOPs; |
| 3649 |
|
|
register U8 *s; |
| 3650 |
|
|
STRLEN len; |
| 3651 |
|
|
|
| 3652 |
|
|
SvGETMAGIC(sv); |
| 3653 |
|
|
if (DO_UTF8(sv)) { |
| 3654 |
|
|
dTARGET; |
| 3655 |
|
|
STRLEN ulen; |
| 3656 |
|
|
register U8 *d; |
| 3657 |
|
|
U8 *send; |
| 3658 |
|
|
U8 tmpbuf[UTF8_MAXBYTES_CASE+1]; |
| 3659 |
|
|
|
| 3660 |
|
|
s = (U8*)SvPV_nomg(sv,len); |
| 3661 |
|
|
if (!len) { |
| 3662 |
|
|
SvUTF8_off(TARG); /* decontaminate */ |
| 3663 |
|
|
sv_setpvn(TARG, "", 0); |
| 3664 |
|
|
SETs(TARG); |
| 3665 |
|
|
} |
| 3666 |
|
|
else { |
| 3667 |
|
|
STRLEN min = len + 1; |
| 3668 |
|
|
|
| 3669 |
|
|
(void)SvUPGRADE(TARG, SVt_PV); |
| 3670 |
|
|
SvGROW(TARG, min); |
| 3671 |
|
|
(void)SvPOK_only(TARG); |
| 3672 |
|
|
d = (U8*)SvPVX(TARG); |
| 3673 |
|
|
send = s + len; |
| 3674 |
|
|
while (s < send) { |
| 3675 |
|
|
STRLEN u = UTF8SKIP(s); |
| 3676 |
|
|
UV uv = toLOWER_utf8(s, tmpbuf, &ulen); |
| 3677 |
|
|
|
| 3678 |
|
|
#define GREEK_CAPITAL_LETTER_SIGMA 0x03A3 /* Unicode U+03A3 */ |
| 3679 |
|
|
if (uv == GREEK_CAPITAL_LETTER_SIGMA) { |
| 3680 |
|
|
/* |
| 3681 |
|
|
* Now if the sigma is NOT followed by |
| 3682 |
|
|
* /$ignorable_sequence$cased_letter/; |
| 3683 |
|
|
* and it IS preceded by |
| 3684 |
|
|
* /$cased_letter$ignorable_sequence/; |
| 3685 |
|
|
* where $ignorable_sequence is |
| 3686 |
|
|
* [\x{2010}\x{AD}\p{Mn}]* |
| 3687 |
|
|
* and $cased_letter is |
| 3688 |
|
|
* [\p{Ll}\p{Lo}\p{Lt}] |
| 3689 |
|
|
* then it should be mapped to 0x03C2, |
| 3690 |
|
|
* (GREEK SMALL LETTER FINAL SIGMA), |
| 3691 |
|
|
* instead of staying 0x03A3. |
| 3692 |
|
|
* "should be": in other words, |
| 3693 |
|
|
* this is not implemented yet. |
| 3694 |
|
|
* See lib/unicore/SpecialCasing.txt. |
| 3695 |
|
|
*/ |
| 3696 |
|
|
} |
| 3697 |
|
|
if (ulen > u && (SvLEN(TARG) < (min += ulen - u))) { |
| 3698 |
|
|
/* If the eventually required minimum size outgrows |
| 3699 |
|
|
* the available space, we need to grow. */ |
| 3700 |
|
|
UV o = d - (U8*)SvPVX(TARG); |
| 3701 |
|
|
|
| 3702 |
|
|
/* If someone lowercases one million U+0130s we |
| 3703 |
|
|
* SvGROW() one million times. Or we could try |
| 3704 |
|
|
* guessing how much to allocate without allocating. |
| 3705 |
|
|
* too much. Such is life. */ |
| 3706 |
|
|
SvGROW(TARG, min); |
| 3707 |
|
|
d = (U8*)SvPVX(TARG) + o; |
| 3708 |
|
|
} |
| 3709 |
|
|
Copy(tmpbuf, d, ulen, U8); |
| 3710 |
|
|
d += ulen; |
| 3711 |
|
|
s += u; |
| 3712 |
|
|
} |
| 3713 |
|
|
*d = '\0'; |
| 3714 |
|
|
SvUTF8_on(TARG); |
| 3715 |
|
|
SvCUR_set(TARG, d - (U8*)SvPVX(TARG)); |
| 3716 |
|
|
SETs(TARG); |
| 3717 |
|
|
} |
| 3718 |
|
|
} |
| 3719 |
|
|
else { |
| 3720 |
|
|
if (!SvPADTMP(sv) || SvREADONLY(sv)) { |
| 3721 |
|
|
dTARGET; |
| 3722 |
|
|
SvUTF8_off(TARG); /* decontaminate */ |
| 3723 |
|
|
sv_setsv_nomg(TARG, sv); |
| 3724 |
|
|
sv = TARG; |
| 3725 |
|
|
SETs(sv); |
| 3726 |
|
|
} |
| 3727 |
|
|
|
| 3728 |
|
|
s = (U8*)SvPV_force_nomg(sv, len); |
| 3729 |
|
|
if (len) { |
| 3730 |
|
|
register U8 *send = s + len; |
| 3731 |
|
|
|
| 3732 |
|
|
if (IN_LOCALE_RUNTIME) { |
| 3733 |
|
|
TAINT; |
| 3734 |
|
|
SvTAINTED_on(sv); |
| 3735 |
|
|
for (; s < send; s++) |
| 3736 |
|
|
*s = toLOWER_LC(*s); |
| 3737 |
|
|
} |
| 3738 |
|
|
else { |
| 3739 |
|
|
for (; s < send; s++) |
| 3740 |
|
|
*s = toLOWER(*s); |
| 3741 |
|
|
} |
| 3742 |
|
|
} |
| 3743 |
|
|
} |
| 3744 |
|
|
SvSETMAGIC(sv); |
| 3745 |
|
|
RETURN; |
| 3746 |
|
|
} |
| 3747 |
|
|
|
| 3748 |
|
|
PP(pp_quotemeta) |
| 3749 |
|
|
{ |
| 3750 |
|
|
dSP; dTARGET; |
| 3751 |
|
|
SV *sv = TOPs; |
| 3752 |
|
|
STRLEN len; |
| 3753 |
|
|
register char *s = SvPV(sv,len); |
| 3754 |
|
|
register char *d; |
| 3755 |
|
|
|
| 3756 |
|
|
SvUTF8_off(TARG); /* decontaminate */ |
| 3757 |
|
|
if (len) { |
| 3758 |
|
|
(void)SvUPGRADE(TARG, SVt_PV); |
| 3759 |
|
|
SvGROW(TARG, (len * 2) + 1); |
| 3760 |
|
|
d = SvPVX(TARG); |
| 3761 |
|
|
if (DO_UTF8(sv)) { |
| 3762 |
|
|
while (len) { |
| 3763 |
|
|
if (UTF8_IS_CONTINUED(*s)) { |
| 3764 |
|
|
STRLEN ulen = UTF8SKIP(s); |
| 3765 |
|
|
if (ulen > len) |
| 3766 |
|
|
ulen = len; |
| 3767 |
|
|
len -= ulen; |
| 3768 |
|
|
while (ulen--) |
| 3769 |
|
|
*d++ = *s++; |
| 3770 |
|
|
} |
| 3771 |
|
|
else { |
| 3772 |
|
|
if (!isALNUM(*s)) |
| 3773 |
|
|
*d++ = '\\'; |
| 3774 |
|
|
*d++ = *s++; |
| 3775 |
|
|
len--; |
| 3776 |
|
|
} |
| 3777 |
|
|
} |
| 3778 |
|
|
SvUTF8_on(TARG); |
| 3779 |
|
|
} |
| 3780 |
|
|
else { |
| 3781 |
|
|
while (len--) { |
| 3782 |
|
|
if (!isALNUM(*s)) |
| 3783 |
|
|
*d++ = '\\'; |
| 3784 |
|
|
*d++ = *s++; |
| 3785 |
|
|
} |
| 3786 |
|
|
} |
| 3787 |
|
|
*d = '\0'; |
| 3788 |
|
|
SvCUR_set(TARG, d - SvPVX(TARG)); |
| 3789 |
|
|
(void)SvPOK_only_UTF8(TARG); |
| 3790 |
|
|
} |
| 3791 |
|
|
else |
| 3792 |
|
|
sv_setpvn(TARG, s, len); |
| 3793 |
|
|
SETs(TARG); |
| 3794 |
|
|
if (SvSMAGICAL(TARG)) |
| 3795 |
|
|
mg_set(TARG); |
| 3796 |
|
|
RETURN; |
| 3797 |
|
|
} |
| 3798 |
|
|
|
| 3799 |
|
|
/* Arrays. */ |
| 3800 |
|
|
|
| 3801 |
|
|
PP(pp_aslice) |
| 3802 |
|
|
{ |
| 3803 |
|
|
dSP; dMARK; dORIGMARK; |
| 3804 |
|
|
register SV** svp; |
| 3805 |
|
|
register AV* av = (AV*)POPs; |
| 3806 |
|
|
register I32 lval = (PL_op->op_flags & OPf_MOD || LVRET); |
| 3807 |
|
|
I32 arybase = PL_curcop->cop_arybase; |
| 3808 |
|
|
I32 elem; |
| 3809 |
|
|
|
| 3810 |
|
|
if (SvTYPE(av) == SVt_PVAV) { |
| 3811 |
|
|
if (lval && PL_op->op_private & OPpLVAL_INTRO) { |
| 3812 |
|
|
I32 max = -1; |
| 3813 |
|
|
for (svp = MARK + 1; svp <= SP; svp++) { |
| 3814 |
|
|
elem = SvIVx(*svp); |
| 3815 |
|
|
if (elem > max) |
| 3816 |
|
|
max = elem; |
| 3817 |
|
|
} |
| 3818 |
|
|
if (max > AvMAX(av)) |
| 3819 |
|
|
av_extend(av, max); |
| 3820 |
|
|
} |
| 3821 |
|
|
while (++MARK <= SP) { |
| 3822 |
|
|
elem = SvIVx(*MARK); |
| 3823 |
|
|
|
| 3824 |
|
|
if (elem > 0) |
| 3825 |
|
|
elem -= arybase; |
| 3826 |
|
|
svp = av_fetch(av, elem, lval); |
| 3827 |
|
|
if (lval) { |
| 3828 |
|
|
if (!svp || *svp == &PL_sv_undef) |
| 3829 |
|
|
DIE(aTHX_ PL_no_aelem, elem); |
| 3830 |
|
|
if (PL_op->op_private & OPpLVAL_INTRO) |
| 3831 |
|
|
save_aelem(av, elem, svp); |
| 3832 |
|
|
} |
| 3833 |
|
|
*MARK = svp ? *svp : &PL_sv_undef; |
| 3834 |
|
|
} |
| 3835 |
|
|
} |
| 3836 |
|
|
if (GIMME != G_ARRAY) { |
| 3837 |
|
|
MARK = ORIGMARK; |
| 3838 |
|
|
*++MARK = SP > ORIGMARK ? *SP : &PL_sv_undef; |
| 3839 |
|
|
SP = MARK; |
| 3840 |
|
|
} |
| 3841 |
|
|
RETURN; |
| 3842 |
|
|
} |
| 3843 |
|
|
|
| 3844 |
|
|
/* Associative arrays. */ |
| 3845 |
|
|
|
| 3846 |
|
|
PP(pp_each) |
| 3847 |
|
|
{ |
| 3848 |
|
|
dSP; |
| 3849 |
|
|
HV *hash = (HV*)POPs; |
| 3850 |
|
|
HE *entry; |
| 3851 |
|
|
I32 gimme = GIMME_V; |
| 3852 |
|
|
I32 realhv = (SvTYPE(hash) == SVt_PVHV); |
| 3853 |
|
|
|
| 3854 |
|
|
PUTBACK; |
| 3855 |
|
|
/* might clobber stack_sp */ |
| 3856 |
|
|
entry = realhv ? hv_iternext(hash) : avhv_iternext((AV*)hash); |
| 3857 |
|
|
SPAGAIN; |
| 3858 |
|
|
|
| 3859 |
|
|
EXTEND(SP, 2); |
| 3860 |
|
|
if (entry) { |
| 3861 |
|
|
SV* sv = hv_iterkeysv(entry); |
| 3862 |
|
|
PUSHs(sv); /* won't clobber stack_sp */ |
| 3863 |
|
|
if (gimme == G_ARRAY) { |
| 3864 |
|
|
SV *val; |
| 3865 |
|
|
PUTBACK; |
| 3866 |
|
|
/* might clobber stack_sp */ |
| 3867 |
|
|
val = realhv ? |
| 3868 |
|
|
hv_iterval(hash, entry) : avhv_iterval((AV*)hash, entry); |
| 3869 |
|
|
SPAGAIN; |
| 3870 |
|
|
PUSHs(val); |
| 3871 |
|
|
} |
| 3872 |
|
|
} |
| 3873 |
|
|
else if (gimme == G_SCALAR) |
| 3874 |
|
|
RETPUSHUNDEF; |
| 3875 |
|
|
|
| 3876 |
|
|
RETURN; |
| 3877 |
|
|
} |
| 3878 |
|
|
|
| 3879 |
|
|
PP(pp_values) |
| 3880 |
|
|
{ |
| 3881 |
|
|
return do_kv(); |
| 3882 |
|
|
} |
| 3883 |
|
|
|
| 3884 |
|
|
PP(pp_keys) |
| 3885 |
|
|
{ |
| 3886 |
|
|
return do_kv(); |
| 3887 |
|
|
} |
| 3888 |
|
|
|
| 3889 |
|
|
PP(pp_delete) |
| 3890 |
|
|
{ |
| 3891 |
|
|
dSP; |
| 3892 |
|
|
I32 gimme = GIMME_V; |
| 3893 |
|
|
I32 discard = (gimme == G_VOID) ? G_DISCARD : 0; |
| 3894 |
|
|
SV *sv; |
| 3895 |
|
|
HV *hv; |
| 3896 |
|
|
|
| 3897 |
|
|
if (PL_op->op_private & OPpSLICE) { |
| 3898 |
|
|
dMARK; dORIGMARK; |
| 3899 |
|
|
U32 hvtype; |
| 3900 |
|
|
hv = (HV*)POPs; |
| 3901 |
|
|
hvtype = SvTYPE(hv); |
| 3902 |
|
|
if (hvtype == SVt_PVHV) { /* hash element */ |
| 3903 |
|
|
while (++MARK <= SP) { |
| 3904 |
|
|
sv = hv_delete_ent(hv, *MARK, discard, 0); |
| 3905 |
|
|
*MARK = sv ? sv : &PL_sv_undef; |
| 3906 |
|
|
} |
| 3907 |
|
|
} |
| 3908 |
|
|
else if (hvtype == SVt_PVAV) { |
| 3909 |
|
|
if (PL_op->op_flags & OPf_SPECIAL) { /* array element */ |
| 3910 |
|
|
while (++MARK <= SP) { |
| 3911 |
|
|
sv = av_delete((AV*)hv, SvIV(*MARK), discard); |
| 3912 |
|
|
*MARK = sv ? sv : &PL_sv_undef; |
| 3913 |
|
|
} |
| 3914 |
|
|
} |
| 3915 |
|
|
else { /* pseudo-hash element */ |
| 3916 |
|
|
while (++MARK <= SP) { |
| 3917 |
|
|
sv = avhv_delete_ent((AV*)hv, *MARK, discard, 0); |
| 3918 |
|
|
*MARK = sv ? sv : &PL_sv_undef; |
| 3919 |
|
|
} |
| 3920 |
|
|
} |
| 3921 |
|
|
} |
| 3922 |
|
|
else |
| 3923 |
|
|
DIE(aTHX_ "Not a HASH reference"); |
| 3924 |
|
|
if (discard) |
| 3925 |
|
|
SP = ORIGMARK; |
| 3926 |
|
|
else if (gimme == G_SCALAR) { |
| 3927 |
|
|
MARK = ORIGMARK; |
| 3928 |
|
|
if (SP > MARK) |
| 3929 |
|
|
*++MARK = *SP; |
| 3930 |
|
|
else |
| 3931 |
|
|
*++MARK = &PL_sv_undef; |
| 3932 |
|
|
SP = MARK; |
| 3933 |
|
|
} |
| 3934 |
|
|
} |
| 3935 |
|
|
else { |
| 3936 |
|
|
SV *keysv = POPs; |
| 3937 |
|
|
hv = (HV*)POPs; |
| 3938 |
|
|
if (SvTYPE(hv) == SVt_PVHV) |
| 3939 |
|
|
sv = hv_delete_ent(hv, keysv, discard, 0); |
| 3940 |
|
|
else if (SvTYPE(hv) == SVt_PVAV) { |
| 3941 |
|
|
if (PL_op->op_flags & OPf_SPECIAL) |
| 3942 |
|
|
sv = av_delete((AV*)hv, SvIV(keysv), discard); |
| 3943 |
|
|
else |
| 3944 |
|
|
sv = avhv_delete_ent((AV*)hv, keysv, discard, 0); |
| 3945 |
|
|
} |
| 3946 |
|
|
else |
| 3947 |
|
|
DIE(aTHX_ "Not a HASH reference"); |
| 3948 |
|
|
if (!sv) |
| 3949 |
|
|
sv = &PL_sv_undef; |
| 3950 |
|
|
if (!discard) |
| 3951 |
|
|
PUSHs(sv); |
| 3952 |
|
|
} |
| 3953 |
|
|
RETURN; |
| 3954 |
|
|
} |
| 3955 |
|
|
|
| 3956 |
|
|
PP(pp_exists) |
| 3957 |
|
|
{ |
| 3958 |
|
|
dSP; |
| 3959 |
|
|
SV *tmpsv; |
| 3960 |
|
|
HV *hv; |
| 3961 |
|
|
|
| 3962 |
|
|
if (PL_op->op_private & OPpEXISTS_SUB) { |
| 3963 |
|
|
GV *gv; |
| 3964 |
|
|
CV *cv; |
| 3965 |
|
|
SV *sv = POPs; |
| 3966 |
|
|
cv = sv_2cv(sv, &hv, &gv, FALSE); |
| 3967 |
|
|
if (cv) |
| 3968 |
|
|
RETPUSHYES; |
| 3969 |
|
|
if (gv && isGV(gv) && GvCV(gv) && !GvCVGEN(gv)) |
| 3970 |
|
|
RETPUSHYES; |
| 3971 |
|
|
RETPUSHNO; |
| 3972 |
|
|
} |
| 3973 |
|
|
tmpsv = POPs; |
| 3974 |
|
|
hv = (HV*)POPs; |
| 3975 |
|
|
if (SvTYPE(hv) == SVt_PVHV) { |
| 3976 |
|
|
if (hv_exists_ent(hv, tmpsv, 0)) |
| 3977 |
|
|
RETPUSHYES; |
| 3978 |
|
|
} |
| 3979 |
|
|
else if (SvTYPE(hv) == SVt_PVAV) { |
| 3980 |
|
|
if (PL_op->op_flags & OPf_SPECIAL) { /* array element */ |
| 3981 |
|
|
if (av_exists((AV*)hv, SvIV(tmpsv))) |
| 3982 |
|
|
RETPUSHYES; |
| 3983 |
|
|
} |
| 3984 |
|
|
else if (avhv_exists_ent((AV*)hv, tmpsv, 0)) /* pseudo-hash element */ |
| 3985 |
|
|
RETPUSHYES; |
| 3986 |
|
|
} |
| 3987 |
|
|
else { |
| 3988 |
|
|
DIE(aTHX_ "Not a HASH reference"); |
| 3989 |
|
|
} |
| 3990 |
|
|
RETPUSHNO; |
| 3991 |
|
|
} |
| 3992 |
|
|
|
| 3993 |
|
|
PP(pp_hslice) |
| 3994 |
|
|
{ |
| 3995 |
|
|
dSP; dMARK; dORIGMARK; |
| 3996 |
|
|
register HV *hv = (HV*)POPs; |
| 3997 |
|
|
register I32 lval = (PL_op->op_flags & OPf_MOD || LVRET); |
| 3998 |
|
|
I32 realhv = (SvTYPE(hv) == SVt_PVHV); |
| 3999 |
|
|
bool localizing = PL_op->op_private & OPpLVAL_INTRO ? TRUE : FALSE; |
| 4000 |
|
|
bool other_magic = FALSE; |
| 4001 |
|
|
|
| 4002 |
|
|
if (localizing) { |
| 4003 |
|
|
MAGIC *mg; |
| 4004 |
|
|
HV *stash; |
| 4005 |
|
|
|
| 4006 |
|
|
other_magic = mg_find((SV*)hv, PERL_MAGIC_env) || |
| 4007 |
|
|
((mg = mg_find((SV*)hv, PERL_MAGIC_tied)) |
| 4008 |
|
|
/* Try to preserve the existenceness of a tied hash |
| 4009 |
|
|
* element by using EXISTS and DELETE if possible. |
| 4010 |
|
|
* Fallback to FETCH and STORE otherwise */ |
| 4011 |
|
|
&& (stash = SvSTASH(SvRV(SvTIED_obj((SV*)hv, mg)))) |
| 4012 |
|
|
&& gv_fetchmethod_autoload(stash, "EXISTS", TRUE) |
| 4013 |
|
|
&& gv_fetchmethod_autoload(stash, "DELETE", TRUE)); |
| 4014 |
|
|
} |
| 4015 |
|
|
|
| 4016 |
|
|
if (!realhv && localizing) |
| 4017 |
|
|
DIE(aTHX_ "Can't localize pseudo-hash element"); |
| 4018 |
|
|
|
| 4019 |
|
|
if (realhv || SvTYPE(hv) == SVt_PVAV) { |
| 4020 |
|
|
while (++MARK <= SP) { |
| 4021 |
|
|
SV *keysv = *MARK; |
| 4022 |
|
|
SV **svp; |
| 4023 |
|
|
bool preeminent = FALSE; |
| 4024 |
|
|
|
| 4025 |
|
|
if (localizing) { |
| 4026 |
|
|
preeminent = SvRMAGICAL(hv) && !other_magic ? 1 : |
| 4027 |
|
|
realhv ? hv_exists_ent(hv, keysv, 0) |
| 4028 |
|
|
: avhv_exists_ent((AV*)hv, keysv, 0); |
| 4029 |
|
|
} |
| 4030 |
|
|
|
| 4031 |
|
|
if (realhv) { |
| 4032 |
|
|
HE *he = hv_fetch_ent(hv, keysv, lval, 0); |
| 4033 |
|
|
svp = he ? &HeVAL(he) : 0; |
| 4034 |
|
|
} |
| 4035 |
|
|
else { |
| 4036 |
|
|
svp = avhv_fetch_ent((AV*)hv, keysv, lval, 0); |
| 4037 |
|
|
} |
| 4038 |
|
|
if (lval) { |
| 4039 |
|
|
if (!svp || *svp == &PL_sv_undef) { |
| 4040 |
|
|
STRLEN n_a; |
| 4041 |
|
|
DIE(aTHX_ PL_no_helem, SvPV(keysv, n_a)); |
| 4042 |
|
|
} |
| 4043 |
|
|
if (localizing) { |
| 4044 |
|
|
if (preeminent) |
| 4045 |
|
|
save_helem(hv, keysv, svp); |
| 4046 |
|
|
else { |
| 4047 |
|
|
STRLEN keylen; |
| 4048 |
|
|
char *key = SvPV(keysv, keylen); |
| 4049 |
|
|
SAVEDELETE(hv, savepvn(key,keylen), keylen); |
| 4050 |
|
|
} |
| 4051 |
|
|
} |
| 4052 |
|
|
} |
| 4053 |
|
|
*MARK = svp ? *svp : &PL_sv_undef; |
| 4054 |
|
|
} |
| 4055 |
|
|
} |
| 4056 |
|
|
if (GIMME != G_ARRAY) { |
| 4057 |
|
|
MARK = ORIGMARK; |
| 4058 |
|
|
*++MARK = SP > ORIGMARK ? *SP : &PL_sv_undef; |
| 4059 |
|
|
SP = MARK; |
| 4060 |
|
|
} |
| 4061 |
|
|
RETURN; |
| 4062 |
|
|
} |
| 4063 |
|
|
|
| 4064 |
|
|
/* List operators. */ |
| 4065 |
|
|
|
| 4066 |
|
|
PP(pp_list) |
| 4067 |
|
|
{ |
| 4068 |
|
|
dSP; dMARK; |
| 4069 |
|
|
if (GIMME != G_ARRAY) { |
| 4070 |
|
|
if (++MARK <= SP) |
| 4071 |
|
|
*MARK = *SP; /* unwanted list, return last item */ |
| 4072 |
|
|
else |
| 4073 |
|
|
*MARK = &PL_sv_undef; |
| 4074 |
|
|
SP = MARK; |
| 4075 |
|
|
} |
| 4076 |
|
|
RETURN; |
| 4077 |
|
|
} |
| 4078 |
|
|
|
| 4079 |
|
|
PP(pp_lslice) |
| 4080 |
|
|
{ |
| 4081 |
|
|
dSP; |
| 4082 |
|
|
SV **lastrelem = PL_stack_sp; |
| 4083 |
|
|
SV **lastlelem = PL_stack_base + POPMARK; |
| 4084 |
|
|
SV **firstlelem = PL_stack_base + POPMARK + 1; |
| 4085 |
|
|
register SV **firstrelem = lastlelem + 1; |
| 4086 |
|
|
I32 arybase = PL_curcop->cop_arybase; |
| 4087 |
|
|
I32 lval = PL_op->op_flags & OPf_MOD; |
| 4088 |
|
|
I32 is_something_there = lval; |
| 4089 |
|
|
|
| 4090 |
|
|
register I32 max = lastrelem - lastlelem; |
| 4091 |
|
|
register SV **lelem; |
| 4092 |
|
|
register I32 ix; |
| 4093 |
|
|
|
| 4094 |
|
|
if (GIMME != G_ARRAY) { |
| 4095 |
|
|
ix = SvIVx(*lastlelem); |
| 4096 |
|
|
if (ix < 0) |
| 4097 |
|
|
ix += max; |
| 4098 |
|
|
else |
| 4099 |
|
|
ix -= arybase; |
| 4100 |
|
|
if (ix < 0 || ix >= max) |
| 4101 |
|
|
*firstlelem = &PL_sv_undef; |
| 4102 |
|
|
else |
| 4103 |
|
|
*firstlelem = firstrelem[ix]; |
| 4104 |
|
|
SP = firstlelem; |
| 4105 |
|
|
RETURN; |
| 4106 |
|
|
} |
| 4107 |
|
|
|
| 4108 |
|
|
if (max == 0) { |
| 4109 |
|
|
SP = firstlelem - 1; |
| 4110 |
|
|
RETURN; |
| 4111 |
|
|
} |
| 4112 |
|
|
|
| 4113 |
|
|
for (lelem = firstlelem; lelem <= lastlelem; lelem++) { |
| 4114 |
|
|
ix = SvIVx(*lelem); |
| 4115 |
|
|
if (ix < 0) |
| 4116 |
|
|
ix += max; |
| 4117 |
|
|
else |
| 4118 |
|
|
ix -= arybase; |
| 4119 |
|
|
if (ix < 0 || ix >= max) |
| 4120 |
|
|
*lelem = &PL_sv_undef; |
| 4121 |
|
|
else { |
| 4122 |
|
|
is_something_there = TRUE; |
| 4123 |
|
|
if (!(*lelem = firstrelem[ix])) |
| 4124 |
|
|
*lelem = &PL_sv_undef; |
| 4125 |
|
|
} |
| 4126 |
|
|
} |
| 4127 |
|
|
if (is_something_there) |
| 4128 |
|
|
SP = lastlelem; |
| 4129 |
|
|
else |
| 4130 |
|
|
SP = firstlelem - 1; |
| 4131 |
|
|
RETURN; |
| 4132 |
|
|
} |
| 4133 |
|
|
|
| 4134 |
|
|
PP(pp_anonlist) |
| 4135 |
|
|
{ |
| 4136 |
|
|
dSP; dMARK; dORIGMARK; |
| 4137 |
|
|
I32 items = SP - MARK; |
| 4138 |
|
|
SV *av = sv_2mortal((SV*)av_make(items, MARK+1)); |
| 4139 |
|
|
SP = ORIGMARK; /* av_make() might realloc stack_sp */ |
| 4140 |
|
|
XPUSHs(av); |
| 4141 |
|
|
RETURN; |
| 4142 |
|
|
} |
| 4143 |
|
|
|
| 4144 |
|
|
PP(pp_anonhash) |
| 4145 |
|
|
{ |
| 4146 |
|
|
dSP; dMARK; dORIGMARK; |
| 4147 |
|
|
HV* hv = (HV*)sv_2mortal((SV*)newHV()); |
| 4148 |
|
|
|
| 4149 |
|
|
while (MARK < SP) { |
| 4150 |
|
|
SV* key = *++MARK; |
| 4151 |
|
|
SV *val = NEWSV(46, 0); |
| 4152 |
|
|
if (MARK < SP) |
| 4153 |
|
|
sv_setsv(val, *++MARK); |
| 4154 |
|
|
else if (ckWARN(WARN_MISC)) |
| 4155 |
|
|
Perl_warner(aTHX_ packWARN(WARN_MISC), "Odd number of elements in anonymous hash"); |
| 4156 |
|
|
(void)hv_store_ent(hv,key,val,0); |
| 4157 |
|
|
} |
| 4158 |
|
|
SP = ORIGMARK; |
| 4159 |
|
|
XPUSHs((SV*)hv); |
| 4160 |
|
|
RETURN; |
| 4161 |
|
|
} |
| 4162 |
|
|
|
| 4163 |
|
|
PP(pp_splice) |
| 4164 |
|
|
{ |
| 4165 |
|
|
dSP; dMARK; dORIGMARK; |
| 4166 |
|
|
register AV *ary = (AV*)*++MARK; |
| 4167 |
|
|
register SV **src; |
| 4168 |
|
|
register SV **dst; |
| 4169 |
|
|
register I32 i; |
| 4170 |
|
|
register I32 offset; |
| 4171 |
|
|
register I32 length; |
| 4172 |
|
|
I32 newlen; |
| 4173 |
|
|
I32 after; |
| 4174 |
|
|
I32 diff; |
| 4175 |
|
|
SV **tmparyval = 0; |
| 4176 |
|
|
MAGIC *mg; |
| 4177 |
|
|
|
| 4178 |
|
|
if ((mg = SvTIED_mg((SV*)ary, PERL_MAGIC_tied))) { |
| 4179 |
|
|
*MARK-- = SvTIED_obj((SV*)ary, mg); |
| 4180 |
|
|
PUSHMARK(MARK); |
| 4181 |
|
|
PUTBACK; |
| 4182 |
|
|
ENTER; |
| 4183 |
|
|
call_method("SPLICE",GIMME_V); |
| 4184 |
|
|
LEAVE; |
| 4185 |
|
|
SPAGAIN; |
| 4186 |
|
|
RETURN; |
| 4187 |
|
|
} |
| 4188 |
|
|
|
| 4189 |
|
|
SP++; |
| 4190 |
|
|
|
| 4191 |
|
|
if (++MARK < SP) { |
| 4192 |
|
|
offset = i = SvIVx(*MARK); |
| 4193 |
|
|
if (offset < 0) |
| 4194 |
|
|
offset += AvFILLp(ary) + 1; |
| 4195 |
|
|
else |
| 4196 |
|
|
offset -= PL_curcop->cop_arybase; |
| 4197 |
|
|
if (offset < 0) |
| 4198 |
|
|
DIE(aTHX_ PL_no_aelem, i); |
| 4199 |
|
|
if (++MARK < SP) { |
| 4200 |
|
|
length = SvIVx(*MARK++); |
| 4201 |
|
|
if (length < 0) { |
| 4202 |
|
|
length += AvFILLp(ary) - offset + 1; |
| 4203 |
|
|
if (length < 0) |
| 4204 |
|
|
length = 0; |
| 4205 |
|
|
} |
| 4206 |
|
|
} |
| 4207 |
|
|
else |
| 4208 |
|
|
length = AvMAX(ary) + 1; /* close enough to infinity */ |
| 4209 |
|
|
} |
| 4210 |
|
|
else { |
| 4211 |
|
|
offset = 0; |
| 4212 |
|
|
length = AvMAX(ary) + 1; |
| 4213 |
|
|
} |
| 4214 |
|
|
if (offset > AvFILLp(ary) + 1) { |
| 4215 |
|
|
if (ckWARN(WARN_MISC)) |
| 4216 |
|
|
Perl_warner(aTHX_ packWARN(WARN_MISC), "splice() offset past end of array" ); |
| 4217 |
|
|
offset = AvFILLp(ary) + 1; |
| 4218 |
|
|
} |
| 4219 |
|
|
after = AvFILLp(ary) + 1 - (offset + length); |
| 4220 |
|
|
if (after < 0) { /* not that much array */ |
| 4221 |
|
|
length += after; /* offset+length now in array */ |
| 4222 |
|
|
after = 0; |
| 4223 |
|
|
if (!AvALLOC(ary)) |
| 4224 |
|
|
av_extend(ary, 0); |
| 4225 |
|
|
} |
| 4226 |
|
|
|
| 4227 |
|
|
/* At this point, MARK .. SP-1 is our new LIST */ |
| 4228 |
|
|
|
| 4229 |
|
|
newlen = SP - MARK; |
| 4230 |
|
|
diff = newlen - length; |
| 4231 |
|
|
if (newlen && !AvREAL(ary) && AvREIFY(ary)) |
| 4232 |
|
|
av_reify(ary); |
| 4233 |
|
|
|
| 4234 |
|
|
/* make new elements SVs now: avoid problems if they're from the array */ |
| 4235 |
|
|
for (dst = MARK, i = newlen; i; i--) { |
| 4236 |
|
|
SV *h = *dst; |
| 4237 |
|
|
*dst++ = newSVsv(h); |
| 4238 |
|
|
} |
| 4239 |
|
|
|
| 4240 |
|
|
if (diff < 0) { /* shrinking the area */ |
| 4241 |
|
|
if (newlen) { |
| 4242 |
|
|
New(451, tmparyval, newlen, SV*); /* so remember insertion */ |
| 4243 |
|
|
Copy(MARK, tmparyval, newlen, SV*); |
| 4244 |
|
|
} |
| 4245 |
|
|
|
| 4246 |
|
|
MARK = ORIGMARK + 1; |
| 4247 |
|
|
if (GIMME == G_ARRAY) { /* copy return vals to stack */ |
| 4248 |
|
|
MEXTEND(MARK, length); |
| 4249 |
|
|
Copy(AvARRAY(ary)+offset, MARK, length, SV*); |
| 4250 |
|
|
if (AvREAL(ary)) { |
| 4251 |
|
|
EXTEND_MORTAL(length); |
| 4252 |
|
|
for (i = length, dst = MARK; i; i--) { |
| 4253 |
|
|
sv_2mortal(*dst); /* free them eventualy */ |
| 4254 |
|
|
dst++; |
| 4255 |
|
|
} |
| 4256 |
|
|
} |
| 4257 |
|
|
MARK += length - 1; |
| 4258 |
|
|
} |
| 4259 |
|
|
else { |
| 4260 |
|
|
*MARK = AvARRAY(ary)[offset+length-1]; |
| 4261 |
|
|
if (AvREAL(ary)) { |
| 4262 |
|
|
sv_2mortal(*MARK); |
| 4263 |
|
|
for (i = length - 1, dst = &AvARRAY(ary)[offset]; i > 0; i--) |
| 4264 |
|
|
SvREFCNT_dec(*dst++); /* free them now */ |
| 4265 |
|
|
} |
| 4266 |
|
|
} |
| 4267 |
|
|
AvFILLp(ary) += diff; |
| 4268 |
|
|
|
| 4269 |
|
|
/* pull up or down? */ |
| 4270 |
|
|
|
| 4271 |
|
|
if (offset < after) { /* easier to pull up */ |
| 4272 |
|
|
if (offset) { /* esp. if nothing to pull */ |
| 4273 |
|
|
src = &AvARRAY(ary)[offset-1]; |
| 4274 |
|
|
dst = src - diff; /* diff is negative */ |
| 4275 |
|
|
for (i = offset; i > 0; i--) /* can't trust Copy */ |
| 4276 |
|
|
*dst-- = *src--; |
| 4277 |
|
|
} |
| 4278 |
|
|
dst = AvARRAY(ary); |
| 4279 |
|
|
SvPVX(ary) = (char*)(AvARRAY(ary) - diff); /* diff is negative */ |
| 4280 |
|
|
AvMAX(ary) += diff; |
| 4281 |
|
|
} |
| 4282 |
|
|
else { |
| 4283 |
|
|
if (after) { /* anything to pull down? */ |
| 4284 |
|
|
src = AvARRAY(ary) + offset + length; |
| 4285 |
|
|
dst = src + diff; /* diff is negative */ |
| 4286 |
|
|
Move(src, dst, after, SV*); |
| 4287 |
|
|
} |
| 4288 |
|
|
dst = &AvARRAY(ary)[AvFILLp(ary)+1]; |
| 4289 |
|
|
/* avoid later double free */ |
| 4290 |
|
|
} |
| 4291 |
|
|
i = -diff; |
| 4292 |
|
|
while (i) |
| 4293 |
|
|
dst[--i] = &PL_sv_undef; |
| 4294 |
|
|
|
| 4295 |
|
|
if (newlen) { |
| 4296 |
|
|
Copy( tmparyval, AvARRAY(ary) + offset, newlen, SV* ); |
| 4297 |
|
|
Safefree(tmparyval); |
| 4298 |
|
|
} |
| 4299 |
|
|
} |
| 4300 |
|
|
else { /* no, expanding (or same) */ |
| 4301 |
|
|
if (length) { |
| 4302 |
|
|
New(452, tmparyval, length, SV*); /* so remember deletion */ |
| 4303 |
|
|
Copy(AvARRAY(ary)+offset, tmparyval, length, SV*); |
| 4304 |
|
|
} |
| 4305 |
|
|
|
| 4306 |
|
|
if (diff > 0) { /* expanding */ |
| 4307 |
|
|
|
| 4308 |
|
|
/* push up or down? */ |
| 4309 |
|
|
|
| 4310 |
|
|
if (offset < after && diff <= AvARRAY(ary) - AvALLOC(ary)) { |
| 4311 |
|
|
if (offset) { |
| 4312 |
|
|
src = AvARRAY(ary); |
| 4313 |
|
|
dst = src - diff; |
| 4314 |
|
|
Move(src, dst, offset, SV*); |
| 4315 |
|
|
} |
| 4316 |
|
|
SvPVX(ary) = (char*)(AvARRAY(ary) - diff);/* diff is positive */ |
| 4317 |
|
|
AvMAX(ary) += diff; |
| 4318 |
|
|
AvFILLp(ary) += diff; |
| 4319 |
|
|
} |
| 4320 |
|
|
else { |
| 4321 |
|
|
if (AvFILLp(ary) + diff >= AvMAX(ary)) /* oh, well */ |
| 4322 |
|
|
av_extend(ary, AvFILLp(ary) + diff); |
| 4323 |
|
|
AvFILLp(ary) += diff; |
| 4324 |
|
|
|
| 4325 |
|
|
if (after) { |
| 4326 |
|
|
dst = AvARRAY(ary) + AvFILLp(ary); |
| 4327 |
|
|
src = dst - diff; |
| 4328 |
|
|
for (i = after; i; i--) { |
| 4329 |
|
|
*dst-- = *src--; |
| 4330 |
|
|
} |
| 4331 |
|
|
} |
| 4332 |
|
|
} |
| 4333 |
|
|
} |
| 4334 |
|
|
|
| 4335 |
|
|
if (newlen) { |
| 4336 |
|
|
Copy( MARK, AvARRAY(ary) + offset, newlen, SV* ); |
| 4337 |
|
|
} |
| 4338 |
|
|
|
| 4339 |
|
|
MARK = ORIGMARK + 1; |
| 4340 |
|
|
if (GIMME == G_ARRAY) { /* copy return vals to stack */ |
| 4341 |
|
|
if (length) { |
| 4342 |
|
|
Copy(tmparyval, MARK, length, SV*); |
| 4343 |
|
|
if (AvREAL(ary)) { |
| 4344 |
|
|
EXTEND_MORTAL(length); |
| 4345 |
|
|
for (i = length, dst = MARK; i; i--) { |
| 4346 |
|
|
sv_2mortal(*dst); /* free them eventualy */ |
| 4347 |
|
|
dst++; |
| 4348 |
|
|
} |
| 4349 |
|
|
} |
| 4350 |
|
|
Safefree(tmparyval); |
| 4351 |
|
|
} |
| 4352 |
|
|
MARK += length - 1; |
| 4353 |
|
|
} |
| 4354 |
|
|
else if (length--) { |
| 4355 |
|
|
*MARK = tmparyval[length]; |
| 4356 |
|
|
if (AvREAL(ary)) { |
| 4357 |
|
|
sv_2mortal(*MARK); |
| 4358 |
|
|
while (length-- > 0) |
| 4359 |
|
|
SvREFCNT_dec(tmparyval[length]); |
| 4360 |
|
|
} |
| 4361 |
|
|
Safefree(tmparyval); |
| 4362 |
|
|
} |
| 4363 |
|
|
else |
| 4364 |
|
|
*MARK = &PL_sv_undef; |
| 4365 |
|
|
} |
| 4366 |
|
|
SP = MARK; |
| 4367 |
|
|
RETURN; |
| 4368 |
|
|
} |
| 4369 |
|
|
|
| 4370 |
|
|
PP(pp_push) |
| 4371 |
|
|
{ |
| 4372 |
|
|
dSP; dMARK; dORIGMARK; dTARGET; |
| 4373 |
|
|
register AV *ary = (AV*)*++MARK; |
| 4374 |
|
|
register SV *sv = &PL_sv_undef; |
| 4375 |
|
|
MAGIC *mg; |
| 4376 |
|
|
|
| 4377 |
|
|
if ((mg = SvTIED_mg((SV*)ary, PERL_MAGIC_tied))) { |
| 4378 |
|
|
*MARK-- = SvTIED_obj((SV*)ary, mg); |
| 4379 |
|
|
PUSHMARK(MARK); |
| 4380 |
|
|
PUTBACK; |
| 4381 |
|
|
ENTER; |
| 4382 |
|
|
call_method("PUSH",G_SCALAR|G_DISCARD); |
| 4383 |
|
|
LEAVE; |
| 4384 |
|
|
SPAGAIN; |
| 4385 |
|
|
} |
| 4386 |
|
|
else { |
| 4387 |
|
|
/* Why no pre-extend of ary here ? */ |
| 4388 |
|
|
for (++MARK; MARK <= SP; MARK++) { |
| 4389 |
|
|
sv = NEWSV(51, 0); |
| 4390 |
|
|
if (*MARK) |
| 4391 |
|
|
sv_setsv(sv, *MARK); |
| 4392 |
|
|
av_push(ary, sv); |
| 4393 |
|
|
} |
| 4394 |
|
|
} |
| 4395 |
|
|
SP = ORIGMARK; |
| 4396 |
|
|
PUSHi( AvFILL(ary) + 1 ); |
| 4397 |
|
|
RETURN; |
| 4398 |
|
|
} |
| 4399 |
|
|
|
| 4400 |
|
|
PP(pp_pop) |
| 4401 |
|
|
{ |
| 4402 |
|
|
dSP; |
| 4403 |
|
|
AV *av = (AV*)POPs; |
| 4404 |
|
|
SV *sv = av_pop(av); |
| 4405 |
|
|
if (AvREAL(av)) |
| 4406 |
|
|
(void)sv_2mortal(sv); |
| 4407 |
|
|
PUSHs(sv); |
| 4408 |
|
|
RETURN; |
| 4409 |
|
|
} |
| 4410 |
|
|
|
| 4411 |
|
|
PP(pp_shift) |
| 4412 |
|
|
{ |
| 4413 |
|
|
dSP; |
| 4414 |
|
|
AV *av = (AV*)POPs; |
| 4415 |
|
|
SV *sv = av_shift(av); |
| 4416 |
|
|
EXTEND(SP, 1); |
| 4417 |
|
|
if (!sv) |
| 4418 |
|
|
RETPUSHUNDEF; |
| 4419 |
|
|
if (AvREAL(av)) |
| 4420 |
|
|
(void)sv_2mortal(sv); |
| 4421 |
|
|
PUSHs(sv); |
| 4422 |
|
|
RETURN; |
| 4423 |
|
|
} |
| 4424 |
|
|
|
| 4425 |
|
|
PP(pp_unshift) |
| 4426 |
|
|
{ |
| 4427 |
|
|
dSP; dMARK; dORIGMARK; dTARGET; |
| 4428 |
|
|
register AV *ary = (AV*)*++MARK; |
| 4429 |
|
|
register SV *sv; |
| 4430 |
|
|
register I32 i = 0; |
| 4431 |
|
|
MAGIC *mg; |
| 4432 |
|
|
|
| 4433 |
|
|
if ((mg = SvTIED_mg((SV*)ary, PERL_MAGIC_tied))) { |
| 4434 |
|
|
*MARK-- = SvTIED_obj((SV*)ary, mg); |
| 4435 |
|
|
PUSHMARK(MARK); |
| 4436 |
|
|
PUTBACK; |
| 4437 |
|
|
ENTER; |
| 4438 |
|
|
call_method("UNSHIFT",G_SCALAR|G_DISCARD); |
| 4439 |
|
|
LEAVE; |
| 4440 |
|
|
SPAGAIN; |
| 4441 |
|
|
} |
| 4442 |
|
|
else { |
| 4443 |
|
|
av_unshift(ary, SP - MARK); |
| 4444 |
|
|
while (MARK < SP) { |
| 4445 |
|
|
sv = newSVsv(*++MARK); |
| 4446 |
|
|
(void)av_store(ary, i++, sv); |
| 4447 |
|
|
} |
| 4448 |
|
|
} |
| 4449 |
|
|
SP = ORIGMARK; |
| 4450 |
|
|
PUSHi( AvFILL(ary) + 1 ); |
| 4451 |
|
|
RETURN; |
| 4452 |
|
|
} |
| 4453 |
|
|
|
| 4454 |
|
|
PP(pp_reverse) |
| 4455 |
|
|
{ |
| 4456 |
|
|
dSP; dMARK; |
| 4457 |
|
|
register SV *tmp; |
| 4458 |
|
|
SV **oldsp = SP; |
| 4459 |
|
|
|
| 4460 |
|
|
if (GIMME == G_ARRAY) { |
| 4461 |
|
|
MARK++; |
| 4462 |
|
|
while (MARK < SP) { |
| 4463 |
|
|
tmp = *MARK; |
| 4464 |
|
|
*MARK++ = *SP; |
| 4465 |
|
|
*SP-- = tmp; |
| 4466 |
|
|
} |
| 4467 |
|
|
/* safe as long as stack cannot get extended in the above */ |
| 4468 |
|
|
SP = oldsp; |
| 4469 |
|
|
} |
| 4470 |
|
|
else { |
| 4471 |
|
|
register char *up; |
| 4472 |
|
|
register char *down; |
| 4473 |
|
|
register I32 tmp; |
| 4474 |
|
|
dTARGET; |
| 4475 |
|
|
STRLEN len; |
| 4476 |
|
|
|
| 4477 |
|
|
SvUTF8_off(TARG); /* decontaminate */ |
| 4478 |
|
|
if (SP - MARK > 1) |
| 4479 |
|
|
do_join(TARG, &PL_sv_no, MARK, SP); |
| 4480 |
|
|
else |
| 4481 |
|
|
sv_setsv(TARG, (SP > MARK) ? *SP : DEFSV); |
| 4482 |
|
|
up = SvPV_force(TARG, len); |
| 4483 |
|
|
if (len > 1) { |
| 4484 |
|
|
if (DO_UTF8(TARG)) { /* first reverse each character */ |
| 4485 |
|
|
U8* s = (U8*)SvPVX(TARG); |
| 4486 |
|
|
U8* send = (U8*)(s + len); |
| 4487 |
|
|
while (s < send) { |
| 4488 |
|
|
if (UTF8_IS_INVARIANT(*s)) { |
| 4489 |
|
|
s++; |
| 4490 |
|
|
continue; |
| 4491 |
|
|
} |
| 4492 |
|
|
else { |
| 4493 |
|
|
if (!utf8_to_uvchr(s, 0)) |
| 4494 |
|
|
break; |
| 4495 |
|
|
up = (char*)s; |
| 4496 |
|
|
s += UTF8SKIP(s); |
| 4497 |
|
|
down = (char*)(s - 1); |
| 4498 |
|
|
/* reverse this character */ |
| 4499 |
|
|
while (down > up) { |
| 4500 |
|
|
tmp = *up; |
| 4501 |
|
|
*up++ = *down; |
| 4502 |
|
|
*down-- = (char)tmp; |
| 4503 |
|
|
} |
| 4504 |
|
|
} |
| 4505 |
|
|
} |
| 4506 |
|
|
up = SvPVX(TARG); |
| 4507 |
|
|
} |
| 4508 |
|
|
down = SvPVX(TARG) + len - 1; |
| 4509 |
|
|
while (down > up) { |
| 4510 |
|
|
tmp = *up; |
| 4511 |
|
|
*up++ = *down; |
| 4512 |
|
|
*down-- = (char)tmp; |
| 4513 |
|
|
} |
| 4514 |
|
|
(void)SvPOK_only_UTF8(TARG); |
| 4515 |
|
|
} |
| 4516 |
|
|
SP = MARK + 1; |
| 4517 |
|
|
SETTARG; |
| 4518 |
|
|
} |
| 4519 |
|
|
RETURN; |
| 4520 |
|
|
} |
| 4521 |
|
|
|
| 4522 |
|
|
PP(pp_split) |
| 4523 |
|
|
{ |
| 4524 |
|
|
dSP; dTARG; |
| 4525 |
|
|
AV *ary; |
| 4526 |
|
|
register IV limit = POPi; /* note, negative is forever */ |
| 4527 |
|
|
SV *sv = POPs; |
| 4528 |
|
|
STRLEN len; |
| 4529 |
|
|
register char *s = SvPV(sv, len); |
| 4530 |
|
|
bool do_utf8 = DO_UTF8(sv); |
| 4531 |
|
|
char *strend = s + len; |
| 4532 |
|
|
register PMOP *pm; |
| 4533 |
|
|
register REGEXP *rx; |
| 4534 |
|
|
register SV *dstr; |
| 4535 |
|
|
register char *m; |
| 4536 |
|
|
I32 iters = 0; |
| 4537 |
|
|
STRLEN slen = do_utf8 ? utf8_length((U8*)s, (U8*)strend) : (strend - s); |
| 4538 |
|
|
I32 maxiters = slen + 10; |
| 4539 |
|
|
I32 i; |
| 4540 |
|
|
char *orig; |
| 4541 |
|
|
I32 origlimit = limit; |
| 4542 |
|
|
I32 realarray = 0; |
| 4543 |
|
|
I32 base; |
| 4544 |
|
|
I32 gimme = GIMME_V; |
| 4545 |
|
|
I32 oldsave = PL_savestack_ix; |
| 4546 |
|
|
I32 make_mortal = 1; |
| 4547 |
|
|
MAGIC *mg = (MAGIC *) NULL; |
| 4548 |
|
|
|
| 4549 |
|
|
#ifdef DEBUGGING |
| 4550 |
|
|
Copy(&LvTARGOFF(POPs), &pm, 1, PMOP*); |
| 4551 |
|
|
#else |
| 4552 |
|
|
pm = (PMOP*)POPs; |
| 4553 |
|
|
#endif |
| 4554 |
|
|
if (!pm || !s) |
| 4555 |
|
|
DIE(aTHX_ "panic: pp_split"); |
| 4556 |
|
|
rx = PM_GETRE(pm); |
| 4557 |
|
|
|
| 4558 |
|
|
TAINT_IF((pm->op_pmflags & PMf_LOCALE) && |
| 4559 |
|
|
(pm->op_pmflags & (PMf_WHITE | PMf_SKIPWHITE))); |
| 4560 |
|
|
|
| 4561 |
|
|
RX_MATCH_UTF8_set(rx, do_utf8); |
| 4562 |
|
|
|
| 4563 |
|
|
if (pm->op_pmreplroot) { |
| 4564 |
|
|
#ifdef USE_ITHREADS |
| 4565 |
|
|
ary = GvAVn((GV*)PAD_SVl(INT2PTR(PADOFFSET, pm->op_pmreplroot))); |
| 4566 |
|
|
#else |
| 4567 |
|
|
ary = GvAVn((GV*)pm->op_pmreplroot); |
| 4568 |
|
|
#endif |
| 4569 |
|
|
} |
| 4570 |
|
|
else if (gimme != G_ARRAY) |
| 4571 |
|
|
#ifdef USE_5005THREADS |
| 4572 |
|
|
ary = (AV*)PAD_SVl(0); |
| 4573 |
|
|
#else |
| 4574 |
|
|
ary = GvAVn(PL_defgv); |
| 4575 |
|
|
#endif /* USE_5005THREADS */ |
| 4576 |
|
|
else |
| 4577 |
|
|
ary = Nullav; |
| 4578 |
|
|
if (ary && (gimme != G_ARRAY || (pm->op_pmflags & PMf_ONCE))) { |
| 4579 |
|
|
realarray = 1; |
| 4580 |
|
|
PUTBACK; |
| 4581 |
|
|
av_extend(ary,0); |
| 4582 |
|
|
av_clear(ary); |
| 4583 |
|
|
SPAGAIN; |
| 4584 |
|
|
if ((mg = SvTIED_mg((SV*)ary, PERL_MAGIC_tied))) { |
| 4585 |
|
|
PUSHMARK(SP); |
| 4586 |
|
|
XPUSHs(SvTIED_obj((SV*)ary, mg)); |
| 4587 |
|
|
} |
| 4588 |
|
|
else { |
| 4589 |
|
|
if (!AvREAL(ary)) { |
| 4590 |
|
|
AvREAL_on(ary); |
| 4591 |
|
|
AvREIFY_off(ary); |
| 4592 |
|
|
for (i = AvFILLp(ary); i >= 0; i--) |
| 4593 |
|
|
AvARRAY(ary)[i] = &PL_sv_undef; /* don't free mere refs */ |
| 4594 |
|
|
} |
| 4595 |
|
|
/* temporarily switch stacks */ |
| 4596 |
|
|
SAVESWITCHSTACK(PL_curstack, ary); |
| 4597 |
|
|
make_mortal = 0; |
| 4598 |
|
|
} |
| 4599 |
|
|
} |
| 4600 |
|
|
base = SP - PL_stack_base; |
| 4601 |
|
|
orig = s; |
| 4602 |
|
|
if (pm->op_pmflags & PMf_SKIPWHITE) { |
| 4603 |
|
|
if (pm->op_pmflags & PMf_LOCALE) { |
| 4604 |
|
|
while (isSPACE_LC(*s)) |
| 4605 |
|
|
s++; |
| 4606 |
|
|
} |
| 4607 |
|
|
else { |
| 4608 |
|
|
while (isSPACE(*s)) |
| 4609 |
|
|
s++; |
| 4610 |
|
|
} |
| 4611 |
|
|
} |
| 4612 |
|
|
if (pm->op_pmflags & (PMf_MULTILINE|PMf_SINGLELINE)) { |
| 4613 |
|
|
SAVEINT(PL_multiline); |
| 4614 |
|
|
PL_multiline = pm->op_pmflags & PMf_MULTILINE; |
| 4615 |
|
|
} |
| 4616 |
|
|
|
| 4617 |
|
|
if (!limit) |
| 4618 |
|
|
limit = maxiters + 2; |
| 4619 |
|
|
if (pm->op_pmflags & PMf_WHITE) { |
| 4620 |
|
|
while (--limit) { |
| 4621 |
|
|
m = s; |
| 4622 |
|
|
while (m < strend && |
| 4623 |
|
|
!((pm->op_pmflags & PMf_LOCALE) |
| 4624 |
|
|
? isSPACE_LC(*m) : isSPACE(*m))) |
| 4625 |
|
|
++m; |
| 4626 |
|
|
if (m >= strend) |
| 4627 |
|
|
break; |
| 4628 |
|
|
|
| 4629 |
|
|
dstr = newSVpvn(s, m-s); |
| 4630 |
|
|
if (make_mortal) |
| 4631 |
|
|
sv_2mortal(dstr); |
| 4632 |
|
|
if (do_utf8) |
| 4633 |
|
|
(void)SvUTF8_on(dstr); |
| 4634 |
|
|
XPUSHs(dstr); |
| 4635 |
|
|
|
| 4636 |
|
|
s = m + 1; |
| 4637 |
|
|
while (s < strend && |
| 4638 |
|
|
((pm->op_pmflags & PMf_LOCALE) |
| 4639 |
|
|
? isSPACE_LC(*s) : isSPACE(*s))) |
| 4640 |
|
|
++s; |
| 4641 |
|
|
} |
| 4642 |
|
|
} |
| 4643 |
|
|
else if (rx->precomp[0] == '^' && rx->precomp[1] == '\0') { |
| 4644 |
|
|
while (--limit) { |
| 4645 |
|
|
/*SUPPRESS 530*/ |
| 4646 |
|
|
for (m = s; m < strend && *m != '\n'; m++) ; |
| 4647 |
|
|
m++; |
| 4648 |
|
|
if (m >= strend) |
| 4649 |
|
|
break; |
| 4650 |
|
|
dstr = newSVpvn(s, m-s); |
| 4651 |
|
|
if (make_mortal) |
| 4652 |
|
|
sv_2mortal(dstr); |
| 4653 |
|
|
if (do_utf8) |
| 4654 |
|
|
(void)SvUTF8_on(dstr); |
| 4655 |
|
|
XPUSHs(dstr); |
| 4656 |
|
|
s = m; |
| 4657 |
|
|
} |
| 4658 |
|
|
} |
| 4659 |
|
|
else if (do_utf8 == ((rx->reganch & ROPT_UTF8) != 0) && |
| 4660 |
|
|
(rx->reganch & RE_USE_INTUIT) && !rx->nparens |
| 4661 |
|
|
&& (rx->reganch & ROPT_CHECK_ALL) |
| 4662 |
|
|
&& !(rx->reganch & ROPT_ANCH)) { |
| 4663 |
|
|
int tail = (rx->reganch & RE_INTUIT_TAIL); |
| 4664 |
|
|
SV *csv = CALLREG_INTUIT_STRING(aTHX_ rx); |
| 4665 |
|
|
|
| 4666 |
|
|
len = rx->minlen; |
| 4667 |
|
|
if (len == 1 && !(rx->reganch & ROPT_UTF8) && !tail) { |
| 4668 |
|
|
STRLEN n_a; |
| 4669 |
|
|
char c = *SvPV(csv, n_a); |
| 4670 |
|
|
while (--limit) { |
| 4671 |
|
|
/*SUPPRESS 530*/ |
| 4672 |
|
|
for (m = s; m < strend && *m != c; m++) ; |
| 4673 |
|
|
if (m >= strend) |
| 4674 |
|
|
break; |
| 4675 |
|
|
dstr = newSVpvn(s, m-s); |
| 4676 |
|
|
if (make_mortal) |
| 4677 |
|
|
sv_2mortal(dstr); |
| 4678 |
|
|
if (do_utf8) |
| 4679 |
|
|
(void)SvUTF8_on(dstr); |
| 4680 |
|
|
XPUSHs(dstr); |
| 4681 |
|
|
/* The rx->minlen is in characters but we want to step |
| 4682 |
|
|
* s ahead by bytes. */ |
| 4683 |
|
|
if (do_utf8) |
| 4684 |
|
|
s = (char*)utf8_hop((U8*)m, len); |
| 4685 |
|
|
else |
| 4686 |
|
|
s = m + len; /* Fake \n at the end */ |
| 4687 |
|
|
} |
| 4688 |
|
|
} |
| 4689 |
|
|
else { |
| 4690 |
|
|
#ifndef lint |
| 4691 |
|
|
while (s < strend && --limit && |
| 4692 |
|
|
(m = fbm_instr((unsigned char*)s, (unsigned char*)strend, |
| 4693 |
|
|
csv, PL_multiline ? FBMrf_MULTILINE : 0)) ) |
| 4694 |
|
|
#endif |
| 4695 |
|
|
{ |
| 4696 |
|
|
dstr = newSVpvn(s, m-s); |
| 4697 |
|
|
if (make_mortal) |
| 4698 |
|
|
sv_2mortal(dstr); |
| 4699 |
|
|
if (do_utf8) |
| 4700 |
|
|
(void)SvUTF8_on(dstr); |
| 4701 |
|
|
XPUSHs(dstr); |
| 4702 |
|
|
/* The rx->minlen is in characters but we want to step |
| 4703 |
|
|
* s ahead by bytes. */ |
| 4704 |
|
|
if (do_utf8) |
| 4705 |
|
|
s = (char*)utf8_hop((U8*)m, len); |
| 4706 |
|
|
else |
| 4707 |
|
|
s = m + len; /* Fake \n at the end */ |
| 4708 |
|
|
} |
| 4709 |
|
|
} |
| 4710 |
|
|
} |
| 4711 |
|
|
else { |
| 4712 |
|
|
maxiters += slen * rx->nparens; |
| 4713 |
|
|
while (s < strend && --limit) |
| 4714 |
|
|
{ |
| 4715 |
|
|
PUTBACK; |
| 4716 |
|
|
i = CALLREGEXEC(aTHX_ rx, s, strend, orig, 1 , sv, NULL, 0); |
| 4717 |
|
|
SPAGAIN; |
| 4718 |
|
|
if (i == 0) |
| 4719 |
|
|
break; |
| 4720 |
|
|
TAINT_IF(RX_MATCH_TAINTED(rx)); |
| 4721 |
|
|
if (RX_MATCH_COPIED(rx) && rx->subbeg != orig) { |
| 4722 |
|
|
m = s; |
| 4723 |
|
|
s = orig; |
| 4724 |
|
|
orig = rx->subbeg; |
| 4725 |
|
|
s = orig + (m - s); |
| 4726 |
|
|
strend = s + (strend - m); |
| 4727 |
|
|
} |
| 4728 |
|
|
m = rx->startp[0] + orig; |
| 4729 |
|
|
dstr = newSVpvn(s, m-s); |
| 4730 |
|
|
if (make_mortal) |
| 4731 |
|
|
sv_2mortal(dstr); |
| 4732 |
|
|
if (do_utf8) |
| 4733 |
|
|
(void)SvUTF8_on(dstr); |
| 4734 |
|
|
XPUSHs(dstr); |
| 4735 |
|
|
if (rx->nparens) { |
| 4736 |
|
|
for (i = 1; i <= (I32)rx->nparens; i++) { |
| 4737 |
|
|
s = rx->startp[i] + orig; |
| 4738 |
|
|
m = rx->endp[i] + orig; |
| 4739 |
|
|
|
| 4740 |
|
|
/* japhy (07/27/01) -- the (m && s) test doesn't catch |
| 4741 |
|
|
parens that didn't match -- they should be set to |
| 4742 |
|
|
undef, not the empty string */ |
| 4743 |
|
|
if (m >= orig && s >= orig) { |
| 4744 |
|
|
dstr = newSVpvn(s, m-s); |
| 4745 |
|
|
} |
| 4746 |
|
|
else |
| 4747 |
|
|
dstr = &PL_sv_undef; /* undef, not "" */ |
| 4748 |
|
|
if (make_mortal) |
| 4749 |
|
|
sv_2mortal(dstr); |
| 4750 |
|
|
if (do_utf8) |
| 4751 |
|
|
(void)SvUTF8_on(dstr); |
| 4752 |
|
|
XPUSHs(dstr); |
| 4753 |
|
|
} |
| 4754 |
|
|
} |
| 4755 |
|
|
s = rx->endp[0] + orig; |
| 4756 |
|
|
} |
| 4757 |
|
|
} |
| 4758 |
|
|
|
| 4759 |
|
|
iters = (SP - PL_stack_base) - base; |
| 4760 |
|
|
if (iters > maxiters) |
| 4761 |
|
|
DIE(aTHX_ "Split loop"); |
| 4762 |
|
|
|
| 4763 |
|
|
/* keep field after final delim? */ |
| 4764 |
|
|
if (s < strend || (iters && origlimit)) { |
| 4765 |
|
|
STRLEN l = strend - s; |
| 4766 |
|
|
dstr = newSVpvn(s, l); |
| 4767 |
|
|
if (make_mortal) |
| 4768 |
|
|
sv_2mortal(dstr); |
| 4769 |
|
|
if (do_utf8) |
| 4770 |
|
|
(void)SvUTF8_on(dstr); |
| 4771 |
|
|
XPUSHs(dstr); |
| 4772 |
|
|
iters++; |
| 4773 |
|
|
} |
| 4774 |
|
|
else if (!origlimit) { |
| 4775 |
|
|
while (iters > 0 && (!TOPs || !SvANY(TOPs) || SvCUR(TOPs) == 0)) { |
| 4776 |
|
|
if (TOPs && !make_mortal) |
| 4777 |
|
|
sv_2mortal(TOPs); |
| 4778 |
|
|
iters--; |
| 4779 |
|
|
*SP-- = &PL_sv_undef; |
| 4780 |
|
|
} |
| 4781 |
|
|
} |
| 4782 |
|
|
|
| 4783 |
|
|
PUTBACK; |
| 4784 |
|
|
LEAVE_SCOPE(oldsave); /* may undo an earlier SWITCHSTACK */ |
| 4785 |
|
|
SPAGAIN; |
| 4786 |
|
|
if (realarray) { |
| 4787 |
|
|
if (!mg) { |
| 4788 |
|
|
if (SvSMAGICAL(ary)) { |
| 4789 |
|
|
PUTBACK; |
| 4790 |
|
|
mg_set((SV*)ary); |
| 4791 |
|
|
SPAGAIN; |
| 4792 |
|
|
} |
| 4793 |
|
|
if (gimme == G_ARRAY) { |
| 4794 |
|
|
EXTEND(SP, iters); |
| 4795 |
|
|
Copy(AvARRAY(ary), SP + 1, iters, SV*); |
| 4796 |
|
|
SP += iters; |
| 4797 |
|
|
RETURN; |
| 4798 |
|
|
} |
| 4799 |
|
|
} |
| 4800 |
|
|
else { |
| 4801 |
|
|
PUTBACK; |
| 4802 |
|
|
ENTER; |
| 4803 |
|
|
call_method("PUSH",G_SCALAR|G_DISCARD); |
| 4804 |
|
|
LEAVE; |
| 4805 |
|
|
SPAGAIN; |
| 4806 |
|
|
if (gimme == G_ARRAY) { |
| 4807 |
|
|
/* EXTEND should not be needed - we just popped them */ |
| 4808 |
|
|
EXTEND(SP, iters); |
| 4809 |
|
|
for (i=0; i < iters; i++) { |
| 4810 |
|
|
SV **svp = av_fetch(ary, i, FALSE); |
| 4811 |
|
|
PUSHs((svp) ? *svp : &PL_sv_undef); |
| 4812 |
|
|
} |
| 4813 |
|
|
RETURN; |
| 4814 |
|
|
} |
| 4815 |
|
|
} |
| 4816 |
|
|
} |
| 4817 |
|
|
else { |
| 4818 |
|
|
if (gimme == G_ARRAY) |
| 4819 |
|
|
RETURN; |
| 4820 |
|
|
} |
| 4821 |
|
|
|
| 4822 |
|
|
GETTARGET; |
| 4823 |
|
|
PUSHi(iters); |
| 4824 |
|
|
RETURN; |
| 4825 |
|
|
} |
| 4826 |
|
|
|
| 4827 |
|
|
#ifdef USE_5005THREADS |
| 4828 |
|
|
void |
| 4829 |
|
|
Perl_unlock_condpair(pTHX_ void *svv) |
| 4830 |
|
|
{ |
| 4831 |
|
|
MAGIC *mg = mg_find((SV*)svv, PERL_MAGIC_mutex); |
| 4832 |
|
|
|
| 4833 |
|
|
if (!mg) |
| 4834 |
|
|
Perl_croak(aTHX_ "panic: unlock_condpair unlocking non-mutex"); |
| 4835 |
|
|
MUTEX_LOCK(MgMUTEXP(mg)); |
| 4836 |
|
|
if (MgOWNER(mg) != thr) |
| 4837 |
|
|
Perl_croak(aTHX_ "panic: unlock_condpair unlocking mutex that we don't own"); |
| 4838 |
|
|
MgOWNER(mg) = 0; |
| 4839 |
|
|
COND_SIGNAL(MgOWNERCONDP(mg)); |
| 4840 |
|
|
DEBUG_S(PerlIO_printf(Perl_debug_log, "0x%"UVxf": unlock 0x%"UVxf"\n", |
| 4841 |
|
|
PTR2UV(thr), PTR2UV(svv))); |
| 4842 |
|
|
MUTEX_UNLOCK(MgMUTEXP(mg)); |
| 4843 |
|
|
} |
| 4844 |
|
|
#endif /* USE_5005THREADS */ |
| 4845 |
|
|
|
| 4846 |
|
|
PP(pp_lock) |
| 4847 |
|
|
{ |
| 4848 |
|
|
dSP; |
| 4849 |
|
|
dTOPss; |
| 4850 |
|
|
SV *retsv = sv; |
| 4851 |
|
|
SvLOCK(sv); |
| 4852 |
|
|
if (SvTYPE(retsv) == SVt_PVAV || SvTYPE(retsv) == SVt_PVHV |
| 4853 |
|
|
|| SvTYPE(retsv) == SVt_PVCV) { |
| 4854 |
|
|
retsv = refto(retsv); |
| 4855 |
|
|
} |
| 4856 |
|
|
SETs(retsv); |
| 4857 |
|
|
RETURN; |
| 4858 |
|
|
} |
| 4859 |
|
|
|
| 4860 |
|
|
PP(pp_threadsv) |
| 4861 |
|
|
{ |
| 4862 |
|
|
#ifdef USE_5005THREADS |
| 4863 |
|
|
dSP; |
| 4864 |
|
|
EXTEND(SP, 1); |
| 4865 |
|
|
if (PL_op->op_private & OPpLVAL_INTRO) |
| 4866 |
|
|
PUSHs(*save_threadsv(PL_op->op_targ)); |
| 4867 |
|
|
else |
| 4868 |
|
|
PUSHs(THREADSV(PL_op->op_targ)); |
| 4869 |
|
|
RETURN; |
| 4870 |
|
|
#else |
| 4871 |
|
|
DIE(aTHX_ "tried to access per-thread data in non-threaded perl"); |
| 4872 |
|
|
#endif /* USE_5005THREADS */ |
| 4873 |
|
|
} |
| 4874 |
|
|
|
| 4875 |
|
|
/* |
| 4876 |
|
|
* Local variables: |
| 4877 |
|
|
* c-indentation-style: bsd |
| 4878 |
|
|
* c-basic-offset: 4 |
| 4879 |
|
|
* indent-tabs-mode: t |
| 4880 |
|
|
* End: |
| 4881 |
|
|
* |
| 4882 |
|
|
* vim: shiftwidth=4: |
| 4883 |
|
|
*/ |