summaryrefslogtreecommitdiff
path: root/pad.h
Commit message (Collapse)AuthorAgeFilesLines
* Used pad name lists for pad idsFather Chrysostomos2012-10-161-2/+1
| | | | | | | | | | | | | | | | | I added pad IDs so that a pad could record which pad it closes over, to avoid problems with closures closing over the wrong pad, resulting in crashes or bizarre copies. These pad IDs were shared between clones of the same pad. In commit 9ef8d56, for efficiency I made clones of the same closure share the same pad name list. It has just occurred to be that each padlist containing the same pad name list also has the same pad ID, so we can just use the pad name list itself as the ID. This makes padlists 32 bits smaller and eliminates PL_pad_generation from the interpreter struct.
* Revert "Set PL_comppad_name on sub entry"Father Chrysostomos2012-09-171-2/+1
| | | | This reverts commit d2c8bf052f5a8bb99050f6d2418d77151eb4b468.
* Set PL_comppad_name on sub entryFather Chrysostomos2012-09-151-1/+2
|
* pad.h: Rename PadnameSTATE; make it a proper booleanFather Chrysostomos2012-08-241-2/+2
| | | | | | I used PadnameIs* for OUR, because I was copying PAD_COMPNAME_FLAGS_isOUR. STATE should be consistent with it. And it was missing the double bang, making the docs wrong.
* pad.h: PadnameSTATEFather Chrysostomos2012-08-231-0/+4
|
* Use FooBAR convention for new pad macrosFather Chrysostomos2012-08-221-40/+40
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | After a while, I realised that it can be confusing for PAD_ARRAY and PAD_MAX to take a pad argument, but for PAD_SV to take a number and PAD_SET_CUR a padlist. I was copying the HEK_KEY convention, which was probably a bad idea. This is what we use elsewhere: TypeMACRO ----===== AvMAX CopFILE PmopSTASH StashHANDLER OpslabREFCNT_dec Furthermore, heks are not part of the API, so what convention they use is not so important. So these: PADNAMELIST_* PADLIST_* PADNAME_* PAD_* are now: Padnamelist* Padlist* Padname* Pad*
* pad.h: Let PADNAME_PV return nullFather Chrysostomos2012-08-221-2/+3
|
* pad.h: typos in macro definitionsFather Chrysostomos2012-08-221-2/+2
| | | | It would help to define these macros properly.
* pad.h: PADNAME_SVFather Chrysostomos2012-08-221-0/+5
| | | | | | | | If CPAN modules should not assume that pad names are SVs, we need to provide a better way than newSVpvn(PADNAME_PV(pn),PADNAME_LEN(pn)) to get an SV out of it, as, knowing that pad names are just SVs, the core can do it more efficiently by simply returning the pad name itself.
* pad.[ch]: PADNAME_OUTERFather Chrysostomos2012-08-221-0/+4
| | | | | I think this is the last bit of pad-as-sv stuff that was not abstracted away in pad-specific macros.
* More PAD APIsFather Chrysostomos2012-08-211-0/+66
| | | | | | | | | | | | | | | | If we are making padlists their own type, and no longer AVs, it makes sense to add APIs for pads, too, so that CPAN code that needs to change now will only have to change once if we ever stop pads them- selves from being AVs. There is no reason pad names have to be SVs, so I am adding sep- arate APIs for pad names, too. The AV containing pad names is now officially a PADNAMELIST, which is accessed, not via *PADLIST_ARRAY(padlist), but via PADLIST_NAMES(padlist). Future optimisations may even merge the padlist with its name list so I have also added macros to access the parts of the name list directly from the padlist.
* Fix format closure bug with redefined outer subFather Chrysostomos2012-08-211-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | CVs close over their outer CVs. So, when you write: my $x = 52; sub foo { sub bar { sub baz { $x } } } baz’s CvOUTSIDE pointer points to bar, bar’s CvOUTSIDE points to foo, and foo’s to the main cv. When the inner reference to $x is looked up, the CvOUTSIDE chain is followed, and each sub’s pad is looked at to see if it has an $x. (This happens at compile time.) It can happen that bar is undefined and then redefined: undef &bar; eval 'sub bar { my $x = 34 }'; After this, baz will still refer to the main cv’s $x (52), but, if baz had ‘eval '$x'’ instead of just $x, it would see the new bar’s $x. (It’s not really a new bar, as its refaddr is the same, but it has a new body.) This particular case is harmless, and is obscure enough that we could define it any way we want, and it could still be considered correct. The real problem happens when CVs are cloned. When a CV is cloned, its name pad already contains the offsets into the parent pad where the values are to be found. If the outer CV has been undefined and redefined, those pad offsets can be com- pletely bogus. Normally, a CV cannot be cloned except when its outer CV is running. And the outer CV cannot have been undefined without also throwing away the op that would have cloned the prototype. But formats can be cloned when the outer CV is not running. So it is possible for cloned formats to close over bogus entries in a new parent pad. In this example, \$x gives us an array ref. It shows ARRAY(0xbaff1ed) instead of SCALAR(0xdeafbee): sub foo { my $x; format = @ ($x,warn \$x)[0] . } undef &foo; eval 'sub foo { my @x; write }'; foo __END__ And if the offset that the format’s pad closes over is beyond the end of the parent’s new pad, we can even get a crash, as in this case: eval 'sub foo {' . '{my ($a,$b,$c,$d,$e,$f,$g,$h,$i,$j,$k,$l,$m,$n,$o,$p,$q,$r,$s,$t,$u)}'x999 . q| my $x; format = @ ($x,warn \$x)[0] . } |; undef &foo; eval 'sub foo { my @x; my $x = 34; write }'; foo(); __END__ So now, instead of using CvROOT to identify clones of CvOUTSIDE(format), we use the padlist ID instead. Padlists don’t actually have an ID, so we give them one. Any time a sub is cloned, the new padlist gets the same ID as the old. The format needs to remember what its outer sub’s padlist ID was, so we put that in the padlist struct, too.
* Stop padlists from being AVsFather Chrysostomos2012-08-211-3/+15
| | | | | | | | | | | | | | | | | | | | | 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.
* Move PAD(LIST) typedefs to perl.hFather Chrysostomos2012-08-211-7/+0
| | | | otherwise they can only be used in some header files.
* [perl #114018] Let eval close over stale vars in active subFather Chrysostomos2012-08-081-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | See also commit cae5dbbe30. These two lines should never produce different values: print $x, "\n"; print eval '$x', "\n"; But they were producing different values if $x happened to have the tale flag set. Even if my in false conditional is not supported (this was the cause of the bug report), it should still work; and it is not the only way to get a stale lexical in an active sub (just the easiest way). As long as the sub containing the eval is active, the eval should be able to see the same variables, stale or not. However, this does get a bit tricky in cases like this, which legiti- mately warn (from t/lib/warnings/pad): { my $x = 1; $y = \$x; # force abandonment rather than clear-in-place at scope exit sub f2 { eval '$x' } } f2(); In this case the f2 sub does not explicitly close over the $x, so by the time the eval is reached the ‘right’ $x is gone. It is only in those cases where the sub containing the eval has the stale variable in its own pad that we can safely ignore the stale flag.
* 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.
* [perl #109718] Clone PL_comppad properlyFather Chrysostomos2012-04-101-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | fork emulation on Windows, which clones a new thread via perl_clone_using, expects to be able to access the current pad imme- diately after the cloning, and crashes if there is no current pad. PL_comppad was not being cloned explicitly, but simply looked up in the pointer table, it being assumed that it had already been cloned. For string evals, before commit 676a678, PL_compcv happened to point to the eval’s CV. PL_compcv is cloned just before PL_comppad is set, so that worked. As of commit 676a678, PL_compcv does not point to the eval’s CV at the eval’s run time, so the pad has not been cloned yet when PL_comppad is set. In the case of string evals, the CV does get cloned, but later on, after PL_comppad is set, when the stacks are cloned. Changing the setting of PL_comppad to do an actual cloning works, as, when the eval’s CV is cloned later (during stack cloning), it will simply pick up the pad that has already been cloned and is waiting for it in the pointer table. This stops eval 'fork' from crashing on Windows.
* Bump several file copyright datesSteffen Schwigon2012-01-191-1/+2
| | | | | | | Sync copyright dates with actual changes according to git history. [Plus run regen_perly.h to update the SHA-256 checksums, and regen/regcharclass.pl to update regcharclass.h]
* Defenestrate PAD_DUPFather Chrysostomos2011-09-011-15/+0
| | | | It has been unused in core since d5b1589c and is not used on CPAN.
* pad.h: Added a padadd_UTF8_NAME flag for pad_add_name_pvn.Brian Fraser2011-07-121-4/+5
|
* APIify pad functionsZefram2011-07-121-9/+31
| | | | | | | Move several pad functions into the core API. Document the pad functions more consistently for perlapi. Fix the interface issues around delimitation of lexical variable names, providing _pvn, _pvs, _pv, and _sv forms of pad_add_name and pad_findmy.
* Test that SvFLAGS() & SVpad_NAME is SVpad_NAME, not just non-zero.Nicholas Clark2011-06-111-2/+1
| | | | | In Perl_find_rundefsv() and PAD_COMPNAME_FLAGS_isOUR(), replace longhand flags test with SvPAD_OUR().
* rename PAD_MAX to PERL_PADSEQ_INTRODavid Mitchell2011-02-061-0/+6
| | | | | | | | and increase its scope to all the perl core rather than just pad.c. The scope needs to increase because we'll need to use it in op.c shortly, and the rename is because it's about to lose any significance as a numerical value, and just become a magic number to be tested for equality.
* Store the PL_compcv instead of the the PL_comppad in parser stack, and make ↵Gerard Goossen2009-12-161-1/+2
| | | | it reference counted. Properly solves [perl #66094]
* Make the style of pad_add_name's flags consistent with pad_new's and pad_tidy's.Nicholas Clark2009-11-151-3/+3
|
* Convert pad_check_dup() to static linkage, and call it from Perl_pad_add_name().Nicholas Clark2009-11-151-2/+2
| | | | | Provide a flag option to Perl_pad_add_name(), pad_add_NO_DUP_CHECK, to supress the call.
* Refactor common code paths from Perl_pad_add_name() into S_pad_add_name_sv().Nicholas Clark2009-11-151-1/+0
| | | | | | The only user of the pad_add_FAKE flag was S_pad_findlex(), so move the relevant code there from Perl_pad_add_name(), and have S_pad_findlex() call S_pad_add_name_sv() directly. This eliminates the pad_add_FAKE flag completely.
* Add length and flags arguments to Perl_pad_check_dup().Nicholas Clark2009-11-091-0/+11
| | | | | | Currently only pad_add_OUR is used. The length is cross-checked against strlen() on the pointer, but the intent is to re-work the entire pad API to be UTF-8 aware, from the current situation of char * pointers only.
* Use of freed comppad array during clear_yystack()Marcus Holland-Moritz2009-04-081-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Message-ID: <20081026231720.34258457@r2d2> Patch description from the original email : I tried to make tests pass on a perl built with -DPERL_POISON, as some tests were dying with segfaults. They all originated from the same source: clear_yystack() after a compile error. [...] As far as I can see, after croaking the newly created CV is destroyed and its pad is undef'd. [...] This will SvREFCNT_dec PL_comppad and set PL_comppad to NULL. However, later, in clear_yystack(), when the ops are freed, the old PL_comppad is restored by PAD_RESTORE_LOCAL, as a reference is still in ps->comppad. But now the pad AV is already dead. Normally (i.e. without PERL_POISON), the dead AV will have AvARRAY(av) set to NULL by av_undef(). So PAD_RESTORE_LOCAL will actually set PL_curpad to NULL, and thus pad_free() will not attempt to do anything. But with PERL_POISON, the storage for AvARRAY(av) (i.e. sv_u) will be reused for chaining the free SV heads in the arena (as opposed to SvANY(sv) in case of !PERL_POISON). This means that PAD_RESTORE_LOCAL will find AvARRAY(av) non-NULL and will set PL_curpad to that value, finally causing the segfault in pad_free(). While I think I understand what's going on, I don't have the slightest clue how to properly fix this. Given that it's not a problem only under PERL_POISON, but always (as dead SV heads are being used), I think it should ultimately be fixed. The only thing I can offer right now is a patch to make it work with PERL_POISON as good (or as bad) as without by making PAD_RESTORE_LOCAL explicitly check if the pad passed in is already dead and refusing to use it if it is.
* Add MUTABLE_AV(), and remove (AV *) casts from headers.Nicholas Clark2008-10-271-3/+3
| | | p4raw-id: //depot/perl@34608
* Add a macro MUTABLE_PTR(p), which on (non-pedantic) gcc will not castNicholas Clark2008-10-271-8/+8
| | | | | | | | | | away const, returning a void *. Add MUTABLE_SV(sv) which uses this, and replace all (SV *) casts either with MUTABLE_SV(sv), or (const SV *). This probably still needs some work - assigning to SvPVX() and SvRV() is now likely to generate a casting error. The core doesn't do this. But as-is it's finding bugs that can be fixed. p4raw-id: //depot/perl@34605
* Update copyright years.Nicholas Clark2008-10-251-1/+1
| | | p4raw-id: //depot/perl@34585
* Re: [PATCH] readable assertion names, now the restReini Urban2008-06-081-35/+39
| | | | | | From: "Reini Urban" <rurban@x-ray.at> Message-ID: <6910a60806080717h1aaaef1fh425a2ef21a62c9ed@mail.gmail.com> p4raw-id: //depot/perl@34030
* A couple of POD fixes by Steven SchubigerRafael Garcia-Suarez2008-01-161-2/+1
| | | p4raw-id: //depot/perl@32982
* Add editor blocks to some header files.Marcus Holland-Moritz2008-01-011-0/+10
| | | p4raw-id: //depot/perl@32793
* Update copyright years in .h files. Also, in .plRafael Garcia-Suarez2007-01-051-1/+1
| | | | | | files that generate .h files, so they'll be ready next time. p4raw-id: //depot/perl@29695
* Rename OURSTASH to SvOURSTASH and OURSTASH_set to SvOURSTASH_set.Nicholas Clark2007-01-031-1/+1
| | | p4raw-id: //depot/perl@29679
* With PAD_COMPNAME_GEN in SvUVX, SvCUR is trustworthy once more.Nicholas Clark2006-12-281-3/+4
| | | p4raw-id: //depot/perl@29633
* Move PAD_COMPNAME_GEN from SvCUR to SvUVX.Nicholas Clark2006-12-281-4/+4
| | | p4raw-id: //depot/perl@29632
* Move PAD_FAKELEX_ANON and PAD_FAKELEX_MULTI to pad.h, export them viaNicholas Clark2006-12-281-0/+5
| | | | | B.pm, so that B::Concise doesn't need to hard code magic numbers. p4raw-id: //depot/perl@29631
* Move the low/high cop sequences from NVX/IVX to a two U32 structureNicholas Clark2006-12-281-4/+53
| | | | | | in the xnv union. This frees up IVX for the PL_generation code, which in turn will allow SvCUR to return to its real purpose. p4raw-id: //depot/perl@29630
* Abstract the pad code's overloaded use of SvNVX and SvIVX intoNicholas Clark2006-12-281-1/+9
| | | | | | 4 macros COP_SEQ_RANGE_LOW, COP_SEQ_RANGE_HIGH, PARENT_PAD_INDEX and PARENT_FAKELEX_FLAGS p4raw-id: //depot/perl@29629
* es: quiet some warnings (with a free AIX cpp insanity avoidance tip)Jarkko Hietaniemi2006-04-101-5/+5
| | | | | | Message-ID: <44375F23.6030900@gmail.com> Date: Sat, 08 Apr 2006 09:58:43 +0300 p4raw-id: //depot/perl@27754
* Add MAD changes to pad code (new function Perl_pad_peg)Nicholas Clark2006-03-081-0/+6
| | | p4raw-id: //depot/perl@27419
* Replace usage of GvSTASH for storing the stash of C<our> withNicholas Clark2006-02-241-1/+1
| | | | | OURSTASH. Set the stash with OURSTASH_SET. p4raw-id: //depot/perl@27306
* As SVs can't both be in a pad, and the name of a variable in the pad,Nicholas Clark2006-02-241-1/+2
| | | | | overlay SVs_PADTMP with SVpad_TYPED and SVs_PADMY with SVpad_OUR. p4raw-id: //depot/perl@27297
* Replace direct flags tests & manipulations for SVpad_TYPED andNicholas Clark2006-02-231-0/+1
| | | | | | SVpad_OUR with macros SvPAD_TYPED(), SvPAD_OUR() etc, to abstract away the flags bits acutally used to store this information. p4raw-id: //depot/perl@27294
* More NullXXX macro removal from Andy LesterRafael Garcia-Suarez2006-02-201-4/+4
| | | p4raw-id: //depot/perl@27238
* Re: [PATCH] s/Null(gv|hv|sv)/NULL/gSteven Schubiger2006-02-031-1/+1
| | | | | | Message-ID: <20060203152449.GI12591@accognoscere.homeunix.org> Date: Fri, 3 Feb 2006 16:24:49 +0100 p4raw-id: //depot/perl@27065
* Update copyright with the 2 years where changes were made.Nicholas Clark2006-01-081-1/+1
| | | p4raw-id: //depot/perl@26737