ext/ox/dump.c in ox-2.14.16 vs ext/ox/dump.c in ox-2.14.17
- old
+ new
@@ -157,16 +157,12 @@
case T_DATA: return (rb_cTime == clas) ? TimeCode : ((ox_date_class == clas) ? DateCode : 0);
case T_STRUCT: return (rb_cRange == clas) ? RangeCode : StructCode;
case T_OBJECT: return (ox_document_clas == clas || ox_element_clas == clas) ? RawCode : ObjectCode;
case T_REGEXP: return RegexpCode;
case T_BIGNUM: return BignumCode;
-#ifdef T_COMPLEX
case T_COMPLEX: return ComplexCode;
-#endif
-#ifdef T_RATIONAL
case T_RATIONAL: return RationalCode;
-#endif
case T_CLASS: return ClassCode;
default: return 0;
}
}
@@ -438,23 +434,17 @@
}
*out->cur = '\0';
}
static void dump_time_thin(Out out, VALUE obj) {
- char buf[64];
- char *b = buf + sizeof(buf) - 1;
-#if HAVE_RB_TIME_TIMESPEC
+ char buf[64];
+ char *b = buf + sizeof(buf) - 1;
struct timespec ts = rb_time_timespec(obj);
time_t sec = ts.tv_sec;
long nsec = ts.tv_nsec;
-#else
- time_t sec = NUM2LONG(rb_funcall2(obj, ox_tv_sec_id, 0, 0));
- long nsec = NUM2LONG(rb_funcall2(obj, ox_tv_nsec_id, 0, 0));
- // long nsec = NUM2LONG(rb_funcall2(obj, ox_tv_usec_id, 0, 0)) * 1000;
-#endif
- char *dot = b - 10;
- long size;
+ char *dot = b - 10;
+ long size;
*b-- = '\0';
for (; dot < b; b--, nsec /= 10) {
*b = '0' + (nsec % 10);
}
@@ -493,22 +483,16 @@
memcpy(out->cur, b, size);
out->cur += size;
}
static void dump_time_xsd(Out out, VALUE obj) {
- struct tm *tm;
-#if HAVE_RB_TIME_TIMESPEC
+ struct tm *tm;
struct timespec ts = rb_time_timespec(obj);
time_t sec = ts.tv_sec;
long nsec = ts.tv_nsec;
-#else
- time_t sec = NUM2LONG(rb_funcall2(obj, ox_tv_sec_id, 0, 0));
- long nsec = NUM2LONG(rb_funcall2(obj, ox_tv_nsec_id, 0, 0));
- // long nsec = NUM2LONG(rb_funcall2(obj, ox_tv_usec_id, 0, 0)) * 1000;
-#endif
- int tzhour, tzmin;
- char tzsign = '+';
+ int tzhour, tzmin;
+ char tzsign = '+';
if (out->end - out->cur <= 33) {
grow(out, 33);
}
/* 2010-07-09T10:47:45.895826+09:00 */
@@ -775,11 +759,11 @@
out->w_start(out, &e);
dump_date(out, obj);
e.indent = -1;
out->w_end(out, &e);
} else if (0 == strcmp("BigDecimal", classname)) {
- volatile VALUE rs = rb_funcall(obj, ox_to_s_id, 0);
+ volatile VALUE rs = rb_String(obj);
e.type = BigDecimalCode;
out->w_start(out, &e);
dump_value(out, StringValuePtr(rs), RSTRING_LEN(rs));
e.indent = -1;
@@ -819,17 +803,12 @@
dump_obj(ox_excl_id, excl, d2, out);
out->w_end(out, &e);
} else {
char num_buf[16];
int d2 = depth + 1;
-#ifdef RUBY_INTEGER_UNIFICATION
long i;
- long cnt = NUM2LONG(rb_struct_size(obj));
-#else // UNIFY_FIXNUM_AND_INTEGER
- int i;
- int cnt = (int)RSTRUCT_LEN(obj);
-#endif // UNIFY_FIXNUM_AND_INTEGER
+ long cnt = NUM2LONG(rb_struct_size(obj));
e.type = StructCode;
e.clas.str = rb_class2name(clas);
e.clas.len = strlen(e.clas.str);
out->w_start(out, &e);
@@ -864,11 +843,10 @@
e.type = RawCode;
out->w_start(out, &e);
dump_gen_element(obj, depth + 1, out);
out->w_end(out, &e);
} else { /* Object */
-#if HAVE_RB_IVAR_FOREACH
e.type = (Qtrue == rb_obj_is_kind_of(obj, rb_eException)) ? ExceptionCode : ObjectCode;
cnt = (int)rb_ivar_count(obj);
e.closed = (0 >= cnt);
out->w_start(out, &e);
if (0 < cnt) {
@@ -877,33 +855,10 @@
out->depth = depth + 1;
rb_ivar_foreach(obj, dump_var, (VALUE)out);
out->depth = od;
out->w_end(out, &e);
}
-#else
- volatile VALUE vars = rb_obj_instance_variables(obj);
- // volatile VALUE vars = rb_funcall2(obj, rb_intern("instance_variables"), 0, 0);
-
- e.type = (Qtrue == rb_obj_is_kind_of(obj, rb_eException)) ? ExceptionCode : ObjectCode;
- cnt = (int)RARRAY_LEN(vars);
- e.closed = (0 >= cnt);
- out->w_start(out, &e);
- if (0 < cnt) {
- const VALUE *np = RARRAY_PTR(vars);
- ID vid;
- unsigned int od = out->depth;
- int i;
-
- out->depth = depth + 1;
- for (i = cnt; 0 < i; i--, np++) {
- vid = rb_to_id(*np);
- dump_var(vid, rb_ivar_get(obj, vid), out);
- }
- out->depth = od;
- out->w_end(out, &e);
- }
-#endif
}
break;
}
case T_REGEXP: {
volatile VALUE rs = rb_funcall2(obj, ox_inspect_id, 0, 0);
@@ -938,33 +893,29 @@
dump_value(out, StringValuePtr(rs), RSTRING_LEN(rs));
e.indent = -1;
out->w_end(out, &e);
break;
}
-#ifdef T_COMPLEX
case T_COMPLEX: e.type = ComplexCode; out->w_start(out, &e);
#ifdef RCOMPLEX
dump_obj(0, RCOMPLEX(obj)->real, depth + 1, out);
dump_obj(0, RCOMPLEX(obj)->imag, depth + 1, out);
#else
dump_obj(0, rb_funcall2(obj, rb_intern("real"), 0, 0), depth + 1, out);
dump_obj(0, rb_funcall2(obj, rb_intern("imag"), 0, 0), depth + 1, out);
#endif
out->w_end(out, &e);
break;
-#endif
-#ifdef T_RATIONAL
case T_RATIONAL: e.type = RationalCode; out->w_start(out, &e);
#ifdef RRATIONAL
dump_obj(0, RRATIONAL(obj)->num, depth + 1, out);
dump_obj(0, RRATIONAL(obj)->den, depth + 1, out);
#else
dump_obj(0, rb_funcall2(obj, rb_intern("numerator"), 0, 0), depth + 1, out);
dump_obj(0, rb_funcall2(obj, rb_intern("denominator"), 0, 0), depth + 1, out);
#endif
out->w_end(out, &e);
break;
-#endif
case T_CLASS: {
e.type = ClassCode;
e.clas.str = rb_class2name(obj);
e.clas.len = strlen(e.clas.str);
e.closed = 1;