iodine 0.7.60 → 0.8.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.
- checksums.yaml +4 -4
- data/.clang-format +15 -0
- data/.rspec +1 -0
- data/.yardopts +1 -3
- data/CHANGELOG.md +132 -12
- data/Gemfile +5 -7
- data/LICENSE.txt +1 -1
- data/README.md +147 -671
- data/Rakefile +9 -16
- data/examples/chatroom.nru +9 -0
- data/examples/client +74 -0
- data/examples/config-hello.nru +9 -0
- data/examples/config-hello.ru +11 -0
- data/examples/config-hijack.ru +13 -0
- data/examples/config-shootout.ru +43 -0
- data/examples/config.nru +120 -0
- data/examples/config.rb +37 -0
- data/examples/config.ru +42 -53
- data/examples/fake +24 -0
- data/examples/hello_neorack +137 -0
- data/examples/routes.nru +29 -0
- data/examples/routes.ru +42 -0
- data/exe/iodine +218 -258
- data/ext/iodine/extconf.rb +27 -100
- data/ext/iodine/fio-stl.h +128336 -0
- data/ext/iodine/fio-stl.md +26396 -0
- data/ext/iodine/iodine.c +213 -1393
- data/ext/iodine/iodine.h +250 -55
- data/ext/iodine/iodine_arg_helper.h +329 -0
- data/ext/iodine/iodine_caller.h +234 -25
- data/ext/iodine/iodine_cli.h +434 -0
- data/ext/iodine/iodine_compression.h +312 -0
- data/ext/iodine/iodine_connection.h +3484 -34
- data/ext/iodine/iodine_core.h +363 -0
- data/ext/iodine/iodine_crypto.h +1441 -0
- data/ext/iodine/iodine_defer.h +225 -4
- data/ext/iodine/iodine_json.h +738 -4
- data/ext/iodine/iodine_listener.h +263 -0
- data/ext/iodine/iodine_log.h +297 -0
- data/ext/iodine/iodine_minimap.h +543 -0
- data/ext/iodine/iodine_mustache.h +461 -4
- data/ext/iodine/iodine_pubsub_eng.h +729 -0
- data/ext/iodine/iodine_pubsub_history.h +547 -0
- data/ext/iodine/iodine_pubsub_msg.h +228 -0
- data/ext/iodine/iodine_redis.h +322 -0
- data/ext/iodine/iodine_store.h +418 -16
- data/ext/iodine/iodine_threads.h +279 -0
- data/ext/iodine/iodine_tls.h +515 -6
- data/ext/iodine/iodine_utils.h +923 -0
- data/iodine.gemspec +37 -42
- data/lib/iodine/benchmark.rb +1690 -0
- data/lib/iodine/documentation.rb +3085 -0
- data/lib/iodine/version.rb +17 -1
- data/lib/iodine.rb +54 -255
- data/logo.svg +36 -0
- data/mustache.md +55 -0
- data/sig/iodine.rbs +4 -0
- metadata +58 -184
- data/.github/ISSUE_TEMPLATE/bug_report.md +0 -40
- data/.github/workflows/ruby.yml +0 -42
- data/.gitignore +0 -21
- data/LIMITS.md +0 -41
- data/SPEC-PubSub-Draft.md +0 -159
- data/SPEC-WebSocket-Draft.md +0 -239
- data/bin/console +0 -22
- data/bin/info.md +0 -353
- data/bin/mustache_bench.rb +0 -100
- data/bin/poc/Gemfile.lock +0 -23
- data/bin/poc/README.md +0 -37
- data/bin/poc/config.ru +0 -66
- data/bin/poc/gemfile +0 -1
- data/bin/poc/www/index.html +0 -57
- data/examples/async_task.ru +0 -92
- data/examples/bates/README.md +0 -3
- data/examples/bates/config.ru +0 -342
- data/examples/bates/david+bold.pdf +0 -0
- data/examples/bates/public/drop-pdf.png +0 -0
- data/examples/bates/public/index.html +0 -600
- data/examples/echo.ru +0 -59
- data/examples/etag.ru +0 -16
- data/examples/hello.ru +0 -29
- data/examples/pubsub_engine.ru +0 -81
- data/examples/rack3.ru +0 -12
- data/examples/redis.ru +0 -70
- data/examples/shootout.ru +0 -73
- data/examples/sub-protocols.ru +0 -90
- data/examples/tcp_client.rb +0 -66
- data/examples/x-sendfile.ru +0 -14
- data/ext/iodine/fio.c +0 -11995
- data/ext/iodine/fio.h +0 -6371
- data/ext/iodine/fio_cli.c +0 -431
- data/ext/iodine/fio_cli.h +0 -189
- data/ext/iodine/fio_json_parser.h +0 -688
- data/ext/iodine/fio_siphash.c +0 -157
- data/ext/iodine/fio_siphash.h +0 -37
- data/ext/iodine/fio_tls.h +0 -129
- data/ext/iodine/fio_tls_missing.c +0 -649
- data/ext/iodine/fio_tls_openssl.c +0 -1106
- data/ext/iodine/fio_tmpfile.h +0 -50
- data/ext/iodine/fiobj.h +0 -44
- data/ext/iodine/fiobj4fio.h +0 -21
- data/ext/iodine/fiobj_ary.c +0 -333
- data/ext/iodine/fiobj_ary.h +0 -139
- data/ext/iodine/fiobj_data.c +0 -1187
- data/ext/iodine/fiobj_data.h +0 -167
- data/ext/iodine/fiobj_hash.c +0 -409
- data/ext/iodine/fiobj_hash.h +0 -176
- data/ext/iodine/fiobj_json.c +0 -622
- data/ext/iodine/fiobj_json.h +0 -68
- data/ext/iodine/fiobj_mem.h +0 -71
- data/ext/iodine/fiobj_mustache.c +0 -317
- data/ext/iodine/fiobj_mustache.h +0 -62
- data/ext/iodine/fiobj_numbers.c +0 -344
- data/ext/iodine/fiobj_numbers.h +0 -127
- data/ext/iodine/fiobj_str.c +0 -433
- data/ext/iodine/fiobj_str.h +0 -172
- data/ext/iodine/fiobject.c +0 -620
- data/ext/iodine/fiobject.h +0 -655
- data/ext/iodine/hpack.h +0 -1923
- data/ext/iodine/http.c +0 -2743
- data/ext/iodine/http.h +0 -1002
- data/ext/iodine/http1.c +0 -910
- data/ext/iodine/http1.h +0 -29
- data/ext/iodine/http1_parser.h +0 -878
- data/ext/iodine/http_internal.c +0 -1279
- data/ext/iodine/http_internal.h +0 -237
- data/ext/iodine/http_mime_parser.h +0 -350
- data/ext/iodine/iodine_caller.c +0 -230
- data/ext/iodine/iodine_connection.c +0 -941
- data/ext/iodine/iodine_defer.c +0 -420
- data/ext/iodine/iodine_fiobj2rb.h +0 -120
- data/ext/iodine/iodine_helpers.c +0 -282
- data/ext/iodine/iodine_helpers.h +0 -12
- data/ext/iodine/iodine_http.c +0 -1181
- data/ext/iodine/iodine_http.h +0 -23
- data/ext/iodine/iodine_json.c +0 -302
- data/ext/iodine/iodine_mustache.c +0 -567
- data/ext/iodine/iodine_pubsub.c +0 -580
- data/ext/iodine/iodine_pubsub.h +0 -26
- data/ext/iodine/iodine_rack_io.c +0 -273
- data/ext/iodine/iodine_rack_io.h +0 -20
- data/ext/iodine/iodine_store.c +0 -148
- data/ext/iodine/iodine_tcp.c +0 -346
- data/ext/iodine/iodine_tcp.h +0 -13
- data/ext/iodine/iodine_tls.c +0 -261
- data/ext/iodine/mustache_parser.h +0 -1546
- data/ext/iodine/redis_engine.c +0 -957
- data/ext/iodine/redis_engine.h +0 -79
- data/ext/iodine/resp_parser.h +0 -317
- data/ext/iodine/websocket_parser.h +0 -506
- data/ext/iodine/websockets.c +0 -743
- data/ext/iodine/websockets.h +0 -185
- data/lib/iodine/connection.rb +0 -61
- data/lib/iodine/json.rb +0 -42
- data/lib/iodine/mustache.rb +0 -113
- data/lib/iodine/pubsub.rb +0 -55
- data/lib/iodine/rack_utils.rb +0 -43
- data/lib/iodine/tls.rb +0 -16
- data/lib/rack/handler/iodine.rb +0 -33
- data/logo.png +0 -0
data/ext/iodine/iodine_http.h
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
#ifndef H_IODINE_HTTP_H
|
|
2
|
-
#define H_IODINE_HTTP_H
|
|
3
|
-
/*
|
|
4
|
-
Copyright: Boaz segev, 2016-2018
|
|
5
|
-
License: MIT
|
|
6
|
-
|
|
7
|
-
Feel free to copy, use and enjoy according to the license provided.
|
|
8
|
-
*/
|
|
9
|
-
#include "iodine.h"
|
|
10
|
-
|
|
11
|
-
/* these three are used also by rb-rack-io.c */
|
|
12
|
-
extern VALUE IODINE_R_INPUT;
|
|
13
|
-
extern VALUE IODINE_R_INPUT_DEFAULT;
|
|
14
|
-
extern VALUE IODINE_R_HIJACK;
|
|
15
|
-
extern VALUE IODINE_R_HIJACK_IO;
|
|
16
|
-
extern VALUE IODINE_R_HIJACK_CB;
|
|
17
|
-
void iodine_init_http(void);
|
|
18
|
-
|
|
19
|
-
intptr_t iodine_http_listen(iodine_connection_args_s args);
|
|
20
|
-
// intptr_t iodine_http_connect(iodine_connection_args_s args); // not yet...
|
|
21
|
-
intptr_t iodine_ws_connect(iodine_connection_args_s args);
|
|
22
|
-
|
|
23
|
-
#endif
|
data/ext/iodine/iodine_json.c
DELETED
|
@@ -1,302 +0,0 @@
|
|
|
1
|
-
#include "iodine.h"
|
|
2
|
-
|
|
3
|
-
#include "fio.h"
|
|
4
|
-
|
|
5
|
-
#include "fio_json_parser.h"
|
|
6
|
-
#include "fiobj.h"
|
|
7
|
-
#include "iodine_fiobj2rb.h"
|
|
8
|
-
#include "iodine_store.h"
|
|
9
|
-
|
|
10
|
-
static VALUE max_nesting;
|
|
11
|
-
static VALUE allow_nan;
|
|
12
|
-
static VALUE symbolize_names;
|
|
13
|
-
static VALUE create_additions;
|
|
14
|
-
static VALUE object_class;
|
|
15
|
-
static VALUE array_class;
|
|
16
|
-
|
|
17
|
-
#define FIO_ARY_NAME fio_json_stack
|
|
18
|
-
#define FIO_ARY_TYPE VALUE
|
|
19
|
-
#include "fio.h"
|
|
20
|
-
|
|
21
|
-
/* *****************************************************************************
|
|
22
|
-
JSON Callacks - these must be implemented in the C file that uses the parser
|
|
23
|
-
***************************************************************************** */
|
|
24
|
-
|
|
25
|
-
/* *****************************************************************************
|
|
26
|
-
JSON Parser handling (practically copied from the FIOBJ library)
|
|
27
|
-
***************************************************************************** */
|
|
28
|
-
|
|
29
|
-
typedef struct {
|
|
30
|
-
json_parser_s p;
|
|
31
|
-
VALUE key;
|
|
32
|
-
VALUE top;
|
|
33
|
-
VALUE target;
|
|
34
|
-
fio_json_stack_s stack;
|
|
35
|
-
uint8_t is_hash;
|
|
36
|
-
uint8_t symbolize;
|
|
37
|
-
} iodine_json_parser_s;
|
|
38
|
-
|
|
39
|
-
static inline void iodine_json_add2parser(iodine_json_parser_s *p, VALUE o) {
|
|
40
|
-
if (p->top) {
|
|
41
|
-
if (p->is_hash) {
|
|
42
|
-
if (p->key) {
|
|
43
|
-
rb_hash_aset(p->top, p->key, o);
|
|
44
|
-
IodineStore.remove(p->key);
|
|
45
|
-
p->key = (VALUE)0;
|
|
46
|
-
} else {
|
|
47
|
-
p->key = o;
|
|
48
|
-
IodineStore.add(o);
|
|
49
|
-
}
|
|
50
|
-
} else {
|
|
51
|
-
rb_ary_push(p->top, o);
|
|
52
|
-
}
|
|
53
|
-
} else {
|
|
54
|
-
IodineStore.add(o);
|
|
55
|
-
p->top = o;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/** a NULL object was detected */
|
|
60
|
-
static void fio_json_on_null(json_parser_s *p) {
|
|
61
|
-
iodine_json_add2parser((iodine_json_parser_s *)p, Qnil);
|
|
62
|
-
}
|
|
63
|
-
/** a TRUE object was detected */
|
|
64
|
-
static void fio_json_on_true(json_parser_s *p) {
|
|
65
|
-
iodine_json_add2parser((iodine_json_parser_s *)p, Qtrue);
|
|
66
|
-
}
|
|
67
|
-
/** a FALSE object was detected */
|
|
68
|
-
static void fio_json_on_false(json_parser_s *p) {
|
|
69
|
-
iodine_json_add2parser((iodine_json_parser_s *)p, Qfalse);
|
|
70
|
-
}
|
|
71
|
-
/** a Numberl was detected (long long). */
|
|
72
|
-
static void fio_json_on_number(json_parser_s *p, long long i) {
|
|
73
|
-
iodine_json_add2parser((iodine_json_parser_s *)p, LONG2NUM(i));
|
|
74
|
-
}
|
|
75
|
-
/** a Float was detected (double). */
|
|
76
|
-
static void fio_json_on_float(json_parser_s *p, double f) {
|
|
77
|
-
iodine_json_add2parser((iodine_json_parser_s *)p, DBL2NUM(f));
|
|
78
|
-
}
|
|
79
|
-
/** a String was detected (int / float). update `pos` to point at ending */
|
|
80
|
-
static void fio_json_on_string(json_parser_s *p, void *start, size_t length) {
|
|
81
|
-
/* Ruby overhead for a rb_str_buf_new is very high. Double copy is faster. */
|
|
82
|
-
char *tmp = fio_malloc(length);
|
|
83
|
-
size_t new_len = fio_json_unescape_str(tmp, start, length);
|
|
84
|
-
VALUE buf;
|
|
85
|
-
if (((iodine_json_parser_s *)p)->symbolize &&
|
|
86
|
-
((iodine_json_parser_s *)p)->is_hash &&
|
|
87
|
-
!((iodine_json_parser_s *)p)->key) {
|
|
88
|
-
ID id = rb_intern2(tmp, new_len);
|
|
89
|
-
buf = rb_id2sym(id);
|
|
90
|
-
} else {
|
|
91
|
-
buf = rb_str_new(tmp, new_len);
|
|
92
|
-
}
|
|
93
|
-
iodine_json_add2parser((iodine_json_parser_s *)p, buf);
|
|
94
|
-
fio_free(tmp);
|
|
95
|
-
}
|
|
96
|
-
/** a dictionary object was detected, should return 0 unless error occurred. */
|
|
97
|
-
static int fio_json_on_start_object(json_parser_s *p) {
|
|
98
|
-
iodine_json_parser_s *pr = (iodine_json_parser_s *)p;
|
|
99
|
-
if (pr->target) {
|
|
100
|
-
/* push NULL, don't free the objects */
|
|
101
|
-
fio_json_stack_push(&pr->stack, pr->top);
|
|
102
|
-
pr->top = pr->target;
|
|
103
|
-
pr->target = 0;
|
|
104
|
-
} else {
|
|
105
|
-
VALUE h = rb_hash_new();
|
|
106
|
-
iodine_json_add2parser(pr, h);
|
|
107
|
-
fio_json_stack_push(&pr->stack, pr->top);
|
|
108
|
-
pr->top = h;
|
|
109
|
-
}
|
|
110
|
-
pr->is_hash = 1;
|
|
111
|
-
return 0;
|
|
112
|
-
}
|
|
113
|
-
/** a dictionary object closure detected */
|
|
114
|
-
static void fio_json_on_end_object(json_parser_s *p) {
|
|
115
|
-
iodine_json_parser_s *pr = (iodine_json_parser_s *)p;
|
|
116
|
-
if (pr->key) {
|
|
117
|
-
FIO_LOG_WARNING("(JSON parsing) malformed JSON, "
|
|
118
|
-
"ignoring dangling Hash key.");
|
|
119
|
-
IodineStore.remove(pr->key);
|
|
120
|
-
pr->key = (VALUE)0;
|
|
121
|
-
}
|
|
122
|
-
fio_json_stack_pop(&pr->stack, &pr->top);
|
|
123
|
-
pr->is_hash = (TYPE(pr->top) == T_HASH);
|
|
124
|
-
}
|
|
125
|
-
/** an array object was detected */
|
|
126
|
-
static int fio_json_on_start_array(json_parser_s *p) {
|
|
127
|
-
iodine_json_parser_s *pr = (iodine_json_parser_s *)p;
|
|
128
|
-
if (pr->target)
|
|
129
|
-
return -1;
|
|
130
|
-
VALUE ary = rb_ary_new();
|
|
131
|
-
iodine_json_add2parser(pr, ary);
|
|
132
|
-
fio_json_stack_push(&pr->stack, pr->top);
|
|
133
|
-
pr->top = ary;
|
|
134
|
-
pr->is_hash = 0;
|
|
135
|
-
return 0;
|
|
136
|
-
}
|
|
137
|
-
/** an array closure was detected */
|
|
138
|
-
static void fio_json_on_end_array(json_parser_s *p) {
|
|
139
|
-
iodine_json_parser_s *pr = (iodine_json_parser_s *)p;
|
|
140
|
-
fio_json_stack_pop(&pr->stack, &pr->top);
|
|
141
|
-
pr->is_hash = (TYPE(pr->top) == T_HASH);
|
|
142
|
-
}
|
|
143
|
-
/** the JSON parsing is complete */
|
|
144
|
-
static void fio_json_on_json(json_parser_s *p) { (void)p; /* do nothing */ }
|
|
145
|
-
/** the JSON parsing is complete */
|
|
146
|
-
static void fio_json_on_error(json_parser_s *p) {
|
|
147
|
-
iodine_json_parser_s *pr = (iodine_json_parser_s *)p;
|
|
148
|
-
#if DEBUG
|
|
149
|
-
FIO_LOG_ERROR("JSON on error called.");
|
|
150
|
-
#endif
|
|
151
|
-
IodineStore.remove((VALUE)fio_json_stack_get(&pr->stack, 0));
|
|
152
|
-
IodineStore.remove(pr->key);
|
|
153
|
-
fio_json_stack_free(&pr->stack);
|
|
154
|
-
*pr = (iodine_json_parser_s){.top = 0};
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
/* *****************************************************************************
|
|
158
|
-
Iodine JSON Implementation
|
|
159
|
-
***************************************************************************** */
|
|
160
|
-
|
|
161
|
-
static inline VALUE iodine_json_convert(VALUE str, fiobj2rb_settings_s s) {
|
|
162
|
-
|
|
163
|
-
iodine_json_parser_s p = {.top = 0, .symbolize = s.str2sym};
|
|
164
|
-
size_t consumed = fio_json_parse(&p.p, RSTRING_PTR(str), RSTRING_LEN(str));
|
|
165
|
-
if (!consumed || p.p.depth) {
|
|
166
|
-
IodineStore.remove((VALUE)fio_json_stack_get(&p.stack, 0));
|
|
167
|
-
p.top = FIOBJ_INVALID;
|
|
168
|
-
}
|
|
169
|
-
fio_json_stack_free(&p.stack);
|
|
170
|
-
if (p.key) {
|
|
171
|
-
IodineStore.remove((VALUE)p.key);
|
|
172
|
-
}
|
|
173
|
-
if (!p.top) {
|
|
174
|
-
rb_raise(rb_eEncodingError, "Malformed JSON format.");
|
|
175
|
-
}
|
|
176
|
-
IodineStore.remove(p.top);
|
|
177
|
-
return p.top;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
// static inline VALUE iodine_json_convert2(VALUE str, fiobj2rb_settings_s s) {
|
|
181
|
-
// FIOBJ json;
|
|
182
|
-
// if (!fiobj_json2obj(&json, RSTRING_PTR(str), RSTRING_LEN(str)) || !json) {
|
|
183
|
-
// rb_raise(rb_eRuntimeError, "JSON parsing failed. Not JSON?");
|
|
184
|
-
// return Qnil;
|
|
185
|
-
// }
|
|
186
|
-
// VALUE ret = fiobj2rb_deep(json, s.str2sym);
|
|
187
|
-
// fiobj_free(json);
|
|
188
|
-
// IodineStore.remove(ret);
|
|
189
|
-
// return ret;
|
|
190
|
-
// }
|
|
191
|
-
|
|
192
|
-
static inline void iodine_json_update_settings(VALUE h,
|
|
193
|
-
fiobj2rb_settings_s *s) {
|
|
194
|
-
VALUE tmp;
|
|
195
|
-
if (rb_hash_aref(h, max_nesting) != Qnil)
|
|
196
|
-
FIO_LOG_WARNING("max_nesting ignored on this JSON implementation.");
|
|
197
|
-
if (rb_hash_aref(h, allow_nan) != Qnil)
|
|
198
|
-
fprintf(stderr, "WARNING: allow_nan ignored on this JSON implementation. "
|
|
199
|
-
"NaN always allowed.\n");
|
|
200
|
-
if (rb_hash_aref(h, create_additions) != Qnil)
|
|
201
|
-
FIO_LOG_WARNING("create_additions ignored on this JSON implementation.");
|
|
202
|
-
if (rb_hash_aref(h, object_class) != Qnil)
|
|
203
|
-
FIO_LOG_WARNING("object_class ignored on this JSON implementation.");
|
|
204
|
-
if (rb_hash_aref(h, array_class) != Qnil)
|
|
205
|
-
FIO_LOG_WARNING("array_class ignored on this JSON implementation.");
|
|
206
|
-
if ((tmp = rb_hash_aref(h, symbolize_names)) != Qnil) {
|
|
207
|
-
if (tmp == Qtrue)
|
|
208
|
-
s->str2sym = 1;
|
|
209
|
-
else if (tmp == Qfalse)
|
|
210
|
-
s->str2sym = 0;
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
/**
|
|
215
|
-
Parse a JSON string using the iodine lenient parser (it's also faster).
|
|
216
|
-
*/
|
|
217
|
-
static VALUE iodine_json_parse(int argc, VALUE *argv, VALUE self) {
|
|
218
|
-
fiobj2rb_settings_s s = {.str2sym = 0};
|
|
219
|
-
if (argc > 2)
|
|
220
|
-
rb_raise(rb_eTypeError, "function requires supports up to two arguments.");
|
|
221
|
-
if (argc == 2) {
|
|
222
|
-
Check_Type(argv[1], T_HASH);
|
|
223
|
-
iodine_json_update_settings(argv[1], &s);
|
|
224
|
-
}
|
|
225
|
-
if (argc >= 1)
|
|
226
|
-
Check_Type(argv[0], T_STRING);
|
|
227
|
-
else
|
|
228
|
-
rb_raise(rb_eTypeError, "function requires at least one argument.");
|
|
229
|
-
return iodine_json_convert(argv[0], s);
|
|
230
|
-
(void)self;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
/**
|
|
234
|
-
Parse a JSON string using the iodine lenient parser with a default Symbol
|
|
235
|
-
rather than String key (this is often faster than the regular
|
|
236
|
-
{Iodine::JSON.parse} function).
|
|
237
|
-
*/
|
|
238
|
-
static VALUE iodine_json_parse_bang(int argc, VALUE *argv, VALUE self) {
|
|
239
|
-
fiobj2rb_settings_s s = {.str2sym = 0};
|
|
240
|
-
if (argc > 2)
|
|
241
|
-
rb_raise(rb_eTypeError, "function requires supports up to two arguments.");
|
|
242
|
-
if (argc == 2) {
|
|
243
|
-
Check_Type(argv[1], T_HASH);
|
|
244
|
-
iodine_json_update_settings(argv[1], &s);
|
|
245
|
-
}
|
|
246
|
-
if (argc >= 1)
|
|
247
|
-
Check_Type(argv[0], T_STRING);
|
|
248
|
-
else
|
|
249
|
-
rb_raise(rb_eTypeError, "function requires at least one argument.");
|
|
250
|
-
return iodine_json_convert(argv[0], s);
|
|
251
|
-
(void)self;
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
void iodine_init_json(void) {
|
|
255
|
-
/**
|
|
256
|
-
Iodine::JSON offers a fast(er) JSON parser that is also lenient and supports
|
|
257
|
-
some JSON extensions such as Hex number recognition and comments.
|
|
258
|
-
|
|
259
|
-
You can test the parser using:
|
|
260
|
-
|
|
261
|
-
JSON_FILENAME="foo.json"
|
|
262
|
-
|
|
263
|
-
require 'json'
|
|
264
|
-
require 'iodine'
|
|
265
|
-
TIMES = 100
|
|
266
|
-
STR = IO.binread(JSON_FILENAME); nil
|
|
267
|
-
|
|
268
|
-
JSON.parse(STR) == Iodine::JSON.parse(STR) # => true
|
|
269
|
-
JSON.parse(STR,
|
|
270
|
-
symbolize_names: true) == Iodine::JSON.parse(STR,
|
|
271
|
-
symbolize_names: true) # => true
|
|
272
|
-
JSON.parse!(STR) == Iodine::JSON.parse!(STR) # => true/false (unknown)
|
|
273
|
-
|
|
274
|
-
# warm-up
|
|
275
|
-
TIMES.times { JSON.parse STR }
|
|
276
|
-
TIMES.times { Iodine::JSON.parse STR }
|
|
277
|
-
|
|
278
|
-
Benchmark.bm do |b|
|
|
279
|
-
sys = b.report("system") { TIMES.times { JSON.parse STR } }
|
|
280
|
-
sys_sym = b.report("system sym") { TIMES.times { JSON.parse STR,
|
|
281
|
-
symbolize_names: true } }
|
|
282
|
-
iodine = b.report("iodine") { TIMES.times { Iodine::JSON.parse STR } }
|
|
283
|
-
iodine_sym = b.report("iodine sym") do
|
|
284
|
-
TIMES.times { Iodine::JSON.parse STR,
|
|
285
|
-
symbolize_names: true }
|
|
286
|
-
end
|
|
287
|
-
puts "System / Iodine: #{sys/iodine}"
|
|
288
|
-
puts "System-sym/Iodine-sym: #{sys_sym/iodine_sym}"
|
|
289
|
-
end; nil
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
*/
|
|
293
|
-
VALUE tmp = rb_define_module_under(IodineModule, "JSON");
|
|
294
|
-
max_nesting = ID2SYM(rb_intern("max_nesting"));
|
|
295
|
-
allow_nan = ID2SYM(rb_intern("allow_nan"));
|
|
296
|
-
symbolize_names = ID2SYM(rb_intern("symbolize_names"));
|
|
297
|
-
create_additions = ID2SYM(rb_intern("create_additions"));
|
|
298
|
-
object_class = ID2SYM(rb_intern("object_class"));
|
|
299
|
-
array_class = ID2SYM(rb_intern("array_class"));
|
|
300
|
-
rb_define_module_function(tmp, "parse", iodine_json_parse, -1);
|
|
301
|
-
rb_define_module_function(tmp, "parse!", iodine_json_parse_bang, -1);
|
|
302
|
-
}
|