summaryrefslogtreecommitdiff
path: root/sv.c
Commit message (Collapse)AuthorAgeFilesLines
* clarify apidoc for Perl_sv_get_backrefsDavid Mitchell2015-05-181-8/+7
|
* [perl #124127] fix cloning arrays with unused elementsTony Cook2015-04-161-1/+1
| | | | | | | | ce0d59fd changed arrays to use NULL instead of &PL_sv_undef for unused elements, unfortunately it missed updating sv_dup_common()'s initialization of unused elements, leaving them as &PL_sv_undef. This resulted in modification of read only value errors at runtime.
* Revert "Don’t call save_re_context"David Mitchell2015-03-301-0/+2
| | | | | | This reverts commit d28a9254e445aee7212523d9a7ff62ae0a743fec. Turns out we need save_re_context() after all
* 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.
* Change some locale manipulation macros in prep for APIKarl Williamson2015-03-191-2/+3
| | | | | | | | | | This changes the way some of the current internal-only macros are named and used in order to simplify things and minimize what gets exposed as part of the API. Although these have not been listed as publicly available, it costs essentially nothing to keep the old names around in case someone was illegally using them.
* don't test non-null argsDavid Mitchell2015-03-111-3/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | For lots of core functions: if a function parameter has been declared NN in embed.fnc, don't test for nullness at the start of the function, i.e. eliminate code like if (!foo) ... On debugging builds the test is redundant, as the PERL_ARGS_ASSERT_FOO at the start of the function will already have croaked. On optimised builds, it will skip the check (and so be slightly faster), but if actually passed a null arg, will now crash with a null-deref SEGV rather than doing whatever the check used to do (e.g. croak, or silently return and let the caller's code logic to go awry). But hopefully this should never happen as such instances will already have been detected on debugging builds. It also has the advantage of shutting up recent clangs which spew forth lots of stuff like: sv.c:6308:10: warning: nonnull parameter 'bigstr' will evaluate to 'true' on first encounter [-Wpointer-bool-conversion] if (!bigstr) The only exception was in dump.c, where rather than skipping the null test, I instead changed the function def in embed.fnc to allow a null arg, on the basis that dump functions are often used for debugging (where pointers may unexpectedly become NULL) and it's better there to display that this item is null than to SEGV. See the p5p thread starting at 20150224112829.GG28599@iabyn.com.
* sprinkle NOTREACHED and FALLTHROUGHDavid Mitchell2015-03-051-3/+11
| | | | | | | | | | | | | | | | | | | | | | | | Coverity complains bitterly about many switch statements in lots of files. Many of these are of the form: case FOO: ... goto baz; case BAR: .... and something as smart as Coverity shouldn't really be complaining about a missing 'break' when the last statement of the previous branch is an unconditional goto/return/continue. But I've shoved in a bunch of 'NOTREACHED' to hopefully shut it up. Missing 'FALLTHROUGH' comments were more reasonable, and I've added them where appropriate. The only confusing one was cx_dup(), where the various CXt_LOOP_ branches all fell through to the next one, and it took a while to figure out that those weren't bugs.
* [perl #123849] sv.c: Fix sv_clear -Do outputFather Chrysostomos2015-03-011-5/+7
| | | | | | We try to print ‘sv_clear clearing PL_stashcache for '%"SVf"'’, but the sv here is a hash, and we can’t do SvPV on it. We need the hash’s name. This has been this way since 103f5a36127.
* init a var in sv_clear() to keep Coverity happy.David Mitchell2015-02-261-1/+2
| | | | | | | | | | | When a new hash is found to iterate over, the old value of hash_index (if any) is temporarily saved (in the new hash), then restored after the hash has been iterated over. This means that the first hash encountered causes the random initial value of hash_index to be saved and then restored. This is perfectly harmless, but makes Coverity unhappy. Since other such tools might also in future detect such dabbling with uninitialised values, its simplest (but unnecessary) to initialise this var to zero.
* Add \b{sb}Karl Williamson2015-02-191-0/+1
|
* Add qr/\b{wb}/Karl Williamson2015-02-191-0/+1
|
* Remove obsolete macros/tables for \XKarl Williamson2015-02-191-2/+0
| | | | | A previous commit changed how \X is implemented, and now we don't need these anymore.
* Add qr/\b{gcb}/Karl Williamson2015-02-191-0/+1
| | | | | | | | | | | A function implements seeing if the space between any two characters is a grapheme cluster break. Afer I wrote this, I realized that an array lookup might be a better implementation, but the deadline for v5.22 was too close to change it. I did see that my gcc optimized it down to an array lookup. This makes the implementation of \X go from being complicated to trivial.
* infnan: revert nan payload/signaling changesJarkko Hietaniemi2015-02-111-454/+364
| | | | | | | | | | | | | | | | | | | | | | | | | 4258cf903c752ec19a3aeee9b93020533d923e1a 91e945c051cfcdf499d5b43aa5ac0a5681cdd595 eb254f2672a985ec3c34810f624f36c18fc35fc7 c9a671b17a9c588469bcef958038daaaaf9cc88b 99fcdd4df47515fb0a62a046e622adec0871754d ba511db061a88439acb528a66c780ab574bb4fb0 0d1cf11425608e9be019f27a3a4575bc71c49e6b c2ea8a88f8537d00ba25ec8feb63ef5dc085ef2b b5a6eedc2f49a90089cca896ee20f41e373fb4c9 30419b527d2c5a06cefe2db9183f59e2697c47fc 29b62199cd4c359dfc6b9d690341de40d105ca5f be181dc9d91c84a2fe03912c993c8259fed92641 4de1bcfe1abdaba0a5da394ddea0cc6fd7e36c7b 6e915616c4ccb4f6cc3122c5d395765db96c0a2d b2e3501558a1017eb529be0915c25d31671e7869 bfaa02d55f4ace1571e6fa9e5b47d5e3ac3cecc6 569f27e562618bdddcf4a9fc71612283a73747e9 4f89311dc8de87ddc9a302c6f2d2c844951bbd28 a307a0b0d83c509cc2adaad8cebb44260294bf36 6640aa2c3b93d7ac78e4e86983fe5948b3ca55f2 b74dc0b3c96390d8bf83d8c3ffc0c2c2d1f0a5d3 c3a8e5a5b4bb89a15de642c023dfd5cbc4678938
* [perl #123554] catch a couple of other size overflowsTony Cook2015-02-101-1/+3
| | | | | | Unfortunately, running out of memory in safesysmalloc() and safesysrealloc() doesn't produce a catchable croak(), so remove the test.
* infnan: the nan quiet/signaling bit is not enoughJarkko Hietaniemi2015-02-081-10/+6
|
* infnan: API context jugglingJarkko Hietaniemi2015-02-081-7/+7
|
* infnan: grok_number* setting the infnan NV directlyJarkko Hietaniemi2015-02-081-7/+9
|
* infnan: nan payload output with sprintf %#gJarkko Hietaniemi2015-02-081-20/+90
|
* infnan: space for nan payload outputJarkko Hietaniemi2015-02-081-2/+24
|
* infnan: move S_hextract earlierJarkko Hietaniemi2015-02-081-336/+336
|
* [PATCH] fix PL_nan_u from leaking in every translation object on Win32 VCDaniel Dragan2015-02-041-0/+7
|
* Prefer NV instead of long double.Jarkko Hietaniemi2015-02-041-12/+17
| | | | | | | | | | | | | Background: sprintf aka sv_vcatpvn_flags uses a long double for floating point values whenever has-long-double, not only when use-long-double. The (only?) reason for this is being able to (perlio) printf long doubles from XS, even if no use-long-double. (see ext/XS-APItest/t/printf.t) Instead of casting the long double (explicitly or implicitly), try keeping also an NV in sync, and using it. Could probably use the NV even more, but trying to stay minimal given the impending 5.22.
* Move the endianness defines from sv.c to perl.hJarkko Hietaniemi2015-02-021-32/+3
|
* Remove context param from sv_get_backrefsFather Chrysostomos2015-01-311-1/+1
| | | | | v5.21.7-83-geaab564 added sv_get_backrefs. v5.21.7-90-g8fbcb65 removed the one use of aTHX.
* infnan: if trailing stuff, fail in looks_like_number()Jarkko Hietaniemi2015-01-281-1/+3
|
* infnan: numify warning testing.Jarkko Hietaniemi2015-01-281-1/+1
|
* move functions marked as mathomed in embed.fnc to mathoms.cDaniel Dragan2015-01-271-8/+0
| | | | | | | | | | | | | | | | Ever since commit 075eb5c9b6 mathom functions must be in mathoms.c for their symbols to be skipped in makedef.pl on Win32 Perl. If a function is marked 'b' in embed.fnc, regen.pl does NOT add its prototype to proto.h (it is commented out). Without the proto.h entry, EXTERN_C will be missing and a -DNO_MATHOMS + C++ Win32 Perl build will not link, since the C function will have a mangled name and the symbol will not be found for creating the perl linking library. Also add EXTERN_C to Win32CORE, the init_Win32CORE symbol is special cased for exporting in makedef.pl. Perl_is_utf8_char_buf was marked as 'b' in commit 3cedd9d930 Perl_sv_copypv was marked as 'b' in commit 4bac9ae47b
* avoid C labels in column 0David Mitchell2015-01-211-4/+4
| | | | | | | | | Generally the guideline is to outdent C labels (e.g. 'foo:') 2 columns from the surrounding code. If the label starts at column zero, then it means that diffs, such as those generated by git, display the label rather than the function name at the head of a diff block: which makes diffs harder to peruse.
* Make numifying "nanblah" warn, just like "345blah" does.Jarkko Hietaniemi2015-01-201-0/+2
|
* infnan: sprintf width and left-align.Jarkko Hietaniemi2015-01-201-5/+24
|
* [perl #123554] avoid a crash from SvGROW(MEM_SIZE_MAX)Tony Cook2015-01-191-2/+5
|
* sv.c: Fix cloning of interp variableKarl Williamson2015-01-131-3/+5
| | | | | | | | This should have been cloned by sv_dup_inc. I don't know why it didn't fail outside of Win32, but fail there it did, spectacularly, but only when I temporarily change some C code to force execution of the affected code, which only gets executed for problematic locales, which may very well not exist on most machines.
* clone PL_cv_has_eval and PL_savebeginDavid Mitchell2014-12-311-0/+3
| | | | | | These two boolean vars weren't being cloned in new threads, and in debugging builds were getting set to 0xab, which -fsanitize=undefined regarded as no suitable value for a boolean.
* sv_vcatpvfn_flags() avoid array bounds errDavid Mitchell2014-12-311-3/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | clang -fsanitize=undefined is being a bit too clever for its own good here. The code looks something like U8 vhex[VHEX_SIZE]; ... v = vhex + ...; if (v < vend) ... The code itself is safe, but ASan detects if you've added a value greater than the buffer size to vhex and whines. I've changed it so that the conditional comes first and is done in such a way that arbitrary values can't be added to vhex. To reproduce: printf "%.1000a\n", 1; gives sv.c:12327:34: runtime error: index 1000 out of bounds for type 'U8 [17]'
* fix more -IV_MIN negationsDavid Mitchell2014-12-311-0/+4
| | | | | | | | | Doing uv = -iv is undefined behaviour if iv happens to be IV_MIN. This occurs in several places in the perl sources. These ones were found by visual code inspection rather than using -fsanitize=undefined, but I've added extra tests so that -fsanitize could find them now.
* fix -IV_MIN negationsDavid Mitchell2014-12-311-4/+6
| | | | | | | | | | | Doing uv = -iv is undefined behaviour if iv happens to be IV_MIN. This occurs in several places in the perl sources. Found by -fsanitize=undefined. Here's a typical message: sv.c:2864:7: runtime error: negation of -9223372036854775808 cannot be represented in type 'IV' (aka 'long'); cast to an unsigned type to negate this value to itself
* Don't raise 'poorly supported' locale warning unnecessarilyKarl Williamson2014-12-291-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Commit 8c6180a91de91a1194f427fc639694f43a903a78 added a warning message for when Perl determines that the program's underlying locale just switched into is poorly supported. At the time it was thought that this would be an extremely rare occurrence. However, a bug in HP-UX - B.11.00/64 causes this message to be raised for the "C" locale. A workaround was done that silenced those. However, before it got fixed, this message would occur gobs of times executing the test suite. It was raised even if the script is not locale-aware, so that the underlying locale was completely irrelevant. There is a good prospect that someone using an older Asian locale as their default would get this message inappropriately, even if they don't use locales, or switch to a supported one before using them. This commit causes the message to be raised only if it actually is relevant. When not in the scope of 'use locale', the message is stored, not raised. Upon the first locale-dependent operation within a bad locale, the saved message is raised, and the storage cleared. I was able to do this without adding extra branching to the main-line non-locale execution code. This was done by adding regnodes which get jumped to by switch statements, and refactoring some existing C tests so they exclude non-locale right off the bat. These changes would have been necessary for another locale warning that I previously agreed to implement, and which is coming a few commits from now. I do not know of any way to add tests in the test suite for this. It is in fact rare for modern locales to have these issues. The way I tested this was to temporarily change the C code so that all locales are viewed as defective, and manually note that the warnings came out where expected, and only where expected. I chose not to try to output this warning on any POSIX functions called. I believe that all that are affected are deprecated or scheduled to be deprecated anyway. And POSIX is closer to the hardware of the machine. For convenience, I also don't output the message for some zero-length pattern matches. If something is going to be matched, the message will likely very soon be raised anyway.
* add cast to make c++ happyYves Orton2014-12-251-1/+1
|
* Rework sv_get_backrefs() so it is simpler, and C++ compliantYves Orton2014-12-251-12/+9
| | | | | | We unroll hv_backreferences_p() in sv_get_backrefs() so the logic is simpler, (we dont need a **SV for this function), and (hopefully) make it C++ compliant at the same time.
* Revert "sv.c: Add cast to make C++ happy"Yves Orton2014-12-251-1/+1
| | | | | | This reverts commit d49cfb746d789072c374f2403d477feb8017ce89. Better patch coming.
* sv.c: Add cast to make C++ happyFather Chrysostomos2014-12-241-1/+1
|
* add new API function sv_get_backrefs()Yves Orton2014-12-251-0/+43
| | | | | | | | | | | This encapsulates the logic to extract the backrefs from a weak-referent. Since sv_get_backrefs() can be used for a similar purposes as hv_backreferences_p() we no longer need to export the later, and therefore this patch also reverts ad2f46a793b4ade67d45ac0086ae62f6756c2752. See perl #123473 for related discussion, and https://github.com/Sereal/Sereal/issues/73 for a practical example of why this API is required.
* Don’t do string overloading for printf int formatsFather Chrysostomos2014-12-101-0/+2
| | | | See <20141130160250.GC31019@pjcj.net>. Commit 354b74ae6f broke this.
* sv.c: Note that sv_2num does not do get-magicFather Chrysostomos2014-12-101-1/+2
|
* sv.c: Remove reference to bogus SvNUM macroFather Chrysostomos2014-12-101-2/+1
| | | | There has never been such a macro.
* Change OP_SIBLING to OpSIBLINGFather Chrysostomos2014-12-071-5/+5
| | | | | | | | | to match the existing convention (OpREFCNT, OpSLAB). Dave Mitchell asked me to wait until after his multideref work was merged. Unfortunately, there are now CPAN modules using OP_SIBLING.
* Add OP_MULTIDEREFDavid Mitchell2014-12-071-12/+214
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This op is an optimisation for any series of one or more array or hash lookups and dereferences, where the key/index is a simple constant or package/lexical variable. If the first-level lookup is of a simple array/hash variable or scalar ref, then that is included in the op too. So all of the following are replaced with a single op: $h{foo} $a[$i] $a[5][$k][$i] $r->{$k} local $a[0][$i] exists $a[$i]{$k} delete $h{foo} while these aren't: $a[0] already handled by OP_AELEMFAST $a[$x+1] not a simple index and these are partially replaced: (expr)->[0]{$k} the bit following (expr) is replaced $h{foo}[$x+1][0] the first and third lookups are each done with a multideref op, while the $x+1 expression and middle lookup are done by existing add, aelem etc ops. Up until now, aggregate dereferencing has been very heavyweight in ops; for example, $r->[0]{$x} is compiled as: gv[*r] s rv2sv sKM/DREFAV,1 rv2av[t2] sKR/1 const[IV 0] s aelem sKM/DREFHV,2 rv2hv sKR/1 gvsv[*x] s helem vK/2 When executing this, in addition to the actual calls to av_fetch() and hv_fetch(), there is a lot of overhead of pushing SVs on and off the stack, and calling lots of little pp() functions from the runops loop (each with its potential indirect branch miss). The multideref op avoids that by running all the code in a loop in a switch statement. It makes use of the new UNOP_AUX type to hold an array of typedef union { PADOFFSET pad_offset; SV *sv; IV iv; UV uv; } UNOP_AUX_item; In something like $a[7][$i]{foo}, the GVs or pad offsets for @a and $i are stored as items in the array, along with a pointer to a const SV holding 'foo', and the UV 7 is stored directly. Along with this, some UVs are used to store a sequence of actions (several actions are squeezed into a single UV). Then the main body of pp_multideref is a big while loop round a switch, which reads actions and values from the AUX array. The two big branches in the switch are ones that are affectively unrolled (/DREFAV, rv2av, aelem) and (/DREFHV, rv2hv, helem) triplets. The other branches are various entry points that handle retrieving the different types of initial value; for example 'my %h; $h{foo}' needs to get %h from the pad, while '(expr)->{foo}' needs to pop expr off the stack. Note that there is a slight complication with /DEREF; in the example above of $r->[0]{$x}, the aelem op is actually aelem sKM/DREFHV,2 which means that the aelem, after having retrieved a (possibly undef) value from the array, is responsible for autovivifying it into a hash, ready for the next op. Similarly, the rv2sv that retrieves $r from the typeglob is responsible for autovivifying it into an AV. This action of doing the next op's work for it complicates matters somewhat. Within pp_multideref, the autovivification action is instead included as the first step of the current action. In terms of benchmarking with Porting/bench.pl, a simple lexical $a[$i][$j] shows a reduction of approx 40% in numbers of instructions executed, while $r->[0][0][0] uses 54% fewer. The speed-up for hash accesses is relatively more modest, since the actual hash lookup (i.e. hv_fetch()) is more expensive than an array lookup. A lexical $h{foo} uses 10% fewer, while $r->{foo}{bar}{baz} uses 34% fewer instructions. Overall, bench.pl --tests='/expr::(array|hash)/' ... gives: PRE POST ------ ------ Ir 100.00 145.00 Dr 100.00 165.30 Dw 100.00 175.74 COND 100.00 132.02 IND 100.00 171.11 COND_m 100.00 127.65 IND_m 100.00 203.90 with cache misses unchanged at 100%. In general, the more lookups done, the bigger the proportionate saving.
* cleanup logic in S_sv_uncowDaniel Dragan2014-12-051-12/+17
| | | | | | | | | | | | | I couldnt understand this code at first glance. Many empty conditional blocks because of page protection ROing which isn't implemented on Win32, caused erratic stepping in my debugger with CC optimizations *off*. -read COWREFCNT only once -save COWREFCNT to an auto for debugger visual inspection -don't check len twice -don't write sv_buf_to_rw() twice No change in behavior is expected.
* [perl #40565] Fix localisation in pseudo-forkFather Chrysostomos2014-12-031-3/+7
| | | | | | | | Several SAVEt_* types were giving the SVs the wrong reference counts in ss_dup, causing child process to lose SVs too soon. See <https://rt.perl.org/Ticket/Display.html?id=40565#txn-1180404> and <https://rt.perl.org/Ticket/Display.html?id=40565#txn-1277127>.