bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] bypass broken inline strtod() definition in <stdlib.h> on Mi


From: Ben Pfaff
Subject: Re: [PATCH] bypass broken inline strtod() definition in <stdlib.h> on Mingw
Date: Sun, 13 Jun 2010 15:18:30 -0700
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux)

Bruno Haible <address@hidden> writes:

>> As you can see, this defines an inline version of strtod() that
>> conflicts with the out-of-line version in lib/strtod.c.
>> 
>> Is there an idiomatic solution for this kind of problem?
>
> Why does it conflict? gnulib's <stdlib.h> replacement already contains the
> idiomatic solution. As you can see from m4/strtod.m4, there are three cases:

Oops.  You are right, of course.

The problem is that AC_FUNC_STRTOD assumes that strtod does not
exist when cross-compiling, which in turn makes the strtod module
assume that it does not need to handle an existing declaration.

Here is a much better (and shorter) version.  Comments?

Thanks,

Ben.

--8<--------------------------cut here-------------------------->8--

>From 7765828c11c214d2d6de33b6b87ba2e94da2bc99 Mon Sep 17 00:00:00 2001
From: Ben Pfaff <address@hidden>
Date: Sun, 13 Jun 2010 15:13:48 -0700
Subject: [PATCH] Properly check for strtod() when cross-compiling.

* m4/strtod.m4: When cross-compiling, do not assume that no strtod()
implementation exists.  Check, and then replace the existing implementation
if there is one.  Fixes a problem with strtod() when cross-compiling to
Mingw.
---
 ChangeLog    |    8 ++++++++
 m4/strtod.m4 |   20 ++++++++++++++------
 2 files changed, 22 insertions(+), 6 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 8e057f7..2c4db7c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2010-06-10  Ben Pfaff  <address@hidden>
+
+       Properly check for strtod() when cross-compiling.
+       * m4/strtod.m4: When cross-compiling, do not assume that no
+       strtod() implementation exists.  Check, and then replace the
+       existing implementation if there is one.  Fixes a problem with
+       strtod() when cross-compiling to Mingw.
+
 2010-06-09  Ben Pfaff  <address@hidden>
 
        Provide means to uninstall ".bin" files installed by relocwrapper.
diff --git a/m4/strtod.m4 b/m4/strtod.m4
index 4cccb6d..f5977f4 100644
--- a/m4/strtod.m4
+++ b/m4/strtod.m4
@@ -1,4 +1,4 @@
-# strtod.m4 serial 14
+# strtod.m4 serial 15
 dnl Copyright (C) 2002-2003, 2006-2010 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -11,7 +11,13 @@ AC_DEFUN([gl_FUNC_STRTOD],
   dnl Note: AC_FUNC_STRTOD does AC_LIBOBJ([strtod]).
   if test $ac_cv_func_strtod = no; then
     HAVE_STRTOD=0
-    gl_PREREQ_STRTOD
+
+    # AC_FUNC_STRTOD assumes that strtod is missing when cross-compiling,
+    # but to reliably provide it we need to know whether it is declared.
+    AC_CHECK_DECLS_ONCE([strtod])
+    if test "$ac_cv_have_decl_strtod" = yes; then
+      REPLACE_STRTOD=1
+    fi
   else
     AC_CACHE_CHECK([whether strtod obeys C99], [gl_cv_func_strtod_works],
       [AC_RUN_IFELSE([AC_LANG_PROGRAM([[
@@ -77,10 +83,12 @@ numeric_equal (double x, double y)
         [gl_cv_func_strtod_works="guessing no"])])
     if test "$gl_cv_func_strtod_works" != yes; then
       REPLACE_STRTOD=1
-      gl_PREREQ_STRTOD
-      dnl Use undocumented macro to set POW_LIB correctly.
-      _AC_LIBOBJ_STRTOD
-    fi
+    fi  
+  fi
+  if test $HAVE_STRTOD = 0 || test $REPLACE_STRTOD = 1; then
+    gl_PREREQ_STRTOD
+    dnl Use undocumented macro to set POW_LIB correctly.
+    _AC_LIBOBJ_STRTOD
   fi
 ])
 
-- 
1.7.1


-- 
"It was then I realized how dire my medical situation was.  Here I was,
 a network admin, unable to leave, and here was someone with a broken
 network.  And they didn't ask me to fix it.  They didn't even try to
 casually pry a hint out of me." --Ryan Tucker in the Monastery



reply via email to

[Prev in Thread] Current Thread [Next in Thread]