psych 1.3.4 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.rdoc +138 -0
  3. data/Manifest.txt +27 -8
  4. data/README.rdoc +23 -2
  5. data/Rakefile +1 -1
  6. data/ext/psych/depend +3 -0
  7. data/ext/psych/extconf.rb +27 -11
  8. data/ext/psych/psych.h +4 -4
  9. data/ext/psych/{emitter.c → psych_emitter.c} +0 -0
  10. data/ext/psych/{emitter.h → psych_emitter.h} +0 -0
  11. data/ext/psych/{parser.c → psych_parser.c} +1 -1
  12. data/ext/psych/{parser.h → psych_parser.h} +0 -0
  13. data/ext/psych/{to_ruby.c → psych_to_ruby.c} +3 -1
  14. data/ext/psych/{to_ruby.h → psych_to_ruby.h} +0 -0
  15. data/ext/psych/{yaml_tree.c → psych_yaml_tree.c} +0 -0
  16. data/ext/psych/{yaml_tree.h → psych_yaml_tree.h} +0 -0
  17. data/ext/psych/yaml/LICENSE +19 -0
  18. data/ext/psych/yaml/api.c +1392 -0
  19. data/ext/psych/yaml/config.h +11 -0
  20. data/ext/psych/yaml/dumper.c +394 -0
  21. data/ext/psych/yaml/emitter.c +2329 -0
  22. data/ext/psych/yaml/loader.c +432 -0
  23. data/ext/psych/yaml/parser.c +1374 -0
  24. data/ext/psych/yaml/reader.c +465 -0
  25. data/ext/psych/yaml/scanner.c +3570 -0
  26. data/ext/psych/yaml/writer.c +141 -0
  27. data/ext/psych/yaml/yaml.h +1971 -0
  28. data/ext/psych/yaml/yaml_private.h +643 -0
  29. data/lib/psych.rb +217 -51
  30. data/lib/psych/class_loader.rb +101 -0
  31. data/lib/psych/core_ext.rb +1 -8
  32. data/lib/psych/deprecated.rb +3 -1
  33. data/lib/psych/exception.rb +13 -0
  34. data/lib/psych/handler.rb +13 -0
  35. data/lib/psych/handlers/recorder.rb +39 -0
  36. data/lib/psych/json/stream.rb +1 -0
  37. data/lib/psych/nodes/node.rb +3 -1
  38. data/lib/psych/scalar_scanner.rb +46 -25
  39. data/lib/psych/stream.rb +1 -0
  40. data/lib/psych/streaming.rb +10 -5
  41. data/lib/psych/syntax_error.rb +3 -1
  42. data/lib/psych/visitors/json_tree.rb +5 -2
  43. data/lib/psych/visitors/to_ruby.rb +123 -75
  44. data/lib/psych/visitors/yaml_tree.rb +59 -17
  45. data/lib/psych/y.rb +9 -0
  46. data/test/psych/handlers/test_recorder.rb +25 -0
  47. data/test/psych/helper.rb +30 -1
  48. data/test/psych/test_alias_and_anchor.rb +1 -1
  49. data/test/psych/test_array.rb +1 -1
  50. data/test/psych/test_boolean.rb +1 -1
  51. data/test/psych/test_class.rb +1 -1
  52. data/test/psych/test_coder.rb +3 -3
  53. data/test/psych/test_date_time.rb +1 -1
  54. data/test/psych/test_deprecated.rb +6 -2
  55. data/test/psych/test_document.rb +1 -1
  56. data/test/psych/test_emitter.rb +1 -1
  57. data/test/psych/test_encoding.rb +51 -65
  58. data/test/psych/test_engine_manager.rb +1 -11
  59. data/test/psych/test_exception.rb +40 -19
  60. data/test/psych/test_hash.rb +1 -1
  61. data/test/psych/test_json_tree.rb +1 -1
  62. data/test/psych/test_merge_keys.rb +52 -1
  63. data/test/psych/test_nil.rb +1 -1
  64. data/test/psych/test_null.rb +1 -1
  65. data/test/psych/test_numeric.rb +21 -1
  66. data/test/psych/test_object.rb +1 -1
  67. data/test/psych/test_object_references.rb +3 -3
  68. data/test/psych/test_omap.rb +1 -1
  69. data/test/psych/test_parser.rb +1 -1
  70. data/test/psych/test_psych.rb +15 -15
  71. data/test/psych/test_safe_load.rb +97 -0
  72. data/test/psych/test_scalar.rb +1 -1
  73. data/test/psych/test_scalar_scanner.rb +17 -2
  74. data/test/psych/test_serialize_subclasses.rb +1 -1
  75. data/test/psych/test_set.rb +1 -1
  76. data/test/psych/test_stream.rb +1 -1
  77. data/test/psych/test_string.rb +51 -3
  78. data/test/psych/test_struct.rb +1 -1
  79. data/test/psych/test_symbol.rb +1 -1
  80. data/test/psych/test_tainted.rb +8 -8
  81. data/test/psych/test_to_yaml_properties.rb +1 -1
  82. data/test/psych/test_tree_builder.rb +1 -1
  83. data/test/psych/test_yaml.rb +22 -2
  84. data/test/psych/test_yamldbm.rb +1 -1
  85. data/test/psych/test_yamlstore.rb +1 -1
  86. data/test/psych/visitors/test_to_ruby.rb +5 -4
  87. data/test/psych/visitors/test_yaml_tree.rb +19 -1
  88. metadata +45 -34
