summaryrefslogtreecommitdiff
path: root/util.c
Commit message (Collapse)AuthorAgeFilesLines
* replace all instances of PERL_IMPLICIT_CONTEXT with MULTIPLICITYTomasz Konojacki2021-06-091-16/+16
| | | | | | | | | | | | Since the removal of PERL_OBJECT (acfe0abcedaf592fb4b9cb69ce3468308ae99d91) PERL_IMPLICIT_CONTEXT and MULTIPLICITY have been synonymous and they're being used interchangeably. To simplify the code, this commit replaces all instances of PERL_IMPLICIT_CONTEXT with MULTIPLICITY. PERL_IMPLICIT_CONTEXT will stay defined for compatibility with XS modules.
* my_strftime(): Don't assume empty %p is an errorKarl Williamson2021-02-171-9/+22
| | | | | | | | | | The strftime() format %p yields an am/pm indicator. Many locales don't have this distinction, and so a format containing just this specifier will return an empty string. Prior to this commit, that was considered an error. What was going on is we kept enlarging the buffer to find a non-empty return, to no avail, and so treat it as an error. This commit special cases this to not make it an error. (It's hard to imagine that the am/pm string alone would exceed the 200 byte limit.)
* util.c: Clarify pod for Perl_formKarl Williamson2021-02-111-3/+3
|
* style: Detabify indentation of the C code maintained by the core.Michael G. Schwern2021-01-171-1274/+1274
| | | | | | | | | | | This just detabifies to get rid of the mixed tab/space indentation. Applying consistent indentation and dealing with other tabs are another issue. Done with `expand -i`. * vutil.* left alone, it's part of version. * Left regen managed files alone for now.
* Document safesys...alloc fcns; safesysfreeKarl Williamson2020-12-271-4/+25
|
* perlapi: Note that my_strftime's result is localizedKarl Williamson2020-12-211-0/+3
|
* Fix broken PERL_MEM_LOG under threadsKarl Williamson2020-12-191-5/+4
| | | | | | | | | | | | | This fixes GH #18341 There are problems with getenv() on threaded perls wchich can lead to incorrect results when compiled with PERL_MEM_LOG. Commit 0b83dfe6dd9b0bda197566adec923f16b9a693cd fixed this for some platforms, but as Tony Cook, pointed out there may be standards-compliant platforms that that didn't fix. The detailed comments outline the issues and (complicated) full solution.
* Remove empty "#ifdef"sTom Hukins2020-12-081-4/+0
|
* Avoid deadlock with PERL_MEM_LOGKarl Williamson2020-11-261-1/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | This fixes GH #18341 The Perl wrapper for getenv() was changed in 5.32 to allocate memory to squirrel safely away the result of the wrapped getenv() call. It does this while in a critical section so as to make sure another thread can't interrupt it and destroy it. Unfortunately, when Perl is compiled for debugging memory problems and has PERL_MEM_LOG enabled, that allocation causes a recursive call to getenv() for the purpose of checking an environment variable to see how to log that allocation. And hence it deadlocks trying to enter the critical section. There are various solutions. One is to use or emulate a general semaphore instead of a binary one. This is effectively what PL_lc_numeric_mutex_depth does for another mutex, and the code for that could be used as a template. But given that this is an extreme edge case which requires Perl to be specially compiled to enable this feature which is used only for debugging, a much simpler, if less safe if it were to ever be used in production, solution should suffice. Tony Cook suggested just avoiding the wrapper for this particular purpose.
* perlapi: Split section Display and DumpKarl Williamson2020-11-061-3/+2
| | | | into Debugging and Display sections
* autodoc.pl: Enhance apidoc_section featureKarl Williamson2020-11-061-9/+9
| | | | | | | | | | | This feature allows documentation destined for perlapi or perlintern to be split into sections of related functions, no matter where the documentation source is. Prior to this commit the line had to contain the exact text of the title of the section. Now it can be a $variable name that autodoc.pl expands to the title. It still has to be an exact match for the variable in autodoc, but now, the expanded text can be changed in autodoc alone, without other files needing to be updated at the same time.
* Fix up delimcpy_no_escape()Karl Williamson2020-10-311-27/+40
| | | | | | I modified this function in ab01742544b98b5b5e13d8e1a6e9df474b9e3005, and did not fully understand the edge cases. This commit now handles those properly, the same as plain delimcpy() does.
* Rewrite delimcpy to use memchr and Copy, not per-byteKarl Williamson2020-10-311-40/+167
| | | | | | | | | | | | | | | | | | | | Prior to this commit delimcpy() parsed its input byte-by-byte, looking for a particular character, and copied the input to the output stopping just before the first such occurrence. memchr() is much faster for finding a single character. The complication is that if the character is preceded by a backslash, it doesn't count as that character, it is considered to be escaped, and parsing continues to the first unescaped occurrence, if any. Each escaping backslash is not copied. The prior code also failed to account for the possibility of the delimiter being a backslash, the same as the escape. The new routine looks for the character with memchr, sees if it is escaped. If not, Copy does the whole copy at once. If it is escaped, it uses Copy up to that backslash, and repeats the process.
* Fix typosSamanta Navarro2020-10-031-1/+1
| | | | | | | | | For: https://github.com/Perl/perl5/pull/18201 Committer: Samanta Navarro is now a Perl author. To keep 'make test_porting' happy: Increment $VERSION in several files. Regenerate uconfig.h via './perl -Ilib regen/uconfig_h.pl'.
* perlapi: croak_nocontext is preferred over plain croakKarl Williamson2020-09-291-2/+3
| | | | When you are about to die, the time/space tradeoff may tilt towards space.
* perlapi: Clarify croak_no_modify()Karl Williamson2020-09-051-3/+6
|
* perlapi: Consolidate some nocontext fcns with their main fcnKarl Williamson2020-09-051-35/+35
|
* Document mini_mktimeKarl Williamson2020-09-051-2/+6
|
* Document several warner() fcnsKarl Williamson2020-09-051-10/+59
|
* Reorganize perlapiKarl Williamson2020-09-041-10/+11
| | | | | This uses a new organization of sections that I came up with. I asked for comments on p5p, but there were none.
* perlapi for get_c_backtrace_dump: fix verbatimKarl Williamson2020-08-311-4/+4
| | | | These weren't indented so weren't treated as verbatim
* Document vformKarl Williamson2020-08-231-0/+3
|
* Document a bunch of foo_nocontext functionsKarl Williamson2020-08-231-2/+27
| | | | These just refer to foo's pod, with an explanation of 'nocontext'
* Change vwarn pod to be in terms of plain warnKarl Williamson2020-08-231-8/+2
|
* util.c: Comment fix-upKarl Williamson2020-08-221-2/+3
|
* Refactor rninstr()Karl Williamson2020-08-221-21/+83
| | | | | | | | | | | | This function finds a needle in a haystack. If memrchr() is available, use it to find the final byte in the needle; If the needle is length 1, that's all we need, and this is special cased. Otherwise it uses memEQ of the other bytes of the needle, from where the needle would have to start, and if no match, repeats. If no memrchr(), it emulates that by just looking backward from the end until it finds the needle's final byte; then proceeds as above.
* Document my_strftimeKarl Williamson2020-08-171-7/+12
|
* ninstr(): Use memchr instead of a loopKarl Williamson2020-08-131-13/+22
| | | | | This function is perl's memmem if that function isn't available. This commit replaces its loop with a call to memchr, which is a C89 function.
* Rewrite delimcpy_no_escape()Karl Williamson2020-08-101-1/+47
| | | | | | | | This was doing a byte-by-byte search and copy. We can make things simpler and faster by 1) only looking within the available space region 2) using memchr for seach 3) using Copy to copy the whole thing at once.
* util.c: Reorder two functionsKarl Williamson2020-08-011-7/+7
| | | | This will make some future commits a little less noisy
* Always expose the perl_tsa_mutex_* functions when threads are enabledTom Stellard2020-07-301-2/+1
| | | | | | | | | These functions were only part of the API if perl is built with clang. However perl modules built with clang still try to use them even when perl itself is built with gcc. This patch replaces the #ifdef PERL_TSA_ACTIVE around these functions with defined(USE_ITHREADS) && defined(I_PTHREAD) so they are always available when treading is enabled. This fixes the clang build of perl modules when perl is built with gcc.
* Remove use of dVAR in coreDagfinn Ilmari Mannsåker2020-07-201-17/+0
| | | | | It only does anything under PERL_GLOBAL_STRUCT, which is gone. Keep the dNOOP defintion for CPAN back-compat
* Remove PERL_GLOBAL_STRUCTDagfinn Ilmari Mannsåker2020-07-201-164/+0
| | | | | | | | This was originally added for MinGW, which no longer needs it, and only still used by Symbian, which is now removed. This also leaves perlapi.[ch] empty, but we keep the header for CPAN backwards compatibility.
* Remove Symbian portDagfinn Ilmari Mannsåker2020-07-201-2/+2
| | | | | Also eliminate USE_HEAP_INSTEAD_OF_STACK and SETSOCKOPT_OPTION_VALUE_T, since Symbian was the only user of those.
* Remove PL_freqKarl Williamson2020-07-171-12/+0
| | | | | This hasn't actually been used since commit 8922e4382e9c1488fdbe46a0f52493860dc897a6.
* Remove EBCDIC PL_freqKarl Williamson2020-07-171-2/+3
| | | | | | Instead, do a translation of the ASCII one at runtime. This is because the table doesn't account for the various EBCDIC flavors, so isn't actually accurate.
* Remove redundant ternary in safesysmallocDagfinn Ilmari Mannsåker2020-07-021-1/+1
| | | | | | | Commit b001a0d149ed99df18916796f3a72b2c888b94d8 changed it to bumping the size from 0 to 1 earlier in the function, but didn't remove the then-redundant ternary that tried to avoid passing zero to PerlMem_malloc().
* Fix a bunch of repeated-word typosDagfinn Ilmari Mannsåker2020-05-221-2/+2
| | | | | Mostly in comments and docs, but some in diagnostic messages and one case of 'or die die'.
* fix PERL_GLOBAL_STRUCT_PRIVATE buildsDavid Mitchell2020-03-201-0/+1
| | | | | Sprinkle some dVAR pixie dust to fix recent bitrot on that build configuration.
* Perl_init_tm: Use mutex to avoid race.Karl Williamson2020-03-181-0/+2
| | | | | | This locks around localtime (and localtime_r which this call may be translated into) which are sensitive to locale and environment changes in their execution.
* Fix pod errorsKarl Williamson2020-03-161-2/+2
| | | | introduced by cd7ac46508e1b2b346c339417237ef487bf59c74
* perlre: Note savepv() allocations need to be freedKarl Williamson2020-03-161-2/+4
|
* Revert "croak_memory_wrap is an inline function."Karl Williamson2020-03-111-0/+9
| | | | | | | This reverts commit 6c714a09cc08600278e72aea1fcdf83576d061b4. croak_memory_wrap is designed to save a few bytes of memory, and was never intended to be inlined. This commit moves it to util.c where the other croak functions are.
* Add thread safety to some environment accessesKarl Williamson2020-03-111-2/+4
| | | | | | | | | | | | | | | | | | The previous commit added a mutex specifically for protecting against simultaneous accesses of the environment. This commit changes the normal getenv, putenv, and clearenv functions to use it, to avoid races. This makes the code simpler in places where we've gotten burned and added stuff to avoid races. Other places where we haven't known we were getting burned could have existed until now. Now that comes automatically, and we can remove the special cases we earlier stumbled over. getenv() returns a pointer to static memory, which can be overwritten at any moment from another thread, or even another getenv from the same thread. This commit changes the accesses to be under control of a mutex, and in the case of getenv, a mortalized copy is created so that there is no possible race.
* Move cntrl_to_mnemonic() to util.c from regcomp.cKarl Williamson2020-01-231-0/+20
| | | | | This is in preparation for it being used elsewhere, to reduce duplication of code.
* Rewrite and inline my_strnlen()Karl Williamson2020-01-131-30/+0
| | | | | | | This commit changes this function to use memchr() instead of looping byte-by-byte through the string. And it inlines it into 3 lines of code. This should give comparable performance to a native libc strnlen().
* util.c: Rmv now always-true assertionKarl Williamson2020-01-121-2/+0
| | | | | Commit 052d914306c3a13afe3fbeb17c8f1c986969f94c changed the type of this parameter to unsigned, so it is now never negative.
* Change len param in savepvn to Size_t from I32Karl Williamson2020-01-071-1/+1
| | | | We handle longer strings than 31 bits.
* util.c: Use inRANGE macroKarl Williamson2019-12-261-2/+2
|
* Add memCHRs() macro and use itKarl Williamson2019-12-181-2/+2
| | | | | | | This replaces strchr("list", c) calls throughout the core. They don't work properly when 'c' is a NUL, returning the position of the terminating NUL in "list" instead of failure. This could lead to segfaults or even security issues.