ffi-yajl 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (214) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +201 -0
  3. data/README.md +17 -0
  4. data/Rakefile +62 -0
  5. data/bin/ffi-yajl-bench +36 -0
  6. data/ext/ffi_yajl/ext/encoder/encoder.c +240 -0
  7. data/ext/ffi_yajl/ext/encoder/extconf.rb +29 -0
  8. data/ext/ffi_yajl/ext/parser/extconf.rb +29 -0
  9. data/ext/ffi_yajl/ext/parser/parser.c +199 -0
  10. data/ext/libyajl2/extconf.rb +65 -0
  11. data/ext/libyajl2/vendored/.gitignore +3 -0
  12. data/ext/libyajl2/vendored/BUILDING +23 -0
  13. data/ext/libyajl2/vendored/BUILDING.win32 +27 -0
  14. data/ext/libyajl2/vendored/CMakeLists.txt +79 -0
  15. data/ext/libyajl2/vendored/COPYING +13 -0
  16. data/ext/libyajl2/vendored/ChangeLog +175 -0
  17. data/ext/libyajl2/vendored/README +74 -0
  18. data/ext/libyajl2/vendored/TODO +9 -0
  19. data/ext/libyajl2/vendored/YAJLDoc.cmake +26 -0
  20. data/ext/libyajl2/vendored/configure +79 -0
  21. data/ext/libyajl2/vendored/example/CMakeLists.txt +23 -0
  22. data/ext/libyajl2/vendored/example/README.md +7 -0
  23. data/ext/libyajl2/vendored/example/parse_config.c +69 -0
  24. data/ext/libyajl2/vendored/example/sample.config +101 -0
  25. data/ext/libyajl2/vendored/perf/CMakeLists.txt +23 -0
  26. data/ext/libyajl2/vendored/perf/documents.c +1418 -0
  27. data/ext/libyajl2/vendored/perf/documents.h +28 -0
  28. data/ext/libyajl2/vendored/perf/perftest.c +134 -0
  29. data/ext/libyajl2/vendored/reformatter/CMakeLists.txt +39 -0
  30. data/ext/libyajl2/vendored/reformatter/json_reformat.c +194 -0
  31. data/ext/libyajl2/vendored/src/CMakeLists.txt +86 -0
  32. data/ext/libyajl2/vendored/src/YAJL.dxy +1258 -0
  33. data/ext/libyajl2/vendored/src/api/yajl_common.h +75 -0
  34. data/ext/libyajl2/vendored/src/api/yajl_gen.h +157 -0
  35. data/ext/libyajl2/vendored/src/api/yajl_parse.h +226 -0
  36. data/ext/libyajl2/vendored/src/api/yajl_tree.h +185 -0
  37. data/ext/libyajl2/vendored/src/api/yajl_version.h.cmake +23 -0
  38. data/ext/libyajl2/vendored/src/yajl +33 -0
  39. data/ext/libyajl2/vendored/src/yajl.c +175 -0
  40. data/ext/libyajl2/vendored/src/yajl.pc.cmake +9 -0
  41. data/ext/libyajl2/vendored/src/yajl_alloc.c +52 -0
  42. data/ext/libyajl2/vendored/src/yajl_alloc.h +34 -0
  43. data/ext/libyajl2/vendored/src/yajl_buf.c +103 -0
  44. data/ext/libyajl2/vendored/src/yajl_buf.h +57 -0
  45. data/ext/libyajl2/vendored/src/yajl_bytestack.h +69 -0
  46. data/ext/libyajl2/vendored/src/yajl_encode.c +220 -0
  47. data/ext/libyajl2/vendored/src/yajl_encode.h +34 -0
  48. data/ext/libyajl2/vendored/src/yajl_gen.c +354 -0
  49. data/ext/libyajl2/vendored/src/yajl_lex.c +763 -0
  50. data/ext/libyajl2/vendored/src/yajl_lex.h +117 -0
  51. data/ext/libyajl2/vendored/src/yajl_parser.c +498 -0
  52. data/ext/libyajl2/vendored/src/yajl_parser.h +78 -0
  53. data/ext/libyajl2/vendored/src/yajl_tree.c +503 -0
  54. data/ext/libyajl2/vendored/src/yajl_version.c +7 -0
  55. data/ext/libyajl2/vendored/test/CMakeLists.txt +23 -0
  56. data/ext/libyajl2/vendored/test/cases/ac_difficult_json_c_test_case_with_comments.json +1 -0
  57. data/ext/libyajl2/vendored/test/cases/ac_difficult_json_c_test_case_with_comments.json.gold +36 -0
  58. data/ext/libyajl2/vendored/test/cases/ac_simple_with_comments.json +11 -0
  59. data/ext/libyajl2/vendored/test/cases/ac_simple_with_comments.json.gold +9 -0
  60. data/ext/libyajl2/vendored/test/cases/ag_false_then_garbage.json +1 -0
  61. data/ext/libyajl2/vendored/test/cases/ag_false_then_garbage.json.gold +2 -0
  62. data/ext/libyajl2/vendored/test/cases/ag_null_then_garbage.json +1 -0
  63. data/ext/libyajl2/vendored/test/cases/ag_null_then_garbage.json.gold +2 -0
  64. data/ext/libyajl2/vendored/test/cases/ag_true_then_garbage.json +1 -0
  65. data/ext/libyajl2/vendored/test/cases/ag_true_then_garbage.json.gold +2 -0
  66. data/ext/libyajl2/vendored/test/cases/am_eof.json +1 -0
  67. data/ext/libyajl2/vendored/test/cases/am_eof.json.gold +4 -0
  68. data/ext/libyajl2/vendored/test/cases/am_integers.json +1 -0
  69. data/ext/libyajl2/vendored/test/cases/am_integers.json.gold +3 -0
  70. data/ext/libyajl2/vendored/test/cases/am_multiple.json +3 -0
  71. data/ext/libyajl2/vendored/test/cases/am_multiple.json.gold +5 -0
  72. data/ext/libyajl2/vendored/test/cases/am_stuff.json +7 -0
  73. data/ext/libyajl2/vendored/test/cases/am_stuff.json.gold +14 -0
  74. data/ext/libyajl2/vendored/test/cases/ap_array_open.json +1 -0
  75. data/ext/libyajl2/vendored/test/cases/ap_array_open.json.gold +2 -0
  76. data/ext/libyajl2/vendored/test/cases/ap_eof_str.json +1 -0
  77. data/ext/libyajl2/vendored/test/cases/ap_eof_str.json.gold +1 -0
  78. data/ext/libyajl2/vendored/test/cases/ap_map_open.json +1 -0
  79. data/ext/libyajl2/vendored/test/cases/ap_map_open.json.gold +2 -0
  80. data/ext/libyajl2/vendored/test/cases/ap_partial_ok.json +1 -0
  81. data/ext/libyajl2/vendored/test/cases/ap_partial_ok.json.gold +4 -0
  82. data/ext/libyajl2/vendored/test/cases/array.json +6 -0
  83. data/ext/libyajl2/vendored/test/cases/array.json.gold +22 -0
  84. data/ext/libyajl2/vendored/test/cases/array_close.json +1 -0
  85. data/ext/libyajl2/vendored/test/cases/array_close.json.gold +2 -0
  86. data/ext/libyajl2/vendored/test/cases/bignums.json +1 -0
  87. data/ext/libyajl2/vendored/test/cases/bignums.json.gold +5 -0
  88. data/ext/libyajl2/vendored/test/cases/bogus_char.json +4 -0
  89. data/ext/libyajl2/vendored/test/cases/bogus_char.json.gold +10 -0
  90. data/ext/libyajl2/vendored/test/cases/codepoints_from_unicode_org.json +1 -0
  91. data/ext/libyajl2/vendored/test/cases/codepoints_from_unicode_org.json.gold +2 -0
  92. data/ext/libyajl2/vendored/test/cases/deep_arrays.json +1 -0
  93. data/ext/libyajl2/vendored/test/cases/deep_arrays.json.gold +2049 -0
  94. data/ext/libyajl2/vendored/test/cases/difficult_json_c_test_case.json +1 -0
  95. data/ext/libyajl2/vendored/test/cases/difficult_json_c_test_case.json.gold +36 -0
  96. data/ext/libyajl2/vendored/test/cases/doubles.json +1 -0
  97. data/ext/libyajl2/vendored/test/cases/doubles.json.gold +7 -0
  98. data/ext/libyajl2/vendored/test/cases/doubles_in_array.json +1 -0
  99. data/ext/libyajl2/vendored/test/cases/doubles_in_array.json.gold +8 -0
  100. data/ext/libyajl2/vendored/test/cases/empty_array.json +1 -0
  101. data/ext/libyajl2/vendored/test/cases/empty_array.json.gold +3 -0
  102. data/ext/libyajl2/vendored/test/cases/empty_string.json +1 -0
  103. data/ext/libyajl2/vendored/test/cases/empty_string.json.gold +2 -0
  104. data/ext/libyajl2/vendored/test/cases/escaped_bulgarian.json +4 -0
  105. data/ext/libyajl2/vendored/test/cases/escaped_bulgarian.json.gold +7 -0
  106. data/ext/libyajl2/vendored/test/cases/escaped_foobar.json +1 -0
  107. data/ext/libyajl2/vendored/test/cases/escaped_foobar.json.gold +2 -0
  108. data/ext/libyajl2/vendored/test/cases/false.json +1 -0
  109. data/ext/libyajl2/vendored/test/cases/false.json.gold +2 -0
  110. data/ext/libyajl2/vendored/test/cases/fg_false_then_garbage.json +1 -0
  111. data/ext/libyajl2/vendored/test/cases/fg_false_then_garbage.json.gold +3 -0
  112. data/ext/libyajl2/vendored/test/cases/fg_issue_7.json +1 -0
  113. data/ext/libyajl2/vendored/test/cases/fg_issue_7.json.gold +3 -0
  114. data/ext/libyajl2/vendored/test/cases/fg_null_then_garbage.json +1 -0
  115. data/ext/libyajl2/vendored/test/cases/fg_null_then_garbage.json.gold +3 -0
  116. data/ext/libyajl2/vendored/test/cases/fg_true_then_garbage.json +1 -0
  117. data/ext/libyajl2/vendored/test/cases/fg_true_then_garbage.json.gold +3 -0
  118. data/ext/libyajl2/vendored/test/cases/four_byte_utf8.json +2 -0
  119. data/ext/libyajl2/vendored/test/cases/four_byte_utf8.json.gold +5 -0
  120. data/ext/libyajl2/vendored/test/cases/high_overflow.json +1 -0
  121. data/ext/libyajl2/vendored/test/cases/high_overflow.json.gold +2 -0
  122. data/ext/libyajl2/vendored/test/cases/integers.json +3 -0
  123. data/ext/libyajl2/vendored/test/cases/integers.json.gold +14 -0
  124. data/ext/libyajl2/vendored/test/cases/invalid_utf8.json +1 -0
  125. data/ext/libyajl2/vendored/test/cases/invalid_utf8.json.gold +3 -0
  126. data/ext/libyajl2/vendored/test/cases/isolated_surrogate_marker.json +1 -0
  127. data/ext/libyajl2/vendored/test/cases/isolated_surrogate_marker.json.gold +2 -0
  128. data/ext/libyajl2/vendored/test/cases/leading_zero_in_number.json +1 -0
  129. data/ext/libyajl2/vendored/test/cases/leading_zero_in_number.json.gold +5 -0
  130. data/ext/libyajl2/vendored/test/cases/lonely_minus_sign.json +7 -0
  131. data/ext/libyajl2/vendored/test/cases/lonely_minus_sign.json.gold +9 -0
  132. data/ext/libyajl2/vendored/test/cases/lonely_number.json +1 -0
  133. data/ext/libyajl2/vendored/test/cases/lonely_number.json.gold +2 -0
  134. data/ext/libyajl2/vendored/test/cases/low_overflow.json +1 -0
  135. data/ext/libyajl2/vendored/test/cases/low_overflow.json.gold +2 -0
  136. data/ext/libyajl2/vendored/test/cases/map_close.json +1 -0
  137. data/ext/libyajl2/vendored/test/cases/map_close.json.gold +2 -0
  138. data/ext/libyajl2/vendored/test/cases/missing_integer_after_decimal_point.json +1 -0
  139. data/ext/libyajl2/vendored/test/cases/missing_integer_after_decimal_point.json.gold +2 -0
  140. data/ext/libyajl2/vendored/test/cases/missing_integer_after_exponent.json +1 -0
  141. data/ext/libyajl2/vendored/test/cases/missing_integer_after_exponent.json.gold +2 -0
  142. data/ext/libyajl2/vendored/test/cases/multiple.json +3 -0
  143. data/ext/libyajl2/vendored/test/cases/multiple.json.gold +4 -0
  144. data/ext/libyajl2/vendored/test/cases/non_utf8_char_in_string.json +1 -0
  145. data/ext/libyajl2/vendored/test/cases/non_utf8_char_in_string.json.gold +8 -0
  146. data/ext/libyajl2/vendored/test/cases/np_partial_bad.json +1 -0
  147. data/ext/libyajl2/vendored/test/cases/np_partial_bad.json.gold +5 -0
  148. data/ext/libyajl2/vendored/test/cases/null.json +1 -0
  149. data/ext/libyajl2/vendored/test/cases/null.json.gold +2 -0
  150. data/ext/libyajl2/vendored/test/cases/nulls_and_bools.json +5 -0
  151. data/ext/libyajl2/vendored/test/cases/nulls_and_bools.json.gold +9 -0
  152. data/ext/libyajl2/vendored/test/cases/simple.json +5 -0
  153. data/ext/libyajl2/vendored/test/cases/simple.json.gold +9 -0
  154. data/ext/libyajl2/vendored/test/cases/simple_with_comments.json +11 -0
  155. data/ext/libyajl2/vendored/test/cases/simple_with_comments.json.gold +5 -0
  156. data/ext/libyajl2/vendored/test/cases/string_invalid_escape.json +1 -0
  157. data/ext/libyajl2/vendored/test/cases/string_invalid_escape.json.gold +3 -0
  158. data/ext/libyajl2/vendored/test/cases/string_invalid_hex_char.json +1 -0
  159. data/ext/libyajl2/vendored/test/cases/string_invalid_hex_char.json.gold +2 -0
  160. data/ext/libyajl2/vendored/test/cases/string_with_escapes.json +3 -0
  161. data/ext/libyajl2/vendored/test/cases/string_with_escapes.json.gold +7 -0
  162. data/ext/libyajl2/vendored/test/cases/string_with_invalid_newline.json +2 -0
  163. data/ext/libyajl2/vendored/test/cases/string_with_invalid_newline.json.gold +2 -0
  164. data/ext/libyajl2/vendored/test/cases/three_byte_utf8.json +1 -0
  165. data/ext/libyajl2/vendored/test/cases/three_byte_utf8.json.gold +7 -0
  166. data/ext/libyajl2/vendored/test/cases/true.json +1 -0
  167. data/ext/libyajl2/vendored/test/cases/true.json.gold +2 -0
  168. data/ext/libyajl2/vendored/test/cases/unescaped_bulgarian.json +1 -0
  169. data/ext/libyajl2/vendored/test/cases/unescaped_bulgarian.json.gold +4 -0
  170. data/ext/libyajl2/vendored/test/cases/zerobyte.json +1 -0
  171. data/ext/libyajl2/vendored/test/cases/zerobyte.json.gold +0 -0
  172. data/ext/libyajl2/vendored/test/run_tests.sh +94 -0
  173. data/ext/libyajl2/vendored/test/yajl_test.c +281 -0
  174. data/ext/libyajl2/vendored/verify/CMakeLists.txt +39 -0
  175. data/ext/libyajl2/vendored/verify/json_verify.c +116 -0
  176. data/lib/ffi_yajl.rb +14 -0
  177. data/lib/ffi_yajl/benchmark.rb +7 -0
  178. data/lib/ffi_yajl/benchmark/MIT-LICENSE +20 -0
  179. data/lib/ffi_yajl/benchmark/encode.rb +135 -0
  180. data/lib/ffi_yajl/benchmark/encode_json_and_marshal.rb +42 -0
  181. data/lib/ffi_yajl/benchmark/encode_json_and_yaml.rb +53 -0
  182. data/lib/ffi_yajl/benchmark/encode_profile.rb +38 -0
  183. data/lib/ffi_yajl/benchmark/http.rb +32 -0
  184. data/lib/ffi_yajl/benchmark/parse.rb +133 -0
  185. data/lib/ffi_yajl/benchmark/parse_json_and_marshal.rb +50 -0
  186. data/lib/ffi_yajl/benchmark/parse_json_and_yaml.rb +55 -0
  187. data/lib/ffi_yajl/benchmark/parse_profile.rb +37 -0
  188. data/lib/ffi_yajl/benchmark/parse_profile_ruby_prof.rb +39 -0
  189. data/lib/ffi_yajl/benchmark/parse_stream.rb +54 -0
  190. data/lib/ffi_yajl/benchmark/subjects/item.json +1 -0
  191. data/lib/ffi_yajl/benchmark/subjects/ohai.json +1216 -0
  192. data/lib/ffi_yajl/benchmark/subjects/ohai.marshal_dump +0 -0
  193. data/lib/ffi_yajl/benchmark/subjects/ohai.yml +975 -0
  194. data/lib/ffi_yajl/benchmark/subjects/twitter_search.json +1 -0
  195. data/lib/ffi_yajl/benchmark/subjects/twitter_stream.json +430 -0
  196. data/lib/ffi_yajl/benchmark/subjects/unicode.json +1 -0
  197. data/lib/ffi_yajl/encoder.rb +53 -0
  198. data/lib/ffi_yajl/ext.rb +22 -0
  199. data/lib/ffi_yajl/ext/.keep +0 -0
  200. data/lib/ffi_yajl/ffi.rb +129 -0
  201. data/lib/ffi_yajl/ffi/encoder.rb +175 -0
  202. data/lib/ffi_yajl/ffi/parser.rb +145 -0
  203. data/lib/ffi_yajl/json_gem.rb +121 -0
  204. data/lib/ffi_yajl/parser.rb +23 -0
  205. data/lib/ffi_yajl/version.rb +3 -0
  206. data/lib/libyajl.so +0 -0
  207. data/lib/libyajl.so.2 +0 -0
  208. data/lib/libyajl.so.2.0.5 +0 -0
  209. data/lib/libyajl_s.a +0 -0
  210. data/spec/ffi_yajl/encoder_spec.rb +39 -0
  211. data/spec/ffi_yajl/json_gem_spec.rb +355 -0
  212. data/spec/ffi_yajl/parser_spec.rb +78 -0
  213. data/spec/spec_helper.rb +14 -0
  214. metadata +332 -0
