libyajl2 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (193) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +25 -0
  3. data/.gitmodules +3 -0
  4. data/.kitchen.cloud.yml +87 -0
  5. data/.kitchen.yml +38 -0
  6. data/.reek.yml +3 -0
  7. data/.rspec +1 -0
  8. data/.rubocop.yml +38 -0
  9. data/.travis.yml +8 -0
  10. data/CONTRIBUTING.md +4 -0
  11. data/Gemfile +12 -0
  12. data/LICENSE +201 -0
  13. data/README.md +9 -0
  14. data/Rakefile +144 -0
  15. data/bootstrap.sh +60 -0
  16. data/ext/libyajl2/Makefile +7 -0
  17. data/ext/libyajl2/extconf.rb +66 -0
  18. data/ext/libyajl2/vendor/yajl/.gitignore +3 -0
  19. data/ext/libyajl2/vendor/yajl/BUILDING +23 -0
  20. data/ext/libyajl2/vendor/yajl/BUILDING.win32 +27 -0
  21. data/ext/libyajl2/vendor/yajl/CMakeLists.txt +81 -0
  22. data/ext/libyajl2/vendor/yajl/COPYING +13 -0
  23. data/ext/libyajl2/vendor/yajl/ChangeLog +189 -0
  24. data/ext/libyajl2/vendor/yajl/README +74 -0
  25. data/ext/libyajl2/vendor/yajl/TODO +9 -0
  26. data/ext/libyajl2/vendor/yajl/YAJLDoc.cmake +26 -0
  27. data/ext/libyajl2/vendor/yajl/configure +81 -0
  28. data/ext/libyajl2/vendor/yajl/example/CMakeLists.txt +23 -0
  29. data/ext/libyajl2/vendor/yajl/example/README.md +7 -0
  30. data/ext/libyajl2/vendor/yajl/example/parse_config.c +69 -0
  31. data/ext/libyajl2/vendor/yajl/example/sample.config +101 -0
  32. data/ext/libyajl2/vendor/yajl/perf/CMakeLists.txt +23 -0
  33. data/ext/libyajl2/vendor/yajl/perf/documents.c +1418 -0
  34. data/ext/libyajl2/vendor/yajl/perf/documents.h +28 -0
  35. data/ext/libyajl2/vendor/yajl/perf/perftest.c +134 -0
  36. data/ext/libyajl2/vendor/yajl/reformatter/CMakeLists.txt +43 -0
  37. data/ext/libyajl2/vendor/yajl/reformatter/json_reformat.c +210 -0
  38. data/ext/libyajl2/vendor/yajl/src/CMakeLists.txt +87 -0
  39. data/ext/libyajl2/vendor/yajl/src/YAJL.dxy +1258 -0
  40. data/ext/libyajl2/vendor/yajl/src/api/yajl_common.h +75 -0
  41. data/ext/libyajl2/vendor/yajl/src/api/yajl_gen.h +167 -0
  42. data/ext/libyajl2/vendor/yajl/src/api/yajl_parse.h +226 -0
  43. data/ext/libyajl2/vendor/yajl/src/api/yajl_tree.h +186 -0
  44. data/ext/libyajl2/vendor/yajl/src/api/yajl_version.h.cmake +23 -0
  45. data/ext/libyajl2/vendor/yajl/src/yajl +33 -0
  46. data/ext/libyajl2/vendor/yajl/src/yajl.c +175 -0
  47. data/ext/libyajl2/vendor/yajl/src/yajl.pc.cmake +9 -0
  48. data/ext/libyajl2/vendor/yajl/src/yajl_alloc.c +52 -0
  49. data/ext/libyajl2/vendor/yajl/src/yajl_alloc.h +34 -0
  50. data/ext/libyajl2/vendor/yajl/src/yajl_buf.c +103 -0
  51. data/ext/libyajl2/vendor/yajl/src/yajl_buf.h +57 -0
  52. data/ext/libyajl2/vendor/yajl/src/yajl_bytestack.h +69 -0
  53. data/ext/libyajl2/vendor/yajl/src/yajl_encode.c +220 -0
  54. data/ext/libyajl2/vendor/yajl/src/yajl_encode.h +34 -0
  55. data/ext/libyajl2/vendor/yajl/src/yajl_gen.c +362 -0
  56. data/ext/libyajl2/vendor/yajl/src/yajl_lex.c +763 -0
  57. data/ext/libyajl2/vendor/yajl/src/yajl_lex.h +117 -0
  58. data/ext/libyajl2/vendor/yajl/src/yajl_parser.c +498 -0
  59. data/ext/libyajl2/vendor/yajl/src/yajl_parser.h +78 -0
  60. data/ext/libyajl2/vendor/yajl/src/yajl_tree.c +503 -0
  61. data/ext/libyajl2/vendor/yajl/src/yajl_version.c +7 -0
  62. data/ext/libyajl2/vendor/yajl/test/CMakeLists.txt +16 -0
  63. data/ext/libyajl2/vendor/yajl/test/api/CMakeLists.txt +25 -0
  64. data/ext/libyajl2/vendor/yajl/test/api/gen-extra-close.c +19 -0
  65. data/ext/libyajl2/vendor/yajl/test/api/run_tests.sh +23 -0
  66. data/ext/libyajl2/vendor/yajl/test/parsing/CMakeLists.txt +23 -0
  67. data/ext/libyajl2/vendor/yajl/test/parsing/cases/ac_difficult_json_c_test_case_with_comments.json +1 -0
  68. data/ext/libyajl2/vendor/yajl/test/parsing/cases/ac_difficult_json_c_test_case_with_comments.json.gold +36 -0
  69. data/ext/libyajl2/vendor/yajl/test/parsing/cases/ac_simple_with_comments.json +11 -0
  70. data/ext/libyajl2/vendor/yajl/test/parsing/cases/ac_simple_with_comments.json.gold +9 -0
  71. data/ext/libyajl2/vendor/yajl/test/parsing/cases/ag_false_then_garbage.json +1 -0
  72. data/ext/libyajl2/vendor/yajl/test/parsing/cases/ag_false_then_garbage.json.gold +2 -0
  73. data/ext/libyajl2/vendor/yajl/test/parsing/cases/ag_null_then_garbage.json +1 -0
  74. data/ext/libyajl2/vendor/yajl/test/parsing/cases/ag_null_then_garbage.json.gold +2 -0
  75. data/ext/libyajl2/vendor/yajl/test/parsing/cases/ag_true_then_garbage.json +1 -0
  76. data/ext/libyajl2/vendor/yajl/test/parsing/cases/ag_true_then_garbage.json.gold +2 -0
  77. data/ext/libyajl2/vendor/yajl/test/parsing/cases/am_eof.json +1 -0
  78. data/ext/libyajl2/vendor/yajl/test/parsing/cases/am_eof.json.gold +4 -0
  79. data/ext/libyajl2/vendor/yajl/test/parsing/cases/am_integers.json +1 -0
  80. data/ext/libyajl2/vendor/yajl/test/parsing/cases/am_integers.json.gold +3 -0
  81. data/ext/libyajl2/vendor/yajl/test/parsing/cases/am_multiple.json +3 -0
  82. data/ext/libyajl2/vendor/yajl/test/parsing/cases/am_multiple.json.gold +5 -0
  83. data/ext/libyajl2/vendor/yajl/test/parsing/cases/am_stuff.json +7 -0
  84. data/ext/libyajl2/vendor/yajl/test/parsing/cases/am_stuff.json.gold +14 -0
  85. data/ext/libyajl2/vendor/yajl/test/parsing/cases/ap_array_open.json +1 -0
  86. data/ext/libyajl2/vendor/yajl/test/parsing/cases/ap_array_open.json.gold +2 -0
  87. data/ext/libyajl2/vendor/yajl/test/parsing/cases/ap_eof_str.json +1 -0
  88. data/ext/libyajl2/vendor/yajl/test/parsing/cases/ap_eof_str.json.gold +1 -0
  89. data/ext/libyajl2/vendor/yajl/test/parsing/cases/ap_map_open.json +1 -0
  90. data/ext/libyajl2/vendor/yajl/test/parsing/cases/ap_map_open.json.gold +2 -0
  91. data/ext/libyajl2/vendor/yajl/test/parsing/cases/ap_partial_ok.json +1 -0
  92. data/ext/libyajl2/vendor/yajl/test/parsing/cases/ap_partial_ok.json.gold +4 -0
  93. data/ext/libyajl2/vendor/yajl/test/parsing/cases/array.json +6 -0
  94. data/ext/libyajl2/vendor/yajl/test/parsing/cases/array.json.gold +22 -0
  95. data/ext/libyajl2/vendor/yajl/test/parsing/cases/array_close.json +1 -0
  96. data/ext/libyajl2/vendor/yajl/test/parsing/cases/array_close.json.gold +2 -0
  97. data/ext/libyajl2/vendor/yajl/test/parsing/cases/bignums.json +1 -0
  98. data/ext/libyajl2/vendor/yajl/test/parsing/cases/bignums.json.gold +5 -0
  99. data/ext/libyajl2/vendor/yajl/test/parsing/cases/bogus_char.json +4 -0
  100. data/ext/libyajl2/vendor/yajl/test/parsing/cases/bogus_char.json.gold +10 -0
  101. data/ext/libyajl2/vendor/yajl/test/parsing/cases/codepoints_from_unicode_org.json +1 -0
  102. data/ext/libyajl2/vendor/yajl/test/parsing/cases/codepoints_from_unicode_org.json.gold +2 -0
  103. data/ext/libyajl2/vendor/yajl/test/parsing/cases/deep_arrays.json +1 -0
  104. data/ext/libyajl2/vendor/yajl/test/parsing/cases/deep_arrays.json.gold +2049 -0
  105. data/ext/libyajl2/vendor/yajl/test/parsing/cases/difficult_json_c_test_case.json +1 -0
  106. data/ext/libyajl2/vendor/yajl/test/parsing/cases/difficult_json_c_test_case.json.gold +36 -0
  107. data/ext/libyajl2/vendor/yajl/test/parsing/cases/doubles.json +1 -0
  108. data/ext/libyajl2/vendor/yajl/test/parsing/cases/doubles.json.gold +7 -0
  109. data/ext/libyajl2/vendor/yajl/test/parsing/cases/doubles_in_array.json +1 -0
  110. data/ext/libyajl2/vendor/yajl/test/parsing/cases/doubles_in_array.json.gold +8 -0
  111. data/ext/libyajl2/vendor/yajl/test/parsing/cases/empty_array.json +1 -0
  112. data/ext/libyajl2/vendor/yajl/test/parsing/cases/empty_array.json.gold +3 -0
  113. data/ext/libyajl2/vendor/yajl/test/parsing/cases/empty_string.json +1 -0
  114. data/ext/libyajl2/vendor/yajl/test/parsing/cases/empty_string.json.gold +2 -0
  115. data/ext/libyajl2/vendor/yajl/test/parsing/cases/escaped_bulgarian.json +4 -0
  116. data/ext/libyajl2/vendor/yajl/test/parsing/cases/escaped_bulgarian.json.gold +7 -0
  117. data/ext/libyajl2/vendor/yajl/test/parsing/cases/escaped_foobar.json +1 -0
  118. data/ext/libyajl2/vendor/yajl/test/parsing/cases/escaped_foobar.json.gold +2 -0
  119. data/ext/libyajl2/vendor/yajl/test/parsing/cases/false.json +1 -0
  120. data/ext/libyajl2/vendor/yajl/test/parsing/cases/false.json.gold +2 -0
  121. data/ext/libyajl2/vendor/yajl/test/parsing/cases/fg_false_then_garbage.json +1 -0
  122. data/ext/libyajl2/vendor/yajl/test/parsing/cases/fg_false_then_garbage.json.gold +3 -0
  123. data/ext/libyajl2/vendor/yajl/test/parsing/cases/fg_issue_7.json +1 -0
  124. data/ext/libyajl2/vendor/yajl/test/parsing/cases/fg_issue_7.json.gold +3 -0
  125. data/ext/libyajl2/vendor/yajl/test/parsing/cases/fg_null_then_garbage.json +1 -0
  126. data/ext/libyajl2/vendor/yajl/test/parsing/cases/fg_null_then_garbage.json.gold +3 -0
  127. data/ext/libyajl2/vendor/yajl/test/parsing/cases/fg_true_then_garbage.json +1 -0
  128. data/ext/libyajl2/vendor/yajl/test/parsing/cases/fg_true_then_garbage.json.gold +3 -0
  129. data/ext/libyajl2/vendor/yajl/test/parsing/cases/four_byte_utf8.json +2 -0
  130. data/ext/libyajl2/vendor/yajl/test/parsing/cases/four_byte_utf8.json.gold +5 -0
  131. data/ext/libyajl2/vendor/yajl/test/parsing/cases/high_overflow.json +1 -0
  132. data/ext/libyajl2/vendor/yajl/test/parsing/cases/high_overflow.json.gold +2 -0
  133. data/ext/libyajl2/vendor/yajl/test/parsing/cases/integers.json +3 -0
  134. data/ext/libyajl2/vendor/yajl/test/parsing/cases/integers.json.gold +14 -0
  135. data/ext/libyajl2/vendor/yajl/test/parsing/cases/invalid_utf8.json +1 -0
  136. data/ext/libyajl2/vendor/yajl/test/parsing/cases/invalid_utf8.json.gold +3 -0
  137. data/ext/libyajl2/vendor/yajl/test/parsing/cases/isolated_surrogate_marker.json +1 -0
  138. data/ext/libyajl2/vendor/yajl/test/parsing/cases/isolated_surrogate_marker.json.gold +2 -0
  139. data/ext/libyajl2/vendor/yajl/test/parsing/cases/leading_zero_in_number.json +1 -0
  140. data/ext/libyajl2/vendor/yajl/test/parsing/cases/leading_zero_in_number.json.gold +5 -0
  141. data/ext/libyajl2/vendor/yajl/test/parsing/cases/lonely_minus_sign.json +7 -0
  142. data/ext/libyajl2/vendor/yajl/test/parsing/cases/lonely_minus_sign.json.gold +9 -0
  143. data/ext/libyajl2/vendor/yajl/test/parsing/cases/lonely_number.json +1 -0
  144. data/ext/libyajl2/vendor/yajl/test/parsing/cases/lonely_number.json.gold +2 -0
  145. data/ext/libyajl2/vendor/yajl/test/parsing/cases/low_overflow.json +1 -0
  146. data/ext/libyajl2/vendor/yajl/test/parsing/cases/low_overflow.json.gold +2 -0
  147. data/ext/libyajl2/vendor/yajl/test/parsing/cases/map_close.json +1 -0
  148. data/ext/libyajl2/vendor/yajl/test/parsing/cases/map_close.json.gold +2 -0
  149. data/ext/libyajl2/vendor/yajl/test/parsing/cases/missing_integer_after_decimal_point.json +1 -0
  150. data/ext/libyajl2/vendor/yajl/test/parsing/cases/missing_integer_after_decimal_point.json.gold +2 -0
  151. data/ext/libyajl2/vendor/yajl/test/parsing/cases/missing_integer_after_exponent.json +1 -0
  152. data/ext/libyajl2/vendor/yajl/test/parsing/cases/missing_integer_after_exponent.json.gold +2 -0
  153. data/ext/libyajl2/vendor/yajl/test/parsing/cases/multiple.json +3 -0
  154. data/ext/libyajl2/vendor/yajl/test/parsing/cases/multiple.json.gold +4 -0
  155. data/ext/libyajl2/vendor/yajl/test/parsing/cases/non_utf8_char_in_string.json +1 -0
  156. data/ext/libyajl2/vendor/yajl/test/parsing/cases/non_utf8_char_in_string.json.gold +8 -0
  157. data/ext/libyajl2/vendor/yajl/test/parsing/cases/np_partial_bad.json +1 -0
  158. data/ext/libyajl2/vendor/yajl/test/parsing/cases/np_partial_bad.json.gold +5 -0
  159. data/ext/libyajl2/vendor/yajl/test/parsing/cases/null.json +1 -0
  160. data/ext/libyajl2/vendor/yajl/test/parsing/cases/null.json.gold +2 -0
  161. data/ext/libyajl2/vendor/yajl/test/parsing/cases/nulls_and_bools.json +5 -0
  162. data/ext/libyajl2/vendor/yajl/test/parsing/cases/nulls_and_bools.json.gold +9 -0
  163. data/ext/libyajl2/vendor/yajl/test/parsing/cases/simple.json +5 -0
  164. data/ext/libyajl2/vendor/yajl/test/parsing/cases/simple.json.gold +9 -0
  165. data/ext/libyajl2/vendor/yajl/test/parsing/cases/simple_with_comments.json +11 -0
  166. data/ext/libyajl2/vendor/yajl/test/parsing/cases/simple_with_comments.json.gold +5 -0
  167. data/ext/libyajl2/vendor/yajl/test/parsing/cases/string_invalid_escape.json +1 -0
  168. data/ext/libyajl2/vendor/yajl/test/parsing/cases/string_invalid_escape.json.gold +3 -0
  169. data/ext/libyajl2/vendor/yajl/test/parsing/cases/string_invalid_hex_char.json +1 -0
  170. data/ext/libyajl2/vendor/yajl/test/parsing/cases/string_invalid_hex_char.json.gold +2 -0
  171. data/ext/libyajl2/vendor/yajl/test/parsing/cases/string_with_escapes.json +3 -0
  172. data/ext/libyajl2/vendor/yajl/test/parsing/cases/string_with_escapes.json.gold +7 -0
  173. data/ext/libyajl2/vendor/yajl/test/parsing/cases/string_with_invalid_newline.json +2 -0
  174. data/ext/libyajl2/vendor/yajl/test/parsing/cases/string_with_invalid_newline.json.gold +2 -0
  175. data/ext/libyajl2/vendor/yajl/test/parsing/cases/three_byte_utf8.json +1 -0
  176. data/ext/libyajl2/vendor/yajl/test/parsing/cases/three_byte_utf8.json.gold +7 -0
  177. data/ext/libyajl2/vendor/yajl/test/parsing/cases/true.json +1 -0
  178. data/ext/libyajl2/vendor/yajl/test/parsing/cases/true.json.gold +2 -0
  179. data/ext/libyajl2/vendor/yajl/test/parsing/cases/unescaped_bulgarian.json +1 -0
  180. data/ext/libyajl2/vendor/yajl/test/parsing/cases/unescaped_bulgarian.json.gold +4 -0
  181. data/ext/libyajl2/vendor/yajl/test/parsing/cases/zerobyte.json +1 -0
  182. data/ext/libyajl2/vendor/yajl/test/parsing/cases/zerobyte.json.gold +0 -0
  183. data/ext/libyajl2/vendor/yajl/test/parsing/run_tests.sh +94 -0
  184. data/ext/libyajl2/vendor/yajl/test/parsing/yajl_test.c +291 -0
  185. data/ext/libyajl2/vendor/yajl/verify/CMakeLists.txt +37 -0
  186. data/ext/libyajl2/vendor/yajl/verify/json_verify.c +120 -0
  187. data/lib/libyajl2.rb +13 -0
  188. data/lib/libyajl2/version.rb +3 -0
  189. data/libyajl2.gemspec +29 -0
  190. data/spec/ffi_spec.rb +20 -0
  191. data/spec/path_spec.rb +15 -0
  192. data/spec/spec_helper.rb +13 -0
  193. metadata +296 -0
