ox-bundlecachetest 2.14.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +751 -0
  3. data/LICENSE +21 -0
  4. data/README.md +351 -0
  5. data/ext/ox/attr.h +78 -0
  6. data/ext/ox/base64.c +105 -0
  7. data/ext/ox/base64.h +18 -0
  8. data/ext/ox/buf.h +162 -0
  9. data/ext/ox/builder.c +948 -0
  10. data/ext/ox/cache.c +351 -0
  11. data/ext/ox/cache.h +21 -0
  12. data/ext/ox/cache8.c +106 -0
  13. data/ext/ox/cache8.h +23 -0
  14. data/ext/ox/dump.c +1260 -0
  15. data/ext/ox/err.c +46 -0
  16. data/ext/ox/err.h +36 -0
  17. data/ext/ox/extconf.rb +47 -0
  18. data/ext/ox/gen_load.c +342 -0
  19. data/ext/ox/hash_load.c +309 -0
  20. data/ext/ox/helper.h +84 -0
  21. data/ext/ox/intern.c +157 -0
  22. data/ext/ox/intern.h +25 -0
  23. data/ext/ox/obj_load.c +809 -0
  24. data/ext/ox/ox.c +1649 -0
  25. data/ext/ox/ox.h +245 -0
  26. data/ext/ox/parse.c +1197 -0
  27. data/ext/ox/sax.c +1570 -0
  28. data/ext/ox/sax.h +69 -0
  29. data/ext/ox/sax_as.c +270 -0
  30. data/ext/ox/sax_buf.c +209 -0
  31. data/ext/ox/sax_buf.h +204 -0
  32. data/ext/ox/sax_hint.c +207 -0
  33. data/ext/ox/sax_hint.h +40 -0
  34. data/ext/ox/sax_stack.h +113 -0
  35. data/ext/ox/slotcache.c +158 -0
  36. data/ext/ox/slotcache.h +19 -0
  37. data/ext/ox/special.c +390 -0
  38. data/ext/ox/special.h +14 -0
  39. data/ext/ox/type.h +39 -0
  40. data/lib/ox/bag.rb +103 -0
  41. data/lib/ox/cdata.rb +10 -0
  42. data/lib/ox/comment.rb +11 -0
  43. data/lib/ox/doctype.rb +11 -0
  44. data/lib/ox/document.rb +28 -0
  45. data/lib/ox/element.rb +464 -0
  46. data/lib/ox/error.rb +25 -0
  47. data/lib/ox/hasattrs.rb +54 -0
  48. data/lib/ox/instruct.rb +34 -0
  49. data/lib/ox/node.rb +23 -0
  50. data/lib/ox/raw.rb +12 -0
  51. data/lib/ox/sax.rb +97 -0
  52. data/lib/ox/version.rb +4 -0
  53. data/lib/ox/xmlrpc_adapter.rb +33 -0
  54. data/lib/ox.rb +79 -0
  55. metadata +128 -0
