On Tue, 27 Aug 2013, Jakub Hrozek wrote:

Now that patch doesn't apply any longer and when I fix it manually it still causes a compiler warning since there's now code using CARES_SIZEOF_LONG. I assume you do something else in Fedora/Red hat?

Yes, here is a patch that is used in the Fedora RPMs. For my use it's good enough as it covers the architectures on single platform I maintain. Not sure if it's good enough for upstream.

Right, it assumes that there's a <bits/wordsize.h> header that defines __WORDSIZE neither of which we can assume "globally".

How about instead relying on <limits.h> which is POSIX ? See my attachment for a fix I belive can work.

--

 / daniel.haxx.se
From f19387dd7243239f2f393220ba375b64f06731ed Mon Sep 17 00:00:00 2001
From: Daniel Stenberg <dan...@haxx.se>
Date: Tue, 27 Aug 2013 13:36:41 +0200
Subject: [PATCH] nowarn: use <limits.h> instead of configure for size of long

This makes the header file much more multi-arch friendly and can be used
as-is with both 32 bit and 64 bit builds.
---
 acinclude.m4  | 18 ------------------
 ares_nowarn.c | 25 +++++++++++--------------
 configure.ac  |  1 -
 3 files changed, 11 insertions(+), 33 deletions(-)

diff --git a/acinclude.m4 b/acinclude.m4
index ec7b0b2..c255198 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -1743,24 +1743,6 @@ cat >>confdefs.h <<_EOF
 _EOF
 ])
 
-
-dnl CARES_CONFIGURE_LONG
-dnl -------------------------------------------------
-dnl Find out the size of long as reported by sizeof() and define
-dnl CARES_SIZEOF_LONG as appropriate to be used in template file
-dnl ares_build.h.in to properly configure the library.
-dnl The size of long is a build time characteristic and as such
-dnl must be recorded in ares_build.h
-
-AC_DEFUN([CARES_CONFIGURE_LONG], [
-  if test -z "$ac_cv_sizeof_long" ||
-    test "$ac_cv_sizeof_long" -eq "0"; then
-    AC_MSG_ERROR([cannot find out size of long.])
-  fi
-  CARES_DEFINE_UNQUOTED([CARES_SIZEOF_LONG], [$ac_cv_sizeof_long])
-])
-
-
 dnl CARES_CONFIGURE_ARES_SOCKLEN_T
 dnl -------------------------------------------------
 dnl Find out suitable ares_socklen_t data type definition and size, making
diff --git a/ares_nowarn.c b/ares_nowarn.c
index a4dce89..d4bd272 100644
--- a/ares_nowarn.c
+++ b/ares_nowarn.c
@@ -1,5 +1,5 @@
 
-/* Copyright (C) 2010-2012 by Daniel Stenberg
+/* Copyright (C) 2010-2013 by Daniel Stenberg
  *
  * Permission to use, copy, modify, and distribute this
  * software and its documentation for any purpose and without
@@ -21,6 +21,10 @@
 #  include <assert.h>
 #endif
 
+#ifdef HAVE_LIMITS_H
+#include <limits.h>
+#endif
+
 #if defined(__INTEL_COMPILER) && defined(__unix__)
 
 #ifdef HAVE_NETINET_IN_H
@@ -65,20 +69,13 @@
 #  error "SIZEOF_INT not defined"
 #endif
 
-#if (CARES_SIZEOF_LONG == 2)
-#  define CARES_MASK_SLONG  0x7FFFL
-#  define CARES_MASK_ULONG  0xFFFFUL
-#elif (CARES_SIZEOF_LONG == 4)
-#  define CARES_MASK_SLONG  0x7FFFFFFFL
-#  define CARES_MASK_ULONG  0xFFFFFFFFUL
-#elif (CARES_SIZEOF_LONG == 8)
-#  define CARES_MASK_SLONG  0x7FFFFFFFFFFFFFFFL
-#  define CARES_MASK_ULONG  0xFFFFFFFFFFFFFFFFUL
-#elif (CARES_SIZEOF_LONG == 16)
-#  define CARES_MASK_SLONG  0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFL
-#  define CARES_MASK_ULONG  0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFUL
+#ifndef HAVE_LIMITS_H
+/* systems without <limits.h> we guess have 32 bit longs */
+#define CARES_MASK_SLONG  0x7FFFFFFFL
+#define CARES_MASK_ULONG  0xFFFFFFFFUL
 #else
-#  error "CARES_SIZEOF_LONG not defined"
+#define CARES_MASK_ULONG  ULONG_MAX
+#define CARES_MASK_SLONG  LONG_MAX
 #endif
 
 /*
diff --git a/configure.ac b/configure.ac
index 9492d7b..0ef8bd4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -457,7 +457,6 @@ AC_CHECK_SIZEOF(size_t)
 AC_CHECK_SIZEOF(long)
 AC_CHECK_SIZEOF(int)
 AC_CHECK_SIZEOF(short)
-CARES_CONFIGURE_LONG
 AC_CHECK_SIZEOF(time_t)
 
 AC_CHECK_TYPE(long long,
-- 
1.8.4.rc3

Reply via email to