summaryrefslogtreecommitdiff
path: root/inline.h
Commit message (Collapse)AuthorAgeFilesLines
* inline.h: Fix typo in commentKarl Williamson2023-05-161-1/+1
|
* Revert "fixup, use old logic until 5.37 - TO BE SQUASHED"Yves Orton2023-03-181-9/+1
| | | | | | | This reverts commit 57e785fdb86b4eb41afd139372aab7841223385f. This uses the new logic instead of the workaround. Thanks to Ilmari for the reminder.
* Inline get_context() for non-Win32Karl Williamson2023-03-011-0/+33
| | | | | | | 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-0/+9
| | | | This trivial function will likely get optimized out
* for loops: protect GV/LVREF from premature freeDavid Mitchell2023-02-281-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | In something like for $package_var (....) { ... } or more experimentally, for \$lvref (....) { ... } when entering the loop in pp_enteriter, perl would pop the GV/LVREF off the stack, but didn't bump its refcount. Thus it was possible (if unlikely) that it could be freed during the loop. In particular this crashed: $f = "foo"; for ${*$f} (1,2) { delete $main::{$f}; # delete the glob *foo ...; } This will become more serious when the stack becomes refcounted, as popping something off the stack will trigger a refcount decrement on it and thus a possible immediate free of the GV. This commit future-proofs for loops against this by ensuring that the refcount of the SV referred to by cx->blk_loop.itervar_u.svp is appropriately bumped up / down on entering / exiting the loop.
* Provide padname_dup_inc() and padnamelist_dup_inc()Paul "LeoNerd" Evans2023-02-131-0/+7
|
* embed.pl - the 's', 'S', 'i' and 'I' flags are mutually exclusiveYves Orton2023-02-011-1/+1
| | | | | | | | | | | | | We had a bug where we processed the first one in the flags definition. Sorting the flags or rearranging them changes the output, which shouldn't happen. This also fixes the handling and specification of PerlEnv_putenv(), which was marked "si" when it should have been marked "i". This required changing its implementation from a Perl_ prefix to a S_ prefix and regenerating. I have run embed.pl in a loop with a local patch to shuffle the flags to see if there were any other order dependencies. No output files changed so I assume with this patch we are free of such bugs.
* Fix PerlEnv_putenv threaded compilation on WindowsKarl Williamson2023-01-121-0/+19
| | | | | A second compilation of a workspace would fail. The first one would succeed because miniperl was being used, which isn't threaded.
* Revert "Revert "Inline strlcat(), strlcpy()""Karl Williamson2023-01-041-0/+74
| | | | | | 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-5/+5
| | | | | | | | | | | | | | | | | | | 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-74/+0
| | | | | | This reverts commit 5be23dd97e360d19c8abb4c0c534f5d5f9d3691a. The original patch seems to break DBM.
* Inline strlcat(), strlcpy()Karl Williamson2022-12-221-0/+74
| | | | These short functions are reasonably frequently used.
* Inline savepv() and related functionsKarl Williamson2022-12-221-0/+118
| | | | | | | 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?
* Do not cast away constnessBart Van Assche2022-12-131-2/+2
| | | | | | | Fix most compiler warnings caused by building Perl extensions with -Wcast-qual. This is realized by changing the type of multiple T * arguments into const T * and by changing a few (T *) casts into (const T *).
* regcomp.c - decompose into smaller filesYves Orton2022-12-091-1/+1
| | | | | | | | | | | | | | | | | This splits a bunch of the subcomponents of the regex engine into smaller files. regcomp_debug.c regcomp_internal.h regcomp_invlist.c regcomp_study.c regcomp_trie.c The only real change besides to the build machine to achieve the split is to also adds some new defines which can be used in embed.fnc to control exports without having to enumerate /every/ regex engine file. For instance all of regcomp*.c defines PERL_IN_REGCOMP_ANY, and this is used in embed.fnc to manage exports.
* Define a newPADxVOP() convenience functionPaul "LeoNerd" Evans2022-12-081-0/+30
| | | | | | | | | This function conveniently sets the ->op_targ field of the returned op, making it neater to use inline in larger trees of new*OP functions used to build optree fragments. This function is implemented as `static inline`, for speed and code-size reasons.
* utf8_hop forwards Change continuation start behaviorKarl Williamson2022-12-071-9/+33
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Prior to this commit, when hopping forwards, and the initial position to hop from is a continuation byte, it treats it and each such successive one as a single character until it gets to a start byte, and switches into normal mode. In contrast, in hopping backwards, all the consecutive continuation bytes are considered to be part of a single character (as they indeed are). Thus there is a discrepancy between forward/backwards hopping; and the forward version seems wrong to me. This commit removes the discrepancy. There is no change in behavior if the starting position is to the beginning of a character. All calls in the core except for the API test are of this form. But, if the initial position is in the middle of a character, it now moves to the beginning of the next character, subtracting just 1 from the count of characters to hop (instead of subtracting however many continuation bytes there are). This is how I would have expected it to work all along. Succinctly, getting to the next character now consumes one hop count, no matter the direction nor which byte in the character is the starting position.
* perlapi: Clarify utf8_hop backwards entriesKarl Williamson2022-12-071-4/+12
|
* inline.h: Add fold failure debug statementsKarl Williamson2022-08-311-1/+7
| | | | Under verbose debugging, this shows cases where folds didn't match.
* Per-word utf8_to_bytes()Karl Williamson2022-08-201-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This changes utf8_to_bytes() to do a per-word initial scan to see if the source is actually downgradable, before starting the conversion. This is significantly faster than the current per-character scan. However, the speed advantage evaporates in doing the actual conversion to being a wash with the previous scheme. Thus it finds out quicker if the source is downgradable. cache grind yields this, based on a 100K character string; the non-downgradable one has the next character after that be the only one that's too large.: Key: Ir Instruction read Dr Data read Dw Data write COND conditional branches IND indirect branches _m branch predict miss _m1 level 1 cache miss _mm last cache (e.g. L3) miss - indeterminate percentage (e.g. 1/0) The numbers represent relative counts per loop iteration, compared to blead at 100.0%. Higher is better: for example, using half as many instructions gives 200%, while using twice as many gives 50%. unicode::bytes_to_utf8_legal_API_test Downgrading 100K valid characters blead proposed ------ ------ Ir 100.00 99.99 Dr 100.00 100.03 Dw 100.00 100.04 COND 100.00 100.05 IND 100.00 100.00 COND_m 100.00 87.25 IND_m 100.00 100.00 Ir_m1 100.00 123.25 Dr_m1 100.00 100.18 Dw_m1 100.00 99.94 Ir_mm 100.00 100.00 Dr_mm 100.00 100.00 Dw_mm 100.00 100.00 unicode::bytes_to_utf8_illegal Finding too high a character after 100K valid ones blead fast ------ ------ Ir 100.00 188.91 Dr 100.00 179.77 Dw 100.00 66.75 COND 100.00 278.47 IND 100.00 100.00 COND_m 100.00 88.71 IND_m 100.00 100.00 Ir_m1 100.00 121.86 Dr_m1 100.00 100.01 Dw_m1 100.00 100.03 Ir_mm 100.00 100.00 Dr_mm 100.00 100.00 Dw_mm 100.00 100.00
* Add a PadnameREFCNT_inc() macroPaul "LeoNerd" Evans2022-08-171-0/+7
| | | | | | | | | Implemented as a static inline function call, so that it can return the padname pointer itself. This would allow use in expressions such as ptr->field = PadnameREFCNT_inc(pn); That makes it similar to the familiar SvREFCNT_inc() macro.
* Add a PERL_MEM_LOG=c optionPaul "LeoNerd" Evans2022-06-211-1/+4
| | | | | Prints more levels of C backtrace on SV allocation operations. Also prints the perl caller file + line number.
* PERL_IS_UTF8_CHAR_DFA: Ensure params evaluated onceKarl Williamson2022-06-201-2/+3
|
* Revert "Do per-word hop back"Karl Williamson2022-06-141-75/+17
| | | | | | | This reverts commit d6ad3b72778369a84a215b498d8d60d5b03aa1af and adds comments that it existed. This is so that this work which isn't really needed based on current usage in core isn't lost, and can be used in the future.
* Do per-word hop backKarl Williamson2022-06-141-10/+75
| | | | | | | This should speed up backing up a large distance in a UTF-8 string. But we don't actually do that in core. I did this work 5 years ago before I realized this. Rather than throw it away, this commit gets it into the history, and the next commit will revert it.
* Add comment to inline.h noting perlstatic.hKarl Williamson2022-06-141-0/+4
|
* Make fc(), qr//i thread-safe on participating platformsKarl Williamson2022-06-111-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | A long standing bug in Perl that has gone undetected is that the array is global that is created when changing locales and tells fc() and qr//i matching what the folds are in the new locale. What this means is that any program only has one set of fold definitions that apply to all threads within it, even if we claim that the locales are thread-safe on the given platform. One possibility for this going undetected so long is that no one is using locales on multi-threaded systems much. Another possibility is that modern UTF-8 locales have the same set of folds as any other one. It is a simple matter to make the fold array per-thread instead of per-process, and that solves the problem transparently to other code. I discovered this stress-testing locale handling under threads. That test will be added in a future commit. In order to keep from having a dTHX inside foldEQ_locale, it has to have a pTHX_ parameter. This means that the other functions that function pointer variables get assigned to point to have to have an identical signature, which means adding pTHX_ to functions that don't require it. The bodies of all these are known to the compiler, since they are all in inline.h or in the same .c file as where they are called. Hence the compiler can optimize out the unused parameter. Two calls of STR_WITH_LEN also have to be changed because of C preprocessor limitations; perhaps there is another way to do it that I'm unfamiliar with.
* inline.h: White space onlyKarl Williamson2022-06-081-5/+5
|
* Move av_new_alloc from av.c to inline.hRichard Leach2022-06-081-0/+43
| | | | | | | There was less benefit in doing this prior to newSV_type becoming an inline function. Now that it is, inlining av_new_alloc can help compilers eliminate redundant setting of AvMAX/AvFILLp and unnecessary branches of any following inlined calls to av_store_simple.
* inline.h: add av_push_simpleRichard Leach2022-06-081-0/+29
| | | | | | | | | | | | | | A simplified version of av_push, along the lines of av_store_simple and av_fetch_simple. This function is trivial, but having it makes refactoring of existing code easier to read. For example, changing: av_push(some_av, val); to: av_push_simple(some_av,val); is easier to read than: av_store_simple(some_av, AvFILLp(some_av) + 1, val)
* Move sv.h functions from inline.h into sv_inline.h,Richard Leach2022-05-281-303/+0
| | | | | so that all functions inlined from sv.* are in one place. This was suggested by @khw.
* Change SvIV and kin to inline functionsKarl Williamson2022-05-281-0/+103
| | | | So that they will evaluate the argument just once.
* perlapi: Fix a couple autodoc build warningsKarl Williamson2022-05-281-1/+1
|
* Evaluate SvPVXtrue's argument just onceKarl Williamson2022-05-281-0/+35
| | | | by making the macro instead an inline function
* fixup, use old logic until 5.37 - TO BE SQUASHEDYves Orton2022-05-271-1/+9
|
* sv.c - add new bool related utility functions and macrosYves Orton2022-05-271-2/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The new bool "type" does not have the usual complement of utility functions and macros. It only has one encapsulating function, which is perfectly reasonable for most use cases where one wants to test if an SV* is a bool, but does a bit too much if one is working on a serialization tool which is likely to want to unroll a nice chunk of the logic. The new type also lacks the usual cohort of utility functions to create new bool SV's. This patch adds the following functions: newSVbool(const bool bool_val) newSV_true() newSV_false() sv_set_true(SV *sv) sv_set_false(SV *sv) sv_set_bool(SV *sv, const bool bool_val) And the following macros: SvIandPOK(sv) SvIandPOK_off(sv) SvIandPOK_on(sv) The following three are intended very specifically for writing serialization code like for Sereal, where it is reasonable to want to unroll the logic contained in Perl_sv_isbool() and SvTRUE(). They are documented as "you dont want to use this except under special circumstances". SvBoolFlagsOK(sv) BOOL_INTERNALS_sv_isbool(sv) BOOL_INTERNALS_sv_isbool_true(sv) BOOL_INTERNALS_sv_isbool_false(sv) SvBoolFlagsOK() is documented as being the same as SvIandPOK(), but this abstracts the intent from the implementation.
* perlapi: Document SvAMAGIC_(on|off)Karl Williamson2022-05-191-0/+17
|
* inline.h: Fix typo in commentKarl Williamson2022-05-041-1/+1
|
* Document CvDEPTHKarl Williamson2022-05-011-0/+7
|
* Fix double encoding of UTF-8 on EBCDICKarl Williamson2022-03-231-1/+4
| | | | | Commit d1e771d8c533168553df9b2a858d967f707fc9fe broke EBCDIC builds by doubly encoding some UTF-8 characters.
* Inlined newSV_type(SVt_NULL) leaner than non-inlined newSV(0)Richard Leach2022-03-071-1/+1
| | | | | | | | | | | | When a function outside of sv.c creates a SV via newSV(0): * There is a call to Perl_newSV * A SV head is uprooted and its flags set * A runtime check is made to effectively see if 0 > 0 * The new SV* is returned Replacing newSV(0) with newSV_type(SVt_NULL) should be more efficient, because (assuming there are SV heads to uproot), the only step is: * A SV head is uprooted and its flags set
* Fix utf8_to_uvchr for non-core callsKarl Williamson2022-03-051-1/+6
| | | | | | | Commit a460925186154b270b7a647a4f30b2f01fd97c4b broke calling this and related functions from outside of core Perl, but only when the input is empty (which is an error anyway, so was not caught except for deliberate API edge case tests in Devel::PPPort).
* utf8_to_uvchr_buf_helper: Check before derefKarl Williamson2022-03-051-1/+1
| | | | *s may not be valid here; check first.
* Refactor utf8 to code point conversionKarl Williamson2022-02-011-23/+41
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Most such conversions occur in the inlined function Perl_utf8n_to_uvchr_msgs(), which several macros like utf8n_to_uvchr() expand to. This commit effectively removes a conditional from inside the loop, and avoids some conditionals when converting the common case of the input being UTF-8 invariant (ASCII on ASCII platforms). Prior to this commit, the code did something different the first time through the loop than the other times. By hoisting that to pre-loop initialization, that conditional is removed from each iteration. That meant rearranging the loop to be a while(1), and have its exit conditions in the middle. All calls to this function from the Perl core pass in a non-empty string. But outside calls could conceivably pass an empty one which could lead to reading outside the buffer. An extra check is added to non-core calls, as is already done elsewhere. This change means that calls from core execute no more conditionals than the typical: if (UTF8_IS_INVARIANT(*s)) { code_point = *s; } else { code_point = utf8n_to_uvchr(s, ...) } I'm therefore thinking these can now just be replaced by the simpler code_point = utf8n_to_uvchr(s, ...) without a noticeable hit in performance. The essential difference is that the former gets its code point from the string already being examined, and the latter looks up data in a 450 byte static array that is referred to constantly, so is likely to be cached.
* newSVpvn_flags(x, .. ,SVs_TEMP) more efficient than sv_2mortal(newSVpv(x,0))Richard Leach2021-11-291-1/+1
|
* Add CopFILEAVn() and use it when cleaning up COP pointersTony Cook2021-11-151-0/+22
| | | | | | | | | | | | | | On threaded builds CopFILEAV() calls gv_fetchfile(), which always created the *{"::_<filenamehere"} glob, so the attempted clean up here could recreate the glob, even if it has already been removed when cleaning up a string eval. To avoid this, add CopFILEAVn() that never creates the glob, nor the AV so that the clean up never adds new objects. This change makes the check for PL_phase unnecessary, but that check is much cheaper than the call for gv_fetchfile_flags() that the macro hides, so retain the check.
* inline.h: _BitScanForward64 is available only on 64-bit architecturesTomasz Konojacki2021-10-211-1/+1
| | | | Fixes #19205
* inline.h: remove superfluous Visual C++ version checksTomasz Konojacki2021-10-211-5/+5
| | | | We no longer support Visual C++ 2012 and older.
* Revert "Introduce a "declaration after statement" into inline.h"Leon Timmermans2021-10-201-1/+3
| | | | | | | This reverts commit 632ce96a35d784df9e43bc8ad87b4e8f1f24a590. Sereal hasn't been fixed yet to deal with the fallout of this change, so we postpone this change for a later moment
* Introduce a "declaration after statement" into inline.hNicholas Clark2021-10-131-3/+1
| | | | | | | | | The core now permits some C99 code, so extensions need to ensure that any C compiler flags they add or change permit C99 code. This code is inlined by XS extensions in the core and on CPAN. The intent is that this commit should show up for any failure bisection, making it obvious what the cause is, and what the fix needs to be.