summaryrefslogtreecommitdiff
path: root/av.c
Commit message (Collapse)AuthorAgeFilesLines
* Don’t crash with $tied[-1] when array is tied to non-objFather Chrysostomos2012-10-281-58/+29
| | | | | The code for checking to see whether $NEGATIVE_INDICES is defined in the tie package was very fragile, and was repeated four times.
* Don’t skip tied EXISTS for negative array indicesFather Chrysostomos2012-10-281-2/+0
| | | | | | | | | | | | | | | | | | | | | | | | This was broken in 5.14.0 for those cases where $NEGATIVE_INDICES is not true: sub TIEARRAY{bless[]}; sub FETCHSIZE { 50 } sub EXISTS { print "does $_[1] exist?\n" } tie @a, ""; exists $a[1]; exists $a[-1]; $NEGATIVE_INDICES=1; exists $a[-1]; $ pbpaste|perl5.12.0 does 1 exist? does 49 exist? does -1 exist? $ pbpaste|perl5.14.0 does 1 exist? does -1 exist? This was broken by 54a4274e3c.
* [perl #115440] Fix various leaks with fatal FETCHFather Chrysostomos2012-10-251-2/+9
| | | | | | | | | | | | | Various pieces of code were creating an SV and then assigning to it from a value that might be magical. If the source scalar is magical, it could die when magic is called, leaking the scalar that would have been assigned to. So we call get-magic before creating the new scalar, and then use a non-magical assignment. Also, anonhash and anonlist were doing nothing to protect the aggre- gate if an argument should die on FETCH, resulting in a leak.
* Stop padlists from being AVsFather Chrysostomos2012-08-211-27/+39
| | | | | | | | | | | | | | | | | | | | | In order to fix a bug, I need to add new fields to padlists. But I cannot easily do that as long as they are AVs. So I have created a new padlist struct. This not only allows me to extend the padlist struct with new members as necessary, but also saves memory, as we now have a three-pointer struct where before we had a whole SV head (3-4 pointers) + XPVAV (5 pointers). This will unfortunately break half of CPAN, but the pad API docs clearly say this: NOTE: this function is experimental and may change or be removed without notice. This would have broken B::Debug, but a patch sent upstream has already been integrated into blead with commit 9d2d23d981.
* Omnibus removal of register declarationsKarl Williamson2012-08-181-6/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This removes most register declarations in C code (and accompanying documentation) in the Perl core. Retained are those in the ext directory, Configure, and those that are associated with assembly language. See: http://stackoverflow.com/questions/314994/whats-a-good-example-of-register-variable-usage-in-c which says, in part: There is no good example of register usage when using modern compilers (read: last 10+ years) because it almost never does any good and can do some bad. When you use register, you are telling the compiler "I know how to optimize my code better than you do" which is almost never the case. One of three things can happen when you use register: The compiler ignores it, this is most likely. In this case the only harm is that you cannot take the address of the variable in the code. The compiler honors your request and as a result the code runs slower. The compiler honors your request and the code runs faster, this is the least likely scenario. Even if one compiler produces better code when you use register, there is no reason to believe another will do the same. If you have some critical code that the compiler is not optimizing well enough your best bet is probably to use assembler for that part anyway but of course do the appropriate profiling to verify the generated code is really a problem first.
* Magic flags harmonization.Chip Salzenberg2012-07-151-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | In restore_magic(), which is called after any magic processing, all of the public OK flags have been shifted into the private OK flags. Thus the lack of an appropriate public OK flags was used to trigger both get magic and required conversions. This scheme did not cover ROK, however, so all properly written code had to make sure mg_get was called the right number of times anyway. Meanwhile the private OK flags gained a second purpose of marking converted but non-authoritative values (e.g. the IV conversion of an NV), and the inadequate flag shift mechanic broke this in some cases. This patch removes the shift mechanic for magic flags, thus exposing (and fixing) some improper usage of magic SVs in which mg_get() was not called correctly. It also has the side effect of making magic get functions specifically set their SVs to undef if that is desired, as the new behavior of empty get functions is to leave the value unchanged. This is a feature, as now get magic that does not modify its value, e.g. tainting, does not have to be special cased. The changes to cpan/ here are only temporary, for development only, to keep blead working until upstream applies them (or something like them). Thanks to Rik and Father C for review input.
* update the editor hints for spaces, not tabsRicardo Signes2012-05-291-2/+2
| | | | | This updates the editor hints in our files for Emacs and vim to request that tabs be inserted as spaces.
* av_fetch: de-duplicate small bit of codeDavid Mitchell2012-02-271-11/+5
| | | | | | | | | | | | | | make the code slightly smaller by changing if (A) return X; if (B) return X; into ` if (A || B) return X;
* Document that [ah]v_undef/clear may free the [ah]vFather Chrysostomos2012-01-091-3/+8
|
* Better fix for perl #107440Father Chrysostomos2012-01-091-3/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | > > Actually, the simplest solution seem to be to put the av or hv on > > the mortals stack in pp_aassign and pp_undef, rather than in > > [ah]v_undef/clear. > > This makes me nervous. The tmps stack is typically cleared only on > statement boundaries, so we run the risks of > > * user-visible delaying of freeing elements; > * large tmps stack growth might be possible with > certain types of loop that repeatedly assign to an array without > freeing tmps (eg map? I think I fixed most map/grep tmps leakage > a > while back, but there may still be some edge cases). > > Surely an ENTER/SAVEFREESV/LEAVE inside pp_aassign is just as > efficient, > without any attendant risks? > > Also, although pp_aassign and pp_undef are now fixed, the > [ah]v_undef/clear functions aren't, and they're part of the public API > that can be called independently of pp_aassign etc. Ideally they > should > be fixed (so they don't crash in mid-loop), and their documentation > updated to point out that on return, their AV/HV arg may have been > freed. This commit takes care of the first part; it changes pp_aassign to use ENTER/SAVEFREESV/LEAVE and adds the same to h_freeentries (called both by hv_undef and hv_clear), av_undef and av_clear. It effectively reverts the C code part of 9f71cfe6ef2.
* Simplify magic logic in av.c:av_storeFather Chrysostomos2012-01-081-2/+1
|
* [perl #85670] Copy magic to ary elems properlyFather Chrysostomos2012-01-061-5/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | On Tue Mar 08 07:26:35 2011, thospel wrote: > #!/usr/bin/perl -l > use Data::Dumper; > use Scalar::Util qw(weaken); > our @ISA; > > for (1..2) { > @ISA = qw(Foo); > weaken($a = \@ISA); > weaken($a = \$ISA[0]); > print STDERR Dumper(\@ISA); > } > > This prints: > $VAR1 = [ > 'Foo' > ]; > $VAR1 = [ > 'Foo', > \$VAR1->[0] > ]; > > So the first time it's the expected @ISA, but the second time round it > automagically added a reference to to the first ISA element > > (bug also exists in blead) Shorter: #!/usr/bin/perl -l use Scalar::Util qw(weaken); weaken($a = \@ISA); @ISA = qw(Foo); use Devel::Peek; Dump \@ISA; weaken($a = \$ISA[0]); print scalar @ISA; # prints 2 The dump shows the problem. backref magic is being copied to the ele- ment. Put the magic in a different order, and everything is fine: #!/usr/bin/perl -l use Scalar::Util qw(weaken); weaken($a = $b = []); *ISA = $a; @ISA = qw(Foo); use Devel::Peek; Dump \@ISA; weaken($a = \$ISA[0]); print scalar @ISA; # prints 2 This code in av_store is so wrong: if (SvSMAGICAL(av)) { const MAGIC* const mg = SvMAGIC(av); if (val != &PL_sv_undef) { sv_magic(val, MUTABLE_SV(av), toLOWER(mg->mg_type), 0, key); } if (PL_delaymagic && mg->mg_type == PERL_MAGIC_isa) PL_delaymagic |= DM_ARRAY_ISA; else mg_set(MUTABLE_SV(av)); } It doesn’t follow the magic chain at all. So anything magic could get attached to the @ISA array, and that will be copied to the element instead of isa magic. Notice that MUTABLE_SV(av) is the second argument to sv_magic, so mg->mg_obj for the element always points back to the array. Since backref magic’s mg->mg_obj points to the backrefs array, @ISA ends up being used as this element’s backrefs array. What if arylen_p gets copied instead? Let’s see: $#ISA = -1; @ISA = qw(Foo); $ISA[0] = "Bar"; main->ber; sub Bar::ber { warn "shave" } __END__ Can't locate object method "ber" via package "main" at - line 7. I’ve fixed this by making av_store walk the magic chain, copying any magic for which toLOWER(mg->mg_type) != mg->mg_type.
* av.c: Consistent use of spaces after dots in apidocsFather Chrysostomos2011-12-271-4/+6
|
* perlapi.pod EnhancementsShlomi Fish2011-07-181-2/+14
| | | | | This is a patch to enhance perlapi.pod by providing Perl equivalents and clarifying documentation where appropriate.
* av.c: Add blank line before =cutFather Chrysostomos2011-07-151-0/+1
| | | | to fix the generated pod
* perlapi: Clarify statement about av_push()Karl Williamson2011-01-291-2/+1
| | | | | Contrary to the previous text, av_store() requires the user to deal with the reference count of the scalar being added.
* [perl #45147] Issue with the exists functionPeter Martini2011-01-021-1/+12
| | | | | | | | Perl_av_exists tested to see if regdata magic was present, but did not have any logic to fetch that data in the positive key case. Additionally, in the negative key case, if AvFILL indicated the key existed, it wouldn't return, and would then fall through to the logic that treated it like a real array.
* Document that av_delete and hv_delete make their return values mortal.Chip Salzenberg2010-10-141-5/+5
|
* Remove offer_nice_chunk(), PL_nice_chunk and PL_nice_chunk_size.Nicholas Clark2010-09-081-5/+1
| | | | | | | | | | | | | | | | | | These provided a non-public API for the hash and array code to donate free memory direct to the SV head allocation routines, instead of returning it to the malloc system with free(). I assume that on some older mallocs this could offer significant benefits. However, my benchmarking on a modern malloc couldn't detect any significant effect (positive or negative) on removing the code. Its (continued) presence, however, has downsides a: slightly more code complexity b: slightly larger interpreter structure c: in the steady state, if net creation of SVs is zero, 1 chunk of allocated but unused memory will exist (per thread) So I think it best to remove it.
* Add Perl_croak_no_modify() to implement Perl_croak("%s", PL_no_modify).Nicholas Clark2010-06-271-7/+7
| | | | | This reduces object code size, reducing CPU cache pressure on the non-exception paths.
* rename DM_ARRAY flag to DM_ARRAY_ISADavid Mitchell2010-06-041-2/+2
| | | | | This better represents its current role as specifically delaying magic on @ISA as opposed to a general array magic delay mechanism.
* Add the perl equivalent for av_make.Shlomi Fish2010-05-251-0/+2
| | | | Signed-off-by: David Golden <dagolden@cpan.org>
* Add the Perl equivalent for av_len.Shlomi Fish2010-05-251-0/+2
| | | | Signed-off-by: David Golden <dagolden@cpan.org>
* Add a missing comma in the av_fill() docs.Shlomi Fish2010-05-251-1/+1
| | | | | | Minor, but still good enough for a commit. Signed-off-by: David Golden <dagolden@cpan.org>
* Clarify the av_fetch() documentation.Shlomi Fish2010-05-251-2/+4
| | | | | | | | Thanks to LeoNerd and Zefram on #p5p on IRC for some insights and suggesting versions for the modified text. I ended up using Zefram's version. Signed-off-by: David Golden <dagolden@cpan.org>
* Add Perl equivalent for av_exists().Shlomi Fish2010-05-251-0/+2
| | | | | | This mentions that it's equivalent to exists($myarray[$key]). Signed-off-by: David Golden <dagolden@cpan.org>
* Add a Perl equivalent to av_delete().Shlomi Fish2010-05-251-1/+3
| | | | Signed-off-by: David Golden <dagolden@cpan.org>
* Add the Perl equivalent example to av_clear.Shlomi Fish2010-05-251-1/+1
| | | | Signed-off-by: David Golden <dagolden@cpan.org>
* Convert Perl_magic_methcall() to varargs.Nicholas Clark2010-04-261-8/+10
| | | | | This means removing its macro wrapper, as there's no portable way to do varargs macros.
* For Perl_magic_methcall() add G_UNDEF_FILL to fill the stack with &PL_sv_undef.Nicholas Clark2010-04-261-2/+2
| | | | | | This replaces the previous special case of using a negative argument count to signify this, allowing the argument count to become unsigned. Rename it from n to argc.
* add Perl_magic_methcallDavid Mitchell2010-04-251-76/+16
| | | | | | | | | | | | | | | Add a new function that wraps the setup needed to call a magic method like FETCH (the existing S_magic_methcall function has been renamed S_magic_methcall1). There is one functional change, done mainly to allow for a single clean wrapper function, and that is that the method calls are no longer wrapped with SAVETMPS/FREETMPS. Previously only about half of them had this, so some relied on the caller to free, some didn't. At least we're consistent now. Doing it this way is necessary because otherwise magic_methcall() can't return an SV (eg for POP) because it'll be a temp and get freed by FREETMPS before it gets returned. So you'd have to copy everything, which would slow things down.
* follow up fix for fd69380d5d5b95ef16e2521cf4251b34ee0ce151David Mitchell2010-04-211-0/+2
| | | | | | | The original fix for tied elements losing magic had a bug that was masked by a bool casting issue. Once the casting was fixed, the bug surfaced: elements of @+ lost their values when returned from a sub. By removing the TEMP flag from the regdatum PVLV, we force it to be copied when returned.
* use cBOOL for bool castsDavid Mitchell2010-04-151-1/+1
| | | | | | | | | | | | | bool b = (bool)some_int doesn't necessarily do what you think. In some builds, bool is defined as char, and that cast's behaviour is thus undefined. So this line in mg.c: const bool was_temp = (bool)SvTEMP(sv); was actually setting was_temp to false even when the SVs_TEMP flag was set. Fix this by replacing all the (bool) casts with a new cBOOL() cast macro that (hopefully) does the right thing.
* [PATCH] [perl #20321] Non-destructive Perl_av_makeBo Borgerson2009-11-021-1/+7
| | | | | | Don't let sv_setsv swipe temps in av_make, since the source array might have multiple references to the same temp scalar (e.g. from a list slice).
* Add Perl_ck_warner_d(), which combines Perl_ckwarn_d() and Perl_warner().Nicholas Clark2009-10-121-4/+4
| | | | | Replace ckWARN_d{,2,3,4}() && Perl_warner() with it, which trades reduced code size for 1 more function call if warnings are not enabled.
* Mention in apidocs that av_push takes ownership of a refcountSteffen Mueller2009-07-311-1/+2
|
* PATCH: Large omnibus patch to clean up the JRRT quotesTom Christiansen2008-11-021-2/+4
| | | | | | Message-ID: <25940.1225611819@chthon> Date: Sun, 02 Nov 2008 01:43:39 -0600 p4raw-id: //depot/perl@34698
* Explicitly specify some printf formats for constant strings.Rafael Garcia-Suarez2008-11-021-7/+7
| | | | | | This is mostly to silence gcc's warning, "format not a string literal and no format arguments". p4raw-id: //depot/perl@34694
* sizeof(const SV *) is the same as sizeof(SV *), except that it doesn'tNicholas Clark2008-10-311-4/+5
| | | | | match my regexp for non-const casts. p4raw-id: //depot/perl@34677
* Eliminate (SV *) casts from the rest of *.c, picking up one (further)Nicholas Clark2008-10-301-39/+43
| | | | | erroneous const in dump.c. p4raw-id: //depot/perl@34675
* Eliminate (AV *) casts in *.c.Nicholas Clark2008-10-291-1/+1
| | | p4raw-id: //depot/perl@34650
* Bugs revealed by replacing (SV *) casts with something that doesn'tNicholas Clark2008-10-271-1/+1
| | | | | | | cast away const - AvFILL() doesn't guarantee that it won't modify the AV * passed to it. So the prototype for Perl_av_len() needs to change, and a const needs to go in Perl_magic_setarraylen(). p4raw-id: //depot/perl@34604
* Update copyright years.Nicholas Clark2008-10-251-2/+2
| | | p4raw-id: //depot/perl@34585
* Two missing 'static's, spotted by Merijn's smoker.Nicholas Clark2008-09-201-1/+1
| | | p4raw-id: //depot/perl@34381
* [DOC PATCH] av.c - clearify that av_shift returns &PL_sv_undef if array is emptyClaes Jacobsson2008-09-071-1/+2
| | | | | Message-Id: <0726E7A8-C29F-409C-81E6-B464EE6A3DDD@surfar.nu> p4raw-id: //depot/perl@34311
* [perl #51636] segmentation fault with array tiesblino@mandriva.com2008-03-121-1/+1
| | | | | | From: blino@mandriva.com (via RT) <perlbug-followup@perl.org> Message-ID: <rt-3.6.HEAD-25460-1205315984-377.51636-75-0@perl.org> p4raw-id: //depot/perl@33495
* Assert that the av argument to all the av_*() functions is an array.Nicholas Clark2008-03-081-0/+23
| | | p4raw-id: //depot/perl@33452
* Comment on why I don't think changing Perl_safesysmalloc_size() in av.cNicholas Clark2008-02-271-0/+13
| | | | | | | analagous to the change in sv.c is a good idea. [It's not a language design issue, so sadly I can't get a talk out of it. Or is that fortunately? :-)] p4raw-id: //depot/perl@33383
* If the C library provides malloc_size(), we can use that in the sameNicholas Clark2008-02-261-3/+4
| | | | | | | places as Perl's malloced_size(), except that we need to be careful of any PERL_TRACK_MEMPOOL manipulations in force. Wrap both as Perl_safesysmalloc_size(), to give a consistent name and interface. p4raw-id: //depot/perl@33379
* assert() that every NN argument is not NULL. Otherwise we have theNicholas Clark2008-02-121-15/+25
| | | | | | | | | | | | ability to create landmines that will explode under someone in the future when they upgrade their compiler to one with better optimisation. We've already done this at least twice. (Yes, some of the assertions are after code that would already have SEGVd because it already deferences a pointer, but they are put in to make it easier to automate checking that each and every case is covered.) Add a tool, checkARGS_ASSERT.pl, to check that every case is covered. p4raw-id: //depot/perl@33291