ext/ox/dump.c in ox-1.2.4 vs ext/ox/dump.c in ox-1.2.5
- old
+ new
@@ -63,17 +63,18 @@
char *cur;
Cache8 circ_cache;
unsigned long circ_cnt;
int indent;
int depth; // used by dumpHash
+ Options opts;
} *Out;
static void dump_obj_to_xml(VALUE obj, Options copts, Out out);
-static void dump_first_obj(VALUE obj, Options copts, Out out);
+static void dump_first_obj(VALUE obj, Out out);
static void dump_obj(ID aid, VALUE obj, unsigned int depth, Out out);
-static void dump_gen_doc(VALUE obj, unsigned int depth, Options copts, Out out);
+static void dump_gen_doc(VALUE obj, unsigned int depth, Out out);
static void dump_gen_element(VALUE obj, unsigned int depth, Out out);
static int dump_gen_attr(VALUE key, VALUE value, Out out);
static int dump_gen_nodes(VALUE obj, unsigned int depth, Out out);
static void dump_gen_val_node(VALUE obj, unsigned int depth,
const char *pre, size_t plen,
@@ -387,12 +388,13 @@
tm->tm_hour, tm->tm_min, tm->tm_sec, usec,
tzsign, tzhour, tzmin);
}
static void
-dump_first_obj(VALUE obj, Options copts, Out out) {
+dump_first_obj(VALUE obj, Out out) {
char buf[128];
+ Options copts = out->opts;
int cnt;
if (Yes == copts->with_xml) {
if ('\0' == *copts->encoding) {
dump_value(out, "<?xml version=\"1.0\"?>", 21);
@@ -620,11 +622,11 @@
e.clas.str = rb_class2name(clas);
e.clas.len = strlen(e.clas.str);
if (ox_document_clas == clas) {
e.type = RawCode;
out->w_start(out, &e);
- dump_gen_doc(obj, depth + 1, 0, out);
+ dump_gen_doc(obj, depth + 1, out);
out->w_end(out, &e);
} else if (ox_element_clas == clas) {
e.type = RawCode;
out->w_start(out, &e);
dump_gen_element(obj, depth + 1, out);
@@ -728,11 +730,18 @@
e.closed = 1;
out->w_start(out, &e);
break;
}
default:
- rb_raise(rb_eNotImpError, "Failed to dump %s Object (%02x)\n", rb_class2name(rb_obj_class(obj)), rb_type(obj));
+ if (StrictEffort == out->opts->effort) {
+ rb_raise(rb_eNotImpError, "Failed to dump %s Object (%02x)\n",
+ rb_class2name(rb_obj_class(obj)), rb_type(obj));
+ } else {
+ e.type = NilClassCode; e.clas.len = 0; e.clas.str = 0;
+ e.closed = 1;
+ out->w_start(out, &e);
+ }
break;
}
}
static int
@@ -749,22 +758,22 @@
return ST_CONTINUE;
}
static void
-dump_gen_doc(VALUE obj, unsigned int depth, Options copts, Out out) {
+dump_gen_doc(VALUE obj, unsigned int depth, Out out) {
VALUE attrs = rb_attr_get(obj, attributes_id);
VALUE nodes = rb_attr_get(obj, nodes_id);
- if (Yes == copts->with_xml) {
+ if (Yes == out->opts->with_xml) {
dump_value(out, "<?xml", 5);
if (Qnil != attrs) {
rb_hash_foreach(attrs, dump_gen_attr, (VALUE)out);
}
dump_value(out, "?>", 2);
}
- if (Yes == copts->with_instruct) {
+ if (Yes == out->opts->with_instruct) {
if (out->buf < out->cur) {
dump_value(out, "\n<?ox version=\"1.0\" mode=\"generic\"?>", 36);
} else {
dump_value(out, "<?ox version=\"1.0\" mode=\"generic\"?>", 35);
}
@@ -913,21 +922,22 @@
out->buf = (char*)malloc(65336);
out->end = out->buf + 65336;
out->cur = out->buf;
out->circ_cache = 0;
out->circ_cnt = 0;
+ out->opts = copts;
if (Yes == copts->circular) {
ox_cache8_new(&out->circ_cache);
}
out->indent = copts->indent;
if (ox_document_clas == clas) {
- dump_gen_doc(obj, -1, copts, out);
+ dump_gen_doc(obj, -1, out);
} else if (ox_element_clas == clas) {
dump_gen_element(obj, 0, out);
} else {
out->w_start = dump_start;
out->w_end = dump_end;
- dump_first_obj(obj, copts, out);
+ dump_first_obj(obj, out);
}
dump_value(out, "\n", 1);
}
char*