summaryrefslogtreecommitdiff
path: root/pp_sys.c
Commit message (Collapse)AuthorAgeFilesLines
* [perl #131645] Fix assert fail in pp_sselectFather Chrysostomos2017-08-291-6/+15
| | | | | | | | | | | | | | | | | | | pp_sselect (4-arg select) process its first three bitfield arguments first, making sure each one has a valid PV, and then it moves on to the final, timeout argument. SvGETMAGIC() on the timeout argument will wipe out any values the SV holds, so if the same scalar is used as a bitfield argument *and* as the timeout, it will no longer hold a valid PV. Assertions later in pp_sselect make sure there is a valid PV. This commit solves the assertion failure by making a temporary copy of any gmagical or overloaded argument. When the temporary copy is made, the values written to the temporary copies of the bitfield arguments are then copied back to the original magical arguments. (cherry picked from commit e26c6904d9f9f5ea818e590331b14038279332d1)
* Moving variables to their innermost scope.Andy Lester2017-02-181-6/+3
| | | | | | Some vars have been tagged as const because they do not change in their new scopes. In pp_reverse in pp.c, I32 tmp is only used to hold a char, so is changed to char.
* Fix memory leak in generating an exception messageAaron Crane2017-02-041-1/+1
| | | | This was my fault; oops.
* RT#130623: assertions when tying into non-packagesAaron Crane2017-01-241-6/+19
|
* Reading/writing bytes from :utf8 handles will be fatal in 5.30Abigail2017-01-161-2/+4
|
* Opening a file and dir using the same symbol will be fatal in 5.28.Abigail2017-01-161-2/+2
| | | | | | | | Perl 5.10 deprecated using the same symbol to open both a filehandle and a dirhandle, as this can lead to confusing code. In Pelr 5.28, this will become a fatal error. This patch changes the warning to reflect this.
* pp_sys.c: White space onlyKarl Williamson2017-01-131-5/+5
| | | | Vertically align some components of an 'if' for readability.
* Change white space to avoid C++ deprecation warningKarl Williamson2016-11-181-27/+27
| | | | | | | | | | | | | | | | | | | | | | 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.
* Improve error for missing tie() pacakge/methodDagfinn Ilmari Mannsåker2016-11-141-4/+17
| | | | | This brings the error messages in line with the ones used for normal method calls, despite not using call_method().
* make the sysread()/syswrite/() etc :utf8 handle warnings defaultTony Cook2016-11-141-6/+6
| | | | as they should be for deprecation warnings
* (perl #129130) make chdir allocate the stack it needsTony Cook2016-10-241-0/+1
| | | | | chdir with no argument didn't ensure there was stack space available for its result.
* pp_sys.c: use new SvPVCLEAR and constant string friendly macrosYves Orton2016-10-191-4/+4
|
* Add is_utf8_fixed_width_buf_flags() and use itKarl Williamson2016-09-251-6/+2
| | | | | | | | This encodes a simple pattern that may not be immediately obvious to someone needing it. If you have a fixed-size buffer that is full of purportedly UTF-8 bytes, is it valid or not? It's easy to do, as shown in this commit. The file test operators -T and -B can be simpified by using this function.
* Use new is_utf8_valid_partial_char()Karl Williamson2016-08-311-4/+4
| | | | | | | | This new function can be used in the implementation of the file test operators, -B and -T, to see if the whole fixed length buffer is valid UTF-8. Previously if all bytes were UTF-8 except the bytes at the end that could have been a partial character, it assumed the whole thing was UTF-8. This improves the prediction slightly
* Use new name 'is_utf8_invariant_string' in coreKarl Williamson2016-08-311-1/+1
| | | | | | This changes the places in the core to use the clearer synonym added by the previous commit. It also changes one place that hand-rolled its own code to use this function instead.
* [perl #128740] Check for null in pp_ghostent et al.Father Chrysostomos2016-08-011-3/+1
| | | | | | | Specifically in the S_space_join_names_mortal static function that several pp functions call. On some platforms (such as Gentoo Linux with torsocks), hent->h_aliases (where hent is a struct hostent *) may be null after a gethostent call.
* (perl #128316) preserve errno from failed system callsTony Cook2016-06-161-2/+2
|
* make gimme consistently U8David Mitchell2016-02-031-5/+5
| | | | | | | | | | | | | The value of gimme stored in the context stack is U8. Make all other uses in the main core consistent with this. My primary motivation on this was that the new function cx_pushblock(), which I gave a 'U8 gimme' parameter, was generating warnings where callers were passing I32 gimme vars to it. Rather than play whack-a-mole, it seemed simpler to just uniformly use U8 everywhere. Porting/bench.pl shows a consistent reduction of about 2 instructions on the loop and sub benchmarks, so this change isn't harming performance.
* convert CX_PUSHFORMAT/POPFORMAT to inline fnsDavid Mitchell2016-02-031-2/+2
| | | | | | Replace CX_PUSHFORMAT() with cx_pushformat() etc. No functional changes.
* convert CX_PUSH/POP/TOPBLOCK to inline fnsDavid Mitchell2016-02-031-2/+2
| | | | | | Replace CX_PUSHBLOCK() with cx_pushblock() etc. No functional changes.
* rename PUSHBLOCK,PUSHSUB etc to CX_PUSHBLOCK etcDavid Mitchell2016-02-031-2/+2
| | | | | | | Earlier all the POPFOO macros were renamed to CX_POPFOO to reflect the changed API (like POPBLOCK no longer decremented cxstack_ix). Now rename the PUSH ones for consistency.
* PUSHFORMAT: don't use implicit argsDavid Mitchell2016-02-031-1/+1
| | | | | Make cv and gv explicit parameters of PUSHFORMAT(), rather than just assuming that there are such vars in scope.
* PUSHBLOCK: don't use implicit argsDavid Mitchell2016-02-031-1/+1
| | | | | Make gimme a parameter of PUSHBLOCK() rather than just assuming that there's a 'gimme' var in scope.
* move PL_savestack_ix saving into PUSHBLOCKDavid Mitchell2016-02-031-1/+1
| | | | | | | | | | | | Currently blku_oldsaveix was being set by the various PUSHFOO macros, except for PUSHSUB and PUSHEVAL which expected their caller to do it manually. Now that all the main context state is stored on the context stack rather than than some on the save stack too, things are a lot simpler, and this messy transitional state can now be rationalised, whereby blku_oldsaveix is now always set by PUSHBLOCK; the exact value being specified by a new arg to PUSHBLOCK.
* eliminate PERL_STACK_OVERFLOW_CHECKDavid Mitchell2016-02-031-3/+1
| | | | | | | | This macro is defined as NOOP on all platforms except for MacOS classic, where it was added as a hook to allow for OSes that have a small CPU stack size. Since pp_entersub et al don't actually use the CPU stack, this hook looks misconceived from the beginning. So remove all uses of it in the core.
* rename POPFOO() to CX_POPFOO()David Mitchell2016-02-031-2/+2
| | | | | | | | | | | | | | | | Rename all the context-popping macros such as POPBLOCK and POPSUB, by giving them a CX_ prefix. (Do TOPBLOCK too). This is principally to deliberately break any existing non-core use of these non-API macros, as their behaviour has changed in this branch. In particular, POPBLOCK(cx) no longer decrements the cxt stack pointer nor sets cx; instead, cx is now expected to already point to the stack frame which POPBLOCK should process. At the same time, giving them a CX_ prefix makes it clearer that these are all part of a family of macros that manipulate the context stack. The PUSHFOO() macros will be renamed in a later commit.
* add CX_CUR() macroDavid Mitchell2016-02-031-2/+2
| | | | | | This is simply #define CX_CUR() (&cxstack[cxstack_ix])
* make POPSUB and POPFORMAT re-entrant safeDavid Mitchell2016-02-031-1/+4
| | | | | | | | | | | | | | | | | | | | | | | | | In code like sub DESTROY { exit } sub f { push @_, bless [] } f() While leaving f, POPSUB will attempt to clear @_. This triggers the destructor, which calls exit, which unwinds the context stack, calling POPSUB again on thr same context stack entry. Thus we need to to be careful that POPSUB can be called multiple times on the same CX stack entry. The general way of doing this is to NULL or update pointers *before* calling SvREFCNT_dec() on the old value. This commit also removes the old CxPOPSUB_DONE mechanism which was a poor bandaid added at the last minute to 5.22 to try and achieve the basics of what this commit does comprehensively (hopefully). Also, CxPOPSUB_DONE was mainly a protection against re-entrantly calling LEAVE_SCOPE(). Since that's now done before POPSUB rather than in the middle of it, it has become reentrant-safe by default.
* add CX_POP(cx) macro: glorified cxstack_ix--David Mitchell2016-02-031-1/+1
| | | | but with extra checking goodness on debugging builds.
* move CX_LEAVE_SCOPE outside the POPFOO'sDavid Mitchell2016-02-031-0/+1
| | | | | | | | | | Currently every POPFOO macro has CX_LEAVE_SCOPE(cx) as its first action. Since this is common code and not specific to a particular POPFOO type, remove it from each POPFOO macro and make each caller of POPFOO explicitly call CX_LEAVE_SCOPE() instead. This should make no functional difference (but will help if you're single-stepping the code in a debugger :-)
* remove newpm param from POPBLOCK() macro.David Mitchell2016-02-031-1/+1
| | | | | | | Since all core usage of POPBLOCK now immediately restores PL_curpm, there's no need to copy the old value to a temp var specified by the caller; just make POPBLOCK itself restore PL_curpm in the same way that it restores all the other PL_ vars.
* reverse the order of POPBLOCK; POPFOODavid Mitchell2016-02-031-2/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently most pp_leavefoo subs have something along the lines of POPBLOCK(cx); POPFOO(cx); where POPBLOCK does cxstack_ix-- and sets cx to point to the top CX stack entry. It then restores a bunch of PL_ vars saved in the CX struct. Then POPFOO does any type-specific restoration, e.g. POPSUB decrements the ref count of the cv that was just executed. However, this is logically the wrong order. When we *enter* a scope, we do PUSHBLOCK; PUSHFOO; so undoing the PUSHBLOCK should be the last thing we do. As it happens, it doesn't really make any difference to the running, which is why we've never fixed it before. Reordering it has two advantages. First, it allows the steps for scope exit to be the exact logical reverse of scope exit, which makes understanding what's going on and debugging easier. It allows us to make the code cleaner. This commit also removes the cxstack_ix-- and setting cx steps from POPBLOCK; now we already expect cx to be set (which it usually already is) and we do the cxstack_ix-- ourselves. This also means we can remove a whole bunch of cxstack_ix++'s that were added immediately after the POPBLOCK in order to prevent the context being inadvertently overwritten before we've finished using it. So in full, POPBLOCK(cx); POPFOO(cx); is now implemented as: cx = &cxstack[cxstack_ix]; ... other stuff done with cx ... POPFOO(cx); POPBLOCK(cx); cxstack_ix--; Finally, this commit also tweaks PL_curcop in pp_leaveeval, since otherwise PL_curcop could temporarily be NULL when debugging code is called in the presence of 'use re Debug'. It also stops the debugging code crashing if PL_curcop is still NULL.
* POPBLOCK: don't set newsp and gimmeDavid Mitchell2016-02-031-4/+1
| | | | | | This macro used to set these two vars as a side-effect. Since we now usually access those values before we call POPBLOCK, it's wasteful to set them again.
* CXt_FORMAT: save ss_ix and tmps_floor in CX structDavid Mitchell2016-02-031-4/+0
| | | | | | To match the recent work in this branch on CXt_SUB, make CXt_FORMAT save PL_savestack_ix and PL_tmps_floor in the context structure rather than doing ENTER/SAVETMPS. It's more efficient and more consistent.
* save old PL_comppad in CXt_SUB/FORMAT blockDavid Mitchell2016-02-031-1/+0
| | | | | | | | | | | | | | | | | | | | Currently when we call a sub, the old value of PL_comppad is saved on the save stack using SAVECOMPPAD(). Instead, save it in a new field in the context struct, called prevcomppad. This is simpler and more efficient. Note that there is already a confusingly-named field in the CXt_SUB context struct called oldcomppad, which holds the value of PL_comppad for the *current* sub, not for its caller. So the new field had to be called something else. One side effect of this is that an existing bug - which causes too much to be popped off the savestack when dieing while leaving a sub scope - is now more noticeable, since PL_curpad and SAVEt_CLEARSV are now out of sync: formerly, the unwinding of the save stack restored PL_curpad in lockstep. The fix for this will come later in this branch, when the whole issue of context stack popping order and reentrancy is addressed; for now, a TODO test has been added.
* [perl #126480] pipe() doesn't need the assertionsTony Cook2015-11-241-2/+0
| | | | | | GvIOn() already performs the checks and produces a nice error message, and similar functions, such as open() and socket(), don't have assertions on this condition.
* pp_sys.c: silence g++ compiler warningDavid Mitchell2015-10-281-2/+10
| | | | The warning is harmless but annoying
* partial PL_statbuf removalDaniel Dragan2015-10-081-3/+7
| | | | | | | | | | | | | | | | Perl_nextargv has to have access to the Stat_t that is written to inside S_openn_cleanup or else run/switches.t, io/argv.t, io/inplace.t, and io/iprefix.t will fail. Removing the uses of PL_statbuf that are using PL_statbuf due to historical reason, and not using PL_statbuf to pass data between different funcs/different callstacks. This patch makes it easier to remove PL_statbuf in the future since the number uses of it has been reduced. -in Perl_apply move SETERRNO before tot--; so the branch can be combined with other "tot--;" branches by CC optmizer -combine 2 Perl_croak(aTHX_ "Illegal suidscript"); statements in S_validate_suid to make code look simpler, drop my_perl arg for space efficiency on threads of rarely executed code
* fix up EXTEND() callersDavid Mitchell2015-10-021-1/+7
| | | | | | | | | | | | | | | | | | | | | | The previous commit made it clear that the N argument to EXTEND() is supposed to be signed, in particular SSize_t, and now typically triggers compiler warnings where this isn't the case. This commit fixes the various places in core that passed the wrong sort of N to EXTEND(). The fixes are in three broad categories. First, where sensible, I've changed the relevant var to be SSize_t. Second, where its expected that N could never be large enough to wrap, I've just added an assert and a cast. Finally, I've added extra code to detect whether the cast could wrap/truncate, and if so set N to -1, which will trigger a panic in stack_grow(). This also fixes [perl #125937] 'x' operator on list causes segfault with possible stack corruption
* amigaos4: use #ifdef/ifndef __amigaos4__ when feasibleAndy Broad2015-09-161-3/+3
|
* amigaos4: move the amigaos exec code under amigaos4Andy Broad2015-09-161-16/+1
| | | | | | | | | | | | | | | | | Largely reimplements 839a9f02, 54fa14d7, e8432c63, 40262ff4. The upside is that now doio.c and pp_sys.c have much less AmigaOS specific ifdefs. As a downside, the exec code is now forked (pun only partially accidental.) The earlier story regarding fork+exec, that the AmigaOS creating thread doesn't terminate but instead continues running is both true and false. The more detailed story is that the user-observable behaviour is as with POSIX/UNIX. The thread that created the new "task" (to use the AmigaOS terms) does hang around -- but all it does is to wait for the new task to terminate, and more importantly, it holds on to the resources like filehandles. If the task were to immediately terminate, the resources would be reclaimed by the kernel.
* amigaos4: fork child handlingAndy Broad2015-09-051-1/+1
|
* amigaos4: use amigaos glue for exec(), system(), waitpid()Andy Broad2015-09-051-4/+52
|
* amigaos4: save and restore stdio handles around execAndy Broad2015-09-051-0/+15
|
* Various pods: Add C<> around many typed-as-is thingsKarl Williamson2015-09-031-3/+3
| | | | Removes 'the' in front of parameter names in some instances.
* Explicitly use and check for FD_CLOEXEC.Jarkko Hietaniemi2015-08-261-11/+13
| | | | | | | | This may break places which have the FD_CLOEXEC functionality but do not have the FD_CLOEXEC define. In any case, using a boolean for the F_SETFD flag is icky. Using an explicit 1 is also dubious.
* [perl #125760] deprecate sys(read|write)(), send(), recv() on :utf8Tony Cook2015-08-171-0/+8
|
* Convert pp_sys to use the time64 public interface.Jarkko Hietaniemi2015-07-221-3/+2
|
* [perl #125373] set $! in chdir() if env not set, clarify docsTony Cook2015-07-071-0/+1
|
* [perl #125305] handle chdir to closed handle correctlyTony Cook2015-06-291-0/+10
|