aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPetri Lehtinen <petri@digip.org>2013-08-15 09:26:29 +0300
committerPetri Lehtinen <petri@digip.org>2013-08-15 09:30:03 +0300
commit5639db6bea63bcccb9c6847b20486dc1178e5cbb (patch)
tree9cec535760f6505f5afdf6c628b65db9137a15c1
parent49ad5328c7a8c5140abc59a4756f7c82950c850e (diff)
downloadjansson-isnan-isinf-checks.zip
jansson-isnan-isinf-checks.tar.gz
jansson-isnan-isinf-checks.tar.bz2
Check for isnan() and isinf() by linkingisnan-isinf-checks
-rw-r--r--configure.ac31
-rw-r--r--jansson.pc.in1
-rw-r--r--src/jansson_config.h.in5
-rw-r--r--src/value.c9
-rw-r--r--win32/jansson_config.h5
5 files changed, 47 insertions, 4 deletions
diff --git a/configure.ac b/configure.ac
index 91d783f..d0707d0 100644
--- a/configure.ac
+++ b/configure.ac
@@ -43,6 +43,37 @@ case "$ac_cv_header_locale_h$ac_cv_func_localeconv" in
esac
AC_SUBST([json_have_localeconv])
+# isinf/isnan
+AC_MSG_CHECKING([whether isnan and isinf are defined and/or need -lm])
+AC_LANG([C])
+
+# First, test without -lm
+isnan_isinf_found=no
+AC_LINK_IFELSE(
+ [AC_LANG_PROGRAM([#include <math.h>], [isnan(0.1); isinf(0.1);])],
+ [AC_MSG_RESULT([defined, -lm not needed]); isnan_isinf_found=yes]
+)
+
+if test "x$isnan_isinf_found" = "xno"; then
+ # Not found, test with -lm
+ libs_before_test=$LIBS
+ LIBS="$LIBS -lm"
+ AC_LINK_IFELSE(
+ [AC_LANG_PROGRAM([#include <math.h>], [isnan(0.1); isinf(0.1);])],
+ [AC_MSG_RESULT([defined, -lm needed]); isnan_isinf_found=yes],
+ [LIBS=$libs_before_test]
+ )
+fi
+
+if test "x$isnan_isinf_found" = "xno"; then
+ # Still not found
+ AC_MSG_RESULT([not defined])
+ json_have_isnan_isinf=0
+else
+ json_have_isnan_isinf=1
+fi
+AC_SUBST([json_have_isnan_isinf])
+
AC_CONFIG_FILES([
jansson.pc
Makefile
diff --git a/jansson.pc.in b/jansson.pc.in
index d9bf4da..b35925a 100644
--- a/jansson.pc.in
+++ b/jansson.pc.in
@@ -7,4 +7,5 @@ Name: Jansson
Description: Library for encoding, decoding and manipulating JSON data
Version: @VERSION@
Libs: -L${libdir} -ljansson
+Libs.private: @LIBS@
Cflags: -I${includedir}
diff --git a/src/jansson_config.h.in b/src/jansson_config.h.in
index 785801f..7c27c97 100644
--- a/src/jansson_config.h.in
+++ b/src/jansson_config.h.in
@@ -36,4 +36,9 @@
otherwise to 0. */
#define JSON_HAVE_LOCALECONV @json_have_localeconv@
+/* If isnan() and isinf() are available in math.h, define to 1,
+ otherwise to 0. Note that you may need to link with -lm on some
+ systems. */
+#define JSON_HAVE_ISNAN_ISINF @json_have_isnan_isinf@
+
#endif
diff --git a/src/value.c b/src/value.c
index 582849b..083dadb 100644
--- a/src/value.c
+++ b/src/value.c
@@ -19,11 +19,12 @@
#include "jansson_private.h"
#include "utf.h"
-/* Work around nonstandard isnan() and isinf() implementations */
-#ifndef isnan
+/* Work around missing isnan() and isinf() implementations */
+#if !JSON_HAVE_ISNAN_ISINF
+/* Undef them just to be sure */
+#undef isnan
+#undef isinf
static JSON_INLINE int isnan(double x) { return x != x; }
-#endif
-#ifndef isinf
static JSON_INLINE int isinf(double x) { return !isnan(x) && isnan(x - x); }
#endif
diff --git a/win32/jansson_config.h b/win32/jansson_config.h
index ab1da5d..f3afc48 100644
--- a/win32/jansson_config.h
+++ b/win32/jansson_config.h
@@ -36,4 +36,9 @@
otherwise to 0. */
#define JSON_HAVE_LOCALECONV 1
+/* If isnan() and isinf() are available in math.h, define to 1,
+ otherwise to 0. Note that you may need to link with -lm on some
+ systems. */
+#define JSON_HAVE_ISNAN_ISINF 1
+
#endif