summaryrefslogtreecommitdiff
path: root/pp.h
Commit message (Collapse)AuthorAgeFilesLines
...
* perlapi: Consistent spaces after dotsFather Chrysostomos2013-12-291-1/+1
| | | | plus some typo fixes. I probably changed some things in perlintern, too.
* Extend STRESS_REALLOC to move the stack with every EXTENDFather Chrysostomos2013-11-221-2/+12
| | | | | | This allows us easily to catch cases where the stack could move to a new memory address while code still holds pointers to the old loca- tion. Indeed, this causes test failures.
* Eliminate POPq, POPuq, TOPq, TOPuq, dPOPqv, dTOPqv, qPOPuqv, dTOPuqv.Nicholas Clark2013-09-171-14/+0
| | | | | | These shortcut macros are unused in the core, and unused by any code on CPAN. If any XS code we can't see *is* using them, it will now fail to compile, and can easily be fixed by replacing the macros with their expansion.
* Use SSize_t for arraysFather Chrysostomos2013-08-251-2/+2
| | | | | | | | | | Make the array interface 64-bit safe by using SSize_t instead of I32 for array indices. This is based on a patch by Chip Salzenberg. This completes what the previous commit began when it changed av_extend.
* Use SSize_t when extending the stackFather Chrysostomos2013-08-251-4/+4
| | | | | | | | | | | | | | | | (I am referring to what is usually known simply as The Stack.) This partially fixes #119161. By casting the argument to int, we can end up truncating/wrapping it on 64-bit systems, so EXTEND(SP, 2147483648) translates into EXTEND(SP, -1), which does not extend the stack at all. Then writing to the stack in code like ()=1..1000000000000 goes past the end of allocated memory and crashes. I can’t really write a test for this, since instead of crashing it will use more memory than I have available (and then I’ll start for- getting things).
* (UN)LIKELY branch prediction hints in a few strategic placesSteffen Mueller2013-03-061-7/+7
| | | | | | | | This adds branch prediction hints to a few strategic places such as growing stack or strings, some exception handling, and a few hot functions such as sv_upgrade. This is not exhaustive by any means.
* Remove the second param to tryAMAGICunTARGETlistFather Chrysostomos2012-12-091-3/+2
| | | | This parameter is no longer used. Its value is always 0.
* pp.h: Remove tryAMAGICunTARGETFather Chrysostomos2012-12-091-7/+4
| | | | | This macro is unused on CPAN and completely undocumented, so this change should be safe.
* Remove "register" declarationsKarl Williamson2012-11-241-1/+1
| | | | | | | This finishes the removal of register declarations started by eb578fdb5569b91c28466a4d1939e381ff6ceaf4. It neglected the ones in function parameter declarations, and didn't include things in dist, ext, and lib, which this does include
* Fix format closure bug with redefined outer subFather Chrysostomos2012-08-211-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | CVs close over their outer CVs. So, when you write: my $x = 52; sub foo { sub bar { sub baz { $x } } } baz’s CvOUTSIDE pointer points to bar, bar’s CvOUTSIDE points to foo, and foo’s to the main cv. When the inner reference to $x is looked up, the CvOUTSIDE chain is followed, and each sub’s pad is looked at to see if it has an $x. (This happens at compile time.) It can happen that bar is undefined and then redefined: undef &bar; eval 'sub bar { my $x = 34 }'; After this, baz will still refer to the main cv’s $x (52), but, if baz had ‘eval '$x'’ instead of just $x, it would see the new bar’s $x. (It’s not really a new bar, as its refaddr is the same, but it has a new body.) This particular case is harmless, and is obscure enough that we could define it any way we want, and it could still be considered correct. The real problem happens when CVs are cloned. When a CV is cloned, its name pad already contains the offsets into the parent pad where the values are to be found. If the outer CV has been undefined and redefined, those pad offsets can be com- pletely bogus. Normally, a CV cannot be cloned except when its outer CV is running. And the outer CV cannot have been undefined without also throwing away the op that would have cloned the prototype. But formats can be cloned when the outer CV is not running. So it is possible for cloned formats to close over bogus entries in a new parent pad. In this example, \$x gives us an array ref. It shows ARRAY(0xbaff1ed) instead of SCALAR(0xdeafbee): sub foo { my $x; format = @ ($x,warn \$x)[0] . } undef &foo; eval 'sub foo { my @x; write }'; foo __END__ And if the offset that the format’s pad closes over is beyond the end of the parent’s new pad, we can even get a crash, as in this case: eval 'sub foo {' . '{my ($a,$b,$c,$d,$e,$f,$g,$h,$i,$j,$k,$l,$m,$n,$o,$p,$q,$r,$s,$t,$u)}'x999 . q| my $x; format = @ ($x,warn \$x)[0] . } |; undef &foo; eval 'sub foo { my @x; my $x = 34; write }'; foo(); __END__ So now, instead of using CvROOT to identify clones of CvOUTSIDE(format), we use the padlist ID instead. Padlists don’t actually have an ID, so we give them one. Any time a sub is cloned, the new padlist gets the same ID as the old. The format needs to remember what its outer sub’s padlist ID was, so we put that in the padlist struct, too.
* pp.h: Make [TP]OPp and [TP]OPpx identicalFather Chrysostomos2012-07-271-4/+5
| | | | | | In the absence of n_a (see 8c074e2a and 95fad918), there is no differ- ence between [TP]OPp and [TP]OPpx except speed, so there is no reason for the x-less variant to be deprecated.
* Use find_runcv_where for pp_coreargs and pp_runcvFather Chrysostomos2012-07-021-0/+1
|
* Make formats close over the right closureFather Chrysostomos2012-06-291-0/+2
| | | | | | | | | | | | | | | | | This was brought up in ticket #113812. Formats that are nested inside closures only work if invoked from directly inside that closure. Calling the format from an inner sub call won’t work. Commit af41786fe57 stopped it from crashing, making it work as well as 5.8, in that closed-over variables would be undefined, being unavailable. This commit adds a variation of the find_runcv function that can check whether CvROOT matches an argument passed in. So we look not for the current sub, but for the topmost sub on the call stack that is a clone of the closure prototype that the format’s CvOUTSIDE field points to.
* propagate context into overloads [perl #47119]Jesse Luehrs2012-06-281-7/+28
| | | | | | | | | | | | | | | | | amagic_call now does its best to propagate the operator's context into the overload callback. It's not always possible - for instance, dereferencing and stringify/boolify/numify always have to return a value, even if it's not used, due to the way the overload callback works in those cases - but the majority of cases should now work. In particular, overloading <> to handle list context properly is now possible. For backcompat reasons (amagic_call and friends are technically public api functions), list context will not be propagated unless specifically requested via the AMGf_want_list flag. If this is passed, and the operator is called in list context, amagic_call returns an AV* holding all of the returned values instead of an SV*. Void context always results in amagic_call returning &PL_sv_undef.
* [perl #112966] Crash on delete local; other local bugsFather Chrysostomos2012-06-231-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Commit bee7c5743fa appears to have fixed this. But what it does is barely significant: diff --git a/sv.c b/sv.c index b96f7c1..a4994f5 100644 --- a/sv.c +++ b/sv.c @@ -9525,6 +9525,11 @@ Perl_sv_bless(pTHX_ SV *const sv, HV *const stash) SvUPGRADE(tmpRef, SVt_PVMG); SvSTASH_set(tmpRef, MUTABLE_HV(SvREFCNT_inc_simple(stash))); + if (Gv_AMG(stash)) + SvAMAGIC_on(sv); + else + (void)SvAMAGIC_off(sv); + if(SvSMAGICAL(tmpRef)) if(mg_find(tmpRef, PERL_MAGIC_ext) || mg_find(tmpRef, PERL_MAGIC_uvar)) mg_set(tmpRef); The crash can still be triggered another way. Instead of a blessing, we need to modify a method (to turn on the potentially-overloaded flag) and then use an operator that respects overloading. This exam- ple crashes before and after bee7c5743fa: eval 'sub Sample::foo {}'; "".bless {},'Sample'; delete local $Sample::{ '()' }; It is the recalculation of overload caches before a localised deletion that causes the crash. And it only happens when the '()' key does not exist. Actually, it turns out that S_delete_local doesn’t behave correctly for rmagical aggregates, except for %ENV: $ ./perl -Ilib -MDevel::Peek -e 'delete local $ISA[0]' Bus error $ ./perl -XIlib -MDevel::Peek -e '??; delete local $::{foo}' Bus error It’s this line, which occurs twice in pp.c:S_do_delete_local, which is at fault: const bool can_preserve = SvCANEXISTDELETE(osv) || mg_find((const SV *)osv, PERL_MAGIC_env); When can_preserve is true, the ‘preeminent’ variable is set based on whether the element exists. Otherwise it is set to true. Why the term ‘preeminent’ was chosen I don’t know, but in this case it means that the element already exists, so it has to be restored after- wards. We can’t just do save_delete. The code for saving a hash element assumes it is non-null, and crashes otherwise. The logic for setting can_preserve is wrong. SvCANEXISTDELETE returns true for non-magical variables and for variables with those tie meth- ods implemented. For magical variables that are not tied, it returns the wrong answer. PERL_MAGIC_env seems to have been added as an exception, to keep it working. But other magical aggregates were not accounted for. This logic was copied from other functions (aslice, hslice, etc.), which are similarly buggy, but they don’t crash: $ ./perl -Ilib -le ' { local $::{foo} } print exists $::{foo}' $ ./perl -Ilib -le 'm??; { local $::{foo} } print exists $::{foo}' 1 In all these cases, it is SvCANEXISTDELETE that is buggy. So this commit fixes it and adds tests for all the code paths that use it. Now no exception needs to be made for PERL_MAGIC_env.
* update the editor hints for spaces, not tabsRicardo Signes2012-05-291-2/+2
| | | | | This updates the editor hints in our files for Emacs and vim to request that tabs be inserted as spaces.
* Fix non-GCC compilationFather Chrysostomos2012-05-211-4/+3
| | | | I mistakenly thought XPUSHs(...) was an expression. Now it is.
* pp.h: Missing macro parenthesesFather Chrysostomos2012-05-211-1/+1
| | | | This wasn’t affecting anything, but was a bug waiting to happen.
* [perl #44895] += warning on uninit magic varFather Chrysostomos2012-01-091-1/+1
| | | | | | | | | | | | | | The only uses of USE_LEFT in core now occur when SvGETMAGIC has already been called. So returning true for magical SVs is not neces- sary. In fact, it was never correct. Also, the code in do_vop (which handles bitwise operations on strings) to avoid an uninitialized warning had the same buggy SvGMAGICAL check. Now, the warning from $uninit += 1 is suppressed for all undefined vars, not just amagical ones. This causes 6 to-do tests in assignwarn.t to pass.
* Remove magical dPOPXnnrl_ul dPOPXiirl_ul macrosFather Chrysostomos2012-01-091-12/+0
| | | | | | These are undocumented and unused on CPAN and in the core. The core now uses _nomg variants.
* Make filetest ops handle get-magic correctly for glob(ref)sFather Chrysostomos2011-09-101-2/+4
| | | | | | This patch uses the recently-added MAYBE_DEREF_GV macro which puts the glob deref logic in one spot. It also adds _nomg and _flags varia- tions of it. _flags understands the SV_GMAGIC flag.
* Don’t call get-magic on a referenced array in chdir, etc.Father Chrysostomos2011-09-101-1/+2
| | | | | | | | | | | | Commit 557fbd17eb added the MAYBE_DEREF_GV macro, which 2ea1cce applied to chdir, chmod and chown. That macro calls get-magic on its arguments checks to see if it might be a gv or ref and, if it’s a ref, calls get-magic on the referent, to see whether it will turn into a gv. That means we’ll end up with chdir($array_obj) calling get-magic on the array. While probably harmless, calling get-magic is superfluous and probably incorrect. I don’t know that there is a reasonable way to test this.
* Add MAYBE_DEREF_GV macroFather Chrysostomos2011-09-101-0/+13
| | | | | | | | | | | | | | | | | There are so many parts of the core (mostly pp functions or functions they call) that need a glob or a globref, including many that call get-magic at the wrong time (or not at all in some cases, that it makes sense to add a macro to do it. It can be used like this: if (gv = MAYBE_DEREF_GV(sv)) /* calls get-magic */ { } else { /* avoid magic here */ }
* Fix overloaded <> when the peephole optimiser is disabled.Gerard Goossen2011-09-011-1/+5
|
* Revert parts of c31c291..96b6b87Father Chrysostomos2011-04-081-10/+3
| | | | | | | | | | | | | | | 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.
* [perl #87708] Fix ‘$tied binop $tied’Father Chrysostomos2011-04-071-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | The short story: In 5.13.1 or .2 these ops started calling get-magic just once if the same gmagical scalar was used for both operands. Then the same value would be used on both sides. In 5.12 FETCH would be called twice with both return values used, but they would be swapped in most cases (so $t/$t would return 1.5 if $t returned 2 and then 3). Now FETCH is called twice and the two operands are used in the right order. Up till now there have been patches to fix specific ops, but I real- ised that the same ten or so lines of code would have to be added to the rest of the 20+ pp_ functions, all of which use tryAMAGICbin_MG (which calls Perl_try_amagic_bin in gv.c), so it made sense to add the code to Perl_try_amagic_bin instead. This fixes all the ops in one fell swoop. The code in question checks whether the left and right operands are the same gmagical scalar. If so, it copies the scalar into a new mor- tal one, and then calls get-magic on the original operand to get its new value (for the rhs). The new scalar is placed just below the top of the stack, so it becomes the left operand. This does slow down the bitwise integer ops slightly, but only in this rare edge case. And the simplification of the code seems worth it. Forthcoming are commits that revert some of the changes already made, as this commit renders them unnecessary.
* [perl #87708] $tied % $tied and $tied * $tied under use integerFather Chrysostomos2011-04-061-4/+0
| | | | | | | | | | | | | | | | | 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] $tied + $tied and $tied - $tied under ‘use integer’Father Chrysostomos2011-04-061-2/+3
| | | | | | | | | This is just part of #87708. This fixes + and - 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 + just worked but the operands were swapped for -.
* [perl #87708] use integer; $tied <=> $tiedFather Chrysostomos2011-04-061-0/+5
| | | | | | | | | 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-0/+5
| | | | | | | 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.
* Convert tied PRINT to using Perl_tied_method()Nicholas Clark2011-01-051-0/+1
| | | | | Add a flag TIED_METHOD_SAY to Perl_tied_method(), to allow tied PRINT to effect C<local $\ = "\n";> within the ENTER/LEAVE pair of Perl_tied_method().
* Rename tied_handle_method() to tied_method(), and make it non-static.Nicholas Clark2011-01-051-0/+8
| | | | It can be used for (at least) the call to "SPLICE" from pp_splice.
* reindent tryAMAGICunTARGET after previous changeDavid Mitchell2011-01-031-20/+20
|
* simplify tryAMAGICunTARGETDavid Mitchell2011-01-031-5/+1
| | | | | Expecting the targ in sp[-1] rather than sp[0] is accomplished cleanly using dATARGET.
* make <expr> always overload if expr is overloadedDavid Mitchell2011-01-021-2/+7
| | | | | | | | Due to the way that '<> as glob' was parsed differently from '<> as filehandle' from 5.6 onwards, something like <$foo[0]> didn't handle overloading, even where $foo[0] was an overloaded object. This was contrary to the docs for overload, and meant that <> couldn't be used as a general overloaded iterator operator.
* overloaded <> sometimes left an extra stack argDavid Mitchell2011-01-021-0/+2
|
* standardise amagic method namingDavid Mitchell2010-12-311-3/+6
| | | | | | | | | | | | | | Some amagic-related macros take the full method enumeration name, (e.g. "add_amg"); while others "helpfully" allow you to pass a shortened version, ("add"), and do a CAT2(meth,_amg) behind the scenes. Standardise on passing the full name; this makes it less confusing and allows you to grep for the enumeration name in the source. It updates two macros to accept full enumeration names: tryAMAGICunTARGET (which isn't used outside the core apparently), and AMG_CALLun, which is replaced by a new AMG_CALLunary (since AMG_CALLun is used outside the core).
* Fix error in tryAMAGICunDEREF() introduced in 25a9ffce153b0e67.Nicholas Clark2010-11-091-1/+1
| | | | tryAMAGICunDEREF() isn't used anywhere in the core. Add tests for it.
* Inline tryAMAGICunDEREF_var() into its callers and eliminate it.Nicholas Clark2010-11-031-4/+4
| | | | Nothing outside the core was using this macro.
* Add Perl_amagic_deref_call() to implement the bulk of tryAMAGICunDEREF_var().Nicholas Clark2010-11-031-15/+2
| | | | | | | | | This removes around 300 bytes of object code from each place it was previously inlined. It also provides a better interface - quite a lot of the core currently bodges things by creating a local variable C<SV **sp = &sv> to use the macro. Change the XS::APItest wrapper to amagic_deref_call().
* Inline RvDEEPCP() into its only caller, Perl_amagic_call().Nicholas Clark2010-11-021-12/+0
| | | | | | | Only Perl_amagic_call() was using RvDEEPCP() when it was added in 5.000, and I believe that it's never had any other users (in the core, on CPAN, or anywhere else visible to Google codesearch). Hence it seems an ideal candidates to be inlined and eliminated.
* Implement the loop in tryAMAGICunDEREF_var() using while, rather than goto.Nicholas Clark2010-11-021-7/+7
| | | | | | | | Yes, it was a while loop implemented using goto, although this only became clear by untangling the macros. I believe it need never have been implemented as goto, given that the other user of tryAMAGICunW_var "broke" out of the "if"'s block using a return, hence that "if" could have been a "while" all along.
* Expand AMG_CALLun_var() into all its users, and eliminate it.Nicholas Clark2010-11-021-6/+6
| | | | | Aside from the 2 callers where it can be replaced with AMG_CALLun(). AMG_CALLun_var was only used in core.
* Inline tryAMAGICunW_var() into macros tryAMAGICun{DEREF_var,TARGET}Nicholas Clark2010-11-021-28/+36
| | | | | | | This also inlines and eliminates FORCE_SETs and setAGAIN. The three eliminated macros were not referenced from anywhere else. (The core, CPAN, code visible to Google codesearch.)
* Eliminate tryAMAGICunW() by refactoring tryAMAGICun{DEREF,TARGET}Nicholas Clark2010-11-021-4/+2
| | | | | tryAMAGICunW was only used within pp.h itself, and not referenced from anywhere else. (The core, CPAN, code visible to Google codesearch.)
* Remove unused AMAGIC macros from pp.h. Neither core nor CPAN uses any.Nicholas Clark2010-11-021-71/+0
| | | | | | | | | | | | | | | | | | | | Since commit 6f1401dc2acd2a2b, many AMAGIC macros in pp.h are no longer used in core, nor in modules or CPAN, nor in code visible to Google codesearch. Specifically: tryAMAGICbinW_var tryAMAGICbinW tryAMAGICbin_var tryAMAGICbin tryAMAGICbinSET tryAMAGICbinSET_var tryAMAGICbinW_var AMG_CALLbinL tryAMAGICun_var tryAMAGICun tryAMAGICunSET_var tryAMAGICunSET tryAMAGICftest
* Return DIE(...) to *return*ing Perl_die(...).Nicholas Clark2010-06-271-1/+1
| | | | | | | | | Much simplification ensues - witness the diffstat. Changes Perl_die_unwind() to use Perl_croak() rather than DIE(). Reverses an unwise part of bb4c52e023e0fcad. Reverts 9e95c6350a60744d and 805bf316c58ab2d7.
* make overload respect get magicDavid Mitchell2010-05-211-0/+34
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In most places, ops checked their args for overload *before* doing mg_get(). This meant that, among other issues, tied vars that returned overloaded objects wouldn't trigger calling the overloaded method. (Actually, for tied and arrays and hashes, it still often would since mg_get gets called beforehand in rvalue context). This patch does the following: Makes sure get magic is called first. Moves most of the overload code formerly included by macros at the start of each pp function into the separate helper functions Perl_try_amagic_bin, Perl_try_amagic_un, S_try_amagic_ftest, with 3 new wrapper macros: tryAMAGICbin_MG, tryAMAGICun_MG, tryAMAGICftest_MG. This made the code 3800 bytes smaller. Makes sure that FETCH is not called multiple times. Much of this bit was helped by some earlier work from Father Chrysostomos. Added new functions and macros sv_inc_nomg(), sv_dec_nomg(), dPOPnv_nomg, dPOPXiirl_ul_nomg, dPOPTOPnnrl_nomg, dPOPTOPiirl_ul_nomg dPOPTOPiirl_nomg, SvIV_please_nomg, SvNV_nomg (again, some of these were based on Father Chrysostomos's work). Fixed the list version of the repeat operator (x): it now only calls overloaded methods for the scalar version: (1,2,$overloaded) x 10 no longer erroneously calls x_method($overloaded,10)) The only thing I haven't checked/fixed yet is overloading the iterator operator, <>.
* avoid use of operator name in macroRobin Barker2010-04-261-0/+1
|
* Fix [perl #74542] 5.12.0 crash on diverse platformsRafael Garcia-Suarez2010-04-211-1/+2
| | | | | | Filetest ops don't always expect an op on the stack, so we should use TOPs only if we're sure that we're not stat'ing the _ filehandle. This is indicated by OPf_KIDS (as checked in ck_ftst).