summaryrefslogtreecommitdiff
path: root/pp.c
Commit message (Collapse)AuthorAgeFilesLines
...
* Correct lock’s prototypeFather Chrysostomos2011-07-211-1/+1
| | | | | | | | | | As of commit f4df43b5, lock is parsed the same way as tied. Before that, the prototype was effectively \[$@%&*], but only because it was buggy (an lvalue sub itself would be passed to the function, instead of its return value). Yet its prototype was set to \$, which was just wrong. This fixes part of #94980.
* Use a switch in pp_prototype for compactnessFather Chrysostomos2011-07-181-26/+15
|
* [perl #94984] Remove prototypes for infix opsFather Chrysostomos2011-07-181-1/+7
| | | | | | | | | | | | | | | | | | | | This commit makes prototype("CORE::$_") return undef for these infix ops, instead of the prototype (or error) shown here: and () cmp Error: Cannot find an op number for cmp eq ($$) ge ($$) gt ($$) le ($$) lt ($$) ne ($$) or () x Error: Cannot find an op number for x xor ($$) Those prototypes are not actually correct, and dying for what are real Perl keywords is just mean.
* Add prototypes for __FILE__ &c.Father Chrysostomos2011-07-081-0/+5
| | | | | | | | | | Before this commit, prototype("CORE::__FILE__") would die with ‘Can’t find an op number...’. That __FILE__ does not have an op number whereas time() does is an implementation detail that should not be exposed to the user. So this commit adds prototypes for __FILE__, __LINE__ and __PACKAGE__.
* For shorter strings, store C<study>'s data as U8s or U16s, instead of U32s.Nicholas Clark2011-07-011-12/+49
| | | | | | | The assumption is that most studied strings are fairly short, hence the pain of the extra code is worth it, given the memory savings. 80 character string, 336 bytes as U8, down from 1344 as U32 800 character string, 2112 bytes as U16, down from 4224 as U32
* Store C<study>'s data as U32s, instead of I32s.Nicholas Clark2011-07-011-13/+8
| | | | The "no more" condition is now represented as ~0, instead of -1.
* Tidy code in pp_study and Perl_screaminstr()Nicholas Clark2011-07-011-8/+6
| | | | | | | | | In pp_study eliminate the variable pos, which duplicates len. ch should be U8, not I32. In Perl_screaminstr(), move the declarations of s and x to their point of use, convert a for loop to a while loop, and avoid incrementing and decrementing s. found is a boolean.
* Store C<study>'s data in in mg_ptr instead of interpreter variables.Nicholas Clark2011-07-011-24/+12
| | | | | This allows more than one C<study> to be active at the same time. It eliminates PL_screamfirst, PL_lastscream, PL_maxscream.
* Merge PL_scream{first,next} into one allocated buffer.Nicholas Clark2011-07-011-8/+5
| | | | | Effectively, PL_screamnext is now PL_screamfirst + 256. The actual interpreter variable PL_screamnext is eliminated.
* Change PL_screamnext to store absolute positions.Nicholas Clark2011-07-011-2/+2
| | | | | | | | | | PL_screamnext gives the position of the next occurrence of the current octet. Previously it stored this as an offset from the current position, with -pos stored for "no more", so that the calculated new offset would be zero, allowing a zero/non-zero loop exit test in Perl_screaminstr(). Now it stores absolute position, with -1 for "no more". Also codify -1 as the "not present" value for PL_screamfirst, instead of any negative value.
* Split out study magic from pos magic.Nicholas Clark2011-07-011-2/+1
| | | | | | study uses magic to call SvSCREAM_off() if the scalar is modified. Allocate it its own magic type ('G' for now - pos magic is 'g'). Share the same "set" routine and vtable as regexp/bm/fm (setregxp and vtbl_regexp).
* add do_ncmp fn and make pp_ncmp, pp_eq etc use itDavid Mitchell2011-06-251-414/+129
| | | | | | | | | | | | | | | | | | | | | | Extract most of the body of pp_ncmp() (numeric compare) into a separate function, do_ncmp(), then make the following ops use it: pp_ncmp pp_lt pp_le pp_eq pp_ne pp_ge pp_gt This removes a lot of similar or duplicated code, most of which is dedicated to handling the various combinations of IV verses UV verses NV verses NaN. The various ops first check for, and directly process, the simple and common case of both args being SvIOK_notUV(), and pass the processing on to do_ncmp() otherwise. Benchmarking seems to indicate (but with a lot of noise) that the SvIOK_notUV case is slightly faster than before, and the do_ncmp() branch slightly slower.
* pp_ncmp: favour the non- Perl_isnan routeDavid Mitchell2011-06-251-1/+1
| | | | | | | | | | | | | | | | | | | | | Currently pp_ncmp(), when comparing two NVs, prefers to check its two args for NaNness first, and if either of them are, then return undef. Only if Perl_isnan isn't defined does it fall back to doing three compares (<, >, =) where if all three fail it returns undef. This is in contrast to the other compare functions (e.g. pp_lt), which only use Perl_isnan if NAN_COMPARE_BROKEN is defined - i.e. they prefer to rely on the '<' (or whatever) test to handle NaNs implicitly. Change pp_ncmp to favour not using Perl_isnan(). This has two advantages: First, speed: in the normal case we replace: two function calls to Perl_isnan plus two comparisons, with: three comparisons. Second, this makes pp_ncmp more similar to the other comparison functions, allowing for code reuse in the future.
* remove unreachable code from various compare opsDavid Mitchell2011-06-251-55/+0
| | | | | | | | | | | | | | | | | | | | | | All the compare ops (such as pp_le), have an initial: tryAMAGICbin_MG(le_amg, AMGf_numeric); The effect of the AMGf_numeric flag is that, if the le overloading fails, but either of the args on the stack is a reference, then that arg is replaced with a temporary non-ref arg that is either the result of '0+' overloading, or is a UV with the numerical value of the ref's address. So by the time the main body of the op is called, neither arg can be a ref. Thus a whole bunch of nearly identical blocks can be removed, which *used* to handle comparing refs: if (SvROK(TOPs) && !SvAMAGIC(TOPs) && SvROK(TOPm1s) && !SvAMAGIC(TOPm1s)) { SP--; SETs(boolSV(SvRV(TOPs) <= SvRV(TOPp1s))); RETURN; }
* study now passes REXEC_SCREAM to the regex engine when SvSCREAM() is true.Nicholas Clark2011-06-231-1/+1
| | | | This causes the regex engine to take advantage of the study data.
* [perl #78462] Don't warn for splice(@a,MAX_LEN)Eric Brine2011-06-211-1/+3
| | | | | | The intent of splice(@a,MAX_LEN) is quite clearly to truncate the array if it's too large. There's no reason to warn if it's currently smaller than the max length.
* Revert "pos in lvalue context now returns a PVMG instead of a PVLV."Father Chrysostomos2011-06-161-2/+4
| | | | | | | | | This reverts commit 571f0e8653a532c34edde36e797ecba446978b1c. I’m afraid I have to revert this, as it does not modify sv_reftype accordingly, and doing so would add *more* complexity (the opposite of what that commit was trying to achieve) and slow down ref() at run time, by making it search for pos magic.
* pos in lvalue context now returns a PVMG instead of a PVLV.Nicholas Clark2011-06-141-4/+2
| | | | | Store the target SV in mg_obj, instead of LvTARG(). This slightly reduces both code complexity and runtime memory use.
* Don't allow study on an FBM scalar, to give more flexibility in SV flag usage.Nicholas Clark2011-06-111-2/+5
| | | | | No real-world code would ever end up studying an FBM scalar, so this isn't a real pessimisation.
* Fix several array-returning bugs in lvalue subsFather Chrysostomos2011-06-041-2/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | This finishes fixing bug #23790. When called in reference context (for(...) or map $_, ...), lvalue subs returning arrays or hashes would return the AV or HV itself, as though it were lvalue context. The result was that $_ would be bound to an AV or HV, which is not supposed to happen, as it’s a scalar (that’s when you start getting ‘Bizarre copy’ errors). Commit 91e34d82 fixed this in pp_leavesublv, but the if condition it added was placed outside the loop, so it only applied when the array was the first thing returned. It also did not take hashes into account. By changing the lvalue-context check in pp_padav, pp_padhv and pp_rv2av (which also serves as pp_rv2hv), I was able to apply a more general fix, which also fix another bug: Those array and hash ops were croaking when called in scalar reference context (...->$method). Because it is no longer part of the sub-leaving code, explicitly returning an array in reference context works now, too. This commit also eliminates the code added by 91e34d82, as it’s no longer necessary.
* Remove duplicate code from pp_study(), caused by a4f4e9060b702ac8.Nicholas Clark2011-05-191-4/+0
| | | | | | | The duplicated code could have had no effect - for the case of pos <= 0 pp_study had already returned NO. The second call to SvPV() would have had no side effects, because scalars with side effects don't have SvPOK() true, so would also have already returned NO.
* study uses I32 internally for offsets, so should be skipped for long strings.Nicholas Clark2011-05-191-2/+2
| | | | | It already skips for anything that isn't a plain byte string with non-zero length. Otherwise it risks becoming confused for strings longer than 2**31.
* Clean: Actually use HvUSEDKEYS() instead of HvKEYS()Michael Witten2011-05-181-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This: commit 8aacddc1ea3837f8f1a911d90c644451fc7cfc86 Author: Nick Ing-Simmons <nik@tiuk.ti.com> Date: Tue Dec 18 15:55:22 2001 +0000 Tidied version of Jeffrey Friedl's <jfriedl@yahoo.com> restricted hashes - added delete of READONLY value inhibit & test for same - re-tabbed p4raw-id: //depot/perlio@13760 essentially deprecated HvKEYS() in favor of HvUSEDKEYS(); this is explained in line 144 (now 313) of file `hv.h': /* * HvKEYS gets the number of keys that actually exist(), and is provided * for backwards compatibility with old XS code. The core uses HvUSEDKEYS * (keys, excluding placeholdes) and HvTOTALKEYS (including placeholders) */ This commit simply puts that into practice, and is equivalent to running the following (at least with a35ef416833511da752c4b5b836b7a8915712aab checked out): git grep -l HvKEYS | sed /hv.h/d | xargs sed -i s/HvKEYS/HvUSEDKEYS/ Notice that HvKEYS is currently just an alias for HvUSEDKEYS: $ git show a35ef416833511da752c4b5b836b7a8915712aab:hv.h | sed -n 318p #define HvKEYS(hv) HvUSEDKEYS(hv) According to `make tests': All tests successful.
* Make push, etc., work on tied scalarsFather Chrysostomos2011-04-181-0/+1
| | | | I broke this with commit d4fc441
* Make keys $scalar an lvalueFather Chrysostomos2011-04-181-0/+6
| | | | | | | | | | | | | | This does a run-time check to see whether $scalar is a hash ref, and dies if it is not. This is to keep keys \@_ consistent with keys @_. I cannot simply use OPf_MOD, since that indicates *potential* lvalue context (including subroutine args). So, instead, I take advantage of the fact that OPf_SPECIAL is always set on the LHS of an assignment (usually to indicate that local() should not erase the value).
* Make keys/value/each $scalar accept only unblessed refsFather Chrysostomos2011-04-181-45/+11
| | | | See ticket #80626.
* fix for pp.c under win32 etcDavid Mitchell2011-04-181-2/+2
| | | | | Commit d4fc4415aac96132fac5b1e43e73bcba33a41b79 added two definitions of the DEREF_PLAIN_ARRAY array; the non-GCC one had syntax errors
* Make push/shift $scalar accept only unblessed aryrefsFather Chrysostomos2011-04-181-4/+33
| | | | See ticket #80626.
* Revert parts of c31c291..96b6b87Father Chrysostomos2011-04-081-1/+1
| | | | | | | | | | | | | | | This restores the old definition of dPOPTOPiirl_nomg from before 96b6b87 and the old definition of dPOPXiirl_ul_nomg from before e62ca0f (except for a bug fix: POPi cannot be used since it’s magical). It also reverts most of c31c291. This does mean that uninitialized warnings for various operators are back in reverse order. So I am reinstating a bug with this commit. But that bug was never a 5.14 blocker and so should never have been fixed during code freeze (and there is the slight possibility that the fix would break sensitive test suites). It was only fixed ‘for free’ as a side effect of fixing [perl #87708], but that bug turned out to have a better fix (commit 75ea7a1) that allows these changes to be reverted.
* Revert "[perl #87708] $tied / $tied under use integer"Father Chrysostomos2011-04-081-2/+3
| | | | | | This reverts most of commit 76422f81b675011beffbdb66c981a36b6fbf4a6b. It is now unnecessary as of commit 75ea7a1.
* [perl #87708] $tied / $tied under use integerFather Chrysostomos2011-04-061-3/+2
| | | | | | | | | This is just part of #87708. This fixes the / operator under ‘use integer’ when the same tied sca- lar is used for both operands and returns two different values. Before this commit, get-magic would be called only once and the same value used. In 5.12.x the operands were swapped.
* [perl #87708] $tied % $tied and $tied * $tied under use integerFather Chrysostomos2011-04-061-7/+7
| | | | | | | | | | | | | | | | | This is just part of #87708. This fixes the % and * operators under ‘use integer’ when the same tied scalar is used for both operands and returns two different val- ues. Before this commit, get-magic would be called only once and the same value used. In 5.12.x * just worked but the operands were swapped for %. It turns out that every operator using the dPOPTOPiirl_nomg macro needs exactly the same treatment, so this commit eliminates the dPOPTOPiirl_halfmg macro added a few commits ago and modifies dPOPTOPiirl_nomg to do was it was doing. This should be perfectly safe, as dPOPTOPiirl_nomg has not been in a stable release (and is only for internal use anyway).
* [perl #87708] use integer; $tied < $tiedFather Chrysostomos2011-04-061-1/+1
| | | | | | | | | This is just part of #87708. This fixes < under ‘use integer’ when the same tied scalar is used for both operands and returns two different values. Before this commit, get-magic would be called only once and the same value used. In 5.12.x the operands were swapped.
* [perl #87708] use integer; $tied > $tiedFather Chrysostomos2011-04-061-1/+1
| | | | | | | | | This is just part of #87708. This fixes > under ‘use integer’ when the same tied scalar is used for both operands and returns two different values. Before this commit, get-magic would be called only once and the same value used. In 5.12.x the operands were swapped.
* [perl #87708] use integer; $tied <= $tiedFather Chrysostomos2011-04-061-1/+1
| | | | | | | | | This is just part of #87708. This fixes <= under ‘use integer’ when the same tied scalar is used for both operands and returns two different values. Before this com- mit, get-magic would be called only once and the same value used. In 5.12.x the operands were swapped.
* [perl #87708] use integer; $tied >= $tiedFather Chrysostomos2011-04-061-1/+1
| | | | | | | | | This is just part of #87708. This fixes >= under ‘use integer’ when the same tied scalar is used for both operands and returns two different values. Before this com- mit, get-magic would be called only once and the same value used. In 5.12.x the operands were swapped.
* [perl #87708] use integer; $tied == $tiedFather Chrysostomos2011-04-061-1/+1
| | | | | | | | | This is just part of #87708. This fixes == under ‘use integer’ when the same tied scalar is used for both operands and returns two different values. Before this com- mit, get-magic would be called only once and the same value used. In 5.12.x it just worked.
* [perl #87708] use integer; $tied != $tiedFather Chrysostomos2011-04-061-1/+1
| | | | | | | | | This is just part of #87708. This fixes != under ‘use integer’ when the same tied scalar is used for both operands and returns two different values. Before this com- mit, get-magic would be called only once and the same value used. In 5.12.x it just worked.
* [perl #87708] use integer; $tied <=> $tiedFather Chrysostomos2011-04-061-1/+1
| | | | | | | | | This is just part of #87708. This fixes <=> under ‘use integer’ when the same tied scalar is used for both operands and returns two different values. Before this com- mit, get-magic would be called only once and the same value used. In 5.12.x, the operands would be reversed.
* [perl #87708] atan2 $tied, $tiedFather Chrysostomos2011-04-051-1/+1
| | | | | | | This fixes atan2 when the same tied scalar is used for both operands and returns two different values. Before this commit, get-magic would be called only once and the same value used. In 5.12.x, the operands would be reversed.
* [perl #87336] lc/uc(first) fail to taint the returned stringFather Chrysostomos2011-03-311-0/+6
| | | | | | | | | | | | | | | This bug was caused by change 28011 (ec9af7d), which stopped pp_lc from using sv_setsv_flags, thereby bypassing these two lines at the end of that function: if (SvTAINTED(sstr)) SvTAINT(dstr); Change 28012 (6730619) did exactly the same thing to pp_uc. 28013 (d54190f) broke ucfirst and lcfirst. This commit simply puts that taint logic at the end of the pp_* functions.
* [perl #82250] fix tainted (s)print formatDavid Mitchell2011-03-141-2/+0
| | | | | | | | | | | | commit 20ee07fbbcfa6be9f90bb8e5474a4d69d7396617 introduced dieing in (s)printf when the format is tainted; however it only worked when the format is part of an expression (because TAINT_PROPER checks for PL_tainted being set). Fix by doing TAINT_PROPER only after get magic has been done on the format SV (which will set PL_tainted). This is done by moving the checks in pp_sprintf and pp_prtf into do_sprintf() (which is called by the two pp functions).
* Fix [perl #85508] regression in print length undefDavid Leadbeater2011-03-061-4/+10
| | | | | | length was returning a temporary copy of undef, this meant it didn't generate a warning when used uninitialised. Return PL_sv_undef but also ensure TARG is cleared if needed.
* Move some #definesKarl Williamson2011-02-271-6/+0
| | | | | These were defined in a .c, but now there is need for them in another .c, so move them to a header.
* [perl #77692] substr causes panic: sv_len_utf8 cache...Father Chrysostomos2011-02-101-1/+2
| | | | | | | | | | | | | | | | | | | pp_substr contains this comment, which was added in perl 5.0 alpha 2 (commit 79072805bf63): PUSHs(TARG); /* avoid SvSETMAGIC here */ Calling set-magic when substr returns an lvalue will cause its argu- ment to be stringified even if the lvalue is not assigned to. That’s why set-magic has to be avoided. But the result is that utf8 caches (stored in magic) on TARG are not reset properly. Since substr lvalues now follow a different code path (and do not use TARG at all), it’s perfectly safe to call set-magic at this point. It’s also the right thing to do in case of other types of magic that might get attached to TARG.
* [perl #81750] Perl 5.12: undef-as-hashref bugFather Chrysostomos2011-01-211-1/+6
| | | | | | | | | | | | | | | | | The addition of the boolkeys op type in commit 867fa1e2d did not account for the fact that rv2hv (%{}) can sometimes return undef (%$undef with strict refs turned off). When the boolkeys op is created (and the rv2hv becomes its kid), the rv2hv is flagged with OPf_REF, meaning that it must return a hash, not the contents. Perl_softrefxv in pp.c checks for that flag. If it is set, it dies with ‘Can't use an undefined value as a HASH reference’ for unde- fined values. This commit changes it to make an exception if rv2hv->op_next is a boolkeys op. It also changes pp_boolkeys to account for undef.
* add GvCV_set() and GvGP_set() macros.David Mitchell2011-01-211-1/+1
| | | | | | | | and make GvCV() and GvGP() rvalue-only. This it to allow a future commit to eliminate some backref magic between GV and CVs, which will require complete control over assignment to the gp_cv slot.
* CH] Change usage of regex/op common to common namesKarl Williamson2011-01-161-1/+1
| | | | | | | | | This patch changes the core functions to use the common names for the fields that are shared between op.c and regcomp.c, just for consistency of using one name throughout the core for the same thing. A grep of cpan shows that both names are used in various modules; so both names must be retained.
* Use multi-bit field for regex character setKarl Williamson2011-01-161-4/+6
| | | | | | | | | | | | | The /d, /l, and /u regex modifiers are mutually exclusive. This patch changes the field that stores the character set to use more than one bit with an enum determining which one. This data structure more closely follows the semantics of their being mutually exclusive, and conserves bits as well, and is better expandable. A small API is added to set and query the bit field. This patch is not .xs source backwards compatible. A handful of cpan programs are affected.
* Generate "Unsupported socket function" stubs using PL_ppaddr.Nicholas Clark2011-01-091-0/+2
| | | | | | | | | | | | | | | Instead of having each socket op conditionally compile as either the implementation or a DIE() depending on #HAS_SOCKET 1: remove the conditional code from the ops themselves 2: only compile the ops if HAS_SOCKET is defined 3: general conditional code for the intialisation of PL_ppaddr - as appropriate either the ops, or Perl_unimplemented_op 4: Amend Perl_unimplemented_op to generate the appropriate DIE() for socket ops (ie not the "panic"... message) Whilst this complicates the support code in regen/opcode.pl, it's already a net saving of 5 lines in the C code.