yajl-ruby 1.1.0 → 1.2.0
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.
Potentially problematic release.
This version of yajl-ruby might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/.gitignore +2 -1
- data/.travis.yml +9 -1
- data/Gemfile +2 -2
- data/README.md +4 -5
- data/ext/yajl/api/yajl_common.h +2 -2
- data/ext/yajl/api/yajl_parse.h +1 -1
- data/ext/yajl/yajl_alloc.h +1 -0
- data/ext/yajl/yajl_buf.h +7 -0
- data/ext/yajl/yajl_encode.h +3 -0
- data/ext/yajl/yajl_ext.c +49 -16
- data/ext/yajl/yajl_ext.h +9 -9
- data/ext/yajl/yajl_lex.h +11 -0
- data/ext/yajl/yajl_parser.h +2 -0
- data/lib/yajl.rb +2 -1
- data/lib/yajl/json_gem/encoding.rb +9 -10
- data/lib/yajl/version.rb +1 -1
- data/script/bootstrap +5 -0
- data/spec/encoding/encoding_spec.rb +42 -1
- data/spec/json_gem_compatibility/compatibility_spec.rb +4 -0
- metadata +69 -95
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 123d047ce44bacef2d09aab8b2f51bf4a0d456d6
|
4
|
+
data.tar.gz: 2d8622c124a07ea78ca3678a8042baed033407ef
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3d68e9873ee4ea9173adc6d46a20c9157b64d4b613e3ea9d5bcff6becc32bc130a26637565b1a6aa3a5c98ddad824e09edae2f83995974da754ba9dfd8e0e444
|
7
|
+
data.tar.gz: a47eb3ca4f465e3cc931e492cb18083ce00e2f7b81d307c1232409dff5509f2138d904877e1397ef3ffd7f3f22f779f1857c0092701716bc650f983ad4e1c61b
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
source
|
1
|
+
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
gemspec
|
3
|
+
gemspec
|
data/README.md
CHANGED
@@ -68,13 +68,13 @@ only had access to chunks of it at a time. No problem!
|
|
68
68
|
|
69
69
|
``` ruby
|
70
70
|
def post_init
|
71
|
-
|
71
|
+
@parser = Yajl::Parser.new(:symbolize_keys => true)
|
72
72
|
end
|
73
73
|
|
74
74
|
def object_parsed(obj)
|
75
|
-
|
76
|
-
|
77
|
-
|
75
|
+
puts "Sometimes one pays most for the things one gets for nothing. - Albert Einstein"
|
76
|
+
puts obj.inspect
|
77
|
+
end
|
78
78
|
|
79
79
|
def connection_completed
|
80
80
|
# once a full JSON object has been parsed from the stream
|
@@ -157,7 +157,6 @@ This allows you to encode JSON as a stream, writing directly to a socket
|
|
157
157
|
``` ruby
|
158
158
|
socket = TCPSocket.new('192.168.1.101', 9000)
|
159
159
|
hash = {:foo => 12425125, :bar => "some string", ... }
|
160
|
-
encoder = Yajl::Encoder.new
|
161
160
|
Yajl::Encoder.encode(hash, socket)
|
162
161
|
```
|
163
162
|
|
data/ext/yajl/api/yajl_common.h
CHANGED
@@ -37,7 +37,7 @@
|
|
37
37
|
extern "C" {
|
38
38
|
#endif
|
39
39
|
|
40
|
-
#define YAJL_MAX_DEPTH
|
40
|
+
#define YAJL_MAX_DEPTH 256
|
41
41
|
|
42
42
|
/* msft dll export gunk. To build a DLL on windows, you
|
43
43
|
* must define WIN32, YAJL_SHARED, and YAJL_BUILD. To use a shared
|
@@ -50,7 +50,7 @@ extern "C" {
|
|
50
50
|
# endif
|
51
51
|
#else
|
52
52
|
# if defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__) >= 303
|
53
|
-
# define YAJL_API __attribute__ ((visibility("
|
53
|
+
# define YAJL_API __attribute__ ((visibility("hidden")))
|
54
54
|
# else
|
55
55
|
# define YAJL_API
|
56
56
|
# endif
|
data/ext/yajl/api/yajl_parse.h
CHANGED
@@ -133,7 +133,7 @@ extern "C" {
|
|
133
133
|
void * ctx);
|
134
134
|
|
135
135
|
/** allow resetting of the lexer without the need to realloc a new parser */
|
136
|
-
void yajl_reset_parser(yajl_handle hand);
|
136
|
+
YAJL_API void yajl_reset_parser(yajl_handle hand);
|
137
137
|
|
138
138
|
/** free a parser handle */
|
139
139
|
YAJL_API void yajl_free(yajl_handle handle);
|
data/ext/yajl/yajl_alloc.h
CHANGED
data/ext/yajl/yajl_buf.h
CHANGED
@@ -50,24 +50,31 @@
|
|
50
50
|
typedef struct yajl_buf_t * yajl_buf;
|
51
51
|
|
52
52
|
/* allocate a new buffer */
|
53
|
+
YAJL_API
|
53
54
|
yajl_buf yajl_buf_alloc(yajl_alloc_funcs * alloc);
|
54
55
|
|
55
56
|
/* free the buffer */
|
57
|
+
YAJL_API
|
56
58
|
void yajl_buf_free(yajl_buf buf);
|
57
59
|
|
58
60
|
/* append a number of bytes to the buffer */
|
61
|
+
YAJL_API
|
59
62
|
void yajl_buf_append(yajl_buf buf, const void * data, unsigned int len);
|
60
63
|
|
61
64
|
/* empty the buffer */
|
65
|
+
YAJL_API
|
62
66
|
void yajl_buf_clear(yajl_buf buf);
|
63
67
|
|
64
68
|
/* get a pointer to the beginning of the buffer */
|
69
|
+
YAJL_API
|
65
70
|
const unsigned char * yajl_buf_data(yajl_buf buf);
|
66
71
|
|
67
72
|
/* get the length of the buffer */
|
73
|
+
YAJL_API
|
68
74
|
unsigned int yajl_buf_len(yajl_buf buf);
|
69
75
|
|
70
76
|
/* truncate the buffer */
|
77
|
+
YAJL_API
|
71
78
|
void yajl_buf_truncate(yajl_buf buf, unsigned int len);
|
72
79
|
|
73
80
|
#endif
|
data/ext/yajl/yajl_encode.h
CHANGED
@@ -36,16 +36,19 @@
|
|
36
36
|
#include "yajl_buf.h"
|
37
37
|
#include "api/yajl_gen.h"
|
38
38
|
|
39
|
+
YAJL_API
|
39
40
|
void yajl_string_encode2(const yajl_print_t printer,
|
40
41
|
void * ctx,
|
41
42
|
const unsigned char * str,
|
42
43
|
unsigned int length,
|
43
44
|
unsigned int htmlSafe);
|
44
45
|
|
46
|
+
YAJL_API
|
45
47
|
void yajl_string_encode(yajl_buf buf, const unsigned char * str,
|
46
48
|
unsigned int length,
|
47
49
|
unsigned int htmlSafe);
|
48
50
|
|
51
|
+
YAJL_API
|
49
52
|
void yajl_string_decode(yajl_buf buf, const unsigned char * str,
|
50
53
|
unsigned int length);
|
51
54
|
|
data/ext/yajl/yajl_ext.c
CHANGED
@@ -54,6 +54,25 @@ static void yajl_check_and_fire_callback(void * ctx) {
|
|
54
54
|
}
|
55
55
|
}
|
56
56
|
|
57
|
+
static char *yajl_raise_encode_error_for_status(yajl_gen_status status, VALUE obj) {
|
58
|
+
switch (status) {
|
59
|
+
case yajl_gen_keys_must_be_strings:
|
60
|
+
rb_raise(cEncodeError, "YAJL internal error: attempted use of non-string object as key");
|
61
|
+
case yajl_max_depth_exceeded:
|
62
|
+
rb_raise(cEncodeError, "Max nesting depth of %d exceeded", YAJL_MAX_DEPTH);
|
63
|
+
case yajl_gen_in_error_state:
|
64
|
+
rb_raise(cEncodeError, "YAJL internal error: a generator function (yajl_gen_XXX) was called while in an error state");
|
65
|
+
case yajl_gen_generation_complete:
|
66
|
+
rb_raise(cEncodeError, "YAJL internal error: attempted to encode to an already-complete document");
|
67
|
+
case yajl_gen_invalid_number:
|
68
|
+
rb_raise(cEncodeError, "Invalid number: cannot encode Infinity, -Infinity, or NaN");
|
69
|
+
case yajl_gen_no_buf:
|
70
|
+
rb_raise(cEncodeError, "YAJL internal error: yajl_gen_get_buf was called, but a print callback was specified, so no internal buffer is available");
|
71
|
+
default:
|
72
|
+
return NULL;
|
73
|
+
}
|
74
|
+
}
|
75
|
+
|
57
76
|
static void yajl_set_static_value(void * ctx, VALUE val) {
|
58
77
|
yajl_parser_wrapper * wrapper;
|
59
78
|
VALUE lastEntry, hash;
|
@@ -96,10 +115,10 @@ static void yajl_encoder_wrapper_free(void * wrapper) {
|
|
96
115
|
yajl_encoder_wrapper * w = wrapper;
|
97
116
|
if (w) {
|
98
117
|
if (w->indentString) {
|
99
|
-
|
118
|
+
xfree(w->indentString);
|
100
119
|
}
|
101
120
|
yajl_gen_free(w->encoder);
|
102
|
-
|
121
|
+
xfree(w);
|
103
122
|
}
|
104
123
|
}
|
105
124
|
|
@@ -111,6 +130,9 @@ static void yajl_encoder_wrapper_mark(void * wrapper) {
|
|
111
130
|
}
|
112
131
|
}
|
113
132
|
|
133
|
+
#define CHECK_STATUS(call) \
|
134
|
+
if ((status = (call)) != yajl_gen_status_ok) { break; }
|
135
|
+
|
114
136
|
void yajl_encode_part(void * wrapper, VALUE obj, VALUE io) {
|
115
137
|
VALUE str, outBuff, otherObj;
|
116
138
|
yajl_encoder_wrapper * w = wrapper;
|
@@ -123,6 +145,9 @@ void yajl_encode_part(void * wrapper, VALUE obj, VALUE io) {
|
|
123
145
|
|
124
146
|
if (io != Qnil || w->on_progress_callback != Qnil) {
|
125
147
|
status = yajl_gen_get_buf(w->encoder, &buffer, &len);
|
148
|
+
if (status != yajl_gen_status_ok) {
|
149
|
+
yajl_raise_encode_error_for_status(status, obj);
|
150
|
+
}
|
126
151
|
if (len >= WRITE_BUFSIZE) {
|
127
152
|
outBuff = rb_str_new((const char *)buffer, len);
|
128
153
|
if (io != Qnil) {
|
@@ -136,7 +161,7 @@ void yajl_encode_part(void * wrapper, VALUE obj, VALUE io) {
|
|
136
161
|
|
137
162
|
switch (TYPE(obj)) {
|
138
163
|
case T_HASH:
|
139
|
-
|
164
|
+
CHECK_STATUS(yajl_gen_map_open(w->encoder));
|
140
165
|
|
141
166
|
/* TODO: itterate through keys in the hash */
|
142
167
|
keys = rb_funcall(obj, intern_keys, 0);
|
@@ -149,24 +174,24 @@ void yajl_encode_part(void * wrapper, VALUE obj, VALUE io) {
|
|
149
174
|
yajl_encode_part(w, rb_hash_aref(obj, entry), io);
|
150
175
|
}
|
151
176
|
|
152
|
-
|
177
|
+
CHECK_STATUS(yajl_gen_map_close(w->encoder));
|
153
178
|
break;
|
154
179
|
case T_ARRAY:
|
155
|
-
|
180
|
+
CHECK_STATUS(yajl_gen_array_open(w->encoder));
|
156
181
|
for(idx=0; idx<RARRAY_LEN(obj); idx++) {
|
157
182
|
otherObj = rb_ary_entry(obj, idx);
|
158
183
|
yajl_encode_part(w, otherObj, io);
|
159
184
|
}
|
160
|
-
|
185
|
+
CHECK_STATUS(yajl_gen_array_close(w->encoder));
|
161
186
|
break;
|
162
187
|
case T_NIL:
|
163
|
-
|
188
|
+
CHECK_STATUS(yajl_gen_null(w->encoder));
|
164
189
|
break;
|
165
190
|
case T_TRUE:
|
166
|
-
|
191
|
+
CHECK_STATUS(yajl_gen_bool(w->encoder, 1));
|
167
192
|
break;
|
168
193
|
case T_FALSE:
|
169
|
-
|
194
|
+
CHECK_STATUS(yajl_gen_bool(w->encoder, 0));
|
170
195
|
break;
|
171
196
|
case T_FIXNUM:
|
172
197
|
case T_FLOAT:
|
@@ -177,12 +202,12 @@ void yajl_encode_part(void * wrapper, VALUE obj, VALUE io) {
|
|
177
202
|
if (memcmp(cptr, "NaN", 3) == 0 || memcmp(cptr, "Infinity", 8) == 0 || memcmp(cptr, "-Infinity", 9) == 0) {
|
178
203
|
rb_raise(cEncodeError, "'%s' is an invalid number", cptr);
|
179
204
|
}
|
180
|
-
|
205
|
+
CHECK_STATUS(yajl_gen_number(w->encoder, cptr, len));
|
181
206
|
break;
|
182
207
|
case T_STRING:
|
183
208
|
cptr = RSTRING_PTR(obj);
|
184
209
|
len = RSTRING_LEN(obj);
|
185
|
-
|
210
|
+
CHECK_STATUS(yajl_gen_string(w->encoder, (const unsigned char *)cptr, len));
|
186
211
|
break;
|
187
212
|
default:
|
188
213
|
if (rb_respond_to(obj, intern_to_json)) {
|
@@ -190,23 +215,28 @@ void yajl_encode_part(void * wrapper, VALUE obj, VALUE io) {
|
|
190
215
|
Check_Type(str, T_STRING);
|
191
216
|
cptr = RSTRING_PTR(str);
|
192
217
|
len = RSTRING_LEN(str);
|
193
|
-
|
218
|
+
CHECK_STATUS(yajl_gen_number(w->encoder, cptr, len));
|
194
219
|
} else {
|
195
220
|
str = rb_funcall(obj, intern_to_s, 0);
|
196
221
|
Check_Type(str, T_STRING);
|
197
222
|
cptr = RSTRING_PTR(str);
|
198
223
|
len = RSTRING_LEN(str);
|
199
|
-
|
224
|
+
CHECK_STATUS(yajl_gen_string(w->encoder, (const unsigned char *)cptr, len));
|
200
225
|
}
|
201
226
|
break;
|
202
227
|
}
|
228
|
+
|
229
|
+
if (status != yajl_gen_status_ok) {
|
230
|
+
yajl_raise_encode_error_for_status(status, obj);
|
231
|
+
rb_raise(cEncodeError, "Encountered unknown YAJL status %d during JSON generation", status);
|
232
|
+
}
|
203
233
|
}
|
204
234
|
|
205
235
|
void yajl_parser_wrapper_free(void * wrapper) {
|
206
236
|
yajl_parser_wrapper * w = wrapper;
|
207
237
|
if (w) {
|
208
238
|
yajl_free(w->parser);
|
209
|
-
|
239
|
+
xfree(w);
|
210
240
|
}
|
211
241
|
}
|
212
242
|
|
@@ -384,7 +414,7 @@ static VALUE rb_yajl_parser_new(int argc, VALUE * argv, VALUE klass) {
|
|
384
414
|
if (rb_hash_aref(opts, sym_check_utf8) == Qfalse) {
|
385
415
|
checkUTF8 = 0;
|
386
416
|
}
|
387
|
-
if (rb_hash_aref(opts, sym_symbolize_keys) == Qtrue) {
|
417
|
+
if (rb_hash_aref(opts, sym_symbolize_keys) == Qtrue || rb_hash_aref(opts, sym_symbolize_names) == Qtrue) {
|
388
418
|
symbolizeKeys = 1;
|
389
419
|
}
|
390
420
|
}
|
@@ -574,7 +604,7 @@ static VALUE rb_yajl_encoder_new(int argc, VALUE * argv, VALUE klass) {
|
|
574
604
|
indent = rb_str_export_to_enc(indent, utf8Encoding);
|
575
605
|
#endif
|
576
606
|
Check_Type(indent, T_STRING);
|
577
|
-
indentString = (unsigned char*)
|
607
|
+
indentString = (unsigned char*)xmalloc(RSTRING_LEN(indent)+1);
|
578
608
|
memcpy(indentString, RSTRING_PTR(indent), RSTRING_LEN(indent));
|
579
609
|
indentString[RSTRING_LEN(indent)] = '\0';
|
580
610
|
actualIndent = indentString;
|
@@ -863,6 +893,8 @@ static VALUE rb_yajl_encoder_enable_json_gem_ext(VALUE klass) {
|
|
863
893
|
void Init_yajl() {
|
864
894
|
mYajl = rb_define_module("Yajl");
|
865
895
|
|
896
|
+
rb_define_const(mYajl, "MAX_DEPTH", INT2NUM(YAJL_MAX_DEPTH));
|
897
|
+
|
866
898
|
cParseError = rb_define_class_under(mYajl, "ParseError", rb_eStandardError);
|
867
899
|
cEncodeError = rb_define_class_under(mYajl, "EncodeError", rb_eStandardError);
|
868
900
|
|
@@ -898,6 +930,7 @@ void Init_yajl() {
|
|
898
930
|
sym_html_safe = ID2SYM(rb_intern("html_safe"));
|
899
931
|
sym_terminator = ID2SYM(rb_intern("terminator"));
|
900
932
|
sym_symbolize_keys = ID2SYM(rb_intern("symbolize_keys"));
|
933
|
+
sym_symbolize_names = ID2SYM(rb_intern("symbolize_names"));
|
901
934
|
|
902
935
|
#ifdef HAVE_RUBY_ENCODING_H
|
903
936
|
utf8Encoding = rb_utf8_encoding();
|
data/ext/yajl/yajl_ext.h
CHANGED
@@ -24,9 +24,9 @@
|
|
24
24
|
#include "api/yajl_parse.h"
|
25
25
|
#include "api/yajl_gen.h"
|
26
26
|
|
27
|
-
|
28
|
-
|
29
|
-
|
27
|
+
/* tell rbx not to use it's caching compat layer
|
28
|
+
by doing this we're making a promize to RBX that
|
29
|
+
we'll never modify the pointers we get back from RSTRING_PTR */
|
30
30
|
#define RSTRING_NOT_MODIFIED
|
31
31
|
|
32
32
|
#include <ruby.h>
|
@@ -56,15 +56,15 @@ static rb_encoding *utf8Encoding;
|
|
56
56
|
static VALUE cParseError, cEncodeError, mYajl, cParser, cEncoder;
|
57
57
|
static ID intern_io_read, intern_call, intern_keys, intern_to_s,
|
58
58
|
intern_to_json, intern_has_key, intern_to_sym, intern_as_json;
|
59
|
-
static ID sym_allow_comments, sym_check_utf8, sym_pretty, sym_indent, sym_terminator, sym_symbolize_keys, sym_html_safe;
|
59
|
+
static ID sym_allow_comments, sym_check_utf8, sym_pretty, sym_indent, sym_terminator, sym_symbolize_keys, sym_symbolize_names, sym_html_safe;
|
60
60
|
|
61
|
-
#define GetParser(obj, sval) (
|
62
|
-
#define GetEncoder(obj, sval) (
|
61
|
+
#define GetParser(obj, sval) Data_Get_Struct(obj, yajl_parser_wrapper, sval);
|
62
|
+
#define GetEncoder(obj, sval) Data_Get_Struct(obj, yajl_encoder_wrapper, sval);
|
63
63
|
|
64
64
|
static void yajl_check_and_fire_callback(void * ctx);
|
65
65
|
static void yajl_set_static_value(void * ctx, VALUE val);
|
66
|
-
void yajl_encode_part(void * wrapper, VALUE obj, VALUE io);
|
67
|
-
void yajl_parse_chunk(const unsigned char * chunk, unsigned int len, yajl_handle parser);
|
66
|
+
static void yajl_encode_part(void * wrapper, VALUE obj, VALUE io);
|
67
|
+
static void yajl_parse_chunk(const unsigned char * chunk, unsigned int len, yajl_handle parser);
|
68
68
|
|
69
69
|
static int yajl_found_null(void * ctx);
|
70
70
|
static int yajl_found_boolean(void * ctx, int boolean);
|
@@ -132,4 +132,4 @@ static VALUE rb_yajl_json_ext_false_to_json(int argc, VALUE * argv, VALUE self);
|
|
132
132
|
static VALUE rb_yajl_json_ext_nil_to_json(int argc, VALUE * argv, VALUE self);
|
133
133
|
static VALUE rb_yajl_encoder_enable_json_gem_ext(VALUE klass);
|
134
134
|
|
135
|
-
void Init_yajl();
|
135
|
+
void Init_yajl();
|
data/ext/yajl/yajl_lex.h
CHANGED
@@ -63,12 +63,16 @@ typedef enum {
|
|
63
63
|
|
64
64
|
typedef struct yajl_lexer_t * yajl_lexer;
|
65
65
|
|
66
|
+
|
67
|
+
YAJL_API
|
66
68
|
yajl_lexer yajl_lex_alloc(yajl_alloc_funcs * alloc,
|
67
69
|
unsigned int allowComments,
|
68
70
|
unsigned int validateUTF8);
|
69
71
|
|
72
|
+
YAJL_API
|
70
73
|
yajl_lexer yajl_lex_realloc(yajl_lexer orig);
|
71
74
|
|
75
|
+
YAJL_API
|
72
76
|
void yajl_lex_free(yajl_lexer lexer);
|
73
77
|
|
74
78
|
/**
|
@@ -93,11 +97,13 @@ n * error messages.
|
|
93
97
|
* implications which require that the client choose a reasonable chunk
|
94
98
|
* size to get adequate performance.
|
95
99
|
*/
|
100
|
+
YAJL_API
|
96
101
|
yajl_tok yajl_lex_lex(yajl_lexer lexer, const unsigned char * jsonText,
|
97
102
|
unsigned int jsonTextLen, unsigned int * offset,
|
98
103
|
const unsigned char ** outBuf, unsigned int * outLen);
|
99
104
|
|
100
105
|
/** have a peek at the next token, but don't move the lexer forward */
|
106
|
+
YAJL_API
|
101
107
|
yajl_tok yajl_lex_peek(yajl_lexer lexer, const unsigned char * jsonText,
|
102
108
|
unsigned int jsonTextLen, unsigned int offset);
|
103
109
|
|
@@ -116,20 +122,25 @@ typedef enum {
|
|
116
122
|
yajl_lex_unallowed_comment
|
117
123
|
} yajl_lex_error;
|
118
124
|
|
125
|
+
YAJL_API
|
119
126
|
const char * yajl_lex_error_to_string(yajl_lex_error error);
|
120
127
|
|
121
128
|
/** allows access to more specific information about the lexical
|
122
129
|
* error when yajl_lex_lex returns yajl_tok_error. */
|
130
|
+
YAJL_API
|
123
131
|
yajl_lex_error yajl_lex_get_error(yajl_lexer lexer);
|
124
132
|
|
125
133
|
/** get the current offset into the most recently lexed json string. */
|
134
|
+
YAJL_API
|
126
135
|
unsigned int yajl_lex_current_offset(yajl_lexer lexer);
|
127
136
|
|
128
137
|
/** get the number of lines lexed by this lexer instance */
|
138
|
+
YAJL_API
|
129
139
|
unsigned int yajl_lex_current_line(yajl_lexer lexer);
|
130
140
|
|
131
141
|
/** get the number of chars lexed by this lexer instance since the last
|
132
142
|
* \n or \r */
|
143
|
+
YAJL_API
|
133
144
|
unsigned int yajl_lex_current_char(yajl_lexer lexer);
|
134
145
|
|
135
146
|
#endif
|
data/ext/yajl/yajl_parser.h
CHANGED
@@ -70,10 +70,12 @@ struct yajl_handle_t {
|
|
70
70
|
yajl_alloc_funcs alloc;
|
71
71
|
};
|
72
72
|
|
73
|
+
YAJL_API
|
73
74
|
yajl_status
|
74
75
|
yajl_do_parse(yajl_handle handle, const unsigned char * jsonText,
|
75
76
|
unsigned int jsonTextLen);
|
76
77
|
|
78
|
+
YAJL_API
|
77
79
|
unsigned char *
|
78
80
|
yajl_render_error_string(yajl_handle hand, const unsigned char * jsonText,
|
79
81
|
unsigned int jsonTextLen, int verbose);
|
data/lib/yajl.rb
CHANGED
@@ -12,6 +12,7 @@ require 'yajl/yajl'
|
|
12
12
|
#
|
13
13
|
# Ruby bindings to the excellent Yajl (Yet Another JSON Parser) ANSI C library.
|
14
14
|
module Yajl
|
15
|
+
|
15
16
|
# For compatibility, has the same signature of Yajl::Parser.parse
|
16
17
|
def self.load(str_or_io, options={}, read_bufsize=nil, &block)
|
17
18
|
Parser.parse(str_or_io, options, read_bufsize, &block)
|
@@ -65,7 +66,7 @@ module Yajl
|
|
65
66
|
args.each do |arg|
|
66
67
|
if arg.is_a?(Hash)
|
67
68
|
options = arg
|
68
|
-
elsif arg.respond_to?(:
|
69
|
+
elsif arg.respond_to?(:write)
|
69
70
|
io = arg
|
70
71
|
end
|
71
72
|
end if args.any?
|
@@ -17,17 +17,16 @@ module JSON
|
|
17
17
|
class JSONError < StandardError; end unless defined?(JSON::JSONError)
|
18
18
|
class GeneratorError < JSONError; end unless defined?(JSON::GeneratorError)
|
19
19
|
|
20
|
-
def self.generate(obj, opts=
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
end
|
27
|
-
Yajl::Encoder.encode(obj, options_map)
|
28
|
-
rescue Yajl::EncodeError => e
|
29
|
-
raise JSON::GeneratorError, e.message
|
20
|
+
def self.generate(obj, opts=nil)
|
21
|
+
opts ||= {}
|
22
|
+
options_map = {}
|
23
|
+
if opts.has_key?(:indent)
|
24
|
+
options_map[:pretty] = true
|
25
|
+
options_map[:indent] = opts[:indent]
|
30
26
|
end
|
27
|
+
Yajl::Encoder.encode(obj, options_map)
|
28
|
+
rescue Yajl::EncodeError => e
|
29
|
+
raise JSON::GeneratorError, e.message
|
31
30
|
end
|
32
31
|
|
33
32
|
def self.pretty_generate(obj, opts={})
|
data/lib/yajl/version.rb
CHANGED
data/script/bootstrap
ADDED
@@ -1,5 +1,7 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb')
|
3
|
+
require 'tmpdir'
|
4
|
+
require 'zlib'
|
3
5
|
|
4
6
|
class Dummy2
|
5
7
|
def to_json
|
@@ -23,7 +25,7 @@ describe "Yajl JSON encoder" do
|
|
23
25
|
FILES = Dir[File.dirname(__FILE__)+'/../../benchmark/subjects/*.json']
|
24
26
|
|
25
27
|
FILES.each do |file|
|
26
|
-
it "should encode #{File.basename(file)} to an
|
28
|
+
it "should encode #{File.basename(file)} to an StringIO" do
|
27
29
|
# we don't care about testing the stream subject as it has multiple JSON strings in it
|
28
30
|
if File.basename(file) != 'twitter_stream.json'
|
29
31
|
input = File.new(File.expand_path(file), 'r')
|
@@ -40,6 +42,27 @@ describe "Yajl JSON encoder" do
|
|
40
42
|
end
|
41
43
|
end
|
42
44
|
|
45
|
+
FILES.each do |file|
|
46
|
+
it "should encode #{File.basename(file)} to a Zlib::GzipWriter" do
|
47
|
+
# we don't care about testing the stream subject as it has multiple JSON strings in it
|
48
|
+
if File.basename(file) != 'twitter_stream.json'
|
49
|
+
hash = File.open(File.expand_path(file), 'r') do |input|
|
50
|
+
Yajl::Parser.parse(input)
|
51
|
+
end
|
52
|
+
hash2 = Dir.mktmpdir do |tmp_dir|
|
53
|
+
output_filename = File.join(tmp_dir, 'output.json')
|
54
|
+
Zlib::GzipWriter.open(output_filename) do |writer|
|
55
|
+
Yajl::Encoder.encode(hash, writer)
|
56
|
+
end
|
57
|
+
Zlib::GzipReader.open(output_filename) do |reader|
|
58
|
+
Yajl::Parser.parse(reader.read)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
hash.should == hash2
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
43
66
|
FILES.each do |file|
|
44
67
|
it "should encode #{File.basename(file)} and return a String" do
|
45
68
|
# we don't care about testing the stream subject as it has multiple JSON strings in it
|
@@ -271,4 +294,22 @@ describe "Yajl JSON encoder" do
|
|
271
294
|
Yajl::Encoder.encode(TheMindKillerDuce.new)
|
272
295
|
}.should raise_error(TypeError)
|
273
296
|
end
|
297
|
+
|
298
|
+
it "should raise an exception for deeply nested arrays" do
|
299
|
+
root = []
|
300
|
+
a = root
|
301
|
+
(Yajl::MAX_DEPTH + 1).times { |_| a << []; a = a[0] }
|
302
|
+
lambda {
|
303
|
+
Yajl::Encoder.encode(root)
|
304
|
+
}.should raise_error(Yajl::EncodeError)
|
305
|
+
end
|
306
|
+
|
307
|
+
it "should raise an exception for deeply nested hashes" do
|
308
|
+
root = {}
|
309
|
+
a = root
|
310
|
+
(Yajl::MAX_DEPTH + 1).times { |_| a["a"] = {}; a = a["a"] }
|
311
|
+
lambda {
|
312
|
+
Yajl::Encoder.encode(root)
|
313
|
+
}.should raise_error(Yajl::EncodeError)
|
314
|
+
end
|
274
315
|
end
|
@@ -51,6 +51,10 @@ describe "JSON Gem compatability API" do
|
|
51
51
|
JSON.default_options[:symbolize_keys] = default # ensure the rest of the test cases expect the default
|
52
52
|
end
|
53
53
|
|
54
|
+
it "should also allow the json gem's symbolize_names key" do
|
55
|
+
JSON.parse('{"foo": 1234}', :symbolize_names => true).should === {:foo => 1234}
|
56
|
+
end
|
57
|
+
|
54
58
|
it "should encode arbitrary classes via their default to_json method" do
|
55
59
|
d = Dummy.new
|
56
60
|
d.to_json.should == "\"#{d.to_s}\""
|
metadata
CHANGED
@@ -1,93 +1,79 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: yajl-ruby
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 1
|
8
|
-
- 1
|
9
|
-
- 0
|
10
|
-
version: 1.1.0
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.2.0
|
11
5
|
platform: ruby
|
12
|
-
authors:
|
6
|
+
authors:
|
13
7
|
- Brian Lopez
|
14
8
|
- Lloyd Hilaiel
|
15
9
|
autorequire:
|
16
10
|
bindir: bin
|
17
11
|
cert_chain: []
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
dependencies:
|
22
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2013-12-17 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
23
15
|
name: rake-compiler
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
- - ">="
|
29
|
-
- !ruby/object:Gem::Version
|
30
|
-
hash: 9
|
31
|
-
segments:
|
32
|
-
- 0
|
33
|
-
- 7
|
34
|
-
- 5
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - '>='
|
19
|
+
- !ruby/object:Gem::Version
|
35
20
|
version: 0.7.5
|
36
21
|
type: :development
|
37
|
-
version_requirements: *id001
|
38
|
-
- !ruby/object:Gem::Dependency
|
39
|
-
name: rspec
|
40
22
|
prerelease: false
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - '>='
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: 0.7.5
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rspec
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - '>='
|
33
|
+
- !ruby/object:Gem::Version
|
51
34
|
version: 2.0.0
|
52
35
|
type: :development
|
53
|
-
version_requirements: *id002
|
54
|
-
- !ruby/object:Gem::Dependency
|
55
|
-
name: activesupport
|
56
36
|
prerelease: false
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: 2.0.0
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: activesupport
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
66
49
|
type: :development
|
67
|
-
version_requirements: *id003
|
68
|
-
- !ruby/object:Gem::Dependency
|
69
|
-
name: json
|
70
50
|
prerelease: false
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: json
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
80
63
|
type: :development
|
81
|
-
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
82
70
|
description:
|
83
71
|
email: seniorlopez@gmail.com
|
84
72
|
executables: []
|
85
|
-
|
86
|
-
extensions:
|
73
|
+
extensions:
|
87
74
|
- ext/yajl/extconf.rb
|
88
75
|
extra_rdoc_files: []
|
89
|
-
|
90
|
-
files:
|
76
|
+
files:
|
91
77
|
- .gitignore
|
92
78
|
- .rspec
|
93
79
|
- .travis.yml
|
@@ -155,6 +141,7 @@ files:
|
|
155
141
|
- lib/yajl/json_gem/encoding.rb
|
156
142
|
- lib/yajl/json_gem/parsing.rb
|
157
143
|
- lib/yajl/version.rb
|
144
|
+
- script/bootstrap
|
158
145
|
- spec/encoding/encoding_spec.rb
|
159
146
|
- spec/global/global_spec.rb
|
160
147
|
- spec/http/fixtures/http.bzip2.dump
|
@@ -237,43 +224,30 @@ files:
|
|
237
224
|
- tasks/compile.rake
|
238
225
|
- tasks/rspec.rake
|
239
226
|
- yajl-ruby.gemspec
|
240
|
-
has_rdoc: true
|
241
227
|
homepage: http://github.com/brianmario/yajl-ruby
|
242
228
|
licenses: []
|
243
|
-
|
229
|
+
metadata: {}
|
244
230
|
post_install_message:
|
245
231
|
rdoc_options: []
|
246
|
-
|
247
|
-
require_paths:
|
232
|
+
require_paths:
|
248
233
|
- lib
|
249
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
- !ruby/object:Gem::Version
|
254
|
-
hash: 59
|
255
|
-
segments:
|
256
|
-
- 1
|
257
|
-
- 8
|
258
|
-
- 6
|
234
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
235
|
+
requirements:
|
236
|
+
- - '>='
|
237
|
+
- !ruby/object:Gem::Version
|
259
238
|
version: 1.8.6
|
260
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
hash: 3
|
266
|
-
segments:
|
267
|
-
- 0
|
268
|
-
version: "0"
|
239
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
240
|
+
requirements:
|
241
|
+
- - '>='
|
242
|
+
- !ruby/object:Gem::Version
|
243
|
+
version: '0'
|
269
244
|
requirements: []
|
270
|
-
|
271
245
|
rubyforge_project:
|
272
|
-
rubygems_version:
|
246
|
+
rubygems_version: 2.0.3
|
273
247
|
signing_key:
|
274
|
-
specification_version:
|
248
|
+
specification_version: 4
|
275
249
|
summary: Ruby C bindings to the excellent Yajl JSON stream-based parser library.
|
276
|
-
test_files:
|
250
|
+
test_files:
|
277
251
|
- examples/encoding/chunked_encoding.rb
|
278
252
|
- examples/encoding/one_shot.rb
|
279
253
|
- examples/encoding/to_an_io.rb
|