diff options
author | Bram Moolenaar <Bram@vim.org> | 2010-05-19 21:57:45 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2010-05-19 21:57:45 +0200 |
commit | fa7584cb8627e3e4226b26ef1bff42f82b8eee1e (patch) | |
tree | 46a20dea1ca10f0b74cfc12d180b25982a0cef31 /src | |
parent | b702c84d0d3d9874a224d81b379f9287b4a58399 (diff) | |
download | vim-git-fa7584cb8627e3e4226b26ef1bff42f82b8eee1e.tar.gz |
Use UINT32_T in the code, define it to uint32_t or unsigned int.
Better autoconf check for uint32_t.
Diffstat (limited to 'src')
-rwxr-xr-x | src/auto/configure | 53 | ||||
-rw-r--r-- | src/blowfish.c | 46 | ||||
-rw-r--r-- | src/config.h.in | 2 | ||||
-rw-r--r-- | src/configure.in | 42 | ||||
-rw-r--r-- | src/netbeans.c | 6 | ||||
-rw-r--r-- | src/sha256.c | 26 | ||||
-rw-r--r-- | src/vim.h | 37 |
7 files changed, 138 insertions, 74 deletions
diff --git a/src/auto/configure b/src/auto/configure index 7537e9325..cc7d2a17e 100755 --- a/src/auto/configure +++ b/src/auto/configure @@ -8649,14 +8649,16 @@ fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi -for ac_header in stdarg.h stdlib.h string.h sys/select.h sys/utsname.h \ - termcap.h fcntl.h sgtty.h sys/ioctl.h sys/time.h sys/types.h termio.h \ - iconv.h langinfo.h math.h unistd.h stropts.h errno.h \ - sys/resource.h sys/systeminfo.h locale.h \ - sys/stream.h termios.h libc.h sys/statfs.h \ - poll.h sys/poll.h pwd.h utime.h sys/param.h libintl.h \ - libgen.h util/debug.h util/msg18n.h frame.h \ - sys/acl.h sys/access.h sys/sysinfo.h wchar.h wctype.h +for ac_header in stdarg.h stdint.h stdlib.h string.h \ + sys/select.h sys/utsname.h termcap.h fcntl.h \ + sgtty.h sys/ioctl.h sys/time.h sys/types.h \ + termio.h iconv.h inttypes.h langinfo.h math.h \ + unistd.h stropts.h errno.h sys/resource.h \ + sys/systeminfo.h locale.h sys/stream.h termios.h \ + libc.h sys/statfs.h poll.h sys/poll.h pwd.h \ + utime.h sys/param.h libintl.h libgen.h \ + util/debug.h util/msg18n.h frame.h sys/acl.h \ + sys/access.h sys/sysinfo.h wchar.h wctype.h do : as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default" @@ -9033,6 +9035,7 @@ _ACEOF ;; esac + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether time.h and sys/time.h may both be included" >&5 $as_echo_n "checking whether time.h and sys/time.h may both be included... " >&6; } if test "${ac_cv_header_time+set}" = set; then : @@ -11216,7 +11219,7 @@ _ACEOF if ac_fn_c_try_run "$LINENO"; then : ac_cv_sizeof_int=`cat conftestval` else - ac_cv_sizeof_int=0 + as_fn_error "failed to determine sizeof(int)" "$LINENO" 5 fi rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ conftest.$ac_objext conftest.beam conftest.$ac_ext @@ -11231,6 +11234,38 @@ cat >>confdefs.h <<_ACEOF _ACEOF +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking uint32_t is 32 bits" >&5 +$as_echo_n "checking uint32_t is 32 bits... " >&6; } +if test "$cross_compiling" = yes; then : + as_fn_error "could not compile program using uint32_t." "$LINENO" 5 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +#ifdef HAVE_STDINT_H +# include <stdint.h> +#endif +#ifdef HAVE_INTTYPES_H +# include <inttypes.h> +#endif +main() { + uint32_t nr1 = (uint32_t)-1; + uint32_t nr2 = (uint32_t)0xffffffffUL; + if (sizeof(uint32_t) != 4 || nr1 != 0xffffffffUL || nr2 + 1 != 0) exit(1); + exit(0); +} +_ACEOF +if ac_fn_c_try_run "$LINENO"; then : + { $as_echo "$as_me:${as_lineno-$LINENO}: result: ok" >&5 +$as_echo "ok" >&6; } +else + as_fn_error "WRONG! uint32_t not defined correctly." "$LINENO" 5 +fi +rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ + conftest.$ac_objext conftest.beam conftest.$ac_ext +fi + + bcopy_test_prog=' #include "confdefs.h" diff --git a/src/blowfish.c b/src/blowfish.c index ee64db65c..01e099306 100644 --- a/src/blowfish.c +++ b/src/blowfish.c @@ -21,7 +21,7 @@ #define BF_OFB_LEN (8*(BF_BLOCK)) typedef union { - uint32_t ul[2]; + UINT32_T ul[2]; char_u uc[8]; } block8; @@ -36,14 +36,14 @@ typedef union { # endif #endif -static void bf_e_block __ARGS((uint32_t *p_xl, uint32_t *p_xr)); +static void bf_e_block __ARGS((UINT32_T *p_xl, UINT32_T *p_xr)); static void bf_e_cblock __ARGS((char_u *block)); -static int bf_check_tables __ARGS((uint32_t ipa[18], uint32_t sbi[4][256], uint32_t val)); +static int bf_check_tables __ARGS((UINT32_T ipa[18], UINT32_T sbi[4][256], UINT32_T val)); static int bf_self_test __ARGS((void)); /* Blowfish code */ -static uint32_t pax[18]; -static uint32_t ipa[18] = { +static UINT32_T pax[18]; +static UINT32_T ipa[18] = { 0x243f6a88u, 0x85a308d3u, 0x13198a2eu, 0x03707344u, 0xa4093822u, 0x299f31d0u, 0x082efa98u, 0xec4e6c89u, 0x452821e6u, @@ -52,8 +52,8 @@ static uint32_t ipa[18] = { 0xb5470917u, 0x9216d5d9u, 0x8979fb1bu }; -static uint32_t sbx[4][256]; -static uint32_t sbi[4][256] = { +static UINT32_T sbx[4][256]; +static UINT32_T sbi[4][256] = { {0xd1310ba6u, 0x98dfb5acu, 0x2ffd72dbu, 0xd01adfb7u, 0xb8e1afedu, 0x6a267e96u, 0xba7c9045u, 0xf12c7f99u, 0x24a19947u, 0xb3916cf7u, 0x0801f2e2u, 0x858efc16u, @@ -331,10 +331,10 @@ static uint32_t sbi[4][256] = { static void bf_e_block(p_xl, p_xr) - uint32_t *p_xl; - uint32_t *p_xr; + UINT32_T *p_xl; + UINT32_T *p_xr; { - uint32_t temp, xl = *p_xl, xr = *p_xr; + UINT32_T temp, xl = *p_xl, xr = *p_xr; F1(0) F2(1) F1(2) F2(3) F1(4) F2(5) F1(6) F2(7) F1(8) F2(9) F1(10) F2(11) F1(12) F2(13) F1(14) F2(15) @@ -346,10 +346,10 @@ bf_e_block(p_xl, p_xr) #if 0 /* not used */ static void bf_d_block(p_xl, p_xr) - uint32_t *p_xl; - uint32_t *p_xr; + UINT32_T *p_xl; + UINT32_T *p_xr; { - uint32_t temp, xl = *p_xl, xr = *p_xr; + UINT32_T temp, xl = *p_xl, xr = *p_xr; F1(17) F2(16) F1(15) F2(14) F1(13) F2(12) F1(11) F2(10) F1(9) F2(8) F1(7) F2(6) F1(5) F2(4) F1(3) F2(2) xl ^= pax[1]; @@ -401,7 +401,7 @@ bf_key_init(password) char_u *password; { int i, j, keypos = 0; - uint32_t val, data_l, data_r; + UINT32_T val, data_l, data_r; char_u *key; int keylen; @@ -447,12 +447,12 @@ bf_key_init(password) */ static int bf_check_tables(ipa, sbi, val) - uint32_t ipa[18]; - uint32_t sbi[4][256]; - uint32_t val; + UINT32_T ipa[18]; + UINT32_T sbi[4][256]; + UINT32_T val; { int i, j; - uint32_t c = 0; + UINT32_T c = 0; for (i = 0; i < 18; i++) c ^= ipa[i]; @@ -467,7 +467,7 @@ typedef struct { char_u plaintxt[8]; char_u cryptxt[8]; char_u badcryptxt[8]; /* cryptxt when big/little endian is wrong */ - uint32_t keysum; + UINT32_T keysum; } struct_bf_test_data; /* @@ -493,6 +493,14 @@ bf_self_test() int i, bn; int err = 0; block8 bk; + UINT32_T ui = 0xffffffffUL; + + /* We can't simply use sizeof(UINT32_T), it would generate a compiler + * warning. */ + if (ui != 0xffffffffUL || ui + 1 != 0) { + err++; + EMSG(_("E820: sizeof(uint32_t) != 4")); + } if (!bf_check_tables(ipa, sbi, 0x6ffa520a)) err++; diff --git a/src/config.h.in b/src/config.h.in index c5f70fc8e..c57cd2fa4 100644 --- a/src/config.h.in +++ b/src/config.h.in @@ -216,6 +216,7 @@ #undef HAVE_FCNTL_H #undef HAVE_FRAME_H #undef HAVE_ICONV_H +#undef HAVE_INTTYPES_H #undef HAVE_LANGINFO_H #undef HAVE_LIBC_H #undef HAVE_LIBGEN_H @@ -228,6 +229,7 @@ #undef HAVE_PWD_H #undef HAVE_SETJMP_H #undef HAVE_SGTTY_H +#undef HAVE_STDINT_H #undef HAVE_STRINGS_H #undef HAVE_STROPTS_H #undef HAVE_SYS_ACCESS_H diff --git a/src/configure.in b/src/configure.in index 72138f78e..0068d34fa 100644 --- a/src/configure.in +++ b/src/configure.in @@ -2174,14 +2174,16 @@ if test $ac_cv_header_sys_wait_h = no; then AC_MSG_RESULT(no)) fi -AC_CHECK_HEADERS(stdarg.h stdlib.h string.h sys/select.h sys/utsname.h \ - termcap.h fcntl.h sgtty.h sys/ioctl.h sys/time.h sys/types.h termio.h \ - iconv.h langinfo.h math.h unistd.h stropts.h errno.h \ - sys/resource.h sys/systeminfo.h locale.h \ - sys/stream.h termios.h libc.h sys/statfs.h \ - poll.h sys/poll.h pwd.h utime.h sys/param.h libintl.h \ - libgen.h util/debug.h util/msg18n.h frame.h \ - sys/acl.h sys/access.h sys/sysinfo.h wchar.h wctype.h) +AC_CHECK_HEADERS(stdarg.h stdint.h stdlib.h string.h \ + sys/select.h sys/utsname.h termcap.h fcntl.h \ + sgtty.h sys/ioctl.h sys/time.h sys/types.h \ + termio.h iconv.h inttypes.h langinfo.h math.h \ + unistd.h stropts.h errno.h sys/resource.h \ + sys/systeminfo.h locale.h sys/stream.h termios.h \ + libc.h sys/statfs.h poll.h sys/poll.h pwd.h \ + utime.h sys/param.h libintl.h libgen.h \ + util/debug.h util/msg18n.h frame.h sys/acl.h \ + sys/access.h sys/sysinfo.h wchar.h wctype.h) dnl sys/ptem.h depends on sys/stream.h on Solaris AC_CHECK_HEADERS(sys/ptem.h, [], [], @@ -2247,6 +2249,7 @@ AC_TYPE_PID_T AC_TYPE_SIZE_T AC_TYPE_UID_T AC_TYPE_UINT32_T + AC_HEADER_TIME AC_CHECK_TYPE(ino_t, long) AC_CHECK_TYPE(dev_t, unsigned) @@ -2975,11 +2978,30 @@ main() exit(0); }], ac_cv_sizeof_int=`cat conftestval`, - ac_cv_sizeof_int=0, - AC_MSG_ERROR(failed to compile test program))]) + AC_MSG_ERROR([failed to determine sizeof(int)]), + AC_MSG_ERROR([failed to compile test program]))]) AC_MSG_RESULT($ac_cv_sizeof_int) AC_DEFINE_UNQUOTED(SIZEOF_INT, $ac_cv_sizeof_int) +dnl Make sure that uint32_t is really 32 bits unsigned. +AC_MSG_CHECKING([uint32_t is 32 bits]) +AC_TRY_RUN([ +#ifdef HAVE_STDINT_H +# include <stdint.h> +#endif +#ifdef HAVE_INTTYPES_H +# include <inttypes.h> +#endif +main() { + uint32_t nr1 = (uint32_t)-1; + uint32_t nr2 = (uint32_t)0xffffffffUL; + if (sizeof(uint32_t) != 4 || nr1 != 0xffffffffUL || nr2 + 1 != 0) exit(1); + exit(0); +}], +AC_MSG_RESULT(ok), +AC_MSG_ERROR([WRONG! uint32_t not defined correctly.]), +AC_MSG_ERROR([could not compile program using uint32_t.])) + dnl Check for memmove() before bcopy(), makes memmove() be used when both are dnl present, fixes problem with incompatibility between Solaris 2.4 and 2.5. diff --git a/src/netbeans.c b/src/netbeans.c index e058f9e8e..93a9aea75 100644 --- a/src/netbeans.c +++ b/src/netbeans.c @@ -43,12 +43,6 @@ # define sock_close(sd) closesocket(sd) # define sleep(t) Sleep(t*1000) /* WinAPI Sleep() accepts milliseconds */ #else - /* uint32_t may be defined by configure, but netdb.h indirectly includes - * stdint.h which tries to typedef uint32_t and fails. */ -# ifdef uint32_t -# undef uint32_t -# undef __uint32_t_defined -# endif # include <netdb.h> # include <netinet/in.h> # include <sys/socket.h> diff --git a/src/sha256.c b/src/sha256.c index de3211a92..9372d5f00 100644 --- a/src/sha256.c +++ b/src/sha256.c @@ -23,14 +23,14 @@ #ifdef FEAT_CRYPT typedef struct { - uint32_t total[2]; - uint32_t state[8]; + UINT32_T total[2]; + UINT32_T state[8]; char_u buffer[64]; } context_sha256_T; static void sha256_starts __ARGS((context_sha256_T *ctx)); static void sha256_process __ARGS((context_sha256_T *ctx, char_u data[64])); -static void sha256_update __ARGS((context_sha256_T *ctx, char_u *input, uint32_t length)); +static void sha256_update __ARGS((context_sha256_T *ctx, char_u *input, UINT32_T length)); static void sha256_finish __ARGS((context_sha256_T *ctx, char_u digest[32])); static char_u *sha256_bytes __ARGS((char_u *buf, int buflen)); static unsigned int get_some_time __ARGS((void)); @@ -38,10 +38,10 @@ static unsigned int get_some_time __ARGS((void)); #define GET_UINT32(n, b, i) \ { \ - (n) = ( (uint32_t)(b)[(i) ] << 24) \ - | ( (uint32_t)(b)[(i) + 1] << 16) \ - | ( (uint32_t)(b)[(i) + 2] << 8) \ - | ( (uint32_t)(b)[(i) + 3] ); \ + (n) = ( (UINT32_T)(b)[(i) ] << 24) \ + | ( (UINT32_T)(b)[(i) + 1] << 16) \ + | ( (UINT32_T)(b)[(i) + 2] << 8) \ + | ( (UINT32_T)(b)[(i) + 3] ); \ } #define PUT_UINT32(n,b,i) \ @@ -74,8 +74,8 @@ sha256_process(ctx, data) context_sha256_T *ctx; char_u data[64]; { - uint32_t temp1, temp2, W[64]; - uint32_t A, B, C, D, E, F, G, H; + UINT32_T temp1, temp2, W[64]; + UINT32_T A, B, C, D, E, F, G, H; GET_UINT32(W[0], data, 0); GET_UINT32(W[1], data, 4); @@ -207,9 +207,9 @@ sha256_process(ctx, data) sha256_update(ctx, input, length) context_sha256_T *ctx; char_u *input; - uint32_t length; + UINT32_T length; { - uint32_t left, fill; + UINT32_T left, fill; if (length == 0) return; @@ -255,8 +255,8 @@ sha256_finish(ctx, digest) context_sha256_T *ctx; char_u digest[32]; { - uint32_t last, padn; - uint32_t high, low; + UINT32_T last, padn; + UINT32_T high, low; char_u msglen[8]; high = (ctx->total[0] >> 29) | (ctx->total[1] << 3); @@ -32,10 +32,6 @@ # include "auto/config.h" # define HAVE_PATHDEF -/* Avoid a problem when stdint.h gets included later, autoconf defines - * uint32_t when it is not typedef'ed. */ -# define __uint32_t_defined - /* * Check if configure correctly managed to find sizeof(int). If this failed, * it becomes zero. This is likely a problem of not being able to run the @@ -52,6 +48,20 @@ # if defined(__CYGWIN32__) && defined(HAVE_FCHDIR) # undef HAVE_FCHDIR # endif + +/* We may need to define the uint32_t on non-Unix system, but using the same + * identifier causes conflicts. Therefore use UINT32_T. */ +# define UINT32_T uint32_t +#endif + +#if !defined(UINT32_T) +# if defined(uint32_t) /* this doesn't catch typedefs, unfortunately */ +# define UINT32_T uint32_t +# else + /* Fall back to assuming unsigned int is 32 bit. If this is wrong then the + * test in blowfish.c will fail. */ +# define UINT32_T unsigned int +# endif #endif /* user ID of root is usually zero, but not for everybody */ @@ -474,6 +484,12 @@ typedef unsigned long u8char_T; /* long should be 32 bits or more */ #include <assert.h> +#ifdef HAVE_STDINT_H +# include <stdint.h> +#endif +#ifdef HAVE_INTTYPES_H +# include <inttypes.h> +#endif #ifdef HAVE_WCTYPE_H # include <wctype.h> #endif @@ -1984,12 +2000,6 @@ typedef int VimClipboard; /* This is required for the prototypes. */ #endif -#if !defined(HAVE_CONFIG_H) && !defined(uint32_t) \ - && (defined(__CYGWIN32__) || defined(__MINGW32__)) - /* Assuming that MingW and Cygwin do not typedef uint32_t. */ -# define uint32_t unsigned int -#endif - /* ISSYMLINK(mode) tests if a file is a symbolic link. */ #if (defined(S_IFMT) && defined(S_IFLNK)) || defined(S_ISLNK) # define HAVE_ISSYMLINK @@ -2075,13 +2085,6 @@ typedef int VimClipboard; /* This is required for the prototypes. */ # undef bool # endif -/* uint32_t may be defined by configure, but perh.h may indirectly include - * stdint.h which tries to typedef uint32_t and fails. */ -# ifdef uint32_t -# undef uint32_t -# undef __uint32_t_defined -# endif - # ifdef __BORLANDC__ /* Borland has the structure stati64 but not _stati64 */ # define _stati64 stati64 |