summaryrefslogtreecommitdiff
path: root/scope.c
Commit message (Collapse)AuthorAgeFilesLines
* only fully calculate the stash (effective) name where neededTony Cook2022-11-181-3/+3
| | | | | | | | | gcc 12 was complaining that evaluating (somehekptr)->hek_key was always true in many places where HvNAME() or HvENAME() was being called in boolean context. Add new macros to check whether the names should be available and use those instead.
* scope.* - revert and rework SAVECOPWARNINGS changeYves Orton2022-11-041-2/+13
| | | | | | | | | | | | | | We can't put PL_compiling or PL_curcop on the save stack as we don't have a way to ensure they cross threads properly. This showed up as a win32 t/op/fork.t failure in the thread based fork emulation layer. This adds a new save type SAVEt_CURCOP_WARNINGS and macro SAVECURCOPWARNINGS() to complement SAVEt_COMPILER_WARNINGS and SAVECOMPILEWARNINGS(). By simply hard coding where the pointers should be restored to we side step the issue of which thread we are in. Thanks to Graham Knop for help identifying that one of my commits was responsible.
* change the return value of SSNEW to SSize_tTony Cook2022-11-031-3/+3
| | | | | | | | | | | | The normal savestack index is an I32, but that counts in ANY (which are typically the larger of pointer or IV sizes), this meant is the save stack was large, but still nowhere need it's limit, the result of SSNEW() could overflow. So make the result SSize_t and adjust SSPTR() to match. SSPTR() asserts to ensure the supplied type is the same size as SSize_t to ensure callers are updated to handle the new limit.
* cop.h - get rid of the STRLEN* stuff from cop_warningsYves Orton2022-11-021-1/+1
| | | | | With RCPV strings we can use the RCPV_LEN() macro, and make this logic a little less weird.
* scope.* - more flexible ways to save warning bitsYves Orton2022-11-021-2/+2
|
* scope_types.h - new header file for scope type dataYves Orton2022-11-011-61/+1
| | | | Next patch this data will be autogenerated.
* cop.h - add support for refcounted filenames in cops under threadsYves Orton2022-11-011-0/+32
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We have a weird bifurcation of the cop logic around threads. With threads we use a char * cop_file member, without it we use a GV * and replace cop_file with cop_filegv. The GV * code refcounts filenames and more or less efficiently shares the filename amongst many opcodes. However under threads we were simplify copying the filenames into each opcode. This is because in theory opcodes created in one thread can be destroyed in another. I say in theory because as far as I know the core code does not actually do this. But we have tests that you can construct a perl, clone it, and then destroy the original, and have the copy work just fine, this means that opcodes constructed in the main thread will be destroyed in the cloned thread. This in turn means that you can't put SV derived structures into the op-tree under threads. Which is why we can not use the GV * stategy under threads. As such this code adds a new struct/type RCPV, which is a refcounted string using shared memory. This is implemented in such a way that code that previously used a char * can continue to do so, as the refcounting data is located a specific offset before the char * pointer itself. This also allows the len data to embedded "into" the PV, which allows us to expose macros to acces the length of what is in theory a null terminated string. struct rcpv { UV refcount; STRLEN len; char pv[1]; }; typedef struct rcpv RCPV; The struct is sized appropriately on creation in rcpv_new() so that the pv member contains the full string plus a null byte. It then returns a pointer to the pv member of the struct. Thus the refcount and length and embedded at a predictable offset in front of the char *, which means we do not have to change any types for members using this. We provide three operations: rcpv_new(), rcpv_copy() and rcpv_free(), which roughly correspond with newSVpv(), SvREFCNT_inc(), SvREFCNT_dec(), and a handful of macros as well. We also expose SAVERCPVFREE which is similar to SAVEGENERICSV but operates on pv's constructed with rcpv_new(). Currently I have not restricted use of this logic to threaded perls. We simply do not use it in unthreaded perls, but I see no reason we couldn't normalize the code to use this in both cases, except possibly that actually the GV case is more efficient. Note that rcpv_new() does NOT use a hash table to dedup strings. Two calls to rcpv_new() with the same arguments will produce two distinct pointers with their own refcount data. Refcounting the cop_file data was Tony Cook's idea.
* mg.c/perl.c/scope.c - fixup mangled indentation and whitespaceYves Orton2022-11-011-1/+1
| | | | | | Various code related to set_and_free_cop_warnings was terribly mangled as far as whitespace goes. This patch cleans it up so it is readable and correctly indented. Whitespace only changes.
* scope.c - sanity check a var before we use itYves Orton2022-10-241-0/+1
|
* Use HvHasAUX() rather than SvOOK() when operating on HVsPaul "LeoNerd" Evans2022-07-021-6/+4
|
* Convert '!!' to cBOOL()Karl Williamson2022-06-141-1/+1
| | | | | | | | | | | | I believe the '!!' is somewhat obscure; I for one didn't know about it for years of programming C, and it was buggy in one compiler, which is why cBOOL was created, I believe. And it is graphically dense, and generally harder to read than the cBOOL() construct. This commit dates from before we moved to C99 where we can simply cast to (bool), and cBOOL() has been rewritten to do that. But the vast majority of code uses cBOOL(), and this commit brings the remainder of the core .[ch] files into uniformity.
* perlapi: Document save_pushptrKarl Williamson2022-05-311-0/+14
|
* perlapi: Document save_[ah]elem(_flags)?Karl Williamson2022-05-271-0/+44
|
* perlintern: Document save_scalar_atKarl Williamson2022-05-271-0/+21
|
* perlapi: Document save_alloc; mark as internalKarl Williamson2022-05-181-0/+9
| | | | This implements SSNEW and kin, which should be used instead of this.
* perlapi: fix typoKarl Williamson2022-05-151-1/+1
|
* perlapi: Add markup for save_gpKarl Williamson2022-05-141-3/+3
|
* perlintern: Document save_[ah]delete; mark internalKarl Williamson2022-05-111-0/+18
| | | | | These implement SAVE[AH]HDELETE which are the API interfaces for this functionality.
* Mark internal and document leave_scopeKarl Williamson2022-05-071-0/+9
|
* perlapi: Mark internal and document some save_FOO fcnsKarl Williamson2022-05-071-9/+77
| | | | These implement uppercase-named macros.
* perlapi: Mark internal, document (push|pop)_scopeKarl Williamson2022-05-071-0/+16
|
* Inlined newSV_type(SVt_NULL) leaner than non-inlined newSV(0)Richard Leach2022-03-071-2/+2
| | | | | | | | | | | | When a function outside of sv.c creates a SV via newSV(0): * There is a call to Perl_newSV * A SV head is uprooted and its flags set * A runtime check is made to effectively see if 0 > 0 * The new SV* is returned Replacing newSV(0) with newSV_type(SVt_NULL) should be more efficient, because (assuming there are SV heads to uproot), the only step is: * A SV head is uprooted and its flags set
* Add a PL_prevailing_version interpreter varPaul "LeoNerd" Evans2022-02-131-2/+3
| | | | | | Save/restore PL_prevailing_version at SAVEHINTS time Have PL_prevailing_version track the applied use VERSION currently in scope
* Remove NetWare supportDagfinn Ilmari Mannsåker2021-10-081-4/+0
| | | | The build has been broken since 2009.
* Create `defer` syntax and `OP_PUSHDEFER` opcodePaul "LeoNerd" Evans2021-08-251-0/+1
| | | | | | | | | | | | | | | Adds syntax `defer { BLOCK }` to create a deferred block; code that is deferred until the scope exits. This syntax is guarded by use feature 'defer'; Adds a new opcode, `OP_PUSHDEFER`, which is a LOGOP whose `op_other` field gives the start of an optree to be deferred until scope exit. That op pointer will be stored on the save stack and invoked as part of scope unwind. Included is support for `B::Deparse` to deparse the optree back into syntax.
* Rename G_ARRAY to G_LIST; provide back-compat when not(PERL_CORE)Paul "LeoNerd" Evans2021-06-021-1/+1
|
* style: Detabify indentation of the C code maintained by the core.Michael G. Schwern2021-01-171-404/+404
| | | | | | | | | | | This just detabifies to get rid of the mixed tab/space indentation. Applying consistent indentation and dealing with other tabs are another issue. Done with `expand -i`. * vutil.* left alone, it's part of version. * Left regen managed files alone for now.
* Implement SAVEt_STRLEN_SMALLPaul "LeoNerd" Evans2020-12-091-3/+17
| | | | | | | Most uses of SAVEt_STRLEN actually store small values; often zero. Rather than using an entire U64-sized element for these values, it saves space to use the same "SMALL" mechanism as other numerical values, like SAVEt_INT_SMALL.
* autodoc.pl: Enhance apidoc_section featureKarl Williamson2020-11-061-1/+1
| | | | | | | | | | | This feature allows documentation destined for perlapi or perlintern to be split into sections of related functions, no matter where the documentation source is. Prior to this commit the line had to contain the exact text of the title of the section. Now it can be a $variable name that autodoc.pl expands to the title. It still has to be an exact match for the variable in autodoc, but now, the expanded text can be changed in autodoc alone, without other files needing to be updated at the same time.
* Reorganize perlapiKarl Williamson2020-09-041-1/+1
| | | | | This uses a new organization of sections that I came up with. I asked for comments on p5p, but there were none.
* Define a new SAVEt_HINT_HH typePaul "LeoNerd" Evans2020-07-301-11/+16
| | | | | | | | | | | Rather than possibly push an extra HV* to the save stack if the right bit is set in the (saved) hints flags, better just to define a different SAVEt type. Having done this, the stack layout is now constant per type value. This fixes https://github.com/Perl/perl5/issues/17895
* Ensure stack is in consistent state while restoring SAVEt_HINTSPaul "LeoNerd" Evans2020-07-201-1/+7
| | | | | | | | | | | | | | | SAVEt_HINTS has a non-constant savestack structure. If the HINT_LOCALIZE_HH flag was set it pushes an additional pointer. In some complex code scenarios it is possible reënter Perl code while destroying nested PL_hintgv hashes (for example, if any stored objects contain `free` magic). Because of this, it is important that we pop the extra value from the save stack before any other code can be invoked, so if they need to inspect or alter the save stack, they can do so in a consistent manner. See also https://github.com/Perl/perl5/issues/17895
* fixup to free_and_set_cop_warnings()David Mitchell2020-03-201-1/+1
| | | | | | | | | | | | | | | | | | | v5.31.9-156-g94c8b9c1f0 introduced the free_and_set_cop_warnings() macro. It's first argument expects a COP rather than a COP*. Its usage in S_restore_cop_warnings(() is to modify PL_cucop, but in order to pass a COP rather than a COP*, the original commit made a local copy of PL_curcop and ended up inadvertently updating the copy instead. This commit changes the maco so it expects a COP*, and updates the bulk of its callers to use &PL_compiling rather than PL_compiling, and fixes up S_restore_cop_warnings(). The symptoms were ASAN failures in a few test scripts including uni/parser.t and ext/XS-APItest/t/handy0*.t. (The S_restore_cop_warnings() function was only used by Perl__force_out_malformed_utf8_message(), so didn't cause many issues outside of test scripts which forced such "malformed "errors).
* Add macro to free and set cop_warningsNicolas R2020-03-161-3/+1
| | | | | This is avoiding the boilerplate to free the cop_warning string when setting it.
* treat TAINT_get and TAINTING_get as unlikelyTony Cook2019-12-161-1/+1
| | | | | | | | | | | | | | | | | While testing #17359 it appeared that inlining of SvTRUE was being suppressed (indicated by -Winline) by being used in the statement: if (TAINT_get || SvTRUE(error)) { but making TAINT_get unlikely allowed it to be inlined. I expect even in a program that does use taint the vast majority of data will be untainted, so I think it's safe to make TAINT_get UNLIKELY(). TAINTING_get is a harder case, but it's only used in a relatively much smaller number of cases, and I expect most runs of a system perl will have neither -T nor -t.
* Faster feature checksTony Cook2019-10-301-0/+2
| | | | | | | | | | | | | | | Perform only a bit check instead of a much more expensive hash lookup to test features. For now I've just added a U32 to the cop structure to store the bits, if we need more we could either add more bits directly, or make it a pointer. We don't have the immediate need for a pointer that warning do since we don't dynamically add new features during compilation/runtime. The changes to %^H are retained so that caller() can be used from perl code to check the features enabled at a given caller's scope.
* Un-revert "[MERGE] add+use si_cxsubix field"David Mitchell2019-09-231-0/+1
| | | | | | | | original merge commit: v5.31.3-198-gd2cd363728 reverted by: v5.31.4-0-g20ef288c53 The commit following this commit fixes the breakage, which that means the revert can be undone.
* Revert "[MERGE] add+use PL_curstackinfo->si_cxsubix field"v5.31.4Max Maischein2019-09-201-1/+0
| | | | | | | | | | | | This reverts commit d2cd363728088adada85312725ac9d96c29659be, reversing changes made to 068b48acd4bdf9e7c69b87f4ba838bdff035053c. This change breaks installing Test::Deep: ... not ok 37 - Test 'isa eq' completed ok 38 - Test 'isa eq' no premature diagnostication ...
* add PL_curstackinfo->si_cxsubix fieldDavid Mitchell2019-09-191-0/+1
| | | | | | | | | | | | | This tracks the most recent sub/eval/format context pushed onto the context stack. Then make dopopto_cursub use it. The previous value is saved in the cxt struct, and is restored whenever the context is popped. This adds a tiny overhead for every sub call, but speeds up other operations, such as determining the caller context when returning a value from a sub - this has to be dpne for every sub call where the last expression is context sensitive, so its often a win.
* perlapi: save_gp is a GV functionKarl Williamson2019-08-091-0/+3
|
* avoid leak with local $h{foo}, $a[n]David Mitchell2019-03-261-3/+14
| | | | | | | | | | | | | | When SAVEt_DELETE / SAVEt_ADELETE deletes a hash/array entry on scope exit, they also decrement the refcount of the hash/array, and for the hash, also free the saved key. However, if the call to hv_delete() or av_delete() dies (e.g. when calling a tied DELETE method) then the hash/array and key will leak because leave_scope() calls av/hv_delete(), *then* does the SvREFCNT_dec() etc. The fix is to push new FREEPV/FREESV actions just before calling av/hv_delete().
* revert smartmatch to 5.27.6 behaviourZefram2017-12-291-1/+0
| | | | | | | | | | | | | The pumpking has determined that the CPAN breakage caused by changing smartmatch [perl #132594] is too great for the smartmatch changes to stay in for 5.28. This reverts most of the merge in commit da4e040f42421764ef069371d77c008e6b801f45. All core behaviour and documentation is reverted. The removal of use of smartmatch from a couple of tests (that aren't testing smartmatch) remains. Customisation of a couple of CPAN modules to make them portable across smartmatch types remains. A small bugfix in scope.c also remains.
* make loop control apply to "given"Zefram2017-11-291-1/+3
| | | | A "given" construct is now officially a one-iteration loop.
* Use memEQs, memNEs in core filesKarl Williamson2017-11-061-4/+2
| | | | | | | | | | Where the length is known, we can use these functions which relieve the programmer and the program reader from having to count characters. The memFOO functions should also be slightly faster than the strFOO equivalents. In some instances in this commit, hard coded numbers are used. These come from the 'case' statement values that apply to them.
* [perl #129916] Allow sub-in-stash outside of mainFather Chrysostomos2017-10-081-0/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The sub-in-stash optimization introduced in 2eaf799e only applied to subs in the main stash, not in other stashes, due to a problem with the logic in newATTRSUB. This comment: Also, we may be called from load_module at run time, so PL_curstash (which sets CvSTASH) may not point to the stash the sub is stored in. explains why we need the PL_curstash != CopSTASH(PL_curcop) check. (Perl_load_module will fail without it.) But that logic does not work properly at compile time (when PL_curcop == &PL_compiling). The value of CopSTASH(&PL_compiling) is never actually used. It is always set to the main stash. So if we check that PL_curstash != CopSTASH(PL_curcop) and forego the optimization in that case, we will never optimize subs outside of the main stash. What we really need is to check IN_PERL_RUNTIME && PL_curstash != opSTASH(PL_curcop). I.e., forego the optimization at run time if the stashes differ. That is what this commit implements. One observable side effect of this change is that deleting a stash element no longer anonymizes the CV if the CV had no GV that it was depending on to provide its name. Since the main thing in such situa- tions is that we do not get a crash, I think this change (arguably an improvement) is acceptable.) ----------- A bit of explanation of various other changes: gv.c:require_tie_mod needed a bit of help, since it could not handle sub refs in stashes. To keep localisation of stash elements working the same way, local($Stash::{foo}) now upgrades a coderef to a full GV before the localisation. (Changes in two pp*.c files and in scope.c:save_gp.) t/op/stash.t contains a test that makes sure that perl does not crash when a GV with a CV pointing to it gets deleted. This commit tweaks the test so that it continues to test that. (There has to be a GV for the test to test what it is meant to test.) Similarly with t/uni/caller.t and t/uni/stash.t. op.c:rv2cv_op_cv with the _MAYBE_NAME_GV flag was returning the cal- ling GV in those cases where a GV-less sub is called via a GV. E.g., *main = \&Foo::foo; main(). This meant that errors like ‘Not enough arguments’ were giving the wrong sub name. newATTRSUB was not calling mro_method_changed_in when storing a sub as an RV. gv_init needs to arrange for the new GV to have the file and line num- ber corresponding to the sub in it. These are taken from CvSTART, which may be off by a few lines, but is the closest we have to the place the sub was declared.
* Add CvGvNAME_HEK helperNicolas R2017-09-211-7/+2
| | | | | | | CvGvNAME_HEK can be used instead of the boilerplate: CvNAMED(sv) ? CvNAME_HEK((CV *)sv) : GvNAME_HEK(CvGV(sv)) This is also saving an extra CvNAMED check from CvNAME_HEK.
* add PL_curstackinfo->si_stack_hwmDavid Mitchell2017-06-241-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | On debugging builds only, add a mechanism for checking pp function calls for insufficient stack extending. It works by: * make the runops loop set a high-water-mark (HWM) variable equal to PL_stack_sp just before calling each pp function; * make EXTEND() etc update this HWM; * on return from the pp function, panic if PL_stack_sp is > HWM. This detects whether pp functions are pushing more items onto the stack than they are requesting space for. There's a possibility of false positives if the code is doing weird stuff like direct manipulation of stacks via PL_curstack, SWITCHSTACK() etc. It's also possible that one pp function "knows" that a previous pp function will have already grown the stack enough. Currently the only place in core that seems to do this is pp_enteriter, which allocates 1 stack slot so that pp_iter doesn't have to check each time it returns &PL_sv_yes/no. To accommodate this, the new macro EXTEND_SKIP() has been added, that tells perl that it's safely skipping an EXTEND() here.
* PERL_GLOBAL_STRUCT_PRIVATE: fix scope.c:arg_countsDavid Mitchell2017-03-171-1/+1
| | | | | t/porting/libperl.t under -DPERL_GLOBAL_STRUCT_PRIVATE doesn't like non-const static data structures
* update size after RenewHugo van der Sanden2017-03-151-12/+17
| | | | | | | | | | | | | | | RT #130841 In general code, change this idiom: PL_foo_max += size; Renew(PL_foo, PL_foo_max, foo_t); to Renew(PL_foo, PL_foo_max + size, foo_t); PL_foo_max += size; so that if Renew dies, PL_foo_max won't be left hanging.
* Change white space to avoid C++ deprecation warningKarl Williamson2016-11-181-25/+25
| | | | | | | | | | | | | | | | | | | | | | C++11 requires space between the end of a string literal and a macro, so that a feature can unambiguously be added to the language. Starting in g++ 6.2, the compiler emits a warning when there isn't a space (presumably so that future versions can support C++11). Unfortunately there are many such instances in the perl core. This commit fixes those, including those in ext/, but individual commits will be used for the other modules, those in dist/ and cpan/. This commit also inserts space at the end of a macro before a string literal, even though that is not deprecated, and removes useless "" literals following a macro (instead of inserting a blank). The result is easier to read, making the macro stand out, and be clearer as to the intention. Code and modules included with the Perl core need to be compilable using C++. This is so that perl can be embedded in C++ programs. (Actually, only the hdr files need to be so compilable, but it would be hard to test that just the hdrs are compilable.) So we need to accommodate changes to the C++ language.