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
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a5228cf19e71ce3e392b4f90821a4747cfb28f91
4
+ data.tar.gz: 71a662f04d7ee86d22ad701ff644ee485f38a44a
5
+ SHA512:
6
+ metadata.gz: 8fca7d40cb1566899d5ed2cf7b39f026e736554319890c9100ede517f2e960f54cba2f079eac3dd329a1dad87ee89dd254a0ea025e3c2adf58d33e7fa8c38fc1
7
+ data.tar.gz: 0bfeb7afa16ee40a2effd45be604dbf2b3099c2a43546fadb81d0978c47959b61fcf19b096a51f5f55878b11154e9f412cd377cbbad78d169a1c690ebd323f2a
data/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,17 @@
1
+
2
+ [![Build Status](https://travis-ci.org/lamont-granquist/ffi-yajl.png)](https://travis-ci.org/lamont-granquist/ffi-yajl) [![Code Climate](https://codeclimate.com/github/lamont-granquist/ffi-yajl.png)](https://codeclimate.com/github/lamont-granquist/ffi-yajl)
3
+
4
+ ## TODO
5
+
6
+ - switching from curling yajl2 sources to using git submodule
7
+ - test both ffi and ext on platforms that support both (MRI, rbx)
8
+
9
+ ## BUILD NOTES
10
+
11
+ - building libyajl2 requires 'apt-get install cmake' on ubuntu, but note
12
+ that 'apt-get install libyajl2' will be better
13
+
14
+ ## KNOWN BUGS
15
+
16
+ - 'rake compile' broken on mac, only tested to work on linux (ubuntu)
17
+ - C Extension segfaults on ruby 1.8.7, so the ffi mode is forced for RUBY_VERSION < 1.9
data/Rakefile ADDED
@@ -0,0 +1,62 @@
1
+ require 'rspec/core/rake_task'
2
+ require 'rubygems/package_task'
3
+ require 'rake/extensiontask'
4
+
5
+ Dir[File.expand_path("../*gemspec", __FILE__)].reverse.each do |gemspec_path|
6
+ gemspec = eval(IO.read(gemspec_path))
7
+ Gem::PackageTask.new(gemspec).define
8
+ end
9
+
10
+ require 'ffi_yajl/version'
11
+
12
+ desc "Run all specs in spec directory"
13
+ RSpec::Core::RakeTask.new(:spec) do |t|
14
+ t.pattern = FileList['spec/**/*_spec.rb']
15
+ end
16
+
17
+ desc "Build it and ship it"
18
+ task :ship => [:clean, :gem] do
19
+ sh("git tag #{Mixlib::ShellOut::VERSION}")
20
+ sh("git push --tags")
21
+ Dir[File.expand_path("../pkg/*.gem", __FILE__)].reverse.each do |built_gem|
22
+ sh("gem push #{built_gem}")
23
+ end
24
+ end
25
+
26
+ unix_gemspec = eval(File.read("ffi-yajl.gemspec"))
27
+
28
+ task :clean do
29
+ sh "rm -rf pkg/* lib/ffi_yajl/ext/*"
30
+ end
31
+
32
+ desc "install the gem locally"
33
+ task :install => [:package] do
34
+ if defined?(RUBY_ENGINE) && RUBY_ENGINE == "jruby"
35
+ sh %{gem install pkg/#{unix_gemspec.name}-#{unix_gemspec.version}-universal-java.gem}
36
+ else
37
+ sh %{gem install pkg/#{unix_gemspec.name}-#{unix_gemspec.version}.gem}
38
+ end
39
+ end
40
+
41
+ spec = Gem::Specification.load('ffi-yajl.gemspec')
42
+
43
+ Rake::ExtensionTask.new do |ext|
44
+ ext.name = 'libyajl'
45
+ ext.lib_dir = 'lib'
46
+ ext.ext_dir = 'ext/libyajl2'
47
+ ext.gem_spec = spec
48
+ end
49
+
50
+ Rake::ExtensionTask.new do |ext|
51
+ ext.name = 'encoder'
52
+ ext.lib_dir = 'lib/ffi_yajl/ext'
53
+ ext.ext_dir = 'ext/ffi_yajl/ext/encoder'
54
+ ext.gem_spec = spec
55
+ end
56
+
57
+ Rake::ExtensionTask.new do |ext|
58
+ ext.name = 'parser'
59
+ ext.lib_dir = 'lib/ffi_yajl/ext'
60
+ ext.ext_dir = 'ext/ffi_yajl/ext/parser'
61
+ ext.gem_spec = spec
62
+ end
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env ruby
2
+
3
+
4
+ $: << File.expand_path(File.join(File.dirname( File.symlink?(__FILE__) ? File.readlink(__FILE__) : __FILE__ ), "../lib"))
5
+
6
+ require 'optparse'
7
+ require 'ffi_yajl/benchmark'
8
+
9
+ opts = {}
10
+ optparse = OptionParser.new do |o|
11
+ o.banner = "Usage: ffi-yajl-bench"
12
+
13
+ opts[:profile] = false
14
+ o.on( '-p', '--profile', 'Run perftools.rb profiling' ) do
15
+ opts[:profile] = true
16
+ end
17
+
18
+ o.on( '-F', '--ffi', 'Force using FFI' ) do
19
+ opts[:ffi] = true
20
+ end
21
+
22
+ o.on( '-E', '--ext', 'Force using C ext' ) do
23
+ opts[:ext] = true
24
+ end
25
+ end
26
+
27
+ optparse.parse!
28
+
29
+ ENV['FORCE_FFI_YAJL'] = 'ffi' if opts[:ffi]
30
+ ENV['FORCE_FFI_YAJL'] = 'ext' if opts[:ext]
31
+
32
+ if opts[:profile]
33
+ FFI_Yajl::Benchmark::ParseProfileRubyProf.new().run()
34
+ else
35
+ FFI_Yajl::Benchmark::Parse.new().run()
36
+ end
@@ -0,0 +1,240 @@
1
+ #include <ruby.h>
2
+ #include <yajl/yajl_gen.h>
3
+
4
+ static VALUE mFFI_Yajl, mExt, mEncoder, mEncoder2, cEncodeError;
5
+
6
+ /* FIXME: the json gem does a whole bunch of indirection around monkeypatching... not sure if we need to as well... */
7
+
8
+ #define CHECK_STATUS(call) \
9
+ if ((status = (call)) != yajl_gen_status_ok) { rb_funcall(mEncoder2, rb_intern("raise_error_for_status"), 1, status); }
10
+
11
+ typedef struct {
12
+ VALUE json_opts;
13
+ int processing_key;
14
+ } ffi_state_t;
15
+
16
+ static VALUE mEncoder_do_yajl_encode(VALUE self, VALUE obj, VALUE yajl_gen_opts) {
17
+ ID sym_ffi_yajl = rb_intern("ffi_yajl");
18
+ VALUE sym_yajl_gen_beautify = ID2SYM(rb_intern("yajl_gen_beautify"));
19
+ VALUE sym_yajl_gen_validate_utf8 = ID2SYM(rb_intern("yajl_gen_validate_utf8"));
20
+ VALUE sym_yajl_gen_indent_string = ID2SYM(rb_intern("yajl_gen_indent_string"));
21
+ yajl_gen yajl_gen;
22
+ const unsigned char *buf;
23
+ size_t len;
24
+ ffi_state_t state;
25
+ VALUE ret;
26
+ VALUE indent_string;
27
+
28
+ yajl_gen = yajl_gen_alloc(NULL);
29
+
30
+ if ( rb_hash_aref(yajl_gen_opts, sym_yajl_gen_beautify) == Qtrue ) {
31
+ yajl_gen_config(yajl_gen, yajl_gen_beautify, 1);
32
+ }
33
+ if ( rb_hash_aref(yajl_gen_opts, sym_yajl_gen_validate_utf8) == Qtrue ) {
34
+ yajl_gen_config(yajl_gen, yajl_gen_validate_utf8, 1);
35
+ }
36
+
37
+ indent_string = rb_hash_aref(yajl_gen_opts, sym_yajl_gen_indent_string);
38
+ if (indent_string != Qnil) {
39
+ yajl_gen_config(yajl_gen, yajl_gen_indent_string, RSTRING_PTR(indent_string));
40
+ } else {
41
+ yajl_gen_config(yajl_gen, yajl_gen_indent_string, " ");
42
+ }
43
+
44
+ state.processing_key = 0;
45
+
46
+ rb_funcall(obj, sym_ffi_yajl, 2, yajl_gen, (VALUE) &state);
47
+
48
+ yajl_gen_get_buf(yajl_gen, &buf, &len);
49
+
50
+ ret = rb_str_new2((char *)buf);
51
+
52
+ yajl_gen_free(yajl_gen);
53
+
54
+ return ret;
55
+ }
56
+
57
+ typedef struct {
58
+ VALUE yajl_gen;
59
+ ffi_state_t *state;
60
+ } ffs_extra_t;
61
+
62
+ int rb_cHash_ffi_yajl_callback(VALUE key, VALUE val, VALUE extra) {
63
+ ffs_extra_t *extra_p = (ffs_extra_t *)extra;
64
+ ID sym_ffi_yajl = rb_intern("ffi_yajl");
65
+
66
+ extra_p->state->processing_key = 1;
67
+ rb_funcall(key, sym_ffi_yajl, 2, extra_p->yajl_gen, extra_p->state);
68
+ extra_p->state->processing_key = 0;
69
+ rb_funcall(val, sym_ffi_yajl, 2, extra_p->yajl_gen, extra_p->state);
70
+
71
+ return 0;
72
+ }
73
+
74
+ static VALUE rb_cHash_ffi_yajl(VALUE self, VALUE yajl_gen, VALUE state) {
75
+ yajl_gen_status status;
76
+ ffs_extra_t extra;
77
+
78
+ extra.yajl_gen = yajl_gen;
79
+ extra.state = (ffi_state_t *)state;
80
+
81
+ CHECK_STATUS(
82
+ yajl_gen_map_open((struct yajl_gen_t *) yajl_gen)
83
+ );
84
+ rb_hash_foreach(self, rb_cHash_ffi_yajl_callback, (VALUE) &extra);
85
+ CHECK_STATUS(
86
+ yajl_gen_map_close((struct yajl_gen_t *) yajl_gen)
87
+ );
88
+
89
+ return Qnil;
90
+ }
91
+
92
+ static VALUE rb_cArray_ffi_yajl(VALUE self, VALUE yajl_gen, VALUE state) {
93
+ yajl_gen_status status;
94
+ ID sym_ffi_yajl = rb_intern("ffi_yajl");
95
+ long i;
96
+ VALUE val;
97
+
98
+ CHECK_STATUS(
99
+ yajl_gen_array_open((struct yajl_gen_t *) yajl_gen)
100
+ );
101
+ for(i=0; i<RARRAY_LEN(self); i++) {
102
+ val = rb_ary_entry(self, i);
103
+ rb_funcall(val, sym_ffi_yajl, 2, yajl_gen, state);
104
+ }
105
+ CHECK_STATUS(
106
+ yajl_gen_array_close((struct yajl_gen_t *) yajl_gen)
107
+ );
108
+
109
+ return Qnil;
110
+ }
111
+
112
+ static VALUE rb_cNilClass_ffi_yajl(VALUE self, VALUE yajl_gen, VALUE state) {
113
+ yajl_gen_status status;
114
+ CHECK_STATUS(
115
+ yajl_gen_null((struct yajl_gen_t *) yajl_gen)
116
+ );
117
+ return Qnil;
118
+ }
119
+
120
+ static VALUE rb_cTrueClass_ffi_yajl(VALUE self, VALUE yajl_gen, VALUE state) {
121
+ yajl_gen_status status;
122
+ CHECK_STATUS(
123
+ yajl_gen_bool((struct yajl_gen_t *) yajl_gen, 1)
124
+ );
125
+ return Qnil;
126
+ }
127
+
128
+ static VALUE rb_cFalseClass_ffi_yajl(VALUE self, VALUE yajl_gen, VALUE state) {
129
+ yajl_gen_status status;
130
+ CHECK_STATUS(
131
+ yajl_gen_bool((struct yajl_gen_t *) yajl_gen, 0)
132
+ );
133
+ return Qnil;
134
+ }
135
+
136
+ static VALUE rb_cFixnum_ffi_yajl(VALUE self, VALUE yajl_gen, VALUE state) {
137
+ yajl_gen_status status;
138
+ ID sym_to_s = rb_intern("to_s");
139
+ VALUE str = rb_funcall(self, sym_to_s, 0);
140
+ char *cptr = RSTRING_PTR(str);
141
+ int len = RSTRING_LEN(str);
142
+
143
+ if (memcmp(cptr, "NaN", 3) == 0 || memcmp(cptr, "Infinity", 8) == 0 || memcmp(cptr, "-Infinity", 9) == 0) {
144
+ rb_raise(cEncodeError, "'%s' is an invalid number", cptr);
145
+ }
146
+ if ( ((ffi_state_t *)state)->processing_key ) {
147
+ CHECK_STATUS(
148
+ yajl_gen_string((struct yajl_gen_t *) yajl_gen, (unsigned char *)cptr, len)
149
+ );
150
+ } else {
151
+ CHECK_STATUS(
152
+ yajl_gen_integer((struct yajl_gen_t *) yajl_gen, NUM2INT(self))
153
+ );
154
+ }
155
+ return Qnil;
156
+ }
157
+
158
+ static VALUE rb_cBignum_ffi_yajl(VALUE self, VALUE yajl_gen, VALUE state) {
159
+ yajl_gen_status status;
160
+ ID sym_to_s = rb_intern("to_s");
161
+ VALUE str = rb_funcall(self, sym_to_s, 0);
162
+ char *cptr = RSTRING_PTR(str);
163
+ int len = RSTRING_LEN(str);
164
+ if (memcmp(cptr, "NaN", 3) == 0 || memcmp(cptr, "Infinity", 8) == 0 || memcmp(cptr, "-Infinity", 9) == 0) {
165
+ rb_raise(cEncodeError, "'%s' is an invalid number", cptr);
166
+ }
167
+ if ( ((ffi_state_t *)state)->processing_key ) {
168
+ CHECK_STATUS(
169
+ yajl_gen_string((struct yajl_gen_t *) yajl_gen, (unsigned char *)cptr, len)
170
+ );
171
+ } else {
172
+ CHECK_STATUS(
173
+ yajl_gen_number((struct yajl_gen_t *) yajl_gen, cptr, len)
174
+ );
175
+ }
176
+ return Qnil;
177
+ }
178
+
179
+ static VALUE rb_cFloat_ffi_yajl(VALUE self, VALUE yajl_gen, VALUE state) {
180
+ yajl_gen_status status;
181
+ ID sym_to_s = rb_intern("to_s");
182
+ VALUE str = rb_funcall(self, sym_to_s, 0);
183
+ char *cptr = RSTRING_PTR(str);
184
+ int len = RSTRING_LEN(str);
185
+ if (memcmp(cptr, "NaN", 3) == 0 || memcmp(cptr, "Infinity", 8) == 0 || memcmp(cptr, "-Infinity", 9) == 0) {
186
+ rb_raise(cEncodeError, "'%s' is an invalid number", cptr);
187
+ }
188
+ if ( ((ffi_state_t *)state)->processing_key ) {
189
+ CHECK_STATUS(
190
+ yajl_gen_string((struct yajl_gen_t *) yajl_gen, (unsigned char *)cptr, len)
191
+ );
192
+ } else {
193
+ CHECK_STATUS(
194
+ yajl_gen_number((struct yajl_gen_t *) yajl_gen, cptr, len)
195
+ );
196
+ }
197
+ return Qnil;
198
+ }
199
+
200
+
201
+ static VALUE rb_cString_ffi_yajl(VALUE self, VALUE yajl_gen, VALUE state) {
202
+ yajl_gen_status status;
203
+ CHECK_STATUS(
204
+ yajl_gen_string((struct yajl_gen_t *) yajl_gen, (unsigned char *)RSTRING_PTR(self), RSTRING_LEN(self))
205
+ );
206
+ return Qnil;
207
+ }
208
+
209
+ static VALUE rb_cObject_ffi_yajl(VALUE self, VALUE yajl_gen, VALUE state) {
210
+ yajl_gen_status status;
211
+ ID sym_to_json = rb_intern("to_json");
212
+ VALUE str;
213
+
214
+ str = rb_funcall(self, sym_to_json, 1, ((ffi_state_t *)state)->json_opts);
215
+ CHECK_STATUS(
216
+ yajl_gen_number((struct yajl_gen_t *) yajl_gen, (char *)RSTRING_PTR(str), RSTRING_LEN(str))
217
+ );
218
+ return Qnil;
219
+ }
220
+
221
+ void Init_encoder() {
222
+ mFFI_Yajl = rb_define_module("FFI_Yajl");
223
+ mEncoder2 = rb_define_class_under(mFFI_Yajl, "Encoder", rb_cObject);
224
+ cEncodeError = rb_define_class_under(mFFI_Yajl, "EncodeError", rb_eStandardError);
225
+ mExt = rb_define_module_under(mFFI_Yajl, "Ext");
226
+ mEncoder = rb_define_module_under(mExt, "Encoder");
227
+ rb_define_method(mEncoder, "do_yajl_encode", mEncoder_do_yajl_encode, 2);
228
+
229
+ rb_define_method(rb_cHash, "ffi_yajl", rb_cHash_ffi_yajl, 2);
230
+ rb_define_method(rb_cArray, "ffi_yajl", rb_cArray_ffi_yajl, 2);
231
+ rb_define_method(rb_cNilClass, "ffi_yajl", rb_cNilClass_ffi_yajl, 2);
232
+ rb_define_method(rb_cTrueClass, "ffi_yajl", rb_cTrueClass_ffi_yajl, 2);
233
+ rb_define_method(rb_cFalseClass, "ffi_yajl", rb_cFalseClass_ffi_yajl, 2);
234
+ rb_define_method(rb_cFixnum, "ffi_yajl", rb_cFixnum_ffi_yajl, 2);
235
+ rb_define_method(rb_cBignum, "ffi_yajl", rb_cBignum_ffi_yajl, 2);
236
+ rb_define_method(rb_cFloat, "ffi_yajl", rb_cFloat_ffi_yajl, 2);
237
+ rb_define_method(rb_cString, "ffi_yajl", rb_cString_ffi_yajl, 2);
238
+ rb_define_method(rb_cObject, "ffi_yajl", rb_cObject_ffi_yajl, 2);
239
+ }
240
+