ox 1.4.6 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of ox might be problematic. Click here for more details.

@@ -87,7 +87,7 @@ str2sym(const char *str, void *encoding) {
87
87
  VALUE rstr = rb_str_new2(str);
88
88
 
89
89
  rb_enc_associate(rstr, (rb_encoding*)encoding);
90
- sym = rb_funcall(rstr, to_sym_id, 0);
90
+ sym = rb_funcall(rstr, ox_to_sym_id, 0);
91
91
  } else {
92
92
  sym = ID2SYM(rb_intern(str));
93
93
  }
@@ -104,14 +104,14 @@ name2var(const char *name, void *encoding) {
104
104
 
105
105
  if ('0' <= *name && *name <= '9') {
106
106
  var_id = INT2NUM(atoi(name));
107
- } else if (Qundef == (var_id = ox_cache_get(attr_cache, name, &slot))) {
107
+ } else if (Qundef == (var_id = ox_cache_get(ox_attr_cache, name, &slot))) {
108
108
  #ifdef HAVE_RUBY_ENCODING_H
109
109
  if (0 != encoding) {
110
110
  VALUE rstr = rb_str_new2(name);
111
111
  VALUE sym;
112
112
 
113
113
  rb_enc_associate(rstr, (rb_encoding*)encoding);
114
- sym = rb_funcall(rstr, to_sym_id, 0);
114
+ sym = rb_funcall(rstr, ox_to_sym_id, 0);
115
115
  var_id = SYM2ID(sym);
116
116
  } else {
117
117
  var_id = rb_intern(name);
@@ -179,7 +179,7 @@ structname2obj(const char *name) {
179
179
  break;
180
180
  }
181
181
  }
182
- ost = rb_const_get(struct_class, rb_intern(s));
182
+ ost = rb_const_get(ox_struct_class, rb_intern(s));
183
183
  // use encoding as the indicator for Ruby 1.8.7 or 1.9.x
184
184
  #ifdef HAVE_RUBY_ENCODING_H
185
185
  return rb_struct_alloc_noinit(ost);
@@ -200,7 +200,7 @@ parse_time(const char *text, VALUE clas) {
200
200
 
201
201
  //printf("**** time parse\n");
202
202
  *args = rb_str_new2(text);
203
- t = rb_funcall2(time_class, parse_id, 1, args);
203
+ t = rb_funcall2(ox_time_class, ox_parse_id, 1, args);
204
204
  }
205
205
  return t;
206
206
  }
@@ -210,7 +210,7 @@ classname2class(const char *name, PInfo pi) {
210
210
  VALUE *slot;
211
211
  VALUE clas;
212
212
 
213
- if (Qundef == (clas = ox_cache_get(class_cache, name, &slot))) {
213
+ if (Qundef == (clas = ox_cache_get(ox_class_cache, name, &slot))) {
214
214
  char class_name[1024];
215
215
  char *s;
216
216
  const char *n = name;
@@ -220,6 +220,9 @@ classname2class(const char *name, PInfo pi) {
220
220
  if (':' == *n) {
221
221
  *s = '\0';
222
222
  n++;
223
+ if (':' != *n) {
224
+ raise_error("Invalid classname, expected another ':'", pi->str, pi->s);
225
+ }
223
226
  if (Qundef == (clas = resolve_classname(clas, class_name, pi->effort))) {
224
227
  return Qundef;
225
228
  }
@@ -451,7 +454,7 @@ add_text(PInfo pi, char *text, int closed) {
451
454
  VALUE sym;
452
455
  VALUE *slot;
453
456
 
454
- if (Qundef == (sym = ox_cache_get(symbol_cache, text, &slot))) {
457
+ if (Qundef == (sym = ox_cache_get(ox_symbol_cache, text, &slot))) {
455
458
  sym = str2sym(text, pi->encoding);
456
459
  *slot = sym;
457
460
  }
@@ -459,7 +462,7 @@ add_text(PInfo pi, char *text, int closed) {
459
462
  break;
460
463
  }
461
464
  case TimeCode:
462
- pi->h->obj = parse_time(text, time_class);
465
+ pi->h->obj = parse_time(text, ox_time_class);
463
466
  break;
464
467
  case String64Code:
465
468
  {
@@ -503,7 +506,7 @@ add_text(PInfo pi, char *text, int closed) {
503
506
  }
504
507
  }
505
508
  from_base64(text, (u_char*)str);
506
- if (Qundef == (sym = ox_cache_get(symbol_cache, str, &slot))) {
509
+ if (Qundef == (sym = ox_cache_get(ox_symbol_cache, str, &slot))) {
507
510
  sym = str2sym(str, pi->encoding);
508
511
  *slot = sym;
509
512
  }
@@ -593,7 +596,7 @@ add_element(PInfo pi, const char *ename, Attr attrs, int hasChildren) {
593
596
  break;
594
597
  case StringCode:
595
598
  // h->obj will be replaced by add_text if it is called
596
- h->obj = empty_string;
599
+ h->obj = ox_empty_string;
597
600
  if (0 != pi->circ_array) {
598
601
  pi->id = get_id_from_attrs(pi, attrs);
599
602
  circ_array_set(pi->circ_array, h->obj, pi->id);
@@ -630,11 +633,11 @@ add_element(PInfo pi, const char *ename, Attr attrs, int hasChildren) {
630
633
  }
631
634
  break;
632
635
  case RangeCode:
633
- h->obj = rb_range_new(zero_fixnum, zero_fixnum, Qfalse);
636
+ h->obj = rb_range_new(ox_zero_fixnum, ox_zero_fixnum, Qfalse);
634
637
  break;
635
638
  case RawCode:
636
639
  if (hasChildren) {
637
- h->obj = parse(pi->s, ox_gen_callbacks, &pi->s, pi->trace, pi->effort);
640
+ h->obj = ox_parse(pi->s, ox_gen_callbacks, &pi->s, pi->trace, pi->effort);
638
641
  if (0 != pi->circ_array) {
639
642
  circ_array_set(pi->circ_array, h->obj, get_id_from_attrs(pi, attrs));
640
643
  }
@@ -697,7 +700,7 @@ end_element(PInfo pi, const char *ename) {
697
700
  if (0 != pi->h && pi->helpers <= pi->h) {
698
701
  Helper h = pi->h;
699
702
 
700
- if (empty_string == h->obj) {
703
+ if (ox_empty_string == h->obj) {
701
704
  // special catch for empty strings
702
705
  h->obj = rb_str_new2("");
703
706
  }
@@ -728,11 +731,11 @@ end_element(PInfo pi, const char *ename) {
728
731
  #ifdef NO_RSTRUCT
729
732
  raise_error("Ruby structs not supported with this verion of Ruby", pi->str, pi->s);
730
733
  #else
731
- if (beg_id == h->var) {
734
+ if (ox_beg_id == h->var) {
732
735
  RSTRUCT_PTR(pi->h->obj)[0] = h->obj;
733
- } else if (end_id == h->var) {
736
+ } else if (ox_end_id == h->var) {
734
737
  RSTRUCT_PTR(pi->h->obj)[1] = h->obj;
735
- } else if (excl_id == h->var) {
738
+ } else if (ox_excl_id == h->var) {
736
739
  RSTRUCT_PTR(pi->h->obj)[2] = h->obj;
737
740
  } else {
738
741
  raise_error("Invalid range attribute", pi->str, pi->s);
@@ -809,7 +812,7 @@ parse_double_time(const char *text, VALUE clas) {
809
812
  args[0] = LONG2NUM(v);
810
813
  args[1] = LONG2NUM(v2);
811
814
 
812
- return rb_funcall2(clas, at_id, 2, args);
815
+ return rb_funcall2(clas, ox_at_id, 2, args);
813
816
  }
814
817
 
815
818
  typedef struct _Tp {
@@ -866,7 +869,7 @@ parse_xsd_time(const char *text, VALUE clas) {
866
869
  args[0] = LONG2NUM(mktime(&tm));
867
870
  args[1] = LONG2NUM(cargs[6]);
868
871
 
869
- return rb_funcall2(clas, at_id, 2, args);
872
+ return rb_funcall2(clas, ox_at_id, 2, args);
870
873
  }
871
874
 
872
875
  // debug functions
@@ -45,65 +45,43 @@ void Init_ox();
45
45
 
46
46
  VALUE Ox = Qnil;
47
47
 
48
- ID at_id;
49
- ID attr_id;
50
- ID attributes_id;
51
- ID beg_id;
52
- ID cdata_id;
53
- ID comment_id;
54
- ID den_id;
55
- ID doctype_id;
56
- ID end_element_id;
57
- ID end_id;
58
- ID error_id;
59
- ID excl_id;
60
- ID fileno_id;
61
- ID inspect_id;
62
- ID instruct_id;
63
- ID keys_id;
64
- ID local_id;
65
- ID mesg_id;
66
- ID message_id;
67
- ID nodes_id;
68
- ID num_id;
69
- ID parse_id;
70
- ID read_id;
71
- ID readpartial_id;
72
- ID start_element_id;
73
- ID text_id;
74
- ID to_c_id;
75
- ID to_s_id;
76
- ID to_sym_id;
77
- ID tv_sec_id;
78
- ID tv_usec_id;
79
- ID value_id;
80
-
81
- VALUE version_sym;
82
- VALUE standalone_sym;
83
- VALUE encoding_sym;
84
- VALUE indent_sym;
85
- VALUE xsd_date_sym;
86
- VALUE opt_format_sym;
87
- VALUE circular_sym;
88
- VALUE mode_sym;
89
- VALUE auto_sym;
90
- VALUE optimized_sym;
91
- VALUE object_sym;
92
- VALUE generic_sym;
93
- VALUE limited_sym;
94
- VALUE strict_sym;
95
- VALUE tolerant_sym;
96
- VALUE effort_sym;
97
- VALUE auto_define_sym;
98
- VALUE trace_sym;
99
- VALUE strict_sym;
100
- VALUE with_dtd_sym;
101
- VALUE with_instruct_sym;
102
- VALUE convert_special_sym;
103
- VALUE with_xml_sym;
104
-
105
- VALUE empty_string;
106
- VALUE zero_fixnum;
48
+ ID ox_at_id;
49
+ ID ox_attr_id;
50
+ ID ox_attributes_id;
51
+ ID ox_beg_id;
52
+ ID ox_cdata_id;
53
+ ID ox_comment_id;
54
+ ID ox_den_id;
55
+ ID ox_doctype_id;
56
+ ID ox_end_element_id;
57
+ ID ox_end_id;
58
+ ID ox_error_id;
59
+ ID ox_excl_id;
60
+ ID ox_fileno_id;
61
+ ID ox_inspect_id;
62
+ ID ox_instruct_id;
63
+ ID ox_keys_id;
64
+ ID ox_local_id;
65
+ ID ox_mesg_id;
66
+ ID ox_message_id;
67
+ ID ox_nodes_id;
68
+ ID ox_num_id;
69
+ ID ox_parse_id;
70
+ ID ox_read_id;
71
+ ID ox_readpartial_id;
72
+ ID ox_start_element_id;
73
+ ID ox_text_id;
74
+ ID ox_to_c_id;
75
+ ID ox_to_s_id;
76
+ ID ox_to_sym_id;
77
+ ID ox_tv_sec_id;
78
+ ID ox_tv_usec_id;
79
+ ID ox_value_id;
80
+
81
+ VALUE ox_encoding_sym;
82
+
83
+ VALUE ox_empty_string;
84
+ VALUE ox_zero_fixnum;
107
85
 
108
86
  VALUE ox_cdata_clas;
109
87
  VALUE ox_comment_clas;
@@ -111,14 +89,35 @@ VALUE ox_doctype_clas;
111
89
  VALUE ox_document_clas;
112
90
  VALUE ox_element_clas;
113
91
  VALUE ox_bag_clas;
114
- VALUE struct_class;
115
- VALUE time_class;
116
-
117
- Cache symbol_cache = 0;
118
- Cache class_cache = 0;
119
- Cache attr_cache = 0;
120
-
121
- struct _Options default_options = {
92
+ VALUE ox_struct_class;
93
+ VALUE ox_time_class;
94
+
95
+ Cache ox_symbol_cache = 0;
96
+ Cache ox_class_cache = 0;
97
+ Cache ox_attr_cache = 0;
98
+
99
+ static VALUE xsd_date_sym;
100
+ static VALUE opt_format_sym;
101
+ static VALUE circular_sym;
102
+ static VALUE mode_sym;
103
+ static VALUE auto_sym;
104
+ static VALUE optimized_sym;
105
+ static VALUE object_sym;
106
+ static VALUE generic_sym;
107
+ static VALUE limited_sym;
108
+ static VALUE strict_sym;
109
+ static VALUE tolerant_sym;
110
+ static VALUE effort_sym;
111
+ static VALUE auto_define_sym;
112
+ static VALUE trace_sym;
113
+ static VALUE strict_sym;
114
+ static VALUE with_dtd_sym;
115
+ static VALUE with_instruct_sym;
116
+ static VALUE convert_special_sym;
117
+ static VALUE with_xml_sym;
118
+ static VALUE indent_sym;
119
+
120
+ struct _Options ox_default_options = {
122
121
  { '\0' }, // encoding
123
122
  2, // indent
124
123
  0, // trace
@@ -138,7 +137,7 @@ extern ParseCallbacks ox_nomode_callbacks;
138
137
 
139
138
  static void parse_dump_options(VALUE ropts, Options copts);
140
139
 
141
- /* call-seq: default_options() => Hash
140
+ /* call-seq: ox_default_options() => Hash
142
141
  *
143
142
  * Returns the default load and dump options as a Hash. The options are
144
143
  * - indent: [Fixnum] number of spaces to indent each element in an XML document
@@ -156,24 +155,24 @@ static void parse_dump_options(VALUE ropts, Options copts);
156
155
  static VALUE
157
156
  get_def_opts(VALUE self) {
158
157
  VALUE opts = rb_hash_new();
159
- int elen = (int)strlen(default_options.encoding);
160
-
161
- rb_hash_aset(opts, encoding_sym, (0 == elen) ? Qnil : rb_str_new(default_options.encoding, elen));
162
- rb_hash_aset(opts, indent_sym, INT2FIX(default_options.indent));
163
- rb_hash_aset(opts, trace_sym, INT2FIX(default_options.trace));
164
- rb_hash_aset(opts, with_dtd_sym, (Yes == default_options.with_dtd) ? Qtrue : ((No == default_options.with_dtd) ? Qfalse : Qnil));
165
- rb_hash_aset(opts, with_xml_sym, (Yes == default_options.with_xml) ? Qtrue : ((No == default_options.with_xml) ? Qfalse : Qnil));
166
- rb_hash_aset(opts, with_instruct_sym, (Yes == default_options.with_instruct) ? Qtrue : ((No == default_options.with_instruct) ? Qfalse : Qnil));
167
- rb_hash_aset(opts, circular_sym, (Yes == default_options.circular) ? Qtrue : ((No == default_options.circular) ? Qfalse : Qnil));
168
- rb_hash_aset(opts, xsd_date_sym, (Yes == default_options.xsd_date) ? Qtrue : ((No == default_options.xsd_date) ? Qfalse : Qnil));
169
- switch (default_options.mode) {
158
+ int elen = (int)strlen(ox_default_options.encoding);
159
+
160
+ rb_hash_aset(opts, ox_encoding_sym, (0 == elen) ? Qnil : rb_str_new(ox_default_options.encoding, elen));
161
+ rb_hash_aset(opts, indent_sym, INT2FIX(ox_default_options.indent));
162
+ rb_hash_aset(opts, trace_sym, INT2FIX(ox_default_options.trace));
163
+ rb_hash_aset(opts, with_dtd_sym, (Yes == ox_default_options.with_dtd) ? Qtrue : ((No == ox_default_options.with_dtd) ? Qfalse : Qnil));
164
+ rb_hash_aset(opts, with_xml_sym, (Yes == ox_default_options.with_xml) ? Qtrue : ((No == ox_default_options.with_xml) ? Qfalse : Qnil));
165
+ rb_hash_aset(opts, with_instruct_sym, (Yes == ox_default_options.with_instruct) ? Qtrue : ((No == ox_default_options.with_instruct) ? Qfalse : Qnil));
166
+ rb_hash_aset(opts, circular_sym, (Yes == ox_default_options.circular) ? Qtrue : ((No == ox_default_options.circular) ? Qfalse : Qnil));
167
+ rb_hash_aset(opts, xsd_date_sym, (Yes == ox_default_options.xsd_date) ? Qtrue : ((No == ox_default_options.xsd_date) ? Qfalse : Qnil));
168
+ switch (ox_default_options.mode) {
170
169
  case ObjMode: rb_hash_aset(opts, mode_sym, object_sym); break;
171
170
  case GenMode: rb_hash_aset(opts, mode_sym, generic_sym); break;
172
171
  case LimMode: rb_hash_aset(opts, mode_sym, limited_sym); break;
173
172
  case NoMode:
174
173
  default: rb_hash_aset(opts, mode_sym, Qnil); break;
175
174
  }
176
- switch (default_options.effort) {
175
+ switch (ox_default_options.effort) {
177
176
  case StrictEffort: rb_hash_aset(opts, effort_sym, strict_sym); break;
178
177
  case TolerantEffort: rb_hash_aset(opts, effort_sym, tolerant_sym); break;
179
178
  case AutoEffort: rb_hash_aset(opts, effort_sym, auto_define_sym); break;
@@ -183,7 +182,7 @@ get_def_opts(VALUE self) {
183
182
  return opts;
184
183
  }
185
184
 
186
- /* call-seq: default_options=(opts)
185
+ /* call-seq: ox_default_options=(opts)
187
186
  *
188
187
  * Sets the default options for load and dump.
189
188
  * @param [Hash] opts options to change
@@ -202,11 +201,11 @@ get_def_opts(VALUE self) {
202
201
  static VALUE
203
202
  set_def_opts(VALUE self, VALUE opts) {
204
203
  struct _YesNoOpt ynos[] = {
205
- { with_xml_sym, &default_options.with_xml },
206
- { with_dtd_sym, &default_options.with_dtd },
207
- { with_instruct_sym, &default_options.with_instruct },
208
- { xsd_date_sym, &default_options.xsd_date },
209
- { circular_sym, &default_options.circular },
204
+ { with_xml_sym, &ox_default_options.with_xml },
205
+ { with_dtd_sym, &ox_default_options.with_dtd },
206
+ { with_instruct_sym, &ox_default_options.with_instruct },
207
+ { xsd_date_sym, &ox_default_options.xsd_date },
208
+ { circular_sym, &ox_default_options.circular },
210
209
  { Qnil, 0 }
211
210
  };
212
211
  YesNoOpt o;
@@ -214,48 +213,48 @@ set_def_opts(VALUE self, VALUE opts) {
214
213
 
215
214
  Check_Type(opts, T_HASH);
216
215
 
217
- v = rb_hash_aref(opts, encoding_sym);
216
+ v = rb_hash_aref(opts, ox_encoding_sym);
218
217
  if (Qnil == v) {
219
- *default_options.encoding = '\0';
218
+ *ox_default_options.encoding = '\0';
220
219
  } else {
221
220
  Check_Type(v, T_STRING);
222
- strncpy(default_options.encoding, StringValuePtr(v), sizeof(default_options.encoding) - 1);
221
+ strncpy(ox_default_options.encoding, StringValuePtr(v), sizeof(ox_default_options.encoding) - 1);
223
222
  }
224
223
 
225
224
  v = rb_hash_aref(opts, indent_sym);
226
225
  if (Qnil != v) {
227
226
  Check_Type(v, T_FIXNUM);
228
- default_options.indent = FIX2INT(v);
227
+ ox_default_options.indent = FIX2INT(v);
229
228
  }
230
229
 
231
230
  v = rb_hash_aref(opts, trace_sym);
232
231
  if (Qnil != v) {
233
232
  Check_Type(v, T_FIXNUM);
234
- default_options.trace = FIX2INT(v);
233
+ ox_default_options.trace = FIX2INT(v);
235
234
  }
236
235
 
237
236
  v = rb_hash_aref(opts, mode_sym);
238
237
  if (Qnil == v) {
239
- default_options.mode = NoMode;
238
+ ox_default_options.mode = NoMode;
240
239
  } else if (object_sym == v) {
241
- default_options.mode = ObjMode;
240
+ ox_default_options.mode = ObjMode;
242
241
  } else if (generic_sym == v) {
243
- default_options.mode = GenMode;
242
+ ox_default_options.mode = GenMode;
244
243
  } else if (limited_sym == v) {
245
- default_options.mode = LimMode;
244
+ ox_default_options.mode = LimMode;
246
245
  } else {
247
246
  rb_raise(rb_eArgError, ":mode must be :object, :generic, :limited, or nil.\n");
248
247
  }
249
248
 
250
249
  v = rb_hash_aref(opts, effort_sym);
251
250
  if (Qnil == v) {
252
- default_options.effort = NoEffort;
251
+ ox_default_options.effort = NoEffort;
253
252
  } else if (strict_sym == v) {
254
- default_options.effort = StrictEffort;
253
+ ox_default_options.effort = StrictEffort;
255
254
  } else if (tolerant_sym == v) {
256
- default_options.effort = TolerantEffort;
255
+ ox_default_options.effort = TolerantEffort;
257
256
  } else if (auto_define_sym == v) {
258
- default_options.effort = AutoEffort;
257
+ ox_default_options.effort = AutoEffort;
259
258
  } else {
260
259
  rb_raise(rb_eArgError, ":effort must be :strict, :tolerant, :auto_define, or nil.\n");
261
260
  }
@@ -292,7 +291,7 @@ to_obj(VALUE self, VALUE ruby_xml) {
292
291
  Check_Type(ruby_xml, T_STRING);
293
292
  // the xml string gets modified so make a copy of it
294
293
  xml = strdup(StringValuePtr(ruby_xml));
295
- obj = parse(xml, ox_obj_callbacks, 0, 0, StrictEffort);
294
+ obj = ox_parse(xml, ox_obj_callbacks, 0, 0, StrictEffort);
296
295
  free(xml);
297
296
  return obj;
298
297
  }
@@ -312,7 +311,7 @@ to_gen(VALUE self, VALUE ruby_xml) {
312
311
  Check_Type(ruby_xml, T_STRING);
313
312
  // the xml string gets modified so make a copy of it
314
313
  xml = strdup(StringValuePtr(ruby_xml));
315
- obj = parse(xml, ox_gen_callbacks, 0, 0, StrictEffort);
314
+ obj = ox_parse(xml, ox_gen_callbacks, 0, 0, StrictEffort);
316
315
  free(xml);
317
316
  return obj;
318
317
  }
@@ -320,7 +319,7 @@ to_gen(VALUE self, VALUE ruby_xml) {
320
319
  static VALUE
321
320
  load(char *xml, int argc, VALUE *argv, VALUE self) {
322
321
  VALUE obj;
323
- struct _Options options = default_options;
322
+ struct _Options options = ox_default_options;
324
323
 
325
324
  if (1 == argc && rb_cHash == rb_obj_class(*argv)) {
326
325
  VALUE h = *argv;
@@ -357,19 +356,19 @@ load(char *xml, int argc, VALUE *argv, VALUE self) {
357
356
  }
358
357
  switch (options.mode) {
359
358
  case ObjMode:
360
- obj = parse(xml, ox_obj_callbacks, 0, options.trace, options.effort);
359
+ obj = ox_parse(xml, ox_obj_callbacks, 0, options.trace, options.effort);
361
360
  break;
362
361
  case GenMode:
363
- obj = parse(xml, ox_gen_callbacks, 0, options.trace, options.effort);
362
+ obj = ox_parse(xml, ox_gen_callbacks, 0, options.trace, options.effort);
364
363
  break;
365
364
  case LimMode:
366
- obj = parse(xml, ox_limited_callbacks, 0, options.trace, options.effort);
365
+ obj = ox_parse(xml, ox_limited_callbacks, 0, options.trace, options.effort);
367
366
  break;
368
367
  case NoMode:
369
- obj = parse(xml, ox_nomode_callbacks, 0, options.trace, options.effort);
368
+ obj = ox_parse(xml, ox_nomode_callbacks, 0, options.trace, options.effort);
370
369
  break;
371
370
  default:
372
- obj = parse(xml, ox_gen_callbacks, 0, options.trace, options.effort);
371
+ obj = ox_parse(xml, ox_gen_callbacks, 0, options.trace, options.effort);
373
372
  break;
374
373
  }
375
374
  free(xml);
@@ -507,7 +506,7 @@ parse_dump_options(VALUE ropts, Options copts) {
507
506
  }
508
507
  copts->trace = NUM2INT(v);
509
508
  }
510
- if (Qnil != (v = rb_hash_lookup(ropts, encoding_sym))) {
509
+ if (Qnil != (v = rb_hash_lookup(ropts, ox_encoding_sym))) {
511
510
  if (rb_cString != rb_obj_class(v)) {
512
511
  rb_raise(rb_eArgError, ":encoding must be a String.\n");
513
512
  }
@@ -555,13 +554,13 @@ parse_dump_options(VALUE ropts, Options copts) {
555
554
  static VALUE
556
555
  dump(int argc, VALUE *argv, VALUE self) {
557
556
  char *xml;
558
- struct _Options copts = default_options;
557
+ struct _Options copts = ox_default_options;
559
558
  VALUE rstr;
560
559
 
561
560
  if (2 == argc) {
562
561
  parse_dump_options(argv[1], &copts);
563
562
  }
564
- if (0 == (xml = write_obj_to_str(*argv, &copts))) {
563
+ if (0 == (xml = ox_write_obj_to_str(*argv, &copts))) {
565
564
  rb_raise(rb_eNoMemError, "Not enough memory.\n");
566
565
  }
567
566
  rstr = rb_str_new2(xml);
@@ -590,13 +589,13 @@ dump(int argc, VALUE *argv, VALUE self) {
590
589
  */
591
590
  static VALUE
592
591
  to_file(int argc, VALUE *argv, VALUE self) {
593
- struct _Options copts = default_options;
592
+ struct _Options copts = ox_default_options;
594
593
 
595
594
  if (3 == argc) {
596
595
  parse_dump_options(argv[2], &copts);
597
596
  }
598
597
  Check_Type(*argv, T_STRING);
599
- write_obj_to_file(argv[1], StringValuePtr(*argv), &copts);
598
+ ox_write_obj_to_file(argv[1], StringValuePtr(*argv), &copts);
600
599
 
601
600
  return Qnil;
602
601
  }
@@ -638,45 +637,44 @@ void Init_ox() {
638
637
  rb_define_module_function(Ox, "to_file", to_file, -1);
639
638
 
640
639
  rb_require("time");
641
- at_id = rb_intern("at");
642
- attr_id = rb_intern("attr");
643
- attributes_id = rb_intern("@attributes");
644
- beg_id = rb_intern("@beg");
645
- cdata_id = rb_intern("cdata");
646
- comment_id = rb_intern("comment");
647
- den_id = rb_intern("@den");
648
- doctype_id = rb_intern("doctype");
649
- end_element_id = rb_intern("end_element");
650
- end_id = rb_intern("@end");
651
- error_id = rb_intern("error");
652
- excl_id = rb_intern("@excl");
653
- fileno_id = rb_intern("fileno");
654
- inspect_id = rb_intern("inspect");
655
- instruct_id = rb_intern("instruct");
656
- keys_id = rb_intern("keys");
657
- local_id = rb_intern("local");
658
- mesg_id = rb_intern("mesg");
659
- message_id = rb_intern("message");
660
- nodes_id = rb_intern("@nodes");
661
- num_id = rb_intern("@num");
662
- parse_id = rb_intern("parse");
663
- readpartial_id = rb_intern("readpartial");
664
- read_id = rb_intern("read");
665
- start_element_id = rb_intern("start_element");
666
- text_id = rb_intern("text");
667
- to_c_id = rb_intern("to_c");
668
- to_s_id = rb_intern("to_s");
669
- to_sym_id = rb_intern("to_sym");
670
- tv_sec_id = rb_intern("tv_sec");
671
- tv_usec_id = rb_intern("tv_usec");
672
- value_id = rb_intern("@value");
673
-
674
- time_class = rb_const_get(rb_cObject, rb_intern("Time"));
675
- struct_class = rb_const_get(rb_cObject, rb_intern("Struct"));
676
-
677
- version_sym = ID2SYM(rb_intern("version")); rb_ary_push(keep, version_sym);
678
- standalone_sym = ID2SYM(rb_intern("standalone")); rb_ary_push(keep, standalone_sym);
679
- encoding_sym = ID2SYM(rb_intern("encoding")); rb_ary_push(keep, encoding_sym);
640
+
641
+ ox_at_id = rb_intern("at");
642
+ ox_attr_id = rb_intern("attr");
643
+ ox_attributes_id = rb_intern("@attributes");
644
+ ox_beg_id = rb_intern("@beg");
645
+ ox_cdata_id = rb_intern("cdata");
646
+ ox_comment_id = rb_intern("comment");
647
+ ox_den_id = rb_intern("@den");
648
+ ox_doctype_id = rb_intern("doctype");
649
+ ox_end_element_id = rb_intern("end_element");
650
+ ox_end_id = rb_intern("@end");
651
+ ox_error_id = rb_intern("error");
652
+ ox_excl_id = rb_intern("@excl");
653
+ ox_fileno_id = rb_intern("fileno");
654
+ ox_inspect_id = rb_intern("inspect");
655
+ ox_instruct_id = rb_intern("instruct");
656
+ ox_keys_id = rb_intern("keys");
657
+ ox_local_id = rb_intern("local");
658
+ ox_mesg_id = rb_intern("mesg");
659
+ ox_message_id = rb_intern("message");
660
+ ox_nodes_id = rb_intern("@nodes");
661
+ ox_num_id = rb_intern("@num");
662
+ ox_parse_id = rb_intern("parse");
663
+ ox_readpartial_id = rb_intern("readpartial");
664
+ ox_read_id = rb_intern("read");
665
+ ox_start_element_id = rb_intern("start_element");
666
+ ox_text_id = rb_intern("text");
667
+ ox_to_c_id = rb_intern("to_c");
668
+ ox_to_s_id = rb_intern("to_s");
669
+ ox_to_sym_id = rb_intern("to_sym");
670
+ ox_tv_sec_id = rb_intern("tv_sec");
671
+ ox_tv_usec_id = rb_intern("tv_usec");
672
+ ox_value_id = rb_intern("@value");
673
+
674
+ ox_time_class = rb_const_get(rb_cObject, rb_intern("Time"));
675
+ ox_struct_class = rb_const_get(rb_cObject, rb_intern("Struct"));
676
+
677
+ ox_encoding_sym = ID2SYM(rb_intern("encoding")); rb_ary_push(keep, ox_encoding_sym);
680
678
  indent_sym = ID2SYM(rb_intern("indent")); rb_ary_push(keep, indent_sym);
681
679
  xsd_date_sym = ID2SYM(rb_intern("xsd_date")); rb_ary_push(keep, xsd_date_sym);
682
680
  opt_format_sym = ID2SYM(rb_intern("opt_format")); rb_ary_push(keep, opt_format_sym);
@@ -697,10 +695,9 @@ void Init_ox() {
697
695
  with_xml_sym = ID2SYM(rb_intern("with_xml")); rb_ary_push(keep, with_xml_sym);
698
696
  convert_special_sym = ID2SYM(rb_intern("convert_special")); rb_ary_push(keep, convert_special_sym);
699
697
 
700
- empty_string = rb_str_new2(""); rb_ary_push(keep, empty_string);
701
- zero_fixnum = INT2NUM(0); rb_ary_push(keep, zero_fixnum);
698
+ ox_empty_string = rb_str_new2(""); rb_ary_push(keep, ox_empty_string);
699
+ ox_zero_fixnum = INT2NUM(0); rb_ary_push(keep, ox_zero_fixnum);
702
700
 
703
-
704
701
  //rb_require("node"); // generic xml node classes
705
702
  ox_document_clas = rb_const_get_at(Ox, rb_intern("Document"));
706
703
  ox_element_clas = rb_const_get_at(Ox, rb_intern("Element"));
@@ -709,16 +706,16 @@ void Init_ox() {
709
706
  ox_cdata_clas = rb_const_get_at(Ox, rb_intern("CData"));
710
707
  ox_bag_clas = rb_const_get_at(Ox, rb_intern("Bag"));
711
708
 
712
- ox_cache_new(&symbol_cache);
713
- ox_cache_new(&class_cache);
714
- ox_cache_new(&attr_cache);
709
+ ox_cache_new(&ox_symbol_cache);
710
+ ox_cache_new(&ox_class_cache);
711
+ ox_cache_new(&ox_attr_cache);
715
712
 
716
713
  rb_define_module_function(Ox, "cache_test", cache_test, 0);
717
714
  rb_define_module_function(Ox, "cache8_test", cache8_test, 0);
718
715
  }
719
716
 
720
717
  void
721
- _raise_error(const char *msg, const char *xml, const char *current, const char* file, int line) {
718
+ _ox_raise_error(const char *msg, const char *xml, const char *current, const char* file, int line) {
722
719
  int xline = 1;
723
720
  int col = 1;
724
721