summaryrefslogtreecommitdiff
path: root/pp.c
Commit message (Collapse)AuthorAgeFilesLines
* Perl 6 -> Raku where appropriateH.Merijn Brand2020-05-301-2/+2
|
* set magic on $lex for $lex = (index(...) == -1) and make it an lvalueTony Cook2020-05-271-4/+9
| | | | | | related to #17737 and fixes #17739 re-work of my original patch that only pushes the final result
* fix utf8 length magic handling for scalar reverseTony Cook2020-05-271-0/+1
| | | | fixes #17737
* Perl_unipmlemented_op: Fix comment and unnecessary PL_op derefDagfinn Ilmari Mannsåker2020-03-291-3/+3
| | | | | | | | | The comment referred to pp_addr, but the correct field is op_ppaddr, and the function itself is called Perl_unimplemented_op, not PL_unimplemented_op. When indexing PL_op_name[], use the local op_type variable that we just got from PL_op->op_type instead of going via PL_op again.
* chained comparisonsZefram2020-03-121-0/+24
|
* pp_i_modulo(): remove workaround for ancient glibc bugDagfinn Ilmari Mannsåker2020-02-051-25/+0
| | | | | | | | | Old glibc versions had a buggy modulo implementation for 64 bit integers on 32-bit architectures. This was fixed in glibc 2.3, released in 2002 (the version check in the code is overly cautious). Removing the alternate PP function support is left for the next commit, in case we need to resurrect it in future.
* pp_crypt(): reindent CPP directivesDavid Mitchell2020-02-041-9/+10
| | | | | | They were all over the place. Whitespace-only.
* pp_crypt(): remove ancient glibc bug workaroundDavid Mitchell2020-02-031-6/+0
| | | | | | | | | | | GH #16552 In 2003 a fix was added to workaround a bug in glibc's crypt_r() implementation (which involved tweaking a private undocumented field within the crypt_data struct). This bug has long since been fixed, but the workaround remained. This commit finally removes that workaround. See also v5.27.11-33-ge9c9cf5759.
* Improve performance of grok_bin_oct_hex()Karl Williamson2020-01-131-1/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit uses a variety of techniques for speeding this up. It is now faster than blead, and has less maintenance cost than before. Most of the checks that the current character isn't NUL are unnecssary. The logic works on that character, even if, for some reason, you can't trust the input length. A special test is added to not output the illegal character message if that character is a NUL. This is simply for backcompat. And a switch statement is used to unroll the loop for the leading digits in the number. This should handle most common cases. Beyond these, and one has to start worrying about overflow. So this version has removed that worrying from the common cases. Extra conditionals are avoided for large numbers by extracting the portability warning message code into a separate static function called from two different places. Simplifying this logic led me to see that if it overflowed, it must be non-portable, so another conditional could be removed. Other conditionals were removed at the expense of adding parameters to the function. This function isn't public, but is called from the grok_hex, et. al. macros. grok_hex knows, for example, that it is looking for an 'x' prefix and not a 'b'. Previously the code had a conditional to determine that. Similarly in pp.c, we look for the prefix. Having found it we can start the parse after the prefix, and tell this function not to look for it. Previously, this work was duplicated. The previous changes had left this function slower than blead. That is in part due to the fact that the loop doesn't go through that many iterations per function call, and the gcc compiler managed to optimize away the conditionals in XDIGIT_VALUE in the call of it from the loop. (The other call in this function did have the conditionals.) Thanks to Sergey Aleynikov for his help on this
* Add the `isa` operatorPaul "LeoNerd" Evans2019-12-091-0/+12
| | | | | | | | | | | | | | | | | | Adds a new infix operator named `isa`, with the semantics that $x isa SomeClass is true if and only if `$x` is a blessed object reference that is either `SomeClass` directly, or includes the class somewhere in its @ISA hierarchy. It is false without warning or error for non-references or non-blessed references. This operator respects `->isa` method overloading, and is intended to replace boilerplate code such as use Scalar::Util 'blessed'; blessed($x) and $x->isa("SomeClass")
* remove CONSERVATIVE and LIBERALTomasz Konojacki2019-10-301-2/+1
| | | | | | | | | | | | These constants were undocumented and don't do anything useful. Saving a few kilobytes of memory doesn't justify the complexity caused by adding a new build flag. All platforms except 64-bit Windows were using LIBERAL. It's not clear why win64 was using -DCONSERVATIVE, but removing it doesn't break anything. [gh #17232]
* use PTR2nat() instead of casting pointers to unsigned longTomasz Konojacki2019-10-301-1/+1
| | | | | | | Casting a pointer to unsigned long will result in truncation when sizeof(void*) > sizeof(unsigned long) [gh #17232]
* fix some signed/unsigned warningsDavid Mitchell2019-10-031-2/+2
| | | | | Note that utf8_distance returns IV, while STR_LEN is an unsigned value of varying sizes.
* Signatures: change param count from IV to UVDavid Mitchell2019-09-231-2/+2
| | | | | | For some reason I was storing the counts of sub signature parameters and optional parameters as signed ints. Since these can never be negative, change them to UV instead.
* OP_ARGCHECK: use custom aux structDavid Mitchell2019-09-231-5/+5
| | | | | | | | | | | | This op is of class OP_UNOP_AUX, Ops of this class have an op_aux pointer which typically points to a variable-length malloced array of IVs, UVs, etc. However in the specific case of OP_ARGCHECK the data stored in the aux struct is fixed. So this commit casts the aux pointer to a struct containing the relevant fields (number of parameters etc), rather than referring to them as aux[0], aux[1] etc. This makes the code more readable. Should be no functional changes.
* Remove remaining assignments to SvCUR and SvLEN in coreDagfinn Ilmari Mannsåker2019-05-281-1/+1
| | | | Also make the macros non-lvalues under PERL_CORE
* Remove undefined behavior from IV shiftingKarl Williamson2019-05-241-1/+20
| | | | | | It is undefined behavior to shift a negative integer to the left. This commit avoids that by treating the value as unsigned, then casting back to integer for return.
* pp.c: Add two UNLIKELY()sKarl Williamson2019-05-241-2/+2
| | | | It should be uncommon to shift beyond a full word
* Create fcn for lossless conversion of NV to IVKarl Williamson2019-05-241-16/+4
| | | | | | | | Essentially the same code was being used in three places, and had undefined C behavior for some inputs. This consolidates the code into one inline function, and rewrites it to avoid undefined behavior.
* pp.c: White-space onlyKarl Williamson2019-05-241-8/+10
| | | | | Fix indentation of this routine to current standards, in preparation for making changes to it, and add a blank line for readability
* pp.c: Silence some MS VC warningsKarl Williamson2019-04-121-7/+8
| | | | These are bogus warnings.
* pp.c: Use safer utf8_hopKarl Williamson2019-03-191-2/+2
|
* pp.c, pp_sys.c: Use DO_UTF8 instead of its expansionKarl Williamson2019-03-191-1/+1
| | | | We have a macro to hide the details of this; use it
* PATCH: [perl #133876] Write out of boundsKarl Williamson2019-03-081-3/+6
| | | | | | | | | | This was caused by a lapse on my part about the inputs to this function that grows memory. I was thinking the trailing NUL was included, but it's not. This patch adds space for that to all calls of sv_utf8_upgrade_flags_grow() in the file. But it occurs to me that maybe the function itself should just add one instead of having the caller do it. If you think so, let me know.
* (perl #133778) adjust MARK if we extend the stack in pp_repeatTony Cook2019-02-211-1/+2
| | | | for a list repeat in scalar/void context
* add dVAR's for PERL_GLOBAL_STRUCT_PRIVATE buildsDavid Mitchell2019-02-191-0/+1
| | | | | | The perl build option -DPERL_GLOBAL_STRUCT_PRIVATE had bit-rotted due to lack of smoking. The main fix is to just add 'dVAR;' to any functions which have a pTHX arg. It's a NOOP on normal builds.
* pp.c: White-space onlyKarl Williamson2019-02-051-4/+5
| | | | Indent block newly formed by the previous commit.
* pp.c: Add handling for Turkish locales for uc() etcKarl Williamson2019-02-051-56/+283
| | | | | | | | The functions lc() uc() ucfirst() lcfirst() and fc() are hereby expanded to handle the differences required in Turkish locales. No Turkish locales are recognized until later in this series of commits.
* pp.c: Clarify commentKarl Williamson2019-02-051-1/+1
|
* Eliminate AMGf_set flagDavid Mitchell2019-02-051-15/+15
| | | | | | | | | | | | | | | | | | | | | I added this flag a few years ago when I revamped the overload macros tryAMAGICbin() etc. It allowed two different classes of macros to share the same functions (Perl_try_amagic_un/Perl_try_amagic_bin) by indicating what type of action is required. However, the last few commits have made those two functions able to robustly always determine whether its an assign-type action ($x op= $y or $lex = $x op $x) or a plain set-result-on-stack operation ($x op $y). So eliminate this flag. Note that this makes the ops which have the AMGf_set flag hard-coded infinitesimally slower, since Perl_try_amagic_bin no longer skips the checks for assign-ness. But compared with the overhead of having already called the overload method, this is is trivial. On the plus side, it makes the code smaller and easier to understand.
* pp.c: White-space onlyKarl Williamson2019-02-041-4/+4
| | | | Indent block newly formed in the previous commit
* pp.c: Avoid use of unsafe functionKarl Williamson2019-02-041-1/+6
| | | | | | The function is unsafe because it doesn't check for running off the end of the buffer if presented with illegal UTF-8. The only remaining use now is from mathoms.c.
* pp.c: Add branch prediction hintKarl Williamson2019-02-041-1/+1
| | | | This conditional is very rarely true
* pp.c: Don't assume worst case memory needsKarl Williamson2019-02-041-15/+40
| | | | | | | | | | | | | | | | Since 5.28, there has been a function that will calculate the expansion of a string when converted into UTF-8, using per-word operations. This means it runs 8 times faster than doing this count previously would have taken. I've come to believe it is better to calculate how much memory we need than to overallocate based on worst-case scenarios. This is because in very large strings, over allocating can lead to unnecessary inefficient processing. This commit changes several instances in pp.c where a string needs to be converted to UTF-8 to not assume the worst case, but instead calculate what's needed using the faster function.
* pp.c: Don't use function call for easy copyKarl Williamson2019-02-041-7/+6
| | | | | | | | | | Like the previous commit, this code is adding the UTF-8 for a Greek character to a string. It previously used Copy, but this character is representable as two bytes in both ASCII and EBCDIC UTF-8, the only character sets that Perl will ever supports, so we can use the specialized code that is used most everywhere else for two byte UTF-8 characters, avoiding the function overhead, and having to treat this character as particularly special.
* pp.c: Don't use function call for easy copyKarl Williamson2019-02-041-4/+2
| | | | | | | | | This code is adding the UTF-8 for a Greek character to a string. It previously used Copy, but this character is representable as two bytes in both ASCII and EBCDIC UTF-8, the only character sets that Perl will ever supports, so we can use the specialized code that is used most everywhere else for two byte UTF-8 characters, avoiding the function overhead, and having to treat this character as particularly special.
* pp.c: pp_fc(): SimplifyKarl Williamson2019-02-041-15/+2
| | | | | | The function being called does everything that the code being eliminated here did. We just pass the function the final destination instead of a temporary.
* pp.c: White-space, comments onlyKarl Williamson2019-02-041-61/+65
|
* pp.c: Reorder clause order in an 'if'Karl Williamson2019-02-041-1/+3
| | | | | This makes the test most likely to fail be first, and adding an UNLIKELY() to it, thus saving a conditional in most instances.
* pp.c: Use faster method to convert to UTF-8Karl Williamson2019-02-041-3/+5
| | | | | | There is a special inline function that's used when converting a single byte to UTF-8, that is faster than the more general one used prior to this commit.
* pp.c: Add missing assertKarl Williamson2019-02-041-0/+1
| | | | The comments say there is an assert, but it wasn't there.
* optimize IV -> UV conversionsTomasz Konojacki2018-11-211-9/+9
| | | | | | | | | | | | | | | | | | | | | | | This commit replaces all instances of code that looks like this: uv = (iv == IV_MIN) ? (UV)iv : (UV)(-iv) with simpler and more optimal: uv = -(UV)iv While -iv indeed results in an undefined behaviour when iv == IV_MIN, -(UV)iv is perfectly well defined and does the right thing. C standard guarantees that the result of (UV)iv (for negative iv) is equal to iv + UV_MAX + 1 (see 6.3.1.3, paragraph 2 in C11). It also guarantees that the result of -uv is UV_MAX - uv + 1 (6.2.5, paragraph 9). That means that the result of -(UV)iv is UV_MAX - (iv + UV_MAX + 1) + 1 which is equal to -iv for *all* possible negative values of iv. [perl #133677]
* Don't localise array / hash slice ref assignmentDavid Mitchell2018-11-051-4/+6
| | | | | | | | | | | | | | | | | | RT #133538 The experimental ref assignment aliasing feature, when applied to array or hash slices, was treating the slice as if it was always localized; e.g. \(@a[3,5,7]) = \(....); was being interpreted as local \(@a[3,5,7]) = \(....); The fix is simple: check for the OPpLVAL_INTRO flag actually being set on the op, rather than unconditionally localising the array/hash elements.
* pp_divide: use modulo instead of multiplicationTomasz Konojacki2018-11-021-1/+4
| | | | | | | | | | | | On most architectures with hardware integer division (like x86 or aarch64), division instruction returns both the remainder and the quotient. It means that performing modulo operation immediately after division using the same operands is 100% free. Essentially this commit changes "div" and "mul" into a single "div" instruction, which results in minor speed up. [perl #133511]
* fix build failure with recent glibcDavid Mitchell2018-05-111-1/+5
| | | | | | | | | | | RT #133184 pp_crypt() directly manipulates a field inside 'struct crypt_data' to work around a bug in an ancient glibc version from circa 2002. New glibc releases don't have this field so perl fails to compile. Make the hack conditional on glibc version. Stolen from a patch to the Fedora 28 distribution.
* Revert "Unweaken refs in in-place reverse"David Mitchell2018-04-261-7/+0
| | | | | | | | | | | This reverts commit 5bad3c4f3a4515aaa622eecdf6f5a84fcaff7ed9. See RT #132142. For now, re-introduce the bug that fails to convert weak refs to strong refs when sorting in place. This is commit 1 of 2.
* PATCH: [perl #133074] 5.26.1: some coverity fixesMarc-Philip2018-04-081-0/+1
| | | | | | | | we have some coverity code scans here. They have found this uninilialized variable in pp.c and the integer overrun in toke.c. Though it might be possible that these are false positives (no reasonable control path gets there), it's good to mute the scan here to see the real problems easier.
* rmv/de-dup static const char array "strings"Daniel Dragan2018-03-071-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | MSVC due to a bug doesn't merge identicals between .o'es or discard these vars and their contents. MEM_WRAP_CHECK_2 has never been used outside of core according to cpan grep MEM_WRAP_CHECK_2 was removed on the "have PERL_MALLOC_WRAP" branch in commit fabdb6c0879 "pre-likely cleanup" without explination, probably bc it was unused. But MEM_WRAP_CHECK_2 was still left on the "no PERL_MALLOC_WRAP" branch, so remove it from the "no" side for tidyness since it was a mistake to leave it there if it was removed from the "yes" side of the #ifdef. Add MEM_WRAP_CHECK_s API, letter "s" means argument is string or static. This lets us get rid of the "%s" argument passed to Perl_croak_nocontext at a couple call sites since we fully control the next and only argument and its guaranteed to be a string literal. This allows merging of 2 "Out of memory during array extend" c strings by linker now. Also change the 2 op.h messages into macros which become string literals at their call sites instead of "read char * from a global char **" which was going on before. VC 2003 32b perl527.dll section size before .text name DE503 virtual size .rdata name 4B621 virtual size after .text name DE503 virtual size .rdata name 4B5D1 virtual size
* pp_repeat: avoid calling GIMME_V twiceDavid Mitchell2018-03-061-2/+3
| | | | | | | | assign its value to a local var instead. GIMME_V can have a considerable overhead when called in unknown context. I audited the rest of the pp*.c files, but didn't find any similar multiple calls.
* ‘Nonelems’ for pushing sparse array on the stackFather Chrysostomos2018-02-181-0/+2
| | | | | | | | | | | | | | | | | To avoid having to create deferred elements every time a sparse array is pushed on to the stack, store a magic scalar in the array itself, which av_exists and refto recognise as not existing. This means there is only a one-time cost for putting such arrays on the stack. It also means that deferred elements that live long enough don’t start pointing to the wrong array entry if the array gets shifted (or unshifted/spliced) in the mean time. Instead, the scalar is already in the array, so it cannot lose its place. This fix only applies when the array as a whole is pushed on to the stack, but it could be extended in future commits to apply to other places where we currently use deferred elements.