summaryrefslogtreecommitdiff
path: root/util.c
Commit message (Collapse)AuthorAgeFilesLines
* PERL_SET_CONTEXT(t) needs to set PL_current_context from C++ tooNicholas Clark2022-01-121-2/+7
| | | | | | | | | | | | | | | | | | | | We want to use C11 thread local storage where possible, as its read overhead is lower. However C++ uses incompatible syntax for TLS, so we have to hide the variable from C++ extensions, and have the read code "fall back" to the pthread_getspecific() approach. However, C++ extensions also need to be able to call PERL_SET_CONTEXT(t) and have everything still work the same as C extensions. Hence they *also* need to set PL_current_context - a variable that has to be hidden from them. Hence change the version of the PERL_SET_CONTEXT macro used by C++ extensions from inline code to a call to Perl_set_context(), and have that set PL_current_context (when used). Technically this commit also fixes a bug in that Perl_set_context() is API and should have been setting PL_current_context since that variable was first introduced. In practice, likely nothing uses this API, as there is no code on CPAN that calls it, and the macro PERL_SET_CONTEXT() is much more prominent.
* z/OS ASCII needs file descriptors on pipes tagged as ASCIIMike Fulton2022-01-011-0/+53
| | | | | | | Add code to change the file descriptor on the file descriptors opened from ``Perl_my_popen_list`` and ``Perl_my_popen`` so that the CCSID of the file descriptor is 819. This change is only when the code is built for ASCII ``#if (__CHARSET_LIB == 1)`` on z/OS ``#if defined(OEMVS)``.
* _MSC_VER is now always >= 1800 (i.e. Visual C++ 2013, aka Visual C++ 12.0)Steve Hay2021-12-161-6/+0
|
* Remove DOS/DJGPP supportDagfinn Ilmari Mannsåker2021-11-021-26/+0
| | | | | | DJGPP is a port of the GNU toolchain to 32-bit x86 systems running DOS. The last known attempt to build Perl on it was on 5.20, which only got as far as building miniperl.
* Remove NetWare supportDagfinn Ilmari Mannsåker2021-10-081-6/+6
| | | | The build has been broken since 2009.
* The different xs_handshake() failures need distinct messagesNicholas Clark2021-09-091-2/+4
| | | | | | | | | | | | | | | | xs_handshake() makes two different comparisons that on failure are reported as "got handshake key %p, needed %p", with opaque hexadecimal values. The first is the "actual" key as generated by the HS_KEY() macro, which encodes various values such as sizeof(PerlInterpreter) and the API version. The second is the address of the current thread's PerlInterpreter struct. Either can fail, and before this commit they would fail with identical text. Hence it wasn't obvious what the problem was, causing "confusion and delay" if one tried to decode the hexadecimal output as the wrong thing. (For example when it's actually pointers mismatching, but one tries to decode the values into API version and structure size, assuming that the values were the packed output from HS_KEY().)
* Don't call av_fetch() with TRUE to create an SV that is immediately freed.Nicholas Clark2021-07-281-6/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | In Perl_my_pclose() the code as been calling av_fetch() with TRUE (lvalue; create the SV if not found) since the Perl 4 -> Perl 5 migration. The code *had* been assuming that the returned result was always a valid SvIV until commit 25d9202327791097 in Jan 2001: Safe fix for Simon's pclose() doing SvIVX of undef -> core bug. which fixes the bug reported in https://www.nntp.perl.org/group/perl.perl5.porters/2001/01/msg28651.html That commit changed the code to default the IV result (the pid) to -1 if the av_fetch() failed to return SVt_IV. However, that commit failed to notice that the value -1 was *already* "in use" *only 4 lines later* as a flag for OS/2 to indicate "Opened by popen." Hence switch the OS/2 sentinel value to -2. The that states that OS/2 has a my_pclose implementation in os2.c is wrong. It was erroneously added by commit 5f05dabc4054964a in Dec 1996: [inseparable changes from patch from perl5.003_11 to perl5.003_12] It appears to be a copy-paste error from the previous comment added about my_popen. I tested this fix with the 2001-era code of commit 25d9202327791097 - it (also) solves the bug reported back then.
* 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.