summaryrefslogtreecommitdiff
path: root/util.c
Commit message (Collapse)AuthorAgeFilesLines
* Get -Accflags=-DPERL_MEM_LOG compiling againMatthew Horsfall2016-04-051-0/+6
| | | | | | | | It had rotted a bit Well, more than one probably. Move the declarations of the functions Perl_mem_log_alloc etc from handy.h into embed.fnc where whey belong, and where Malloc_t will have already been defined.
* Move the zeroing back before the dladdr() call.Jarkko Hietaniemi2016-03-271-5/+5
|
* [perl #127773: Assertion failure in perl built with Dusecbacktrace]Vladimir Timofeev2016-03-271-9/+10
|
* [perl #127764] Perl with '-Dusecbacktrace' doesn't compile on darwinJarkko Hietaniemi2016-03-221-1/+1
| | | | Fix a thinko in 22ff3130.
* rename and function-ise dtrace macrosDavid Mitchell2016-03-181-0/+78
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit: 1. Renames the various dtrace probe macros into a consistent and self-documenting pattern, e.g. ENTRY_PROBE => PERL_DTRACE_PROBE_ENTRY RETURN_PROBE => PERL_DTRACE_PROBE_RETURN Since they're supposed to be defined only under PERL_CORE, this shouldn't break anything that's not being naughty. 2. Implement the main body of these macros using a real function. They were formerly defined along the lines of if (PERL_SUB_ENTRY_ENABLED()) PERL_SUB_ENTRY(...); The PERL_SUB_ENTRY() part is a macro generated by the dtrace system, which for example on linux expands to a large bunch of assembly directives. Replace the direct macro with a function wrapper, e.g. if (PERL_SUB_ENTRY_ENABLED()) Perl_dtrace_probe_call(aTHX_ cv, TRUE); This reduces to once the number of times the macro is expanded. The new functions also take simpler args and then process the values they need using intermediate temporary vars to avoid huge macro expansions. For example ENTRY_PROBE(CvNAMED(cv) ? HEK_KEY(CvNAME_HEK(cv)) : GvENAME(CvGV(cv)), CopFILE((const COP *)CvSTART(cv)), CopLINE((const COP *)CvSTART(cv)), CopSTASHPV((const COP *)CvSTART(cv))); is now PERL_DTRACE_PROBE_ENTRY(cv); This reduces the executable size by 1K on -O2 -Dusedtrace builds, and by 45K on -DDEBUGGING -Dusedtrace builds.
* amigaos4: better popen() + pclose() implementationAndy Broad2016-03-111-4/+1
| | | | | | | popen(): handle better the case where the popened external might exit before the child process manages to start. pclose(): protect with a semaphore.
* perlapi: Document ninstr() and rninstr()Karl Williamson2016-03-101-3/+40
|
* make building without memcpy work (RT #127619)Lukas Mai2016-03-071-1/+6
|
* util.c: make my_mem*/my_b* prototypes more like the originalsLukas Mai2016-03-071-25/+19
|
* Time::HiRes moved from "cpan" to "dist" in 91ba54Tom Hukins2016-02-091-1/+1
|
* util.c: fix/simplify unused arg logic in my_vsnprintfLukas Mai2016-01-311-3/+2
|
* [perl #126240] avoid leaking memory when setting $ENV{foo} on darwinTony Cook2016-01-061-1/+1
| | | | | | | | | My change in e396210 was incomplete, that change was intended to force use of setenv()/unsetenv() on Darwin, but ended up using putenv() instead, which is a leaky mechanism. Added darwin to the list of many others that work better with setenv()/ unsetenv().
* [perl #123991] report an error if we can't parse the number after -CTony Cook2015-12-071-0/+3
|
* annotate the mutex use of atfork_lock and atfork_unlockJarkko Hietaniemi2015-11-231-0/+18
| | | | | | | | | | | | | | util.c:2729:1: warning: mutex 'PL_perlio_mutex' is still held at the end of function [-Wthread-safety-analysis] } util.c:2729:1: warning: mutex 'PL_op_mutex' is still held at the end of function [-Wthread-safety-analysis] } util.c:2739:5: warning: releasing mutex 'PL_perlio_mutex' that was not held [-Wthread-safety-analysis] MUTEX_UNLOCK(&PL_perlio_mutex); util.c:2744:5: warning: releasing mutex 'PL_op_mutex' that was not held [-Wthread-safety-analysis] OP_REFCNT_UNLOCK;
* clang thread safety annotationsJarkko Hietaniemi2015-11-231-0/+22
| | | | | | | | | | | | http://clang.llvm.org/docs/ThreadSafetyAnalysis.html Static (compile-time) annotations for declaring the multithreaded behavior of functions, variables, and capabilities (like mutexes). Available since about clang 3.5. ./Configure -des -Dusedevel -Dusethreads -Dcc=clang -Accflags='-Wthread-safety' clang -Wthread-safety then checks the validity of the annotations.
* VMS-specific statbuf in Perl_find_script.Craig A. Berry2015-10-151-0/+1
| | | | | | | | In 97466d2cbf895b I added a declaration at function scope, but in some paths that was overridden at an inner scope, leaving the function-level one declared but not used. So lets go back to the original intent of 45a23732c73c8 and have a separate declaration in each block that needs it.
* Revert "Missed one statbuf declaration in 45a23732c73."Craig A. Berry2015-10-151-1/+1
| | | | | | | This reverts commit 97466d2cbf895b35ac41b8bf7c31db955b52d48e. Adding a declaration at function scope causes unused variable warnings when there are paths that redeclare it at an inner scope.
* make /fixed-substr/ much faster.David Mitchell2015-10-131-69/+102
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | TL;DR: on platforms with a libc memchr() implementation which makes good use of underlying hardware support, patterns which include fixed substrings will now often be much faster; for example with glibc on on a recent x86_64 CPU, this: $s = "a" x 1000 . "wxyz"; $s =~ /wxyz/ for 1..30000 is now about 7 times faster. On systems with slow memchr(), e.g. 32-bit ARM Raspberry Pi, there will be a small or little speedup. Conversely, some pathological cases, such as "ab" x 1000 =~ /aa/ will be slower now; up to 3 times slower on the rPi, 1.5x slower on x86_64. In detail: The perl core includes a Boyer-Moore substring matcher, Perl_fbm_instr(), which is used to quickly find a fixed substring within a longer string, where a table of lookups is pre-computed from the substring. As well as being used in index() when the substring is a constant, its main use is in patterns. When the regex engine compiles a pattern, it typically takes note of the two longest fixed substrings within the pattern; for example in /[01]abc\w+de\d+fghij+/ the two longest are "abc" and "fghij". The engine uses Perl_fbm_instr() to scan for these two strings before running the full NFA. This often allows the string to be quickly rejected, or to find a suitable minimum starting point to run the NFA. However, Perl_fbm_instr() was written about 16 years ago and has been virtually untouched since, so it could do with some love. It currently special-cases strings of length 1 and 2, using roll-your-own loops along the lines of while (s < end) { if (*s++ = c1) ... } while strings of length 3+ use the Boyer-Moore algorithm. The big advantage of BM is that in a best-case, where none of the characters from the substring are found in this region of the string, it only has to test every N'th char, where N is length of the substring. For example when searching for wxyz in abcdefghikl..., it just reads and tests d,h,l,.. However these days some platforms have decent memchr() implementations. For example, glibc has assembly-level implementations for i386, x86_64, sparc32/64, powerpc32/64, s390-32/64, arm, m68k and ia64 by the looks of it. These can often be substantially faster than a C-level implementation. This commit makes Perl_fbm_instr() use memchr() where possible. For the length == 1 special case, it just calls memchr() directly rather than using a loop as previously. For the length == 2 special case, it continues to distinguish the cases where the two chars of the substring are the same or differ. For the former it calls memchr() after an initial direct failure, i.e. if (*s != c) { s++; s = memchr(....); ... } For the latter case it does a similar direct test first (to avoid the costly overhead of a call to memchr() when the next char is the one we seek anyway), but in addition, on each failure to find the second char following a found first char, it swaps which char it's searching for. This means that in something like "aaaaaaa..." =~ /ab/, it wont keep hopping 1 char position with memchar(s,'a'); after the first hop it will do memchr(s,'b') and skip lots of chars in one go. This helps reduce the number of pathological cases. For the length >= 3 cases (normal BM), it keeps using BM, but after each iteration where the pointer has been incremented by the skip determined by the BM algorithm, it now does an additional if (*s != c) { s++; s = memchr(....); ... } step before running the next iteration of BM.
* fbm_instr(): tweak docs and formattingDavid Mitchell2015-10-131-4/+26
| | | | | Expand the commentary at the start of this function; add more blank lines to separate chunks of code, and document what SVpbm_TAIL is for.
* Missed one statbuf declaration in 45a23732c73.Craig A. Berry2015-10-091-1/+1
| | | | | The VMS-specific corner of the ifdef jungle ended up using statbuf without declaring it, so add a declaration.
* partial PL_statbuf removalDaniel Dragan2015-10-081-14/+23
| | | | | | | | | | | | | | | | Perl_nextargv has to have access to the Stat_t that is written to inside S_openn_cleanup or else run/switches.t, io/argv.t, io/inplace.t, and io/iprefix.t will fail. Removing the uses of PL_statbuf that are using PL_statbuf due to historical reason, and not using PL_statbuf to pass data between different funcs/different callstacks. This patch makes it easier to remove PL_statbuf in the future since the number uses of it has been reduced. -in Perl_apply move SETERRNO before tot--; so the branch can be combined with other "tot--;" branches by CC optmizer -combine 2 Perl_croak(aTHX_ "Illegal suidscript"); statements in S_validate_suid to make code look simpler, drop my_perl arg for space efficiency on threads of rarely executed code
* amigaos4: use #ifdef/ifndef __amigaos4__ when feasibleAndy Broad2015-09-161-3/+3
|
* amigaos4: random device nameAndy Broad2015-09-051-1/+5
|
* amigaos4: avoid my_pcloseAndy Broad2015-09-051-2/+5
|
* amigaos4: use my_popen from amigaos.cAndy Broad2015-09-051-2/+2
|
* amigaos4: avoid my_popen_listAndy Broad2015-09-051-1/+1
|
* amigaos4: use our own environ implementationAndy Broad2015-09-051-0/+11
|
* amigaos4: use amigaos glue for exec(), system(), waitpid()Andy Broad2015-09-051-0/+6
|
* perlapi: NitsKarl Williamson2015-09-031-2/+3
|
* Various pods: Add C<> around many typed-as-is thingsKarl Williamson2015-09-031-25/+26
| | | | Removes 'the' in front of parameter names in some instances.
* Explicitly use and check for FD_CLOEXEC.Jarkko Hietaniemi2015-08-261-1/+1
| | | | | | | | This may break places which have the FD_CLOEXEC functionality but do not have the FD_CLOEXEC define. In any case, using a boolean for the F_SETFD flag is icky. Using an explicit 1 is also dubious.
* dont create *{"_<$filename"} globs for perl lang debugging of XSUBsDaniel Dragan2015-08-121-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 1st problem, *{"_<$filename"} globs aren't created for PP code unless PERLDB_LINE || PERLDB_SAVESRC are on (see Perl_yylex ). Creating XSUBs unconditionally created the *{"_<$filename"} globs for XSUB, even if PP subs were not getting the debugging globs created. This is probably an oversight, from commit b195d4879f which tried to deprecate using the *{"_<$filename"} GVs for storing the originating filename of the CV which was partially reverted 2 months later in commit 57843af05b with CvFILE becoming a char * instead of GV *. To speed up XSUB registration time, and decrease memory when not in Perl lang debugging mode dont create the debugging globs for XSUBs unless in Perl lang debugging mode. see also http://www.nntp.perl.org/group/perl.perl5.porters/2000/06/msg13832.html 2nd problem, since the perl debugger can't step into C code, nor set breakpoints in it, there is no reason to create *{"_<$filename"} globs for .c files. Since someone maybe one day might try to implement that feature, comment out the code instead of deleting it. This will slightly reduce the size of perl binary, and speed up XSUB registration time, and decrease memory usage when using the Perl debugger. see also (no responses) http://www.nntp.perl.org/group/perl.perl5.porters/2015/06/msg229014.html perl has a number of core perma-XSUBs (UNIVERSAL/PerlIO/DynaLoader/Internals/mro/misc const subs/etc). Each of these previously got a "_<foo.c" glob. I counted 7 .c debugging globs on my perl. This commit, before on WinXP, running threaded perl with -e"system 'pause'" as a sample script, "Private Bytes" (all process unique memory, IE not shared, not mmaped) was 488 KB, after this commit it was 484 KB, which means that enough malloc memory was saved plus a little bit of chance, to cross one 4 KB page of memory. IDK the exact amount of saved memory is over or under 4KB.
* perlapi: Use F<> around file namesKarl Williamson2015-08-011-1/+1
|
* Use U64 (a type) instead of U64TYPE (a define).Jarkko Hietaniemi2015-07-291-1/+1
| | | | Builds on top of 16d89be8.
* Remove gettimeofday() workarounds for VMS in util.c.Craig A. Berry2015-07-021-15/+4
| | | | | VMS has had gettimeofday() since v7.0, released in 1999, so there's no reason now to be special casing native workarounds.
* [perl #125381] fix -Cnn parsingHugo van der Sanden2015-06-111-9/+8
| | | | | | | Commit 22ff313068 for [perl #123814] inadvertently changed the logic when parsing a numeric parameter to the -C option, such that the successfully parsed number was not saved as the option value if it parsed to the end of the argument.
* don't fatalize warnings during unwinding (#123398)Lukas Mai2015-06-091-1/+4
|
* 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.
* don't test non-null argsDavid Mitchell2015-03-111-4/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* [perl #123814] replace grok_atou with grok_atoUVHugo van der Sanden2015-03-091-21/+40
| | | | | | | | | | | | Some questions and loose ends: XXX gv.c:S_gv_magicalize - why are we using SSize_t for paren? XXX mg.c:Perl_magic_set - need appopriate error handling for $) XXX regcomp.c:S_reg - need to check if we do the right thing if parno was not grokked Perl_get_debug_opts should probably return something unsigned; not sure if that's something we can change.
* Consistently use NOT_REACHED; /* NOTREACHED */Jarkko Hietaniemi2015-03-041-1/+1
| | | | | | Both needed: the macro is for compilers, the comment for static checkers. (This doesn't address whether each spot is correct and necessary.)
* [perl #123554] fix threaded builds and prevent a warningTony Cook2015-02-101-8/+22
|
* [perl #123554] catch a couple of other size overflowsTony Cook2015-02-101-6/+9
| | | | | | Unfortunately, running out of memory in safesysmalloc() and safesysrealloc() doesn't produce a catchable croak(), so remove the test.
* Corrections to spelling and grammatical errors.Lajos Veres2015-01-281-2/+2
| | | | Extracted from patch submitted by Lajos Veres in RT #123693.
* Revert the support for new warning categories outside of "all"Ævar Arnfjörð Bjarmason2015-01-251-21/+6
| | | | | | | | | | | | | | | | | | | | | | | | This reverts & amends my v5.21.7-151-gea5519d and Karl Williamson's v5.21.7-183-g2f3cbe1, the latter was only need because of the former. I've also taken the opportunity to fix the long-standing trivial bug with misaligned code in warnings.{pm,h}. That was easier to commit along with this than to split it up from the other generated changes. Why revert this? See the "use warnings 'absolutely-all-almost';" thread on perl5-porters for the latest summary: http://www.nntp.perl.org/group/perl.perl5.porters/2015/01/msg225066.html Basically as I explained in v5.21.7-151-gea5519d the current design of the API makes it too contentious to freely add new warnings, but there's no consensus on how to solve that. I.e. whether we should just add them to "all", or do this change, or several other possible things outlined in that thread and elsewhere. Since the deadline for contentious changes for v5.22 is already past us I'm backing this out for now.
* [-Dusecbacktrace] Close the BFD descriptor.Jarkko Hietaniemi2015-01-071-0/+6
| | | | | Otherwise we leak several dozens of megabytes, if not more, for each Perl_dump_c_backtrace().
* Add support for new warning categories outside of "all"Ævar Arnfjörð Bjarmason2014-12-291-6/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When someone suggests a new warning on p5p it always often up being argued about on the basis that it'll break existing code, and that we shouldn't add warnings for possibly legitimate code just because it's unusual or odd. As I pointed out in a discussion about RT #121025 (see [1]) we only keep having this discussion because until now we've had no facility to add new warnings outside of the default set that'll be retroactively enabled for everything that does 'use warnings'. This patch introduces such a facility. As a proof of concept I'm adding a warning for something that was added as a warning in the past, but pulled out because it was deemed too controversial at the time: warning about the use of grep in void context. That warning was added back in v5.10.0-218-g74295f0 but quickly pulled out in v5.10.0-230-gf5df478. See [2] for the discussion about it at the time. Now if you do: use warnings; grep /42/, (1,2); You'll get no warnings as before, but if you do: use warnings qw(extra); # Or its sole subcategory: void_unusual grep /42/, (1,2); You'll get a warning about "Unusual use of grep in void context". To turn off this warning once you've turned it on it's *not* sufficient to do: no warnings; You need to do: no warnings qw(pedantic); Or: no warnings qw(everything); I'm willing to change that, but first we should ask ourselves whether this should continue to remain a symmetric operation: {use,no} warnings ['all']; There's more elaboration on how this works in the changes I'm making to the perldelta and the warnings documentation. But briefly this should be 100% backwards compatible, but allow us to have our cake and eat it too in the future by adding new warnings without imposing them on existing code written against older perl versions (unless that code explicitly requested to get new warnings as they upgrade perl). The patch to the warnings.pm documentation lays out a backwards compatibility policy for warnings, we promise that we'll continue the status quo with the "all" category, but for other categories (including future additions) we'll make such promises on a per-category basis. TODO: I wanted to come up with some more general facility for being able to add these new warnings without altering the behavior of the -w and -W switches. I.e. now we'll emit this, as intended: $ ./perl -Ilib -w -e 'grep /42/, (1,2)' $ ./perl -Ilib -W -e 'grep /42/, (1,2)' $ ./perl -Ilib -e 'use warnings; grep /42/, (1,2)' $ ./perl -Ilib -e 'use warnings "extra"; grep /42/, (1,2)' Unusual use of grep in void context at -e line 1. I.e. we don't want -w and -W to mean "use warnings 'everything'", it should continue to mean "use warnings 'all'". But due to how they're implemented I couldn't find an easy way to generalize this. Right now I'm just hardcoding an exception to the new warning category I've added outside "all" for these warnings. That should be followed-up with a more general solution, but for now if we only have a few of these catogeries we should be fine. This patch incorporates work from Andreas Guðmundsson <andreasg@nasarde.org> who picked up an earlier version of mine and figured out the change being made to mg.c here. That change removes an optimization in the ${^WARNING_BITS} magic which might make things a tad slower. 1. https://rt.perl.org/Ticket/Display.html?id=121025#txn-1276663 2. http://www.nntp.perl.org/group/perl.perl5.porters/2007/12/msg131922.html
* improve xs_handshake() diag messageDavid Mitchell2014-12-171-2/+2
| | | | | | | | | | | | | | | The important part of the error message is that the binaries are mismatched; the details of the handshake keys are an implementation detail. Or to put it another way, when someone mixes up their paths, getting something like Fcntl.c: Invalid handshake key got 0xcf80000 needed 0xd700000, binaries are mismatched Is a bit scary and confusing. This is hopefully (slightly) less scary: Fcntl.c: loadable library and perl binaries are mismatched (got handshake key 0xcf80000, needed 0xd700000)
* xs_handshake(() clean up desciptionDavid Mitchell2014-12-171-22/+37
| | | | | | Clean up the description of this function; in particular, say at the top what the function is for; fix typos; and generally improve the readability of the text.