@@ -0,0 +1,28 @@
1
+ /*
2
+ * Copyright (c) 2007-2014, Lloyd Hilaiel <me@lloyd.io>
3
+ *
4
+ * Permission to use, copy, modify, and/or distribute this software for any
5
+ * purpose with or without fee is hereby granted, provided that the above
6
+ * copyright notice and this permission notice appear in all copies.
7
+ *
8
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15
+ */
16
+
17
+ #ifndef __DOCUMENTS_H__
18
+ #define __DOCUMENTS_H__
19
+
20
+ /* a header that provides access to several json documents broken into chunks of
21
+ * less than 4k, cause C99 says that's what we should do and YAJL likes streams */
22
+
23
+ extern const char ** g_documents[];
24
+ int num_docs(void);
25
+ const char ** get_doc(int i);
26
+ unsigned int doc_size(int i);
27
+
28
+ #endif
@@ -0,0 +1,134 @@
1
+ /*
2
+ * Copyright (c) 2007-2014, Lloyd Hilaiel <me@lloyd.io>
3
+ *
4
+ * Permission to use, copy, modify, and/or distribute this software for any
5
+ * purpose with or without fee is hereby granted, provided that the above
6
+ * copyright notice and this permission notice appear in all copies.
7
+ *
8
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15
+ */
16
+
17
+ #include <yajl/yajl_parse.h>
18
+ #include <stdio.h>
19
+ #include <stdlib.h>
20
+ #include <string.h>
21
+
22
+ #include "documents.h"
23
+
24
+ /* a platform specific defn' of a function to get a high res time in a
25
+ * portable format */
26
+ #ifndef WIN32
27
+ #include <sys/time.h>
28
+ static double mygettime(void) {
29
+ struct timeval now;
30
+ gettimeofday(&now, NULL);
31
+ return now.tv_sec + (now.tv_usec / 1000000.0);
32
+ }
33
+ #else
34
+ #define _WIN32 1
35
+ #include <windows.h>
36
+ static double mygettime(void) {
37
+ long long tval;
38
+ FILETIME ft;
39
+ GetSystemTimeAsFileTime(&ft);
40
+ tval = ft.dwHighDateTime;
41
+ tval <<=32;
42
+ tval |= ft.dwLowDateTime;
43
+ return tval / 10000000.00;
44
+ }
45
+ #endif
46
+
47
+ #define PARSE_TIME_SECS 3
48
+
49
+ static int
50
+ run(int validate_utf8)
51
+ {
52
+ long long times = 0;
53
+ double starttime;
54
+
55
+ starttime = mygettime();
56
+
57
+ /* allocate a parser */
58
+ for (;;) {
59
+ int i;
60
+ {
61
+ double now = mygettime();
62
+ if (now - starttime >= PARSE_TIME_SECS) break;
63
+ }
64
+
65
+ for (i = 0; i < 100; i++) {
66
+ yajl_handle hand = yajl_alloc(NULL, NULL, NULL);
67
+ yajl_status stat;
68
+ const char ** d;
69
+
70
+ yajl_config(hand, yajl_dont_validate_strings, validate_utf8 ? 0 : 1);
71
+
72
+ for (d = get_doc(times % num_docs()); *d; d++) {
73
+ stat = yajl_parse(hand, (unsigned char *) *d, strlen(*d));
74
+ if (stat != yajl_status_ok) break;
75
+ }
76
+
77
+ stat = yajl_complete_parse(hand);
78
+
79
+ if (stat != yajl_status_ok) {
80
+ unsigned char * str =
81
+ yajl_get_error(hand, 1,
82
+ (unsigned char *) *d,
83
+ (*d ? strlen(*d) : 0));
84
+ fprintf(stderr, "%s", (const char *) str);
85
+ yajl_free_error(hand, str);
86
+ return 1;
87
+ }
88
+ yajl_free(hand);
89
+ times++;
90
+ }
91
+ }
92
+
93
+ /* parsed doc 'times' times */
94
+ {
95
+ double throughput;
96
+ double now;
97
+ const char * all_units[] = { "B/s", "KB/s", "MB/s", (char *) 0 };
98
+ const char ** units = all_units;
99
+ int i, avg_doc_size = 0;
100
+
101
+ now = mygettime();
102
+
103
+ for (i = 0; i < num_docs(); i++) avg_doc_size += doc_size(i);
104
+ avg_doc_size /= num_docs();
105
+
106
+ throughput = (times * avg_doc_size) / (now - starttime);
107
+
108
+ while (*(units + 1) && throughput > 1024) {
109
+ throughput /= 1024;
110
+ units++;
111
+ }
112
+
113
+ printf("Parsing speed: %g %s\n", throughput, *units);
114
+ }
115
+
116
+ return 0;
117
+ }
118
+
119
+ int
120
+ main(void)
121
+ {
122
+ int rv = 0;
123
+
124
+ printf("-- speed tests determine parsing throughput given %d different sample documents --\n",
125
+ num_docs());
126
+
127
+ printf("With UTF8 validation:\n");
128
+ rv = run(1);
129
+ if (rv != 0) return rv;
130
+ printf("Without UTF8 validation:\n");
131
+ rv = run(0);
132
+ return rv;
133
+ }
134
+
@@ -0,0 +1,43 @@
1
+ # Copyright (c) 2007-2014, Lloyd Hilaiel <me@lloyd.io>
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
+ # set up a paths
16
+ SET (binDir ${CMAKE_CURRENT_BINARY_DIR}/../${YAJL_DIST_NAME}/bin)
17
+
18
+ # create a directories
19
+ FILE(MAKE_DIRECTORY ${binDir})
20
+
21
+ SET (SRCS json_reformat.c)
22
+
23
+ # use the library we build, duh.
24
+ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}/../${YAJL_DIST_NAME}/include)
25
+ LINK_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}/../${YAJL_DIST_NAME}/lib)
26
+
27
+ ADD_EXECUTABLE(json_reformat ${SRCS})
28
+
29
+ TARGET_LINK_LIBRARIES(json_reformat yajl_s)
30
+
31
+ # In some environments, we must explicitly link libm (like qnx,
32
+ # thanks @shahbag)
33
+ IF (NOT WIN32)
34
+ TARGET_LINK_LIBRARIES(json_reformat m)
35
+ ENDIF (NOT WIN32)
36
+
37
+ # copy the binary into the output directory
38
+ GET_TARGET_PROPERTY(binPath json_reformat LOCATION)
39
+
40
+ ADD_CUSTOM_COMMAND(TARGET json_reformat POST_BUILD
41
+ COMMAND ${CMAKE_COMMAND} -E copy_if_different ${binPath} ${binDir})
42
+
43
+ INSTALL(TARGETS json_reformat RUNTIME DESTINATION bin)
@@ -0,0 +1,210 @@
1
+ /*
2
+ * Copyright (c) 2007-2014, Lloyd Hilaiel <me@lloyd.io>
3
+ *
4
+ * Permission to use, copy, modify, and/or distribute this software for any
5
+ * purpose with or without fee is hereby granted, provided that the above
6
+ * copyright notice and this permission notice appear in all copies.
7
+ *
8
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15
+ */
16
+
17
+ #include <yajl/yajl_parse.h>
18
+ #include <yajl/yajl_gen.h>
19
+
20
+ #include <stdio.h>
21
+ #include <stdlib.h>
22
+ #include <string.h>
23
+
24
+ /* non-zero when we're reformatting a stream */
25
+ static int s_streamReformat = 0;
26
+
27
+ #define GEN_AND_RETURN(func) \
28
+ { \
29
+ yajl_gen_status __stat = func; \
30
+ if (__stat == yajl_gen_generation_complete && s_streamReformat) { \
31
+ yajl_gen_reset(g, "\n"); \
32
+ __stat = func; \
33
+ } \
34
+ return __stat == yajl_gen_status_ok; }
35
+
36
+ static int reformat_null(void * ctx)
37
+ {
38
+ yajl_gen g = (yajl_gen) ctx;
39
+ GEN_AND_RETURN(yajl_gen_null(g));
40
+ }
41
+
42
+ static int reformat_boolean(void * ctx, int boolean)
43
+ {
44
+ yajl_gen g = (yajl_gen) ctx;
45
+ GEN_AND_RETURN(yajl_gen_bool(g, boolean));
46
+ }
47
+
48
+ static int reformat_number(void * ctx, const char * s, size_t l)
49
+ {
50
+ yajl_gen g = (yajl_gen) ctx;
51
+ GEN_AND_RETURN(yajl_gen_number(g, s, l));
52
+ }
53
+
54
+ static int reformat_string(void * ctx, const unsigned char * stringVal,
55
+ size_t stringLen)
56
+ {
57
+ yajl_gen g = (yajl_gen) ctx;
58
+ GEN_AND_RETURN(yajl_gen_string(g, stringVal, stringLen));
59
+ }
60
+
61
+ static int reformat_map_key(void * ctx, const unsigned char * stringVal,
62
+ size_t stringLen)
63
+ {
64
+ yajl_gen g = (yajl_gen) ctx;
65
+ GEN_AND_RETURN(yajl_gen_string(g, stringVal, stringLen));
66
+ }
67
+
68
+ static int reformat_start_map(void * ctx)
69
+ {
70
+ yajl_gen g = (yajl_gen) ctx;
71
+ GEN_AND_RETURN(yajl_gen_map_open(g));
72
+ }
73
+
74
+
75
+ static int reformat_end_map(void * ctx)
76
+ {
77
+ yajl_gen g = (yajl_gen) ctx;
78
+ GEN_AND_RETURN(yajl_gen_map_close(g));
79
+ }
80
+
81
+ static int reformat_start_array(void * ctx)
82
+ {
83
+ yajl_gen g = (yajl_gen) ctx;
84
+ GEN_AND_RETURN(yajl_gen_array_open(g));
85
+ }
86
+
87
+ static int reformat_end_array(void * ctx)
88
+ {
89
+ yajl_gen g = (yajl_gen) ctx;
90
+ GEN_AND_RETURN(yajl_gen_array_close(g));
91
+ }
92
+
93
+ static yajl_callbacks callbacks = {
94
+ reformat_null,
95
+ reformat_boolean,
96
+ NULL,
97
+ NULL,
98
+ reformat_number,
99
+ reformat_string,
100
+ reformat_start_map,
101
+ reformat_map_key,
102
+ reformat_end_map,
103
+ reformat_start_array,
104
+ reformat_end_array
105
+ };
106
+
107
+ static void
108
+ usage(const char * progname)
109
+ {
110
+ fprintf(stderr, "%s: reformat json from stdin\n"
111
+ "usage: json_reformat [options]\n"
112
+ " -e escape any forward slashes (for embedding in HTML)\n"
113
+ " -m minimize json rather than beautify (default)\n"
114
+ " -s reformat a stream of multiple json entites\n"
115
+ " -u allow invalid UTF8 inside strings during parsing\n",
116
+ progname);
117
+ exit(1);
118
+ }
119
+
120
+ int
121
+ main(int argc, char ** argv)
122
+ {
123
+ yajl_handle hand;
124
+ static unsigned char fileData[65536];
125
+ /* generator config */
126
+ yajl_gen g;
127
+ yajl_status stat;
128
+ size_t rd;
129
+ int retval = 0;
130
+ int a = 1;
131
+
132
+ g = yajl_gen_alloc(NULL);
133
+ yajl_gen_config(g, yajl_gen_beautify, 1);
134
+ yajl_gen_config(g, yajl_gen_validate_utf8, 1);
135
+
136
+ /* ok. open file. let's read and parse */
137
+ hand = yajl_alloc(&callbacks, NULL, (void *) g);
138
+ /* and let's allow comments by default */
139
+ yajl_config(hand, yajl_allow_comments, 1);
140
+
141
+ /* check arguments.*/
142
+ while ((a < argc) && (argv[a][0] == '-') && (strlen(argv[a]) > 1)) {
143
+ unsigned int i;
144
+ for ( i=1; i < strlen(argv[a]); i++) {
145
+ switch (argv[a][i]) {
146
+ case 'm':
147
+ yajl_gen_config(g, yajl_gen_beautify, 0);
148
+ break;
149
+ case 's':
150
+ yajl_config(hand, yajl_allow_multiple_values, 1);
151
+ s_streamReformat = 1;
152
+ break;
153
+ case 'u':
154
+ yajl_config(hand, yajl_dont_validate_strings, 1);
155
+ break;
156
+ case 'e':
157
+ yajl_gen_config(g, yajl_gen_escape_solidus, 1);
158
+ break;
159
+ default:
160
+ fprintf(stderr, "unrecognized option: '%c'\n\n",
161
+ argv[a][i]);
162
+ usage(argv[0]);
163
+ }
164
+ }
165
+ ++a;
166
+ }
167
+ if (a < argc) {
168
+ usage(argv[0]);
169
+ }
170
+
171
+
172
+ for (;;) {
173
+ rd = fread((void *) fileData, 1, sizeof(fileData) - 1, stdin);
174
+
175
+ if (rd == 0) {
176
+ if (!feof(stdin)) {
177
+ fprintf(stderr, "error on file read.\n");
178
+ retval = 1;
179
+ }
180
+ break;
181
+ }
182
+ fileData[rd] = 0;
183
+
184
+ stat = yajl_parse(hand, fileData, rd);
185
+
186
+ if (stat != yajl_status_ok) break;
187
+
188
+ {
189
+ const unsigned char * buf;
190
+ size_t len;
191
+ yajl_gen_get_buf(g, &buf, &len);
192
+ fwrite(buf, 1, len, stdout);
193
+ yajl_gen_clear(g);
194
+ }
195
+ }
196
+
197
+ stat = yajl_complete_parse(hand);
198
+
199
+ if (stat != yajl_status_ok) {
200
+ unsigned char * str = yajl_get_error(hand, 1, fileData, rd);
201
+ fprintf(stderr, "%s", (const char *) str);
202
+ yajl_free_error(hand, str);
203
+ retval = 1;
204
+ }
205
+
206
+ yajl_gen_free(g);
207
+ yajl_free(hand);
208
+
209
+ return retval;
210
+ }
@@ -0,0 +1,87 @@
1
+ # Copyright (c) 2007-2014, Lloyd Hilaiel <me@lloyd.io>
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
+ SET (SRCS yajl.c yajl_lex.c yajl_parser.c yajl_buf.c
16
+ yajl_encode.c yajl_gen.c yajl_alloc.c
17
+ yajl_tree.c yajl_version.c
18
+ )
19
+ SET (HDRS yajl_parser.h yajl_lex.h yajl_buf.h yajl_encode.h yajl_alloc.h)
20
+ SET (PUB_HDRS api/yajl_parse.h api/yajl_gen.h api/yajl_common.h api/yajl_tree.h)
21
+
22
+ # useful when fixing lexer bugs.
23
+ #ADD_DEFINITIONS(-DYAJL_LEXER_DEBUG)
24
+
25
+ # Ensure defined when building YAJL (as opposed to using it from
26
+ # another project). Used to ensure correct function export when
27
+ # building win32 DLL.
28
+ ADD_DEFINITIONS(-DYAJL_BUILD)
29
+
30
+ # set up some paths
31
+ SET (libDir ${CMAKE_CURRENT_BINARY_DIR}/../${YAJL_DIST_NAME}/lib)
32
+ SET (incDir ${CMAKE_CURRENT_BINARY_DIR}/../${YAJL_DIST_NAME}/include/yajl)
33
+ SET (shareDir ${CMAKE_CURRENT_BINARY_DIR}/../${YAJL_DIST_NAME}/share/pkgconfig)
34
+
35
+ # set the output path for libraries
36
+ SET(LIBRARY_OUTPUT_PATH ${libDir})
37
+
38
+ ADD_LIBRARY(yajl_s STATIC ${SRCS} ${HDRS} ${PUB_HDRS})
39
+
40
+ ADD_LIBRARY(yajl SHARED ${SRCS} ${HDRS} ${PUB_HDRS})
41
+
42
+ #### setup shared library version number
43
+ SET_TARGET_PROPERTIES(yajl PROPERTIES
44
+ DEFINE_SYMBOL YAJL_SHARED
45
+ SOVERSION ${YAJL_MAJOR}
46
+ VERSION ${YAJL_MAJOR}.${YAJL_MINOR}.${YAJL_MICRO})
47
+
48
+ #### ensure a .dylib has correct absolute installation paths upon installation
49
+ IF(APPLE)
50
+ MESSAGE("INSTALL_NAME_DIR: ${CMAKE_INSTALL_PREFIX}/lib")
51
+ SET_TARGET_PROPERTIES(yajl PROPERTIES
52
+ INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/lib")
53
+ ENDIF(APPLE)
54
+
55
+ #### build up an sdk as a post build step
56
+
57
+ # create some directories
58
+ FILE(MAKE_DIRECTORY ${libDir})
59
+ FILE(MAKE_DIRECTORY ${incDir})
60
+
61
+ # generate build-time source
62
+ SET(dollar $)
63
+ CONFIGURE_FILE(api/yajl_version.h.cmake ${incDir}/yajl_version.h)
64
+ CONFIGURE_FILE(yajl.pc.cmake ${shareDir}/yajl.pc)
65
+
66
+ # copy public headers to output directory
67
+ FOREACH (header ${PUB_HDRS})
68
+ SET (header ${CMAKE_CURRENT_SOURCE_DIR}/${header})
69
+
70
+ EXEC_PROGRAM(${CMAKE_COMMAND} ARGS -E copy_if_different ${header} ${incDir})
71
+
72
+ ADD_CUSTOM_COMMAND(TARGET yajl_s POST_BUILD
73
+ COMMAND ${CMAKE_COMMAND} -E copy_if_different ${header} ${incDir})
74
+ ENDFOREACH (header ${PUB_HDRS})
75
+
76
+ INCLUDE_DIRECTORIES(${incDir}/..)
77
+
78
+ # at build time you may specify the cmake variable LIB_SUFFIX to handle
79
+ # 64-bit systems which use 'lib64'
80
+ INSTALL(TARGETS yajl
81
+ RUNTIME DESTINATION lib${LIB_SUFFIX}
82
+ LIBRARY DESTINATION lib${LIB_SUFFIX}
83
+ ARCHIVE DESTINATION lib${LIB_SUFFIX})
84
+ INSTALL(TARGETS yajl_s ARCHIVE DESTINATION lib${LIB_SUFFIX})
85
+ INSTALL(FILES ${PUB_HDRS} DESTINATION include/yajl)
86
+ INSTALL(FILES ${incDir}/yajl_version.h DESTINATION include/yajl)
87
+ INSTALL(FILES ${shareDir}/yajl.pc DESTINATION share/pkgconfig)