data/ext/ox/err.c ADDED
@@ -0,0 +1,46 @@
1
+ /* err.c
2
+ * Copyright (c) 2011, Peter Ohler
3
+ * All rights reserved.
4
+ */
5
+
6
+ #include "err.h"
7
+
8
+ #include <stdarg.h>
9
+
10
+ void ox_err_set(Err e, VALUE clas, const char *format, ...) {
11
+ va_list ap;
12
+
13
+ va_start(ap, format);
14
+ e->clas = clas;
15
+ vsnprintf(e->msg, sizeof(e->msg) - 1, format, ap);
16
+ va_end(ap);
17
+ }
18
+
19
+ #if __GNUC__ > 4
20
+ _Noreturn void
21
+ #else
22
+ void
23
+ #endif
24
+ ox_err_raise(Err e) {
25
+ rb_raise(e->clas, "%s", e->msg);
26
+ }
27
+
28
+ void _ox_err_set_with_location(Err err,
29
+ const char *msg,
30
+ const char *xml,
31
+ const char *current,
32
+ const char *file,
33
+ int line) {
34
+ int xline = 1;
35
+ int col = 1;
36
+
37
+ for (; xml < current && '\n' != *current; current--) {
38
+ col++;
39
+ }
40
+ for (; xml < current; current--) {
41
+ if ('\n' == *current) {
42
+ xline++;
43
+ }
44
+ }
45
+ ox_err_set(err, ox_parse_error_class, "%s at line %d, column %d [%s:%d]\n", msg, xline, col, file, line);
46
+ }
data/ext/ox/err.h ADDED
@@ -0,0 +1,36 @@
1
+ /* err.h
2
+ * Copyright (c) 2011, Peter Ohler
3
+ * All rights reserved.
4
+ */
5
+
6
+ #ifndef OX_ERR_H
7
+ #define OX_ERR_H
8
+
9
+ #include "ruby.h"
10
+
11
+ #define set_error(err, msg, xml, current) _ox_err_set_with_location(err, msg, xml, current, __FILE__, __LINE__)
12
+
13
+ typedef struct _err {
14
+ VALUE clas;
15
+ char msg[128];
16
+ } *Err;
17
+
18
+ extern VALUE ox_arg_error_class;
19
+ extern VALUE ox_parse_error_class;
20
+ extern VALUE ox_syntax_error_class;
21
+
22
+ extern void ox_err_set(Err e, VALUE clas, const char *format, ...);
23
+ extern void
24
+ _ox_err_set_with_location(Err err, const char *msg, const char *xml, const char *current, const char *file, int line);
25
+ extern void ox_err_raise(Err e);
26
+
27
+ inline static void err_init(Err e) {
28
+ e->clas = Qnil;
29
+ *e->msg = '\0';
30
+ }
31
+
32
+ inline static int err_has(Err e) {
33
+ return (Qnil != e->clas);
34
+ }
35
+
36
+ #endif /* OX_ERR_H */
data/ext/ox/extconf.rb ADDED
@@ -0,0 +1,47 @@
1
+ require 'mkmf'
2
+
3
+ extension_name = 'ox'
4
+ dir_config(extension_name)
5
+
6
+ parts = RUBY_DESCRIPTION.split(' ')
7
+ type = parts[0].downcase
8
+ type = 'ree' if 'ruby' == type && RUBY_DESCRIPTION.include?('Ruby Enterprise Edition')
9
+ platform = RUBY_PLATFORM
10
+ version = RUBY_VERSION.split('.')
11
+ puts ">>>>> Creating Makefile for #{type} version #{RUBY_VERSION} on #{platform} <<<<<"
12
+
13
+ dflags = {
14
+ 'RUBY_TYPE' => type,
15
+ (type.upcase + '_RUBY') => nil,
16
+ 'RUBY_VERSION' => RUBY_VERSION,
17
+ 'RUBY_VERSION_MAJOR' => version[0],
18
+ 'RUBY_VERSION_MINOR' => version[1],
19
+ 'RUBY_VERSION_MICRO' => version[2]
20
+ }
21
+
22
+ dflags.each do |k, v|
23
+ if v.nil?
24
+ $CPPFLAGS += " -D#{k}"
25
+ else
26
+ $CPPFLAGS += " -D#{k}=#{v}"
27
+ end
28
+ end
29
+ $CPPFLAGS += ' -Wall'
30
+ # puts "*** $CPPFLAGS: #{$CPPFLAGS}"
31
+ CONFIG['warnflags'].slice!(/ -Wsuggest-attribute=format/)
32
+ CONFIG['warnflags'].slice!(/ -Wdeclaration-after-statement/)
33
+ CONFIG['warnflags'].slice!(/ -Wmissing-noreturn/)
34
+
35
+ have_func('rb_ext_ractor_safe', 'ruby.h')
36
+ have_func('pthread_mutex_init')
37
+ have_func('rb_enc_interned_str')
38
+ have_func('index')
39
+
40
+ have_header('ruby/st.h')
41
+ have_header('sys/uio.h')
42
+
43
+ have_struct_member('struct tm', 'tm_gmtoff')
44
+
45
+ create_makefile("ox/#{extension_name}")
46
+
47
+ `make clean`
data/ext/ox/gen_load.c ADDED
@@ -0,0 +1,342 @@
1
+ /* gen_load.c
2
+ * Copyright (c) 2011, Peter Ohler
3
+ * All rights reserved.
4
+ */
5
+
6
+ #include <errno.h>
7
+ #include <stdarg.h>
8
+ #include <stdio.h>
9
+ #include <stdlib.h>
10
+ #include <string.h>
11
+
12
+ #include "intern.h"
13
+ #include "ox.h"
14
+ #include "ruby.h"
15
+ #include "ruby/encoding.h"
16
+
17
+ static void instruct(PInfo pi, const char *target, Attr attrs, const char *content);
18
+ static void create_doc(PInfo pi);
19
+ static void create_prolog_doc(PInfo pi, const char *target, Attr attrs);
20
+ static void nomode_instruct(PInfo pi, const char *target, Attr attrs, const char *content);
21
+ static void add_doctype(PInfo pi, const char *docType);
22
+ static void add_comment(PInfo pi, const char *comment);
23
+ static void add_cdata(PInfo pi, const char *cdata, size_t len);
24
+ static void add_text(PInfo pi, char *text, int closed);
25
+ static void add_element(PInfo pi, const char *ename, Attr attrs, int hasChildren);
26
+ static void end_element(PInfo pi, const char *ename);
27
+ static void add_instruct(PInfo pi, const char *name, Attr attrs, const char *content);
28
+
29
+ extern ParseCallbacks ox_obj_callbacks;
30
+
31
+ struct _parseCallbacks _ox_gen_callbacks = {
32
+ instruct, /* instruct, */
33
+ add_doctype,
34
+ add_comment,
35
+ add_cdata,
36
+ add_text,
37
+ add_element,
38
+ end_element,
39
+ NULL,
40
+ };
41
+
42
+ ParseCallbacks ox_gen_callbacks = &_ox_gen_callbacks;
43
+
44
+ struct _parseCallbacks _ox_limited_callbacks = {
45
+ 0,
46
+ 0,
47
+ 0,
48
+ 0,
49
+ add_text,
50
+ add_element,
51
+ end_element,
52
+ NULL,
53
+ };
54
+
55
+ ParseCallbacks ox_limited_callbacks = &_ox_limited_callbacks;
56
+
57
+ struct _parseCallbacks _ox_nomode_callbacks = {
58
+ nomode_instruct,
59
+ add_doctype,
60
+ add_comment,
61
+ add_cdata,
62
+ add_text,
63
+ add_element,
64
+ end_element,
65
+ NULL,
66
+ };
67
+
68
+ ParseCallbacks ox_nomode_callbacks = &_ox_nomode_callbacks;
69
+
70
+ static void create_doc(PInfo pi) {
71
+ VALUE doc;
72
+ VALUE nodes;
73
+
74
+ helper_stack_init(&pi->helpers);
75
+ doc = rb_obj_alloc(ox_document_clas);
76
+ RB_GC_GUARD(doc);
77
+ nodes = rb_ary_new();
78
+ rb_ivar_set(doc, ox_attributes_id, rb_hash_new());
79
+ rb_ivar_set(doc, ox_nodes_id, nodes);
80
+ helper_stack_push(&pi->helpers, 0, nodes, NoCode);
81
+ pi->obj = doc;
82
+ }
83
+
84
+ static void create_prolog_doc(PInfo pi, const char *target, Attr attrs) {
85
+ volatile VALUE doc;
86
+ volatile VALUE ah;
87
+ volatile VALUE nodes;
88
+ volatile VALUE sym;
89
+
90
+ if (!helper_stack_empty(&pi->helpers)) { /* top level object */
91
+ ox_err_set(&pi->err, ox_syntax_error_class, "Prolog must be the first element in an XML document.\n");
92
+ return;
93
+ }
94
+ doc = rb_obj_alloc(ox_document_clas);
95
+ ah = rb_hash_new();
96
+ for (; 0 != attrs->name; attrs++) {
97
+ if (Qnil != pi->options->attr_key_mod) {
98
+ sym = rb_funcall(pi->options->attr_key_mod, ox_call_id, 1, rb_str_new2(attrs->name));
99
+ rb_hash_aset(ah, sym, rb_str_new2(attrs->value));
100
+ } else if (Yes == pi->options->sym_keys) {
101
+ if (0 != pi->options->rb_enc) {
102
+ VALUE rstr = rb_str_new2(attrs->name);
103
+
104
+ rb_enc_associate(rstr, pi->options->rb_enc);
105
+ sym = rb_str_intern(rstr);
106
+ } else {
107
+ sym = ID2SYM(rb_intern(attrs->name));
108
+ }
109
+ sym = ID2SYM(rb_intern(attrs->name));
110
+ rb_hash_aset(ah, sym, rb_str_new2(attrs->value));
111
+ } else {
112
+ volatile VALUE rstr = rb_str_new2(attrs->name);
113
+
114
+ if (0 != pi->options->rb_enc) {
115
+ rb_enc_associate(rstr, pi->options->rb_enc);
116
+ }
117
+ rb_hash_aset(ah, rstr, rb_str_new2(attrs->value));
118
+ }
119
+ if (0 == strcmp("encoding", attrs->name)) {
120
+ pi->options->rb_enc = rb_enc_find(attrs->value);
121
+ }
122
+ }
123
+ nodes = rb_ary_new();
124
+ rb_ivar_set(doc, ox_attributes_id, ah);
125
+ rb_ivar_set(doc, ox_nodes_id, nodes);
126
+ helper_stack_push(&pi->helpers, 0, nodes, ArrayCode);
127
+ pi->obj = doc;
128
+ }
129
+
130
+ static void instruct(PInfo pi, const char *target, Attr attrs, const char *content) {
131
+ if (0 == strcmp("xml", target)) {
132
+ create_prolog_doc(pi, target, attrs);
133
+ } else if (0 == strcmp("ox", target)) {
134
+ for (; 0 != attrs->name; attrs++) {
135
+ if (0 == strcmp("version", attrs->name)) {
136
+ if (0 != strcmp("1.0", attrs->value)) {
137
+ ox_err_set(&pi->err,
138
+ ox_syntax_error_class,
139
+ "Only Ox XML Object version 1.0 supported, not %s.\n",
140
+ attrs->value);
141
+ return;
142
+ }
143
+ }
144
+ /* ignore other instructions */
145
+ }
146
+ } else {
147
+ add_instruct(pi, target, attrs, content);
148
+ }
149
+ }
150
+
151
+ static void nomode_instruct(PInfo pi, const char *target, Attr attrs, const char *content) {
152
+ if (0 == strcmp("xml", target)) {
153
+ create_prolog_doc(pi, target, attrs);
154
+ } else if (0 == strcmp("ox", target)) {
155
+ for (; 0 != attrs->name; attrs++) {
156
+ if (0 == strcmp("version", attrs->name)) {
157
+ if (0 != strcmp("1.0", attrs->value)) {
158
+ ox_err_set(&pi->err,
159
+ ox_syntax_error_class,
160
+ "Only Ox XML Object version 1.0 supported, not %s.\n",
161
+ attrs->value);
162
+ return;
163
+ }
164
+ } else if (0 == strcmp("mode", attrs->name)) {
165
+ if (0 == strcmp("object", attrs->value)) {
166
+ pi->pcb = ox_obj_callbacks;
167
+ pi->obj = Qnil;
168
+ helper_stack_init(&pi->helpers);
169
+ } else if (0 == strcmp("generic", attrs->value)) {
170
+ pi->pcb = ox_gen_callbacks;
171
+ } else if (0 == strcmp("limited", attrs->value)) {
172
+ pi->pcb = ox_limited_callbacks;
173
+ pi->obj = Qnil;
174
+ helper_stack_init(&pi->helpers);
175
+ } else {
176
+ ox_err_set(&pi->err,
177
+ ox_syntax_error_class,
178
+ "%s is not a valid processing instruction mode.\n",
179
+ attrs->value);
180
+ return;
181
+ }
182
+ }
183
+ }
184
+ } else {
185
+ if (TRACE <= pi->options->trace) {
186
+ printf("Processing instruction %s ignored.\n", target);
187
+ }
188
+ }
189
+ }
190
+
191
+ static void add_doctype(PInfo pi, const char *docType) {
192
+ VALUE n = rb_obj_alloc(ox_doctype_clas);
193
+ VALUE s = rb_str_new2(docType);
194
+
195
+ if (0 != pi->options->rb_enc) {
196
+ rb_enc_associate(s, pi->options->rb_enc);
197
+ }
198
+ rb_ivar_set(n, ox_at_value_id, s);
199
+ if (helper_stack_empty(&pi->helpers)) { /* top level object */
200
+ create_doc(pi);
201
+ }
202
+ rb_ary_push(helper_stack_peek(&pi->helpers)->obj, n);
203
+ }
204
+
205
+ static void add_comment(PInfo pi, const char *comment) {
206
+ VALUE n = rb_obj_alloc(ox_comment_clas);
207
+ VALUE s = rb_str_new2(comment);
208
+
209
+ if (0 != pi->options->rb_enc) {
210
+ rb_enc_associate(s, pi->options->rb_enc);
211
+ }
212
+ rb_ivar_set(n, ox_at_value_id, s);
213
+ if (helper_stack_empty(&pi->helpers)) { /* top level object */
214
+ create_doc(pi);
215
+ }
216
+ rb_ary_push(helper_stack_peek(&pi->helpers)->obj, n);
217
+ }
218
+
219
+ static void add_cdata(PInfo pi, const char *cdata, size_t len) {
220
+ VALUE n = rb_obj_alloc(ox_cdata_clas);
221
+ VALUE s = rb_str_new2(cdata);
222
+
223
+ if (0 != pi->options->rb_enc) {
224
+ rb_enc_associate(s, pi->options->rb_enc);
225
+ }
226
+ rb_ivar_set(n, ox_at_value_id, s);
227
+ if (helper_stack_empty(&pi->helpers)) { /* top level object */
228
+ create_doc(pi);
229
+ }
230
+ rb_ary_push(helper_stack_peek(&pi->helpers)->obj, n);
231
+ }
232
+
233
+ static void add_text(PInfo pi, char *text, int closed) {
234
+ VALUE s = rb_str_new2(text);
235
+
236
+ if (0 != pi->options->rb_enc) {
237
+ rb_enc_associate(s, pi->options->rb_enc);
238
+ }
239
+ if (helper_stack_empty(&pi->helpers)) { /* top level object */
240
+ create_doc(pi);
241
+ }
242
+ rb_ary_push(helper_stack_peek(&pi->helpers)->obj, s);
243
+ }
244
+
245
+ static void add_element(PInfo pi, const char *ename, Attr attrs, int hasChildren) {
246
+ VALUE e;
247
+ VALUE s = rb_str_new2(ename);
248
+
249
+ if (Qnil != pi->options->element_key_mod) {
250
+ s = rb_funcall(pi->options->element_key_mod, ox_call_id, 1, s);
251
+ }
252
+ if (0 != pi->options->rb_enc) {
253
+ rb_enc_associate(s, pi->options->rb_enc);
254
+ }
255
+ e = rb_obj_alloc(ox_element_clas);
256
+ rb_ivar_set(e, ox_at_value_id, s);
257
+ if (0 != attrs->name) {
258
+ volatile VALUE ah = rb_hash_new();
259
+
260
+ for (; 0 != attrs->name; attrs++) {
261
+ volatile VALUE sym;
262
+
263
+ if (Qnil != pi->options->attr_key_mod) {
264
+ sym = rb_funcall(pi->options->attr_key_mod, ox_call_id, 1, rb_str_new2(attrs->name));
265
+ } else if (Yes == pi->options->sym_keys) {
266
+ sym = ox_sym_intern(attrs->name, strlen(attrs->name), NULL);
267
+ } else {
268
+ sym = ox_str_intern(attrs->name, strlen(attrs->name), NULL);
269
+ }
270
+ s = rb_str_new2(attrs->value);
271
+ if (0 != pi->options->rb_enc) {
272
+ rb_enc_associate(s, pi->options->rb_enc);
273
+ }
274
+ rb_hash_aset(ah, sym, s);
275
+ }
276
+ rb_ivar_set(e, ox_attributes_id, ah);
277
+ }
278
+ if (helper_stack_empty(&pi->helpers)) { /* top level object */
279
+ pi->obj = e;
280
+ } else {
281
+ rb_ary_push(helper_stack_peek(&pi->helpers)->obj, e);
282
+ }
283
+ if (hasChildren) {
284
+ VALUE nodes = rb_ary_new();
285
+
286
+ rb_ivar_set(e, ox_nodes_id, nodes);
287
+ helper_stack_push(&pi->helpers, 0, nodes, NoCode);
288
+ } else {
289
+ helper_stack_push(&pi->helpers, 0, Qnil, NoCode); // will be popped in end_element
290
+ }
291
+ }
292
+
293
+ static void end_element(PInfo pi, const char *ename) {
294
+ if (!helper_stack_empty(&pi->helpers)) {
295
+ helper_stack_pop(&pi->helpers);
296
+ }
297
+ }
298
+
299
+ static void add_instruct(PInfo pi, const char *name, Attr attrs, const char *content) {
300
+ VALUE inst;
301
+ VALUE s = rb_str_new2(name);
302
+ VALUE c = Qnil;
303
+
304
+ if (0 != content) {
305
+ c = rb_str_new2(content);
306
+ }
307
+ if (0 != pi->options->rb_enc) {
308
+ rb_enc_associate(s, pi->options->rb_enc);
309
+ if (0 != content) {
310
+ rb_enc_associate(c, pi->options->rb_enc);
311
+ }
312
+ }
313
+ inst = rb_obj_alloc(ox_instruct_clas);
314
+ rb_ivar_set(inst, ox_at_value_id, s);
315
+ if (0 != content) {
316
+ rb_ivar_set(inst, ox_at_content_id, c);
317
+ } else if (0 != attrs->name) {
318
+ volatile VALUE ah = rb_hash_new();
319
+
320
+ for (; 0 != attrs->name; attrs++) {
321
+ volatile VALUE sym;
322
+
323
+ if (Qnil != pi->options->attr_key_mod) {
324
+ sym = rb_funcall(pi->options->attr_key_mod, ox_call_id, 1, rb_str_new2(attrs->name));
325
+ } else if (Yes == pi->options->sym_keys) {
326
+ sym = ox_sym_intern(attrs->name, strlen(attrs->name), NULL);
327
+ } else {
328
+ sym = ox_str_intern(attrs->name, strlen(attrs->name), NULL);
329
+ }
330
+ s = rb_str_new2(attrs->value);
331
+ if (0 != pi->options->rb_enc) {
332
+ rb_enc_associate(s, pi->options->rb_enc);
333
+ }
334
+ rb_hash_aset(ah, sym, s);
335
+ }
336
+ rb_ivar_set(inst, ox_attributes_id, ah);
337
+ }
338
+ if (helper_stack_empty(&pi->helpers)) { /* top level object */
339
+ create_doc(pi);
340
+ }
341
+ rb_ary_push(helper_stack_peek(&pi->helpers)->obj, inst);
342
+ }