summaryrefslogtreecommitdiff
path: root/pp_ctl.c
Commit message (Collapse)AuthorAgeFilesLines
* CH] Change usage of regex/op common to common namesKarl Williamson2011-01-161-1/+1
| | | | | | | | | This patch changes the core functions to use the common names for the fields that are shared between op.c and regcomp.c, just for consistency of using one name throughout the core for the same thing. A grep of cpan shows that both names are used in various modules; so both names must be retained.
* Generate pp_* prototypes in pp_proto.h, and remove pp.symNicholas Clark2011-01-091-7/+7
| | | | | | | | | | | 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-3/+3
| | | | | | | | | # 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).
* [perl #68712] caller() filenames broken by "use"Father Chrysostomos2010-12-101-6/+4
| | | | | | | | | | | | | | | | | | | | | | | | | require() sets the file name for PL_compiling but localises it to the calling scope, not the scope that it creates. As a result, caller() during or after require (in the same scope that require was called from) will return the wrong file name for whichever code is being com- piled at the time and any scope sharing the same CopFILE (or something like that): $ ./miniperl -Ilib -e 'BEGIN{require strict; warn join ", ", caller(0)}' main, lib/strict.pm, 1, main::BEGIN, 1, , , , 0, , at -e line 1. ^^^^^^^^^^^^^ should be -e This commit moves the SAVECOPFILE_FREE and CopFILE_set down below the ENTER_with_name to put it in the right scope. It was in its existing location presumably because namesv needed to be freed before any code that could die (and the CopFILE_set call reads a PV allocated for namesv). So now namesv is mortalised instead. The if(tryrsfp) is no longer necessary, as that code is never reached when tryrsfp is false. The block in between that sets %INC was reading CopFILE. It can simply use the same tryname variable that is passed to CopFILE_set.
* [perl #66104] Bugs in extended regexp featuresFather Chrysostomos2010-12-071-0/+19
| | | | | | | | | | | | | | | More precisely: Make run-time (?{...}) inherit pragmata. This commit makes Perl_sv_compile_2op_is_broken (nice name!) copy the hints from PL_curcop if invoked during run time. Usually they are inherited from the code that is currently being compiled (which works for $foo =~ /(?{...})/), but the code currently being compiled is not the enclosing scope at run time ($bar = '(?{...})'; $foo =~ $bar), hence the need for copying in a similar manner to pp_entereval. Theoretically this code should also have to avoid copying a statement label, but goto inside a regexp eval does not currently work, so I cannot prove or disprove that yet.
* stopgap hack for $@ as unwinding reason indicatorZefram2010-12-071-0/+34
| | | | | | | Set $@ early in a die as well as late, so that it continues to function as an unreliable indicator of whether unwinding in progress is due to an exception. This is a stopgap arrangement, until the unwinding process can be introspected properly.
* Avoid redundant hv_delete call in pp_enterevalFather Chrysostomos2010-11-261-1/+1
| | | | | This commit just avoids a redundant hv_delete call if leave_scope is already going to do it.
* Stop eval "BEGIN{die}" from leakingFather Chrysostomos2010-11-261-1/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This fixes the rest of [perl #78438]. eval "BEGIN{die}" creates a *{"_<(eval 1)"} glob regardless of $^P’s setting in non-threaded builds as of change f9bddea (5.12.0). Here are the results with various configurations: version threaded eval text $^P Is *{"_<(eval 1)"} set? ------- -------- --------- --- ----------------------- 5.10.1 yes BEGIN{} 0 no 5.10.1 yes BEGIN{die} 0 no 5.10.1 yes BEGIN{} 0xA yes 5.10.1 yes BEGIN{die} 0xA no 5.10.1 no BEGIN{} 0 no 5.10.1 no BEGIN{die} 0 no 5.10.1 no BEGIN{} 0xA yes 5.10.1 no BEGIN{die} 0xA no 5.13.7 yes BEGIN{} 0 no 5.13.7 yes BEGIN{die} 0 no 5.13.7 yes BEGIN{} 0xA yes 5.13.7 yes BEGIN{die} 0xA yes 5.13.7 no BEGIN{} 0 no 5.13.7 no BEGIN{die} 0 yes 5.13.7 no BEGIN{} 0xA yes 5.13.7 no BEGIN{die} 0xA yes Notice that, for non-threaded builds, BEGIN{die} goes from never sav- ing the text to always saving it. The commit in question is: commit f9bddea7d2a0d824366014c8ee6ba57e7dedd8c3 Author: Nicholas Clark <nick@ccl4.org> Date: Tue Dec 2 20:43:58 2008 +0000 Implement PERLDBf_SAVESRC_INVALID, which saves source lines for string evals that fail to compile. p4raw-id: //depot/perl@34985 It stops unconditionally using the scoping mechanism to delete $::{"_<(eval $num)"} on compilation failure: - safestr = savepvn(tmpbuf, len); - SAVEDELETE(PL_defstash, safestr, len); but instead does it explicitly in this block: + if (doeval(gimme, NULL, runcv, seq)) { + if (was != PL_breakable_sub_gen /* Some subs defined here. */ + ? (PERLDB_LINE || PERLDB_SAVESRC) + : PERLDB_SAVESRC_NOSUBS) { + /* Retain the filegv we created. */ + } else { + char *const safestr = savepvn(tmpbuf, len); + SAVEDELETE(PL_defstash, safestr, len); + } + return DOCATCH(PL_eval_start); + } else { + /* We have already left the scope set up earler thanks to the LEAVE + in doeval(). */ + if (PERLDB_SAVESRC_INVALID) { + /* Retain the filegv we created. */ + } else { + (void)hv_delete(PL_defstash, tmpbuf, len, G_DISCARD); + } + return PL_op->op_next; + } In the case of BEGIN{die}, that doeval() never returns, so the clean-up code is not reached. S_doeval never returns because call_list calls Perl_croak if it catches a BEGIN error (appending the extra ‘BEGIN failed--compilation aborted’, etc.). That takes execution all the way back to perl_run, so it bypasses the clean-up code in pp_entereval. What’s leaking is the GV created earlier in pp_entereval by this line: CopFILE_set(&PL_compiling, tmpbuf+2); CopFILE_set simply stores a string under threads, but creates a GV under non-threaded builds. This commit solves the problem by scheduling a deletion *before* call- ing doeval, if the source lines have not been saved. This works because the usual code to handle it is only bypassed when there is a BEGIN block (a subroutine), so PL_breakable_sub_gen will have gone up. So we never need to delete the saved lines when that code is bypassed.
* [perl #78438] Memory leak with 'use v5.42'Father Chrysostomos2010-11-251-3/+4
|
* Stop eval "use 6" from leakingFather Chrysostomos2010-11-251-2/+4
|
* Stop eval "no 5" from leakingFather Chrysostomos2010-11-251-1/+3
|
* Make BEGIN {require 5.12.0} behave as documented.Nicholas Clark2010-11-251-17/+0
| | | | | | Previously in a BEGIN block, require was behaving identically to use 5.12.0 - ie erroneously executing the use feature ':5.12.0'; and use strict; use warnings behaviour, which only use was documented to provide.
* Deprecate sv_compile_2op()Nicholas Clark2010-11-241-1/+13
| | | | | | | | | It attempted to provide an API to compile code down to an optree, but failed to bind correctly to lexicals in the enclosing scope. It's not possible to fix this problem within the constraints of its parameters and return value. Searches suggest +that nothing on CPAN is using it, so removing it should have zero impact.
* Implement $^A taintingNiko Tyni2010-11-141-0/+4
| | | | | | | | | The format accumulator $^A now becomes tainted when formline() is called with tainted data. There is still one failing test from the TODO set; it seems that the $^A get magic is handled too late for the taintedness to show up.
* Fix a crash with a tainted formline() pictureNiko Tyni2010-11-141-1/+1
| | | | | | | A private (tainted) string did not get its share of space in the destination string, causing a buffer overflow later. Originally reported by Roland Kuhn as http://bugs.debian.org/575318
* Remove an unused variableFlorian Ragwitz2010-11-091-1/+0
|
* In S_check_type_and_open() call PerlIO_openn() directly if possible.Nicholas Clark2010-11-091-0/+4
| | | | | | | This saves creating a mortal SV on every file require (and a strlen()). This commit brought to you with the aid of the campaign for elimination of strlen().
* Change S_doopen_pm() and S_check_type_and_open() to take an SV parameter.Nicholas Clark2010-11-091-27/+18
| | | | | Previously S_doopen_pm() took a char */STRLEN pair, but it happened that the pointer was always from an SV. So pass the SV directly.
* fix thinko in code commentDavid Mitchell2010-10-261-1/+1
|
* refactor and regularise label/statement grammarZefram2010-10-251-0/+8
| | | | | | | | | | | | | | | | | | | | Refactoring of the grammar around statements. New production <barestmt> encompasses a statement without label. It includes all statement types, including declarations, with no unnecessary intermediate non-terminals. It generates an op tree for the statement's content, with no leading state op. The <fullstmt> production has just one rule, consisting of optional label followed by <barestmt>. It puts a state op on the front of the statement's content ops. To support the regular statement op structure, the op sequence for for(;;) loops no longer has a second state op between the initialisation and the loop. Instead, the unstack op type is slightly adapted to achieve the stack clearing without a state op. The newFOROP() constructor function no longer generates a state op, that now being the job of the <fullstmt> production. Consequently it no longer takes a parameter stating what label is to go in the state op. This brings it in line with the other op constructors.
* don't rely on ghost contexts being unmolestedZefram2010-10-241-4/+9
| | | | | | | | Dying and returning from a format both relied on the state of a just-popped context frame being preserved across a LEAVE. Don't rely on it. Test using an operator ripped off from Scope::Cleanup, which makes it easy to run arbitrary Perl code during cleanup, without isolating it on a separate context stack as the DESTROY mechanism does.
* full API for cop hint hashesZefram2010-10-211-15/+5
| | | | | | | | | | | | | 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.]
* add lex_start to the APIZefram2010-10-211-3/+3
| | | | | lex_start() is added to the API, marked experimental, and documented. It also gains a flags parameter for foreseeable future use.
* remove redundant lex_endZefram2010-10-211-4/+0
| | | | | | | The lex_end() function is redundant, because the lexer context object is actually finalised by parser_free(), triggered by the save stack. The lex_end() function has historically been empty, except when the PL_doextract global was being misused to store lexer state.
* remove filter inheritance option from lex_startZefram2010-10-211-3/+3
| | | | | | | | The only uses of lex_start that had the new_filter parameter false, to make the new lexer context share source filters with the previous lexer context, were uses with rsfp null, which therefore never invoked source filters. Inheriting source filters from a logically unrelated file seems like a silly idea anyway.
* Stop 'use v5.8' leaking memory. Fixes #78436.Nicholas Clark2010-10-191-1/+1
| | | | Based on a patch proposed by Niko Tyni.
* Remove some excess cleverness from the Bhk macros.Ben Morrow2010-10-101-1/+1
| | | | | | | | | Allowing BhkENTRY(bhk, start) to look up the bhk_start member defeats much of the point of having a bhk_ prefix in the first place: if a member is added later called (say) 'bhk_die', any invocation of BhkENTRY(bhk, die) will expand to BhkENTRY(bhk, Perl_die) because of the API macros. Requiring BhkENTRY(bhk, bhk_start), while tedious, is much safer.
* stop map,grep leaking temps [perl #48004]David Mitchell2010-10-041-2/+39
| | | | | | | | | | | | | | | | The former behaviour of map and grep was to never free any temps. Thus for large lists (and even worse, nested maps), the tmps stack could grow very large. For all cases expect list-context map, the fix is easy: just do a FREETMPS at the end of each iteration. The list-context map however, needs to accumulate a list of temporaries over the course of the iterations, and finally return that list to the caller (which is responsible for freeing them). We get round this by, at the end of each iteration, directly manipulating the tmps stack to free everything *except* the values to be returned. To make this efficient, we splice in the returned tmp items at the base of the stack frame, move PL_tmps_floor above them, then do a FREETMPS (so they may appear twice on the temps stack, but initially only get freed once).
* G_KEEPERR sometimes set $@David Mitchell2010-10-031-2/+8
| | | | | | eval_sv(sv,G_KEEPERR) is supposed to warn on errors, rather than set $@; but in the particular case of compile-time errors it still set $@ instead. See [perl ##3719].
* [perl #76814] FETCH called twice - m and sFather Chrysostomos2010-09-241-1/+9
| | | | | | This fixes m and s. It modifies pp_regcomp to avoid extra magic. It also corrects a bug in sv_catsv_flags, which would still call mg_get(ssv) even without the SV_GMAGIC flag set.
* [perl #70614] Seg. fault with eval/use/UNITCHECK/DESTROY/eval combinationFather Chrysostomos2010-09-221-1/+4
| | | | | | | | | | | | | This case can be reduced to: eval "UNITCHECK{ eval 0 }" (eval 0 triggers the bug more reliably than eval ''.) The inner eval clobbers PL_eval_start, so when the UNITCHECK finishes, the outer eval tries to call the inner eval’s code, which has been freed already. This commit saves PL_eval_start and restores it after UNITCHECK.
* [perl #19078] wrong match order inside replacementFather Chrysostomos2010-09-201-0/+1
| | | | | | | | | | | | | | | | | | | | | | $ perl -le '$_="CCCGGG"; s!.!@a{print("[$&]"),/./}!g' [C] [C] [C] [C] [C] [C] What’s happening is that the s/// does not reset PL_curpm for each iteration, because it doesn’t usually have to. The RHS’s scoping takes care of it most of the time. This happens with the /e modifier and with @{...}. In this example, though, we have a subscript, not a block. This sub- script is in the same scope as the s/// itself. The assumption that the substitution operator will never have to reset PL_curpm itself appears to be incorrect. This fixes it.
* add hv_copy_hints_hv and save_hints to the APIZefram2010-09-161-1/+1
|
* bad things happened with for $x (...) { *x = *y }David Mitchell2010-09-081-5/+2
| | | | | | | | | | | | | | | | | | | | | | | | 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).
* move some comments back to the lines they refer toDavid Mitchell2010-09-081-6/+5
|
* swap round a confusing #ifndef ... #else ...David Mitchell2010-09-081-3/+3
|
* create itervar_u union in struct block_loopDavid Mitchell2010-09-081-13/+8
| | | | | | | 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 next_op from struct block_loopDavid Mitchell2010-09-081-2/+2
| | | | | | 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.
* API functions for accessing the runtime hinthash.Ben Morrow2010-09-071-17/+51
| | | | | | | Add hinthash_fetch(sv|pv[ns]) as a replacement for refcounted_he_fetch, which is not API (and should not be). Also add caller_cx, as the correct XS equivalent to caller(). Lots of modules seem to have copies of this, so a proper API function will be more maintainable in future.
* function interface to parse Perl statementZefram2010-09-061-3/+3
| | | | | | | | | | | | | yyparse() becomes reentrant. The yacc stack and related resources are allocated in yyparse(), rather than in lex_start(), and they are localised to yyparse(), preserving their values from any outer parser. yyparse() now takes a parameter which determines which production it will parse at the top level. New API function parse_fullstmt() uses this facility to parse just a single statement. The top-level single-statement production that is used for this then messes with the parser's head so that the parsing stops without seeing EOF, and any lookahead token seen after the statement is pushed back to the lexer.
* Change the first argument of Perl_fetch_cop_label() to COP *Nicholas Clark2010-09-021-3/+2
| | | | | | | | | | 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.
* Remove CALL_FPTR and CPERLscope.Ben Morrow2010-08-201-1/+1
| | | | | | | | | | | | | | | | These are left from PERL_OBJECT, which was an implementation of multiplicity using C++ objects. PERL_OBJECT was removed in 5.8, but the macros seem to have been cargo-culted all over the core (including in places where they would have been inappropriate originally). Since they now do exactly nothing, it's cleaner to remove them. I have left the definitions in perl.h, under #ifndef PERL_CORE, since some CPAN XS code uses them (also often incorrectly). I have also left STATIC alone, since it seems potentially more useful and is much more ingrained. The only appearance of these macros this patch doesn't touch is in Devel-PPPort, because that's a CPAN module.
* Add Perl_init_dbargs(), to set up @DB::args without losing SV references.Nicholas Clark2010-07-211-5/+2
|
* Fix for RT#2353: catch yyparse() exceptions in (?{...})George Greer2010-07-121-0/+4
| | | | | | | | | | | Ticket is entitled: "panic: top_env when localizing a lexical variable in qr{(?{...})}" but a better description would be: "(?{...}) does not catch yyparse() exceptions in regex compilation" Changes Perl_sv_compile_2op() to tell doeval() that it must use S_try_yyparse() to catch any exception that yyparse() may throw.
* Macroify the block_hooks structure.Ben Morrow2010-07-121-0/+2
| | | | | Add a flags member, so it can be extended later if necessary. Add a bhk_eval member, called from doeval to catch requires and string evals.
* Don't set strict for 'no 6;'David Golden2010-07-061-15/+14
| | | | | | | | Commit faee19b51573e81abe8811f1256a1d27777d6d04 was incomplete and only stopped features from being enabled under 'no'. This patch merges all 'use N.NN' type logic into a single if clause and then checks version numbers in separate if statements within it.
* In pp_regcomp and pp_entereval, use newSVpvn_flags() to simplify code.Nicholas Clark2010-07-051-12/+5
|
* PL_amagic_generation doesn't show overload loadedDavid Mitchell2010-07-031-9/+7
| | | | | | PL_amagic_generation is non-zero even without the presence of 'use overload', so don't bother using it as a short-cut test of whether we can skip AMAGIC processing
* fix bad indentation in pp_regcompDavid Mitchell2010-07-031-2/+2
|