This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
grok_bslash_[ox]: Add param to silence non-portable warnings
authorKarl Williamson <public@khwilliamson.com>
Mon, 7 Jan 2013 15:23:58 +0000 (08:23 -0700)
committerKarl Williamson <public@khwilliamson.com>
Fri, 11 Jan 2013 18:50:36 +0000 (11:50 -0700)
If a hex or octal number is too big to fit in a 32 bit word, grok_oct
and grok_hex by default output a warning that it is a non-portable
value.  This new parameter to the grok_bslash functions can cause them
to shut up those warnings.  This is currently unused, but will be needed
in future commits.

dquote_static.c
embed.fnc
embed.h
proto.h
regcomp.c
toke.c

index f3cade8..61845cc 100644 (file)
@@ -87,6 +87,7 @@ S_grok_bslash_c(pTHX_ const char source, const bool utf8, const bool output_warn
 STATIC bool
 S_grok_bslash_o(pTHX_ char **s, UV *uv, const char** error_msg,
                       const bool output_warning, const bool strict,
+                      const bool silence_non_portable,
                       const bool UTF)
 {
 
@@ -110,6 +111,8 @@ S_grok_bslash_o(pTHX_ char **s, UV *uv, const char** error_msg,
  *         them
  *     strict is true if this should fail instead of warn if there are
  *         non-octal digits within the braces
+ *      silence_non_portable is true if to suppress warnings about the code
+ *          point returned being too large to fit on all platforms.
  *     UTF is true iff the string *s is encoded in UTF-8.
  */
     char* e;
@@ -150,6 +153,10 @@ S_grok_bslash_o(pTHX_ char **s, UV *uv, const char** error_msg,
        return FALSE;
     }
 
+    if (silence_non_portable) {
+        flags |= PERL_SCAN_SILENT_NON_PORTABLE;
+    }
+
     *uv = grok_oct(*s, &numbers_len, &flags, NULL);
     /* Note that if has non-octal, will ignore everything starting with that up
      * to the '}' */
@@ -180,6 +187,7 @@ S_grok_bslash_o(pTHX_ char **s, UV *uv, const char** error_msg,
 PERL_STATIC_INLINE bool
 S_grok_bslash_x(pTHX_ char **s, UV *uv, const char** error_msg,
                       const bool output_warning, const bool strict,
+                      const bool silence_non_portable,
                       const bool UTF)
 {
 
@@ -268,6 +276,9 @@ S_grok_bslash_x(pTHX_ char **s, UV *uv, const char** error_msg,
     }
 
     flags |= PERL_SCAN_ALLOW_UNDERSCORES;
+    if (silence_non_portable) {
+        flags |= PERL_SCAN_SILENT_NON_PORTABLE;
+    }
 
     *uv = grok_hex(*s, &numbers_len, &flags, NULL);
     /* Note that if has non-hex, will ignore everything starting with that up
index bd8c2cf..e6bb9bc 100644 (file)
--- a/embed.fnc
+++ b/embed.fnc
@@ -736,14 +736,18 @@ ApdR      |I32    |looks_like_number|NN SV *const sv
 Apd    |UV     |grok_bin       |NN const char* start|NN STRLEN* len_p|NN I32* flags|NULLOK NV *result
 #if defined(PERL_IN_REGCOMP_C) || defined(PERL_IN_TOKE_C)
 EMsR   |char   |grok_bslash_c  |const char source|const bool utf8|const bool output_warning
-EMsR   |bool   |grok_bslash_o  |NN char** s|NN UV* uv \
-                               |NN const char** error_msg   \
-                               |const bool output_warning   \
-                               |const bool strict|const bool utf8
-EMiR   |bool   |grok_bslash_x  |NN char** s|NN UV* uv \
-                               |NN const char** error_msg   \
-                               |const bool output_warning   \
-                               |const bool strict|const bool utf8
+EMsR   |bool   |grok_bslash_o  |NN char** s|NN UV* uv           \
+                               |NN const char** error_msg       \
+                               |const bool output_warning       \
+                               |const bool strict               \
+                               |const bool silence_non_portable \
+                               |const bool utf8
+EMiR   |bool   |grok_bslash_x  |NN char** s|NN UV* uv           \
+                               |NN const char** error_msg       \
+                               |const bool output_warning       \
+                               |const bool strict               \
+                               |const bool silence_non_portable \
+                               |const bool utf8
 #endif
 Apd    |UV     |grok_hex       |NN const char* start|NN STRLEN* len_p|NN I32* flags|NULLOK NV *result
 Apd    |int    |grok_number    |NN const char *pv|STRLEN len|NULLOK UV *valuep
diff --git a/embed.h b/embed.h
index 125c6a7..86d9006 100644 (file)
--- a/embed.h
+++ b/embed.h
 #  endif
 #  if defined(PERL_IN_REGCOMP_C) || defined(PERL_IN_TOKE_C)
 #define grok_bslash_c(a,b,c)   S_grok_bslash_c(aTHX_ a,b,c)
-#define grok_bslash_o(a,b,c,d,e,f)     S_grok_bslash_o(aTHX_ a,b,c,d,e,f)
-#define grok_bslash_x(a,b,c,d,e,f)     S_grok_bslash_x(aTHX_ a,b,c,d,e,f)
+#define grok_bslash_o(a,b,c,d,e,f,g)   S_grok_bslash_o(aTHX_ a,b,c,d,e,f,g)
+#define grok_bslash_x(a,b,c,d,e,f,g)   S_grok_bslash_x(aTHX_ a,b,c,d,e,f,g)
 #define regcurly(a)            S_regcurly(aTHX_ a)
 #  endif
 #  if defined(PERL_IN_REGCOMP_C) || defined(PERL_IN_UTF8_C)
diff --git a/proto.h b/proto.h
index 6123569..40784c2 100644 (file)
--- a/proto.h
+++ b/proto.h
@@ -6756,7 +6756,7 @@ PERL_CALLCONV SV* Perl__core_swash_init(pTHX_ const char* pkg, const char* name,
 STATIC char    S_grok_bslash_c(pTHX_ const char source, const bool utf8, const bool output_warning)
                        __attribute__warn_unused_result__;
 
-STATIC bool    S_grok_bslash_o(pTHX_ char** s, UV* uv, const char** error_msg, const bool output_warning, const bool strict, const bool utf8)
+STATIC bool    S_grok_bslash_o(pTHX_ char** s, UV* uv, const char** error_msg, const bool output_warning, const bool strict, const bool silence_non_portable, const bool utf8)
                        __attribute__warn_unused_result__
                        __attribute__nonnull__(pTHX_1)
                        __attribute__nonnull__(pTHX_2)
@@ -6764,7 +6764,7 @@ STATIC bool       S_grok_bslash_o(pTHX_ char** s, UV* uv, const char** error_msg, cons
 #define PERL_ARGS_ASSERT_GROK_BSLASH_O \
        assert(s); assert(uv); assert(error_msg)
 
-PERL_STATIC_INLINE bool        S_grok_bslash_x(pTHX_ char** s, UV* uv, const char** error_msg, const bool output_warning, const bool strict, const bool utf8)
+PERL_STATIC_INLINE bool        S_grok_bslash_x(pTHX_ char** s, UV* uv, const char** error_msg, const bool output_warning, const bool strict, const bool silence_non_portable, const bool utf8)
                        __attribute__warn_unused_result__
                        __attribute__nonnull__(pTHX_1)
                        __attribute__nonnull__(pTHX_2)
index c699996..ea6ba26 100644 (file)
--- a/regcomp.c
+++ b/regcomp.c
@@ -10620,6 +10620,9 @@ tryagain:
                                                       &error_msg,
                                                       TRUE, /* out warnings */
                                                        FALSE, /* not strict */
+                                                       TRUE, /* Output warnings
+                                                                for non-
+                                                                portables */
                                                        UTF);
                            if (! valid) {
                                RExC_parse = p; /* going to die anyway; point
@@ -10645,6 +10648,9 @@ tryagain:
                                                       &error_msg,
                                                       TRUE, /* out warnings */
                                                        FALSE, /* not strict */
+                                                       TRUE, /* Output warnings
+                                                                for non-
+                                                                portables */
                                                        UTF);
                            if (! valid) {
                                RExC_parse = p; /* going to die anyway; point
@@ -11568,6 +11574,8 @@ parseit:
                                               &error_msg,
                                               SIZE_ONLY,
                                                FALSE, /* Not strict */
+                                               TRUE, /* Output warnings for
+                                                         non-portables */
                                                UTF);
                    if (! valid) {
                        vFAIL(error_msg);
@@ -11586,6 +11594,8 @@ parseit:
                                               &error_msg,
                                               TRUE, /* Output warnings */
                                                FALSE, /* Not strict */
+                                               TRUE, /* Output warnings for
+                                                         non-portables */
                                                UTF);
                    if (! valid) {
                        vFAIL(error_msg);
diff --git a/toke.c b/toke.c
index dbadf60..8c53580 100644 (file)
--- a/toke.c
+++ b/toke.c
@@ -3292,6 +3292,8 @@ S_scan_const(pTHX_ char *start)
                    bool valid = grok_bslash_o(&s, &uv, &error,
                                                TRUE, /* Output warning */
                                                FALSE, /* Not strict */
+                                               TRUE, /* Output warnings for
+                                                         non-portables */
                                                UTF);
                    if (! valid) {
                        yyerror(error);
@@ -3308,6 +3310,8 @@ S_scan_const(pTHX_ char *start)
                    bool valid = grok_bslash_x(&s, &uv, &error,
                                                TRUE, /* Output warning */
                                                FALSE, /* Not strict */
+                                               TRUE,  /* Output warnings for
+                                                         non-portables */
                                                UTF);
                    if (! valid) {
                        yyerror(error);