summaryrefslogtreecommitdiff
path: root/inline.h
Commit message (Collapse)AuthorAgeFilesLines
* Replace common Emacs file-local variables with dir-localsDagfinn Ilmari Mannsåker2015-03-221-6/+0
| | | | | | | | | | | | | | | | An empty cpan/.dir-locals.el stops Emacs using the core defaults for code imported from CPAN. Committer's work: To keep t/porting/cmp_version.t and t/porting/utils.t happy, $VERSION needed to be incremented in many files, including throughout dist/PathTools. perldelta entry for module updates. Add two Emacs control files to MANIFEST; re-sort MANIFEST. For: RT #124119.
* [perl #123202] speed up scalar //g against tainted stringsTony Cook2015-02-261-0/+24
|
* Account for string eval when const-izing sub(){$x}Father Chrysostomos2014-11-131-0/+35
| | | | | If we have a string eval in the same scope as the variable, it is potentially in value context.
* char * pv can never be null in S_is_safe_syscallDaniel Dragan2014-11-051-1/+1
| | | | | embed.fnc marks arg pv as NN, and PERL_ARGS_ASSERT_IS_SAFE_SYSCALL contains assert(pv). Remove the test and branch for efficiency.
* Remove most uses of PADMYFather Chrysostomos2014-09-241-12/+0
| | | | SVs_PADMY is now 0, and SvPADMY means !SvPADTMP.
* Stop setting PADMY; renumber PADSTALEFather Chrysostomos2014-09-241-2/+2
| | | | | | | | | | | | | | | | | | | | The PADMY flag was originally used on values stored in pads as a way to mark those slots ase being in use already during pad allocation. That changed for the most part all the way back in bbce6d6978 (perl5.003_09), but vestiges still remained, because some ops used PADMY for their targets. I removed the last one yesterday in 14d91147. So the PADMY flag now serves no purpose. At run time, the sole purpose of PADMY is to determine the meaning of the flag bit shared by PADTMP and PADSTALE. If PADMY is set, the flag means the latter. Instead of that more complicated check, we can just renumber PADSTALE to use the PADMY bit and assume that anything not PADTMP is PADMY. This commit changes the flags and does just enough to get tests passing (except Peek.t). fixup for padmy flag renumbering
* For lexical subs, reify CvGV from CvSTASH and CvNAME_HEKFather Chrysostomos2014-09-151-0/+8
| | | | | From now on, the presence of a name hek implies a GV. Any access to CvGV will cause that implicit GV to be reified.
* Try simpler usage for file-level GCC_DIAG_RESTORE.Jarkko Hietaniemi2014-06-211-2/+2
|
* GCC_DIAG_IGNORE/RESTORE whine in non-gcc if at file level.Jarkko Hietaniemi2014-06-201-0/+4
|
* GCC_DIAG_IGNORE needs to end with semicolon (inline.h).Jarkko Hietaniemi2014-06-181-1/+1
| | | | | | | Furthermore, make the GCC_DIAG_IGNORE and _RESTORE to be dNOOPs, so that they can be at any level of the code, including global, even when the compiler is not gcc (or lookalike). If they are just empty, ";" will be left at the call site.
* __clang__ seems to be thing, but leave also __clang.Jarkko Hietaniemi2014-06-181-7/+2
| | | | This fixes the GCC_DIAG_IGNORE() + GCC_DIAG_RESTORE with clang.
* Some low-hanging -Wunreachable-code fruits.Jarkko Hietaniemi2014-06-151-0/+27
| | | | | | | | | | | | | | | | | | | | | | | | | | - 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?)
* perlapi: Refactor placements, headings of some functionsKarl Williamson2014-06-051-0/+2
| | | | | | | | | | | | | | 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
* Move some deprecated utf8-handling functions to mathomsKarl Williamson2014-05-311-19/+3
| | | | | This entailed creating new internal functions for some of them to call so that the functionality can be retained during the deprecation period.
* Create isUTF8_CHAR() macro and use itKarl Williamson2014-05-311-16/+12
| | | | | | | | | | | | | | | | | | This macro will inline the code to determine if a character is well-formed UTF-8 for code points below a certain value, falling back to a slower function for larger ones. On ASCII platforms, it will inline for well-beyond all legal Unicode code points. On EBCDIC, it currently does it for code points up to 0x3FFF. This could be increased, but our porting tests do the regen every time to make sure everything is ok, and making it larger slows that down. This is worked around on ASCII by normally commenting out the code that generates this info, but including in utf8.h a version that did get generated. This is static information and won't change. (This could be done for EBCDIC too, but I chose not to at this time as each code page has a different macro generated, and it gets ugly getting all of them in utf8.h) Using this macro allowed for simplification of several functions in utf8.c
* utf8.c: Move a static function to inline.hKarl Williamson2014-05-311-0/+31
| | | | | This is in preparation for it being called from outside utf8.c. It is renamed to have a leading underscore to emphasize its private nature
* Revert bootstrapping to non-ASCII platformsKarl Williamson2014-05-311-47/+0
| | | | | | | | | | | | | | | | | | | This effectively reverts commit 3ded5eb052cdc3f861ec0c0ff85348086d653be0. That commit created a scheme to bootstrap Perl onto a non-ASCII platform, by adding the allowing a Configure option that caused the compiled code to bypass a number of normal macro definitions and use slower, generic ones, sufficient to get miniperl to compile on the target architecture. One would then use miniperl to run a few scripts that would re-order certain header files, Using this one could then recompile all of perl, and once that was done, use it to recompile to use the normal fast macros. This worked, but was a cumbersome process. We now have the infrastructure, since commit 6ff677df5d6fe0f52ca0b6736f8b5a46ac402943, to cross compile on an ASCII platform to EBCDIC, the likely only non-ASCII character set to ever be used. So the new infrastructure will be used in future commits.
* Wrap various pod uses of NUL with C<>Karl Williamson2014-05-301-1/+1
| | | | | | This makes the uses of this consistent in our pods. Also changed one use of the word 'buffer' into 'string', the latter being more appropriate.
* [perl #121112] only warn if newline is the last non-NUL characterTony Cook2014-05-281-0/+32
|
* [perl #120670] make perl headers C++11 compatibleTony Cook2014-01-161-1/+1
|
* Use separate macros for byte vs uv UnicodeKarl Williamson2013-09-101-1/+1
| | | | | | | This removes a macro not yet even in a development release, and splits its calls into two classes: those where the input is a byte; and those where it can be any unsigned integer. The byte implementation avoids a function call on EBCDIC platforms.
* [perl #117265] correctly handle overloaded stringsTony Cook2013-09-091-6/+5
|
* handy.h: Allow bootstrapping to non-ASCII platformKarl Williamson2013-08-291-0/+47
| | | | | | | | | | | | | This adds a bunch of macros and moves things around to support conditional compilation when Configure is called with -DBOOTSTRAP_CHARSET. Doing so causes the usual macros that are table-driven to not be used, since the table may not be valid when bringing Perl up for the first time on a non-ASCII platform. This allows it to compile using the platform's native C library ctype functions, which should work enough to compile miniperl, and allow the table to be changed to be valid. Then Configure can be re-run to not bootstrap, and normal compilation can proceed
* Remove unnecessary temp variable in converting to UTF-8Karl Williamson2013-08-291-6/+4
| | | | These areas of code included a temporary that is unnecessary.
* Extract common code to an inline functionKarl Williamson2013-08-291-2/+20
| | | | | This fairly short paradigm is repeated in several places; a later commit will improve it.
* inline.h: Avoid redundant ckWARN callFather Chrysostomos2013-08-281-3/+1
| | | | | ckWARN calls Perl_ckwarn. So does Perl_ck_warner. So there is no need to use both.
* [perl #117265] safesyscalls: check embedded nul in syscall argsTony Cook2013-08-261-0/+50
| | | | | | | | | | | | | | | | Check for the nul char in pathnames and string arguments to syscalls, return undef and set errno to ENOENT. Added to the io warnings category syscalls. Strings with embedded \0 chars were prev. ignored in the syscall but kept in perl. The hidden payloads in these invalid string args may cause unnoticed security problems, as they are hard to detect, ignored by the syscalls but kept around in perl PVs. Allow an ending \0 though, as several modules add a \0 to such strings without adjusting the length. This is based on a change originally by Reini Urban, but pretty much all of the code has been replaced.
* Stop pos() from being confused by changing utf8nessFather Chrysostomos2013-08-251-1/+22
| | | | | | | | | | | | | | | | | | | | | | | The value of pos() is stored as a byte offset. If it is stored on a tied variable or a reference (or glob), then the stringification could change, resulting in pos() now pointing to a different character off- set or pointing to the middle of a character: $ ./perl -Ilib -le '$x = bless [], chr 256; pos $x=1; bless $x, a; print pos $x' 2 $ ./perl -Ilib -le '$x = bless [], chr 256; pos $x=1; bless $x, "\x{1000}"; print pos $x' Malformed UTF-8 character (unexpected end of string) in match position at -e line 1. 0 So pos() should be stored as a character offset. The regular expression engine expects byte offsets always, so allow it to store bytes when possible (a pure non-magical string) but use char- acters otherwise. This does result in more complexity than I should like, but the alter- native (always storing a character offset) would slow down regular expressions, which is a big no-no.
* Use SSize_t for arraysFather Chrysostomos2013-08-251-1/+1
| | | | | | | | | | Make the array interface 64-bit safe by using SSize_t instead of I32 for array indices. This is based on a patch by Chip Salzenberg. This completes what the previous commit began when it changed av_extend.
* Revert "[perl #117855] Store CopFILEGV in a pad under ithreads"Father Chrysostomos2013-08-091-15/+0
| | | | | | | | | | | | This reverts commit c82ecf346. It turn out to be faulty, because a location shared betweens threads (the cop) was holding a reference count on a pad entry in a particu- lar thread. So when you free the cop, how do you know where to do SvREFCNT_dec? In reverting c82ecf346, this commit still preserves the bug fix from 1311cfc0a7b, but shifts it around.
* [perl #117855] Store CopFILEGV in a pad under ithreadsFather Chrysostomos2013-08-051-0/+15
| | | | | | | | | | | | | | | | This saves having to allocate a separate string buffer for every cop (control op; every statement has one). Under non-threaded builds, every cop has a pointer to the GV for that source file, namely *{"_<filename"}. Under threaded builds, the name of the GV used to be stored instead. Now we store an offset into the per-interpreter PL_filegvpad, which points to the GV. This makes no significant speed difference, but it reduces mem- ory usage.
* Revert "Remove the non-inline function S_croak_memory_wrap from inline.h."Tony Cook2013-07-241-0/+16
| | | | | | | | | This reverts commit 43387ee1abcd83c3c7586b7f7aa86e838d239aac. Which reverted parts of f019c49e380f764c1ead36fe3602184804292711, but that reversion may no longer be necessary. See [perl #116989]
* S_strip_spaces doesn't need to be seen out of corePeter Martini2013-07-021-0/+2
|
* Remove spaces from a (copy of) a proto when used. The logic that uses ↵Peter Martini2013-06-251-0/+28
| | | | prototypes assumes spaces were already gone, which may not be true if they were added via XS / set_prototype.
* Branch prediction hint for SvREFCNT_decSteffen Mueller2013-06-111-2/+2
| | | | | | | | | When decrementing the refcount on an SV, we have to branch on whether or not we've reached a refcount of 0. But a quick instrumentation shows that in virtually any program small or large, the number of decrements without freeing greatly outweighs the number of decrements that cause a free. Therefore, it's a net win to suggest to the compiler to emit a branch prediction hint to go into the just-decrement branch.
* Remove the non-inline function S_croak_memory_wrap from inline.h.Andy Dougherty2013-03-281-16/+0
| | | | | | | | | | | | | | | | | | | | This appears to resolve these three related tickets: [perl #116989] S_croak_memory_wrap breaks gcc warning flags detection [perl #117319] Can't include perl.h without linking to libperl [perl #117331] Time::HiRes::clock_gettime not implemented on Linux (regression?) This patch changes S_croak_memory_wrap from a static (but not inline) function into an ordinary exported function Perl_croak_memory_wrap. This has the advantage of allowing programs (particuarly probes, such as in cflags.SH and Time::HiRes) to include perl.h without linking against libperl. Since it is not a static function defined within each compilation unit, the optimizer can no longer remove it when it's not needed or inline it as needed. This likely negates some of the savings that motivated the original commit 380f764c1ead36fe3602184804292711. However, calling the simpler function Perl_croak_memory_wrap() still does take less set-up than the previous version, so it may still be a slight win. Specific cross-platform measurements are welcome.
* (UN)LIKELY branch prediction hints in a few strategic placesSteffen Mueller2013-03-061-3/+3
| | | | | | | | This adds branch prediction hints to a few strategic places such as growing stack or strings, some exception handling, and a few hot functions such as sv_upgrade. This is not exhaustive by any means.
* Inline av_top_index()Karl Williamson2013-02-081-0/+11
| | | | | This function is just an assert and a macro call. Avoid the function call overhead by making it inline.
* Create deprecated fncs to replace to-be-removed macrosKarl Williamson2013-01-121-0/+21
| | | | | | | | | | | These macros should not be used as they are prone to misuse. There are no occurrences of them in CPAN. The single use of either of them in core has recently been removed (commit 8d40577bdbdfa85ed3293f84bf26a313b1b92f55), because it was a misuse. Instead code should use isIDFIRST_lazy_if or isWORDCHAR_lazy_if (isALNUM_lazy_if is also available, but can be confused with the Posix alnum, which it doesn't mean).
* silence some non-clang warningsDavid Mitchell2012-12-041-0/+4
| | | | | | | | | | | | | ccde85316a0db149f30359ebfdf031ef602b0344 added some #pragma clang ... lines to shut up clang. This caused gcc to give voluminous 'unknown pragma "clang"' output. Sigh. Hopefully now fixed, although it all seems very cumbersome.
* silence some clang warningsDavid Mitchell2012-12-041-0/+3
| | | | | | | | principally, proto.h was sometimes being included twice - once before a fn decl, and once after - giving rise to a 'decl after def' warning. Also, S_croak_memory_wrap was declared static in every source file, but not used in some. So selectively disable the unused-function warning.
* add SvREFCNT_dec_NN()David Mitchell2012-12-041-0/+10
| | | | | | | | | Like SvREFCNT_dec(), but skips the not null check, making code potentially smaller and faster. Also as proof of concept, updates the SvREFCNT_dec's in scope.c where it's obvious the value can't be NULL. There are still 500+ uses in the perl core that need evaluating!
* make SvREFCNT_dec() more efficientDavid Mitchell2012-12-041-6/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Historically, SvREFCNT_dec was just #define SvREFCNT_dec(sv) sv_free((SV*)(sv)) then in 5.10.0, for GCC, the macro was partially inlined, avoiding a function call for the refcnt > 1 case. Recently, the macro was turned into an inline function, providing the function-call avoidance to other platforms too. However, the macro/inline-function is quite big, and appears over 500 times in the core source. Its action is logically equivalent to: if (sv) { if (SvREFCNT(sv) > 1) SvREFCNT(sv)--; else if (SvREFCNT == 1) { // normal case SvREFCNT(sv)--; sv_free2(sv); } else { // exceptional case sv_free(sv); } } Where sv_free2() handles the "normal" quick cases, while sv_free() handles the odd cases (e,g. a ref count already at 0 during global destruction). This means we have to plant code that potentially calls two different subs, over 500 times. This commit changes SvREFCNT_dec and sv_free2() to look like: PERL_STATIC_INLINE void S_SvREFCNT_dec(pTHX_ SV *sv) { if (sv) { U32 rc = SvREFCNT(sv); if (rc > 1) SvREFCNT(sv) = rc - 1; else Perl_sv_free2(aTHX_ sv, rc); } } Perl_sv_free2(pTHX_ SV *const sv, const U32 rc) { if (rc == 1) { SvREFCNT(sv) = 0; ... do sv_clear, del_SV etc ... return } /* handle exceptional rc == 0 */ ... } So for the normal cases (rc > 1, rc == 1) there is the same amount of testing and function calls, but the second test has been moved inside the sv_free2() function. This makes the perl executable about 10-15K smaller, and apparently a bit faster (modulo the fact that most benchmarks are just measuring noise). The refcount is passed as a second arg to sv_free2(), as on platforms that pass the first few args in registers, it saves reading sv->sv_refcnt again.
* Allow regexp-to-pvlv assignmentFather Chrysostomos2012-10-301-0/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | Since the xpvlv and regexp structs conflict, we have to find somewhere else to put the regexp struct. I was going to sneak it in SvPVX, allocating a buffer large enough to fit the regexp struct followed by the string, and have SvPVX - sizeof(regexp) point to the struct. But that would make all regexp flag-checking macros fatter, and those are used in hot code. So I came up with another method. Regexp stringification is not speed-critical. So we can move the regexp stringification out of re->sv_u and put it in the regexp struct. Then the regexp struct itself can be pointed to by re->sv_u. So SVt_REGEXPs will have re->sv_any and re->sv_u pointing to the same spot. PVLVs can then have sv->sv_any point to the xpvlv body as usual, but have sv->sv_u point to a regexp struct. All regexp member access can go through sv_u instead of sv_any, which will be no slower than before. Regular expressions will no longer be SvPOK, so we give sv_2pv spec- ial logic for regexps. We don’t need to make the regexp struct larger, as SvLEN is currently always 0 iff mother_re is set. So we can replace the SvLEN field with the pv. SvFAKE is never used without SvPOK or SvSCREAM also set. So we can use that to identify regexps.
* optimize memory wrap croaks, often used in MEM_WRAP_CHECKDaniel Dragan2012-10-251-0/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Most perls are built with PERL_MALLOC_WRAP. This causes MEM_WRAP_CHECK macro to perform some checks on the requested allocation size in macro Newx. The checks are performed at the caller, not in the callee (for me on Win32 perl the callee in Newx is Perl_safesysmalloc) of Newx. If the check fails a "Perl_croak_nocontext("%s",PL_memory_wrap)" is done. In x86 machine code, "if(bad_alloc) Perl_croak_nocontext("%s",PL_memory_wrap); will be written as "cond jmp ahead ~15 bytes", "push const pointer", "push const pointer", "call const pointer". For each Newx where the allocation amount was not a constant (constant folding would remove the croak memory wrap branch compleatly), the branch takes 15-19 bytes depending on x86 compiler. There are about 80 Newx'es in the interp (win32 dynamic linking perl) that do the memory wrap check and have a "Perl_croak_nocontext("%s",PL_memory_wrap)" in them after all optimizations by the compiler. This patch reduces the memory wrap branch from 15-19 to 5 bytes on x86. Since croak_memory_wrap is a static and a noreturn, a compiler with IPO may optimize the whole branch to "cond jmp 32 bits relative" at each callsite. A less optimal complier may do "cond jmp 8 bits relative (jump past the "call S_croak_memory_wrap" instruction), then "call S_croak_memory_wrap". Both ways are better than the current situation. The reason why croak_memory_wrap is a static and not an export is that the compiler has more opportunity to optimize/reduce the impact of the memory wrap branch at the call site if the target is in the same image rather than in a different image, which would require using the platform specific dynamic linking mechanism/export table/etc, which often requires a new stack frame per ABI of the platform. If a dynamic linked XS module does not use S_croak_memory_wrap it will be removed from the image by the C compiler. If it is included in the XS image, it is a very small block of code and a 3 byte string litteral. A CPU cache line is typically 32 or 64 bytes and a memory read is typically 16. Cutting the instructions by 10 to 16 bytes out of "hot code" (10 of the ~80 call sites are pp_*) is a worthy goal. In a few places the memory wrap croak is used explictly, not from a MEM_WRAP_CHECK, this patch converts those to use the static. If PERL_MALLOC_WRAP is undef, there are still a couple uses of croak memory wrap, so do not keep S_croak_memory_wrap in a ifdef PERL_MALLOC_WRAP. Also see http://www.nntp.perl.org/group/perl.perl5.porters/2012/10/msg194383.html and [perl #115456].
* Oops; fix threaded buildFather Chrysostomos2012-10-011-1/+1
|
* Stop substr lvalues from being confused by changing UTF8nessFather Chrysostomos2012-10-011-0/+12
|
* Unify CvDEPTH for formats and subsFather Chrysostomos2012-09-111-3/+1
| | | | | | | | As Dave Mitchell pointed out, while putting the CvDEPTH field for for- mats in the SvCUR slot might save memory for formats, it slows down sub calls because CvDEPTH is used on subs in very hot code paths. Checking the SvTYPE to determine which field to use should not be necessary.
* Move S_CvDEPTHp from cv.h to inline.h; shrink macrosFather Chrysostomos2012-08-211-0/+11
| | | | | This allows us to use assert() inside S_CvDEPTHp, so we no longer need GCC and non-GCC variants of the macro that calls it.
* Static inline functions for SvPADTMP and SvPADSTALEFather Chrysostomos2012-08-211-0/+38
| | | | | This allows non-GCC compilers to have assertions and avoids repeating the macros.