summaryrefslogtreecommitdiff
path: root/gv.c
Commit message (Collapse)AuthorAgeFilesLines
* add GvCV_set() and GvGP_set() macros.David Mitchell2011-01-211-8/+9
| | | | | | | | and make GvCV() and GvGP() rvalue-only. This it to allow a future commit to eliminate some backref magic between GV and CVs, which will require complete control over assignment to the gp_cv slot.
* Generate pp_* prototypes in pp_proto.h, and remove pp.symNicholas Clark2011-01-091-1/+1
| | | | | | | | | | | Eliminate the #define pp_foo Perl_pp_foo(pTHX) macros, and update the 13 locations that relied on them. regen/opcode.pl now generates prototypes for the PP functions directly, into pp_proto.h. It no longer writes pp.sym, and regen/embed.pl no longer reads this, removing the only ordering dependency in the regen scripts. opcode.pl is now responsible for prototypes for pp_* functions. (embed.pl remains responsible for ck_* functions, reading from regen/opcodes)
* Fix typos (spelling errors) in Perl sources.Peter J. Acklam) (via RT2011-01-071-1/+1
| | | | | | | | | # New Ticket Created by (Peter J. Acklam) # Please include the string: [perl #81904] # in the subject line of all future correspondence about this issue. # <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=81904 > Signed-off-by: Abigail <abigail@abigail.be>
* standardise amagic method namingDavid Mitchell2010-12-311-1/+1
| | | | | | | | | | | | | | Some amagic-related macros take the full method enumeration name, (e.g. "add_amg"); while others "helpfully" allow you to pass a shortened version, ("add"), and do a CAT2(meth,_amg) behind the scenes. Standardise on passing the full name; this makes it less confusing and allows you to grep for the enumeration name in the source. It updates two macros to accept full enumeration names: tryAMAGICunTARGET (which isn't used outside the core apparently), and AMG_CALLun, which is replaced by a new AMG_CALLunary (since AMG_CALLun is used outside the core).
* Silence some data truncation compiler warningsJan Dubois2010-12-161-1/+1
|
* [perl #71286] fallback/nomethod failuresMichael Breen2010-12-031-6/+19
| | | | | | | | | | | | | | | | | This fixes two bugs related to overload and fallback on binary ops. First, if *either* of the args has a 'nomethod', this will now be used; previously the RH nomethod was ignored if the LH arg had fallback value of undef or 1. Second, if neither arg has a 'nomethod', then the fallback to the built-in op will now only occur if *both* args have fallback => 1; previously it would do so if the *RHS* had fallback => 1. Clearly the old behaviour was wrong, but there were two ways to fix this: (a) *both* args have fallback => 1; (b) *either* arg has fallback=> 1. It could be argued either way, but the the choice of 'both' was that classes that hadn't set 'fallback => 1' were implicitly implying that their objects aren't suitable for fallback, regardless of the presence of conversion methods.
* Eliminate strlen and strEQ usage in gv_fetchmethodFlorian Ragwitz2010-11-301-4/+5
| | | | | This commit brought to you with the aid of the campaign for elimination of strlen().
* Filehandle method calls load IO::File on demandDavid Golden2010-11-291-0/+13
| | | | | | | | | | | | | | | | | | | | | When a method call on a filehandle would die because the method can not be resolved and L<IO::File> has not been loaded, Perl now loads IO::File via C<require> and attempts method resolution again: open my $fh, ">", $file; $fh->binmode(":raw"); # loads IO::File and succeeds This also works for globs like STDOUT, STDERR and STDIN: STDOUT->autoflush(1); Because this on-demand load only happens if method resolution fails, the legacy approach of manually loading an IO::File parent class for partial method support still works as expected: use IO::Handle; open my $fh, ">", $file; $fh->autoflush(1); # IO::File not loaded
* Fix compiler warningFather Chrysostomos2010-11-261-1/+1
|
* [perl #78634] Conflict in defining constant INITFather Chrysostomos2010-11-261-0/+3
| | | | | | | | | | | | | When gv_init tries to turn a constant named INIT into a CV, the auto- matic special processing of the INIT ‘block’ kicks in, which removes the CV from the GV. This should not happen with gv_init, as $::{INIT} = \5 is supposed to be equivalent to *INIT = sub(){5}, which does not do that. This commit makes gv_init check for that, increase the reference count, and reassign the CV. It does not stop the CV from being called as a special block, but it is harmless to call a constant CV.
* Only call mro_package_moved on new substashesFather Chrysostomos2010-11-221-8/+10
| | | | | | | | | | | | Commit 298d65111 added this mro_package_moved call. It does not need to happen if the substash already exists, as it will already have had effective names assigned to it. It also may not be a good idea to set it in such cases, as it may make a recursive call to mro_get_linear_isa. I know this is utter paranoia, but someone may write a mro plugin that is not reëntrant. (The speed gain is worth it, though.)
* Newly-created stashes may need effective names addedFather Chrysostomos2010-11-221-0/+6
|
* Eliminate PL_dirtyFlorian Ragwitz2010-11-141-1/+1
| | | | | It now only exists as a compatibility macro for extensions that want to introspect it.
* Add ${^GLOBAL_PHASE}Florian Ragwitz2010-11-141-1/+6
| | | | This exposes the current top-level interpreter phase to perl space.
* [perl #79024] Bleadperl 80ebaca breaks OVID/Class-Trait-0.31.tar.gzFather Chrysostomos2010-11-111-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | Commit 80ebaca actually exposed an existing bug that Class::Trait was really close to triggering already: undef *ISA; # @ISA no longer magical Class::Trait’s tests just happened not to call ->isa before making any changes to @ISA. Now that the meta->isa cache is created immediately, Class::Trait fails. This bug can be reproduced in earlier perls by putting an ->isa call right after the undef: undef *{"Extra::TSpouse::ISA"}; 'Extra::TSpouse'->isa('Class::Trait::Base'); unshift @{"Extra::TSpouse::ISA"}, Class::Trait::Base; warn Extra::TSpouse->isa('Class::Trait::Base'); # something's wrong This commit modifies gv_fetchpvn_flags to magicalise @ISA whenever it is fetched.
* Add Perl_amagic_deref_call() to implement the bulk of tryAMAGICunDEREF_var().Nicholas Clark2010-11-031-0/+19
| | | | | | | | | This removes around 300 bytes of object code from each place it was previously inlined. It also provides a better interface - quite a lot of the core currently bodges things by creating a local variable C<SV **sp = &sv> to use the macro. Change the XS::APItest wrapper to amagic_deref_call().
* Inline RvDEEPCP() into its only caller, Perl_amagic_call().Nicholas Clark2010-11-021-1/+9
| | | | | | | Only Perl_amagic_call() was using RvDEEPCP() when it was added in 5.000, and I believe that it's never had any other users (in the core, on CPAN, or anywhere else visible to Google codesearch). Hence it seems an ideal candidates to be inlined and eliminated.
* Expand AMG_CALLun_var() into all its users, and eliminate it.Nicholas Clark2010-11-021-1/+2
| | | | | Aside from the 2 callers where it can be replaced with AMG_CALLun(). AMG_CALLun_var was only used in core.
* add CvSTASH_set() macro and make CvSTASH() rvalue onlyZefram2010-10-251-8/+17
| | | | | | Now that CvSTASH requires backreference bookkeeping, stop people from directly assigning to it (by using CvSTASH() as an lvalue), and instead force them to use CvSTASH_set().
* full API for cop hint hashesZefram2010-10-211-2/+1
| | | | | | | | | | | | | Expose cop hint hashes as a type COPHH, with a cophh_* API which is a macro layer over the refcounted_he_* API. The documentation for cophh_* describes purely API-visible behaviour, whereas the refcounted_he_* documentation describes the functions mainly in terms of the implementation. Revise the cop_hints_* API, using the flags parameter consistently and reimplementing in terms of cophh_*. Use the cophh_* and cop_hints_* functions consistently where appropriate. [Modified by the committer to update two calls to Perl_refcounted_he_fetch recently added to newPMOP.]
* In Perl_gv_autoload4(), remove weakref before reassigning to CvSTASH()Nicholas Clark2010-10-211-0/+2
| | | | | | | Fixes a minor bug introduced in 4c74a7df3242aa95. The underlying assumption of the XS AUTOLOAD implementation, that the fields are unused, remains invalid.
* Remove now-unused parameters from S_gv_magicalize_isa().Nicholas Clark2010-10-091-3/+3
| | | | 997daa56862a0fc7 eliminated the need for passing these in.
* Move the automatic instantiation of @AnyDBM_File::ISA to Perl_yylex()Nicholas Clark2010-10-091-15/+0
| | | | | | | | | | | case KEY_dbmopen in Perl_yylex() has always had special-case code to create @AnyDBM_File::ISA, using GV_ADDMULTI. S_gv_magicalize_isa() [part of Perl_gv_fetchpvn_flags()] has special case code to spot "AnyDBM_File::ISA" being created with GV_ADDMULTI, and populate the variable if it is empty. Grouping the special case code in one place makes more sense. Removing the special case code from gv.c means that there is no longer a check clause in the code path for *every* package's @ISA initialisation.
* Remove dead code from Perl_gv_stashpvn().Nicholas Clark2010-10-081-4/+2
| | | | | | | | GvHV() and HvNAME() will both always already be set, as gv_fetchpvn_flags() will initialise these as it walks the string in its initial loop to locate the correct stash, then return early because name == name_end. This code has been dead since it was added in 5.000.
* Fix bugs in e771aaa95f65a9c4 (reducing copying in gv_fetchpvn_flags)Nicholas Clark2010-10-081-8/+9
| | | | Bug spotting and 1 fix by Jerry D. Hedden.
* Perl_gv_fetchpvn_flags() can avoid copying when the package separator is ::Nicholas Clark2010-10-081-8/+9
|
* Avoid downgrading GVs during global destructionFather Chrysostomos2010-10-031-0/+5
| | | | | | | | | | | | | | | | | | | | | | Recently we’ve been getting assertions from gv.t like this: Assertion failed: (SvTYPE(sv) != SVTYPEMASK), function Perl_sv_clear, file sv.c, line 5783. This only happens in non-threaded builds and with PERL_DESTRUCT_LEVEL set to 2 (as in make test). These started with 13be902 (lvalue-to-glob assignment), but only because of the tests it added. The real cause turns out to be f746176, which introduced gv_try_downgrade. If a subroutine contains an op that references a downgradable GV, then gv_try_downgrade, if called on that GV during global destruction, *might* leave dangling pointers elsewhere; where exactly I wot not. Since memory-saving operations such as this downgrading are questiona- ble anyway durng global destruction, skip it, at least for now.
* [perl #77362] Assigning glob to lvalue causes stringificationFather Chrysostomos2010-09-261-1/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This test from t/op/gv.t was added by change 22315/4ce457a6: { # test the assignment of a GLOB to an LVALUE my $e = ''; local $SIG{__DIE__} = sub { $e = $_[0] }; my $v; sub f { $_[0] = 0; $_[0] = "a"; $_[0] = *DATA } f($v); is ($v, '*main::DATA'); my $x = <$v>; is ($x, "perl\n"); } That change was the one that made glob-to-lvalue assignment work to begin with. But this test passes in perl version *prior* to that change. This patch fixes the test and adds tests to make sure what is assigned is actually a glob, and not just a string. It also happens to fix the stringification bug. In doing so, it essen- tially ‘enables’ globs-as-PVLVs. It turns out that many different parts of the perl source don’t fully take this into account, so this patch also fixes the following to work with them (I tried to make these into separate patches, but they are so intertwined it just got too complicated): • GvIO(gv) to make readline and other I/O ops work. • Autovivification of glob slots. • tie *$pvlv • *$pvlv = undef, *$pvlv = $number, *$pvlv = $ref • Duplicating a filehandle accessed through a PVLV glob when the stringified form of the glob cannot be used to access the file handle (!) • Using a PVLV glob as a subroutine reference • Coderef assignment when the glob is no longer in the symbol table • open with a PVLV glob for the filehandle • -t and -T • Unopened file handle warnings
* [perl #71806] perldb does not setup %dbline with the shebang option -dFather Chrysostomos2010-09-231-2/+2
| | | | | | | | | | | | | | | The first time gv_fetchfile is called for a particular file, it creates the glob and, if debugging is on, creates an AV. If the glob already exists (i.e., in subsequent calls), the AV is not created. The attached patch moves the check for debugging mode and the creation of the AV outside the if-block that checks whether the glob exists. This bug seems to have existed for a very long time and has been intermittent. It seems that many different things can change the order in which #!perl -d and gv_fetchfile occur. Whether compilation options affect it I do not know. I can reproduce it in 5.6.2, 5.8.[123456] (non-threaded) and 5.11.3 (both threaded and non-threaded), but not 5.8.[789] or 5.10.[01] (threaded).
* Fix build for threaded perlsFlorian Ragwitz2010-09-081-2/+2
| | | | Ooops. I broke it with commit ad7cce9f36d376e55b45dd79ec28a7f795b5ae4e.
* Move magicalize_{isa,overload} out into functionsFlorian Ragwitz2010-09-081-28/+44
| | | | | This way c++ compilers like us again, as we don't do jumps that skip initialisations anymore.
* [perl #76138] perl inadvertently destroys signal handlers as of f746176000Father Chrysostomos2010-09-061-21/+50
| | | | | Stop magic applied to $!, %SIG, et al. from applying to similarly- named variables in other packages.
* small code tweak in Perl_gv_initDavid Mitchell2010-07-241-1/+2
| | | | (follow-up to previous commit, fix for #76540)
* [perl #76540] "print CONSTANT," gives double-freeDavid Mitchell2010-07-241-1/+9
| | | | | | | | | gv_init() has name and len args, but newCONSTSUB() (which it calls) doesn't have a len arg, so any trailing garbage in name gets used by newCONSTSUB. In the test case, this means that we end up attaching the const CV to both the "FOO" and qq{FOO, "\\n";\n} GVs. So it gets freed twice.
* add CvGV_set() macro and make CvGV() rvalue onlyDavid Mitchell2010-07-181-2/+2
| | | | | | Now that CvGV can sometimes be reference counted, stop people from directly assigning to it (by using CvGV as an lvalue), and instead force them to use CvGV_set()
* change when to make CvGV refcountedDavid Mitchell2010-07-181-4/+4
| | | | | | | | | | | Rather than making CvGV refcounted if the CV is anon, decide based on whether the GV pointed to by CvGV holds a reference back to us. Normally these two will be equivalent, but this way is more robust if people are doing weird things. Also spotted an error with cv_clone not clearing the CVf_CVGV_RC flag on the newly cloned cv. This shouldn't normally matter as it will get set shortly anyway, but best to keep things logically correct.
* add CVf_CVGV_RC flagDavid Mitchell2010-07-181-4/+4
| | | | | | | | | | | | | after the recent commit 803f274831f937654d48f8cf0468521cbf8f5dff, the CvGV field is sometimes reference counted. Since it was intended that the reference counting would happen only for anonymous CVs, the CVf_ANON flag was co-opted to indicate whether RC was being used. This is not entirely robust; for example, sub __ANON__ {} is a non-anon sub which points to the same GV used by anon subs, which while itself doesn't directly break things, shows that the potential for breakage is there. So add a separate flag just to indicate the reference count status of the CvGV field.
* protect CvGV weakref with backrefDavid Mitchell2010-07-141-2/+49
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Each CV usually has a pointer, CvGV(cv), back to the GV that corresponds to the CV's name (or to *foo::__ANON__ for anon CVs). This pointer wasn't reference counted, to avoid loops. This could leave it dangling if the GV is deleted. We fix this by: For named subs, adding backref magic to the GV, so that when the GV is freed, it can trigger processing the CV's CvGV field. This processing consists of: if it looks like the freeing of the GV is about to trigger freeing of the CV too, set it to NULL; otherwise make it point to *foo::__ANON__ (and set CvAONON(cv)). For anon subs, make CvGV a strong reference, i.e. increment the refcnt of *foo::__ANON__. This doesn't cause a loop, since in this case the __ANON__ glob doesn't point to the CV. This also avoids dangling pointers if someone does an explicit 'delete $foo::{__ANON__}'. Note that there was already some partial protection for CvGV with commit f1c32fec87699aee2eeb638f44135f21217d2127. This worked by anonymising any corresponding CV when freeing a stash or stash entry. This had two drawbacks. First it didn't fix CVs that were anonmous or that weren't currently pointed to by the GV (e.g. after local *foo), and second, it caused *all* CVs to get anonymised during cleanup, even the ones that would have been deleted shortly afterwards anyway. This commit effectively removes that former commit, while reusing a bit of the actual anonymising code.
* protect CvSTASH weakref with backrefsDavid Mitchell2010-07-141-0/+4
| | | | | | | | | | | | | | Each CV usually has a pointer, CvSTASH, back to the stash that it was complied in. This pointer isn't reference counted, to avoid loops. Which can leave it dangling if the stash is deleted. There is already protection for the similar GvSTASH field in GVs: the stash has an array of backrefs, xhv_backreferences, pointing to the GVs whose GvSTASHes point to it, and which is used to zero all the GvSTASH fields should the stash be deleted. All this patch does is also add the CVs with CvSTASH to that stash's backref list too.
* tidy some code in gv_init()David Mitchell2010-07-141-6/+8
| | | | Use an intermediate variable cv to avoid lots of GvCV(gv)'s
* make overload respect get magicDavid Mitchell2010-05-211-0/+96
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In most places, ops checked their args for overload *before* doing mg_get(). This meant that, among other issues, tied vars that returned overloaded objects wouldn't trigger calling the overloaded method. (Actually, for tied and arrays and hashes, it still often would since mg_get gets called beforehand in rvalue context). This patch does the following: Makes sure get magic is called first. Moves most of the overload code formerly included by macros at the start of each pp function into the separate helper functions Perl_try_amagic_bin, Perl_try_amagic_un, S_try_amagic_ftest, with 3 new wrapper macros: tryAMAGICbin_MG, tryAMAGICun_MG, tryAMAGICftest_MG. This made the code 3800 bytes smaller. Makes sure that FETCH is not called multiple times. Much of this bit was helped by some earlier work from Father Chrysostomos. Added new functions and macros sv_inc_nomg(), sv_dec_nomg(), dPOPnv_nomg, dPOPXiirl_ul_nomg, dPOPTOPnnrl_nomg, dPOPTOPiirl_ul_nomg dPOPTOPiirl_nomg, SvIV_please_nomg, SvNV_nomg (again, some of these were based on Father Chrysostomos's work). Fixed the list version of the repeat operator (x): it now only calls overloaded methods for the scalar version: (1,2,$overloaded) x 10 no longer erroneously calls x_method($overloaded,10)) The only thing I haven't checked/fixed yet is overloading the iterator operator, <>.
* [perl #73712] ‘Variable is not imported’ cannot be suppressedFather Chrysostomos2010-04-131-2/+7
| | | | | | | | | | | | | | | | The message ‘Variable "%s" is not imported’ cannot be suppressed, even with -X (local $SIG{__WARN__}=sub{} is what I have to use): perl -Xle '$foo;use strict; eval q/$foo/ or die "---$@---"' Variable "$foo" is not imported at (eval 1) line 2. ---Global symbol "$foo" requires explicit package name at (eval 1) line 2. --- at -e line 1. This is because we have what appears to the user to be a multi-line error message. It is in fact a warning ‘Variable...’ followed by an error ‘Global symbol...’. The attached patch assigns a warning category to the warning.
* PL_defoutgv isn't always a GV.David Mitchell2010-03-301-2/+2
| | | | | | | | | | | | | | | | | | | | Nasty code like the following results in PL_defoutgv not pointing to a valid GV: my $x = *STDERR; select($x); $x = 1; This causes all sorts of SEGVs when PL_defoutgv is subsequently accessed, because most code assumes that it has a valid gv_gp pointer. It also turns out that PL_defoutgv is under-tested; for example, temporarily hacking pp_close to make an arg-less close() croak didn't cause any minitest failures. Add a new test file that does some basic testing of a bad PL_defoutgv, and fix all the obvious badness in accessing it. This also fixes #20727, which although ostensibly a tie bug, was due to PL_defoutgv pointing to a tiedelem scalar, and fun like that described above happening.
* [perl #72740]: Blead breaks LEMBARK/LinkedList-Single-0.99.1.tar.gzZefram2010-03-101-10/+23
| | | | | | | | | | | | | | | | | | | | | | | | | | f7461760003db2ce68155c97ea6c1658e96fcd27 improved the PL_check hook for bareword subs, but broke the above module. This is Zefram's followup: The issue is that speculative function lookups were leaving detritus consisting of empty GVs in the stash. These didn't affect normal functioning, but code that looks inside the stash could see them, and code that makes unreliable assumptions about the format of the stash can be broken. This is the same general mode of failure that we saw with namespace::clean. LinkedList-Single's failing test was using direct stash access poorly, in a way that made for a poor test, quite apart from making too many assumptions about stash structure. In the latest version of the package, 0.99.6, the test has been changed to a much better form, which actually tests what it meant to and incidentally doesn't read the stash at all. Although they don't affect normal functioning, the empty GVs shouldn't be there. It's much like the upgraded constant subs, which we concluded ought to be downgraded when the upgraded form is no longer required, in order to save memory. The solution here is similar: delete the empty GV when it is detected that a real GV is no longer required. The present patch does this at the same time as checking for constant-sub downgradability.
* Make perl's magic variables in gv.c grep-ableÆvar Arnfjörð Bjarmason2010-01-201-35/+35
| | | | | | It can be hard especially for those unfamiliar with the source to find where variables like $` and $[ are set up, now they're just a ack -Q away.
* fix bug 67156: overload: nomethod(..., '!') return value invertedMichael Breen2009-12-141-20/+10
|
* Bareword sub lookupsZefram2009-11-081-0/+47
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Attached is a patch that changes how the tokeniser looks up subroutines, when they're referenced by a bareword, for prototype and const-sub purposes. Formerly, it has looked up bareword subs directly in the package, which is contrary to the way the generated op tree looks up the sub, via an rv2cv op. The patch makes the tokeniser generate the rv2cv op earlier, and dig around in that. The motivation for this is to allow modules to hook the rv2cv op creation, to affect the name->subroutine lookup process. Currently, such hooking affects op execution as intended, but everything goes wrong with a bareword ref where the tokeniser looks at some unrelated CV, or a blank space, in the package. With the patch in place, an rv2cv hook correctly affects the tokeniser and therefore the prototype-based aspects of parsing. The patch also changes ck_subr (which applies the argument context and checking parts of prototype behaviour) to handle subs referenced by an RV const op inside the rv2cv, where formerly it would only handle a gv op inside the rv2cv. This is to support the most likely kind of modified rv2cv op. The attached patch is the resulting revised version of the bareword sub patch. It incorporates the original patch (allowing rv2cv op hookers to control prototype processing), the GV-downgrading addition, and a mention in perldelta.
* Implement the 'qr' overload type.Ben Morrow2009-11-011-0/+1
| | | | | | | | | | | If this is defined, it will be called instead of stringification whenever an object is used as a regexp or interpolated into a regexp. This will fall back to stringification even without C<fallback => 1>, for compatibility. An overloaded 'qr' must return either a REGEXP or a ref to a REGEXP (such as created by qr//). Any further overloading on the return value will be ignored.
* Enable deprecation warnings by default.Nicholas Clark2009-10-161-3/+3
|
* Remove category 'syntax' from 5 warnings that should just be in 'deprecated'.Nicholas Clark2009-10-131-1/+1
| | | | | | | None were documented as also being in 'syntax'. Effectively, this completes the reorganisation of commits 12bcd1a617c74d6e and 9014280dc8264580. See http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/2009-10/msg00601.html and http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/2002-03/msg00850.html