summaryrefslogtreecommitdiff
path: root/gv.c
Commit message (Collapse)AuthorAgeFilesLines
* Note that certain flags are documentedKarl Williamson2019-12-171-0/+7
| | | | | | | | | | | This is useful in Devel::PPPort for generating its api-info data. That useful feature of D:P allows someone to find out what was the first release of Perl to have a function, macro, or flag. And whether using ppport.h backports it further. I went through apidoc.pod and looked for flags that were documented but that D:P didn't know about. This commit adds entries for each so that D:P can find them.
* Add the `isa` operatorPaul "LeoNerd" Evans2019-12-091-3/+4
| | | | | | | | | | | | | | | | | | Adds a new infix operator named `isa`, with the semantics that $x isa SomeClass is true if and only if `$x` is a blessed object reference that is either `SomeClass` directly, or includes the class somewhere in its @ISA hierarchy. It is false without warning or error for non-references or non-blessed references. This operator respects `->isa` method overloading, and is intended to replace boilerplate code such as use Scalar::Util 'blessed'; blessed($x) and $x->isa("SomeClass")
* updates to $^H{feature_validname} now update cop_featuresTony Cook2019-12-051-4/+0
| | | | This removes $^{FEATURE_BITS}, since it's no longer needed.
* gv.c: SVf needs to be surrounded by spacesKarl Williamson2019-11-051-2/+2
| | | | perl can be compiled with C++, and this is illegal there.
* S_gv_fetchmeth_internal fix STRLEN warningNicolas R2019-11-041-3/+3
| | | | | | | | | | Fixes #17250 cast STRLEN to int Fix warnings from recent change GH #17222 We could also consider casting it using ' x & PERL_INT_MAX'
* Factor out common code from sv_derived_from_* subs familySergey Aleynikov2019-11-041-2/+2
| | | | | into one that takes both SV*/char*+len arguments, like hv_common, to be able to use speedups from SV* stash lookup API.
* And silence some silly examples.Max Maischein2019-11-031-4/+26
| | | | | | | | From RT88754 Adapted to the current Perl by Max Maischein Created from https://github.com/Perl/perl5/issues/11259
* Faster feature checksTony Cook2019-10-301-0/+4
| | | | | | | | | | | | | | | Perform only a bit check instead of a much more expensive hash lookup to test features. For now I've just added a U32 to the cop structure to store the bits, if we need more we could either add more bits directly, or make it a pointer. We don't have the immediate need for a pointer that warning do since we don't dynamically add new features during compilation/runtime. The changes to %^H are retained so that caller() can be used from perl code to check the features enabled at a given caller's scope.
* gv.c: Note that some GV_foo constants are documentedKarl Williamson2019-09-021-0/+4
|
* (perl #134193) make the varname match the %[+-] namesTony Cook2019-06-191-2/+2
| | | | when loading Tie/Hash/NamedCapture.pm for the long name variants
* (perl #134193) allow %{^CAPTURE} to work when @{^CAPTURE} comes firstTony Cook2019-06-191-4/+2
| | | | | | | | | gv_magicalize() is called when the GV is created, so when the array was mentioned first, the hash wouldn't reach this code and the magic wouldn't be added to the hash. This also fixes a similar problem with (%|@){^CAPTURE_ALL}, though @{^CAPTURE_ALL} is unused at this point.
* Remove remaining assignments to SvCUR and SvLEN in coreDagfinn Ilmari Mannsåker2019-05-281-2/+2
| | | | Also make the macros non-lvalues under PERL_CORE
* Fix recent double free in S_parse_gv_stash_name()David Mitchell2019-04-031-1/+0
| | | | | | | | | | | | | | RT #133977 My recent commit v5.29.9-29-g657ed7c1c1 moved all buffer freeing to the end of the function, but missed removing one of the existing frees. The problem was spotted by James E Keenan and diagnosed by Tony Cook; I just added a test. A simple reproducer is my $def = defined *{"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'x"};
* fix leak in package name lookupDavid Mitchell2019-03-261-4/+9
| | | | | | | | | | | | | | S_parse_gv_stash_name() mallocs a temporary buffer when scanning package names longer than 64 bytes. Depending on how it exits the function, it doesn't always free the buffer afterwards. Change the function so that there are only two exit points (which free the buffer) and make other bits of code goto those two points. Can be reproduced with e.g. &{"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'x"} Similar code is already present in t/op/stash_parse_gv.t
* Perl_try_amagic_un/bin re-indentDavid Mitchell2019-02-051-36/+35
| | | | | After the previous commit's simplification, eliminate a set of braces and re-indent a block of code.
* Eliminate AMGf_set flagDavid Mitchell2019-02-051-13/+2
| | | | | | | | | | | | | | | | | | | | | I added this flag a few years ago when I revamped the overload macros tryAMAGICbin() etc. It allowed two different classes of macros to share the same functions (Perl_try_amagic_un/Perl_try_amagic_bin) by indicating what type of action is required. However, the last few commits have made those two functions able to robustly always determine whether its an assign-type action ($x op= $y or $lex = $x op $x) or a plain set-result-on-stack operation ($x op $y). So eliminate this flag. Note that this makes the ops which have the AMGf_set flag hard-coded infinitesimally slower, since Perl_try_amagic_bin no longer skips the checks for assign-ness. But compared with the overhead of having already called the overload method, this is is trivial. On the plus side, it makes the code smaller and easier to understand.
* Perl_try_amagic_bin(): eliminate dATARGETDavid Mitchell2019-02-051-1/+2
| | | | | | | | | | .. and replace with explicit tests and assigns to targ. This macro includes an OPf_STACKED test which has already been done above. Also, by protecting the OPf_STACKED test within a AMGf_assign test, we can eliminate the AMGf_set flag in the next commit, and use the same set of code for both AMGf_set and AMGf_assign variant calls to Perl_try_amagic_bin().
* Eliminate SvPADMY tests from overload codeDavid Mitchell2019-02-051-3/+19
| | | | | | | | | | | | | | | | | | | | A couple of places in the overload code do SvPADMY(TARG) to decide whether this is a normal op like ($x op $y), where the targ will have SVs_PADTMP set, or a lexical assignment like $lex = ($x op $y) where the assign has been optimised away and the op is expected to directly assign to the targ which it thinks is a PADTMP but is really $lex. Since the SVs_PADMY flag was eliminated a while ago, SvPADMY() is just defined as !(SvFLAGS(sv) & SVs_PADTMP). Thus the overload code is relying on the absence of a PADTMP flag in the target to deduce that the OPpTARGET_MY optimisation is in effect. This seems to work (at least for the code in the test suite), but can't be regarded as robust. This commit removes each SvPADMY() test and replaces it with the twin if ( (PL_opargs[PL_op->op_type] & OA_TARGLEX) && (PL_op->op_private & OPpTARGET_MY)) tests.
* Eliminate opASSIGN macro usage from coreDavid Mitchell2019-02-051-3/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | This macro is defined as (PL_op->op_flags & OPf_STACKED) and indicates, for ops which support it, that the mutator-variant of the op is present (e.g. $x += 1). This macro was mainly used as an arg for the old-style overloading macros (tryAMAGICbin()) which were eliminated several years ago. This commit removes its vestigial usage, and instead tests OPf_STACKED directly at each location, along with adding a comment about the significance of the flag. This removes one item of obfuscation from the overloading code. There is one potentially functional change in this commit: Perl_try_amagic_bin() was sometimes testing for OPf_STACKED without first checking that it had been called with the AMGf_assign flag (which indicates that this op supports a mutator variant). With this commit, it now checks first, so this is theoretically a bug fix. In practice that section of code was never reached without AMGf_assign always being set anyway.
* Fatalize use of $* and $#James E Keenan2018-10-171-11/+6
| | | | | | | | Adapt tests in various files to removal of these variables. Add t/lib/croak/gv to test fatalizations of $# and $* -- tests therein adapted from tests formerly in t/lib/warnings/gv. Per: RT # 133583
* Remove support for setting $[ to a non-zero valueDagfinn Ilmari Mannsåker2018-09-261-11/+2
| | | | This removes arybase and all its surrounding machinery.
* PATCH: [perl #133121] Fix crash in gv_fetchmeth_svSergey Aleynikov2018-04-191-1/+3
| | | | | | S_gv_fetchmeth_internal supports its arguments being either an SV or a (name, len) pair. But when performing an ISA traversal to get method from a parent class, it accounted only for the latter.
* Add ${^SAFE_LOCALES}Karl Williamson2018-02-181-0/+4
| | | | | | | This read-only variable returns a boolean as to whether it is safe to use locales in this perl. Without threads it returns 1; when a future commit adds thread-safe locale handling, it will also return 1 if that is enabled.
* revert smartmatch to 5.27.6 behaviourZefram2017-12-291-3/+2
| | | | | | | | | | | | | The pumpking has determined that the CPAN breakage caused by changing smartmatch [perl #132594] is too great for the smartmatch changes to stay in for 5.28. This reverts most of the merge in commit da4e040f42421764ef069371d77c008e6b801f45. All core behaviour and documentation is reverted. The removal of use of smartmatch from a couple of tests (that aren't testing smartmatch) remains. Customisation of a couple of CPAN modules to make them portable across smartmatch types remains. A small bugfix in scope.c also remains.
* merge branch zefram/dumb_matchZefram2017-12-171-2/+3
|\
| * add "whereis"Zefram2017-12-061-1/+2
| | | | | | | | | | "whereis" is like "whereso" except that it performs an implicit smartmatch.
| * change "when" keyword to "whereso"Zefram2017-12-051-1/+1
| |
| * remove useless "default" mechanismZefram2017-11-281-1/+1
| |
* | stop using &PL_sv_yes as no-op methodZefram2017-12-051-3/+4
|/ | | | | | | | | | | Method lookup yields a fake method for ->import or ->unimport if there's no actual method, for historical reasons so that "use" doesn't barf if there's no import method. This fake method used to be &PL_sv_yes being used as a magic placeholder, recognised specially by pp_entersub. But &PL_sv_yes is a string, which we'd expect to serve as a symbolic CV ref. Change method lookup to yield an actual CV with a body in this case, and remove the special case from pp_entersub. This fixes the remaining part of [perl #126042].
* Blead breaks DBD::SQLiteKarl Williamson2017-11-071-3/+2
| | | | | | | | | | | This partially reverts 0f12654f40. The particular spot being reverted is in gv.c, and the change did not take into account all the nuances involved, so simply revert it. I believe what is happening is that a negative number is being generated and treated as a very large number. Instead the code should retain the original test that it was ok to do the subtraction, before actually doing it.
* Use memBEGINs() in coreKarl Williamson2017-11-061-1/+1
|
* Change some strBEGINs() to memBEGINs()Karl Williamson2017-11-061-2/+3
| | | | | | The latter is generally faster when the length is already known. This commit also changes a few hard-coded numbers to use sizeof().
* Use memEQs, memNEs in core filesKarl Williamson2017-11-061-9/+9
| | | | | | | | | | Where the length is known, we can use these functions which relieve the programmer and the program reader from having to count characters. The memFOO functions should also be slightly faster than the strFOO equivalents. In some instances in this commit, hard coded numbers are used. These come from the 'case' statement values that apply to them.
* Rename strEQs to strBEGINs; remove strNEsKarl Williamson2017-11-061-7/+7
| | | | | | | | | | The original names are confusing. See thread beginning with http://nntp.perl.org/group/perl.perl5.porters/244335 The two macros are mapped into just that one, complementing the result for the few cases where strNEs was used.
* Add OP_MULTICONCAT opDavid Mitchell2017-10-311-1/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Allow multiple OP_CONCAT, OP_CONST ops, plus optionally an OP_SASSIGN or OP_STRINGIFY, to be combined into a single OP_MULTICONCAT op, which can make things a *lot* faster: 4x or more. In more detail: it will optimise into a single OP_MULTICONCAT, most expressions of the form LHS RHS where LHS is one of (empty) my $lexical = $lexical = $lexical .= expression = expression .= and RHS is one of (A . B . C . ...) where A,B,C etc are expressions and/or string constants "aAbBc..." where a,A,b,B etc are expressions and/or string constants sprintf "..%s..%s..", A,B,.. where the format is a constant string containing only '%s' and '%%' elements, and A,B, etc are scalar expressions (so only a fixed, compile-time-known number of args: no arrays or list context function calls etc) It doesn't optimise other forms, such as ($a . $b) . ($c. $d) ((($a .= $b) .= $c) .= $d); (although sub-parts of those expressions might be converted to an OP_MULTICONCAT). This is partly because it would be hard to maintain the correct ordering of tie or overload calls. The compiler uses heuristics to determine when to convert: in general, expressions involving a single OP_CONCAT aren't converted, unless some other saving can be made, for example if an OP_CONST can be eliminated, or in the presence of 'my $x = .. ' which OP_MULTICONCAT can apply OPpTARGET_MY to, but OP_CONST can't. The multiconcat op is of type UNOP_AUX, with the op_aux structure directly holding a pointer to a single constant char* string plus a list of segment lengths. So for "a=$a b=$b\n"; the constant string is "a= b=\n", and the segment lengths are (2,3,1). If the constant string has different non-utf8 and utf8 representations (such as "\x80") then both variants are pre-computed and stored in the aux struct, along with two sets of segment lengths. For all the above LHS types, any SASSIGN op is optimised away. For a LHS of '$lex=', '$lex.=' or 'my $lex=', the PADSV is optimised away too. For example where $a and $b are lexical vars, this statement: my $c = "a=$a, b=$b\n"; formerly compiled to const[PV "a="] s padsv[$a:1,3] s concat[t4] sK/2 const[PV ", b="] s concat[t5] sKS/2 padsv[$b:1,3] s concat[t6] sKS/2 const[PV "\n"] s concat[t7] sKS/2 padsv[$c:2,3] sRM*/LVINTRO sassign vKS/2 and now compiles to: padsv[$a:1,3] s padsv[$b:1,3] s multiconcat("a=, b=\n",2,4,1)[$c:2,3] vK/LVINTRO,TARGMY,STRINGIFY In terms of how much faster it is, this code: my $a = "the quick brown fox jumps over the lazy dog"; my $b = "to be, or not to be; sorry, what was the question again?"; for my $i (1..10_000_000) { my $c = "a=$a, b=$b\n"; } runs 2.7 times faster, and if you throw utf8 mixtures in it gets even better. This loop runs 4 times faster: my $s; my $a = "ab\x{100}cde"; my $b = "fghij"; my $c = "\x{101}klmn"; for my $i (1..10_000_000) { $s = "\x{100}wxyz"; $s .= "foo=$a bar=$b baz=$c"; } The main ways in which OP_MULTICONCAT gains its speed are: * any OP_CONSTs are eliminated, and the constant bits (already in the right encoding) are copied directly from the constant string attached to the op's aux structure. * It optimises away any SASSIGN op, and possibly a PADSV op on the LHS, in all cases; OP_CONCAT only did this in very limited circumstances. * Because it has a holistic view of the entire concatenation expression, it can do the whole thing in one efficient go, rather than creating and copying intermediate results. pp_multiconcat() goes to considerable efforts to avoid inefficiencies. For example it will only SvGROW() the target once, and to the exact size needed, no matter what mix of utf8 and non-utf8 appear on the LHS and RHS. It never allocates any temporary SVs except possibly in the case of tie or overloading. * It does all its own appending and utf8 handling rather than calling out to functions like sv_catsv(). * It's very good at handling the LHS appearing on the RHS; for example in $x = "abcd"; $x = "-$x-$x-"; It will do roughly the equivalent of the following (where targ is $x); SvPV_force(targ); SvGROW(targ, 11); p = SvPVX(targ); Move(p, p+1, 4, char); Copy("-", p, 1, char); Copy("-", p+5, 1, char); Copy(p+1, p+6, 4, char); Copy("-", p+10, 1, char); SvCUR(targ) = 11; p[11] = '\0'; Formerly, pp_concat would have used multiple PADTMPs or temporary SVs to handle situations like that. The code is quite big; both S_maybe_multiconcat() and pp_multiconcat() (the main compile-time and runtime parts of the implementation) are over 700 lines each. It turns out that when you combine multiple ops, the number of edge cases grows exponentially ;-)
* Use SvLEN_set/SvCUR_set in a few extra locationsNicolas R2017-10-191-1/+1
| | | | | | SvLEN was set without using the generic macro SvLEN_set. Use it in three extra locations, and also use SvCUR_set instead of SvCUR.
* get rid of "implicit fallthrough" warnings with gcc 7Lukas Mai2017-10-131-2/+1
|
* [perl #129916] Allow sub-in-stash outside of mainFather Chrysostomos2017-10-081-5/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* Unbreak gv_fetchmeth_svFather Chrysostomos2017-10-081-1/+2
| | | | | | | | | Commit v5.21.6-383-gc290e18 stopped gv_fetchmeth_sv from working cor- rectly when fetching a constant with a utf8 name, because it no longer passed the utf8 flag to the underlying functions. That utf8 flag gets passed to gv_init when upgrading a glob proxy (such as a constant) into a real glob.
* Add CvGvNAME_HEK helperNicolas R2017-09-211-2/+1
| | | | | | | CvGvNAME_HEK can be used instead of the boilerplate: CvNAMED(sv) ? CvNAME_HEK((CV *)sv) : GvNAME_HEK(CvGV(sv)) This is also saving an extra CvNAMED check from CvNAME_HEK.
* add a small buffer to gv_stash_nameNicolas R2017-09-051-5/+14
|
* Reduce malloc&free for S_parse_gv_stash_nameNicolas R2017-09-051-12/+13
| | | | | | | | | | S_parse_gv_stash_name was using multiple malloc and free when using ' as package separator. We can malloc & free only once the tmpbuffer as we know the size max. This is also sligthly improving iterations when using :: as we do not need to check if we need to free the tmp buffer. This is also saving an extra '*gv && *gv != (const GV *)&PL_sv_undef' check.
* use cv_set_call_checker_flags() where possibleZefram2017-08-081-5/+6
| | | | | | | | | | | | | | | Call checkers established by core code were being set through cv_set_call_checker(), so requiring GVs to be created in some cases where they could be avoided. Make all the checkers non-GV-namegv capable, and set them with cv_set_call_checker_flags(). The checkers for Devel::Peek::Dump() and utf8::{unicode_to_native,native_to_unicode}() were already fit to handle non-GV names, so required no changes. The checker for CORE:: subs, ck_entersub_args_core(), was naughtily using the name to decide which sub it was dealing with in some cases, so move that information into the ckobj that was already being used to identify the sub in most cases. It also required reformulation of some error reporting code to use cv_name().
* make callers of SvTRUE() more efficientDavid Mitchell2017-07-271-2/+2
| | | | | | Where its obvious that the args can't be null, use SvTRUE_NN() instead. Avoid possible multiple evaluations of the arg by assigning to a local var first if necessary.
* use the new PL_sv_zero in obvious placesDavid Mitchell2017-07-271-2/+2
| | | | | | | | | | | | | | | | | | | | | | | In places that do things like mPUSHi(0) or newSViv(0), replace them with PUSHs(&PL_sv_zero) and &PL_sv_zero, etc. This avoids the cost of creating and/or mortalising an SV, and/or setting its value to 0. This commit causes a subtle change to tainting in various places as a side-effect. For example, grep in scalar context retunrs 0 if it has no args. Formerly the zero value could in theory get tainted: @a = (); $x = ( ($^X . ""), grep { 1 } @a); It used to be the case that $x would be tainted; now its not. In practice this doesn't matter - the zero value was only getting tainted as a side-effect of tainting's "if anything in the statement uses a tainted value, taint everything" mechanism, which gives (documented) false positives. This commit merely removes some such false positives, and makes the behaviour similar to functions which return &PL_sv_undef/no/yes, which are also immune to side-effect tainting.
* gv.c, mg.c: fix 32-bit compiler warningsDavid Mitchell2017-06-121-4/+4
| | | | | | | | | mg.c:641:21: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast] UV uv = (UV)mg->mg_obj; It's storing a char-ranged integer value as an SV*. By using SSize_t rather than UV to store the char, it avoids mismatched size warnings.
* Fatalize inheriting AUTOLOAD for non-methods.Abigail2017-06-061-5/+3
| | | | This was deprecated in 5.004.
* S_require_tie_mod(): use a new stackDavid Mitchell2017-06-051-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | RT #130861 This function is used to load a module associated with various magic vars, like $[ and %+. Since it can be called 'unexpectedly', it should use a new stack. The issue in this ticket was equivalent to my $var = '['; $$var; where the symbolic dereference triggered a run-time load of arybase.pm, which grew the stack, invalidating the SP in pp_rv2sv. Note that most of the stuff which S_require_tie_mod() calls, such as load_module(), will do its own PUSHSTACK(); but S_require_tie_mod() also does a bit of stack manipulation itself. The test case includes a magic number, 125, which happens to be the exact size necessary to trigger a stack realloc in S_require_tie_mod(). In later perl versions this value may well change. But it seemed too expensive to call fresh_perl_is() 100's of times with different values of $n. This commit also adds a SPAGAIN to pp_rv2sv on the 'belt and braces' principle. This commit is based on an earlier effort by Aaron Crane.
* Add NOT_REACHED to quiet clang -Weverything warningsAndy Lester2017-06-011-0/+1
|
* [perl #131085] Crash with sub-in-stashFather Chrysostomos2017-06-011-1/+1
| | | | | | | | | | $ perl -e '$::{"A"} = sub {}; \&{"A"}' Segmentation fault (core dumped) The code that vivifies a typeglob out of a code ref assumed that the CV had a name hek, which is always the case when perl itself puts the code ref there (via ‘sub A{}’), but is not necessarily the case if someone is insinuating other stuff into the stash.