@@ -0,0 +1,643 @@
1
+ #ifdef RUBY_EXTCONF_H
2
+ #include RUBY_EXTCONF_H
3
+ #endif
4
+
5
+ #if HAVE_CONFIG_H
6
+ #include <config.h>
7
+ #endif
8
+
9
+ #include <yaml.h>
10
+
11
+ #include <assert.h>
12
+ #include <limits.h>
13
+
14
+ /*
15
+ * Memory management.
16
+ */
17
+
18
+ YAML_DECLARE(void *)
19
+ yaml_malloc(size_t size);
20
+
21
+ YAML_DECLARE(void *)
22
+ yaml_realloc(void *ptr, size_t size);
23
+
24
+ YAML_DECLARE(void)
25
+ yaml_free(void *ptr);
26
+
27
+ YAML_DECLARE(yaml_char_t *)
28
+ yaml_strdup(const yaml_char_t *);
29
+
30
+ /*
31
+ * Reader: Ensure that the buffer contains at least `length` characters.
32
+ */
33
+
34
+ YAML_DECLARE(int)
35
+ yaml_parser_update_buffer(yaml_parser_t *parser, size_t length);
36
+
37
+ /*
38
+ * Scanner: Ensure that the token stack contains at least one token ready.
39
+ */
40
+
41
+ YAML_DECLARE(int)
42
+ yaml_parser_fetch_more_tokens(yaml_parser_t *parser);
43
+
44
+ /*
45
+ * The size of the input raw buffer.
46
+ */
47
+
48
+ #define INPUT_RAW_BUFFER_SIZE 16384
49
+
50
+ /*
51
+ * The size of the input buffer.
52
+ *
53
+ * It should be possible to decode the whole raw buffer.
54
+ */
55
+
56
+ #define INPUT_BUFFER_SIZE (INPUT_RAW_BUFFER_SIZE*3)
57
+
58
+ /*
59
+ * The size of the output buffer.
60
+ */
61
+
62
+ #define OUTPUT_BUFFER_SIZE 16384
63
+
64
+ /*
65
+ * The size of the output raw buffer.
66
+ *
67
+ * It should be possible to encode the whole output buffer.
68
+ */
69
+
70
+ #define OUTPUT_RAW_BUFFER_SIZE (OUTPUT_BUFFER_SIZE*2+2)
71
+
72
+ /*
73
+ * The size of other stacks and queues.
74
+ */
75
+
76
+ #define INITIAL_STACK_SIZE 16
77
+ #define INITIAL_QUEUE_SIZE 16
78
+ #define INITIAL_STRING_SIZE 16
79
+
80
+ /*
81
+ * Buffer management.
82
+ */
83
+
84
+ #define BUFFER_INIT(context,buffer,size) \
85
+ (((buffer).start = yaml_malloc(size)) ? \
86
+ ((buffer).last = (buffer).pointer = (buffer).start, \
87
+ (buffer).end = (buffer).start+(size), \
88
+ 1) : \
89
+ ((context)->error = YAML_MEMORY_ERROR, \
90
+ 0))
91
+
92
+ #define BUFFER_DEL(context,buffer) \
93
+ (yaml_free((buffer).start), \
94
+ (buffer).start = (buffer).pointer = (buffer).end = 0)
95
+
96
+ /*
97
+ * String management.
98
+ */
99
+
100
+ typedef struct {
101
+ yaml_char_t *start;
102
+ yaml_char_t *end;
103
+ yaml_char_t *pointer;
104
+ } yaml_string_t;
105
+
106
+ YAML_DECLARE(int)
107
+ yaml_string_extend(yaml_char_t **start,
108
+ yaml_char_t **pointer, yaml_char_t **end);
109
+
110
+ YAML_DECLARE(int)
111
+ yaml_string_join(
112
+ yaml_char_t **a_start, yaml_char_t **a_pointer, yaml_char_t **a_end,
113
+ yaml_char_t **b_start, yaml_char_t **b_pointer, yaml_char_t **b_end);
114
+
115
+ #define NULL_STRING { NULL, NULL, NULL }
116
+
117
+ #define STRING(string,length) { (string), (string)+(length), (string) }
118
+
119
+ #define STRING_ASSIGN(value,string,length) \
120
+ ((value).start = (string), \
121
+ (value).end = (string)+(length), \
122
+ (value).pointer = (string))
123
+
124
+ #define STRING_INIT(context,string,size) \
125
+ (((string).start = yaml_malloc(size)) ? \
126
+ ((string).pointer = (string).start, \
127
+ (string).end = (string).start+(size), \
128
+ memset((string).start, 0, (size)), \
129
+ 1) : \
130
+ ((context)->error = YAML_MEMORY_ERROR, \
131
+ 0))
132
+
133
+ #define STRING_DEL(context,string) \
134
+ (yaml_free((string).start), \
135
+ (string).start = (string).pointer = (string).end = 0)
136
+
137
+ #define STRING_EXTEND(context,string) \
138
+ (((string).pointer+5 < (string).end) \
139
+ || yaml_string_extend(&(string).start, \
140
+ &(string).pointer, &(string).end))
141
+
142
+ #define CLEAR(context,string) \
143
+ ((string).pointer = (string).start, \
144
+ memset((string).start, 0, (string).end-(string).start))
145
+
146
+ #define JOIN(context,string_a,string_b) \
147
+ ((yaml_string_join(&(string_a).start, &(string_a).pointer, \
148
+ &(string_a).end, &(string_b).start, \
149
+ &(string_b).pointer, &(string_b).end)) ? \
150
+ ((string_b).pointer = (string_b).start, \
151
+ 1) : \
152
+ ((context)->error = YAML_MEMORY_ERROR, \
153
+ 0))
154
+
155
+ /*
156
+ * String check operations.
157
+ */
158
+
159
+ /*
160
+ * Check the octet at the specified position.
161
+ */
162
+
163
+ #define CHECK_AT(string,octet,offset) \
164
+ ((string).pointer[offset] == (yaml_char_t)(octet))
165
+
166
+ /*
167
+ * Check the current octet in the buffer.
168
+ */
169
+
170
+ #define CHECK(string,octet) CHECK_AT((string),(octet),0)
171
+
172
+ /*
173
+ * Check if the character at the specified position is an alphabetical
174
+ * character, a digit, '_', or '-'.
175
+ */
176
+
177
+ #define IS_ALPHA_AT(string,offset) \
178
+ (((string).pointer[offset] >= (yaml_char_t) '0' && \
179
+ (string).pointer[offset] <= (yaml_char_t) '9') || \
180
+ ((string).pointer[offset] >= (yaml_char_t) 'A' && \
181
+ (string).pointer[offset] <= (yaml_char_t) 'Z') || \
182
+ ((string).pointer[offset] >= (yaml_char_t) 'a' && \
183
+ (string).pointer[offset] <= (yaml_char_t) 'z') || \
184
+ (string).pointer[offset] == '_' || \
185
+ (string).pointer[offset] == '-')
186
+
187
+ #define IS_ALPHA(string) IS_ALPHA_AT((string),0)
188
+
189
+ /*
190
+ * Check if the character at the specified position is a digit.
191
+ */
192
+
193
+ #define IS_DIGIT_AT(string,offset) \
194
+ (((string).pointer[offset] >= (yaml_char_t) '0' && \
195
+ (string).pointer[offset] <= (yaml_char_t) '9'))
196
+
197
+ #define IS_DIGIT(string) IS_DIGIT_AT((string),0)
198
+
199
+ /*
200
+ * Get the value of a digit.
201
+ */
202
+
203
+ #define AS_DIGIT_AT(string,offset) \
204
+ ((string).pointer[offset] - (yaml_char_t) '0')
205
+
206
+ #define AS_DIGIT(string) AS_DIGIT_AT((string),0)
207
+
208
+ /*
209
+ * Check if the character at the specified position is a hex-digit.
210
+ */
211
+
212
+ #define IS_HEX_AT(string,offset) \
213
+ (((string).pointer[offset] >= (yaml_char_t) '0' && \
214
+ (string).pointer[offset] <= (yaml_char_t) '9') || \
215
+ ((string).pointer[offset] >= (yaml_char_t) 'A' && \
216
+ (string).pointer[offset] <= (yaml_char_t) 'F') || \
217
+ ((string).pointer[offset] >= (yaml_char_t) 'a' && \
218
+ (string).pointer[offset] <= (yaml_char_t) 'f'))
219
+
220
+ #define IS_HEX(string) IS_HEX_AT((string),0)
221
+
222
+ /*
223
+ * Get the value of a hex-digit.
224
+ */
225
+
226
+ #define AS_HEX_AT(string,offset) \
227
+ (((string).pointer[offset] >= (yaml_char_t) 'A' && \
228
+ (string).pointer[offset] <= (yaml_char_t) 'F') ? \
229
+ ((string).pointer[offset] - (yaml_char_t) 'A' + 10) : \
230
+ ((string).pointer[offset] >= (yaml_char_t) 'a' && \
231
+ (string).pointer[offset] <= (yaml_char_t) 'f') ? \
232
+ ((string).pointer[offset] - (yaml_char_t) 'a' + 10) : \
233
+ ((string).pointer[offset] - (yaml_char_t) '0'))
234
+
235
+ #define AS_HEX(string) AS_HEX_AT((string),0)
236
+
237
+ /*
238
+ * Check if the character is ASCII.
239
+ */
240
+
241
+ #define IS_ASCII_AT(string,offset) \
242
+ ((string).pointer[offset] <= (yaml_char_t) '\x7F')
243
+
244
+ #define IS_ASCII(string) IS_ASCII_AT((string),0)
245
+
246
+ /*
247
+ * Check if the character can be printed unescaped.
248
+ */
249
+
250
+ #define IS_PRINTABLE_AT(string,offset) \
251
+ (((string).pointer[offset] == 0x0A) /* . == #x0A */ \
252
+ || ((string).pointer[offset] >= 0x20 /* #x20 <= . <= #x7E */ \
253
+ && (string).pointer[offset] <= 0x7E) \
254
+ || ((string).pointer[offset] == 0xC2 /* #0xA0 <= . <= #xD7FF */ \
255
+ && (string).pointer[offset+1] >= 0xA0) \
256
+ || ((string).pointer[offset] > 0xC2 \
257
+ && (string).pointer[offset] < 0xED) \
258
+ || ((string).pointer[offset] == 0xED \
259
+ && (string).pointer[offset+1] < 0xA0) \
260
+ || ((string).pointer[offset] == 0xEE) \
261
+ || ((string).pointer[offset] == 0xEF /* #xE000 <= . <= #xFFFD */ \
262
+ && !((string).pointer[offset+1] == 0xBB /* && . != #xFEFF */ \
263
+ && (string).pointer[offset+2] == 0xBF) \
264
+ && !((string).pointer[offset+1] == 0xBF \
265
+ && ((string).pointer[offset+2] == 0xBE \
266
+ || (string).pointer[offset+2] == 0xBF))))
267
+
268
+ #define IS_PRINTABLE(string) IS_PRINTABLE_AT((string),0)
269
+
270
+ /*
271
+ * Check if the character at the specified position is NUL.
272
+ */
273
+
274
+ #define IS_Z_AT(string,offset) CHECK_AT((string),'\0',(offset))
275
+
276
+ #define IS_Z(string) IS_Z_AT((string),0)
277
+
278
+ /*
279
+ * Check if the character at the specified position is BOM.
280
+ */
281
+
282
+ #define IS_BOM_AT(string,offset) \
283
+ (CHECK_AT((string),'\xEF',(offset)) \
284
+ && CHECK_AT((string),'\xBB',(offset)+1) \
285
+ && CHECK_AT((string),'\xBF',(offset)+2)) /* BOM (#xFEFF) */
286
+
287
+ #define IS_BOM(string) IS_BOM_AT(string,0)
288
+
289
+ /*
290
+ * Check if the character at the specified position is space.
291
+ */
292
+
293
+ #define IS_SPACE_AT(string,offset) CHECK_AT((string),' ',(offset))
294
+
295
+ #define IS_SPACE(string) IS_SPACE_AT((string),0)
296
+
297
+ /*
298
+ * Check if the character at the specified position is tab.
299
+ */
300
+
301
+ #define IS_TAB_AT(string,offset) CHECK_AT((string),'\t',(offset))
302
+
303
+ #define IS_TAB(string) IS_TAB_AT((string),0)
304
+
305
+ /*
306
+ * Check if the character at the specified position is blank (space or tab).
307
+ */
308
+
309
+ #define IS_BLANK_AT(string,offset) \
310
+ (IS_SPACE_AT((string),(offset)) || IS_TAB_AT((string),(offset)))
311
+
312
+ #define IS_BLANK(string) IS_BLANK_AT((string),0)
313
+
314
+ /*
315
+ * Check if the character at the specified position is a line break.
316
+ */
317
+
318
+ #define IS_BREAK_AT(string,offset) \
319
+ (CHECK_AT((string),'\r',(offset)) /* CR (#xD)*/ \
320
+ || CHECK_AT((string),'\n',(offset)) /* LF (#xA) */ \
321
+ || (CHECK_AT((string),'\xC2',(offset)) \
322
+ && CHECK_AT((string),'\x85',(offset)+1)) /* NEL (#x85) */ \
323
+ || (CHECK_AT((string),'\xE2',(offset)) \
324
+ && CHECK_AT((string),'\x80',(offset)+1) \
325
+ && CHECK_AT((string),'\xA8',(offset)+2)) /* LS (#x2028) */ \
326
+ || (CHECK_AT((string),'\xE2',(offset)) \
327
+ && CHECK_AT((string),'\x80',(offset)+1) \
328
+ && CHECK_AT((string),'\xA9',(offset)+2))) /* PS (#x2029) */
329
+
330
+ #define IS_BREAK(string) IS_BREAK_AT((string),0)
331
+
332
+ #define IS_CRLF_AT(string,offset) \
333
+ (CHECK_AT((string),'\r',(offset)) && CHECK_AT((string),'\n',(offset)+1))
334
+
335
+ #define IS_CRLF(string) IS_CRLF_AT((string),0)
336
+
337
+ /*
338
+ * Check if the character is a line break or NUL.
339
+ */
340
+
341
+ #define IS_BREAKZ_AT(string,offset) \
342
+ (IS_BREAK_AT((string),(offset)) || IS_Z_AT((string),(offset)))
343
+
344
+ #define IS_BREAKZ(string) IS_BREAKZ_AT((string),0)
345
+
346
+ /*
347
+ * Check if the character is a line break, space, or NUL.
348
+ */
349
+
350
+ #define IS_SPACEZ_AT(string,offset) \
351
+ (IS_SPACE_AT((string),(offset)) || IS_BREAKZ_AT((string),(offset)))
352
+
353
+ #define IS_SPACEZ(string) IS_SPACEZ_AT((string),0)
354
+
355
+ /*
356
+ * Check if the character is a line break, space, tab, or NUL.
357
+ */
358
+
359
+ #define IS_BLANKZ_AT(string,offset) \
360
+ (IS_BLANK_AT((string),(offset)) || IS_BREAKZ_AT((string),(offset)))
361
+
362
+ #define IS_BLANKZ(string) IS_BLANKZ_AT((string),0)
363
+
364
+ /*
365
+ * Determine the width of the character.
366
+ */
367
+
368
+ #define WIDTH_AT(string,offset) \
369
+ (((string).pointer[offset] & 0x80) == 0x00 ? 1 : \
370
+ ((string).pointer[offset] & 0xE0) == 0xC0 ? 2 : \
371
+ ((string).pointer[offset] & 0xF0) == 0xE0 ? 3 : \
372
+ ((string).pointer[offset] & 0xF8) == 0xF0 ? 4 : 0)
373
+
374
+ #define WIDTH(string) WIDTH_AT((string),0)
375
+
376
+ /*
377
+ * Move the string pointer to the next character.
378
+ */
379
+
380
+ #define MOVE(string) ((string).pointer += WIDTH((string)))
381
+
382
+ /*
383
+ * Copy a character and move the pointers of both strings.
384
+ */
385
+
386
+ #define COPY(string_a,string_b) \
387
+ ((*(string_b).pointer & 0x80) == 0x00 ? \
388
+ (*((string_a).pointer++) = *((string_b).pointer++)) : \
389
+ (*(string_b).pointer & 0xE0) == 0xC0 ? \
390
+ (*((string_a).pointer++) = *((string_b).pointer++), \
391
+ *((string_a).pointer++) = *((string_b).pointer++)) : \
392
+ (*(string_b).pointer & 0xF0) == 0xE0 ? \
393
+ (*((string_a).pointer++) = *((string_b).pointer++), \
394
+ *((string_a).pointer++) = *((string_b).pointer++), \
395
+ *((string_a).pointer++) = *((string_b).pointer++)) : \
396
+ (*(string_b).pointer & 0xF8) == 0xF0 ? \
397
+ (*((string_a).pointer++) = *((string_b).pointer++), \
398
+ *((string_a).pointer++) = *((string_b).pointer++), \
399
+ *((string_a).pointer++) = *((string_b).pointer++), \
400
+ *((string_a).pointer++) = *((string_b).pointer++)) : 0)
401
+
402
+ /*
403
+ * Stack and queue management.
404
+ */
405
+
406
+ YAML_DECLARE(int)
407
+ yaml_stack_extend(void **start, void **top, void **end);
408
+
409
+ YAML_DECLARE(int)
410
+ yaml_queue_extend(void **start, void **head, void **tail, void **end);
411
+
412
+ #define STACK_INIT(context,stack,size) \
413
+ (((stack).start = yaml_malloc((size)*sizeof(*(stack).start))) ? \
414
+ ((stack).top = (stack).start, \
415
+ (stack).end = (stack).start+(size), \
416
+ 1) : \
417
+ ((context)->error = YAML_MEMORY_ERROR, \
418
+ 0))
419
+
420
+ #define STACK_DEL(context,stack) \
421
+ (yaml_free((stack).start), \
422
+ (stack).start = (stack).top = (stack).end = 0)
423
+
424
+ #define STACK_EMPTY(context,stack) \
425
+ ((stack).start == (stack).top)
426
+
427
+ #define PUSH(context,stack,value) \
428
+ (((stack).top != (stack).end \
429
+ || yaml_stack_extend((void **)&(stack).start, \
430
+ (void **)&(stack).top, (void **)&(stack).end)) ? \
431
+ (*((stack).top++) = value, \
432
+ 1) : \
433
+ ((context)->error = YAML_MEMORY_ERROR, \
434
+ 0))
435
+
436
+ #define POP(context,stack) \
437
+ (*(--(stack).top))
438
+
439
+ #define QUEUE_INIT(context,queue,size) \
440
+ (((queue).start = yaml_malloc((size)*sizeof(*(queue).start))) ? \
441
+ ((queue).head = (queue).tail = (queue).start, \
442
+ (queue).end = (queue).start+(size), \
443
+ 1) : \
444
+ ((context)->error = YAML_MEMORY_ERROR, \
445
+ 0))
446
+
447
+ #define QUEUE_DEL(context,queue) \
448
+ (yaml_free((queue).start), \
449
+ (queue).start = (queue).head = (queue).tail = (queue).end = 0)
450
+
451
+ #define QUEUE_EMPTY(context,queue) \
452
+ ((queue).head == (queue).tail)
453
+
454
+ #define ENQUEUE(context,queue,value) \
455
+ (((queue).tail != (queue).end \
456
+ || yaml_queue_extend((void **)&(queue).start, (void **)&(queue).head, \
457
+ (void **)&(queue).tail, (void **)&(queue).end)) ? \
458
+ (*((queue).tail++) = value, \
459
+ 1) : \
460
+ ((context)->error = YAML_MEMORY_ERROR, \
461
+ 0))
462
+
463
+ #define DEQUEUE(context,queue) \
464
+ (*((queue).head++))
465
+
466
+ #define QUEUE_INSERT(context,queue,index,value) \
467
+ (((queue).tail != (queue).end \
468
+ || yaml_queue_extend((void **)&(queue).start, (void **)&(queue).head, \
469
+ (void **)&(queue).tail, (void **)&(queue).end)) ? \
470
+ (memmove((queue).head+(index)+1,(queue).head+(index), \
471
+ ((queue).tail-(queue).head-(index))*sizeof(*(queue).start)), \
472
+ *((queue).head+(index)) = value, \
473
+ (queue).tail++, \
474
+ 1) : \
475
+ ((context)->error = YAML_MEMORY_ERROR, \
476
+ 0))
477
+
478
+ /*
479
+ * Token initializers.
480
+ */
481
+
482
+ #define TOKEN_INIT(token,token_type,token_start_mark,token_end_mark) \
483
+ (memset(&(token), 0, sizeof(yaml_token_t)), \
484
+ (token).type = (token_type), \
485
+ (token).start_mark = (token_start_mark), \
486
+ (token).end_mark = (token_end_mark))
487
+
488
+ #define STREAM_START_TOKEN_INIT(token,token_encoding,start_mark,end_mark) \
489
+ (TOKEN_INIT((token),YAML_STREAM_START_TOKEN,(start_mark),(end_mark)), \
490
+ (token).data.stream_start.encoding = (token_encoding))
491
+
492
+ #define STREAM_END_TOKEN_INIT(token,start_mark,end_mark) \
493
+ (TOKEN_INIT((token),YAML_STREAM_END_TOKEN,(start_mark),(end_mark)))
494
+
495
+ #define ALIAS_TOKEN_INIT(token,token_value,start_mark,end_mark) \
496
+ (TOKEN_INIT((token),YAML_ALIAS_TOKEN,(start_mark),(end_mark)), \
497
+ (token).data.alias.value = (token_value))
498
+
499
+ #define ANCHOR_TOKEN_INIT(token,token_value,start_mark,end_mark) \
500
+ (TOKEN_INIT((token),YAML_ANCHOR_TOKEN,(start_mark),(end_mark)), \
501
+ (token).data.anchor.value = (token_value))
502
+
503
+ #define TAG_TOKEN_INIT(token,token_handle,token_suffix,start_mark,end_mark) \
504
+ (TOKEN_INIT((token),YAML_TAG_TOKEN,(start_mark),(end_mark)), \
505
+ (token).data.tag.handle = (token_handle), \
506
+ (token).data.tag.suffix = (token_suffix))
507
+
508
+ #define SCALAR_TOKEN_INIT(token,token_value,token_length,token_style,start_mark,end_mark) \
509
+ (TOKEN_INIT((token),YAML_SCALAR_TOKEN,(start_mark),(end_mark)), \
510
+ (token).data.scalar.value = (token_value), \
511
+ (token).data.scalar.length = (token_length), \
512
+ (token).data.scalar.style = (token_style))
513
+
514
+ #define VERSION_DIRECTIVE_TOKEN_INIT(token,token_major,token_minor,start_mark,end_mark) \
515
+ (TOKEN_INIT((token),YAML_VERSION_DIRECTIVE_TOKEN,(start_mark),(end_mark)), \
516
+ (token).data.version_directive.major = (token_major), \
517
+ (token).data.version_directive.minor = (token_minor))
518
+
519
+ #define TAG_DIRECTIVE_TOKEN_INIT(token,token_handle,token_prefix,start_mark,end_mark) \
520
+ (TOKEN_INIT((token),YAML_TAG_DIRECTIVE_TOKEN,(start_mark),(end_mark)), \
521
+ (token).data.tag_directive.handle = (token_handle), \
522
+ (token).data.tag_directive.prefix = (token_prefix))
523
+
524
+ /*
525
+ * Event initializers.
526
+ */
527
+
528
+ #define EVENT_INIT(event,event_type,event_start_mark,event_end_mark) \
529
+ (memset(&(event), 0, sizeof(yaml_event_t)), \
530
+ (event).type = (event_type), \
531
+ (event).start_mark = (event_start_mark), \
532
+ (event).end_mark = (event_end_mark))
533
+
534
+ #define STREAM_START_EVENT_INIT(event,event_encoding,start_mark,end_mark) \
535
+ (EVENT_INIT((event),YAML_STREAM_START_EVENT,(start_mark),(end_mark)), \
536
+ (event).data.stream_start.encoding = (event_encoding))
537
+
538
+ #define STREAM_END_EVENT_INIT(event,start_mark,end_mark) \
539
+ (EVENT_INIT((event),YAML_STREAM_END_EVENT,(start_mark),(end_mark)))
540
+
541
+ #define DOCUMENT_START_EVENT_INIT(event,event_version_directive, \
542
+ event_tag_directives_start,event_tag_directives_end,event_implicit,start_mark,end_mark) \
543
+ (EVENT_INIT((event),YAML_DOCUMENT_START_EVENT,(start_mark),(end_mark)), \
544
+ (event).data.document_start.version_directive = (event_version_directive), \
545
+ (event).data.document_start.tag_directives.start = (event_tag_directives_start), \
546
+ (event).data.document_start.tag_directives.end = (event_tag_directives_end), \
547
+ (event).data.document_start.implicit = (event_implicit))
548
+
549
+ #define DOCUMENT_END_EVENT_INIT(event,event_implicit,start_mark,end_mark) \
550
+ (EVENT_INIT((event),YAML_DOCUMENT_END_EVENT,(start_mark),(end_mark)), \
551
+ (event).data.document_end.implicit = (event_implicit))
552
+
553
+ #define ALIAS_EVENT_INIT(event,event_anchor,start_mark,end_mark) \
554
+ (EVENT_INIT((event),YAML_ALIAS_EVENT,(start_mark),(end_mark)), \
555
+ (event).data.alias.anchor = (event_anchor))
556
+
557
+ #define SCALAR_EVENT_INIT(event,event_anchor,event_tag,event_value,event_length, \
558
+ event_plain_implicit, event_quoted_implicit,event_style,start_mark,end_mark) \
559
+ (EVENT_INIT((event),YAML_SCALAR_EVENT,(start_mark),(end_mark)), \
560
+ (event).data.scalar.anchor = (event_anchor), \
561
+ (event).data.scalar.tag = (event_tag), \
562
+ (event).data.scalar.value = (event_value), \
563
+ (event).data.scalar.length = (event_length), \
564
+ (event).data.scalar.plain_implicit = (event_plain_implicit), \
565
+ (event).data.scalar.quoted_implicit = (event_quoted_implicit), \
566
+ (event).data.scalar.style = (event_style))
567
+
568
+ #define SEQUENCE_START_EVENT_INIT(event,event_anchor,event_tag, \
569
+ event_implicit,event_style,start_mark,end_mark) \
570
+ (EVENT_INIT((event),YAML_SEQUENCE_START_EVENT,(start_mark),(end_mark)), \
571
+ (event).data.sequence_start.anchor = (event_anchor), \
572
+ (event).data.sequence_start.tag = (event_tag), \
573
+ (event).data.sequence_start.implicit = (event_implicit), \
574
+ (event).data.sequence_start.style = (event_style))
575
+
576
+ #define SEQUENCE_END_EVENT_INIT(event,start_mark,end_mark) \
577
+ (EVENT_INIT((event),YAML_SEQUENCE_END_EVENT,(start_mark),(end_mark)))
578
+
579
+ #define MAPPING_START_EVENT_INIT(event,event_anchor,event_tag, \
580
+ event_implicit,event_style,start_mark,end_mark) \
581
+ (EVENT_INIT((event),YAML_MAPPING_START_EVENT,(start_mark),(end_mark)), \
582
+ (event).data.mapping_start.anchor = (event_anchor), \
583
+ (event).data.mapping_start.tag = (event_tag), \
584
+ (event).data.mapping_start.implicit = (event_implicit), \
585
+ (event).data.mapping_start.style = (event_style))
586
+
587
+ #define MAPPING_END_EVENT_INIT(event,start_mark,end_mark) \
588
+ (EVENT_INIT((event),YAML_MAPPING_END_EVENT,(start_mark),(end_mark)))
589
+
590
+ /*
591
+ * Document initializer.
592
+ */
593
+
594
+ #define DOCUMENT_INIT(document,document_nodes_start,document_nodes_end, \
595
+ document_version_directive,document_tag_directives_start, \
596
+ document_tag_directives_end,document_start_implicit, \
597
+ document_end_implicit,document_start_mark,document_end_mark) \
598
+ (memset(&(document), 0, sizeof(yaml_document_t)), \
599
+ (document).nodes.start = (document_nodes_start), \
600
+ (document).nodes.end = (document_nodes_end), \
601
+ (document).nodes.top = (document_nodes_start), \
602
+ (document).version_directive = (document_version_directive), \
603
+ (document).tag_directives.start = (document_tag_directives_start), \
604
+ (document).tag_directives.end = (document_tag_directives_end), \
605
+ (document).start_implicit = (document_start_implicit), \
606
+ (document).end_implicit = (document_end_implicit), \
607
+ (document).start_mark = (document_start_mark), \
608
+ (document).end_mark = (document_end_mark))
609
+
610
+ /*
611
+ * Node initializers.
612
+ */
613
+
614
+ #define NODE_INIT(node,node_type,node_tag,node_start_mark,node_end_mark) \
615
+ (memset(&(node), 0, sizeof(yaml_node_t)), \
616
+ (node).type = (node_type), \
617
+ (node).tag = (node_tag), \
618
+ (node).start_mark = (node_start_mark), \
619
+ (node).end_mark = (node_end_mark))
620
+
621
+ #define SCALAR_NODE_INIT(node,node_tag,node_value,node_length, \
622
+ node_style,start_mark,end_mark) \
623
+ (NODE_INIT((node),YAML_SCALAR_NODE,(node_tag),(start_mark),(end_mark)), \
624
+ (node).data.scalar.value = (node_value), \
625
+ (node).data.scalar.length = (node_length), \
626
+ (node).data.scalar.style = (node_style))
627
+
628
+ #define SEQUENCE_NODE_INIT(node,node_tag,node_items_start,node_items_end, \
629
+ node_style,start_mark,end_mark) \
630
+ (NODE_INIT((node),YAML_SEQUENCE_NODE,(node_tag),(start_mark),(end_mark)), \
631
+ (node).data.sequence.items.start = (node_items_start), \
632
+ (node).data.sequence.items.end = (node_items_end), \
633
+ (node).data.sequence.items.top = (node_items_start), \
634
+ (node).data.sequence.style = (node_style))
635
+
636
+ #define MAPPING_NODE_INIT(node,node_tag,node_pairs_start,node_pairs_end, \
637
+ node_style,start_mark,end_mark) \
638
+ (NODE_INIT((node),YAML_MAPPING_NODE,(node_tag),(start_mark),(end_mark)), \
639
+ (node).data.mapping.pairs.start = (node_pairs_start), \
640
+ (node).data.mapping.pairs.end = (node_pairs_end), \
641
+ (node).data.mapping.pairs.top = (node_pairs_start), \
642
+ (node).data.mapping.style = (node_style))
643
+