rurban / Cpanel-JSON-XS

Improved fork of JSON-XS

Home Page:http://search.cpan.org/dist/Cpanel-JSON-XS/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

inf/nan detection on aix

pheuch opened this issue · comments

I have experienced the following failure when trying to build Cpanel-JSON-XS-4.19 on AIX

AIX 7.2 TL 4
compiler: IBM XL C/C++ for AIX, V12.1 (5765-J02, 5725-C72) Version: 12.01.0000.0017
perl-5.20.1 (osname=aix, osvers=6.1.0.0, archname=aix-thread-multi)

The failure looks like this

[0:t72] /home/perl_ph/.cpan/build/Cpanel-JSON-XS-4.19-2 $ perl Makefile.PL
probe for xlocale.h... "tmp.c", line 2.10: 1506-296 (S) #include file <xlocale.h> not found.
"tmp.c", line 5.25: 1506-275 (S) Unexpected text integer constant encountered.
"tmp.c", line 5.15: 1506-045 (S) Undeclared identifier locale_t.
not found
xlc_r -q32 -D_ALL_SOURCE -D_ANSI_C_SOURCE -D_POSIX_SOURCE -qmaxmem=-1 -qnoansialias -qlanglvl=extc99 -DUSE_NATIVE_DLOPEN -DNEED_PTHREAD_INIT -q32 -D_LARGE_FILES -o tmp  -brtl -bdynamic -b32 tmp.c -lbind -lnsl -ldbm -ldl -lld -lm -lcrypt -lpthreads -lc
Checking if your kit is complete...
Looks good
Generating a Unix-style Makefile
Writing Makefile for Cpanel::JSON::XS
Writing MYMETA.yml and MYMETA.json
[0:t72] /home/perl_ph/.cpan/build/Cpanel-JSON-XS-4.19-2 $ make
cp XS/Boolean.pm blib/lib/Cpanel/JSON/XS/Boolean.pm
cp XS/Type.pm blib/lib/Cpanel/JSON/XS/Type.pm
cp XS.pm blib/lib/Cpanel/JSON/XS.pm
Running Mkbootstrap for XS ()
        chmod 644 "XS.bs"
         "/usr/bin/perl" -MExtUtils::Command::MM -e 'cp_nonempty' -- XS.bs blib/arch/auto/Cpanel/JSON/XS/XS.bs 644
        "/usr/bin/perl" "/usr/opt/perl5/lib/5.20.1/ExtUtils/xsubpp"  -typemap '/usr/opt/perl5/lib/5.20.1/ExtUtils/typemap' -typemap '/home/perl_ph/.cpan/build/Cpanel-JSON-XS-4.19-2/typemap'  XS.xs > XS.xsc
        mv XS.xsc XS.c
        xlc_r -q32 -c    -D_ALL_SOURCE -D_ANSI_C_SOURCE -D_POSIX_SOURCE -qmaxmem=-1 -qnoansialias -qlanglvl=extc99 -DUSE_NATIVE_DLOPEN -DNEED_PTHREAD_INIT -q32 -D_LARGE_FILES -O    -DVERSION=\"4.19\"  -DXS_VERSION=\"4.19\"  "-I/usr/opt/perl5/lib/5.20.1/aix-thread-multi/CORE"   XS.c
        "/usr/bin/perl" -MExtUtils::Mksymlists  -e "Mksymlists('NAME'=>\"Cpanel::JSON::XS\", 'DLBASE' => 'XS', 'DL_FUNCS' => {  }, 'FUNCLIST' => [], 'IMPORTS' => {  }, 'DL_VARS' => []);"
        rm -f blib/arch/auto/Cpanel/JSON/XS/XS.so
        ld  -bhalt:4 -G -bI:/usr/opt/perl5/lib/5.20.1/aix-thread-multi/CORE/perl.exp  -bnoentry -lpthreads -lc -lm -bE:XS.exp XS.o  -o blib/arch/auto/Cpanel/JSON/XS/XS.so        
        chmod 755 blib/arch/auto/Cpanel/JSON/XS/XS.so
        cp bin/cpanel_json_xs blib/script/cpanel_json_xs
        "/usr/bin/perl" -MExtUtils::MY -e 'MY->fixin(shift)' -- blib/script/cpanel_json_xs
