summaryrefslogtreecommitdiff
path: root/pp_sys.c
Commit message (Collapse)AuthorAgeFilesLines
* Remove or downgrade unnecessary dVAR.Jarkko Hietaniemi2014-06-251-90/+68
| | | | | | | | You need to configure with g++ *and* -Accflags=-DPERL_GLOBAL_STRUCT or -Accflags=-DPERL_GLOBAL_STRUCT_PRIVATE to see any difference. (g++ does not do the "post-annotation" form of "unused".) The version code has some of these issues, reported upstream.
* Revert "/* NOTREACHED */ belongs *before* the unreachable."Jarkko Hietaniemi2014-06-191-2/+1
| | | | | | This reverts commit 148f39b7de6eae9ddd59e0b0aff691d6abea7aca. (Still needs more work, but wanted to see how well this passed with Jenkins.)
* /* NOTREACHED */ belongs *before* the unreachable.Jarkko Hietaniemi2014-06-191-1/+2
| | | | | | Definitely not *after* it. It marks the start of the unreachable, not the first unrechable line. And if they are in that order, it looks better to linebreak after the lint hint.
* Avoid missing return warning in pp_die.Craig A. Berry2014-06-181-0/+1
| | | | | Even though it can't be reached, the absence of a return statement makes the VMS C compiler warn that it's missing.
* Some low-hanging -Wunreachable-code fruits.Jarkko Hietaniemi2014-06-151-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | - after return/croak/die/exit, return/break are pointless (break is not a terminator/separator, it's a goto) - after goto, another goto (!) is pointless - in some cases (usually function ends) introduce explicit NOT_REACHED to make the noreturn nature clearer (do not do this everywhere, though, since that would mean adding NOT_REACHED after every croak) - for the added NOT_REACHED also add /* NOTREACHED */ since NOT_REACHED is for gcc (and VC), while the comment is for linters - declaring variables in switch blocks is just too fragile: it kind of works for narrowing the scope (which is nice), but breaks the moment there are initializations for the variables (the initializations will be skipped since the flow will bypass the start of the block); in some easy cases simply hoist the declarations out of the block and move them earlier Note 1: Since after this patch the core is not yet -Wunreachable-code clean, not enabling that via cflags.SH, one needs to -Accflags=... it. Note 2: At least with the older gcc 4.4.7 there are far too many "unreachable code" warnings, which seem to go away with gcc 4.8, maybe better flow control analysis. Therefore, the warning should eventually be enabled only for modernish gccs (what about clang and Intel cc?)
* Revert "Some low-hanging -Wunreachable-code fruits."Jarkko Hietaniemi2014-06-131-2/+1
| | | | | | | This reverts commit 8c2b19724d117cecfa186d044abdbf766372c679. I don't understand - smoke-me came back happy with three separate reports... oh well, some other time.
* Some low-hanging -Wunreachable-code fruits.Jarkko Hietaniemi2014-06-131-1/+2
| | | | | | | | | | | | | | | | | | - after croak/die/exit (or return), break (or return!) are pointless (break is not a terminator/separator, it's a promise of a jump) - after goto, another goto (!) is pointless - in some cases (usually function ends) introduce explicit NOT_REACHED to make the noreturn nature clearer (do not do this everywhere, though, since that would mean adding NOT_REACHED after every croak) - for the added NOT_REACHED also add /* NOTREACHED */ since NOT_REACHED is for gcc (and VC), while the comment is for linters - declaring variables in switch blocks is just too fragile: it kind of works for narrowing the scope (which is nice), but breaks the moment there are initializations for the variables (they will be skipped!); in some easy cases simply hoist the declarations out of the block and move them earlier There are still a few places left.
* Allow to compile if don't have LC_CTYPE etc definedKarl Williamson2014-06-121-1/+1
| | | | | | | | Commit d6ded95025185cb1ec8ca3ba5879cab881d8b180 introduced the ability to specify individual category parameters to 'use locale'. However in doing so, it causes Perl to not be able to compile on platforms that don't have some or all of those categories defined, such as Android. This commit uses #ifdefs to remedy that.
* Removed NeXT supportBrian Fraser2014-06-111-5/+1
|
* perlapi: Refactor placements, headings of some functionsKarl Williamson2014-06-051-0/+3
| | | | | | | | | | | | | | It is not very user friendly to list functions as "Functions found in file FOO". Better is to group them by purpose, as many were already. I went through and placed the ones that weren't already so grouped into groups. Patches welcome if you have a better classification. I changed the headings of some so that the important disctinction was the first word so that they are placed in the file more appropriately. And a couple of ones that I had created myself, I came up with a name that I think is better than the original
* Add parameters to "use locale"Karl Williamson2014-06-051-1/+1
| | | | | | | This commit allows one to specify to enable locale-awareness for only a specified subset of the locale categories. Thus you could make a section of code LC_MESSAGES aware, with no locale-awareness for the other categories.
* refactor pp_tiedDaniel Dragan2014-06-041-6/+8
| | | | | | | | | | | remove some redundant code regarding stack handling -removed: -4/-8 pop on SP +4/+8 push on SP PUTBACK function's machine code size dropped from 0xC5 to 0xBD bytes on VC2003
* Unify the "fall-through" lint annotation.Jarkko Hietaniemi2014-05-291-2/+2
| | | | | | | Used by linters (static checkers), and also good for human readers. Even though "FALL THROUGH" seems to be the most common, e.g BSD lint manual only knows "FALLTHROUGH" (or "FALLTHRU").
* Followup to 316ebaf (aka perl #121894).Jarkko Hietaniemi2014-05-291-0/+1
| | | | | | | | Adding asserts to more spots. Fix for Coverity perl5 CIDs 28962,28968,28969: CID ...: Dereference after null check (FORWARD_NULL) var_deref_op: Dereferencing null pointer p->q
* fcntl receiving -1 from fileno, fcntl failing.Jarkko Hietaniemi2014-05-291-44/+122
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (Also very few spots of negative numgroups for getgroups(), and fgetc() return, but almost all checking is for fcntl.) (merged fix for perl #121743 and perl #121745: hopefully picked up all the fixes-to-fixes from the ticket...) Fix for Coverity perl5 CIDs 28990..29003,29005..29011,29013, 45354,45363,49926: Argument cannot be negative (NEGATIVE_RETURNS) fd is passed to a parameter that cannot be negative. and CIDs 29004, 29012: Argument cannot be negative (NEGATIVE_RETURNS) num_groups is passed to a parameter that cannot be negative and because of CIDs 29005 and 29006 also CID 28924. In the first set of issues a fd is retrieved from PerlIO_fileno, and that is then used in places like fstat(), fchown(), dup(), etc., without checking whether the fd is valid (>=0). In the second set of issues a potentially negative number is potentially passed to getgroups(). The CIDs 29005 and 29006 were a bit messy: fixing them needed also resolving CID 28924 where the return value of fstat() was ignored, and for completeness adding two croak calls (with perldiag updates): a bit of a waste since it's suidperl code.
* Uninitialized tmbuf.Jarkko Hietaniemi2014-05-291-14/+13
| | | | | | | | | | | | | | | Fix for Coverity perl5 CID 29088: Uninitialized scalar variable (UNINIT) uninit_use: Using uninitialized value tmbuf.tm_year. There is a code path that can lead to accessing uninitialized tmbuf: when the too-small or too-large time inputs to gmtime/localtime happen. - make it so that the tm_year is used only on successful code path: pp_sys.c - add the gmtime failed / localtime failed errors to perldiag: pod/perldiag.pod - test those errors: t/op/time.t
* pp_sys.c: Optimize out a call to PerlIO_get_cntNiels Thykier2014-05-281-2/+3
| | | | | | | If PerlIO_getc returns EOF, PerlIO_get_cnt is not going to return a positive value all of a sudden. Signed-off-by: Niels Thykier <niels@thykier.net>
* [perl #121112] only warn if newline is the last non-NUL characterTony Cook2014-05-281-9/+10
|
* Change core uses of Perl_do_openn() to Perl_do_open6() or Perl_do_open_raw().Nicholas Clark2014-03-191-4/+3
| | | | | | Calls to Perl_do_openn() all have at least 2 unused arguments which clutter the code and hinder easy understanding. Perl_do_open6() and Perl_do_open_raw() each only do one job, so don't have the dead arguments.
* tbuffer_t no longer exists on VMS.Craig A. Berry2014-03-021-7/+0
| | | | | | | | | | | | | | | | | | It was replaced by the standard tms struct in v7.0, released in 1995. Explicit support for pre-7.0 was removed in 32995a382d65b for Perl 5.16, but I missed the tbuffer_t bit, which tripped up Nicholas in 25983af42cdcf2dc, because he asked for: struct tbuffer_t which via macro expansion became: struct struct tms which failed to compile. So remove code that's unnecessarily different on VMS, leaving only a tbuffer_t compatibility macro with a more appropriate comment so it will hopefully be less likely to get used in new code.
* pp_tms should use a local struct tms, instead of PL_timesbuf.Nicholas Clark2014-03-011-10/+13
| | | | | | | | | | PL_timesbuf is effectively a vestige of Perl 1, and doesn't actually need to be an interpreter variable. It will be removed early in v5.21.x, but it's a good idea to refactor the code not to use it before then. A local struct tms will be on the C stack, which will be in the CPU's L1 cache, whereas the relevant part of the interpreter struct may well not be in the CPU cache at all. Therefore this change might reduce cache pressure fractionally. A local variable access should also be simpler machine code on most CPU architectures.
* Change av_len calls to av_tindex for clarityKarl Williamson2014-02-201-1/+1
| | | | | | av_tindex is a more clearly named synonym for av_len, available starting in v5.18. This changes the core uses to it, including modules in /ext, which are not dual-lifed.
* [perl #118843] work around recv() behaviour on cygwinTony Cook2014-01-151-0/+8
| | | | | | | | | cygwin inherits recv behaviour from the Win32 sockets API which doesn't modify the namebuf or it's associated size when you recv() from a connected socket, handle this the same way Win32 does by zeroing the length if it's the same as before calling recv(). Also adds some basic socket function tests to the core tests.
* Make getc unset the utf8 flag on its retvalFather Chrysostomos2014-01-121-0/+1
| | | | | | | | The same scalar (the target) is used to return the value each time the same getc operator is called. It was turning on the utf8 flag when necessary, but not turning it off. (I suspect recv has the same bug. I haven’t confirmed.)
* pp_sys.c:S_doform: remove redundant null checkFather Chrysostomos2014-01-111-1/+1
| | | | | | This static function is called from exactly two places that both die aforehand if cv is null. Further, the cv parameter is already marked as non-null.
* perlapi: Consistent spaces after dotsFather Chrysostomos2013-12-291-1/+1
| | | | plus some typo fixes. I probably changed some things in perlintern, too.
* pp_sys.c remove null checks and localityDaniel Dragan2013-12-241-6/+7
| | | | | pp_enterwrite, EXTEND contains a funccall, dont save gv around it pp_ioctl, move optype to first place used to reduce liveness
* pp_sys.c: More null check removalFather Chrysostomos2013-12-241-7/+1
| | | | | Thanks again to Daniel Dragan for pointing out candidates in <rt-4.0.18-29603-1387872667-551.120842-15-0@perl.org> (ticket #120842).
* pp_sys.c: Remove redundant null checksFather Chrysostomos2013-12-231-26/+14
| | | | | | | | | | | | | Nulls only get pushed on to the stack when pp_coreargs uses them to represent missing optional arguments. Ops that take * prototypes will have had their arguments passed through rv2gv first, so they should always be GVs. GvIOn never returns null. When given a GV argument, it creates a new IO entry and returns that. When given any other argument it croaks. Thank you to Daniel Dragan for providing a list of candidate pp functions in <rt-4.0.18-29609-1387862001-129.120842-15-0@perl.org> (ticket #120842).
* pp_sys.c: Remove null checks from pp_sockpairFather Chrysostomos2013-12-231-15/+5
| | | | | | | | | | There is actually no way for nulls to reach this code. Nulls on the stack only happen with pp_coreargs, and only with ops that have optional arguments, of which socketpair is not one. GvIOn uses gv_add_by_type, which adds a new IO if there is not already one, so it will never return null if the GV is not null.
* refactor pp_socket, pp_socketpair, pp_bindDaniel Dragan2013-12-231-8/+10
| | | | | | | | | | pp_socket: remove unreachable made by commit 9c9f25b8ce pp_socketpair: increase locality, now gv2/io2 is tested before gv1 is processed, *v1 vars become non-const to avoid large WS changes in opening new scope pp_bind: move op_type's init so it isn't saved by CC across a func call
* [perl #118651] don't overwrite $! in readdir()Tony Cook2013-12-181-1/+1
| | | | | | POSIX expects readdir() to leave errno alone when it reaches end of directory without an error so that case can be detected. Do the same in perl.
* silence -Wformat-nonliteral compiler warningsDavid Mitchell2013-11-281-1/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Due to the security risks associated with user-supplied formats being passed to C-level printf() style functions (eg %n), gcc has a -Wformat-nonliteral warning that complains whenever such a function is passed a non-literal format string. This commit silences all such warnings in core and ext/. The main changes are 1) the 'f' (format) flag in embed.fnc is now handled slightly more cleverly. Rather than just applying to functions whose last arg is '...' (and where the format arg is assumed to be the previous arg), it can now handle non-'...' functions: arg checking is disabled, but format checking is sill done: it works by assuming that an arg called 'fmt', 'pat' or 'f' is the format string (and dies if fails to find exactly one such arg). 2) with the new embed.fnc functionally, more functions have been marked with the 'f' flag. When such a function passes its fmt arg onto an inner printf-like function, we simply disable the warning for that call using GCC_DIAG_IGNORE(-Wformat-nonliteral), since we know that the caller must have already checked it. 3) In quite a few places the format string isn't literal, but it *is* constant (e.g. PL_warn_uninit_sv). For those cases, again disable the warning. 4) In pp_formline(), a particular format was was one of several different literal strings depending on circumstances. Rather than assigning this string to a temporary variable, incorporate the ?: branches directly in the function call arg. gcc is clever enough to decide the arg is then always literal.
* Revert "make perl core quiet under -Wfloat-equal"David Mitchell2013-11-161-1/+1
| | | | | | | | | | | A suggested way of avoiding the the warning on nv1 != nv2 by replacing it with (nv1 < nv2 || nv1 > nv2), has too many issues with NaN. [perl #120538]. I haven't found any other way of selectively disabling the warning, so for now I'm just reverting the whole commit. This reverts commit c279c4550ce59702722d0921739b1a1b92701b0d.
* make perl core quiet under -Wfloat-equalDavid Mitchell2013-11-091-1/+1
| | | | | | | | | | | | | | | | | | | | The gcc option -Wfloat-equal warns when two floating-point numbers are directly compared for equality or inequality, the idea being that this is usually a logic error, and that you should be checking that the values are instead very near to each other. perl on the other hand has lots of reasons to do a direct comparison. Add two macros, NV_eq_nowarn(a,b) and NV_eq_nowarn(a,b) that do the same as (a == b) and (a != b), but without the warnings. They achieve this by instead doing (a < b) || ( a > b). Under gcc at least, this is optimised into the same code as the direct comparison. The are three places that I've left untouched, because they are handling NaNs, and that gets a bit tricky. In particular (nv != nv) is a test for a NaN, and replacing it with (< || >) creates signalling NaNs (whereas == and != create quiet NaNs)
* Fix &CORE::exit/die under vmsish "hushed"Father Chrysostomos2013-11-081-1/+2
| | | | | | | This commit makes them behave like exit and die without the ampersand by moving the OPpHUSH_VMSISH hint from exit/die op to the current statement (nextstate/cop) instead. &CORE:: subs intentionally lack a nextstate op, so they can see the hints in the caller’s nextstate op.
* Call select's 4th arg's magicEric Brine2013-10-181-1/+2
| | | | | | [perl #120102] CORE::select ignoring timeout var's magic Patch by Eric, with tested added by davem.
* Removed the ifdefs for INCOMPLETE_TAINTSBrian Fraser2013-09-211-10/+0
| | | | | This was added in 5.5/5.6 as a backwards-compatibility measure when taint was extended to happen in more places.
* Removed HAS_SOCKET__bad_code_maybeBrian Fraser2013-09-211-14/+0
|
* Remove PERL_MICRO where it is conditionally used with other definesDavid Leadbeater2013-09-101-7/+7
| | | | | There are several cases where PERL_MICRO is used combined with defines not set in uconfig.h, the additional test isn't needed.
* Fix PerlIO_get_cnt and friendsLeon Timmermans2013-09-071-1/+1
| | | | These functions worked with ints instead of SSize_t,
* [perl #119311] Keep CvDEPTH and savestack in syncFather Chrysostomos2013-08-271-1/+1
| | | | | | | | | | | | | | | | when unwinding sub and format calls. The comments in the added test file explain what the problem is. The fix is to call LEAVE_SCOPE in POPSUB and POPFORMAT (to free their lexicals) before lowering CvDEPTH. If the context has already been popped via cxstack_ix--, then LEAVE_SCOPE could overwrite it, so accessing cx after LEAVE_SCOPE is unsafe. Hence the changes to POPSUB and POPFORMAT are a bit involved. Some callers of POPSUB do a temporary cxstack_ix++ first so they can access cx afterwards. Two cases needed to be changed to work that way.
* Stop system select from croaking on read-only COW ""Father Chrysostomos2013-08-111-3/+4
| | | | | | | | | | | System select (select with 4 arguments) does not allow any of its first three arguments to be read-only unless they are undef or empty strings. It does not work properly for read-only copy-on-write empty strings, because it passes all copy-on-write through sv_force_normal under the expectation that they will shortly be modified. It should not be doing that for read-only empty strings.
* [perl #27010] Make tie work through defelemsFather Chrysostomos2013-07-161-0/+10
| | | | | | | | | When elements of @_ refer to nonexistent hash or array elements, then the magic scalar in $_[0] delegates all set/get actions to the element in represents, vivifying it if needed. tie/tied/untie, however, were not delegating to the element, but were tying the the magical ‘deferred element’ scalar itself.
* pp_sys.c: Use macro instead of reinventing itKarl Williamson2013-07-071-7/+1
| | | | The Strerror macro is defined properly to handle either case here.
* change tied_method to use SVs with precomputed hash valuesRuslan Zakirov2013-06-301-13/+13
|
* Remove ‘bad top format’ errorFather Chrysostomos2013-06-091-2/+1
| | | | | | This is unreachable. It only happens in pp_leavewrite when IoTOP_GV(io) is null, but the code leading up to it makes sure that IoTOP_GV(io) is not null. If it is still null, it jumps past the error with ‘goto forget_top’.
* Stop making assumptions about uids and gids.Brian Fraser2013-06-041-43/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | The code dealt rather inconsistently with uids and gids. Some places assumed that they could be safely stored in UVs, others in IVs, others in ints; All of them should've been using the macros from config.h instead. Similarly, code that created SVs or pushed values into the stack was also making incorrect assumptions -- As a point of reference, only pp_stat did the right thing: #if Uid_t_size > IVSIZE mPUSHn(PL_statcache.st_uid); #else # if Uid_t_sign <= 0 mPUSHi(PL_statcache.st_uid); # else mPUSHu(PL_statcache.st_uid); # endif #endif The other places were potential bugs, and some were even causing warnings in some unusual OSs, like haiku or qnx. This commit ammends the situation by introducing four new macros, SvUID(), sv_setuid(), SvGID(), and sv_setgid(), and using them where needed.
* Provide ntohl, ntohs, htonl and htons no-op macros on big endian systems.Nicholas Clark2013-05-201-10/+0
| | | | | | | | | | | This means that there are always macros or functions for ntohl, ntohs, htonl and htons available, so eliminate use of HAS_NTOHL etc, and unconditionally compile the code that it was protecting. However, as code on CPAN is using these guard macros, define all of them in perl.h (Technically the 4 are not quite no-ops, as they truncate their values to 32 or 16 bits, to be consistent with the implementations for platforms which need re-ordering.)
* [perl #117743] don't warn on $@ = undef; die;Tony Cook2013-04-261-1/+2
| | | | and fix the test that's meant to detect this bug.