Skip to content

Commit

Permalink
Revert "Remove checking whether rb_gc_mark_movable exists (#876)"
Browse files Browse the repository at this point in the history
This reverts commit 7e991e6.
  • Loading branch information
Watson1978 committed May 7, 2023
1 parent 7e991e6 commit 326353e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions ext/oj/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
}

# Support for compaction.
have_func('rb_gc_mark_movable')
have_func('stpcpy')
have_func('pthread_mutex_init')
have_func('rb_enc_interned_str')
Expand Down
16 changes: 13 additions & 3 deletions ext/oj/fast.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@
// #define BATCH_SIZE (4096 / sizeof(struct _leaf) - 1)
#define BATCH_SIZE 100

// Support for compaction
#ifdef HAVE_RB_GC_MARK_MOVABLE
#define mark rb_gc_mark_movable
#else
#define mark rb_gc_mark
#endif

typedef struct _batch {
struct _batch *next;
int next_avail;
Expand Down Expand Up @@ -684,7 +691,7 @@ static void mark_leaf(Leaf leaf) {
} while (e != first);
}
break;
case RUBY_VAL: rb_gc_mark_movable(leaf->value); break;
case RUBY_VAL: mark(leaf->value); break;

default: break;
}
Expand All @@ -695,11 +702,11 @@ static void mark_doc(void *ptr) {
if (NULL != ptr) {
Doc doc = (Doc)ptr;

rb_gc_mark_movable(doc->self);
mark(doc->self);
mark_leaf(doc->data);
}
}

#ifdef HAVE_RB_GC_MARK_MOVABLE
static void compact_leaf(Leaf leaf) {
switch (leaf->value_type) {
case COL_VAL:
Expand Down Expand Up @@ -727,14 +734,17 @@ static void compact_doc(void *ptr) {
compact_leaf(doc->data);
}
}
#endif

static const rb_data_type_t oj_doc_type = {
"Oj/doc",
{
mark_doc,
free_doc_cb,
NULL,
#ifdef HAVE_RB_GC_MARK_MOVABLE
compact_doc,
#endif
},
0,
0,
Expand Down

0 comments on commit 326353e

Please sign in to comment.