summaryrefslogtreecommitdiff
path: root/mg.c
Commit message (Collapse)AuthorAgeFilesLines
* (perl #127663) safer in-place editingTony Cook2017-09-111-0/+36
| | | | | | | | | | | | Previously in-place editing opened the file then immediately *replaced* the file, so if an error occurs while writing the output, such as running out of space, the content of the original file is lost. This changes in-place editing to write to a work file which is renamed over the original only once the output file is successfully closed. It also fixes an issue with setting setuid/setgid file modes for recursive in-place editing.
* (perl #128263) handle PL_last_in_gv being &PL_sv_undefTony Cook2017-08-311-1/+1
| | | | | | | | | | | | rv2gv will return &PL_sv_undef when it can't get a GV, previously this could cause an assertion failure in mg.c My original fix for this changed each op that deals with GVs for I/O to set PL_last_in_gv to NULL if there was no io object in the GV, but this changes other behaviour as noted by FatherC. Also partly reverts 84ee769f, which unnecessarily did the same for readline(), so now we're consistent.
* add sv_string_from_errnum()Zefram2017-08-191-7/+51
| | | | | | This is a new API function, partly substituting for the my_strerror() that was recently removed from the public API, but also incorporating the decoding work that's done for $!.
* Improve heuristic for UTF-8 detection in "$!"Karl Williamson2017-08-181-5/+17
| | | | | | | | | | | | | | | | | Previously, the stringification of "$!" was considered to be UTF-8 if it had any characters with the high bit set, and everything was syntactically legal UTF-8. This may to correctly guess on short strings where there are only a few non-ASCII bytes. This could happen in languages based on the Latin script where many words don't use non-ASCII. This commit adds a check that the locale is a UTF-8 one. That check is a call to an already-existing subroutine which goes to some lengths to get an accurate answer, and should be essentially completely reliable on modern systems that have nl_langinfo() and/or mbtowc(). See the thread starting at http://nntp.perl.org/group/perl.perl5.porters/245902
* change sv_setsv(sv,NULL) to sv_set_undef(sv)David Mitchell2017-07-271-5/+6
| | | | | | | | | | | | | | There are still a few core occurrences of sv_setsv(sv, NULL); which is equivalent to sv_setsv(sv, &PL_sv_undef); but which can now be done more efficiently with sv_set_undef(sv);
* gv.c, mg.c: fix 32-bit compiler warningsDavid Mitchell2017-06-121-7/+7
| | | | | | | | | mg.c:641:21: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast] UV uv = (UV)mg->mg_obj; It's storing a char-ranged integer value as an SV*. By using SSize_t rather than UV to store the char, it avoids mismatched size warnings.
* Make setting ${^ENCODING} to a defined value fatalDagfinn Ilmari Mannsåker2017-06-071-7/+2
| | | | | | | This has been deprecated since 5.22 and a no-op since 5.26. Remove the now-obsolete t/uni/heavy.t test, which only tested that utf8_heavy.pl didn't fail to load when ${^ENCODING} was set.
* Forbid setting $/ to a reference to a non-postive integerDagfinn Ilmari Mannsåker2017-06-051-7/+4
| | | | | | | | This used to work like setting it to 'undef', but has been deprecated since Perl 5.20. In passing, avoid duplicate duplicate uninitialized warning by reusing the SvIV() result already stored in 'val'.
* Fix inconsistent whitespace in mg.cDagfinn Ilmari Mannsåker2017-06-051-8/+8
| | | | | | | | A handful of assignments are lacking a space on the left-hand side, which is not consistent with the rest of the project style (perlstyle mandates «Space around most operators»). Also, a comment was mis-aligned.
* Define and use symbolic constants for LvFLAGSDagfinn Ilmari Mannsåker2017-06-021-5/+5
|
* vec(): defer lvalue out-of-range croakingDavid Mitchell2017-03-311-1/+4
| | | | | | | | | | | | | | | | | | | | | RT #131083 Recent commits v5.25.10-81-gd69c430 and v5.25.10-82-g67dd6f3 added out-of-range/overflow checks for the offset arg of vec(). However in lvalue context, these croaks now happen before the SVt_PVLV was created, rather than when its set magic was called. This means that something like sub f { $x = $_[0] } f(vec($s, -1, 8)) now croaks even though the out-of-range value never ended up getting used in lvalue context. This commit fixes things by, in pp_vec(), rather than croaking, just set flag bits in LvFLAGS() to indicate that the offset is -Ve / out-of-range. Then in Perl_magic_getvec(), return 0 if these flags are set, and in Perl_magic_setvec() croak with a suitable error.
* Moving variables to their innermost scope.Andy Lester2017-02-181-4/+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.
* toke.c: Fix bugs where UTF-8 is turned on in mid chunkKarl Williamson2017-02-131-0/+8
| | | | | | | | | | | | | | | | | | | | Previous commits have tightened up the checking of UTF-8 for well-formedness in the input program or string eval. This is done in lex_next_chunk and lex_start. But it doesn't handle the case of use utf8; foo because 'foo' is checked while UTF-8 is still off. This solves that problem by noticing when utf8 is turned on, and then rechecking at the next opportunity. See thread beginning at http://nntp.perl.org/group/perl.perl5.porters/242916 This fixes [perl #130675]. A test will be added in a future commit This catches some errors earlier than they used to be and aborts. so some tests in the suite had to be split into multiple parts.
* mg.c: PL_hints is unsignedKarl Williamson2017-02-131-2/+2
| | | | Therefore it's dangerous to presume things fit into an IV.
* Use cBOOL() instead of ? TRUE : FALSEDagfinn Ilmari Mannsåker2017-01-251-1/+1
| | | | Except under cpan/ and dist/
* avoid disabling utf8 pos cache on tainted stringsDavid Mitchell2017-01-211-6/+25
| | | | | | | | | | | | | | | | | | | | | | | | RT #130584 When pos() or similar is used on a utf8 string, perl attaches magic to it that caches a couple of byte<->char offset conversions. This can avoid quadratic behaviour when continually scanning a big chunk of a long string to convert a byte offset to a char offset when pos() is called. v5.17.3-203-g7d1328b added code to invalidate this cache when get magic is called on an SV, since the get magic may change the value of the SV. However, under -T, taint magic gets added to a tainted string, which includes a get method which doesn't actually change the SV's value. So make a special exception to get-magic-cache-invalidation if the only get magic on the string is taint. This stops code like the following going quadratic under -T: $_ = "... long tainted utf8 string ..."; while ( /..../g) { my $p = pos(); # calculating pos() goes quadratic }
* Reformat overlong comment.Abigail2017-01-161-5/+7
| | | | pod/perlhack.pod says to try hard not to exceed 79 columns.
* $/ = \-1 will be fatal in Perl 5.28.Abigail2017-01-161-1/+1
| | | | | | | | | Setting $/ to a reference of a non-positive integer has been deprecated since 5.20, in which it was special cased to act like you had set to $/ to undef. In Perl 5.28, setting $/ to a reference to a non-positive integer will be a fatal error.
* Setting ${^ENCODE} will be fatal by 5.28.Abigail2017-01-161-2/+2
| | | | | Hence, we adapted the warning, to mention the version in which it will become a fatal error.
* add setproctitle() support for DragonFly BSDPeter Avalos2017-01-071-1/+1
| | | | | | RT #130068 (applied untested, as I don't have access to a dragonfly box - DAPM)
* add sv_set_undef() API functionDavid Mitchell2016-11-241-13/+15
| | | | | | | This function is equivalent to sv_setsv(sv, &PL_sv_undef), but more efficient. Also change the obvious places in the core to use the new idiom.
* Change white space to avoid C++ deprecation warningKarl Williamson2016-11-181-3/+3
| | | | | | | | | | | | | | | | | | | | | | 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.
* eliminate SVpbm_VALID flagDavid Mitchell2016-11-121-6/+3
| | | | | | | | This flag is set on an SV to indicate that it has PERL_MAGIC_bm (fast Boyer-Moore) magic attached. Instead just directly check whether it has such magic. This frees up the 0x40000000 bit for anything except AVs and HVs
* eliminate SVpbm_TAIL/SvTAIL_on()/SvTAIL_off()David Mitchell2016-11-121-1/+0
| | | | | | | | | | | | (but keep SvTAIL()) This flag is only set on SVs that have Boyer-Moore magic attached. Such SVs already re-purpose the unused IVX slot of that SV to store BmUSEFUL. This commit repurposes the unused NVX slot to store this boolean value instead. Now that flag bit (0x80000000) is only used with AVs, HVs, RVs and scalar SVs with IOK.
* new feature @{^CAPTURE} (and %{^CAPTURE} and %{^CAPTURE_ALL})Yves Orton2016-11-011-12/+25
| | | | | | | | | @{^CAPTURE} exposes the capture buffers of the last match as an array. So $1 is ${^CAPTURE}[0]. %{^CAPTURE} is the equivalent to %+ (ie named captures) %{^CAPTURE_ALL} is the equivalent to %- (ie all named captures).
* mg.c: use new SvPVCLEAR and constant string friendly macrosYves Orton2016-10-191-6/+6
|
* add some code comments for the users of delimcpy()David Mitchell2016-09-071-0/+2
| | | | | | | | While fixing delimcpy(), I found that it wasn't always clear what its callers did, so I've added some extra code comments. also add a balancing '}' in a comment block to help editors that jump between matching brackets.
* Tainted dirs on VMS when not under DCL.Craig A. Berry2016-09-051-4/+7
| | | | | | | Since 483efd0abe3 the path delimiter is a ':' instead of '|' on VMS when running under a Unix shell. So use that as a guide to whether we should use a colon or a slash to detect relative directories that should be tainted.
* Fix checks for tainted dir in $ENV{PATH}Father Chrysostomos2016-09-031-1/+1
| | | | | | | | | | | | | | | | | | | $ cat > foo #!/usr/bin/perl print "What?!\n" ^D $ chmod +x foo $ ./perl -Ilib -Te '$ENV{PATH}="."; exec "foo"' Insecure directory in $ENV{PATH} while running with -T switch at -e line 1. That is what I expect to see. But: $ ./perl -Ilib -Te '$ENV{PATH}="/\\:."; exec "foo"' What?! Perl is allowing the \ to escape the :, but the \ is not treated as an escape by the system, allowing a relative path in PATH to be consid- ered safe.
* 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.
* Remove mg.c:_get_encodingFather Chrysostomos2016-07-131-6/+0
| | | | Nothing uses it now, and it does nothing.
* Remove PL_(lex_)encoding and all dependent codeFather Chrysostomos2016-07-131-34/+0
|
* Disable ${^ENCODING}Father Chrysostomos2016-07-131-34/+2
| | | | ${^ENCODING} is disabled and tests are modified to account.
* mg.c: move declaration of i closer to its useLukas Mai2016-01-311-1/+1
| | | | | This should avoid the "unused variable 'i'" warning that pops up in some configurations.
* Probe for and expose more fields for SA_SIGINFODagfinn Ilmari Mannsåker2016-01-261-7/+21
| | | | | | | | These are all specified by POSIX/SUSv3, but not all platforms have them, as mentioned in POSIX.pm. We can only test the pid, uid and code fields, since they are the only ones that are defined for a user-sent signal.
* Perl_magic_set(): remove unused var 's'David Mitchell2015-12-011-7/+8
| | | | | | | | This var is (mostly) unused, but is set in a couple of places, hence: mg.c:2657:17: warning: variable ‘s’ set but not used In the one place it is used, declare it in a narrower scope.
* split off the $0 setting so mutex use can be annotatedJarkko Hietaniemi2015-11-231-68/+81
| | | | | | No warnings were emitted since the use of the PL_dollarzero_mutex was correctly bracketed by mutex lock and unlock, but by splitting off the code and annotating it is more likely to stay correct.
* reimplement $^WIN32_SLOPPY_STAT as a magic varDaniel Dragan2015-10-191-0/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The original implementation in commit cba61fe146 was sloppy. It is named like a special var, it is listed as a special var, but it was a regular GV. Since nobody knows this var exists, and full stat is the default (which I disagree with see below). There will be alot more PP and C/XS perl stat() calls (atleast a couple to dozens or low 100s for short lived perl processes) than reads/writes to this global scalar (rounded to 0 R/Ws) in a Win32 perl process. So avoid the 1 usually failing GV package (hash) lookup for each PP/XS/PL C stat by using magic vars and a C bool. This is a perf increase. Use sv_true instead of SvTRUE_NN because this code is extremely rare to execute and the macro has large machine code. I disagree with the default being full stat with since this increases the number of kernel IO calls and ASCII->UTF16 conversions, and there was perf criticism in the original thread that implemented this this http://www.nntp.perl.org/group/perl.perl5.porters/2006/02/msg109917.html but why full stat is default is for another ticket. This patch lessens the overhead of full stat until something else is decided. Change the initial value of the sloppystat setting for miniperl to be true instead of doing it in buildcustomize.pl in PP. Revert part of commit 8ce7a7e8b0 "speed up miniperl require on Win32" to acomplish this. Unlike Unix perl, no object files are shared between mini and full perl, so changing the default is fine on Win32 Perl. If minitest/miniperl really need hard link testing/support, they can explictly turn off sloppy stat and enable full stat with the special var. Changing the stat default from C for miniperl avoids creating the special GV on each miniperl process start as it previously was with the buildcustomize.pl way. Changing stat setting in C and not PP also saves a couple IO calls in win32_stat when opening the first .pl if it isn't -e, and opening buildcustomize.pl in all permutations. The PP code in S_parse_body contains a -f. See ticket for this patch for details. Only CPAN use of this special var is File-Stat-Moose-0.06/lib/File/Stat/Moose.pm#L208 according to cpangrep.
* fix up EXTEND() callersDavid Mitchell2015-10-021-1/+3
| | | | | | | | | | | | | | | | | | | | | | 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: setenv magic should work with __amigaos4__Andy Broad2015-09-051-2/+2
| | | | The code was protected with AMIGAOS which was AmigaOS 3.
* perlapi: Change some 'eg' to 'e.g.'Karl Williamson2015-09-031-2/+2
| | | | To make more standard
* perlapi: Add some S<>Karl Williamson2015-09-031-1/+1
| | | | | so that these constructs appear on a single output line for reader convenience.
* Various pods: Add C<> around many typed-as-is thingsKarl Williamson2015-09-031-13/+13
| | | | Removes 'the' in front of parameter names in some instances.
* perlapi, perlintern: Add L<> links to podKarl Williamson2015-09-031-8/+8
|
* perlapi: Use C<> instead of I<> for parameter names, etcKarl Williamson2015-08-011-1/+1
| | | | | The majority of perlapi uses C<> to specify these things, but a few things used I<> instead. Standardize to C<>.
* Remove PERL_OLD_COPY_ON_WRITEFather Chrysostomos2015-06-291-6/+0
|
* silence some gcc -pendantic warningsDavid Mitchell2015-06-191-1/+1
|
* Revert "Don’t call save_re_context"David Mitchell2015-03-301-0/+1
| | | | | | 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.
* mg.c:Perl_magic_set: don't use 0 as "failed" gid_tHugo van der Sanden2015-03-101-2/+8
| | | | | | | | For [perl #123814] we added checking for grok_* parse failures in magic_set for $), but used 0 as the placeholder result in those cases (since we don't have an effective way to report an error for this). (Gid_t)(-1) is a safer placeholder, since on many systems that'll map to an explicit bad group id.