nutcracker 0.4.0.16 → 0.4.1.18

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