summaryrefslogtreecommitdiff
path: root/inline.h
diff options
context:
space:
mode:
authorJarkko Hietaniemi <jhi@iki.fi>2014-06-15 09:41:30 -0400
committerJarkko Hietaniemi <jhi@iki.fi>2014-06-15 21:00:07 -0400
commit81d52ecd50d856aa8879413261956d0801e7fd12 (patch)
treeb672e3331504ebd1670bbc67be3f33e358fef061 /inline.h
parentd39195d4cbd0258917ad8f5f002fc6548080938a (diff)
downloadperl-81d52ecd50d856aa8879413261956d0801e7fd12.tar.gz
Some low-hanging -Wunreachable-code fruits.
- after return/croak/die/exit, return/break are pointless (break is not a terminator/separator, it's a goto) - after goto, another goto (!) is pointless - in some cases (usually function ends) introduce explicit NOT_REACHED to make the noreturn nature clearer (do not do this everywhere, though, since that would mean adding NOT_REACHED after every croak) - for the added NOT_REACHED also add /* NOTREACHED */ since NOT_REACHED is for gcc (and VC), while the comment is for linters - declaring variables in switch blocks is just too fragile: it kind of works for narrowing the scope (which is nice), but breaks the moment there are initializations for the variables (the initializations will be skipped since the flow will bypass the start of the block); in some easy cases simply hoist the declarations out of the block and move them earlier Note 1: Since after this patch the core is not yet -Wunreachable-code clean, not enabling that via cflags.SH, one needs to -Accflags=... it. Note 2: At least with the older gcc 4.4.7 there are far too many "unreachable code" warnings, which seem to go away with gcc 4.8, maybe better flow control analysis. Therefore, the warning should eventually be enabled only for modernish gccs (what about clang and Intel cc?)
Diffstat (limited to 'inline.h')
-rw-r--r--inline.h27
1 files changed, 27 insertions, 0 deletions
diff --git a/inline.h b/inline.h
index a914729c3c..619c79ee7c 100644
--- a/inline.h
+++ b/inline.h
@@ -320,6 +320,33 @@ S_should_warn_nl(const char *pv) {
#endif
+/* ------------------ pp.c, regcomp.c, toke.c, universal.c ------------ */
+
+#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;
+ }
+ /* The NOT_REACHED; hides an assert() which has a rather complex
+ * definition in perl.h. */
+ NOT_REACHED; /* NOTREACHED */
+ return "?"; /* Unknown */
+}
+
/*
* Local variables:
* c-indentation-style: bsd