Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Building on AIX fails with not expanding SIZE_MAX #1031

Closed
scddev opened this issue Dec 21, 2021 · 5 comments
Closed

Building on AIX fails with not expanding SIZE_MAX #1031

scddev opened this issue Dec 21, 2021 · 5 comments

Comments

@scddev
Copy link
Contributor

scddev commented Dec 21, 2021

A fresh git clone fails to build on AIX.

Surprisingly alloc.c works while hiredis.c and all other files (read.c, sds.c, ...) which would use hi_*alloc methods fail not expanding SIZE_MAX.

~/hiredis $ cmake -S . -B build
-- The C compiler identification is GNU 6.3.0
-- The CXX compiler identification is GNU 6.3.0
-- Check for working C compiler: /usr/bin/gcc
-- Check for working C compiler: /usr/bin/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
Detected version: 1.0.3
-- Configuring done
-- Generating done
-- Build files have been written to: /home/scd/hiredis/build
[~/hiredis $ cmake --build build
gmake[1]: Entering directory '/home/scd/hiredis/build'
gmake[2]: Entering directory '/home/scd/hiredis/build'
Scanning dependencies of target hiredis
gmake[2]: Leaving directory '/home/scd/hiredis/build'
gmake[2]: Entering directory '/home/scd/hiredis/build'
[  5%] Building C object CMakeFiles/hiredis.dir/alloc.c.o
[ 10%] Building C object CMakeFiles/hiredis.dir/async.c.o
[ 15%] Building C object CMakeFiles/hiredis.dir/dict.c.o
[ 20%] Building C object CMakeFiles/hiredis.dir/hiredis.c.o
In file included from /home/scd/hiredis/hiredis.h:46:0,
                 from /home/scd/hiredis/hiredis.c:41:
/home/scd/hiredis/alloc.h: In function 'hi_calloc':
/home/scd/hiredis/alloc.h:64:9: error: 'SIZE_MAX' undeclared (first use in this function)
     if (SIZE_MAX / size < nmemb)
         ^~~~~~~~
/home/scd/hiredis/alloc.h:64:9: note: each undeclared identifier is reported only once for each function it appears in
gmake[2]: *** [CMakeFiles/hiredis.dir/build.make;102: CMakeFiles/hiredis.dir/hiredis.c.o] Error 1
gmake[2]: Leaving directory '/home/scd/hiredis/build'
gmake[1]: *** [CMakeFiles/Makefile2;110: CMakeFiles/hiredis.dir/all] Error 2
gmake[1]: Leaving directory '/home/scd/hiredis/build'
gmake: *** [Makefile;163: all] Error 2

As a quickfix for me was removing the alloc.h from hiredis.h and adding it directly into the .c files after the fmacros.h include.

Also tried with a gcc 9 just to make sure the old gcc 6.3 is not causing any problem:

In file included from /home/scd/hiredis/hiredis.h:46,
                 from /home/scd/hiredis/hiredis.c:41:
/home/scd/hiredis/alloc.h: In function 'hi_calloc':
/home/scd/hiredis/alloc.h:64:9: error: 'SIZE_MAX' undeclared (first use in this function)
   64 |     if (SIZE_MAX / size < nmemb)
      |         ^~~~~~~~
/home/scd/hiredis/alloc.h:35:1: note: 'SIZE_MAX' is defined in header '<stdint.h>'; did you forget to '#include <stdint.h>'?
   34 | #include <stddef.h> /* for size_t */
  +++ |+#include <stdint.h>
   35 | #include <stdint.h>
/home/scd/hiredis/alloc.h:64:9: note: each undeclared identifier is reported only once for each function it appears in
   64 |     if (SIZE_MAX / size < nmemb)
      |         ^~~~~~~~
@scddev scddev changed the title Building on AIX fails Building on AIX fails with not expanding SIZE_MAX Dec 21, 2021
@michael-grunder
Copy link
Collaborator

I'm unfamiliar with AIX and don't have access to a machine with it, but this error doesn't make any sense to me.

According to the c99 standard SIZE_MAX will be defined in stdint.h, which we are including.

Is AIX non-compliant, or am I totally confused?

@scddev
Copy link
Contributor Author

scddev commented Dec 22, 2021

I tracked it down to _XOPEN_SOURCE in fmacros.h, as soon as it is not defined, everything works as expected. Will try to dig a little what parts are switched on/off in stdint.h.

diff --git a/fmacros.h b/fmacros.h
index 3227faa..754a53c 100644
--- a/fmacros.h
+++ b/fmacros.h
@@ -1,8 +1,10 @@
 #ifndef __HIREDIS_FMACRO_H
 #define __HIREDIS_FMACRO_H
 
+#ifndef _AIX
 #define _XOPEN_SOURCE 600
 #define _POSIX_C_SOURCE 200112L
+#endif
 
 #if defined(__APPLE__) && defined(__MACH__)
 /* Enable TCP_KEEPALIVE */

A look in the history of fmacros.h revealed a similar solution already in 952a33f.

@michael-grunder
Copy link
Collaborator

Thanks for investigating. I'm open to a PR that compiles for you.

I'd gladly do it myself but I don't have access to an AIX machine.

@scddev
Copy link
Contributor Author

scddev commented Dec 23, 2021

Will have a look after my vacation.

My other platform will be Solaris, I will take a look at that one too. There was also some handling in fmacros.h previously.

@michael-grunder
Copy link
Collaborator

Closing via f2e8010

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants