summaryrefslogtreecommitdiff
path: root/cop.h
Commit message (Collapse)AuthorAgeFilesLines
* Stop here-docs from gutting (caller $n)[6]Father Chrysostomos2012-08-271-0/+2
| | | | | | | | | (caller $n)[6] returns the text of the eval. Actually, it would return, not the text of the eval, but the text with all the here-doc bodies missing. In this commit, I’m abusing the SvSCREAM flag to indicate that the eval text stored in the context stack is refcounted.
* Use PADLIST in more placesFather Chrysostomos2012-08-211-2/+2
| | | | | Much code relies on the fact that PADLIST is typedeffed as AV. PADLIST should be treated as a distinct type.
* assert_(...)Father Chrysostomos2012-08-051-5/+1
| | | | | | | | This new macro expands to ‘assert(...),’ (with a trailing comma) under debugging builds; the empty string otherwise. It allows for the removal of some #ifdef DEBUGGINGs, which could not be avoided otherwise.
* Don’t let active formats be freedFather Chrysostomos2012-08-051-0/+2
| | | | | | | | | | | | | | This crashes: format FOO = @< undef *FOO . $~ = FOO; write The context stack needs to hold a reference count for formats, just as it does for subs.
* Recursive formats and closures in formats.Father Chrysostomos2012-08-051-0/+2
| | | | | | | | | | | | | | Formats called recursively were using the same set of lexicals, so the inner call would stomp on the outer calls vars, usually clearing them when exiting. Previous commits prepared a CvDEPTH field for formats. This commit sets it in P(USH|OP)FORMAT and pushes a new pad in enterwrite. This also allows closures to work properly in formats. Formerly they caused assertion failures in cv_clone. Now cv_clone’s assumptions about CvDEPTH on CvOUTSIDE and find_runcv are met when subs are embed- ded in formats.
* make calling of /(?{}) code blocks correctDavid Mitchell2012-06-131-3/+36
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Formerly, it just updated PL_comppad, set PL_op to the first op of the code block, and did CALLRUNOPS(). This had a lot of problems, e.g. depth of recursion, and not having anything on the context stack for die/caller/next/goto etc to see, usually leading to segfaults. Make it so that it uses the MULTICALL API instead. This makes it push a new stack and a CxSUB context stack frame; it also makes us share code rather than rolling our own. MULTICALL had to be extended in two ways to make this work; but these have not yet been made part of the public API. First, it had to allow changing of the current CV while leaving the current CxSUB frame in place, and secondly it had to allow pushing a CV with a zero increment of CvDEPTH. This latter is to handle direct literal blocks: /(?{...})/ which are compiled into the same CV as the surrounding scope; therefore we need to push the same sub twice at the same depth (usually 1), i.e. $ ./perl -Dstv -e'sub f { /(?{$x})/ } f' ... (29912:-e:1) gvsv(main::x) STACK 0: MAIN CX 0: BLOCK => CX 1: SUB => <=== the same sub ... retop=leave STACK 1: SORT CX 0: SUB => UNDEF <==== ... as this retop=(null) (note that stack 1 is misidentified as SORT; this is a bug in MULTICALl to be fixed later). One has to be very careful with the save stack; /(?{})/ is designed not to introduce a new scope, so that the effects of 'local' etc accumulate across multiple block invocations (but get popped on backtracking). This is why we couldn't just do a POP_MULTICALL/PUSH_MULTICALL pair to change the current CV; the former would pop the save stack too. Note that in the current implementation, after calling out to the first code block, we leave the CxSUB and PL_comppad value in place, on the assumption that it may be soon re-used, and only pop the CxSUB at the end of S_regmatch(). However, when popping the savestack on backtracking, this will restore PL_comppad to its original value; so when calling a new code block with the same CV, we can't rely on PL_comppad still being correct. Also, this means that outside of a code block call, the context stack and PL_comppad are wrong; I can't think of anything within the regex code that could be using these; but it if it turns out not to be the case, then we'd have to change it so that after each code block call, we pop the CxSUB off the stack and restore PL_comppad, but without popping the save stack.
* cop.h: Clarify commentFather Chrysostomos2012-06-071-1/+2
|
* Obliterate CopSTASH_freeFather Chrysostomos2012-06-041-1/+0
| | | | It is unused outside the core, defined as a no-op, and undocumented.
* [perl #78742] Store CopSTASH in a pad under threadsFather Chrysostomos2012-06-041-38/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Before this commit, a pointer to the cop’s stash was stored in cop->cop_stash under non-threaded perls, and the name and name length were stored in cop->cop_stashpv and cop->cop_stashlen under ithreads. Consequently, eval "__PACKAGE__" would end up returning the wrong package name under threads if the current package had been assigned over. This commit changes the way cops store their stash under threads. Now it is an offset (cop->cop_stashoff) into the new PL_stashpad array (just a mallocked block), which holds pointers to all stashes that have code compiled in them. I didn’t use the lexical pads, because CopSTASH(cop) won’t work unless PL_curpad is holding the right pad. And things start to get very hairy in pp_caller, since the correct pad isn’t anywhere easily accessible on the context stack (oldcomppad actually referring to the current comppad). The approach I’ve followed uses far less code, too. In addition to fixing the bug, this also saves memory. Instead of allocating a separate PV for every single statement (to hold the stash name), now all lines of code in a package can share the same stashpad slot. So, on a 32-bit OS X, that’s 16 bytes less memory per COP for short package names. Since stashoff is the same size as stashpv, there is no difference there. Each package now needs just 4 bytes in the stashpad for storing a pointer. For speed’s sake PL_stashpadix stores the index of the last-used stashpad offset. So only when switching packages is there a linear search through the stashpad.
* 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 #112316] Make strict vars respect assignment from null pkgFather Chrysostomos2012-04-191-14/+21
| | | | | | Under threads, strict vars was not respecting glob assignment from a package with a null in its name if the name of the package assigned to was equal to the prefix of the current package up to the null.
* Label UTF8 cleanupBrian Fraser2012-03-251-0/+4
| | | | | This meant changing LABEL's definition in perly.y, so most of this commit is actually from the regened files.
* Provide as much diagnostic information as possible in "panic: ..." messages.Nicholas Clark2012-01-161-1/+1
| | | | | | | | | | | | | | | The convention is that when the interpreter dies with an internal error, the message starts "panic: ". Historically, many panic messages had been terse fixed strings, which means that the out-of-range values that triggered the panic are lost. Now we try to report these values, as such panics may not be repeatable, and the original error message may be the only diagnostic we get when we try to find the cause. We can't report diagnostics when the panic message is generated by something other than croak(), as we don't have *printf-style format strings. Don't attempt to report values in panics related to *printf buffer overflows, as attempting to format the values to strings may repeat or compound the original error.
* Groundwork to allow cops and pmops to store the UTF8 flagBrian Fraser2011-10-061-3/+15
| | | | | | | | | With threaded builds, cop.h and op.h get an extra member in their structs, to save the UTF-8ness of the stash's name. *STASH_set() checks for the flag, stores it through *STASH_flags(), and *STASH() uses the latter to fetch the correct scalar.
* remove index offsetting ($[)Zefram2011-09-091-24/+0
| | | | | | $[ remains as a variable. It no longer has compile-time magic. At runtime, it always reads as zero, accepts a write of zero, but dies on writing any other value.
* Use OPpDEREF for lvalue sub, such that the flags contains the deref type, ↵Gerard Goossen2011-09-011-1/+1
| | | | | | | instead of deriving it from the opchain. Also contains a test where using the opchain to determine the deref type fails.
* Rename store/fetch_cop_label as cop_*Father Chrysostomos2011-07-161-1/+1
| | | | | | | | This makes them consistent with other functions that put the basic datum type first (like hv_*, sv_*, cophh_*). Since fetch_cop_label is marked as experimental (M), this change should be OK.
* Change was_lvalue_sub back to X; spell out the only use of itFather Chrysostomos2011-07-141-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | OK, now I understand what’s happening. If there is a public macro (PUSHSUB) that contains a call to a pri- vate function (was_lvalue_sub), that function has to be exported, so that non-core code can call it. But if it is marked X, there is no was_lvalue_sub shorthand macro visible to non-core code, so when the PUSHSUB macro is expanded in such code, the was_lvalue_sub(...) bit becomes a call to the function literally named was_lvalue_sub, as opposed to Perl_lvalue_sub (and is compiled that way on forgiving platforms). Making it A makes that macro available to non-core code, but also implies that it is available for direct use by extensions, which is not the case with was_lvalue_sub. So, this commit makes it X again, but spells it out in PUSHSUB, so there is no need for the function’s macro to be available when PUSHSUB is expanded. Hence, there is no need for the was_lvalue_sub macro to exist, so this commit also removes it. See also these three commits: c73b0699db 7b70e81778 777d901444
* Propagate (non-)lvalue context through nested callsFather Chrysostomos2011-07-091-1/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Before this commit, this code would fail: $foo = "foo"; sub foo :lvalue{ return index "foo","o" } sub bar :lvalue { foo } $x = bar; (It would fail for ‘return $]’ as well. Whether it’s a PADTMP or a read-only scalar makes no difference.) foo would think it was being called in true lvalue context, because the entersub op that called it (in bar) was marked that way, bar being an lvalue sub as well. The PUSHSUB macro in cop.h needed to be modified to account for dynamic, or indetermine, context (i.e., indeterminable at compile time). This happens when an entersub op is an argument to return or the last statement in a subroutine. In those cases it has to propa- gate the context from the caller. So what we now do is this: Both lvalue and in-args flags are turned on for an entersub op when op_lvalue is called with OP_LEAVESUBLV as the type. Then PUSHSUB copies into the context stack only those flags that are set both on the current entersub op and in the context stack for the previous sub call.
* [perl #7946] Lvalue subs do not autovivifyFather Chrysostomos2011-06-031-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit makes autovivification work with lvalue subs. It follows the same technique used by other autovivifiable ops (aelem, helem, tc.), except that, due to flag constraints, it uses a single flag and instead checks the op tree at run time to find out what sort of thing to vivify. The flag constraints are that these two flags: #define OPpENTERSUB_HASTARG 32 /* Called from OP tree. */ #define OPpENTERSUB_NOMOD 64 /* Immune to op_lvalue() for :attrlist. */ conflict with these: #define OPpDEREF (32|64) /* autovivify: Want ref to something: */ #define OPpDEREF_AV 32 /* Want ref to AV. */ #define OPpDEREF_HV 64 /* Want ref to HV. */ #define OPpDEREF_SV (32|64) /* Want ref to SV. */ Renumbering HASTARG and NOMOD is problematic, as there are places in op.c that change entersubs into rv2cvs, and the entersub and rv2cv flags would conflict. Setting the flags correctly when changing the type is hard and would result in subtle bugs if not done perfectly. Ops like ${...} don’t actually autovivify; it’s the op inside that does it. In those cases, the parent op is flagged with OPpDEREFed, and it skips get-magic, as it has already been called by the inner op. Since entersub is now marked as being an autovivifying op, ${...} in lvalue context ends up skipping get-magic if there is a foo() inside. And this affects even regular subs. So pp_leavesub and pp_return have to call get-magic; hence the new tests in gmagic.t.
* cop.h: pod: Fix broken linksKarl Williamson2011-05-181-4/+4
|
* struct subst; remove macro for obsolete fieldDavid Mitchell2011-02-181-1/+0
| | | | The field was removed a while ago, but the macro sb_once remained.
* Update old activestate links to point to git.Michael Stevens2011-01-201-2/+3
|
* In Perl_write_to_stderr(), use Perl_magic_methcall() if STDERR is tied.Nicholas Clark2011-01-131-0/+2
| | | | | | Add a flag G_WRITING_TO_STDERR to signal that Perl_magic_methcall() needs to localise PL_stderrgv to NULL, and save/free temps, inside its ENTER/LEAVE pair.
* 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>
* [perl #80548] Add the stash name to DTrace probesDavid Leadbeater2010-12-101-2/+4
| | | | | | | | | | | This adds an additional parameter to perl's dtrace probes with the stash name of the subroutine. This generally looks nicer than the filename but gives a similar level of context. As this is an additional parameter this will not have an impact on existing DTrace scripts. (Also due to the way DTrace works I believe it does not break binary compatibility and would be safe to backport to maint-5.12 if desired, but I'm not a DTrace expert.)
* mark cophh API as experimentalZefram2010-10-211-16/+16
|
* full API for cop hint hashesZefram2010-10-211-7/+303
| | | | | | | | | | | | | 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.]
* Recursive MULTICALL prematurely freed CVDavid Mitchell2010-10-191-2/+2
| | | | | | | | See [perl #78070]. Basically, POPSUB/LEAVESUB had a mechanism to decrement the reference count of the CV only at CvDEPTH==1; POP_MULTICALL was decrementing it at all depths.
* Define CxPADLOOP unconditionally, as post f83b46a0 it is always used.Nicholas Clark2010-09-091-3/+1
| | | | Previously it was only used under -DITHREADS
* bad things happened with for $x (...) { *x = *y }David Mitchell2010-09-081-5/+9
| | | | | | | | | | | | | | | | | | | | | | | | fix for [perl #21469]: since the GP may be pulled from under us and freed, coredumps and strange things can happen. Fix this by storing a pointer to the GV in the loop block, rather than a pointer to the GvSV slot. The ITHREADS variant already stores GV rather than than &GvSV; extend this to non-threaded builds too. Also, for both threaded and non-threaded, it used to push &GvSV on the save stack. Fix this by introducing a new save type, SAVEt_GVSV. This behaves similarly to SAVEt_SV, but without magic get/set. This means that for $package_var (...) is now close in behaviour to local $package_var = ... (except for the magic bit).
* create itervar_u union in struct block_loopDavid Mitchell2010-09-081-19/+12
| | | | | | | make it clearer what types of pointer to the iterator variable can be stored, reduce the amount of #ifdef USE_ITHREADS, get rid of some macros, and generally make the code easier to follow. No change to the size of the structure.
* eliminate targoffset from struct block_loopDavid Mitchell2010-09-081-6/+4
| | | | This value is also available via via cx->blk_loop.my_op->op_targ
* eliminate next_op from struct block_loopDavid Mitchell2010-09-081-13/+0
| | | | | | This field is only used in non-threaded builds, and the comments imply that this is because in non-threaded builds this value may be modified. But nothing in core modifies it.
* Change the first argument of Perl_fetch_cop_label() to COP *Nicholas Clark2010-09-021-1/+1
| | | | | | | | | | From a suggestion from Ben Morrow. The first argument used to be struct refcounted_he *, which exposed an implementation detail - that the COP's labels are (now) stored in this way. Google Code Search and an unpacked CPAN both fail to find any users of this API, so the impact should be minimal.
* Revert "Fix off-by-one: avoid allocating an extra context"Chip Salzenberg2010-07-271-1/+1
| | | | | This reverts commit 395b8e2d02eadc9b0639534410c39c530bc8a33d. The fencepost error is coming from inside the programmer!
* Fix off-by-one: avoid allocating an extra contextChip Salzenberg2010-07-271-1/+1
| | | | (patch req by Nicholas)
* Stop using WITH_THR and WITH_THX, as they were never necessary here.Nicholas Clark2010-06-161-2/+2
|
* Merge remote branch 'zefram/zefram/reliable_exception' into bleadRafael Garcia-Suarez2010-05-041-1/+1
|\ | | | | | | | | Conflicts: pp_ctl.c
| * bring G_KEEPERR back to the realm of sanityZefram2010-04-231-1/+1
| | | | | | | | | | | | | | | | | | Makes the G_KEEPERR logic more consistent, and in particular make it sensibly handle non-string exceptions. An exception in a destructor is now always emitted as a warning, and never copied or merged into $@ of the surrounding context. No more clobbering exceptions being handled elsewhere, and no more double reporting. This fixes the rest of [perl #74538].
* | For Perl_magic_methcall() add G_UNDEF_FILL to fill the stack with &PL_sv_undef.Nicholas Clark2010-04-261-0/+3
|/ | | | | | 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.
* Move PERL_ASYNC_CHECK() from POPBLOCK() to the kill case of Perl_apply().Nicholas Clark2010-04-181-1/+0
| | | | | | This ensures that (safe) signals sent to the same process are still dispatched within the same statement (as before), without overloading the semantics of block popping.
* Move PERL_ASYNC_CHECK() from the runloop to control flow OPs.Nicholas Clark2010-04-151-0/+1
| | | | | | | | | For the typical code this gives a 5% speedup, and removes the cost of "safe signals". Tight looping code will show less gains, but should never be slower. Subtle bugs might remain - there might be constructions that enter the runloop (where signals used to be dispatched) but don't contain any PERL_ASYNC_CHECK() calls themselves.
* more mods to -Dl debugging outputDavid Mitchell2010-04-061-9/+6
|
* improve -Dl debugging outputDavid Mitchell2010-03-301-21/+61
| | | | | In particular, distinguish between scope and context stack push/pops, show depth of JUMPENV stack, and show STACKINFO push/pops
* Eliminate OP_SETSTATE from cop.h headerReini Urban2009-12-131-3/+3
| | | | | | | | | It had been added with change 3728 to track linenumbers in optimized else, disabled by change 4309, and removed with change 33072. Bump copyright, latest change was "Fix MULTICALL in List-Util" 2009-03-07 with commit 1bbbfc50
* Add line information to jumplevel debug informationGerard Goossen2009-11-121-4/+6
| | | | | | | | | | | | | Add information about where in the C code the jumplevel poping/setting up was done. Gerard From 7b95a19d6fbd3615a034cea79fa087b80e4a9555 Mon Sep 17 00:00:00 2001 From: Gerard Goossen <gerard@ggoossen.net> Date: Thu, 12 Nov 2009 16:50:13 +0100 Subject: [PATCH] Add line information to jumplevel debug information provided when using -Dl Signed-off-by: H.Merijn Brand <h.m.brand@xs4all.nl>
* Add assertion to JMPENV_POP to assert that the jumplevel popped is the top ↵Gerard Goossen2009-10-311-0/+1
| | | | level jumplevel
* Add clear magic to %^H so that the HE chain is reset when you empty it.Zefram2009-08-211-4/+9
| | | | This fixes [perl #68590] : %^H not lexical enough.
* Remove all #ifdef MACOS_TRADITIONAL code in core and non-dual-life XS code.Nicholas Clark2009-04-271-5/+1
| | | | | | | | (MacOS support was removed from MakeMaker in 6.22, and merged to blead on 15th December 2004 with 5dca256ec738057dc331fb644a93eca44ad5fa14. After this point MacOS wouldn't even have been able to build the perl binary, because it would not have been able to build DynaLoader. If anyone wishes to resurrect MacOS, start by reversing this commit and the relevant part of that commit.)