diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2013-12-13 16:58:22 -0800 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2013-12-13 16:58:22 -0800 |
commit | ea5d89e3f5998f2664f3a9498274691d4b7165df (patch) | |
tree | 75cca3279b51e342d863d199427f33eb89835cd0 /ext | |
parent | d152d4826c802a9558c1c336d70bcfd6b5827634 (diff) | |
download | ffi-yajl-ea5d89e3f5998f2664f3a9498274691d4b7165df.tar.gz |
fix precision issue by using yajl_gen_number
yajl_gen_double disagrees with ruby's Float#to_s in incompatible ways
Diffstat (limited to 'ext')
-rw-r--r-- | ext/ffi_yajl/ext/encoder/encoder.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/ext/ffi_yajl/ext/encoder/encoder.c b/ext/ffi_yajl/ext/encoder/encoder.c index f4853dd..ee02435 100644 --- a/ext/ffi_yajl/ext/encoder/encoder.c +++ b/ext/ffi_yajl/ext/encoder/encoder.c @@ -132,10 +132,11 @@ static VALUE rb_cBignum_ffi_yajl(VALUE self, VALUE yajl_gen, VALUE state) { ID sym_to_s = rb_intern("to_s"); VALUE str = rb_funcall(self, sym_to_s, 0); char *cptr = RSTRING_PTR(str); + int len = RSTRING_LEN(str); if (memcmp(cptr, "NaN", 3) == 0 || memcmp(cptr, "Infinity", 8) == 0 || memcmp(cptr, "-Infinity", 9) == 0) { rb_raise(cEncodeError, "'%s' is an invalid number", cptr); } - rb_raise( rb_eNotImpError, "Bignum#ffi_yajl not implemented"); + yajl_gen_number((struct yajl_gen_t *) yajl_gen, cptr, len); return Qnil; } @@ -143,10 +144,11 @@ static VALUE rb_cFloat_ffi_yajl(VALUE self, VALUE yajl_gen, VALUE state) { ID sym_to_s = rb_intern("to_s"); VALUE str = rb_funcall(self, sym_to_s, 0); char *cptr = RSTRING_PTR(str); + int len = RSTRING_LEN(str); if (memcmp(cptr, "NaN", 3) == 0 || memcmp(cptr, "Infinity", 8) == 0 || memcmp(cptr, "-Infinity", 9) == 0) { rb_raise(cEncodeError, "'%s' is an invalid number", cptr); } - yajl_gen_double((struct yajl_gen_t *) yajl_gen, NUM2DBL(self)); + yajl_gen_number((struct yajl_gen_t *) yajl_gen, cptr, len); return Qnil; } |