summaryrefslogtreecommitdiff
path: root/util.c
Commit message (Collapse)AuthorAgeFilesLines
* Remove duplicate "the" in commentsElvin Aslanov2023-05-031-1/+1
| | | | Fix spelling on various files pertaining to core Perl.
* replace "define\t" with "define " in most "normal" core files.Yves Orton2023-04-291-10/+10
| | | | | | | | | | | | | | | | | | | The main exceptions being dist/, ext/, and Configure related files, which will be updated in a subsequent commit. Files in the cpan/ directory are also omitted as they are not owned by the core. '#define' has seven characters, so following it with a \t makes it look like '#define ' when it is not, which then frustrates attempts to find where a given define is. If you *know* then you do a git grep -P 'define\s+WHATEVER' but if don't or you forget, you can get very confused trying to find where a given define is located. This fixes all such cases so they actually are 'define WHATEVER' instead. If this patch is getting in your way with blame analysis then view it with the -w option to blame.
* util.c - avoid warning about truncated pointer valueYves Orton2023-03-291-1/+35
| | | | | | | | | | | This code is part of the fallback rng initialization, it should only be used in odd circumstances, and it is intended to be "random"ish, so the logic change should not be a problem. This more or less reverts commit 4b4c4ab35e70f005167c863eae6d2003492c393c, although the S_ptr_hash() now lives in util.c instead of hv.c. Turns out having a decent pointer hash /is/ useful.
* util.c - assign HS_GETXSVERLEN() to var before assertYves Orton2023-03-291-3/+3
| | | | | This makes it easier to see the value with gdb, and also avoids an assignment in the if condition body.
* Inline get_context() for non-Win32Karl Williamson2023-03-011-29/+0
| | | | | | | This trivial function should get optimized out. But I couldn't get it to work for Windows, because the two likely hdr files don't have PL_thr_key defined in them. I suppose a new hdr file could be created that gets included later. But I didn't think it was worth it.
* Inline get_vtbl()Karl Williamson2023-03-011-10/+0
| | | | This trivial function will likely get optimized out
* toke.c - invoke __DIE__ handler after compilation errors in evalYves Orton2023-02-201-2/+2
| | | | | | | | | | | | | | | | | Currently whether the __DIE__ signal handler triggers during compilation of an eval string depends on the selection of the errors it contains. Certain types of compilation error are considered "deferred errors" and will not terminate compilation immediately, for instance undeclared variables do not confuse the compiler so they do not trigger immediate termination, and we will report them without limit provided they are the only errors encountered. Whether a given error terminates compilation or not or uses the error count to decide to do so seems to be somewhat random, and it is quite possible that compilation can complete, with errors, without ever "throwing" the exception so it can be passed to the __DIE__ handler. This patch ensures that when the eval has failed due to errors the $SIG{__DIE__} handler is invoked before the eval completes.
* snprintf() calls need to have proper radixKarl Williamson2023-02-101-11/+41
| | | | | | | | | | | | | | | | | | | Calls to libc snprintf() were neglected to be changed when perl was fixed to change the radix character to the proper one based on whether or not 'use locale' is in effect. Perl-level code is unaffected, but core and XS code is. This commit changes to wrap snprintf() calls with the macros designed for the purpose, long used for similar situations elsewhere in the code. Doing this requires the thread context. I achieved this in a few places by a dTHX, instead of assuming a caller would have the context already available, and adding a pTHX_ parameter. I tried doing it the other way, and got a few breakages in our test suite. Formatting already requires significant CPU time, so this addition should just be in the noise This bug was found by new tests that will be added in a future commit.
* util.c: White-space onlyKarl Williamson2023-02-101-11/+15
| | | | Properly indent some preprocessor directives
* util.c - move was_here to be initialized earlierYves Orton2023-02-081-1/+1
| | | | | | | | | | | | | | | | | | Otherwise the goto out_of_memory breaks threaded builds under debugging as originally reported by Karl as we jump over the initialization of the variable and then use it later on. util.c: In function ‘void* Perl_safesysrealloc(void*, size_t)’: util.c:335:11: error: jump to label ‘out_of_memory’ 335 | out_of_memory: | ^~~~~~~~~~~~~ util.c:248:18: note: from here 248 | goto out_of_memory; | ^~~~~~~~~~~~~ util.c:277:12: note: crosses initialization of ‘UV was_where’ 277 | UV was_where = PTR2UV(where); | ^~~~~~~~~ make: *** [makefile:260: util.o] Error 1
* Avoid a use-after-free warning by converting a pointer to a UV for debug ↵Paul "LeoNerd" Evans2023-02-071-1/+2
| | | | print purposes before we call realloc() on it
* Move my_strftime() from util.c to locale.cKarl Williamson2023-01-051-135/+0
| | | | | | | | | | | | Stress testing has shown that unless LC_TIME and LC_CTYPE are the same locale, mojibake can result on some platforms. locale.c already handles this for various other similar cases, and has the infrastructure available to easily handle this one too. util.c does not. The only code change is to a comment to reflect that things are now in a different file.
* Refactor my_strftime() into using a do ... while();Karl Williamson2023-01-051-58/+48
| | | | | This function can be simplified by using a do/while form to eliminate the second call to strftime().
* my_strftime: Test for trivial case before anything elseKarl Williamson2023-01-051-5/+11
| | | | | If the passed in format is the empty string, the result is going to also be the empty string. There is no need to do any other work.
* Perl_my_strftime(): Reformat sourceKarl Williamson2023-01-051-91/+94
| | | | | | This converts to use 4 space indentation, removes pre-C99 workarounds, moving declarations closer to first use as allowed by C99, and adds a few comments.
* perlapi,POSIX.pod: Note problematic behavior with strftime()Karl Williamson2023-01-051-1/+2
| | | | Mojibake currently can happen without taking care
* Revert "Revert "Inline strlcat(), strlcpy()""Karl Williamson2023-01-041-74/+0
| | | | | | This reverts commit 81620fbedd5f5cb87f240d7809dc669cd60d0139. The original commit was wrongly blamed for breakage, when it was the harness parallelism that was at fault; since fixed, mostly.
* Correct typos as per GH 20435James E Keenan2022-12-291-4/+4
| | | | | | | | | | | | | | | | | | | In GH 20435 many typos in our C code were corrected. However, this pull request was not applied to blead and developed merge conflicts. I extracted diffs for the individual modified files and applied them with 'git apply', excepting four files where patch conflicts were reported. Those files were: handy.h locale.c regcomp.c toke.c We can handle these in a subsequent commit. Also, had to run these two programs to keep 'make test_porting' happy: $ ./perl -Ilib regen/uconfig_h.pl $ ./perl -Ilib regen/regcomp.pl regnodes.h
* Revert "Inline strlcat(), strlcpy()"Yves Orton2022-12-221-0/+74
| | | | | | This reverts commit 5be23dd97e360d19c8abb4c0c534f5d5f9d3691a. The original patch seems to break DBM.
* Inline strlcat(), strlcpy()Karl Williamson2022-12-221-74/+0
| | | | These short functions are reasonably frequently used.
* Inline savepv() and related functionsKarl Williamson2022-12-221-118/+0
| | | | | | | These short functions are moved from util.c to inline.h. savesharedpv() and savesharedpvn() aren't moved because there is a complication of needing also to move croak_no_mem(), which could be done, but are these called enough to justify it?
* util.c - clarify unusual use of rcpv_new()Yves Orton2022-11-231-1/+3
|
* only fully calculate the stash (effective) name where neededTony Cook2022-11-181-1/+1
| | | | | | | | | gcc 12 was complaining that evaluating (somehekptr)->hek_key was always true in many places where HvNAME() or HvENAME() was being called in boolean context. Add new macros to check whether the names should be available and use those instead.
* cop.h - get rid of the STRLEN* stuff from cop_warningsYves Orton2022-11-021-9/+6
| | | | | With RCPV strings we can use the RCPV_LEN() macro, and make this logic a little less weird.
* op.c - use refcounted pv pointers for cop_warningsYves Orton2022-11-011-4/+1
| | | | | | this allows multiple ops to share the same underlying warning bit vector. the vectors are not deduped, however they are efficiently copied and shared.
* Switch libc per-interpreter data when tTHX changesKarl Williamson2022-10-181-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | As noted in the previous commit, some library functions now keep per-thread state. So far the only ones we care about are libc locale-changing ones. When perl changes threads by swapping out tTHX, those library functions need to be informed about the new value so that they remain in sync with what perl thinks the locale should be. This commit creates a function to do this, and changes the thread-changing macros to also call this as part of the change. For POSIX 2008, the function just calls uselocale() using the per-interpreter object introduced previously. For Windows, this commit adds a per-interpreter string of the current LC_ALL, and the function calls setlocale on that. We keep the same string for POSIX 2008 implementations that lack querylocale(), so this commit just enables that variable on Windows as well. The code is already in place to free the memory the string occupies when done. The commit also creates a mechanism to skip this during thread destruction. A thread in its death throes doesn't need to have accurate locale information, and the information needed to map from thread to what libc needs to know gets destroyed as part of those throes, while relics of the thread remain. I couldn't find a way to accurately know if we are dealing with a relic or not, so the solution I adopted was to just not switch during destruction. This commit completes fixing #20155.
* Use `LINE_Tf` thoroughly for formatting the value of CopLINE()TAKAI Kousuke2022-10-131-3/+3
| | | | | | The value of CopLINE() used to be formatted with various way; sometimes with `%ld` and `(long)` cast, sometimes `IVdf` and `(IV)` cast, or `%d` and so on.
* util.c: Add locks around strftime() callsKarl Williamson2022-09-291-0/+4
|
* util.c: mktime needs to run under a mutexKarl Williamson2022-09-291-0/+2
| | | | per the Posix standard
* perl.h: Finish implementing combo ENV/LOCALE mutexesKarl Williamson2022-09-291-2/+3
| | | | | | | | | | | | | | | | | | There are cases where an executing function is vulnerable to either the locale or environment being changed by another thread. This commit implements macros that use mutexes to protect these critical sections. There are two cases that exist: one where the functions only read; and one where they can also need exclusive control so that a competing thread can't overwrite the returned static buffer before it is safely copied. 5.32 had a placeholder for these, but didn't actually implement it. Instead it locked just the ENV portion. On modern platforms with thread-safe locales, the locale portion is a no-op anyway, so things worked on them. This new commit extends that safety to other platforms. This has long been a vulnerability in Perl.
* Change ENV/LOCALE locking read macro namesKarl Williamson2022-09-291-2/+2
| | | | The old name was confusing.
* Add my_strftime8()Karl Williamson2022-08-221-4/+11
| | | | | This is like plain my_strftime(), but additionally returns an indication of the UTF-8ness of the returned string
* Replace sv_2mortal(newSVhek( with newSVhek_mortalRichard Leach2022-08-051-2/+2
| | | | The new Perl_newSVhek_mortal function is slightly more efficient.
* Also log CopSTASHPVPaul "LeoNerd" Evans2022-06-211-2/+3
|
* Add a PERL_MEM_LOG=c optionPaul "LeoNerd" Evans2022-06-211-1/+27
| | | | | Prints more levels of C backtrace on SV allocation operations. Also prints the perl caller file + line number.
* allow building with -DPERL_MEM_LOG on Win32Tony Cook2022-06-161-1/+5
| | | | | | | | This appears to have been broken for a while, and became more broken with 75acd14e, which made newSV_type() inline. This will also prevent warnings about calls to undeclared functions on systems that don't need symbols to be exported.
* Create perlstatic.hKarl Williamson2022-06-141-9/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is used for functions that we don't suggest should be inlined, but we think the compiler will generate better code if it has full knowledge about them. At the moment, it only contains a single function which can be tail-call optimized. The Lord of the Rings quote for this file was suggested by Leon Timmermans. The proximal cause of this commit can be gleaned from this email: From - Mon Nov 16 09:20:50 2020 X-Mozilla-Status: 0001 X-Mozilla-Status2: 00800000 X-Mozilla-Keys: Subject: Re: about commit "Revert "croak_memory_wrap is an inline function."" (khw) To: bulk88 <bulk88@hotmail.com>, perl5-porters@perl.org References: <20200429011948.14287.qmail@lists-nntp.develooper.com> From: Karl Williamson <public@khwilliamson.com> Message-ID: <6f38382c-8fb5-ba1a-51c6-409fa5b56d2b@khwilliamson.com> Date: Mon, 16 Nov 2020 09:20:41 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.4.3 MIME-Version: 1.0 In-Reply-To: <20200429011948.14287.qmail@lists-nntp.develooper.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit On 4/28/20 7:19 PM, bulk88 wrote: > https://perl5.git.perl.org/perl5.git/commitdiff/d68c938a1e6c6b4bfe907decbb4929780ee06eae > > > Why was this done? Perl_croak_memory_wrap is supposed to be a static > linkage, not globally visible C function, in every perl .o file that the > CC/linker should toss the static func if its not used. I wanted to avoid > the PLT/GOT runtime C symbol substitution/LDPRELOAD mechanism and let > the CC turn Perl_croak_memory_wrap into a single conditional jump > (offset from current instruction pointer), with no return and no C stack > entry, jump instruction instead of > > call get_EIP //x86 32 only > mov eax, *(eax_aka_eip+offset into PLT) > call eax I reverted this because, first of all, gcc with the appropriate -W options raised warnings that it was disregarding the request and was not inlining this function, and 2nd of all, there was no indication in the comments as to why this function had been inlined.
* perlapi: Deprecate 5 functionsKarl Williamson2022-06-081-0/+20
| | | | | | | | | | and document two of them, which I had done before I realized they were to be deprecated. These functions are obsolete, and stemmed from a long-solved problem in Windows. There are a couple of uses on cpan of a couple of them. But people should just use PL_opnames[], for example, instead of the function here that returns the address of that array.
* util.c: merge the win32 and non-win32 implementations of my_setenvTomasz Konojacki2022-05-291-35/+13
|
* make PERL_USE_SAFE_PUTENV the default and the only optionTomasz Konojacki2022-05-291-92/+4
| | | | | | | Now environ isn't owned by Perl and calling setenv/putenv in XS code will no longer result in memory corruption. Fixes #19399
* util.c: POSIX doesn't allow calling setenv() with a NULL valueTomasz Konojacki2022-05-291-5/+1
|
* util.c: small refactoring of my_setenv and my_clearenvTomasz Konojacki2022-05-291-41/+37
| | | | | | | | | | - Early return is much better than wrapping the whole function with if(). - Remove pointless (void) casts. - Move variable declarations closer to their first use. - Normalize indentation.
* probe for setenv in ConfigureTomasz Konojacki2022-05-291-11/+3
|
* perlapi: Document and mark internal my_popen_listKarl Williamson2022-05-181-0/+8
| | | | This implements PerlProc_popen_list on some systems.
* perlapi: Document and mark internal my_socketpairKarl Williamson2022-05-181-0/+10
| | | | | This emulates socketpair on some systems that lack it; and should all be under the level that XS code would deal with.
* perlapi: Document repeatcpyKarl Williamson2022-05-181-0/+10
|
* perlapi: die_nocontext goes with 'die', not 'die_sv'Karl Williamson2022-05-141-11/+11
| | | | It had wrongly been added to the wrong entry.
* perlintern: Document [gs]et_context; mark internalKarl Williamson2022-05-111-0/+18
| | | | | These implement PERL_[GS]ET_CONTEXT which are the API interfaces for this functionality.
* perlapi: Document rsignal_stateKarl Williamson2022-05-111-0/+10
|
* perlapi: Add some commentary for rsignal()Karl Williamson2022-05-111-2/+4
|