lloyd / yajl

A fast streaming JSON parsing library in C.
http://lloyd.github.com/yajl
ISC License
2.15k stars 436 forks source link

isinf sometimes missing on solaris/open solaris #18

Open razamatan opened 13 years ago

razamatan commented 13 years ago

i was basically getting symbol missing errors with yajl on open solaris. it turns out the box's math.h doesn't have isinf.

i googled, and this is problematic for a lot of other projects: http://www.google.com/search?q=open+solaris+isinf+undefined

the mysql bug thread is particularly convincing: http://bugs.mysql.com/bug.php?id=14862

for now, i got my yajl working by hacking this in there, but i know it's not safe since it's not testing for the environment to have ieeefp.h. sigh.

diff --git a/src/yajl_gen.c b/src/yajl_gen.c
index 548d948..5a66e22 100644
--- a/src/yajl_gen.c
+++ b/src/yajl_gen.c
@@ -194,6 +194,10 @@ yajl_gen_integer(yajl_gen g, long int number)
 #define isnan _isnan
 #define isinf !_finite
 #endif
+#ifndef isinf
+#include <ieeefp.h>
+#define isinf(x) (!finite((x)) && (x)==(x))
+#endif

 yajl_gen_status
 yajl_gen_double(yajl_gen g, double number)

feel free to run w/ the environment checks.

fyi, i'm using yajl by way of py-yajl. this hack worked pretty well since it seems that the py-yajl build process ignores the necessity for cmake and goes straight to compiling using gcc. i'll likely file an issue with py-yajl with a fix to pass in some -Dsymbol to force the isinf setting. perhaps if the fix were to read #ifdef MISSING_ISINF based on not finding isinf in math.h, then i can do a similar test in py-yajl's setup.py to set that as an extra compiler flag.

thanks.

acme commented 13 years ago

I've noticed this too. I use the following for JSON::YAJL, my Perl interface:

diff --git a/yajl/yajl_gen.c b/yajl/yajl_gen.c
index d4770bb..fbc5187 100644
--- a/yajl/yajl_gen.c
+++ b/yajl/yajl_gen.c
@@ -195,6 +195,14 @@ yajl_gen_integer(yajl_gen g, long int number)
 #define isinf !_finite
 #endif

+/* Solaris doesn't have isinf? */
+#if defined (__SVR4) && defined (__sun)
+#ifndef isinf
+#include 
+#define isinf(x) (!finite((x)) && (x)==(x))
+#endif
+#endif
+
 yajl_gen_status
 yajl_gen_double(yajl_gen g, double number)
 {
acme commented 13 years ago

Just to let you know that I need to I apply a similar patch for YAJL 2.