Skip to content

Commit

Permalink
Add flag to num groks to silence non-portable warnings
Browse files Browse the repository at this point in the history
Unicode inversion lists commonly will contain UV_MAX, which may
trigger these warnings.  Add a flag to suppress them to the numeric
grok functions, which can be set by the code that is dealing with
these lists
  • Loading branch information
Karl Williamson committed Jul 3, 2011
1 parent f1b6712 commit 0247078
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
21 changes: 18 additions & 3 deletions numeric.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ C<PERL_SCAN_ALLOW_UNDERSCORES> is set in I<*flags> then the binary
number may use '_' characters to separate digits.
=cut
Not documented yet because experimental is C<PERL_SCAN_SILENT_NON_PORTABLE
which suppresses any message for non-portable numbers that are still valid
on this platform.
*/

UV
Expand Down Expand Up @@ -206,7 +210,8 @@ Perl_grok_bin(pTHX_ const char *start, STRLEN *len_p, I32 *flags, NV *result)

if ( ( overflowed && value_nv > 4294967295.0)
#if UVSIZE > 4
|| (!overflowed && value > 0xffffffff )
|| (!overflowed && value > 0xffffffff
&& ! (*flags & PERL_SCAN_SILENT_NON_PORTABLE))
#endif
) {
Perl_ck_warner(aTHX_ packWARN(WARN_PORTABLE),
Expand Down Expand Up @@ -248,6 +253,10 @@ C<PERL_SCAN_ALLOW_UNDERSCORES> is set in I<*flags> then the hex
number may use '_' characters to separate digits.
=cut
Not documented yet because experimental is C<PERL_SCAN_SILENT_NON_PORTABLE
which suppresses any message for non-portable numbers that are still valid
on this platform.
*/

UV
Expand Down Expand Up @@ -323,7 +332,8 @@ Perl_grok_hex(pTHX_ const char *start, STRLEN *len_p, I32 *flags, NV *result)

if ( ( overflowed && value_nv > 4294967295.0)
#if UVSIZE > 4
|| (!overflowed && value > 0xffffffff )
|| (!overflowed && value > 0xffffffff
&& ! (*flags & PERL_SCAN_SILENT_NON_PORTABLE))
#endif
) {
Perl_ck_warner(aTHX_ packWARN(WARN_PORTABLE),
Expand Down Expand Up @@ -363,6 +373,10 @@ If C<PERL_SCAN_ALLOW_UNDERSCORES> is set in I<*flags> then the octal
number may use '_' characters to separate digits.
=cut
Not documented yet because experimental is C<PERL_SCAN_SILENT_NON_PORTABLE
which suppresses any message for non-portable numbers that are still valid
on this platform.
*/

UV
Expand Down Expand Up @@ -428,7 +442,8 @@ Perl_grok_oct(pTHX_ const char *start, STRLEN *len_p, I32 *flags, NV *result)

if ( ( overflowed && value_nv > 4294967295.0)
#if UVSIZE > 4
|| (!overflowed && value > 0xffffffff )
|| (!overflowed && value > 0xffffffff
&& ! (*flags & PERL_SCAN_SILENT_NON_PORTABLE))
#endif
) {
Perl_ck_warner(aTHX_ packWARN(WARN_PORTABLE),
Expand Down
2 changes: 2 additions & 0 deletions perl.h
Original file line number Diff line number Diff line change
Expand Up @@ -5543,6 +5543,8 @@ int flock(int fd, int op);
#define PERL_SCAN_ALLOW_UNDERSCORES 0x01 /* grok_??? accept _ in numbers */
#define PERL_SCAN_DISALLOW_PREFIX 0x02 /* grok_??? reject 0x in hex etc */
#define PERL_SCAN_SILENT_ILLDIGIT 0x04 /* grok_??? not warn about illegal digits */
#define PERL_SCAN_SILENT_NON_PORTABLE 0x08 /* grok_??? not warn about very large
numbers which are <= UV_MAX */
/* Output flags: */
#define PERL_SCAN_GREATER_THAN_UV_MAX 0x02 /* should this merge with above? */

Expand Down
13 changes: 9 additions & 4 deletions utf8.c
Original file line number Diff line number Diff line change
Expand Up @@ -2268,7 +2268,9 @@ S_swash_scan_list_line(pTHX_ U8* l, U8* const lend, UV* min, UV* max, UV* val,
{
const int typeto = typestr[0] == 'T' && typestr[1] == 'o';
STRLEN numlen; /* Length of the number */
I32 flags = PERL_SCAN_SILENT_ILLDIGIT | PERL_SCAN_DISALLOW_PREFIX;
I32 flags = PERL_SCAN_SILENT_ILLDIGIT
| PERL_SCAN_DISALLOW_PREFIX
| PERL_SCAN_SILENT_NON_PORTABLE;

/* nl points to the next \n in the scan */
U8* const nl = (U8*)memchr(l, '\n', lend - l);
Expand All @@ -2288,7 +2290,9 @@ S_swash_scan_list_line(pTHX_ U8* l, U8* const lend, UV* min, UV* max, UV* val,
/* The max range value follows, separated by a BLANK */
if (isBLANK(*l)) {
++l;
flags = PERL_SCAN_SILENT_ILLDIGIT | PERL_SCAN_DISALLOW_PREFIX;
flags = PERL_SCAN_SILENT_ILLDIGIT
| PERL_SCAN_DISALLOW_PREFIX
| PERL_SCAN_SILENT_NON_PORTABLE;
numlen = lend - l;
*max = grok_hex((char *)l, &numlen, &flags, NULL);
if (numlen)
Expand All @@ -2301,8 +2305,9 @@ S_swash_scan_list_line(pTHX_ U8* l, U8* const lend, UV* min, UV* max, UV* val,
if (wants_value) {
if (isBLANK(*l)) {
++l;
flags = PERL_SCAN_SILENT_ILLDIGIT |
PERL_SCAN_DISALLOW_PREFIX;
flags = PERL_SCAN_SILENT_ILLDIGIT
| PERL_SCAN_DISALLOW_PREFIX
| PERL_SCAN_SILENT_NON_PORTABLE;
numlen = lend - l;
*val = grok_hex((char *)l, &numlen, &flags, NULL);
if (numlen)
Expand Down

0 comments on commit 0247078

Please sign in to comment.