summaryrefslogtreecommitdiff
path: root/gv.c
Commit message (Collapse)AuthorAgeFilesLines
* Change white space to avoid C++ deprecation warningKarl Williamson2016-11-181-24/+24
| | | | | | | | | | | | | | | | | | | | | | 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.
* Remove obsolete commentDagfinn Ilmari Mannsåker2016-11-131-2/+0
| | | | | | - "Don't merge yet" - too late - "as it's likely to get a len parameter" - added in 44130a26 - "and possibly even a U32 hash" - that'd be a new function
* new feature @{^CAPTURE} (and %{^CAPTURE} and %{^CAPTURE_ALL})Yves Orton2016-11-011-14/+32
| | | | | | | | | @{^CAPTURE} exposes the capture buffers of the last match as an array. So $1 is ${^CAPTURE}[0]. %{^CAPTURE} is the equivalent to %+ (ie named captures) %{^CAPTURE_ALL} is the equivalent to %- (ie all named captures).
* optimise gv.c a bit (we could do better)Yves Orton2016-10-271-4/+8
| | | | | | | | We save a few ops for package vars starting with 'E' by checking the second char as well. We could probably be much smarter with this switch, but we would have to generate it, which involves its own issues.
* must check all the EXPORT vars in two places!Yves Orton2016-10-271-1/+6
| | | | (Silence lots of used once warnings we used to not generate)
* gv.c: rework special var matching logic to be simplerYves Orton2016-10-191-28/+30
| | | | | | | | | | | | | | | | | The old code used a bunch of tricks that IMO are unlikely to actually make any performance difference, and make the code harder to read, search, and understand, and less amenable to using string constant friendly macros. So for instance instead of switching on the first char and then comparing the second on for an exact match instead just compare the full string. The extra char is unlikely to make a difference to the underlying code that gets called, and the end result is easier searching. Another issue is that some of the code was inadverdantly doing prefix matches, and not exact matchs for certain magic var names. This is fixed as part of these changes.
* gv.c: rework string separator parsing to use new string macrosYves Orton2016-10-191-5/+6
|
* gv.c: switch to using string constant friendly macrosYves Orton2016-10-191-7/+7
|
* gv.c: add a require_tie_mod_s() wrapper for constant string argsYves Orton2016-10-191-7/+14
|
* gv.c: document where @- and @+ (and %- and %+ are initialized in gv.c)Yves Orton2016-10-191-2/+2
|
* fix #129267: rework gv_fetchmethod_pvn_flags separator parsingYves Orton2016-09-131-10/+26
| | | | | | | | | | | With previous code we could overrun the end of the name when the last char in the string was a colon. This reworks the code so it is more clear what is going on, and so it more similar to other code that also parses out package separaters in gv.c. This is a rework of the reverted patches: 243ca72 rename "nend" name_cursor in Perl_gv_fetchmethod_pvn_flags b053c93 fix: [perl #129267] Possible string overrun with invalid len in gv.c
* clean up gv_fetchmethod_pvn_flags: rename nsplit to last_separatorYves Orton2016-09-131-12/+12
| | | | | nsplit if set points at the first char of the last separator in name, so rename it so it is more comprehensible what it means.
* clean up gv_fetchmethod_pvn_flags: move origname init to function startYves Orton2016-09-131-1/+0
| | | | | so it is more obvious that it is a constant copy of the original name.
* clean up gv_fetchmethod_pvn_flags: introduce name_endYves Orton2016-09-131-6/+8
| | | | | | | | nend is used for too many things, this replaces various uses of nend with name_end, which is constant. this is a first step to fixing [perl #129267], which shouldnt change any behavior
* Revert "fix: [perl #129267] Possible string overrun with invalid len in gv.c"Yves Orton2016-09-131-6/+5
| | | | This reverts commit b053c9385f29680bc812db3da64ce5c4d45d0cf7.
* Revert "rename "nend" name_cursor in Perl_gv_fetchmethod_pvn_flags"Yves Orton2016-09-131-13/+13
| | | | This reverts commit 243ca72243bd234ab5ef1818a32b9c6dd68f777c.
* rename "nend" name_cursor in Perl_gv_fetchmethod_pvn_flagsYves Orton2016-09-131-13/+13
| | | | | nend is a crappy name, and we use name_cursor in other contexts that do similar things. consistency++
* fix: [perl #129267] Possible string overrun with invalid len in gv.cYves Orton2016-09-131-5/+6
| | | | | | | | | Perl_gv_fetchmethod_pvn_flags contains various subtle logic bugs related to parsing fully qualified method names. In particular if you feed the function a string which ends with a single colon it will end up accessing memory past the end of the string. In addition when checking for the second colon in a fully qualified name we could potentially access memory we dont own, and certainly access memory not part of the string
* gv.c:require_tie_mod: Make var name a char paramFather Chrysostomos2016-08-121-11/+8
| | | | | | | | | | | | | | | This reduces machine code size a little and simplifies require_tie_mod. On a non-debugging Linux GCC build with -O2: Before: $ ls -l gv.o -rw-r--r-- 1 sprout p5p 88704 Aug 12 07:29 gv.o After: $ ls -l gv.o -rw-r--r-- 1 sprout p5p 88656 Aug 12 17:29 gv.o
* gv.c:require_tie_mod: Create namesv only when neededFather Chrysostomos2016-08-041-10/+7
| | | | | | | We only need it as an SV when we are going to load a module. We can- not share the SV with Perl_load_module, is ck_require mangles it ("Errno" → "Errno.pm"). The other uses of the SV are unnecessary, as we have pv interfaces available.
* Rationalise gv.c:gv_magicalizeFather Chrysostomos2016-08-041-24/+22
| | | | | | | | | | | | | | | | | | | This code is confusing, and confusion has resulted in bugs. So rework the code a bit to make it more comprehensible. gv_magicalize no longer has such an arcane return value. What it does now is simply add appropriate magic to (or do appropriate vivification in) the GV passed as its argument. It returns true if magic or vivi- fication was applicable. The caller (gv_fetchpvn_flags) uses that return value to determine whether to install the GV in the symbol table, if the caller has requested that a symbol only be added if it is a magical one (GV_ADDMG). This reworking does mean that the GV is now checked for content even when it would make no difference, but I think the resulting clarity (ahem, *relative* clarity) of the code is worth it.
* Revert "gv.c:require_tie_mod: Create namesv only when needed"James E Keenan2016-08-041-5/+6
| | | | | | | This reverts commit e167a7177da799ca1757dc382b386abd3ae29491. Observed to cause many test failures on Linux and FreeBSD. See message on list with subject "Many test failures in blead".
* gv.c:require_tie_mod: Create namesv only when neededFather Chrysostomos2016-08-041-6/+5
| | | | | | We only need it as an SV when we are going to load a module. Also, there is no need for two separate SVs; we can use the same one for Perl_load_module as we use subsequently in gv_stashsv.
* gv.c: comment typeoFather Chrysostomos2016-08-041-1/+1
|
* gv.c:require_tie_mod: Accept pvn paramsFather Chrysostomos2016-08-041-7/+9
| | | | | | All the callers create the SV on the fly. We might as well put the SV creation into the function itself. (A forthcoming commit will refactor things to avoid the SV when possible.)
* Rework mod loading for %- and %!; fix mem leakFather Chrysostomos2016-08-041-39/+46
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | There are many built-in variables that perl creates on demand for efficiency’s sake. gv_fetchpvn_flags (which is responsible for sym- bol lookup) will fill in those variables automatically when add- ing a symbol. The special GV_ADDMG flag passed to this function by a few code paths (such as defined *{"..."}) tells gv_fetchpvn_flags to add the symbol, but only if it is one of the ‘magical’ built-in variables that we pre- tend already exist. To accomplish this, when the GV_ADDMG flag is passed, gv_fetchpvn_flags, if the symbol does not already exist, creates a new GV that is not attached to the stash. It then runs it through its magicalization code and checks afterward to see whether the GV changed. If it did, then it gets added to the stash. Otherwise, it is discarded. Three of the variables, %-, %!, and $], are problematic, in that they are implemented by external modules. gv_fetchpvn_flags loads those modules, which tie the variable in question, and then control is returned to gv_fetchpvn_flags. If it has a GV that has not been installed in the symbol table yet, then the module will vivify that GV on its own by a recursive call to gv_fetchpvn_flags (with the GV_ADD flag, which does none of this temporary-dangling-GV stuff), and gv_fetchpvn_flags will have a separate one which, when installed, would clobber the one with the tied variable. We solved that by having the GV installed right before calling the module, for those three variables (in perl 5.16). The implementation changed in commit v5.19.3-437-g930867a, which was supposed to clean up the code and make it easier to follow. Unfortun- ately there was a bug in the implementation. It tries to install the GV for those cases *before* the magicalization code, but the logic is wrong. It checks to see whether we are adding only magical symbols (addmg) and whether the GV has anything in it, but before anything has been added to the GV. So the symbol never gets installed. Instead, it just leaks, and the one that the implementing module vivifies gets used. This leak can be observed with XS::APItest::sv_count: $ ./perl -Ilib -MXS::APItest -e 'for (1..10){ defined *{"!"}; delete $::{"!"}; warn sv_count }' 3833 at -e line 1. 4496 at -e line 1. 4500 at -e line 1. 4504 at -e line 1. 4508 at -e line 1. 4512 at -e line 1. 4516 at -e line 1. 4520 at -e line 1. 4524 at -e line 1. 4528 at -e line 1. Perl 5.18 does not exhibit the leak. So in this commit I am finally implementing something that was dis- cussed about the time that v5.19.3-437-g930867a was introduced. To avoid the whole problem of recursive calls to gv_fetchpvn_flags vying over whose GV counts, I have stopped the implementing modules from tying the variables themselves. Instead, whichever gv_fetchpvn_flags call is trying to create the glob is now responsible for seeing that the variable is tied after the module is loaded. Each module now pro- vides a _tie_it function that gv_fetchpvn_flags can call. One remaining infelicity is that Errno mentions $! in its source, so *! will be vivified when it is loading, only to be clobbered by the GV subsequently installed by gv_fetch_pvn_flags. But at least it will not leak. One test that failed as a result of this (in t/op/magic.t) was try- ing to undo the loading of Errno.pm in order to test it afresh with *{"!"}. But it did not remove *! before the test. The new logic in the code happens to work in such a way that the tiedness of the vari- able determines whether the module needs to be loaded (which is neces- sary, now that the module does not tie the variable). Since the test is by no means normal code, it seems reasonable to change it.
* Exempt @DB::args from ‘used once’ warningsFather Chrysostomos2016-07-311-0/+4
| | | | | | | | | | | | | | | | | A perfectly benign use of @DB::args like sub foo { package DB { () = caller 0 } print "@DB::args\n" } foo(1..3); warns under -w, though that is exactly its intended use. That is is not nice. warnings.pm itself uses @DB::args, which is why this went unnoticed for so many years. This commit eliminates the ‘used once’ warning, but the ‘Possible unintended interpolation’ message that that code produces will be handled in another commit.
* gv.c: Add a comment about what powers Foo->import|unimportÆvar Arnfjörð Bjarmason2016-07-151-0/+3
| | | | | | | | | | | | | This comments some ancient code added by Larry back in perl-5.000-ga0d0e21, I was searching for what made this not error: $ ./miniperl -we 'package Foo {} Foo->import' Commenting out this "if" clause will make that error the same way that this would: $ ./miniperl -we 'package Foo {} Foo->whatever Can't locate object method "whatever" via package "Foo" at -e line 1.
* Disable ${^ENCODING}Father Chrysostomos2016-07-131-3/+0
| | | | ${^ENCODING} is disabled and tests are modified to account.
* [perl #128238] Crash with non-stash in stashFather Chrysostomos2016-06-231-2/+2
| | | | | | | | This is a follow-up to e7acdfe976f. Even if the name of the stash entry ends with ::, it may not itself contain a real stash (though this only happens with code that assigns directly to stash entries, which has undefined behaviour according to perlmod), so skip hashes that are not stashes.
* only treat stash entries with .*:: as sub-stashesDavid Mitchell2016-06-211-1/+4
| | | | | | | | | RT #128238 %: = 0 would cause an assertion failure in Perl_gv_check(), since when it searched a stash for substashes, it assumed anything ending in ':' was a substash, whereas substashes end in '::'. So check for a double colon before recursing.
* Allow assignment to &CORE::keys()Father Chrysostomos2016-05-201-1/+1
|
* Allow &CORE::foo() with array functionsFather Chrysostomos2016-05-201-5/+1
|
* Allow &CORE::foo() with hash functionsFather Chrysostomos2016-05-201-3/+1
| | | | | &CORE::keys does not yet work as an lvalue. (I’m not sure how to make that work.)
* Add missing break in switch.Jarkko Hietaniemi2016-02-071-0/+1
| | | | Coverity CID 28986: Missing break in switch (MISSING_BREAK)
* make gimme consistently U8David Mitchell2016-02-031-1/+1
| | | | | | | | | | | | | The value of gimme stored in the context stack is U8. Make all other uses in the main core consistent with this. My primary motivation on this was that the new function cx_pushblock(), which I gave a 'U8 gimme' parameter, was generating warnings where callers were passing I32 gimme vars to it. Rather than play whack-a-mole, it seemed simpler to just uniformly use U8 everywhere. Porting/bench.pl shows a consistent reduction of about 2 instructions on the loop and sub benchmarks, so this change isn't harming performance.
* reimplement $^WIN32_SLOPPY_STAT as a magic varDaniel Dragan2015-10-191-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The original implementation in commit cba61fe146 was sloppy. It is named like a special var, it is listed as a special var, but it was a regular GV. Since nobody knows this var exists, and full stat is the default (which I disagree with see below). There will be alot more PP and C/XS perl stat() calls (atleast a couple to dozens or low 100s for short lived perl processes) than reads/writes to this global scalar (rounded to 0 R/Ws) in a Win32 perl process. So avoid the 1 usually failing GV package (hash) lookup for each PP/XS/PL C stat by using magic vars and a C bool. This is a perf increase. Use sv_true instead of SvTRUE_NN because this code is extremely rare to execute and the macro has large machine code. I disagree with the default being full stat with since this increases the number of kernel IO calls and ASCII->UTF16 conversions, and there was perf criticism in the original thread that implemented this this http://www.nntp.perl.org/group/perl.perl5.porters/2006/02/msg109917.html but why full stat is default is for another ticket. This patch lessens the overhead of full stat until something else is decided. Change the initial value of the sloppystat setting for miniperl to be true instead of doing it in buildcustomize.pl in PP. Revert part of commit 8ce7a7e8b0 "speed up miniperl require on Win32" to acomplish this. Unlike Unix perl, no object files are shared between mini and full perl, so changing the default is fine on Win32 Perl. If minitest/miniperl really need hard link testing/support, they can explictly turn off sloppy stat and enable full stat with the special var. Changing the stat default from C for miniperl avoids creating the special GV on each miniperl process start as it previously was with the buildcustomize.pl way. Changing stat setting in C and not PP also saves a couple IO calls in win32_stat when opening the first .pl if it isn't -e, and opening buildcustomize.pl in all permutations. The PP code in S_parse_body contains a -f. See ticket for this patch for details. Only CPAN use of this special var is File-Stat-Moose-0.06/lib/File/Stat/Moose.pm#L208 according to cpangrep.
* perlapi use 'UTF-8' instead of variants of thatKarl Williamson2015-09-031-2/+2
|
* Various pods: Add C<> around many typed-as-is thingsKarl Williamson2015-09-031-19/+19
| | | | Removes 'the' in front of parameter names in some instances.
* perlapi, perlintern: Add L<> links to podKarl Williamson2015-09-031-3/+5
|
* dont create *{"_<$filename"} globs for perl lang debugging of XSUBsDaniel Dragan2015-08-121-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 1st problem, *{"_<$filename"} globs aren't created for PP code unless PERLDB_LINE || PERLDB_SAVESRC are on (see Perl_yylex ). Creating XSUBs unconditionally created the *{"_<$filename"} globs for XSUB, even if PP subs were not getting the debugging globs created. This is probably an oversight, from commit b195d4879f which tried to deprecate using the *{"_<$filename"} GVs for storing the originating filename of the CV which was partially reverted 2 months later in commit 57843af05b with CvFILE becoming a char * instead of GV *. To speed up XSUB registration time, and decrease memory when not in Perl lang debugging mode dont create the debugging globs for XSUBs unless in Perl lang debugging mode. see also http://www.nntp.perl.org/group/perl.perl5.porters/2000/06/msg13832.html 2nd problem, since the perl debugger can't step into C code, nor set breakpoints in it, there is no reason to create *{"_<$filename"} globs for .c files. Since someone maybe one day might try to implement that feature, comment out the code instead of deleting it. This will slightly reduce the size of perl binary, and speed up XSUB registration time, and decrease memory usage when using the Perl debugger. see also (no responses) http://www.nntp.perl.org/group/perl.perl5.porters/2015/06/msg229014.html perl has a number of core perma-XSUBs (UNIVERSAL/PerlIO/DynaLoader/Internals/mro/misc const subs/etc). Each of these previously got a "_<foo.c" glob. I counted 7 .c debugging globs on my perl. This commit, before on WinXP, running threaded perl with -e"system 'pause'" as a sample script, "Private Bytes" (all process unique memory, IE not shared, not mmaped) was 488 KB, after this commit it was 484 KB, which means that enough malloc memory was saved plus a little bit of chance, to cross one 4 KB page of memory. IDK the exact amount of saved memory is over or under 4KB.
* [perl #125541] Fix crash with %::=(); J->${\"::"}Father Chrysostomos2015-07-241-1/+1
| | | | | | | | | | | | | | gv_stashpvn does not expect gv_fetchpv to return something that is not a GV. If someone has blown away the stash with %::=(), then the $::{"main::"} entry no longer exists, but gv_fetchpv expects it to be there. This patch just makes this case fail somewhat gracefully instead of crashing: $ ./miniperl -e '%::=(); J->${\"::"}' Can't locate object method "" via package "" (perhaps you forgot to load ""?) at -e line 1. If someone does %::=(), nothing more reasonable should be expected. At least it does not crash now.
* overload.c -> overload.incJarkko Hietaniemi2015-07-221-1/+1
|
* combine PERLDB_LINE and PERLDB_SAVESRC flag testsDaniel Dragan2015-07-221-1/+1
| | | | | | | | On VC2003 32b -O1, the .text section of miniperl.exe decreased from 0xAEFCD bytes of machine code to 0xAEF9D after this patch. see also http://www.nntp.perl.org/group/perl.perl5.porters/2015/07/msg229308.html
* gv_const_sv() handle subrefs directly in the stashTony Cook2015-03-241-1/+1
| | | | | | With 2eaf799e sub declarations can store sub references directly in the stash, but gv_const_sv(), which might be passed an entry from the stash didn't handle that case.
* 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.
* [perl #123814] replace grok_atou with grok_atoUVHugo van der Sanden2015-03-091-7/+5
| | | | | | | | | | | | Some questions and loose ends: XXX gv.c:S_gv_magicalize - why are we using SSize_t for paren? XXX mg.c:Perl_magic_set - need appopriate error handling for $) XXX regcomp.c:S_reg - need to check if we do the right thing if parno was not grokked Perl_get_debug_opts should probably return something unsigned; not sure if that's something we can change.
* [perl #123960] sv.c: Fix gp_free -Do outputFather Chrysostomos2015-03-011-2/+5
| | | | | | We try to print ‘gp_free clearing PL_stashcache for '%"HEKf"'’, but without checking that we actually have a hek. This has been this way since 103f5a36127.
* [PATCH] fix PL_nan_u from leaking in every translation object on Win32 VCDaniel Dragan2015-02-041-1/+1
|
* 5th arg to indicate numeric bitwise overloadingFather Chrysostomos2015-01-311-2/+9
|