summaryrefslogtreecommitdiff
path: root/handy.h
Commit message (Collapse)AuthorAgeFilesLines
* handy.h: Make inRANGE more robustKarl Williamson2019-04-201-5/+21
| | | | | | | | | | | | | | | | | | | | | | It turns out that in order to make this work or assert if it won't, it needs to be more complicated. The problem has to do with signed and unsigned operands. It now special cases where the item being checked to be in the range is a char, and casts that to a U8. Otherwise, there is a problem when that is a negative signed type and the range is above the int_max for that type. An assert is added to detect this rare event (not rare for chars, hence the special case). The use of sizeof() for this case means that it will be resolved at compile time and not generate extra code. I did an experiment, and gcc even under -O0 compiled away the sizeof() clause. As an example of why this is needed, suppose we have a signed char, -127, and we want to see if it is in the range 128-130, expressed as ints. Without casting that -127 to an unsigned char, it would subtract 128 from -127, yield -255, which when cast to an unsigned int would be wrong. But casting the -127 to U8 first yields 129, and gives the correct result. The same issue could happen wih ints if the range is above INT_MAX, but that is a much rarer case, and this macro asserts against it.
* handy.h: Parenthesize formal parameters in macro defnKarl Williamson2019-03-311-1/+1
| | | | | These should be parenthesized to prevent issues when called with an expression.
* handy.h: Convert some macros to use inRANGEKarl Williamson2019-03-291-18/+16
| | | | the latter is faster, having only one conditional.
* handy.h: Comments, remove extraneous parensKarl Williamson2019-03-291-1/+4
|
* handy.h: Change some macros to use new inRANGEKarl Williamson2019-03-211-6/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | It turns out that on ASCII platforms, several of the character classes are expressible as a single range, and using the new inRANGE macro saves some instructions each time versus the array lookup still done for these on EBCDIC platforms. Here is a sample benchmark Key: Ir Instruction read Dr Data read Dw Data write COND conditional branches IND indirect branches The numbers represent raw counts per loop iteration. isDIGIT_A('5') blead hack Ratio % ----- ----- ------- Ir 358.0 355.0 100.8 Dr 123.0 121.0 101.7 Dw 57.0 57.0 100.0 COND 51.0 50.0 102.0 IND 7.0 7.0 100.0 The differences are small, but these macros are executed ubiquitously
* Generalize macro and move to handy.hKarl Williamson2019-03-211-0/+6
| | | | | | | The macro verified that its input was in the range '1' to '9' by using a subtraction and a single conditional. This commit generalizes this non-obvious method of avoiding a conditional, and moves it to handy.h so it can be used in other places.
* utf8.c: Add functions for Turkic locale case changingKarl Williamson2019-02-051-3/+5
| | | | | | These override the normal handling of UTF-8 locale case changing. They aren't actually called yet, until later in this series of commits.
* handy.h: Add commentKarl Williamson2019-02-041-1/+3
|
* handy.h: White-space onlyKarl Williamson2019-02-041-1/+1
| | | | Vertically align the ternary colon with the question mark above it.
* handy.h: Add void * casts to memEQ, memNEKarl Williamson2019-02-041-2/+2
| | | | | This change is to allow these macros to be called without having to do casting in the call.
* handy.h: Fix definition of isPOWER_OF_2()Karl Williamson2018-12-091-1/+1
| | | | Prior to this commit, it returned TRUE if the input was 0.
* Move isPOWER_OF_2() macro to handy.hKarl Williamson2018-11-261-0/+8
| | | | | This is in preparation for it to be used outside of the file which previously defined it.
* handy.h: Add some commentsKarl Williamson2018-11-161-2/+7
| | | | This allows us to remove a comment in regcomp.c
* handy.h: Silence compiler warningKarl Williamson2018-09-201-4/+4
| | | | | | | | | | | | This warning was introduced in db54010671d6c27faf667d658073743b14cd9b58. and is about comparing signed and unsigned results. This commit casts both operands to ptrdiff_t which is likely the widest signed type available on the platform. This can fail if the one of the operands is greater than PTRDIFF_MAX. But lots of other things can fail in that case as well. As the reply from Tomasz Konojacki in the thread starting with http://nntp.perl.org/group/perl.perl5.porters/251541 points out, compilers are now assuming that no object is larger than PTRDIFF_MAX, and if they can assume that, so can we.
* perlapi: Fix up SV handling podKarl Williamson2018-08-051-1/+1
| | | | | | | | | The pod for this has gotten screwed up over the releases, with a section entitled SV-Body Allocation containing a bunch of SV manipulation functions, and another section with that name containing still more with no real rhyme or reason as to why one would be in one vs the other. And one function was in both places. This commit consolidates all these into one section entitled "SV Manipulation Functions"
* handy.h: Remove obsolete commentKarl Williamson2018-06-251-7/+0
|
* Remove obsolete variablesKarl Williamson2018-03-311-13/+7
| | | | | These were for when some of the Posix character classes were implemented as swashes, which is no longer the case, so these can be removed.
* Remove no longer used constant and #if checks.Karl Williamson2018-03-311-25/+0
| | | | This is now obsolete as a result of the last few commits.
* rmv/de-dup static const char array "strings"Daniel Dragan2018-03-071-1/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | MSVC due to a bug doesn't merge identicals between .o'es or discard these vars and their contents. MEM_WRAP_CHECK_2 has never been used outside of core according to cpan grep MEM_WRAP_CHECK_2 was removed on the "have PERL_MALLOC_WRAP" branch in commit fabdb6c0879 "pre-likely cleanup" without explination, probably bc it was unused. But MEM_WRAP_CHECK_2 was still left on the "no PERL_MALLOC_WRAP" branch, so remove it from the "no" side for tidyness since it was a mistake to leave it there if it was removed from the "yes" side of the #ifdef. Add MEM_WRAP_CHECK_s API, letter "s" means argument is string or static. This lets us get rid of the "%s" argument passed to Perl_croak_nocontext at a couple call sites since we fully control the next and only argument and its guaranteed to be a string literal. This allows merging of 2 "Out of memory during array extend" c strings by linker now. Also change the 2 op.h messages into macros which become string literals at their call sites instead of "read char * from a global char **" which was going on before. VC 2003 32b perl527.dll section size before .text name DE503 virtual size .rdata name 4B621 virtual size after .text name DE503 virtual size .rdata name 4B5D1 virtual size
* remove unreferenced copies of char * swash_property_names[]Daniel Dragan2018-02-271-3/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Due to some MSVC bug or perl's not using MS specific CC options that I've never figured out, MSVC does not remove unreferenced by a single .obj or combine identical, static const data vars. MSVC funcs get removed & combined correctly. Since for var swash_property_names removing it from .objs that dont need it is very easy, do it. It saves some memory space. Perhaps some other platforms/OSes/CCs have similar problems removing unreferenced symbols from final binaries so this patch would help on those CCs too. regexec.c stopped using swash_property_names in commit 2a16ac9277 in 5.19.8 "regexec.c: Use compiled-in POSIX definitions" regcomp.c stopped using swash_property_names in commit bcb875216f in 5.19.8 "regcomp.c: Rmv code for delayed 'til runtime POSIX defns" with MSVC 2008 64, before miniperl.exe disk file size 1761KB .rdata virtual size 0xBC354 bytes perl527.dll disk file size 2040KB .rdata virtual size 0xC9421 bytes after this commit miniperl.exe disk file size 1761KB .rdata virtual size 0xBC2C4 bytes perl527.dll disk file size 2040KB .rdata virtual size 0xC9381 bytes ~144 bytes saved by removing unused copies of swash_property_names array. There are other cases of large duplicate static const data vars still in the perl527.dll binary but this patch covers a very simple case.
* handy.h: Add commentKarl Williamson2018-01-171-0/+1
|
* Emulate C99 int_fast8_t, etc typedefsKarl Williamson2017-12-181-0/+20
| | | | | | | | | | | | | | These are useful if you know you have a variable with a restricted range, and so could fit in a byte or 16 bits, but speed is more important. These C99 typedefs allows you to specify the minimal size you need, and allows the compiler to substitute a wider type if it is faster. This commit adds typedefs spelled the same as the C99 ones, but upper cased. On non-C99 compilers, it just uses 'int' behind the scenes, which should be safe. These are currently restricted to core to be sure these aren't a bad idea before they are made public.
* Emulate some C99 macros and typedefsKarl Williamson2017-12-081-49/+0
| | | | | | | | | | | | | | | | | | | | | | On systems that don't have them, this emulates U?INT(16|32)_C U?INTMAX_C and the typedefs u?intmax_t Since, these are typedefs that can't be tested for if they exist, this creates PERL_U?INTMAX_T typedefs instead, setting them to the standard values in stdint.h if it is available. In addition, it moves the pre-existing emulation of U?INT64_C from handy.h to perl.h. This is because there was duplicate-ish logic in the two files, and the handy.h version appears to be better thought out. It converts the couple of places in core that were using the other deleted logic to instead use the C99 names.
* handy.h: Fix definition of WIDEST_UTYPE for non-coreKarl Williamson2017-12-071-5/+3
| | | | | | | | | | | | | | Because HAS_QUAD is not defined outside the perl core, this macro was not getting defined properly for 64-bit systems. This means, for example, that someone using this to cast could end up with the wrong answer. For example isASCII(2**32) would yield true, because the high bit would get dropped by the cast, making the value appear to be zero. This unfortunately creates a warning message in the compile that WIDEST_UTYPE is redefined, as the definition of that is defective in PPPort. It should only define it if it wasn't previously defined, and it is wrongly using the 32 bit version. This is added impetus to get PPPort fixed
* handy.h: Make U64, I64 available outside coreKarl Williamson2017-12-071-1/+1
| | | | | | | | | | | | The ones corresponding to shorter sizes, like I32, are available everywhere. There is no reason to restrict just the 64 variety. This fixes the bug in the definition for INT64_C and UINT64_C which caused these to not be defined outside core on some platforms, such as Windows. See commit 3edba68397e487b39cca6e7fc0b75ab4a2f6a341 for more explanation
* remove stray NULLOK/NN from apidoc directivesZefram2017-12-061-1/+1
|
* Try harder to define INT64_C and UINT64_C.Craig A. Berry2017-11-301-1/+7
| | | | | | | | | | | | | | | | | These are steadily being used in more and more macros that are available to extensions as well as core, but the use of Perl's home-grown versions (for when we don't get them from stdint.h) has depended on the definition of HAS_QUAD. However, HAS_QUAD is explicitly turned off in perl.h when PERL_CORE is not defined, and has warnings about widespread breakage if that undef were to be removed (referring to RT #119753). So extensions that use macros that in turn use INT64_C or UINT64_C were failing to build. So in order to know that 64-bit integers are available without using the HAS_QUAD macro that was intended for just that purpose, use QUADKIND as a way of saying "We know we had HAS_QUAD before you hid it from us." Ugh.
* handy.h: add a comment about perl_assert_ptr()Yves Orton2017-11-161-0/+3
|
* better document macros taking literal stringsZefram2017-11-121-31/+31
| | | | | | | | | | When giving a function-style prototype for a macro taking a literal string parameter, put a string literal in place of a type for that parameter. This goofy appearance makes it obvious that this isn't really a function, and clues the reader in that the parameter can't actually be an arbitrary expression of the right type. Also change the nonsensical "NUL-terminated literal string" to "literal string" to describe these parameters. Fixes [perl #116286].
* Revert "Simplify _MEM_WRAP_NEEDS_RUNTIME_CHECK()"Lukas Mai2017-11-111-1/+2
| | | | This reverts commit 004073bac990d90244eb463f435c52d4040b36df.
* fix MEM_SIZE_MAX definitionLukas Mai2017-11-111-1/+1
|
* handy.h: Clarify commentKarl Williamson2017-11-091-2/+3
|
* PERL_STRLEN_ROUNDUP: parenthesize macro parameterLukas Mai2017-11-081-2/+3
| | | | | | | Also: - factor out common expression - remove redundant double parens - add spaces to expression
* handy.h: Add commentsKarl Williamson2017-11-061-0/+45
| | | | | This adds a description of the naming conventions to be used for any new string comparison macros.
* Make new macros privateKarl Williamson2017-11-061-2/+6
| | | | Until we decide these weren't a bad idea
* handy.h: Make uniform the defns of strFOO, memFOOKarl Williamson2017-11-061-6/+6
| | | | For consistency
* Remove _memEQs, _memNEsKarl Williamson2017-11-061-6/+0
| | | | All uses of these private macros have been replaced by other calls.
* Add memENDPs and use it in coreKarl Williamson2017-11-061-0/+3
| | | | This corresponds to memBEGINPs
* Add memBEGINPs() to core and use itKarl Williamson2017-11-061-0/+3
| | | | | | This macro is like memBEGINs(), but the 'P' signifies we want a proper substring, meaning that the 2nd string parameter must not be the entire first parameter.
* Add memBEGINs(), memENDs() and use them in APItestKarl Williamson2017-11-061-0/+7
| | | | | | | | | memBEGINs() is like strBEGINs(), but can be used for buffers without trailing NULs. It can also be used when there is a trailing NUL, and the length is known, as it should be somewhat faster, only having to check for one ending condition. Same for memENDs vs strENDs
* Rename strEQs to strBEGINs; remove strNEsKarl Williamson2017-11-061-7/+1
| | | | | | | | | | The original names are confusing. See thread beginning with http://nntp.perl.org/group/perl.perl5.porters/244335 The two macros are mapped into just that one, complementing the result for the few cases where strNEs was used.
* handy.h: Add parens around macro expansionKarl Williamson2017-10-241-1/+1
| | | | | This guarantees the expected precedence no matter what the context it is called in.
* Rely on C89 NULLAaron Crane2017-10-211-7/+0
|
* handy.h: simplify cpp conditionalsAaron Crane2017-10-211-25/+17
|
* Assume we have sane C89 memcmp()Aaron Crane2017-10-211-7/+2
| | | | | | | "Sane" means that it works correctly on bytes with their high bit set, as C89 also requires. We therefore no longer need to probe for and/or use BSD bcmp().
* Assume we have C89 memset()Aaron Crane2017-10-211-5/+0
| | | | This means we also never need to consider using BSD bzero().
* Remove USE_STRUCT_COPY in favour of C89 struct assignmentAaron Crane2017-10-211-4/+0
| | | | | At least for now, we retain the StructCopy() macro, but its definition always just uses struct assignment.
* avoid 'the address of ... will always evaluate as ...' warns in mem macrosYves Orton2017-09-131-7/+10
| | | | | | | | | | | | | In f14cf363205 we added asserts to our memory macros (Copy(), Zero() etc) to ensure that the target is non-null. These asserts throw warnings like perl.c: In function ‘Perl_eval_sv’: perl.c:2976:264: warning: the address of ‘myop’ will always evaluate as ‘true’ [-Waddress] Zero(&myop, 1, UNOP); which is annoying. This patch changes how these asserts are coded so we avoid the warning. Thanks to Zefram for the fix.
* handy.h: White space onlyKarl Williamson2017-09-091-4/+4
| | | | ALign some things vertically for easier reading
* (perl #131746) avoid undefined behaviour in Copy() etcTony Cook2017-09-041-7/+7
| | | | | | | | | | | | | | | | | These functions depend on C library functions which have undefined behaviour when passed NULL pointers, even when passed a zero 'n' value. Some compilers use this information, ie. assume the pointers are non-NULL when optimizing any following code, so we do need to prevent such unguarded calls. My initial thought was to add conditionals to each macro to skip the call to the library function when n is zero, but this adds a cost to every use of these macros, even when the n value is always true. So instead I added asserts() which will give us a much more visible indicator of such broken code and revealed the pp_caller and Glob.xs issues also patched here.