summaryrefslogtreecommitdiff
path: root/gv.c
Commit message (Collapse)AuthorAgeFilesLines
* Silence compiler warningsRobin Barker2012-02-091-1/+1
| | | | | | | Cf. RT #110208. - Remove missing unused variables: op.c, regcomp.c - Silence -Wformat type error: sv.c - Cast first part of (,) expression as (void): gv.c
* Move amagic hint checking to new functionFather Chrysostomos2012-01-241-17/+26
| | | | so that stringification will be able to use it, too.
* [rt.cpan.org #74289] Don’t make *CORE::foo read-onlyFather Chrysostomos2012-01-231-3/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | newATTRSUB requires the sub name to be passed to it wrapped up in a const op. Commit 8756617677dbd allowed it to accept a GV that way, since S_maybe_add_coresub (in gv.c) needed to pass it an existing GV not in the symbol table yet (to simplify code elsewhere). This had the inadvertent side-effect of making the GV read-only, since that’s what the check function for const ops does. Even if we were to call this a feature, it wouldn’t make sense as implemented, as GVs for non-ampable (&-able) subs like *CORE::chdir were not being made read-only. This commit adds a new flag to newATTRSUB, to allow a GV to be passed as the o parameter, instead of an op. While this may look as though it’s undoing the simplification in commit 8756617677dbd by adding more code, the new code is still conceptually simpler and more straightforward. Since newATTRSUB is in the API, I had to add a new _flags variant. (How did newATTRSUB get into the API to begin with?) In adding a test, I also discovered that ‘used once’ warnings were applying to these subs, which is obviously wrong. Commit 8756617677dbd caused that, too, as it was relying on the side-effect of newATTRSUB doing a GV lookup. This fixes that, too, by turning on the multi flag in S_maybe_add_coresub.
* defined *{"+"} should not stop %+ from workingFather Chrysostomos2012-01-131-0/+4
| | | | | | | | | | | | The same applies to %-. This is something I broke when merging is_magical_gv with gv_fetchpvn_flags. gv_fetchpvn_flags must make sure its *+ glob is present in the symbol table when it loads Tie::Hash::NamedCapture. If it adds it afterwards it will clobber another *+ that Tie::Hash::NamedCapture has autovivi- fied and tied in the mean time.
* defined *{"!"} should not stop %! from workingFather Chrysostomos2012-01-131-0/+4
| | | | | | | | | This is something I broke when merging is_magical_gv with gv_fetchpvn_flags. gv_fetchpvn_flags must make sure its *! glob is present in the sym- bol table it loads Errno. If it adds it afterwards it will clobber another *! that Errno has autovivified and tied in the mean time.
* [perl #24237] @& should not stop $& from workingFather Chrysostomos2012-01-101-4/+9
| | | | | | | | | | | | | | | | | Mentioning $& in a program slows everything down, because it force regular expressions to do a pre-match copy. It used to happen for any symbol named &, e.g., @& and %&. This was changed in commit b4a9608f339, but that commit did not take into account that the code path in question is only followed on creation of the *& glob. It should still be applying magic to $&, even if it is not setting PL_sawampersand. The other place in gv_fetchpvn_flags that magical- ises scalars (which currently handles %- %+ %! $] and @ISA), should also turn on PL_sawampersand for $&. All of the above applies to $' and $` as well.
* Don’t double-free GVs in gv:S_maybe_add_coresubFather Chrysostomos2012-01-011-1/+1
| | | | | Commit 8756617677 did not take into account that newSVOP steals a ref- erence count.
* Simplify gv:S_maybe_add_coresubFather Chrysostomos2012-01-011-22/+7
| | | | | | | | | | | It was working around the fact that newATTRSUB expects to be able to look up the GV by name. And for speed, it was going through hoops to try to avoid creating extra SVs holding the name unnecessarily. By tweaking newATTRSUB to accept a GV instead of a name, we can sim- plify not only S_maybe_add_coresub but all its callers, too.
* diag_listed_as galoreFather Chrysostomos2011-12-281-0/+2
| | | | | In two instances, I actually modified to code to avoid %s for a constant string, as it should be faster that way.
* Move diag_listed_as entry in gv.cFather Chrysostomos2011-12-271-1/+1
| | | | It wasn’t close enough for diag.t to see it.
* Use new feature-testing macrosFather Chrysostomos2011-12-241-1/+2
| | | | | | | Instead of using FEATURE_IS_ENABLED("say"), etc., now use FEATURE_SAY_IS_ENABLED instead. These new macros, in feature.h, also check feature bundle hints in PL_hints, so we can start using those hints. Two commits ago, feature.pm started setting them.
* Use only \w+ for internal feature namesFather Chrysostomos2011-12-241-1/+1
| | | | This will make it possible to create macros for each.
* Disable $[ under 5.16Father Chrysostomos2011-12-151-1/+3
| | | | | | | | | | | | | | | | | | | | | This adds the array_base feature to feature.pm Perl_feature_is_enabled has been modified to use PL_curcop, rather than PL_hintgv, so it can work with run-time hints as well. (PL_curcop holds the current state op at run time, and &PL_compiling at compile time, so it works for both.) The hints in $^H are not stored in the same place at compile time and run time, so the FEATURE_IS_ENABLED macro has been modified to check first whether PL_curop == &PL_compiling. Since array_base is on by default with no hint for it in %^H, it is a ‘negative’ feature, whose entry in %^H turns it off. feature.pm has been modified to support such negative features. The new FEATURE_IS_ENABLED_d can check whether such default features are enabled. This does make things less efficient, as every version declaration now loads feature.pm to disable all features (including turning off array_base, which entails adding an entry to %^H) before loading the new bundle. I have plans to make this more efficient.
* Fix segfault on overloaded arithmetic assignmentDavid Golden2011-12-091-2/+2
| | | | | | | | | | | | | Consider an arithmetic assignment operation of the form $left += $right A segfault was occuring in the case where $right is an overloaded object but $left is not; and where $right does not override "+=" but does provide a 'nomethod' override. Internally, Perl_amagic_call was attempting to clone $left as if it were an overloaded object, causing the segfault. This commit fixes the segfault by only cloning the left operand when the left operand is the overloaded one.
* [perl #105024] UNIVERSAL::AUTOLOAD and %+Father Chrysostomos2011-11-301-1/+1
| | | | | | | | | | The code in gv.c for loading a tie module automatically (S_require_tie_mod) was only loading the module if its stash did not exist or if a particular method (usually TIEHASH) could not be found. But it was triggering autoloading, such that a universal AUTOLOAD method would allow it to ‘find’ the method it was looking for, even if it did not exist. So autovivifying the package somehow (e.g., by men- tioning one of its symbols) could prevent the module from loading.
* panic after cow-to-stash assignmentFather Chrysostomos2011-11-281-1/+3
| | | | | | | | | | | | | | | | | | | | This type of thing isn’t officially supported, but perl shouldn’t be freeing unallocated memory (the 9th octet of a freed HEK) as a result: $::{whatever} = __PACKAGE__; *{"whatever"}; A string stored in the symbol table like that is actually a subroutine stub. ‘sub foo($)’ is stored as '$' in the "foo" slot to save space. gv_init_pvn (formerly known as gv_init) checks SvPOK first thing, assuming, if it is set, that it can reuse SvPVX as the CV’s prototype, without reallocating or copying it. That works most of the time. For COW strings (such as those returned by __PACKAGE__), SvPVX points to the hek_key field (the 9th octet) of a shared HEK. When the CV is freed, it ends up trying to do Safefree(that_hek + 8) effectively, which is bad.
* gv.c: Remove SV_GMAGIC from sv_catpvn_flags call.Father Chrysostomos2011-11-241-1/+1
| | | | This function doesn’t take that flag. It wasn’t doing anything.
* Make constant promotion null-cleanFather Chrysostomos2011-11-201-12/+1
| | | | | | When an optimised constant is promoted to a CV, the name’s length can be passed straight to newCONSTSUB_flags, as it now has a length param- eter which it passes to newXS_len_flags.
* Add len flag to newCONSTSUB_flagsFather Chrysostomos2011-11-201-1/+4
| | | | | This function was added after 5.14.0, so it is not too late to change it. It is currently unused.
* expunge gratuitous Unicode punctuation in commentsZefram2011-11-161-1/+1
|
* [perl #96326] *{$io} should not be semi-definedFather Chrysostomos2011-11-061-5/+1
| | | | | | | | | | | | | | | | | | | | | gv_efullname4 produces undef if the GV points to no stash, instead of using __ANON__, as it does when the stash has no name. Instead of going through hoops to try and work around it elsewhere, fix gv_efullname4. This means that $x = *$io; $x .= "whate’er"; no longer produces an uninitialized warning. (The warning was rather strange, as defined() returned true.) This commit also gives the glob the name $__ANONIO__ (yes, with a dol- lar sign). It may seem a little strange, but there is precedent in other autovivified globs, such as those open() produces when it cannot determine the variable name (e.g, open $t->{fh}).
* Reimplement $[ as a moduleFather Chrysostomos2011-10-211-7/+17
| | | | | | | | | | | | | | | | | This commit reimplements $[ using PL_check hooks, custom pp func- tions and ties. Outside of its compile-time use, $[ is now parsed as a simple varia- ble, so function calls like foo($[) are permitted, which was not the case with the former implementation removed by e1dccc0. I consider that a bug fix. The ‘That use of $[ is unsupported’ errors are out of necessity deferred to run-time and implemented by a tied $[. Indices between 0 and the array base are now treated consistently, as are indices between a negative array base and zero. That, too, is a bug fix.
* [perl #6828] Set $AUTOLOAD once more for XS autoloadingFather Chrysostomos2011-10-111-5/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In 5.6.0, XS autoloading worked. $AUTOLOAD would be set, as with a Perl sub. Commit ed850460 (5.6.1) allowed ‘sub AUTOLOAD;’ to prevent autoload inheritance. But the code to check for that mistakenly equated an XSUB with a forward declaration. So XS autoloading simply did not work any more. Then someone found it didn’t work and introduced it as a ‘new’ feature in 5.8.0, with commit adb5a9ae. For efficiency’s sake, instead of joining the package name and sub name together, only to have the XSUB do the same, it set the CvSTASH and SvPVX fields of the SV. SvPVX was already being used for the sub’s prototype, so 8fa6a409 (just recently) made the autoloaded sub name and the prototype play along nicely together, with a few fix-up commits (05b525f4, 3d5f9785 and 74ee33f2). It was only after that that I find out that $AUTOLOAD used to be set for XSUBs. See the discussion at these two links http://www.nntp.perl.org/group/perl.perl5.porters/;msgid=4E9468E8.8050206@cpan.org https://rt.perl.org/rt3/Ticket/Display.html?id=72708 This commit restores the original behaviour of setting $AUTOLOAD for XSUBs, while retaining the CvSTASH+SvPVX method as well, as it has been documented for a while. Steffen Müller’s AUTOLOAD tests that I committed recently (120b7a08) needed to be adjusted a bit. The test count was off, which was my fault (I *thought* I had checked that.) The test XSUB was using get_sv("AUTOLOAD"), which ended up fetching the caller’s $AUTOLOAD. It was also using SvPV_set on an undefined scalar, which does not turn the SvPOK flag on.
* Avoid creating extra SVs in gv_fullname4Father Chrysostomos2011-10-101-7/+7
|
* gv.c:gv_autoload_pvn: Avoid warning due to temp flagFather Chrysostomos2011-10-101-0/+1
|
* Resolve XS AUTOLOAD-prototype conflictFather Chrysostomos2011-10-091-4/+44
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Did you know that a subroutine’s prototype can be modified with s///? Don’t look: *AUTOLOAD = *Internals'SvREFCNT; my $f = "Just another "; eval{main->$f}; print prototype AUTOLOAD; $f =~ s/Just another /Perl hacker,\n/; print prototype AUTOLOAD; You did look, didn’t you? You must admit that’s creepy. The problem goes back to this: commit adb5a9ae91a0bed93d396bb0abda99831f9e2e6f Author: Doug MacEachern <dougm@covalent.net> Date: Sat Jan 6 01:30:05 2001 -0800 [patch] xsub AUTOLOAD fix/optimization Message-ID: <Pine.LNX.4.10.10101060924280.24460-100000@mojo.covalent.net> Allow AUTOLOAD to be an xsub and allow such xsubs to avoid use of $AUTOLOAD. p4raw-id: //depot/perl@8362 which includes this: + if (CvXSUB(cv)) { + /* rather than lookup/init $AUTOLOAD here + * only to have the XSUB do another lookup for $AUTOLOAD + * and split that value on the last '::', + * pass along the same data via some unused fields in the CV + */ + CvSTASH(cv) = stash; + SvPVX(cv) = (char *)name; /* cast to loose constness warning */ + SvCUR(cv) = len; + return gv; + } That ‘unused’ field is not unused. It’s where the prototype is stored. So, not only is it clobbering the prototype, it’s also leak- ing it by assigning over the top of SvPVX. Furthermore, it’s blindly assigning someone else’s string, which could be freed before it’s even used. Since it has been documented for a long time that SvPVX contains the name of the AUTOLOADed sub, and since the use of SvPVX for prototypes is documented nowhere, we have to preserve the former. So this commit makes the prototype and the sub name share the same buffer, in a manner resembling that which CvFILE used before I changed it with bad4ae38. There are two new internal macros, CvPROTO and CvPROTOLEN for retriev- ing the prototype.
* Don’t put malformed UTF8 in $AUTOLOADFather Chrysostomos2011-10-071-1/+4
|
* Use HEKfFather Chrysostomos2011-10-071-12/+16
| | | | This avoids creating a lot of temporary SVs.
* Suppress some uninit warnings in gv.c:S_maybe_add_coresubFather Chrysostomos2011-10-071-4/+4
| | | | | | Suprisingly, gcc figured out that these were never used uninitialised when I had the body of this function as part of gv_fetchpvn_flags, but now it has trouble recognising that fact.
* Cast to signed before negating, to avoid compiler warningsBrian Fraser2011-10-061-4/+5
|
* gv.c, op.c, pp.c: Stash-injected prototypes and prototype() are UTF-8 clean.Brian Fraser2011-10-061-0/+2
| | | | | | | | This makes perl -E '$::{example} = "\x{30cb}"; say prototype example;' store and fetch the correctly flagged prototype. With this, all TODO tests in gv.t pass; The next commit will deal with making the parsing of prototypes nul-clean.
* gv.c: Use name_end to avoid compiler warningFather Chrysostomos2011-10-061-1/+1
| | | | | | | In this code path, name_cursor could be uninitialised if gv_fetchpvn_flags is called with GV_NOTQUAL|GV_ADDWARN. Whenever it is initialised, it is the same as name_end by the time this part of the function is reached.
* gv.c: Make more warnings utf8-cleanBrian Fraser2011-10-061-24/+30
|
* Make gv.c and pp_ctl.c warnings utf8-cleanBrian Fraser2011-10-061-24/+32
|
* pp_hot.c: method_common is UTF-8 aware.Brian Fraser2011-10-061-2/+4
| | | | | | | | | | Not really useful yet, since named methods aren't correctly flagged; that is to access a \x{30cb} method, you'd need to do something like Obj->${\"\x{30cb}"}. Committer’s note: I’m also including one piece of the ‘gv.c and pp_ctl.c warnings’ patch so that the newly-added tests in this commit pass.
* gv.c: gv_fetchmethod_(flags|autoload) UTF8 cleanup.Brian Fraser2011-10-061-6/+7
|
* gv.c: S_gv_get_super_pkg UTF8 cleanup.Brian Fraser2011-10-061-4/+7
|
* gv.c: gv_fetchmeth_pvn_autoload UTF8 cleanup.Brian Fraser2011-10-061-2/+2
| | | | As with the previous commit, no Perl-level visible changes.
* gv.c: gv_fetchmeth_pvn UTF8 cleanup.Brian Fraser2011-10-061-3/+4
| | | | | | | Since gv_fetchmeth_pvn is primarily used from within gv.c, and not much of anything is passing in the flag yet, this has no visible changes on the Perl level; So tests remain entirely in XS::APItest for the time being.
* gv.c: gv_init_pvn now uses newCONSTSUB_flags.Brian Fraser2011-10-061-1/+1
|
* gv.c: gv_autoload4 is now UTF-8 clean.Brian Fraser2011-10-061-13/+22
| | | | This also uncomments the UTF-8 tests in XS::APItest.
* gv.c: gp_free UTF8 cleanupBrian Fraser2011-10-061-4/+5
|
* Merge multi and flags params to gv_init_*Father Chrysostomos2011-10-061-17/+20
| | | | | Since multi is a boolean (even though it’s typed as an int), there is no need to have a separate parameter. We can just use a flag bit.
* gv.c: Initial gv_fetchpvn_flags and gv_stashpvn UTF8 cleanupBrian Fraser2011-10-061-7/+7
| | | | | | | | | Now that a glob can be initialized and fetched in UTF-8, the next commit will introduce some changes in toke.c to actually test this. Committer’s note: To keep tests passing I had to incorporate the toke.c:S_pending_ident changes in the same patch.
* gv.c: gv_name_set and gv_init_(etc) now initialize the GV's name as UTF-8 if ↵Brian Fraser2011-10-061-21/+18
| | | | | | | | | | | | | | | passed the UTF8 flag. newCONSTSUB is still unclean however, so constant subs are still generated under a wrong name. gv_fullname4 is also UTF-8 aware now; While that should've gotten it's own commit and tests, it's not possible to test the UTF-8 part without the gv_init changes, and it's not possible to test the gv_init changes without gv_fullname4. Chicken and egg, as it were. So let's compromise and wait for the relevant tests once globs can be intiialized as UTF-8 from the Perl level without XS magic.
* gv.c: newGVgen_flags and a flags parameter for gv_get_super_pkg.Brian Fraser2011-10-061-8/+10
|
* Remove method param from gv_autoload_*Father Chrysostomos2011-10-061-6/+8
| | | | | | | | method is a boolean flag (typed I32, but used as a boolean) added by commit 54310121b442. These new gv_autoload_* functions have a flags parameter, so there’s no reason for this extra effective bool. We can just use a flag bit.
* Remove 4 from new gv_autoload4_(sv|pvn?) functionsFather Chrysostomos2011-10-061-8/+8
| | | | | | | | | | | | The 4 was added in commit 54310121b442 (inseparable changes during 5.003/4 developement), presumably the ‘Don't look up &AUTOLOAD in @ISA when calling plain function’ part. Before that, gv_autoload had three arguments, so the 4 indicated the new version (with the method argument). Since these new functions don’t all have four arguments, and since they have a new naming convention, there is not reason for the 4.
* gv.c: Added gv_autoload4_(sv|pv|pvn)Brian Fraser2011-10-061-2/+21
|
* gv.c: Make Gv_AMupdate use gv_fetchmethod_sv_flagsBrian Fraser2011-10-061-2/+1
|