summaryrefslogtreecommitdiff
path: root/sv.c
Commit message (Collapse)AuthorAgeFilesLines
* In Perl_sv_del_backref(), don't panic if svp is NULL during global destruction.Nicholas Clark2012-01-131-3/+12
| | | | | | | | It's possible that the referencing SV is being freed partway through the freeing of reference target. If this happens, the backreferences array of the target has already been freed, and so svp will be NULL. If this is the case, do nothing and return. Previously, this condition was not recognised and the code would panic.
* In Perl_sv_del_backref(), don't panic if the backref array is already freed.Nicholas Clark2012-01-131-0/+3
| | | | | | | | | | During global destruction, it's possible for the array containing backreferences to be freed before the SV that owns it. If this happens, don't mistake it for a scalar backreference stored directly, and then get confused and panic because things seem inconsistent. http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/2011-12/msg00039.html gives more information.
* Better panic diagnostics in Perl_sv_del_backref()Nicholas Clark2012-01-131-2/+3
| | | | | | If panicing with a croak(), include in the panic message the values which caused the croak. This reveals something about the cause of the panic, and more subtly, which of the two possible panic locations this is.
* [perl #107366] Don’t clone GVs during thread joinFather Chrysostomos2012-01-011-0/+21
| | | | | | | | | | | | | | | | unless they are orphaned. This commit stops globs that still reside in their stashes from being cloned during a join. That way, a sub like sub{$::x++}, when cloned into a subthread and returned from it, will still point to the same $::x. This commit takes the conservative approach of copying on those globs that can be found under their names in the original thread. While this doesn’t work for all cases, it’s probably not possible to make it work all the time.
* [perl #103492] Make %n printf format work with UnicodeFather Chrysostomos2011-12-311-1/+1
| | | | | | | It was using the internal byte count instead of the number of charac- ters. The iatter is documented. The former is useless, even for C code calling this, as later arguments could cause the current buffer to be upgraded to utf8, throwing off any offsets returned.
* 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.
* Correct spelling of sv_insert error msgFather Chrysostomos2011-12-281-1/+1
| | | | It is already documented in perldiag with the right spelling.
* perldiag: Remove ‘in %s’ from bizarre copy msgFather Chrysostomos2011-12-271-0/+1
| | | | | so that splain can find the message even when there is no op mentioned.
* sv.c:dirp_dup: Avoid compiler warningFather Chrysostomos2011-12-251-1/+1
| | | | | | | Some compilers complain, because -1 is being assigned to an unsigned variable. This variable is not actually used before being assigned to, but we have to initialise it as some other compilers cannot detect that.
* Add diag_listed_as for non-numeric warningsFather Chrysostomos2011-12-251-0/+2
|
* sv.c: consistent spaces after dots in apidocsFather Chrysostomos2011-12-231-7/+9
|
* Don’t clobber all magic when clobbering vstringFather Chrysostomos2011-12-231-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This code in sv_setsv, introduced in ece467f9b3, can’t possi- bly be right: if ( SvVOK(dstr) ) { /* need to nuke the magic */ mg_free(dstr); } And here is a test to prove it: sub TIESCALAR { bless[]} sub STORE {} tie $@, ""; $@ = v0; warn tied $@; # main=ARRAY(0xc0ffee) $@ = 3; warn tied $@; # something’s wrong It blows away tiedness. You could do that to any variable. Let’s see: $! = v0; $! = 3; open foo, 'oentuhaeontu' or die $!; # 3 at - line 3. Youch! Let’s just free vstring magic, shall we?
* Avoid an unused temp scalar in sv.c:S_sv_unglobFather Chrysostomos2011-12-171-1/+1
| | | | This is something I missed in 804b5ed7.
* [perl #97988] Nullify PL_last_in_gv when unglobbedFather Chrysostomos2011-12-171-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | Code like this can cause PL_last_in_gv to point to a coercible glob: $f{g} = *STDOUT; readline $f{g}; If $f{g} is then modified such that it is no longer a glob, PL_last_in_gv ends up pointing to a non-glob: $f{g} = 3; If $f{g} is freed now, the PL_last_in_gv-nulling code in sv_clear will be skipped, as it only applies to globs. undef %f; # now PL_last_in_gv points to a freed scalar The resulting freed scalar can be reused by another handle, *{"foom"} = *other; causing tell() with no arguments to return the position on *other, even though *other was no the last handle read from. This commit fixes it by nulling PL_last_in_gv when a coercible glob is coerced.
* perldiag: Retitle ‘Cannot copy’Father Chrysostomos2011-12-161-0/+1
| | | | Without the ‘in %s’ it covers both forms of the error message.
* Use syntax from perlguts for testing objectsJohn Peacock2011-12-091-1/+1
| | | | | | | | | | | | | The following paragraph is in perlguts.pod: To check if you've got an object derived from a specific class you have to write: if (sv_isobject(sv) && sv_derived_from(sv, class)) { ... } which does the right thing with magical things like tied scalars. Signed-off-by: David Golden <dagolden@cpan.org>
* Clarify docs for sv_usepvn_flagsFather Chrysostomos2011-12-041-1/+3
| | | | | Note that the string must be the start of a mallocked block of memory, and not a pointer to the middle of it.
* Remove SvTAINT from sv_sethekFather Chrysostomos2011-12-031-4/+0
| | | | | | | | | | | This was copied from sv_usepvn_flags in commit 58b643af9. It is unnecessary, and probably incorrect, as heks are not tainted. Why sv_sethek used sv_usepvn_flags to begin with I don’t know, but I imagine it was for brevity’s sake. This code was ultimately derived from newSVhek, which doesn’t use sv_usepvn_flags. Because of that, and because it is now far enough removed from sv_usepvn_flags, I have removed the comment referring to it.
* Stop calling sv_usepvn_flags from sv_sethekPeter Martini2011-12-031-1/+7
| | | | | | | | | | | | | | | sv_usepvn_flags assumes that ptr is at the head of a block of memory allocated by malloc. If perl's malloc is in use, the data structures malloc uses and the data allocated for perl are intermixed, and accounting done by malloced_size in sv_usepvn_flags will overwrite valid memory if its called on an address that is not the start of a malloced block. The actual work being accomplished by sv_usepvn_flags, and not undone immediately after by sv_sethek, is limited to 3 calls on the SV. Inlining those calls removes the dependency on malloc. This fixes perl #104034.
* Allow COW PVMGs to be tiedFather Chrysostomos2011-12-011-3/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This logic in sv_magic is wrong: if (SvREADONLY(sv)) { if ( /* its okay to attach magic to shared strings; the subsequent * upgrade to PVMG will unshare the string */ !(SvFAKE(sv) && SvTYPE(sv) < SVt_PVMG) && IN_PERL_RUNTIME && !PERL_MAGIC_TYPE_READONLY_ACCEPTABLE(how) ) { Perl_croak_no_modify(aTHX); } } There is nothing wrong with attaching magic to a shared string that will stay shared. Also, shared strings are not always < SVt_PVMG. Sometimes a PVMG or PVLV can end up with a shared string. In those cases, the logic above treats them as read-only, which they ain’t. The easiest example is a downgraded typeglob: $x = *foo; # now a PVGV undef $x ; # downgraded to PVMG $x = __PACKAGE__; # now a shared string (COW) tie $x, "main"; # bang! $x is considered read-only sub main::TIESCALAR{bless[]}
* Use SvOOK_onFather Chrysostomos2011-12-011-3/+2
| | | | | | Now that SvOOK_on has a usable definition (i.e., it leaves the NIOK flags alone), we can use it and remove the comments warning against it.
* sv.c: fix comment typo added by ce2077b184Father Chrysostomos2011-11-301-1/+1
|
* sv.c/find_uninit_var: Explain kid-scanning loop betterFather Chrysostomos2011-11-291-2/+7
| | | | | Hopefully this explanation will be clearer and will prevent clumsy individuals like me from introducing bugs like #103766.
* sv.c: typoFather Chrysostomos2011-11-291-1/+1
|
* sv.c: Turn a FIXME comment into an explanationFather Chrysostomos2011-11-271-3/+3
|
* ‘Inline’ S_sv_unglobFather Chrysostomos2011-11-241-1/+1
| | | | | S_sv_unglob is only called in one place, so inline it (but cheat, to preserve blame history).
* Make COW-clobbering fasterFather Chrysostomos2011-11-241-3/+8
| | | | | | | | | | | | | | | | | | | | | | | There is this special SV_COW_DROP_PV flag that gets passed to sv_force_normal_flags to signal that the SV is about to be clobbered, so there is no point in allocating a new PV. But this flag was not actually being used, until the previous commit commandeered it for globs (despite the name). Now it actually does what it says. Before and after: $ time ./perl -e '$x = __PACKAGE__, undef $x for 1..8000000' real 0m5.758s user 0m5.740s sys 0m0.008s $ time ./perl -e '$x = __PACKAGE__, undef $x for 1..8000000' real 0m3.290s user 0m3.282s sys 0m0.006s
* Make assignment over glob copies much fasterFather Chrysostomos2011-11-241-4/+6
| | | | | | | | | | | | | | | | | | | sv_force_normal is passed the SV_COW_DROP_PV flag if the scalar is about to be written over. That flag is not currently used. We can speed up assignment over fake GVs a lot by taking advantage of the flag. Before and after: $ time ./perl -e '$x = *foo, undef $x for 1..2000000' real 0m4.264s user 0m4.248s sys 0m0.007s $ time ./perl -e '$x = *foo, undef $x for 1..2000000' real 0m1.820s user 0m1.812s sys 0m0.005s
* sysread should not ignore magic on its bufferFather Chrysostomos2011-11-241-1/+2
| | | | | | sysread uses SvPV_force, which has a bug in it. Even if the SV_GMAGIC flag is passed to sv_pvn_force_flags (which SvPV_force does), it ignores magic in any typeglob argument.
* printf "%vd", "version" should not SEGVFather Chrysostomos2011-11-231-1/+1
| | | | See perl #102586.
* sv.c/sv_insert_flags: typoFather Chrysostomos2011-11-221-1/+2
|
* amagic_deref_call does not necessitate SPAGAINFather Chrysostomos2011-11-221-2/+0
| | | | | As amagic_deref_call pushes a new stack, PL_stack_sp will always have the same value before and after, so SPAGAIN is unnecessary.
* [perl #103766] Wrong $" warning in perl 5.14Father Chrysostomos2011-11-221-7/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This code: "@{[ $x ]}" was producing the warning: Use of uninitialized value $" in join or string at -e line 1. erroneously, as of commit 6d1f0892c. Commit 6d1f0892c was meant to fix bug #72090, which caused the varia- ble to be mentioned even for the > warning in this instance: $ ./perl -we '$a = @$a > 0' Use of uninitialized value $a in array dereference at -e line 1. Use of uninitialized value $a in numeric gt (>) at -e line 1. The fix for #72090 was wrong, because the loop that it modified loops through the kid ops, finding out how many candidates there are. If there is only one candidate left, it is used. Skipping ops that could be responsible for the undefined value just because we don’t want to mention their variables is the wrong approach, at least in that loop, as the blame will fall on whatever other op is left if there is only one. There is code further up to deal with the OP_RV2[AH]V case, that des- cends explicitly into the child ops. This commit tweaks that code to descend only for the top-level op, to allow @{ $x } to warn still about an uninitialised value used in array dereference. Where @{...} is an operand to the operator that is emitting the warning, we don’t descend. That is how #72090 should have been fixed to begin with, as it has no odd side effects. This bug (#103766) affects any other cases where there are two oper- ands and one is @{...} or %{...}: $ perl5.15.4 -e 'use warnings "uninitialized"; $y = 6; $y + @{ $x }' Use of uninitialized value $x in array dereference at -e line 1. Use of uninitialized value $y in addition (+) at -e line 1. $y is obviously not responsible there.
* sv.c: newSVpvf( → Perl_newSVpvf(aTHX_Father Chrysostomos2011-11-211-1/+1
| | | | | I don’t know why this is necessary, but there are some strange #defines surrounding this function.
* Put sub redef warnings in one placeFather Chrysostomos2011-11-211-38/+16
| | | | | | | | | | The logic surrounding subroutine redefinition warnings (to warn or not to warn?) was in three places. Over time, they drifted apart, to the point that newXS was following completely different rules. It was only warning for redefinition of functions in the autouse namespace. Recent commits have brought it into conformity with the other redefi- nition warnings. Obviously it’s about time we put it in one function.
* Make constant sub redef warnings obey scopeFather Chrysostomos2011-11-211-0/+1
| | | | | | | | | | | In perldiag, this is listed as (S), which means that outside of any use/no warnings scope it always warns, regardless of $^W. But this warning was ignoring use/no warnings, too. There were actually tests for this oddity, but I think those were added by mistake, or this was just not thought through. I cannot see how this is not a bug.
* Don’t call an early-returning destructorFather Chrysostomos2011-11-211-2/+10
| | | | | | | | | | | | | | | | This speeds things up 2.8 times in my naïve benchmarks. This applies to code like: use constant DEBUG => 1; DESTROY { return unless DEBUG; ... } which gets optimised down to: DESTROY { return; ... } Adding such a destructor will now have almost no impact on speed in production.
* Restore autouse’s exemption from redef warningsFather Chrysostomos2011-11-211-1/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This also restores the subroutine redefinition warning for newly-cre- ated XSUBs outside the autouse package. See below. This commit added the exemption to fix a known bug, that loading a module and importing from it would cause a redefinition warning if there were an autouse stub: perl-5.004_03-1092-g2f34f9d commit 2f34f9d4825ac9262ece854fc4c50479f4838ff8 Author: Ilya Zakharevich <ilya@math.berkeley.edu> Date: Mon Mar 2 16:36:02 1998 -0500 Make autouse -w-safe p4raw-id: //depot/perl@781 The subroutine redefinition warning occurs in three places. This commit removed the autouse exemption from two of them. I can’t see how it wasn’t a mistake, as <5104D4DBC598D211B5FE0000F8FE7EB202D49EE9@mbtlipnt02.btlabs.bt.co.uk> (the apparent source of the patch, makes no mention of it: perl-5.005_02-2920-ge476b1b commit e476b1b5c29f354cf8dad61a9fc6d855bdfb5b7d Author: Gurusamy Sarathy <gsar@cpan.org> Date: Sun Feb 20 22:58:09 2000 +0000 lexical warnings update, ability to inspect bitmask in calling scope, among other things (from Paul Marquess) p4raw-id: //depot/perl@5170 This commit refactored things to remove some compiler warnings, but in doing so reversed the logic of the condition, causing redefini- tion warnings for newly-created XSUBs to apply only to subs from the autouse package: perl-5.8.0-5131-g66a1b24 commit 66a1b24beb76ea873ad4caa57ee3ab9df945afbf Author: Andy Lester <andy@petdance.com> Date: Mon Jun 6 05:11:07 2005 -0500 Random cleanups #47 Message-ID: <20050606151107.GC7022@petdance.com> p4raw-id: //depot/perl@24735 I’ve basically reinstated the changes in 2f34f9d4, but with tests this time. It may not make sense for autouse to be exempt for newATTRSUB and newXS, but keeping the logic surrounding the warning as close as possible to being the same could allow future refactorings to merge them.
* sv.c: I missed a dotFather Chrysostomos2011-11-211-1/+1
|
* sort does not call get-magic after dereffingFather Chrysostomos2011-11-191-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | sort $f @list accepts a globref for $f, and probably has since Perl 5.000, even if it was by mistake that it ever worked. It doesn’t respect get-magic, however: $ perl -le 'sub s { $b <=> $a }; $f = \*s; print sort $f 1,2,3' 321 $ ./perl -Ilib -le ' sub TIESCALAR{bless[]} sub FETCH {*s} sub s { $b <=> $a }; tie $f, ""; $g = \$f; print sort $g 1,2,3' Not a subroutine reference at -e line 1. Interestingly, this commit added support for sort $coderef @foo: commit 7a4920e67d1e2d67a4397a908141c6608866ebb0 Author: Graham Barr <gbarr@pobox.com> Date: Fri Nov 27 05:16:50 1998 +0000 integrate change#2246 from mainline, while still allowing C<sort $globref @foo> allow C<sort $coderef @foo> p4raw-link: @2246 on //depot/perl: c6e96bcb406bc8b8d8610606459ff606ad6883aa p4raw-id: //depot/maint-5.005/perl@2315 p4raw-integrated: from //depot/perl@2314 'merge in' t/op/sort.t (@1760..) If I’m reading this code correctly, it did so by nulling out whatever op used to come after the pushmark (now it is always a null): $ perl -MO=Concise -e 'sort $fo @fo'8 <@> leave[1 ref] vKP/REFC ->(end) 1 <0> enter ->2 2 <;> nextstate(main 1 -e:1) v:{ ->3 7 <@> sort vKS ->8 3 <0> pushmark s ->4 - <1> null K/1 ->5 <--- Lo! - <1> ex-rv2sv sK/1 ->- 4 <#> gvsv[*fo] s ->5 6 <1> rv2av[t3] lK/1 ->7 5 <#> gv[*fo] s ->6 -e syntax OK To preserve the globref support (which the nulled op was providing before), it added it to sv_2cv, which was the wrong place if you ask me. Now it means that &{\*_} works, in addition to &{*_}. Other deref ops don’t have this property. Bug? Maybe. But we can just pretend it’s a feature and live with it. In any case, extracting the entry of a typeglob without calling get- magic on it first doesn’t seem right.
* Document sv_2io’s invocation of magicFather Chrysostomos2011-11-191-0/+3
|
* Call FETCH once on handle passed as 3rd arg to open()Father Chrysostomos2011-11-191-4/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | When open() has three arguments and the second ends with & the third argument is treated as a handle. In some cases get-magic was being skipped; in others, it was being called three times. This commit fixes it by modifying sv_2io. In 5.8.x (before commit 7a5fd60d4), sv_2io did not call get-magic at all except when croaking ("Bad filehandle: %"SVf). In 5.10.0 (after commit 7a5fd60d4), it started calling get-magic only if the sv was neither a glob, a reference, or undef. So it has never been reliable in its invocation of get-magic. sv_2io now consistently skips get-magic on the sv passed in directly to it (open(), the only caller in the core, has already called get- magic before passing it in). It now calls get-magic on SvRV(sv) if what is passed in is a reference, so open(fh, ">&", \$tied) will work. Interestingly, open supports multiple levels of references: \\\\\\\\\\\\open+f,">&",\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ \\\\\\\\\\\*STDOUT;print{f}"Just another Perl hacker,\n",.\\\\\\\y\\\
* sv.c: More consistent use of spaces after dotsFather Chrysostomos2011-11-191-72/+78
| | | | in apidocs, plus other tweaks
* Correct sv_catsv_flags docsFather Chrysostomos2011-11-191-1/+3
| | | | Get-magic is only called on ssv. SV_SMAGIC is accepted, too.
* Correct sv_catpv_flags docsFather Chrysostomos2011-11-191-2/+2
| | | | SV_SMAGIC, not SV_GMAGIC.
* Correct sv_catpvn_flags docsFather Chrysostomos2011-11-191-2/+3
| | | | It respects SV_SMAGIC flag, not SV_GMAGIC (which it ignores).
* Mention implicit $_ in y///r uninit warningFather Chrysostomos2011-11-191-0/+1
| | | | This brings it into conformity with y without the /r.
* Mention the variable name in the new length warningsFather Chrysostomos2011-11-181-2/+2
|
* Tweaks to find_uninit_var docsFather Chrysostomos2011-11-181-3/+3
| | | | | | • Typos • Double space after fullstop, as that is how nroff renders a fullstop at the end of a line in mid-paragraph.
* Unused variable in in sv_eqBrian Fraser2011-11-171-3/+0
|