X-Git-Url: https://perl5.git.perl.org/perl5.git/blobdiff_plain/9de15fec376a8ff90a38fad0ff322c72c2995765..4244b0292358460164f4c7053e251706d22071b1:/regexp.h diff --git a/regexp.h b/regexp.h index 004d614..5776a90 100644 --- a/regexp.h +++ b/regexp.h @@ -190,20 +190,17 @@ equivalent to the following snippet: if (SvMAGICAL(sv)) mg_get(sv); - if (SvROK(sv) && - (tmpsv = (SV*)SvRV(sv)) && - SvTYPE(tmpsv) == SVt_PVMG && - (tmpmg = mg_find(tmpsv, PERL_MAGIC_qr))) - { - return (REGEXP *)tmpmg->mg_obj; - } + if (SvROK(sv)) + sv = MUTABLE_SV(SvRV(sv)); + if (SvTYPE(sv) == SVt_REGEXP) + return (REGEXP*) sv; NULL will be returned if a REGEXP* is not found. =for apidoc Am|bool|SvRXOK|SV* sv -Returns a boolean indicating whether the SV contains qr magic -(PERL_MAGIC_qr). +Returns a boolean indicating whether the SV (or the one it references) +is a REGEXP. If you want to do something with the REGEXP* later use SvRX instead and check for NULL. @@ -221,8 +218,8 @@ and check for NULL. * Note that the flags whose names start with RXf_PMf_ are defined in * op_reg_common.h, being copied from the parallel flags of op_pmflags * - * NOTE: if you modify any RXf flags you should run regen.pl or regcomp.pl - * so that regnodes.h is updated with the changes. + * NOTE: if you modify any RXf flags you should run regen.pl or + * regen/regcomp.pl so that regnodes.h is updated with the changes. * */ @@ -236,12 +233,12 @@ and check for NULL. case SINGLE_PAT_MOD: *(pmfl) |= RXf_PMf_SINGLELINE; break; \ case XTENDED_PAT_MOD: *(pmfl) |= RXf_PMf_EXTENDED; break -/* Note, includes locale, unicode */ +/* Note, includes charset ones, assumes 0 is the default for them */ #define STD_PMMOD_FLAGS_CLEAR(pmfl) \ - *(pmfl) &= ~(RXf_PMf_FOLD|RXf_PMf_MULTILINE|RXf_PMf_SINGLELINE|RXf_PMf_EXTENDED|RXf_PMf_LOCALE|RXf_PMf_UNICODE) + *(pmfl) &= ~(RXf_PMf_FOLD|RXf_PMf_MULTILINE|RXf_PMf_SINGLELINE|RXf_PMf_EXTENDED|RXf_PMf_CHARSET) /* chars and strings used as regex pattern modifiers - * Singlular is a 'c'har, plural is a "string" + * Singular is a 'c'har, plural is a "string" * * NOTE, KEEPCOPY was originally 'k', but was changed to 'p' for preserve * for compatibility reasons with Regexp::Common which highjacked (?k:...) @@ -260,7 +257,8 @@ and check for NULL. #define NONDESTRUCT_PAT_MOD 'r' #define LOCALE_PAT_MOD 'l' #define UNICODE_PAT_MOD 'u' -#define DUAL_PAT_MOD 'd' +#define DEPENDS_PAT_MOD 'd' +#define ASCII_RESTRICT_PAT_MOD 'a' #define ONCE_PAT_MODS "o" #define KEEPCOPY_PAT_MODS "p" @@ -269,32 +267,67 @@ and check for NULL. #define NONDESTRUCT_PAT_MODS "r" #define LOCALE_PAT_MODS "l" #define UNICODE_PAT_MODS "u" -#define DUAL_PAT_MODS "d" +#define DEPENDS_PAT_MODS "d" +#define ASCII_RESTRICT_PAT_MODS "a" +#define ASCII_MORE_RESTRICT_PAT_MODS "aa" /* This string is expected by regcomp.c to be ordered so that the first * character is the flag in bit RXf_PMf_STD_PMMOD_SHIFT of extflags; the next * character is bit +1, etc. */ #define STD_PAT_MODS "msix" +#define CHARSET_PAT_MODS ASCII_RESTRICT_PAT_MODS DEPENDS_PAT_MODS LOCALE_PAT_MODS UNICODE_PAT_MODS + /* This string is expected by XS_re_regexp_pattern() in universal.c to be ordered * so that the first character is the flag in bit RXf_PMf_STD_PMMOD_SHIFT of * extflags; the next character is in bit +1, etc. */ #define INT_PAT_MODS STD_PAT_MODS KEEPCOPY_PAT_MODS #define EXT_PAT_MODS ONCE_PAT_MODS KEEPCOPY_PAT_MODS -#define QR_PAT_MODS STD_PAT_MODS EXT_PAT_MODS +#define QR_PAT_MODS STD_PAT_MODS EXT_PAT_MODS CHARSET_PAT_MODS #define M_PAT_MODS QR_PAT_MODS LOOP_PAT_MODS #define S_PAT_MODS M_PAT_MODS EXEC_PAT_MODS NONDESTRUCT_PAT_MODS /* - * NOTE: if you modify any RXf flags you should run regen.pl or regcomp.pl - * so that regnodes.h is updated with the changes. + * NOTE: if you modify any RXf flags you should run regen.pl or + * regen/regcomp.pl so that regnodes.h is updated with the changes. * */ /* Leave some space, so future bit allocations can go either in the shared or * unshared area without affecting binary compatibility */ -#define RXf_BASE_SHIFT (_RXf_PMf_SHIFT_NEXT+2) +#define RXf_BASE_SHIFT (_RXf_PMf_SHIFT_NEXT+1) + +/* embed.pl doesn't yet know how to handle static inline functions, so + manually decorate them here with gcc-style attributes. +*/ +PERL_STATIC_INLINE const char * +get_regex_charset_name(const U32 flags, STRLEN* const lenp) + __attribute__warn_unused_result__; + +#define MAX_CHARSET_NAME_LENGTH 2 + +PERL_STATIC_INLINE const char * +get_regex_charset_name(const U32 flags, STRLEN* const lenp) +{ + /* Returns a string that corresponds to the name of the regex character set + * given by 'flags', and *lenp is set the length of that string, which + * cannot exceed MAX_CHARSET_NAME_LENGTH characters */ + + *lenp = 1; + switch (get_regex_charset(flags)) { + case REGEX_DEPENDS_CHARSET: return DEPENDS_PAT_MODS; + case REGEX_LOCALE_CHARSET: return LOCALE_PAT_MODS; + case REGEX_UNICODE_CHARSET: return UNICODE_PAT_MODS; + case REGEX_ASCII_RESTRICTED_CHARSET: return ASCII_RESTRICT_PAT_MODS; + case REGEX_ASCII_MORE_RESTRICTED_CHARSET: + *lenp = 2; + return ASCII_MORE_RESTRICT_PAT_MODS; + default: + return "?"; /* Unknown */ + } + return "?"; /* Unknown */ +} /* Anchor and GPOS related stuff */ #define RXf_ANCH_BOL (1<<(RXf_BASE_SHIFT+0)) @@ -336,8 +369,12 @@ and check for NULL. /* Copy and tainted info */ #define RXf_COPY_DONE (1<<(RXf_BASE_SHIFT+16)) + +/* during execution: pattern temporarily tainted by executing locale ops; + * post-execution: $1 et al are tainted */ #define RXf_TAINTED_SEEN (1<<(RXf_BASE_SHIFT+17)) -#define RXf_TAINTED (1<<(RXf_BASE_SHIFT+18)) /* this pattern is tainted */ +/* this pattern was tainted during compilation */ +#define RXf_TAINTED (1<<(RXf_BASE_SHIFT+18)) /* Flags indicating special patterns */ #define RXf_START_ONLY (1<<(RXf_BASE_SHIFT+19)) /* Pattern is /^/ */ @@ -349,8 +386,8 @@ and check for NULL. #endif /* - * NOTE: if you modify any RXf flags you should run regen.pl or regcomp.pl - * so that regnodes.h is updated with the changes. + * NOTE: if you modify any RXf flags you should run regen.pl or + * regen/regcomp.pl so that regnodes.h is updated with the changes. * */ @@ -436,7 +473,7 @@ and check for NULL. #endif /* PLUGGABLE_RE_EXTENSION */ -/* Stuff that needs to be included in the plugable extension goes below here */ +/* Stuff that needs to be included in the pluggable extension goes below here */ #ifdef PERL_OLD_COPY_ON_WRITE #define RX_MATCH_COPY_FREE(rx) \