diff options
author | Tony Cook <tony@develop-help.com> | 2020-01-22 15:38:15 +1100 |
---|---|---|
committer | Tony Cook <tony@develop-help.com> | 2020-03-04 15:18:56 +1100 |
commit | 61656d9bbdc24db0c87d2062a110e0b87515f976 (patch) | |
tree | 880df011c2a620186c0b86a8559499f4948d44a3 | |
parent | f6231ebfc0a4a5472c54d7a8d9fb20a2daa9bf37 (diff) | |
download | perl-61656d9bbdc24db0c87d2062a110e0b87515f976.tar.gz |
APItest: get a compile-time warning if IVdf doesn't match IV_MAX
and similarly for UVuf/UV_MAX.
This already warns in PPPort, but that's for testing PPPort, not
the core.
-rw-r--r-- | ext/XS-APItest/APItest.xs | 11 | ||||
-rw-r--r-- | ext/XS-APItest/t/printf.t | 14 |
2 files changed, 24 insertions, 1 deletions
diff --git a/ext/XS-APItest/APItest.xs b/ext/XS-APItest/APItest.xs index bc4805127a..3cf8eeff86 100644 --- a/ext/XS-APItest/APItest.xs +++ b/ext/XS-APItest/APItest.xs @@ -4505,6 +4505,17 @@ PerlIO_stdin() FILE * PerlIO_exportFILE(PerlIO *f, const char *mode) +SV * +test_MAX_types() + CODE: + /* tests that IV_MAX and UV_MAX have types suitable + for the IVdf and UVdf formats. + If this warns then don't add casts here. + */ + RETVAL = newSVpvf("iv %" IVdf " uv %" UVuf, IV_MAX, UV_MAX); + OUTPUT: + RETVAL + MODULE = XS::APItest PACKAGE = XS::APItest::AUTOLOADtest int diff --git a/ext/XS-APItest/t/printf.t b/ext/XS-APItest/t/printf.t index 968fdc4627..28f21e35e1 100644 --- a/ext/XS-APItest/t/printf.t +++ b/ext/XS-APItest/t/printf.t @@ -6,7 +6,7 @@ BEGIN { } } -use Test::More tests => 11; +use Test::More tests => 12; BEGIN { use_ok('XS::APItest') }; @@ -51,3 +51,15 @@ SKIP: { is($output[4], "7.000", "print_long_double"); } +{ + # GH #17338 + # This is unlikely to fail here since int and long are the + # same size on our usual platforms, but it's less likely to + # be ignored than the warning that's the real diagnostic + # for this bug. + my $uv_max = ~0; + my $iv_max = $uv_max >> 1; + my $max_out = "iv $iv_max uv $uv_max"; + is(test_MAX_types(), $max_out, + "check types for IV_MAX and UV_MAX match IVdf/UVuf"); +} |