ext/ox/dump.c in ox-1.2.11 vs ext/ox/dump.c in ox-1.2.12
- old
+ new
@@ -33,11 +33,11 @@
#include <time.h>
#include <stdio.h>
#include <string.h>
#include "ruby.h"
-#include "ruby/oniguruma.h"
+#include "ruby/st.h"
#include "base64.h"
#include "cache8.h"
#include "ox.h"
typedef struct _Str {
@@ -116,32 +116,36 @@
}
inline static Type
obj_class_code(VALUE obj) {
switch (rb_type(obj)) {
- case RUBY_T_NIL: return NilClassCode;
- case RUBY_T_ARRAY: return ArrayCode;
- case RUBY_T_HASH: return HashCode;
- case RUBY_T_TRUE: return TrueClassCode;
- case RUBY_T_FALSE: return FalseClassCode;
- case RUBY_T_FIXNUM: return FixnumCode;
- case RUBY_T_FLOAT: return FloatCode;
- case RUBY_T_STRING: return (is_xml_friendly((u_char*)StringValuePtr(obj), (int)RSTRING_LEN(obj))) ? StringCode : String64Code;
- case RUBY_T_SYMBOL:
+ case T_NIL: return NilClassCode;
+ case T_ARRAY: return ArrayCode;
+ case T_HASH: return HashCode;
+ case T_TRUE: return TrueClassCode;
+ case T_FALSE: return FalseClassCode;
+ case T_FIXNUM: return FixnumCode;
+ case T_FLOAT: return FloatCode;
+ case T_STRING: return (is_xml_friendly((u_char*)StringValuePtr(obj), (int)RSTRING_LEN(obj))) ? StringCode : String64Code;
+ case T_SYMBOL:
{
const char *sym = rb_id2name(SYM2ID(obj));
return (is_xml_friendly((u_char*)sym, (int)strlen(sym))) ? SymbolCode : Symbol64Code;
}
- case RUBY_T_DATA: return (rb_cTime == rb_obj_class(obj)) ? TimeCode : 0;
- case RUBY_T_STRUCT: return (rb_cRange == rb_obj_class(obj)) ? RangeCode : StructCode;
- case RUBY_T_OBJECT: return (ox_document_clas == rb_obj_class(obj) || ox_element_clas == rb_obj_class(obj)) ? RawCode : ObjectCode;
- case RUBY_T_REGEXP: return RegexpCode;
- case RUBY_T_BIGNUM: return BignumCode;
- case RUBY_T_COMPLEX: return ComplexCode;
- case RUBY_T_RATIONAL: return RationalCode;
- case RUBY_T_CLASS: return ClassCode;
+ case T_DATA: return (rb_cTime == rb_obj_class(obj)) ? TimeCode : 0;
+ case T_STRUCT: return (rb_cRange == rb_obj_class(obj)) ? RangeCode : StructCode;
+ case T_OBJECT: return (ox_document_clas == rb_obj_class(obj) || ox_element_clas == rb_obj_class(obj)) ? 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;
}
}
inline static void
@@ -447,16 +451,16 @@
}
e.id = 0;
e.clas.len = 0;
e.clas.str = 0;
switch (rb_type(obj)) {
- case RUBY_T_NIL:
+ case T_NIL:
e.type = NilClassCode;
e.closed = 1;
out->w_start(out, &e);
break;
- case RUBY_T_ARRAY:
+ case T_ARRAY:
if (0 != out->circ_cache && check_circular(out, obj, &e)) {
break;
}
cnt = (int)RARRAY_LEN(obj);
e.type = ArrayCode;
@@ -471,11 +475,11 @@
dump_obj(0, *np, d2, out);
}
out->w_end(out, &e);
}
break;
- case RUBY_T_HASH:
+ case T_HASH:
if (0 != out->circ_cache && check_circular(out, obj, &e)) {
break;
}
cnt = (int)RHASH_SIZE(obj);
e.type = HashCode;
@@ -488,36 +492,36 @@
rb_hash_foreach(obj, dump_hash, (VALUE)out);
out->depth = od;
out->w_end(out, &e);
}
break;
- case RUBY_T_TRUE:
+ case T_TRUE:
e.type = TrueClassCode;
e.closed = 1;
out->w_start(out, &e);
break;
- case RUBY_T_FALSE:
+ case T_FALSE:
e.type = FalseClassCode;
e.closed = 1;
out->w_start(out, &e);
break;
- case RUBY_T_FIXNUM:
+ case T_FIXNUM:
e.type = FixnumCode;
out->w_start(out, &e);
dump_num(out, obj);
e.indent = -1;
out->w_end(out, &e);
break;
- case RUBY_T_FLOAT:
+ case T_FLOAT:
e.type = FloatCode;
cnt = sprintf(value_buf, "%0.16g", RFLOAT_VALUE(obj)); // used sprintf due to bug in snprintf
out->w_start(out, &e);
dump_value(out, value_buf, cnt);
e.indent = -1;
out->w_end(out, &e);
break;
- case RUBY_T_STRING:
+ case T_STRING:
{
const char *str;
if (0 != out->circ_cache && check_circular(out, obj, &e)) {
break;
@@ -550,11 +554,11 @@
free(b64);
}
}
break;
}
- case RUBY_T_SYMBOL:
+ case T_SYMBOL:
{
const char *sym = rb_id2name(SYM2ID(obj));
cnt = (int)strlen(sym);
if (is_xml_friendly((u_char*)sym, cnt)) {
@@ -583,11 +587,11 @@
free(b64);
}
}
break;
}
- case RUBY_T_DATA:
+ case T_DATA:
{
VALUE clas;
clas = rb_obj_class(obj);
if (rb_cTime == clas) {
@@ -596,20 +600,20 @@
out->w_time(out, obj);
e.indent = -1;
out->w_end(out, &e);
} else {
if (StrictEffort == out->opts->effort) {
- rb_raise(rb_eNotImpError, "Failed to dump RUBY_T_DATA %s\n", rb_class2name(clas));
+ rb_raise(rb_eNotImpError, "Failed to dump T_DATA %s\n", rb_class2name(clas));
} else {
e.type = NilClassCode;
e.closed = 1;
out->w_start(out, &e);
}
}
break;
}
- case RUBY_T_STRUCT:
+ case T_STRUCT:
{
VALUE clas;
if (0 != out->circ_cache && check_circular(out, obj, &e)) {
break;
@@ -643,11 +647,11 @@
}
out->w_end(out, &e);
}
break;
}
- case RUBY_T_OBJECT:
+ case T_OBJECT:
{
VALUE clas;
if (0 != out->circ_cache && check_circular(out, obj, &e)) {
break;
@@ -679,11 +683,11 @@
out->w_end(out, &e);
}
}
break;
}
- case RUBY_T_REGEXP:
+ case T_REGEXP:
{
#if 1
VALUE rs = rb_funcall2(obj, inspect_id, 0, 0);
const char *s = StringValuePtr(rs);
@@ -729,36 +733,40 @@
#endif
e.indent = -1;
out->w_end(out, &e);
break;
}
- case RUBY_T_BIGNUM:
+ case T_BIGNUM:
{
VALUE rs = rb_big2str(obj, 10);
e.type = BignumCode;
out->w_start(out, &e);
dump_value(out, StringValuePtr(rs), RSTRING_LEN(rs));
e.indent = -1;
out->w_end(out, &e);
break;
}
- case RUBY_T_COMPLEX:
+#ifdef T_COMPLEX
+ case T_COMPLEX:
e.type = ComplexCode;
out->w_start(out, &e);
dump_obj(0, RCOMPLEX(obj)->real, depth + 1, out);
dump_obj(0, RCOMPLEX(obj)->imag, depth + 1, out);
out->w_end(out, &e);
break;
- case RUBY_T_RATIONAL:
+#endif
+#ifdef T_RATIONAL
+ case T_RATIONAL:
e.type = RationalCode;
out->w_start(out, &e);
dump_obj(0, RRATIONAL(obj)->num, depth + 1, out);
dump_obj(0, RRATIONAL(obj)->den, depth + 1, out);
out->w_end(out, &e);
break;
- case RUBY_T_CLASS:
+#endif
+ case T_CLASS:
{
e.type = ClassCode;
e.clas.str = rb_class2name(obj);
e.clas.len = strlen(e.clas.str);
e.closed = 1;
@@ -778,11 +786,11 @@
}
}
static int
dump_var(ID key, VALUE value, Out out) {
- if (RUBY_T_DATA == rb_type(value) && rb_cTime != rb_obj_class(value)) {
+ if (T_DATA == rb_type(value) && rb_cTime != rb_obj_class(value)) {
/* There is a secret recipe that keeps Exception mesg attributes as a
* T_DATA until it is needed. StringValue() makes the value needed and
* it is converted to a regular Ruby Object. It might seem reasonable
* to expect that this would be done before calling the foreach
* callback but it isn't. A slight hack fixes the inconsistency. If
@@ -907,11 +915,11 @@
return indent_needed;
}
static int
dump_gen_attr(VALUE key, VALUE value, Out out) {
- const char *ks = (RUBY_T_SYMBOL == rb_type(key)) ? rb_id2name(SYM2ID(key)) : StringValuePtr(key);
+ const char *ks = (T_SYMBOL == rb_type(key)) ? rb_id2name(SYM2ID(key)) : StringValuePtr(key);
size_t klen = strlen(ks);
size_t size = 4 + klen + RSTRING_LEN(value);
if (out->end - out->cur <= (long)size) {
grow(out, size);
@@ -934,10 +942,10 @@
const char *val;
size_t vlen;
size_t size;
int indent;
- if (RUBY_T_STRING != rb_type(v)) {
+ if (T_STRING != rb_type(v)) {
return;
}
val = StringValuePtr(v);
vlen = RSTRING_LEN(v);
if (0 > out->indent) {