summaryrefslogtreecommitdiff
path: root/gv.c
Commit message (Collapse)AuthorAgeFilesLines
* 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
|
* gv.c: Make &.= overloading workFather Chrysostomos2015-01-311-0/+3
|
* Revert "refactor gv_add_by_type"Matthew Horsfall2015-01-201-81/+50
| | | | | | | This reverts commit 819b139db33e2022424694e381422766903d4f65. This could be repapplied for 5.23.1, with modifications or additional patches to solve the breakage discussed in RT 123580.
* refactor gv_add_by_typeDaniel Dragan2015-01-061-50/+81
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | gv_add_by_type was added in commit d5713896ec in 5.11.0 . Improve gv_add_by_type by making it return the newly created SV*, instead of the the GV *, which the caller must deref both the GV head to get svu and then deref a slice into the GP, even though it already derefed svu and GP right before, to figure out whether to call gv_add_by_type in the first place. The original version of this patch had gv_add_by_type returning a SV ** to ensure lvalue-ness but it was discovered it wasn't needed and not smart. -rename gv_add_by_type since it was removed from public api and its proto changed -remove null check since it is impossible to pass null through GvAVn(), and unlikely with gv_AVadd, null segvs reliably crash in the rare case of a problem -instead of S_gv_init_svtype and gv_add_by_type using a tree of logic/ conditional jumps in asm, use a lookup table, GPe (e=enum or entry) enums are identical to offsets into the GP struct, all of then fit under 0xFF, if the CC and CPU arch wants, CC can load the const once into a register, then use the number for the 2nd deref, then use the number again as an arg to gv_add_by_type, the low (&~0xf) or high (<<2) 2 bits in a GPe can be used for something else in the future since GPe is pointer aligned -SVt_LAST triggers "panic: sv_upgrade to unknown type", so use that value for entries of a GP which are not SV head *s and are invalid to pass as an arg -remove the tree of logic in S_gv_init_svtype, replace with a table -S_gv_init_svtype is now tail call friendly and very small -change the GV**n to be rvalues only, assigning to GV**n is probably a memory leak -fix 1 core GV**n as lvalue use -GvSVn's unusual former definition is from commit 547f15c3f9 in 2005 and DEFSV as lvalue is gone in core as of commit 414bf5ae08 from 2008 since all the GV**n macros are now rvalues, this goes too -PTRPTR2IDX and PTRSIZELOG2 could use better names -in pp_rv2av dont declare strings like that VC linker won't dedup that, and other parts of core also have "an ARRAY", perl521.dll previously had 2 "an ARRAY" and "a HASH" strings in it due to this before VC 2003 32 perl521.dll .text 0xc8813 in machine code bytes after .text 0xc8623
* Fix gv_fetchmeth_sv: it might stringify SV more than once.syber2014-12-081-2/+8
|
* Fix method assertion failuresFather Chrysostomos2014-12-071-3/+9
|
* gv_fetchmeth_sv now supports SV shared hashessyber2014-12-061-14/+19
| | | | | | | | | | | | | | | | | | | gv_fetchmeth_internal added, which receives method name both as SV and const char. Now it calls hv_common instead of hv_fetch. gv_fetchmeth_pvn and gv_fetchmeth_sv are now just wrappers for gv_fetchmeth_internal Result: x2 speedup for gv_fetchmeth_sv new SV is a shared hash BEFORE PVN - 28.5 Mcalls/s SV SHARED HASH - 26 Mcalls/s AFTER PVN - 29.4 Mcalls/s SV SHARED HASH - 51 Mcalls/s
* Refactor bodyless-IV/NV hacks into defineEric Herman2014-11-281-0/+2
| | | | | | This commit adds documentation of the bodyless-IV/NV hacks as well as moving the offset calculation into a somewhat sensibly-named define instead of cargo-culting the obscure logic in many different places.
* Make encoding pragma lexical in scopeKarl Williamson2014-11-201-1/+4
| | | | | | | | | | | | | | | | | | | | The encoding pragma is deprecated, but in the meantime it causes spooky action at a distance with other modules that it may be combined with. In these modules, operations such as chr(), ord(), and utf8::upgrade() will suddenly start doing the wrong thing. The documentation for 'encoding' has said to call it after loading other modules, but this may be impractical. This is especially bad with anything that auto-loads at first use, like \N{} does now for charnames. There is an issue with combining this with setting the variable ${^ENCODING} directly. The potential for conflicts has always been there, and remains. This commit introduces a shadow hidden variable, subservient to ${^ENCODING} (to preserve backwards compatibility) that has lexical scope validity. The pod for 'encoding' has been revamped to be more concise, clear, use more idiomatic English, and to speak from a modern perspective.
* [perl #123103] Just set SVf_READONLY on magic varsFather Chrysostomos2014-11-031-0/+10
| | | | | | a623f8939 was arguably a little too eager. It’s purpose is to protect vars whose modification can causes hangs and crashes. I don’t believe that is the case for any magic vars.
* [perl #57512] Warnings for implicitly closed handlesFather Chrysostomos2014-11-021-0/+10
| | | | | | | | | | | | | | | | | | If the implicit close() fails, warn about it, mentioning $! in the message. This is a default warning in the io category. We do this in two spots, sv_clear and gp_free. While sv_clear would be sufficient to get the warning emitted, the warning won’t contain the name of the handle when called from there, because lone IO thing- ies are nameless. Doing it also when a GV’s glob pointer is freed--as long as the IO thingy in there has a reference count of 1--allows the name to be included in the message, because we still have the glob, which is where the name is stored. The result: $ ./miniperl -Ilib -e 'open fh, ">/Volumes/Disk Image/foo"; print fh "x"x1000, "\n" for 1..50; undef *fh' Warning: unable to close filehandle fh properly: No space left on device at -e line 1.
* free up CvPADLIST slot for XSUBs for future useDaniel Dragan2014-10-311-0/+1
| | | | | | | | | | | | | | | | | | | CvRESERVED is a placeholder, it will be replaced with a sentinal value from future revised BOOTCHECK API. CvPADLIST_set was helpful during development of this patch, so keep it around for now. PoisonPADLIST's magic value is from PERL_POISON 0xEF pattern. Some PoisonPADLIST locations will get code from future BOOTCHECK API. Make padlist_dup a NN function to avoid overhead of calling it for XSUBs during closing. Perl_cv_undef_flags's else if (CvISXSUB(&cvbody)) is to avoid whitespace changes. Filed as perl [#123059].
* [perl #122799] Always turn off CvNAMED in cvgv-setFather Chrysostomos2014-09-201-1/+1
| | | | | | | | | | | | Instead of turning off the flag only when we need to turn it off (when there is a hek, which is the only time it should be on), just turn it off unconditionally. This gets Scope::Upper working once more. While it is arguably the module’s fault, it’s still a good idea to make cvgv_set robust. CvNAMED should never be on after calling it, regardless of the previous state of the CV.
* gv.c: For ‘Global symbol’ msg, don’t check utf8ness twiceFather Chrysostomos2014-09-181-6/+3
| | | | | | We already take care of possible utf8ness in the format string. There is no need to turn on the flag afterwards. This double utf8 check has been present since ecad31f018.
* [perl #121638] Make ‘Global symbol’ message more newbie-friendlyFather Chrysostomos2014-09-181-1/+6
| | | | | | by suggesting the declaration of a lexical variable, but without removing the ‘Global symbol’ part, since much code no doubt depends on its presence.
* Avoid reifing GVs in gv.c:gv_try_downgradeFather Chrysostomos2014-09-151-1/+1
| | | | | I’m not sure that it’s even possible for a CV with a name hek to reach this code path, but if that happens this avoids reifying the GV.
* Avoid reifying GVs when lex subs are used for overloadFather Chrysostomos2014-09-151-6/+8
| | | | Takes more code, but I think the new code is clearer....
* Avoid reifying GV when lex stub is used as methodFather Chrysostomos2014-09-151-1/+1
|
* Avoid creating GVs when subs are declaredFather Chrysostomos2014-09-151-5/+26
| | | | | | | | | | | | | | | | | | | | | | | | | | | This patch changes ‘sub foo {...}’ declarations to store subroutine references in the stash, to save memory. Typeglobs still notionally exist. Accessing CvGV(cv) will reify them. Hence, currently the savings are lost when a sub call is compiled. $ ./miniperl -e 'sub foo{} BEGIN { warn $::{foo} } foo(); BEGIN { warn $::{foo} }' CODE(0x7f8ef082ad98) at -e line 1. *main::foo at -e line 1. This optimisation is skipped if the subroutine declaration contains a package separator. Concerning the changes in caller.t, this code: sub foo { print +(caller(0))[3],"\n" } my $fooref = delete $::{foo}; $fooref -> (); used to crash in 5.7.3 or thereabouts. It was fixed by 16658 (aka 07b8c804e8) to produce ‘(unknown)’ instead. Then in 5.13.3 it was changed (by 803f274) to produce ‘main::__ANON__’ instead. So the tests are really checking that we don’t get a crash. I think it is acceptable that it has now changed to ‘main::foo’.
* For lexical subs, reify CvGV from CvSTASH and CvNAME_HEKFather Chrysostomos2014-09-151-1/+24
| | | | | From now on, the presence of a name hek implies a GV. Any access to CvGV will cause that implicit GV to be reified.
* Turn on CVf_LEXICAL for lexical subsFather Chrysostomos2014-09-151-0/+1
| | | | | This flag will signify that lexical subs should not have package names associated with them in error messages, etc.
* introduce gv_stashsvpvn_cached()syber2014-09-021-9/+50
| | | | | | | | | | | | | Wrap gv_stashpvn_internal() with a routine which caches what it does, and rework gv_stashsv() and gv_stashpvn() to use the cached codepath. Also rework the documentation of gv_stashsv() and gv_stashpvn() that the gv_stashsv() is prefered as there is a mechanism to cache the hash value associated with the name which requires an SV to passed in as an argument for caching purposes. Note this is a reworked version of sybers original patch.
* Rename S_stashpvn to S_gv_stashpvn_internal and add to embed.fncYves Orton2014-09-021-4/+13
| | | | | | | S_stashpvn was not added to embed.fnc properly, and is named contrary to general expectations of the Perl internals. This fixes that, there should be no other functional differences.
* Fix crash in leave_scope when my sub has CvGVFather Chrysostomos2014-08-281-1/+4
| | | | | | | Sub declaration can reuse an existing stub. So it is possible to define a package sub using a stub that was originally lexical. Hence, leave_scope needs to take into account that a my-sub may not have a name hek any more.
* Fix crash when lex subs are used for overloadFather Chrysostomos2014-08-281-1/+1
|
* Fix crash when lex subs are used for AUTOLOADFather Chrysostomos2014-08-281-1/+1
|
* Make S_method_common use gv_stashpvn instead of copypasted cache usagesyber2014-08-201-0/+1
| | | | | | The previous commit copied the PL_stashcache handling code from S_method_common() to gv_stashpvn(), so now we can call that function directly rather than doing it ourselves.
* Make gv_stashpvn() use PL_stashcachesyber2014-08-201-2/+21
| | | | | | | | | | | | | perl has a stash name lookup cache, which is currently just used for looking up up class names in Some::Class->method calls. This means that a lookup of the class name 'A::B::C' gets reduced from doing several stash lookups (e.g. $::{'A::'}{'B::'}{'C::'}) to a single cache lookup (e.g. $PL_stashcache{'A::B::C::'}, so to speak). Make gv_stashpvn() use this cache too, which means that all package name lookups benefit, not just class method calls. Among other things, this also indirectly affects bless operations both from Perl (OP_BLESS) and XS.
* Use grok_atou instead of strtoul (no explicit strtol uses).Jarkko Hietaniemi2014-07-221-1/+1
|
* Remove or downgrade unnecessary dVAR.Jarkko Hietaniemi2014-06-251-15/+0
| | | | | | | | You need to configure with g++ *and* -Accflags=-DPERL_GLOBAL_STRUCT or -Accflags=-DPERL_GLOBAL_STRUCT_PRIVATE to see any difference. (g++ does not do the "post-annotation" form of "unused".) The version code has some of these issues, reported upstream.
* Unused contexts found under PERL_GLOBAL_STRUCT.Jarkko Hietaniemi2014-06-241-0/+1
|
* Some low-hanging -Wunreachable-code fruits.Jarkko Hietaniemi2014-06-151-4/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | - after return/croak/die/exit, return/break are pointless (break is not a terminator/separator, it's a goto) - after goto, another goto (!) is pointless - in some cases (usually function ends) introduce explicit NOT_REACHED to make the noreturn nature clearer (do not do this everywhere, though, since that would mean adding NOT_REACHED after every croak) - for the added NOT_REACHED also add /* NOTREACHED */ since NOT_REACHED is for gcc (and VC), while the comment is for linters - declaring variables in switch blocks is just too fragile: it kind of works for narrowing the scope (which is nice), but breaks the moment there are initializations for the variables (the initializations will be skipped since the flow will bypass the start of the block); in some easy cases simply hoist the declarations out of the block and move them earlier Note 1: Since after this patch the core is not yet -Wunreachable-code clean, not enabling that via cflags.SH, one needs to -Accflags=... it. Note 2: At least with the older gcc 4.4.7 there are far too many "unreachable code" warnings, which seem to go away with gcc 4.8, maybe better flow control analysis. Therefore, the warning should eventually be enabled only for modernish gccs (what about clang and Intel cc?)
* Revert "Some low-hanging -Wunreachable-code fruits."Jarkko Hietaniemi2014-06-131-3/+4
| | | | | | | This reverts commit 8c2b19724d117cecfa186d044abdbf766372c679. I don't understand - smoke-me came back happy with three separate reports... oh well, some other time.
* Some low-hanging -Wunreachable-code fruits.Jarkko Hietaniemi2014-06-131-4/+3
| | | | | | | | | | | | | | | | | | - after croak/die/exit (or return), break (or return!) are pointless (break is not a terminator/separator, it's a promise of a jump) - after goto, another goto (!) is pointless - in some cases (usually function ends) introduce explicit NOT_REACHED to make the noreturn nature clearer (do not do this everywhere, though, since that would mean adding NOT_REACHED after every croak) - for the added NOT_REACHED also add /* NOTREACHED */ since NOT_REACHED is for gcc (and VC), while the comment is for linters - declaring variables in switch blocks is just too fragile: it kind of works for narrowing the scope (which is nice), but breaks the moment there are initializations for the variables (they will be skipped!); in some easy cases simply hoist the declarations out of the block and move them earlier There are still a few places left.
* Adding missing HEKfARG() invocationsBrian Fraser2014-06-131-1/+1
| | | | This silences a chunk of warnings under -Wformat
* perlapi: Include general informationKarl Williamson2014-06-051-1/+0
| | | | | | | | | | | Unlike other pod handling routines, autodoc requires the line following an =head1 to be non-empty for its text to be included in the paragraph started by the heading. If you fail to do this, silently the text will be omitted from perlapi. I went through the source code, and where it was apparent that the text was supposed to be in perlapi, deleted the empty line so it would be, with some revisions to make more sense. I added =cuts where I thought it best for the text to not be included.
* Unify the "fall-through" lint annotation.Jarkko Hietaniemi2014-05-291-2/+2
| | | | | | | Used by linters (static checkers), and also good for human readers. Even though "FALL THROUGH" seems to be the most common, e.g BSD lint manual only knows "FALLTHROUGH" (or "FALLTHRU").
* Annotate intentional case fallthrough, or add breaks.Jarkko Hietaniemi2014-05-281-0/+1
| | | | | | | | | | | | | | Fix suspicious (*) switch cases found by Coverity by annotating with either "/* FALLTHROUGH */" or adding a break; The FALLTHROUGH was much more common, but the break turned out to be the right choice in three spots. All changes tested to work. (*) suspicious = case1 + code + case2, and neither flow control (like break) nor fallthrough annotation between code and case2. Fix for Coverity perl5 CIDs 28977..28989, 45353.
* make core safe against HvAUX() reallocDavid Mitchell2014-03-071-7/+3
| | | | | | | | | | | | | | | | | Since the HvAUX structure is just tacked onto the end of the HvARRAY() struct, code like this can do bad things: aux = HvAUX(); ... something that might split hv ... aux->foo = ...; /* SEGV! */ So I've visually audited core for places where HbAUX() is saved and then re-used, and re-initialised the var if it looks like HvARRAY() could have changed in the meantime. I've been very conservative about what might be unsafe. For example, destructors or __WARN__ handlers could call perl code that modifies the hash.
* [perl #121362] overload optimisation added a SEGVDavid Mitchell2014-03-041-2/+4
| | | | | | | | | | | My recent commit 3d147ac29d12abdb to "speed up (non)overloaded derefs" introduced a potential SEGV. In Perl_Gv_AMupdate(), the 'aux' variable is set to HvAUX(hv). My patch used the value of the variable later on in the function, but it turns out that by then, S_hsplit() may have been called, and thus HvARRAY (and HvAUX()) may have been reallocated. Issue first spotted by Andreas' awesome BBC service, and diagnosed by Nicholas Clark.
* speed up (non)overloaded derefsDavid Mitchell2014-02-281-2/+37
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Consider a class that has some minimal overloading added - e.g. to give pretty stringification of objects - but which *doesn't* overload dereference methods such as '@[]'. '%[]' etc. In this case, simple dereferencing, such as $obj->[0] or $obj->{foo} becomes much slower than if the object was blessed into a non-overloaded class. This is because every time a dereferencing is performed in pp_rv2av for example, the "normal" code path has to go through the full checking of: * is the stash into which the referent is blessed overloaded? If so, * retrieve the overload magic from the stash; * check whether the overload method cache has been invalidated and if so rebuild it; * check whether we are in the scope of 'no overloading', and if so is the current method disabled in this scope? * Is there a '@{}' or whatever (or 'nomethod') method in the cache? If not, then process the ref as normal. That's a lot of extra overhead to decide that an overloaded method doesn't in fact need to be called. This commit adds a new flag to the newish xhv_aux_flags field, HvAUXf_NO_DEREF, which signals that the overloading of this stash contains no deref (nor 'nomethod') overloaded methods. Thus a quick check for this flag in the common case allows us to short-circuit all the above checks except the first one. Before this commit, a simple $obj->[0] was about 40-50% slower if the class it was blessed into was overloaded (but didn't have deref methods); after the commit, the slowdown is 0-10%. (These timings are very approximate, given the vagaries of nano benchmarks.)
* Document what the gv_check() function doesDavid Mitchell2014-02-281-0/+5
|
* gv_check(): use aux flag rather than IsCOWDavid Mitchell2014-02-281-5/+12
| | | | | | | | | | Currently the SVf_IsCOW flag doesn't have any meaning for HVs, except that it is used in the specific case of gv_check() to temporarily mark a stash as being scanned. Since stashes will have the HV_AUX fields, we can use a flags bit in the new xhv_aux_flags field instead. This then potentially frees up the SVf_IsCOW for use as a new general flag bit for *all* HVs (including non-stash ones).
* Silence some VC++ compiler warningsSteve Hay2014-02-251-3/+3
| | | | | | | | | | gv.c(1455) : warning C4146: unary minus operator applied to unsigned type, result still unsigned gv.c(1586) : warning C4146: unary minus operator applied to unsigned type, result still unsigned gv.c(2122) : warning C4146: unary minus operator applied to unsigned type, result still unsigned toke.c(12423) : warning C4244: '=' : conversion from 'I32' to 'char', possible loss of data win32.c(3017) : warning C4022: 'SetHandleInformation' : pointer mismatch for actual parameter 1 win32.c(2971) : warning C4101: 'old_h' : unreferenced local variable win32.c(2967) : warning C4101: 'oldfd' : unreferenced local variable
* [perl #115736] fix undocumented param from newATTRSUB_flagsDaniel Dragan2013-12-231-2/+2
| | | | | flags param was poorly designed and didn't have a formal api. Replace it with the bool it really is. See #115736 for details.