summaryrefslogtreecommitdiff
path: root/pad.c
Commit message (Collapse)AuthorAgeFilesLines
* Correct pad.c pod: PadARRAY, not PAD_ARRAYFather Chrysostomos2018-01-181-1/+1
|
* Fix broken POD markup in perlapi/Pad Data StructuresDagfinn Ilmari Mannsåker2018-01-161-1/+1
|
* assert nested CV existence when freeing CVZefram2017-12-301-2/+4
| | | | | | | [perl #131631] has a convoluted test case that messes up parser error recovery and causes a segv via null pointer dereference. Turn the segv into an assertion failure, by asserting non-nullness of the pointer. This doesn't fix the actual problem with error recovery.
* put shadowing warnings in their own categoryZefram2017-12-061-4/+4
| | | | As proposed in [perl #125330].
* [perl #129916] Allow sub-in-stash outside of mainFather Chrysostomos2017-10-081-1/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The sub-in-stash optimization introduced in 2eaf799e only applied to subs in the main stash, not in other stashes, due to a problem with the logic in newATTRSUB. This comment: Also, we may be called from load_module at run time, so PL_curstash (which sets CvSTASH) may not point to the stash the sub is stored in. explains why we need the PL_curstash != CopSTASH(PL_curcop) check. (Perl_load_module will fail without it.) But that logic does not work properly at compile time (when PL_curcop == &PL_compiling). The value of CopSTASH(&PL_compiling) is never actually used. It is always set to the main stash. So if we check that PL_curstash != CopSTASH(PL_curcop) and forego the optimization in that case, we will never optimize subs outside of the main stash. What we really need is to check IN_PERL_RUNTIME && PL_curstash != opSTASH(PL_curcop). I.e., forego the optimization at run time if the stashes differ. That is what this commit implements. One observable side effect of this change is that deleting a stash element no longer anonymizes the CV if the CV had no GV that it was depending on to provide its name. Since the main thing in such situa- tions is that we do not get a crash, I think this change (arguably an improvement) is acceptable.) ----------- A bit of explanation of various other changes: gv.c:require_tie_mod needed a bit of help, since it could not handle sub refs in stashes. To keep localisation of stash elements working the same way, local($Stash::{foo}) now upgrades a coderef to a full GV before the localisation. (Changes in two pp*.c files and in scope.c:save_gp.) t/op/stash.t contains a test that makes sure that perl does not crash when a GV with a CV pointing to it gets deleted. This commit tweaks the test so that it continues to test that. (There has to be a GV for the test to test what it is meant to test.) Similarly with t/uni/caller.t and t/uni/stash.t. op.c:rv2cv_op_cv with the _MAYBE_NAME_GV flag was returning the cal- ling GV in those cases where a GV-less sub is called via a GV. E.g., *main = \&Foo::foo; main(). This meant that errors like ‘Not enough arguments’ were giving the wrong sub name. newATTRSUB was not calling mro_method_changed_in when storing a sub as an RV. gv_init needs to arrange for the new GV to have the file and line num- ber corresponding to the sub in it. These are taken from CvSTART, which may be off by a few lines, but is the closest we have to the place the sub was declared.
* pad.c: comment typoFather Chrysostomos2017-07-021-1/+1
|
* pad.c: POD typoFather Chrysostomos2017-07-021-1/+1
|
* Deprecating the modifyable variables in constants by 5.32.Abigail2017-01-161-1/+2
| | | | It was already deprecated, but we're now adding a version number.
* Change white space to avoid C++ deprecation warningKarl Williamson2016-11-181-29/+29
| | | | | | | | | | | | | | | | | | | | | | C++11 requires space between the end of a string literal and a macro, so that a feature can unambiguously be added to the language. Starting in g++ 6.2, the compiler emits a warning when there isn't a space (presumably so that future versions can support C++11). Unfortunately there are many such instances in the perl core. This commit fixes those, including those in ext/, but individual commits will be used for the other modules, those in dist/ and cpan/. This commit also inserts space at the end of a macro before a string literal, even though that is not deprecated, and removes useless "" literals following a macro (instead of inserting a blank). The result is easier to read, making the macro stand out, and be clearer as to the intention. Code and modules included with the Perl core need to be compilable using C++. This is so that perl can be embedded in C++ programs. (Actually, only the hdr files need to be so compilable, but it would be hard to test that just the hdrs are compilable.) So we need to accommodate changes to the C++ language.
* Eliminate xpad_cop_seq from _xnvu unionDavid Mitchell2016-09-271-2/+2
| | | | | | | | | | | | | PVNV's used to be used to hold pad names (like '$lex'), but aren't used for this purpose any more. So eliminate the xpad_cop_seq part of the union. Since S_scan_subst() was using xnv_u.xpad_cop_seq.xlow to store a temporary line count, add a new union member for that. The main usage of this field on CPAN is to define COP_SEQ_RANGE_LOW()-style macros, so if the module is still using xpad_cop_seq for that purpose, it's already broken.
* make PL_ pad vars be of type PADOFFSETDavid Mitchell2016-09-261-36/+34
| | | | | | | | | | | | | | | | | | Now that that PADOFFSET is signed, make PL_comppad_name_fill PL_comppad_name_floor PL_padix PL_constpadix PL_padix_floor PL_min_intro_pending PL_max_intro_pending be of type PADOFFSET rather than I32, to match the rest of the pad interface. At the same time, change various I32 local vars in pad.c functions to be PADOFFSET.
* remove a bunch of XXX's from pad.cDavid Mitchell2016-09-261-38/+0
| | | | | | | | | | | | | | | | When in 2002 I moved a bunch of code from op.c etc into a new file, pad.c, I left this comment at the top: /* XXX DAPM * As of Sept 2002, this file is new and may be in a state of flux for * a while. I've marked things I intent to come back and look at further * with an 'XXX DAPM' comment. */ Well, 12 years have passed since then, and if I was going to do any of this stuff I would probably have done it by now, or someone else would. So this commit removes the XXX's.
* pad.c comments: clarify PERL_PADSEQ_INTRODavid Mitchell2016-09-261-2/+8
|
* fix builds under USE_PAD_RESETDavid Mitchell2016-09-261-1/+1
| | | | It had suffered some bitrot.
* pad.c:pad_fixup_inner_anons: Add assertionsFather Chrysostomos2016-09-101-0/+2
| | | | | These would have made it easier to track down the bug fixed by the previous commit.
* signatures: eliminate XSIGVAR, add KEY_sigvarDavid Mitchell2016-08-181-1/+4
| | | | | | | | | | | | | | When I moved subroutine signature processing into perly.y with v5.25.3-101-gd3d9da4, I added a new lexer PL_expect state, XSIGVAR. This indicated, when about to parse a variable, that it was a signature element rather than a my variable; in particular, it makes ($,...) be toked as the lone sigil '$' rather than the punctuation variable '$,'. However this is a bit heavy-handled; so instead this commit adds a new allowed pseudo-keyword value to PL_in_my: as well as KEY_my, KEY_our and KEY_state, it can now be KEY_sigvar. This is a less intrusive change to the lexer.
* Remove find_rundefsv2Father Chrysostomos2015-09-291-18/+0
| | | | | It was never public, and was only written for the sake of pp_coreargs, which no longer uses it.
* Gut public rundefsv functionsFather Chrysostomos2015-09-291-23/+10
| | | | | As long as the lexical $_ syntax is disabled anyway, this is what they would return.
* perlapi: Change slightly weird constructKarl Williamson2015-09-031-1/+1
| | | | | As a native English speaker, I find it clearer to say that a bit vector has a particular bit set, rather than to say that it includes that bit.
* perlapi use 'UTF-8' instead of variants of thatKarl Williamson2015-09-031-1/+1
|
* perlapi: Add some S<>Karl Williamson2015-09-031-1/+1
| | | | | so that these constructs appear on a single output line for reader convenience.
* Various pods: Add C<> around many typed-as-is thingsKarl Williamson2015-09-031-45/+46
| | | | Removes 'the' in front of parameter names in some instances.
* perlapi, perlintern: Add L<> links to podKarl Williamson2015-09-031-1/+1
|
* perlapi: Use C<> instead of I<> for parameter names, etcKarl Williamson2015-08-011-19/+19
| | | | | The majority of perlapi uses C<> to specify these things, but a few things used I<> instead. Standardize to C<>.
* dont use a 64 bit constant for a 32 bit valueDaniel Dragan2015-05-191-1/+1
| | | | | | | | | | | | Perl on MSVC6 doesnt support 64 bit ints (p5p choice not to support it) so this macro isn't defined on MSVC6 builds, commit e59642234e hid this mistake from non-DEBUGGING builds. The mistake is a copy paste mistake from commit eacbb37937 . Miniperl fails at VC6 link time due to UINT64_C symboil not being found. ..\pad.c(165) : warning C4013: 'UINT64_C' undefined; assuming extern returning int ..\pad.c(165) : warning C4018: '!=' : signed/unsigned mismatch
* null ptr deref in Perl_cv_forget_slabDavid Mitchell2015-05-051-3/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | RT #124385 Parsing following a syntax error could result in a null ptr dereference. This commit contains a band-aid that returns from Perl_cv_forget_slab() if the cv arg is null; but the real issue is much deeper and needs a more general fix at some point. Basically, both the lexer and the parser use the save stack, and after an error, they can get out of sync. In particular: 1) when handling a double-quoted string, the lexer does an ENTER, saves most of its current state on the save stack, then uses the literal string as the toke source. When it reaches the end of the string, it LEAVEs, restores the lexer state and continues with the main source. 2) Whenever the parser starts a new block or sub scope, it remembers the current save stack position, and at end of scope, pops the save stack back to that position. In something like "@{ sub {]}} }}}" the lexer sees a double-quoted string, and saves the current lex state. The parser sees the start of a sub, and saves PL_compcv etc. Then a parse error occurs. The parser goes into error recovery, discarding tokens until it can return to a sane state. The lexer runs out of tokens when toking the string, does a LEAVE, and switches back to toking the main source. This LEAVE restores both the lexer's and the parser's state; in particular the parser gets its old PL_compcv restored, even though the parser hasn't finished compiling the current sub. Later, series of '}' tokens coming through allows the parser to finish the sub. Since PL_error_count > 0, it discards the just-compiled sub and sets PL_compcv to null. Normally the LEAVE_SCOPE done just after this would restore PL_compcv to its old value (e.g. PL_main_cv) but the stack has already been popped, so PL_compcv gets left null, and SEGVs occur. The two main ways I can think of fixing this in the long term are 1) avoid the lexer using the save stack for long-term state storage; in particular, make S_sublex_push() malloc a new parser object rather than saving the current lexer state on the save stack. 2) At the end of a sublex, if PL_error_count > 0, don't try to restore state and continue, instead just croak. N.B. the test that this commit adds to lex.t doesn't actually trigger the SEGV, since the bad code is wrapped in an eval which (for reasons I haven't researched) avoids the SEGV.
* [perl #124187] don't call pad_findlex() on a NULL CVTony Cook2015-05-051-0/+4
|
* perlapi: Wrap long verbatim lines to 79 columnsKarl Williamson2015-04-231-8/+11
|
* Replace common Emacs file-local variables with dir-localsDagfinn Ilmari Mannsåker2015-03-221-6/+0
| | | | | | | | | | | | | | | | An empty cpan/.dir-locals.el stops Emacs using the core defaults for code imported from CPAN. Committer's work: To keep t/porting/cmp_version.t and t/porting/utils.t happy, $VERSION needed to be incremented in many files, including throughout dist/PathTools. perldelta entry for module updates. Add two Emacs control files to MANIFEST; re-sort MANIFEST. For: RT #124119.
* silence some compiler warnings.David Mitchell2015-02-241-1/+1
| | | | | (Some compilers have strange ideas about the signedness of the bool type verses the signedness of a boolean expression like a == b).
* Confused cloning of nested state subsFather Chrysostomos2015-01-111-10/+72
| | | | | | | | | | | | | | | | | | | | | | use feature 'lexical_subs','state'; no warnings 'experimental'; my $sub = sub{ state sub sb4; state sub a { state $x = 42; sub sb4 { $x; } } a(); print sb4(), "\n"; }; $sub->(); The output: Bizarre copy of CODE in subroutine exit at - line 10. The sb4 sub was trying to close over the wrong pad; namely, the one belonging to the anonymous sub.
* pad.c: Remove unused context paramsFather Chrysostomos2015-01-061-4/+4
|
* pad.c: Obsolete commentFather Chrysostomos2015-01-031-4/+0
| | | | This comment, added by 3291825f, was made obsolete by 0f94cb1f.
* Fix CvOUTSIDE for state subs in predeclared subsFather Chrysostomos2015-01-031-4/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | use 5.018; use experimental 'lexical_subs'; $::x = "global"; sub x; sub x { state $x = 42; state sub x { print eval '$x', "\n" } \&x; } x()->(); __END__ Output: Segmentation fault: 11 Because this line in pad.c:S_findpadlex: 1141 const PADLIST * const padlist = CvPADLIST(cv); is trying to read this SV: SV = UNKNOWN(0x76) (0xaa170e4fd) at 0x10060c928 REFCNT = 1697135711 FLAGS = (PADSTALE,TEMP,GMG,SMG,IOK,pNOK,pPOK,UTF8) (i.e., gibberish). During compilation, ‘sub x{’ creates a new CV. When the sub is about to be installed (when the final ‘}’ is reached), the existing stub must be reused. So everything is copied from the new CV (PL_compcv) to the stub. Also, any CvOUTSIDE pointers of nested subs get updated to point to the erstwhile stub. State subs were not getting their CvOUTSIDE pointers updated. This patch implements that.
* Fix bad read in pad.c:cv_undefFather Chrysostomos2014-12-171-1/+3
| | | | | | | | | | | | When freeing a sub, we can’t assume an entry named "&" contains a CV. It may instead be a weak reference to a format or named sub, or undef if such a reference went stale, in which case we don’t want to mess with CvOUTSIDE pointers. This bug probably goes back to v5.17.1-213-ge09ac07, when weak refer- ences started being stored in "&" pad entries. It didn’t start trig- gering AddressSanitizer failures until it was extended to named subs, in v5.21.6-386-ga70f21d.
* Don’t set PadlistMAXNAMED for single-char entriesFather Chrysostomos2014-12-141-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | This fixes perl #123430. Single-character entries like "$" and "&" are not actually named entries, but are partially treated as such for the sake of bookkeeping and scope. (E.g., a flipflop target must have the same lifetime as a state variable.) PadlistMAXNAMED is an optimisation that marks the offset of the high- est pad slot with a name. If there any many anonymous pad slots after the last named one, we don’t want to search through them when looking up a symbol. So we mark the maximum named slot and skip half the pad if we are lucky. Commit v5.21.4-51-g14d9114 caused flipflop targets to be allocated as variables named "$", causing compilation of some generated code to slow down. At compile time, the name pad is not extended to the length of the pad until the end of subroutine compilation. So prior to 14d9114 flipflop targets would not make the name pad any longer. Now that flipflop targets expand the name pad, stop setting PadlistMAXNAMED, so that things are no slower than before. This is not really the best fix, IMO, because code that is sensitive to this will slow down dramatically if you tweak it ever so slightly by adding a ‘my $x’ here or there.
* Unify format and named-sub pad weakref codeFather Chrysostomos2014-12-091-9/+3
|
* Fix OUTSIDE for named subs inside predeclared subsFather Chrysostomos2014-12-091-0/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This prints 42 as expected (foo initialises $x and bar reads it via eval): use 5.01; sub foo { state $x = 42; sub bar { eval 'print $x // "u", "\n"'; } } foo(); bar(); If you predeclare foo and vivify its glob, use 5.01; *foo; # vivifies the glob at compile time sub foo; sub foo { state $x = 42; sub bar { eval 'print $x // "u", "\n"'; } } foo(); bar(); then the output is ‘u’, because $x is now undefined. What’s happening is that ‘eval’ follows CvOUTSIDE pointers (each sub points to its outer sub), searching each pad to find a lexical $x. In the former case it succeeds. In the latter, bar’s CvOUTSIDE pointer is pointing to the wrong thing, so the search fails and $x is treated as global. You can see it’s global with this example, which prints ‘globular’: use 5.01; *foo; # vivifies the glob at compile time sub foo; sub foo { state $x = 42; sub bar { eval 'print $x // "u", "\n"'; } } foo(); $main::x = "globular"; bar(); When a sub is compiled, a new CV is created at the outset and put in PL_compcv. When the sub finishes compiling, the CV in PL_compcv is installed in the sub’s typeglob (or as a subref in the stash if pos- sible). If there is already a stub in a typeglob, since that stub could be referenced elsewhere, we have to reuse that stub and transfer the contents of PL_compcv to that stub. If we have any subs inside it, those will now have CvOUTSIDE point- ers pointing to the old PL_compcv that has been eviscerated. So we go through the pad and fix up the outside pointers for any subs found there. Named subs don’t get stored in the pad like that, so the CvOUTSIDE fix-up never happens. Hence the bug above. The bug does not occur if the glob is not vivified before the sub def- inition, because a stub declaration will skip creating a real CV if it can. It can’t if there is a typeglob. The solution, of course, is to store named subs in the outer sub’s pad. We can skip this if the outer ‘sub’ is an eval or the main pro- gram. These two types of CVs obviously don’t reuse existing stubs, since they never get installed in the symbol table. Since named subs have strong outside pointers, we have to store weak refs in the pad, just as we do for formats.
* Change OP_SIBLING to OpSIBLINGFather Chrysostomos2014-12-071-2/+2
| | | | | | | | | to match the existing convention (OpREFCNT, OpSLAB). Dave Mitchell asked me to wait until after his multideref work was merged. Unfortunately, there are now CPAN modules using OP_SIBLING.
* Use cBOOL.Jarkko Hietaniemi2014-12-071-1/+1
|
* Revert ‘Used pad name lists for pad ids’Father Chrysostomos2014-12-061-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This reverts commit 8771da69db30134352181c38401c7e50753a7ee8. Pad lists need to carry IDs around with them, so that when something tries to close over a pad, it is possible to confirm that the right pad is being closed over (either the original outer pad, or a clone of it). (See the commit message of db4cf31d1, in which commit I added an ID to the padlist struct.) In 8771da69 I found that I could use the memory address of the pad’s name list (name lists are shared) and avoid the extra field. Some time after 8771da69 I realised that a pad list could be freed, and the same address reused for another pad list, so using a memory address may not be so wise. I thought it highly unlikely, though, and put it on the back burner. I have just run into that. t/comp/form_scope.t is now failing for me with test 13, added by db4cf31d1. It bisects to 3d6de2cd1 (PERL_PADNAME_MINIMAL), but that’s a red herring. Trivial changes to the script make the problem go away. And it only happens on non- debugging builds, and only on my machine. Stepping through with gdb shows that the format-cloning is following the format prototype’s out- side pointer and confirming that it is has the correct pad (yes, the memory addresses are the same), which I know it doesn’t, because I can see what the test is doing. While generation numbers can still fall afoul of the same problem, it is much less likely. Anyway, the worst thing about 8771da69 is the typo in the first word of the commit message.
* pad.c: Various doc updatesFather Chrysostomos2014-11-301-32/+30
|
* [perl #123223] Make PADNAME a separate typeFather Chrysostomos2014-11-301-40/+162
| | | | | | | | | | | distinct from SV. This should fix the CPAN modules that were failing when the PadnameLVALUE flag was added, because it shared the same bit as SVs_OBJECT and pad names were going through code paths not designed to handle pad names. Unfortunately, it will probably break other CPAN modules, but I think this change is for the better, as it makes both pad names and SVs sim- pler and makes pad names take less memory.
* Use PADNAME rather than SV in pad.c:padlist_dupFather Chrysostomos2014-11-301-4/+4
|
* Use PADNAME rather than SV in pad.c:pad_pushFather Chrysostomos2014-11-301-4/+4
|
* Use PADNAME rather than SV in pad.c:cv_clone_padFather Chrysostomos2014-11-301-12/+11
|
* Use PADNAME rather than SV in pad.c:do_dump_padFather Chrysostomos2014-11-301-5/+5
|
* Use PADNAME rather than SV in pad.c:pad_tidyFather Chrysostomos2014-11-301-3/+3
|
* Use PADNAME rather than SV in pad.c:pad_leavemyFather Chrysostomos2014-11-301-7/+7
|
* Use PADNAME rather than SV in pad.c:intro_myFather Chrysostomos2014-11-301-4/+4
|