summaryrefslogtreecommitdiff
path: root/scope.h
Commit message (Collapse)AuthorAgeFilesLines
* refactor Perl_leave_scopeDavid Mitchell2012-12-041-52/+71
| | | | | | | | | | | | | | | | | | | This is a large and hot function. The main problem with it is that there is code to pop a few args repeated in just about every branch. Also, there are a whole bunch of local vars (sv, av, hv, gv etc) that are never all used simultaneously, but are really just there for casting convenience. Together, they defeat the compiler's register allocation algorithms (well, they did for gcc anyway). We fix this by just declaring three general vars, arg0,1,2 of type ANY, and move the popping code to above the switch(). We sort the SAVEt_* indices in order of number of args, so it's quick to determine how many args we need to pop for a particular type. Together with the previous commits which added the SS_ADD_* macros, this reduces the size of scope.o (-O2, gcc x86_64) by about 9% (threaded) or 17% (unthreaded), and seems to speed up simple loops / function calls by around 5%.
* Add SS_ADD_* macros and replace most SSPUSH* usesDavid Mitchell2012-12-041-11/+52
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The current idiom for adding an entry to the savestack is SSCHECK(3); SSPUSHINT(...); SSPUSHPTR(...); SSPUSHUV(SAVEt_...); Replace this with a new idiom: { dSS_ADD; SS_ADD_INT(...); SS_ADD_PTR(...); SS_ADD_UV(SAVEt_...); SS_ADD_END(3); } This is designed to be more efficient. First, it defines some local vars, and defers updating PL_savestack_ix to the end. Second, it performs the 'is there space on the stack' check *after* pushing. Doing the check last means that values in registers will have been pushed and no longer needed, so don't need saving around the call to grow. Also, tail-call elimination of the grow() can be done. These changes reduce the code of something like save_pushptrptr() to half its former size. Of course, doing the size check *after* pushing means we must always ensure there are SS_MAXPUSH free slots on the savestack */
* Clear method caches when unwinding local *foo=sub{}Father Chrysostomos2012-11-291-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | local *foo=sub{} is done in two stages: • First the local *foo localises the GP (the glob pointer, or list of slots), setting a flag on the GV. • Then scalar assignment sees the flag on the GV on the LHS and loca- lises a single slot. The slot localisation only stores on the savestack a pointer into the GP struct and the old value. There is no reference to the GV. To restore a method properly, we have to have a reference to the GV when the slot localisation is undone. So in this commit I have added a new save type, SAVEt_GVSLOT. It is like SAVEt_GENERIC_SV, except it pushes the GV as well. Currently it is used only for CVs, but I will need it for HVs and maybe AVs as well. It is possible for the unwinding of the slot localisation to affect only a GV other than the one that is pushed, if glob assignments have taken place since the local *foo. So we have to check whether the pointer is inside the GP and use PL_sub_generation++ if it is not.
* save_freeop is not an expression, remove PL_XpvDaniel Dragan2012-11-151-12/+3
| | | | | | save_freeop and SAVEFREEOP are never used in expressions only statements. Using PL_Xpv is never ideal. For me .text section dropped from 0xC1DFF to 0xC1DBF after applying this.
* add SAVEt_CLEARPADRANGEDavid Mitchell2012-11-101-0/+1
| | | | | Add a new save type that does the equivalent of multiple SAVEt_CLEARSV's for a given target range. This makes the new padange op more efficient.
* Restore special blocks to working orderFather Chrysostomos2012-09-261-1/+3
| | | | | | | | | | | | | | | | | | I accidentally broke these in commit 85ffec3682, yet everything passed for me under threads+mad. PL_compcv is usually restored to its previous value at the end of newATTRSUB when LEAVE_SCOPE is called. But BEGIN blocks are called before that. I needed PL_compcv to be restored to its previ- ous value before it was called, so I added LEAVE_SCOPE before process_special_blocks. But that caused the name to be freed before S_process_special_blocks got a chance to look at it. So I have now added a new parameter to S_process_special_blocks to allow *it* to call LEAVE_SCOPE after it determines that it is a BEGIN block, but before it calls it.
* Revert "Set PL_comppad_name on sub entry"Father Chrysostomos2012-09-171-2/+1
| | | | This reverts commit d2c8bf052f5a8bb99050f6d2418d77151eb4b468.
* Set PL_comppad_name on sub entryFather Chrysostomos2012-09-151-1/+2
|
* Prevent double frees/crashes with format syntax errsFather Chrysostomos2012-08-081-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This was brought up in ticket #43425. The new slab allocator for ops (8be227ab5e) makes a CV responsible for cleaning up its ops if it is freed prematurely (before the root is attached). Certain syntax errors involving formats can cause the parser to free the CV owning an op when that op is on the PL_nextval stack. This happens in these cases: format = @ use; format strict . format = @ ;use strict . format foo require bar In the first two cases it is the line containing ‘strict’ that is being interpreted as a format picture line and being fed through force_next by S_scan_formline. Then the error condition kicks in after the force, causing a LEAVE_SCOPE in the parser (perly.c) which frees the sub owning the const op for the format picture. Then a token with a freed op is fed to the parser. To make this clearer, when the second case above is parsed, the tokens produced are as follows: format = [;] [formline] "@\n" [,] ; use [<word>] [;] [formline] <freed> [;] . Notice how there is an implicit semicolon before each (implicit) formline. Notice also how there is an implicit semicolon before the final dot. The <freed> thing represents the "strict\n" constant after it has been freed. (-DT displays it as THING(opval=op_freed).) When the implicit semicolon is emitted before a formline, the next two tokens (formline and the string constant for this format picture line) are put on to the PL_nextval stack via force_next. It is when the implicit semicolon before "strict\n" is emitted that the parser sees the error (there is only one path through the gram- mar that uses the USE token, and it must have two WORDs following it; therefore a semicolon after one WORD is an immediate error), calling LEAVE_SCOPE, which frees the sub created by ‘use’, which owns the const op on the PL_nextval stack containing the word "strict" and con- sequently frees it. I thought I could fix this by putting an implicit do { ... } around the argument line. (This would fix another bug, whereby the argument line in a format can ‘leak out’ of the formline(...).) But this does not solve anything, as we end up with four tokens ( } ; formline const ) on the PL_nextval stack when we emit the implicit semicolon after ‘use’, instead of two. format= @ ;use strict . will turn into format = [;] [formline] "@\n" [,] [do] [{] ; use [<word>] [;] [}] [;] [formline] "strict\n"/<freed> [;] . It is when the lexer reaches "strict" that it will emit the semicolon after the use. So we will be in the same situation as before. So fixing the fact that the argument line can ‘leak out’ of the formline and start a new statement won’t solve this particu- lar problem. I tried eliminating the LEAVE_SCOPE. (See <https://rt.perl.org/rt3/Ticket/Display.html?id=43425#txn-273447> where Dave Mitchell explains that the LEAVE_SCOPE is not strictly nec- essary, but it is ‘still good to ensure that the savestack gets cor- rectly popped during error recovery’.) That does not help, because the lexer itself does ENTER/LEAVE to make sure form_lex_state and lex_formbrack get restored properly after the lexer exits the format (see 583c9d5cccf and 64a408986cf). So when the final dot is reached, the ‘use’ CV is freed. Then an op tree that includes the now-freed "strict\n" const op is passed to newFORM, which tries to do op_free(block) (as of 3 commits ago; before that the errors were more catastrophic), and ends up freeing an op belonging to a freed slab. Removing LEAVE_SCOPE did actually fix ‘format foo require bar’, because there is no ENTER/LEAVE involved there, as the = (ENTER) has not been reached yet. It was failing because ‘require bar’ would call force_next for "bar", and then feed a REQUIRE token to the parser, which would immediately see the error and call LEAVE_SCOPE (free- ing the format), with the "bar" (belonging to the format’s slab) still pending. The final solution I came up with was to reuse an mechanism I came up with earlier. Since the savestack may cause ops to outlive their CVs due to SAVEFREEOP, opslab_force_free (called when an incomplete CV is freed prematurely) will skip any op with o->op_savestack set. The nextval stack can use the same flag. To make sure nothing goes awry (we don’t want the same op on the nextval stack and the savestack at the same time), I added a few assertions.
* Flag ops that are on the savestackFather Chrysostomos2012-06-291-1/+15
| | | | | | | | | This is to allow future commits to free dangling ops after errors. If an op is on the savestack, then it is going to be freed by scope.c, and op_free must not be called on it by anyone else. So we flag such ops new.
* Say goodbye to SAVECOPSTASHFather Chrysostomos2012-06-041-3/+2
| | | | This is undocumented and unused.
* [perl #78742] Store CopSTASH in a pad under threadsFather Chrysostomos2012-06-041-4/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Before this commit, a pointer to the cop’s stash was stored in cop->cop_stash under non-threaded perls, and the name and name length were stored in cop->cop_stashpv and cop->cop_stashlen under ithreads. Consequently, eval "__PACKAGE__" would end up returning the wrong package name under threads if the current package had been assigned over. This commit changes the way cops store their stash under threads. Now it is an offset (cop->cop_stashoff) into the new PL_stashpad array (just a mallocked block), which holds pointers to all stashes that have code compiled in them. I didn’t use the lexical pads, because CopSTASH(cop) won’t work unless PL_curpad is holding the right pad. And things start to get very hairy in pp_caller, since the correct pad isn’t anywhere easily accessible on the context stack (oldcomppad actually referring to the current comppad). The approach I’ve followed uses far less code, too. In addition to fixing the bug, this also saves memory. Instead of allocating a separate PV for every single statement (to hold the stash name), now all lines of code in a package can share the same stashpad slot. So, on a 32-bit OS X, that’s 16 bytes less memory per COP for short package names. Since stashoff is the same size as stashpv, there is no difference there. Each package now needs just 4 bytes in the stashpad for storing a pointer. For speed’s sake PL_stashpadix stores the index of the last-used stashpad offset. So only when switching packages is there a linear search through the stashpad.
* 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.
* [perl #113060] Save cop_stashlen threaded even with shared cop pvReini Urban2012-05-291-1/+2
| | | | | | | | | Perl_sv_compile_2op_is_broken() does at line 3354 a LEAVE_with_name("eval"), a SSPOPSTR via SAVEt_SHARED_PVREF for the localized cop_stashpv, but not for the cop_stashlen. The cop in question is PL_compiling, which was "AutoSplit" before with len=9 and restores it back to "main" but keeps len 9. Thus leading to a heap-overflow in gv_stashpvn.
* [perl #112316] Make strict vars respect assignment from null pkgFather Chrysostomos2012-04-191-1/+2
| | | | | | Under threads, strict vars was not respecting glob assignment from a package with a null in its name if the name of the package assigned to was equal to the prefix of the current package up to the null.
* remove index offsetting ($[)Zefram2011-09-091-3/+0
| | | | | | $[ remains as a variable. It no longer has compile-time magic. At runtime, it always reads as zero, accepts a write of zero, but dies on writing any other value.
* Fix typos (spelling errors) in Perl sources.Peter J. Acklam) (via RT2011-01-071-1/+1
| | | | | | | | | # New Ticket Created by (Peter J. Acklam) # Please include the string: [perl #81904] # in the subject line of all future correspondence about this issue. # <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=81904 > Signed-off-by: Abigail <abigail@abigail.be>
* add SAVEFREECOPHH()Zefram2010-10-281-0/+2
| | | | | Add the facility for the save stack to free (decrement the refcount of) a COPHH*.
* bad things happened with for $x (...) { *x = *y }David Mitchell2010-09-081-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | fix for [perl #21469]: since the GP may be pulled from under us and freed, coredumps and strange things can happen. Fix this by storing a pointer to the GV in the loop block, rather than a pointer to the GvSV slot. The ITHREADS variant already stores GV rather than than &GvSV; extend this to non-threaded builds too. Also, for both threaded and non-threaded, it used to push &GvSV on the save stack. Fix this by introducing a new save type, SAVEt_GVSV. This behaves similarly to SAVEt_SV, but without magic get/set. This means that for $package_var (...) is now close in behaviour to local $package_var = ... (except for the magic bit).
* When saving ints, if the value is small enough save it with the type.Nicholas Clark2010-05-051-0/+1
| | | | This uses a new type, SAVEt_INT_SMALL.
* When saving I32s, if the value is small enough save it with the type.Nicholas Clark2010-05-051-0/+1
| | | | This uses a new type, SAVEt_I32_SMALL.
* On the save stack, store the save type as the bottom 6 bits of a UV.Nicholas Clark2010-05-011-2/+7
| | | | This makes the other 26 (or 58) bits available for save data.
* remove bool* cast from SAVEBOOLDavid Mitchell2010-04-211-1/+1
| | | | | SAVEBOOL() should only be used on variables of type bool; casting pointers to variables of other types into bool* is just wrong.
* Skip the scope name checks if PL_scopestack_name is NULL.Nicholas Clark2009-11-181-4/+7
| | | | | | It's possible that someone has built a module with -DDEBUGGING, but they're using it against a perl built non-DEBUGGING, in which case PL_scopestack_name will be NULL. Better to skip the checks than to SEGV.
* Performance optimisation in assert, suggested by Tim BunceRafael Garcia-Suarez2009-11-151-1/+3
| | | | | | Most compilers will store only a single copy of identical literal strings. So changing that assert to check the pointer first would significantly reduce the cost.
* Add ENTER_with_name and LEAVE_with_name to automaticly check for matching ↵Gerard Goossen2009-11-121-0/+28
| | | | ENTER/LEAVE when debugging is enabled
* Introduce save_hdelete() and SAVEHDELETE()Vincent Pit2009-07-251-0/+2
| | | | save_hdelete() is just like save_delete() except that it takes an SV instead of char buffer.
* Add a new SAVEf_KEEPOLDELEM flag to save_scalar_at() and save_{a,h}elem_flags()Vincent Pit2009-07-251-0/+1
| | | | When set, save_scalar_at() doesn't replace the given SV by a fresh new one. local magic is not called in this case.
* Introduce save_aelem_flags()Vincent Pit2009-07-251-0/+1
| | | | It's the symmetric of save_helem_flags(). save_aelem() is now a macro wrapping around save_aelem_flags().
* The 2nd arg to save_alloc() must be cast to I32 to avoid pointer truncation ↵Jan Dubois2009-07-031-1/+1
| | | | warnings on 64-bit platforms.
* Add save_adelete()/SAVEADELETE() to save on the stack an array element deleteVincent Pit2008-12-281-0/+3
|
* Move the implmentation of SAVEHINTS() into a new Perl_save_hints() inNicholas Clark2008-12-011-16/+1
| | | | | | scope.c. "Inlined" macro functions in scope.h are actually space inefficient. p4raw-id: //depot/perl@34965
* For SAVEHINTS(), re-order the savestack to be (?:PTR, )? INT, PTR.Nicholas Clark2008-12-011-6/+6
| | | | | This brings it to the same order as save_aelem() or save_pushi32ptr(). p4raw-id: //depot/perl@34964
* Expose save_pushi32ptr() and implement SAVECOPARYBASE() with it.Nicholas Clark2008-12-011-7/+1
| | | p4raw-id: //depot/perl@34963
* Expose save_pushptrptr() and implement SAVESWITCHSTACK() with it.Nicholas Clark2008-12-011-4/+1
| | | p4raw-id: //depot/perl@34960
* Re-implement the macros SAVECOMPPAD(), SAVECOMPILEWARNINGS(),Nicholas Clark2008-11-301-18/+3
| | | | | | | SAVEPARSER() in terms of save_pushptr(). This shinks the exectuable by about 4K. Maybe some of the other scope.h macros should become functions. p4raw-id: //depot/perl@34958
* Convert all the scope save functions of the formNicholas Clark2008-11-301-0/+6
| | | | | | | | | SSCHECK(2); SSPUSHPTR(o); SSPUSHINT(SAVEt_FREEOP); into a single function Perl_save_pushptr(ptr, type), which the others call. Implement the others as macros. This reduces the object code size. p4raw-id: //depot/perl@34956
* Re: [perl #60360] [PATCH] UPDATED: local $SIG{FOO} = sub {...}; sets signal ↵Chip Salzenberg2008-11-131-0/+4
| | | | | | | | | | | | handler to SIG_DFL Message-ID: <20081112234504.GI2062@tytlal.topaz.cx> Updated patch to retain source compatibility. Plus using the correct PERL_ARGS_ASSERT_SAVE_HELEM_FLAGS macro and running make regen. p4raw-id: //depot/perl@34829
* Add MUTABLE_HV(), and remove (HV *) casts from headers.Nicholas Clark2008-10-281-1/+1
| | | p4raw-id: //depot/perl@34619
* Add a macro MUTABLE_PTR(p), which on (non-pedantic) gcc will not castNicholas Clark2008-10-271-5/+5
| | | | | | | | | | away const, returning a void *. Add MUTABLE_SV(sv) which uses this, and replace all (SV *) casts either with MUTABLE_SV(sv), or (const SV *). This probably still needs some work - assigning to SvPVX() and SvRV() is now likely to generate a casting error. The core doesn't do this. But as-is it's finding bugs that can be fixed. p4raw-id: //depot/perl@34605
* Update copyright years.Nicholas Clark2008-10-251-2/+2
| | | p4raw-id: //depot/perl@34585
* A macro used only once isn't a typing saving, and 3 macro definitionsNicholas Clark2008-04-061-4/+0
| | | | | | | never used are more obfuscation than clarification, so inline the only use of SAVECOPLABEL_FREE(), and remove the unthreaded variant and both SAVECOPLABEL()s. Exterminate! Exterminate! Exterminate! p4raw-id: //depot/perl@33654
* Investigation reveals that the work of restoring the iterator to theNicholas Clark2008-01-261-2/+2
| | | | | | | | | | | | | | | | | pad is shared between POPLOOP, using itersave, and the end of scope restore action requested by Perl_save_padsv(). In fact, the only user of SAVEt_PADSV is pp_enteriter, and it already provides enough information to allow it to perform the sv_2mortal() in POPLOOP. So make it do so. Rather than creating a new routine, use the existing routine because nothing else (at least nothing else known to Google's codesearch) uses it. But rename it just in case something we can't see is being naughty and using our private functions - they will get link errors against 5.12. All this means that itersave is now redundant. So remove it. This makes struct context 48 bytes on ILP32 platforms with 32bit IVs, down from 64 bytes in 5.10. 33% more context stack in the same memory. p4raw-id: //depot/perl@33080
* Add editor blocks to some header files.Marcus Holland-Moritz2008-01-011-0/+9
| | | p4raw-id: //depot/perl@32793
* Update copyright years in .h files. Also, in .plRafael Garcia-Suarez2007-01-051-1/+1
| | | | | | files that generate .h files, so they'll be ready next time. p4raw-id: //depot/perl@29695
* handle cloning of parsers on the save stackDave Mitchell2007-01-031-0/+8
| | | p4raw-id: //depot/perl@29678
* Re: [PATCH] do not meddle in the affairs of PERL_TRACK_MEMPOOLJarkko Hietaniemi2006-12-181-0/+4
| | | | | | | Message-ID: <4586084E.8040706@iki.fi> Introduce CopLABEL() macro to deal with labels attached to COPs. p4raw-id: //depot/perl@29585
* [perl #40557] regexec.c saves context stack position improperly Dave Bailey2006-10-181-0/+9
| | | | | | From: Dave Bailey (via RT) <perlbug-followup@perl.org> Message-ID: <rt-3.5.HEAD-4979-1161103047-337.40557-75-0@perl.org> p4raw-id: //depot/perl@29033
* Rename cop_hints to cop_hints_hashNicholas Clark2006-05-201-3/+3
| | | p4raw-id: //depot/perl@28252
* Re: [PATCH] cleanup 212 warnings emitted by gcc-4.2Marcus Holland-Moritz2006-04-261-2/+2
| | | | | Message-ID: <20060424232038.7550f9b6@r2d2> p4raw-id: //depot/perl@27962