@@ -0,0 +1,29 @@
1
+ require 'mkmf'
2
+
3
+ # the customer is always right, ruby is always compiled to be stupid
4
+ $CFLAGS = ENV['CFLAGS'] if ENV['CFLAGS']
5
+ $LDFLAGS = ENV['LDFLAGS'] if ENV['LDFLAGS']
6
+ RbConfig::MAKEFILE_CONFIG['CC'] = ENV['CC'] if ENV['CC']
7
+
8
+ # search our gem root first to pick up libyajl2 that we vendored
9
+ gem_root = File.expand_path(File.join(File.dirname(__FILE__), "../../../.."))
10
+ $CFLAGS = "-I#{gem_root}/include -L#{gem_root}/lib #{$CFLAGS}"
11
+ $LDFLAGS = "-L#{gem_root}/lib #{$CFLAGS}"
12
+
13
+ puts gem_root
14
+ puts $CFLAGS
15
+ puts $LDFLAGS
16
+
17
+ # except if you're doing an unoptimized gcc install we're going to help you out a bit
18
+ if RbConfig::MAKEFILE_CONFIG['CC'] =~ /gcc|clang/
19
+ $CFLAGS << " -O3" unless $CFLAGS[/-O\d/]
20
+ # how many people realize that -Wall is a compiler-specific flag???
21
+ # apparently not many based on reading lots of shitty extconf.rb's out there
22
+ $CFLAGS << " -Wall"
23
+ end
24
+
25
+ $LDFLAGS << " -lyajl"
26
+
27
+ dir_config 'encoder'
28
+
29
+ create_makefile 'ffi_yajl/ext/encoder'
@@ -0,0 +1,29 @@
1
+ require 'mkmf'
2
+
3
+ # the customer is always right, ruby is always compiled to be stupid
4
+ $CFLAGS = ENV['CFLAGS'] if ENV['CFLAGS']
5
+ $LDFLAGS = ENV['LDFLAGS'] if ENV['LDFLAGS']
6
+ RbConfig::MAKEFILE_CONFIG['CC'] = ENV['CC'] if ENV['CC']
7
+
8
+ # search our gem root first to pick up libyajl2 that we vendored
9
+ gem_root = File.expand_path(File.join(File.dirname(__FILE__), "../../../.."))
10
+ $CFLAGS = "-I#{gem_root}/include -L#{gem_root}/lib #{$CFLAGS}"
11
+ $LDFLAGS = "-L#{gem_root}/lib #{$CFLAGS}"
12
+
13
+ puts gem_root
14
+ puts $CFLAGS
15
+ puts $LDFLAGS
16
+
17
+ # except if you're doing an unoptimized gcc install we're going to help you out a bit
18
+ if RbConfig::MAKEFILE_CONFIG['CC'] =~ /gcc|clang/
19
+ $CFLAGS << " -O3" unless $CFLAGS[/-O\d/]
20
+ # how many people realize that -Wall is a compiler-specific flag???
21
+ # apparently not many based on reading lots of shitty extconf.rb's out there
22
+ $CFLAGS << " -Wall"
23
+ end
24
+
25
+ $LDFLAGS << " -lyajl"
26
+
27
+ dir_config 'parser'
28
+
29
+ create_makefile 'ffi_yajl/ext/parser'
@@ -0,0 +1,199 @@
1
+ #include <ruby.h>
2
+ #include <yajl/yajl_parse.h>
3
+
4
+ #ifdef HAVE_RUBY_ENCODING_H
5
+ #include <ruby/encoding.h>
6
+ static rb_encoding *utf8Encoding;
7
+ #endif
8
+
9
+ static VALUE mFFI_Yajl, mExt, mParser, cParseError;
10
+
11
+ typedef struct {
12
+ VALUE finished;
13
+ VALUE stack;
14
+ VALUE key_stack;
15
+ VALUE key;
16
+ } CTX;
17
+
18
+ void set_value(CTX *ctx, VALUE val) {
19
+ long len = RARRAY_LEN(ctx->stack);
20
+ VALUE last = rb_ary_entry(ctx->stack, len-1);
21
+ switch (TYPE(last)) {
22
+ case T_ARRAY:
23
+ rb_ary_push(last, val);
24
+ break;
25
+ case T_HASH:
26
+ rb_hash_aset(last, ctx->key, val);
27
+ break;
28
+ default:
29
+ break;
30
+ }
31
+ }
32
+
33
+ void set_key(CTX *ctx, VALUE key) {
34
+ ctx->key = key;
35
+ }
36
+
37
+ void start_object(CTX *ctx, VALUE obj) {
38
+ rb_ary_push(ctx->key_stack, ctx->key);
39
+ rb_ary_push(ctx->stack, obj);
40
+ }
41
+
42
+ void end_object(CTX *ctx) {
43
+ ctx->key = rb_ary_pop(ctx->key_stack);
44
+ if ( RARRAY_LEN(ctx->stack) > 1 ) {
45
+ set_value(ctx, rb_ary_pop(ctx->stack));
46
+ } else {
47
+ ctx->finished = rb_ary_pop(ctx->stack);
48
+ }
49
+ }
50
+
51
+ int null_callback(void *ctx) {
52
+ set_value(ctx, Qnil);
53
+ return 1;
54
+ }
55
+
56
+ int boolean_callback(void *ctx, int boolean) {
57
+ set_value(ctx, boolean ? Qtrue : Qfalse);
58
+ return 1;
59
+ }
60
+
61
+ int integer_callback(void *ctx, long long intVal) {
62
+ set_value(ctx, LONG2NUM(intVal));
63
+ return 1;
64
+ }
65
+
66
+ int double_callback(void *ctx, double doubleVal) {
67
+ set_value(ctx, rb_float_new(doubleVal));
68
+ return 1;
69
+ }
70
+
71
+ int number_callback(void *ctx, const char *numberVal, size_t numberLen) {
72
+ char buf[numberLen+1];
73
+ buf[numberLen] = 0;
74
+ memcpy(buf, numberVal, numberLen);
75
+ if (memchr(buf, '.', numberLen) ||
76
+ memchr(buf, 'e', numberLen) ||
77
+ memchr(buf, 'E', numberLen)) {
78
+ set_value(ctx, rb_float_new(strtod(buf, NULL)));
79
+ } else {
80
+ set_value(ctx, rb_cstr2inum(buf, 10));
81
+ }
82
+ return 1;
83
+ }
84
+
85
+ int string_callback(void *ctx, const unsigned char *stringVal, size_t stringLen) {
86
+ char buf[stringLen+1];
87
+ VALUE str;
88
+ #ifdef HAVE_RUBY_ENCODING_H
89
+ rb_encoding *default_internal_enc;
90
+ #endif
91
+
92
+ buf[stringLen] = 0;
93
+ memcpy(buf, stringVal, stringLen);
94
+ str = rb_str_new2(buf);
95
+ #ifdef HAVE_RUBY_ENCODING_H
96
+ default_internal_enc = rb_default_internal_encoding();
97
+ rb_enc_associate(str, utf8Encoding);
98
+ if (default_internal_enc) {
99
+ str = rb_str_export_to_enc(str, default_internal_enc);
100
+ }
101
+ #endif
102
+ set_value(ctx,str);
103
+ return 1;
104
+ }
105
+
106
+ int start_map_callback(void *ctx) {
107
+ start_object(ctx,rb_hash_new());
108
+ return 1;
109
+ }
110
+
111
+ int map_key_callback(void *ctx, const unsigned char *stringVal, size_t stringLen) {
112
+ char buf[stringLen+1];
113
+ VALUE str;
114
+ #ifdef HAVE_RUBY_ENCODING_H
115
+ rb_encoding *default_internal_enc;
116
+ #endif
117
+
118
+ buf[stringLen] = 0;
119
+ memcpy(buf, stringVal, stringLen);
120
+ str = rb_str_new2(buf);
121
+ #ifdef HAVE_RUBY_ENCODING_H
122
+ default_internal_enc = rb_default_internal_encoding();
123
+ rb_enc_associate(str, utf8Encoding);
124
+ if (default_internal_enc) {
125
+ str = rb_str_export_to_enc(str, default_internal_enc);
126
+ }
127
+ #endif
128
+ set_key(ctx,str);
129
+ return 1;
130
+ }
131
+
132
+ int end_map_callback(void *ctx) {
133
+ end_object(ctx);
134
+ return 1;
135
+ }
136
+
137
+ int start_array_callback(void *ctx) {
138
+ start_object(ctx,rb_ary_new());
139
+ return 1;
140
+ }
141
+
142
+ int end_array_callback(void *ctx) {
143
+ end_object(ctx);
144
+ return 1;
145
+ }
146
+
147
+ static yajl_callbacks callbacks = {
148
+ null_callback,
149
+ boolean_callback,
150
+ integer_callback,
151
+ double_callback,
152
+ number_callback,
153
+ string_callback,
154
+ start_map_callback,
155
+ map_key_callback,
156
+ end_map_callback,
157
+ start_array_callback,
158
+ end_array_callback,
159
+ };
160
+
161
+ static VALUE mParser_do_yajl_parse(VALUE self, VALUE str, VALUE opts) {
162
+ yajl_handle hand;
163
+ yajl_status stat;
164
+ unsigned char *err;
165
+ CTX ctx;
166
+
167
+ ctx.stack = rb_ary_new();
168
+ ctx.key_stack = rb_ary_new();
169
+
170
+ hand = yajl_alloc(&callbacks, NULL, &ctx);
171
+ if ((stat = yajl_parse(hand, (unsigned char *)RSTRING_PTR(str), RSTRING_LEN(str))) != yajl_status_ok) {
172
+ err = yajl_get_error(hand, 1, (unsigned char *)RSTRING_PTR(str), RSTRING_LEN(str));
173
+ goto raise;
174
+ }
175
+ if ((stat = yajl_complete_parse(hand)) != yajl_status_ok) {
176
+ err = yajl_get_error(hand, 1, (unsigned char *)RSTRING_PTR(str), RSTRING_LEN(str));
177
+ goto raise;
178
+ }
179
+ yajl_free(hand);
180
+ return ctx.finished;
181
+
182
+ raise:
183
+ if (hand) {
184
+ yajl_free(hand);
185
+ }
186
+ rb_raise(cParseError, "%s", err);
187
+ }
188
+
189
+ void Init_parser() {
190
+ mFFI_Yajl = rb_define_module("FFI_Yajl");
191
+ cParseError = rb_define_class_under(mFFI_Yajl, "ParseError", rb_eStandardError);
192
+ mExt = rb_define_module_under(mFFI_Yajl, "Ext");
193
+ mParser = rb_define_module_under(mExt, "Parser");
194
+ rb_define_method(mParser, "do_yajl_parse", mParser_do_yajl_parse, 2);
195
+ #ifdef HAVE_RUBY_ENCODING_H
196
+ utf8Encoding = rb_utf8_encoding();
197
+ #endif
198
+ }
199
+
@@ -0,0 +1,65 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rbconfig'
4
+
5
+ cflags = ENV['CFLAGS']
6
+ ldflags = ENV['LDFLAGS']
7
+ cc = ENV['CC']
8
+
9
+ # use the CC that ruby was compiled with by default
10
+ cc ||= RbConfig::MAKEFILE_CONFIG['CC']
11
+ cflags ||= ""
12
+ ldflags ||= ""
13
+
14
+ # then ultimately default back to gcc
15
+ cc ||= "gcc"
16
+
17
+ # FIXME: add more compilers with default options
18
+ if cc =~ /gcc|clang/
19
+ cflags << " -O3" unless cflags =~ /-O\d/
20
+ cflags << " -Wall"
21
+ end
22
+
23
+ if !defined?(RUBY_ENGINE) || RUBY_ENGINE == 'ruby' || RUBY_ENGINE == 'rbx'
24
+ require 'mkmf'
25
+
26
+ # yajl_complete_parse is only in >= 2.0
27
+ libyajl2_ok = have_library("yajl", "yajl_complete_parse", [ "yajl/yajl_parse.h" ]) && have_func("yajl_complete_parse")
28
+ else
29
+ # always install libyajl2 on Jruby
30
+ # FIXME: get the conditional mkmf stuff to work on Jruby
31
+ libyajl2_ok = false
32
+ end
33
+
34
+ prefix=File.expand_path(File.join(File.dirname(__FILE__), "..", ".."))
35
+
36
+ #dir_config 'libyajl2'
37
+
38
+ if libyajl2_ok
39
+ File.open("Makefile", "w") do |mf|
40
+ mf.puts "# Dummy makefile when we don't build the library"
41
+ mf.puts "all install::\n"
42
+ end
43
+ else
44
+ ENV['CFLAGS'] = cflags
45
+ ENV['LDFLAGS'] = ldflags
46
+ ENV['CC'] = cc
47
+ unless File.exists?("vendored")
48
+ system("pwd")
49
+ puts "FOOOOOOOO: #{__FILE__}"
50
+ system("ls -lad #{File.expand_path(File.join(File.dirname(__FILE__), "vendored"))}")
51
+ end
52
+ system("cp -rf #{File.expand_path(File.join(File.dirname(__FILE__), "vendored"))} .") unless File.exists?("vendored")
53
+
54
+ File.open("Makefile", "w") do |mf|
55
+ mf.puts "# Makefile for building vendored libyajl2"
56
+ mf.puts "CFLAGS = #{ENV['CFLAGS']}"
57
+ mf.puts "LDFLAGS = #{ENV['LDFLAGS']}"
58
+ mf.puts "CC = #{ENV['CC']}\n"
59
+ mf.puts "all install::"
60
+ mf.puts "\tcd vendored && ./configure --prefix=#{prefix}"
61
+ mf.puts "\tcd vendored && make install"
62
+ mf.puts "\tcp -f vendored/build/yajl-2.0.5/lib/libyajl.so .\n"
63
+ end
64
+ end
65
+
@@ -0,0 +1,3 @@
1
+ .DS_Store
2
+ Makefile
3
+ /build/
@@ -0,0 +1,23 @@
1
+ Short story (If you already have ruby and cmake):
2
+
3
+ ./configure && make install
4
+
5
+ When things go wrong:
6
+
7
+ attain CMake (http://www.cmake.org) and ruby (http://ruby-lang.org) and
8
+ try again.
9
+
10
+ OR, attain CMake and build by hand:
11
+
12
+ 1. mkdir build
13
+ 2. cd build
14
+ 3. cmake ..
15
+ 4. make
16
+ 5. build output left in yajl-X.Y.Z
17
+
18
+ NOTE: for 64-bit systems where lib64 is used you can pass the cmake
19
+ variable LIB_SUFFIX to cause installation into the system's 'lib64'
20
+ directory.
21
+
22
+ best,
23
+ lloyd
@@ -0,0 +1,27 @@
1
+ YAJL has been successfully built using Visual Studio 8. CMake, a
2
+ build file generator, is used to build the software. CMake supports
3
+ several different build environments, so you may either build YAJL
4
+ using the IDE via the following steps:
5
+
6
+ 1. acquire cmake (http://www.cmake.org)
7
+ 2. mkdir build
8
+ 3. cd build
9
+ 4. cmake ..
10
+ 5. devenv YetAnotherJSONParser.sln /project ALL_BUILD /build Release
11
+ 6. build output is left in build/yajl-X.Y.Z
12
+
13
+ Or you can build from the command line using nmake:
14
+
15
+ 1. Click Start > Programs > Microsoft Visual Studio > Visual Studio
16
+ Tools > Visual Studio Command Prompt -- for your version of Visual
17
+ Studio, which will open a command prompt. You may verify that the
18
+ compiler is in your path by typing "cl /?" at the prompt.
19
+ 2. cd C:\path\to\yajl\source\
20
+ 3. mkdir build
21
+ 4. cd build
22
+ 5. cmake -G"NMake Makefiles" -DCMAKE_BUILD_TYPE=Release ..
23
+ 6. nmake
24
+ 7. nmake install
25
+
26
+ Earlier versions of visual studio and other build generators haven't
27
+ been thoroughly tested, but should work without any major issues.
@@ -0,0 +1,79 @@
1
+ # Copyright (c) 2007-2011, Lloyd Hilaiel <lloyd@hilaiel.com>
2
+ #
3
+ # Permission to use, copy, modify, and/or distribute this software for any
4
+ # purpose with or without fee is hereby granted, provided that the above
5
+ # copyright notice and this permission notice appear in all copies.
6
+ #
7
+ # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8
+ # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9
+ # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10
+ # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11
+ # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12
+ # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13
+ # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14
+
15
+ CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
16
+
17
+ PROJECT(YetAnotherJSONParser C)
18
+
19
+ SET (YAJL_MAJOR 2)
20
+ SET (YAJL_MINOR 0)
21
+ SET (YAJL_MICRO 5)
22
+
23
+ SET (YAJL_DIST_NAME "yajl-${YAJL_MAJOR}.${YAJL_MINOR}.${YAJL_MICRO}")
24
+
25
+ IF (NOT CMAKE_BUILD_TYPE)
26
+ SET(CMAKE_BUILD_TYPE "Release")
27
+ ENDIF (NOT CMAKE_BUILD_TYPE)
28
+
29
+ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
30
+
31
+ IF (WIN32)
32
+ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4")
33
+ ADD_DEFINITIONS(-DWIN32)
34
+ SET(linkFlags "/PDB:NONE /INCREMENTAL:NO /OPT:NOREF /OPT:NOICF")
35
+ SET(CMAKE_EXE_LINKER_FLAGS "${linkFlags}"
36
+ CACHE STRING "YAJL linker flags" FORCE)
37
+ SET(CMAKE_EXE_LINKER_FLAGS_DEBUG ""
38
+ CACHE STRING "YAJL debug linker flags" FORCE)
39
+ SET(CMAKE_EXE_LINKER_FLAGS_RELEASE
40
+ CACHE STRING "YAJL release linker flags" FORCE)
41
+ SET(CMAKE_SHARED_LINKER_FLAGS "${linkFlags}"
42
+ CACHE STRING "YAJL shared linker flags" FORCE)
43
+ SET(CMAKE_MODULE_LINKER_FLAGS "${linkFlags}"
44
+ CACHE STRING "YAJL module linker flags" FORCE)
45
+
46
+ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4996 /wd4255 /wd4130 /wd4100 /wd4711")
47
+ SET(CMAKE_C_FLAGS_DEBUG "/D DEBUG /Od /Z7")
48
+ SET(CMAKE_C_FLAGS_RELEASE "/D NDEBUG /O2")
49
+ ELSE (WIN32)
50
+ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
51
+ IF(CMAKE_COMPILER_IS_GNUCC)
52
+ INCLUDE(CheckCCompilerFlag)
53
+ CHECK_C_COMPILER_FLAG(-fvisibility=hidden HAVE_GCC_VISIBILITY)
54
+ IF(HAVE_GCC_VISIBILITY)
55
+ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden")
56
+ ENDIF(HAVE_GCC_VISIBILITY)
57
+ ENDIF(CMAKE_COMPILER_IS_GNUCC)
58
+ SET(CMAKE_C_FLAGS
59
+ "${CMAKE_C_FLAGS} -std=c99 -pedantic -Wpointer-arith -Wno-format-y2k -Wstrict-prototypes -Wmissing-declarations -Wnested-externs -Wextra -Wundef -Wwrite-strings -Wold-style-definition -Wredundant-decls -Wno-unused-parameter -Wno-sign-compare -Wmissing-prototypes")
60
+
61
+ SET(CMAKE_C_FLAGS_DEBUG "-DDEBUG -g")
62
+ SET(CMAKE_C_FLAGS_RELEASE "-DNDEBUG -O2 -Wuninitialized")
63
+ ENDIF (WIN32)
64
+
65
+
66
+ ADD_SUBDIRECTORY(src)
67
+ ADD_SUBDIRECTORY(test)
68
+ ADD_SUBDIRECTORY(reformatter)
69
+ ADD_SUBDIRECTORY(verify)
70
+ ADD_SUBDIRECTORY(example)
71
+ ADD_SUBDIRECTORY(perf)
72
+
73
+ INCLUDE(YAJLDoc.cmake)
74
+
75
+ # a test target
76
+ ADD_CUSTOM_TARGET(test
77
+ ./run_tests.sh ${CMAKE_CURRENT_BINARY_DIR}/test/yajl_test
78
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/test)
79
+