Manifying 1 pod document
Manifying 3 pod documents
[0:t72] /home/perl_ph/.cpan/build/Cpanel-JSON-XS-4.19-2 $ make test
         "/usr/bin/perl" -MExtUtils::Command::MM -e 'cp_nonempty' -- XS.bs blib/arch/auto/Cpanel/JSON/XS/XS.bs 644
        PERL_DL_NONLAZY=1 "/usr/bin/perl" "-MExtUtils::Command::MM" "-MTest::Harness" "-e" "undef *Test::Harness::Switches; test_harness(0, 'blib/lib', 'blib/arch')" -Mcommon::sense t/*.t
...
t/117_numbers.t ............ 1/25 
#   Failed test 'inf -> "inf" stringify_infnan(1)'
#   at t/117_numbers.t line 73.
#          got: '[INF.0]'
#     expected: '["inf"]'

#   Failed test '-inf -> "-inf"'
#   at t/117_numbers.t line 73.
#          got: '[-INF.0]'
#     expected: '["-inf"]'

#   Failed test 'nan -> "nan"'
#   at t/117_numbers.t line 73.
#          got: '[-NaNQ]'
#     expected: '["NANQ"]'

#   Failed test '-nan -> "-nan"'
#   at t/117_numbers.t line 73.
#          got: '[NaNQ]'
#     expected: '["NANQ"]'

#   Failed test '-nan -> "-nan"'
#   at t/117_numbers.t line 73.
#          got: '[NaNQ]'
#     expected: '["NANQ"]'

#   Failed test 'inf stringify_infnan(2)'
#   at t/117_numbers.t line 73.
#          got: '[INF.0]'
#     expected: '[inf]'

#   Failed test '-inf'
#   at t/117_numbers.t line 73.
#          got: '[-INF.0]'
#     expected: '[-inf]'

#   Failed test 'nan'
#   at t/117_numbers.t line 73.
#          got: '[-NaNQ]'
#     expected: '[NANQ]'

#   Failed test '-nan'
#   at t/117_numbers.t line 73.
#          got: '[NaNQ]'
#     expected: '[NANQ]'

#   Failed test '-nan'
#   at t/117_numbers.t line 73.
#          got: '[NaNQ]'
#     expected: '[NANQ]'

#   Failed test 'inf stringify_infnan(3)'
#   at t/117_numbers.t line 101.
#          got: '[INF.0]'
#     expected: '["inf"]'

#   Failed test '-inf'
#   at t/117_numbers.t line 102.
#          got: '[-INF.0]'
#     expected: '["-inf"]'

#   Failed test 'nan'
#   at t/117_numbers.t line 103.
#          got: '[-NaNQ]'
#     expected: '["nan"]'

#   Failed test 'nan or -nan'
#   at t/117_numbers.t line 104.
#          got: '[NaNQ]'
#     expected: '["nan"]'

#   Failed test 'nan or -nan'
#   at t/117_numbers.t line 105.
#          got: '[NaNQ]'
#     expected: '["nan"]'
# Looks like you failed 15 tests of 25.

Thanks, just another libc.
Will add support for that

Same issue on AIX 7.2 with xlc 16.1 compiler for reference, assuming when the AIX 7.2 libc support is added it will address this.

Thanks, I will add these strings for AIX

Can you test the inf-aix branch with AIX support?

same as before:

t/117_numbers.t ............ 1/25 
#   Failed test 'inf -> "inf" stringify_infnan(1)'
#   at t/117_numbers.t line 73.
#          got: '[INF.0]'
#     expected: '["inf"]'

#   Failed test '-inf -> "-inf"'
#   at t/117_numbers.t line 73.
#          got: '[-INF.0]'
#     expected: '["-inf"]'

#   Failed test 'nan -> "nan"'
#   at t/117_numbers.t line 73.
#          got: '[-NaNQ]'
#     expected: '["NANQ"]'

#   Failed test '-nan -> "-nan"'
#   at t/117_numbers.t line 73.
#          got: '[NaNQ]'
#     expected: '["NANQ"]'

#   Failed test '-nan -> "-nan"'
#   at t/117_numbers.t line 73.
#          got: '[NaNQ]'
#     expected: '["NANQ"]'

#   Failed test 'inf stringify_infnan(2)'
#   at t/117_numbers.t line 73.
#          got: '[INF.0]'
#     expected: '[inf]'

#   Failed test '-inf'
#   at t/117_numbers.t line 73.
#          got: '[-INF.0]'
#     expected: '[-inf]'

#   Failed test 'nan'
#   at t/117_numbers.t line 73.
#          got: '[-NaNQ]'
#     expected: '[NANQ]'

#   Failed test '-nan'
#   at t/117_numbers.t line 73.
#          got: '[NaNQ]'
#     expected: '[NANQ]'

#   Failed test '-nan'
#   at t/117_numbers.t line 73.
#          got: '[NaNQ]'
#     expected: '[NANQ]'

#   Failed test 'inf stringify_infnan(3)'
#   at t/117_numbers.t line 101.
#          got: '[INF.0]'
#     expected: '["inf"]'

#   Failed test '-inf'
#   at t/117_numbers.t line 102.
#          got: '[-INF.0]'
#     expected: '["-inf"]'

#   Failed test 'nan'
#   at t/117_numbers.t line 103.
#          got: '[-NaNQ]'
#     expected: '["nan"]'

#   Failed test 'nan or -nan'
#   at t/117_numbers.t line 104.
#          got: '[NaNQ]'
#     expected: '["nan"]'

#   Failed test 'nan or -nan'
#   at t/117_numbers.t line 105.
#          got: '[NaNQ]'
#     expected: '["nan"]'
# Looks like you failed 15 tests of 25.

I think I fixed the AIX problem now. There was another special case for QNAN around, which I removed.
Can you try inf-aix 26203a2

Thanks. Can I have a more detailed log of the failing test file? Same as before? Very strange if so.

Hello Reini, seems to be two problems in one issue. I opened the issue for AIX 7.2 TL 4. Perl 5.20.1. AIX 7.2 TL 5 is usung Perl 5.26.

Tested your fix in commit 26203a2 and nothing did change. Same error as before.

This needs to be debugged on AIX. I'll keep the old STD_QNAN string, this might need to be libc version-specific and the detection is also wrong.

commented

This is the same issue with a different set of tools in use, maybe this helps to understand and fix the issue:

uname -s
AIX
oslevel -s
7200-04-02-2028
gcc --version
gcc (GCC) 8.3.0

Configuration of the non-system perl (5.14.2) that we are working with and how perl was compiled with gcc in the past

perl -V:'(version|osname|osvers|archname|cc|gccversion)'
archname='aix-thread-multi-64all';
cc='gcc -maix64 -static-libgcc -maix64';
gccversion='4.4.5';
osname='aix';
osvers='6.1.0.0';
version='5.14.2';

Problems already occured when I have started to configure Cpanel-JSON-XS-4.25

perl Makefile.PL
probe for xlocale.h... tmp.c:2:10: fatal error: xlocale.h: No such file or directory
 #include <xlocale.h>
          ^~~~~~~~~~~
compilation terminated.
not found
gcc -maix64 -static-libgcc -maix64 -D_THREAD_SAFE -I/usr/local/perl-5.14.2_64_8/include -D_ALL_SOURCE -D_ANSI_C_SOURCE -D_POSIX_SOURCE -DUSE_NATIVE_DLOPEN -DNEED_PTHREAD_INIT -fno-strict-aliasing -pipe -I/usr/local/include -maix64 -DUSE_64_BIT_ALL -o tmp  -Wl,-brtl,-bexpall,-bmaxdata:0x80000000 -L/usr/local/perl-5.14.2_64_8/lib -Wl,-brtl -Wl,-bdynamic -Wl,-b64 tmp.c -lbind -lnsl -ldbm -ldl -lld -lm -lcrypt -lpthreads -lc
Checking if your kit is complete...
Looks good
Generating a Unix-style Makefile
Writing Makefile for Cpanel::JSON::XS
Writing MYMETA.yml and MYMETA.json

And now the test that is failing

make TEST_FILES=t/117_numbers.t test
Running Mkbootstrap for XS ()
chmod 644 "XS.bs"
"/usr/local/perl/bin/perl" -MExtUtils::Command::MM -e 'cp_nonempty' -- XS.bs blib/arch/auto/Cpanel/JSON/XS/XS.bs 644
"/usr/local/perl/bin/perl" "/usr/local/perl-5.14.2_64_8/lib/5.14.2/ExtUtils/xsubpp"  -typemap '/usr/local/perl-5.14.2_64_8/lib/5.14.2/ExtUtils/typemap' -typemap '/home/micsw/.cpan/build/Cpanel-JSON-XS-4.25-lK2SfT/typemap'  XS.xs > XS.xsc
mv XS.xsc XS.c
gcc -maix64 -static-libgcc -maix64 -c   -D_THREAD_SAFE -I/usr/local/perl-5.14.2_64_8/include -D_ALL_SOURCE -D_ANSI_C_SOURCE -D_POSIX_SOURCE -DUSE_NATIVE_DLOPEN -DNEED_PTHREAD_INIT -fno-strict-aliasing -pipe -I/usr/local/include -maix64 -DUSE_64_BIT_ALL -O2   -DVERSION=\"4.25\" -DXS_VERSION=\"4.25\"  "-I/usr/local/perl-5.14.2_64_8/lib/5.14.2/aix-thread-multi-64all/CORE"  -Wall -Werror=declaration-after-statement -Wextra -W XS.c
"/usr/local/perl/bin/perl" -MExtUtils::Mksymlists \
     -e "Mksymlists('NAME'=>\"Cpanel::JSON::XS\", 'DLBASE' => 'XS', 'DL_FUNCS' => {  }, 'FUNCLIST' => [], 'IMPORTS' => {  }, 'DL_VARS' => []);"
rm -f blib/arch/auto/Cpanel/JSON/XS/XS.so
gcc -maix64 -static-libgcc -maix64  -Wl,-b64 -Wl,-bhalt:4 -Wl,-G -Wl,-bI:/usr/local/perl-5.14.2_64_8/lib/5.14.2/aix-thread-multi-64all/CORE/perl.exp  -Wl,-bnoentry -lpthreads -lc -lm -L/usr/local/perl-5.14.2_64_8/lib -Wl,-bE:XS.exp XS.o  -o blib/arch/auto/Cpanel/JSON/XS/XS.so  \
      \

chmod 755 blib/arch/auto/Cpanel/JSON/XS/XS.so
cp XS/Boolean.pm blib/lib/Cpanel/JSON/XS/Boolean.pm
cp XS/Type.pm blib/lib/Cpanel/JSON/XS/Type.pm
cp XS.pm blib/lib/Cpanel/JSON/XS.pm
cp bin/cpanel_json_xs blib/script/cpanel_json_xs
"/usr/local/perl/bin/perl" -MExtUtils::MY -e 'MY->fixin(shift)' -- blib/script/cpanel_json_xs
PERL_DL_NONLAZY=1 "/usr/local/perl/bin/perl" "-MExtUtils::Command::MM" "-MTest::Harness" "-e" "undef *Test::Harness::Switches; test_harness(0, 'blib/lib', 'blib/arch')" t/117_numbers.t
t/117_numbers.t .. 1/25
#   Failed test 'inf -> "inf" stringify_infnan(1)'
#   at t/117_numbers.t line 73.
#          got: '[INF.0]'
#     expected: '["inf"]'

#   Failed test '-inf -> "-inf"'
#   at t/117_numbers.t line 73.
#          got: '[-INF.0]'
#     expected: '["-inf"]'

#   Failed test 'nan -> "nan"'
#   at t/117_numbers.t line 73.
#          got: '[-NaNQ]'
#     expected: '["NANQ"]'

#   Failed test '-nan -> "-nan"'
#   at t/117_numbers.t line 73.
#          got: '[NaNQ]'
#     expected: '["NANQ"]'

#   Failed test '-nan -> "-nan"'
#   at t/117_numbers.t line 73.
#          got: '[NaNQ]'
#     expected: '["NANQ"]'

#   Failed test 'inf stringify_infnan(2)'
#   at t/117_numbers.t line 73.
#          got: '[INF.0]'
#     expected: '[inf]'

#   Failed test '-inf'
#   at t/117_numbers.t line 73.
#          got: '[-INF.0]'
#     expected: '[-inf]'

#   Failed test 'nan'
#   at t/117_numbers.t line 73.
#          got: '[-NaNQ]'
#     expected: '[NANQ]'

#   Failed test '-nan'
#   at t/117_numbers.t line 73.
#          got: '[NaNQ]'
#     expected: '[NANQ]'

#   Failed test '-nan'
#   at t/117_numbers.t line 73.
#          got: '[NaNQ]'
#     expected: '[NANQ]'

#   Failed test 'inf stringify_infnan(3)'
#   at t/117_numbers.t line 101.
#          got: '[INF.0]'
#     expected: '["inf"]'

#   Failed test '-inf'
#   at t/117_numbers.t line 102.
#          got: '[-INF.0]'
#     expected: '["-inf"]'

#   Failed test 'nan'
#   at t/117_numbers.t line 103.
#          got: '[-NaNQ]'
#     expected: '["nan"]'

#   Failed test 'nan or -nan'
#   at t/117_numbers.t line 104.
#          got: '[NaNQ]'
#     expected: '["nan"]'

#   Failed test 'nan or -nan'
#   at t/117_numbers.t line 105.
#          got: '[NaNQ]'
#     expected: '["nan"]'
# Looks like you failed 15 tests of 25.
t/117_numbers.t .. Dubious, test returned 15 (wstat 3840, 0xf00)
Failed 15/25 subtests

Test Summary Report
-------------------
t/117_numbers.t (Wstat: 3840 Tests: 25 Failed: 15)
  Failed tests:  6-20
  Non-zero exit status: 15
Files=1, Tests=25,  0 wallclock secs ( 0.01 usr  0.00 sys +  0.02 cusr  0.00 csys =  0.03 CPU)
Result: FAIL
Failed 1/1 test programs. 15/25 subtests failed.
gmake: *** [Makefile:1221: test_dynamic] Error 15


Still the case for Cpanel-JSON-XS-4.36 on AIX 5.3.0.0/TL12-05 using 5.14.2/aix-64all
e.g.

#   Failed test 'inf stringify_infnan(3)'
#   at t/117_numbers.t line 101.
#          got: '[INF.0]'
#     expected: '["inf"]'

With vac.C 12.1.0.12, this patch gives me a full-PASS on AIX 5.3.0.0/TL12-05 as from the last post:

diff -purd a/XS.xs b/XS.xs
--- a/XS.xs	2023-03-02 16:10:08 +0100
+++ b/XS.xs	2023-05-25 16:19:26 +0200
@@ -88,15 +88,17 @@
 #define HAVE_NEG_NAN
 #define STR_NEG_INF "---"
 #define STR_NEG_NAN "?"
-#elif defined(_AIX)
+#elif defined(_AIX) || defined(_AIX50)
 /* xlC compiler: __TOS_AIX__ FIXME: This does not work yet. GH #165 */
