Permalink
Browse files

fixed GC bug in Oj::Doc

  • Loading branch information...
1 parent a758900 commit 39423df5d79b1df52547c8a970d0226cd263a435 Peter Ohler committed Jul 6, 2012
Showing with 9 additions and 17 deletions.
  1. +2 −14 README.md
  2. +6 −2 ext/oj/fast.c
  3. +1 −1 lib/oj/version.rb
View
@@ -32,21 +32,9 @@ A fast JSON parser and Object marshaller as a Ruby gem.
## <a name="release">Release Notes</a>
-### Release 1.2.11
+### Release 1.2.12
- - Added :max_stack option to limit the size of string allocated on the stack.
-
-### Release 1.2.10
-
- - Added check for circular on loading of circular dumped JSON.
-
- - Added support for direct serialization of BigDecimal, Rational, Date, and DateTime.
-
- - Added json.rb to $" in mimic mode to avoid pulling in the real JSON by accident.
-
- - Oj is now thread safe for all functions.
-
- - The / (solidus) character is now placed in strings without being escaped.
+ - Fixed GC bug in Oj::Doc, the fast parser.
## <a name="description">Description</a>
View
@@ -562,7 +562,7 @@ read_obj(ParseInfo pi) {
} else if (',' == *pi->s) {
pi->s++;
} else {
- printf("*** '%s'\n", pi->s);
+ //printf("*** '%s'\n", pi->s);
raise_error("invalid format, expected , or } while in an object", pi->str, pi->s);
}
*end = '\0';
@@ -839,10 +839,12 @@ parse_json(VALUE clas, char *json, int given, int allocated) {
pi.doc = doc;
// last arg is free func void* func(void*)
doc->self = rb_data_object_alloc(clas, doc, 0, free_doc_cb);
+ rb_gc_register_address(&doc->self);
doc->json = json;
DATA_PTR(doc->self) = doc;
result = rb_protect(protect_open_proc, (VALUE)&pi, &ex);
if (given || 0 != ex) {
+ rb_gc_unregister_address(&doc->self);
DATA_PTR(doc->self) = 0;
doc_free(pi.doc);
if (allocated) {
@@ -1318,11 +1320,12 @@ doc_type(int argc, VALUE *argv, VALUE self) {
*/
static VALUE
doc_fetch(int argc, VALUE *argv, VALUE self) {
- Doc doc = self_doc(self);
+ Doc doc;
Leaf leaf;
VALUE val = Qnil;
const char *path = 0;
+ doc = self_doc(self);
if (1 <= argc) {
Check_Type(*argv, T_STRING);
path = StringValuePtr(*argv);
@@ -1584,6 +1587,7 @@ static VALUE
doc_close(VALUE self) {
Doc doc = self_doc(self);
+ rb_gc_unregister_address(&doc->self);
DATA_PTR(doc->self) = 0;
if (0 != doc) {
xfree(doc->json);
View
@@ -1,5 +1,5 @@
module Oj
# Current version of the module.
- VERSION = '1.2.11'
+ VERSION = '1.2.12'
end

0 comments on commit 39423df

Please sign in to comment.