pkgsrc-Users archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Portable replacement for __WORDSIZE define?
Hi,
I'm currently working on getting glusterfs-10.3 working in pkgsrc, since
earlier versions (tested 8.2 (current pkgsrc), 9.2) die on sparc64 with
SIGBUS due to misaligned access, which appears to have been fixed sometime
before the 10.3 version.
I've managed to build & install the package on NetBSD/sparc64 9.3 and
after superficial testing (mount gluster export, read & write), things
seem to work.
However, during the build I ran into two Linuxisms in glusterfs-10.3:
- use of bash syntax in configure (of all places);
- once found, easy to patch out, so not much of an issue
- upstream bug: https://github.com/gluster/glusterfs/issues/3940
- glusterfs-10.3 uses __WORDSIZE to figure out if the system is
32 or 64 bit - but that one comes out of the Linux includes, e.g.
/usr/include/x86_64-linux-gnu/bits/wordsize.h on a 64 bit Linux box
and predictably, on NetBSD the C compiler barfs about that
The __WORDSIZE issue shows up in libglusterfs/src/glusterfs/dict.h:
322 /* POSIX-compliant systems requires the 'time_t' to be a signed integer. */
323 #if __WORDSIZE == 64
324 #define dict_get_time(dict, key, val) dict_get_int64((dict), (key), (val))
325 #define dict_set_time(dict, key, val) dict_set_int64((dict), (key), (val))
326 #elif __WORDSIZE == 32
327 #define dict_get_time(dict, key, val) \
328 dict_get_int32((dict), (key), ((int32_t *)(val)))
329 #define dict_set_time(dict, key, val) \
330 dict_set_int32((dict), (key), ((int32_t)(val)))
331 #else
332 #error "unknown word size"
333 #endif /* WORDSIZE check */
Just to be able to build the code I simply dropped "#define __WORDSIZE 64"
in front of the above, but that is obviously just a strictly local hack.
I'm sure I'm not the first one to run into this on a non-Linux platform,
but digging around didn't yield any obvious clean portable replacement.
Sure, I can just check what comes back from sizeof(void *) to get the
pointer size in C code to see if it is 32 or 64 bit, but the snippet above
relies on a preprocessor define.
One variant I found (in cmocka) basically looks for either the C language
data model defines or the CPU architecture defines to figure this out:
/* If __WORDSIZE is not set, try to figure it out and default to 32 bit. */
#ifndef __WORDSIZE
# if (defined(__x86_64__) && !defined(__ILP32__)) || defined(__sparc_v9__) || defined(__sparcv9)
# define __WORDSIZE 64
# else
# define __WORDSIZE 32
# endif
#endif
And given that there aren't all _that_ many 64 bit architectures around,
that might be one approach. But I hope someone with a better understanding
of portable C programming than me has a better solution.
Hoping for help,
Alex.
--
"Opportunity is missed by most people because it is dressed in overalls and
looks like work." -- Thomas A. Edison
Home |
Main Index |
Thread Index |
Old Index