-#define STR_INF "INF.0"
-#define STR_INF2 "-INF.0"
+#define STR_INF "INF"
+#define STR_INF2 "INF.0"
+#define HAVE_NEG_NAN
+#define STR_NEG_INF "-INF"
 #define HAVE_NEG_NAN
 #define HAVE_QNAN
 #define STR_NAN "NaN"
-//#define STR_QNAN "NaNQ"
-#define STR_QNAN "NANQ"
+#define STR_QNAN "NaNQ"
+//#define STR_QNAN "NANQ"
 #else
 #define STR_INF "inf"
 #define STR_NAN "nan"
@@ -2219,6 +2221,9 @@ encode_sv (pTHX_ enc_t *enc, SV *sv, SV 
             }
 #endif
 
+/* #if defined(_AIX) || defined(_AIX50)
+ * (void)fprintf (stderr, "#|# >%s<\n", enc->cur);
+ * #endif */
 #ifdef STR_INF4
           if (UNLIKELY(strEQc(enc->cur, STR_INF)
                        || strEQc(enc->cur, STR_INF2)
@@ -2237,6 +2242,13 @@ encode_sv (pTHX_ enc_t *enc, SV *sv, SV 
           else if (UNLIKELY(strEQc(enc->cur, STR_NEG_NAN)))
             inf_or_nan = 3;
 #endif
+#if defined(_AIX) || defined(_AIX50)
+          else if (UNLIKELY(strEQc(enc->cur, STR_INF)
+                         || strEQc(enc->cur, STR_INF2)))
+            inf_or_nan = 1;
+          else if (UNLIKELY(strEQc(enc->cur, STR_NEG_INF)))
+            inf_or_nan = 2;
+#endif
           else if
 #ifdef HAVE_QNAN
 # ifdef STR_QNAN2
diff -purd a/t/117_numbers.t b/t/117_numbers.t
--- a/t/117_numbers.t	2020-10-27 18:39:10 +0100
+++ b/t/117_numbers.t	2023-05-25 16:20:07 +0200
@@ -21,7 +21,7 @@ my (@inf, @neg_inf, @nan, @neg_nan);
 my ($inf, $nan) =
   ($^O eq 'MSWin32') ? ('1.#INF','1.#QNAN') :
   ($^O eq 'solaris') ? ('Infinity','NaN') :
-  ($^O eq 'aix')     ? ('inf','NANQ') :
+  ($^O eq 'aix')     ? ('INF','NaNQ') :
   ($^O eq 'hpux')    ? ('++','-?') :
                        ('inf','nan');
 my $neg_nan =

Thanks. Care for a PR? I'm just at the movies for the whole week, with cellphone only

commented

I have applied the patches to the commit master/14d815f and it works on AIX/7300-01-02-2320 too. Thx.

OK, I'll create a PR later today. Thanks for verifying!

Thanks, merged