ffi-yajl 0.0.1-universal-java → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (211) hide show
  1. checksums.yaml +5 -5
  2. data/LICENSE +21 -201
  3. data/README.md +105 -10
  4. data/bin/ffi-yajl-bench +11 -11
  5. data/ext/ffi_yajl/ext/dlopen/dlopen.c +40 -0
  6. data/ext/ffi_yajl/ext/dlopen/extconf.rb +16 -0
  7. data/ext/ffi_yajl/ext/dlopen/yajl.sym +18 -0
  8. data/ext/ffi_yajl/ext/encoder/encoder.c +270 -115
  9. data/ext/ffi_yajl/ext/encoder/extconf.rb +71 -14
  10. data/ext/ffi_yajl/ext/parser/extconf.rb +71 -14
  11. data/ext/ffi_yajl/ext/parser/parser.c +85 -44
  12. data/lib/ffi_yajl/benchmark/encode.rb +39 -92
  13. data/lib/ffi_yajl/benchmark/encode_json_and_marshal.rb +23 -23
  14. data/lib/ffi_yajl/benchmark/encode_json_and_yaml.rb +24 -30
  15. data/lib/ffi_yajl/benchmark/encode_profile.rb +15 -19
  16. data/lib/ffi_yajl/benchmark/http.rb +21 -25
  17. data/lib/ffi_yajl/benchmark/parse.rb +77 -117
  18. data/lib/ffi_yajl/benchmark/parse_json_and_marshal.rb +27 -27
  19. data/lib/ffi_yajl/benchmark/parse_json_and_yaml.rb +30 -30
  20. data/lib/ffi_yajl/benchmark/parse_profile.rb +14 -18
  21. data/lib/ffi_yajl/benchmark/parse_profile_ruby_prof.rb +14 -19
  22. data/lib/ffi_yajl/benchmark/parse_stream.rb +28 -28
  23. data/lib/ffi_yajl/benchmark.rb +26 -6
  24. data/lib/ffi_yajl/encoder.rb +47 -6
  25. data/lib/ffi_yajl/ext.rb +37 -10
  26. data/lib/ffi_yajl/ffi/encoder.rb +150 -63
  27. data/lib/ffi_yajl/ffi/parser.rb +82 -64
  28. data/lib/ffi_yajl/ffi.rb +70 -46
  29. data/lib/ffi_yajl/map_library_name.rb +109 -0
  30. data/lib/ffi_yajl/parser.rb +69 -1
  31. data/lib/ffi_yajl/platform.rb +29 -0
  32. data/lib/ffi_yajl/version.rb +23 -1
  33. data/lib/ffi_yajl.rb +44 -8
  34. metadata +25 -238
  35. data/Rakefile +0 -62
  36. data/ext/libyajl2/extconf.rb +0 -65
  37. data/ext/libyajl2/vendored/.git +0 -1
  38. data/ext/libyajl2/vendored/.gitignore +0 -3
  39. data/ext/libyajl2/vendored/BUILDING +0 -23
  40. data/ext/libyajl2/vendored/BUILDING.win32 +0 -27
  41. data/ext/libyajl2/vendored/CMakeLists.txt +0 -79
  42. data/ext/libyajl2/vendored/COPYING +0 -13
  43. data/ext/libyajl2/vendored/ChangeLog +0 -175
  44. data/ext/libyajl2/vendored/README +0 -74
  45. data/ext/libyajl2/vendored/TODO +0 -9
  46. data/ext/libyajl2/vendored/YAJLDoc.cmake +0 -26
  47. data/ext/libyajl2/vendored/configure +0 -79
  48. data/ext/libyajl2/vendored/example/CMakeLists.txt +0 -23
  49. data/ext/libyajl2/vendored/example/README.md +0 -7
  50. data/ext/libyajl2/vendored/example/parse_config.c +0 -69
  51. data/ext/libyajl2/vendored/example/sample.config +0 -101
  52. data/ext/libyajl2/vendored/perf/CMakeLists.txt +0 -23
  53. data/ext/libyajl2/vendored/perf/documents.c +0 -1418
  54. data/ext/libyajl2/vendored/perf/documents.h +0 -28
  55. data/ext/libyajl2/vendored/perf/perftest.c +0 -134
  56. data/ext/libyajl2/vendored/reformatter/CMakeLists.txt +0 -39
  57. data/ext/libyajl2/vendored/reformatter/json_reformat.c +0 -194
  58. data/ext/libyajl2/vendored/src/CMakeLists.txt +0 -86
  59. data/ext/libyajl2/vendored/src/YAJL.dxy +0 -1258
  60. data/ext/libyajl2/vendored/src/api/yajl_common.h +0 -75
  61. data/ext/libyajl2/vendored/src/api/yajl_gen.h +0 -157
  62. data/ext/libyajl2/vendored/src/api/yajl_parse.h +0 -226
  63. data/ext/libyajl2/vendored/src/api/yajl_tree.h +0 -185
  64. data/ext/libyajl2/vendored/src/api/yajl_version.h.cmake +0 -23
  65. data/ext/libyajl2/vendored/src/yajl +0 -33
  66. data/ext/libyajl2/vendored/src/yajl.c +0 -175
  67. data/ext/libyajl2/vendored/src/yajl.pc.cmake +0 -9
  68. data/ext/libyajl2/vendored/src/yajl_alloc.c +0 -52
  69. data/ext/libyajl2/vendored/src/yajl_alloc.h +0 -34
  70. data/ext/libyajl2/vendored/src/yajl_buf.c +0 -103
  71. data/ext/libyajl2/vendored/src/yajl_buf.h +0 -57
  72. data/ext/libyajl2/vendored/src/yajl_bytestack.h +0 -69
  73. data/ext/libyajl2/vendored/src/yajl_encode.c +0 -220
  74. data/ext/libyajl2/vendored/src/yajl_encode.h +0 -34
  75. data/ext/libyajl2/vendored/src/yajl_gen.c +0 -354
  76. data/ext/libyajl2/vendored/src/yajl_lex.c +0 -763
  77. data/ext/libyajl2/vendored/src/yajl_lex.h +0 -117
  78. data/ext/libyajl2/vendored/src/yajl_parser.c +0 -498
  79. data/ext/libyajl2/vendored/src/yajl_parser.h +0 -78
  80. data/ext/libyajl2/vendored/src/yajl_tree.c +0 -503
  81. data/ext/libyajl2/vendored/src/yajl_version.c +0 -7
  82. data/ext/libyajl2/vendored/test/CMakeLists.txt +0 -23
  83. data/ext/libyajl2/vendored/test/cases/ac_difficult_json_c_test_case_with_comments.json +0 -1
  84. data/ext/libyajl2/vendored/test/cases/ac_difficult_json_c_test_case_with_comments.json.gold +0 -36
  85. data/ext/libyajl2/vendored/test/cases/ac_simple_with_comments.json +0 -11
  86. data/ext/libyajl2/vendored/test/cases/ac_simple_with_comments.json.gold +0 -9
  87. data/ext/libyajl2/vendored/test/cases/ag_false_then_garbage.json +0 -1
  88. data/ext/libyajl2/vendored/test/cases/ag_false_then_garbage.json.gold +0 -2
  89. data/ext/libyajl2/vendored/test/cases/ag_null_then_garbage.json +0 -1
  90. data/ext/libyajl2/vendored/test/cases/ag_null_then_garbage.json.gold +0 -2
  91. data/ext/libyajl2/vendored/test/cases/ag_true_then_garbage.json +0 -1
  92. data/ext/libyajl2/vendored/test/cases/ag_true_then_garbage.json.gold +0 -2
  93. data/ext/libyajl2/vendored/test/cases/am_eof.json +0 -1
  94. data/ext/libyajl2/vendored/test/cases/am_eof.json.gold +0 -4
  95. data/ext/libyajl2/vendored/test/cases/am_integers.json +0 -1
  96. data/ext/libyajl2/vendored/test/cases/am_integers.json.gold +0 -3
  97. data/ext/libyajl2/vendored/test/cases/am_multiple.json +0 -3
  98. data/ext/libyajl2/vendored/test/cases/am_multiple.json.gold +0 -5
  99. data/ext/libyajl2/vendored/test/cases/am_stuff.json +0 -7
  100. data/ext/libyajl2/vendored/test/cases/am_stuff.json.gold +0 -14
  101. data/ext/libyajl2/vendored/test/cases/ap_array_open.json +0 -1
  102. data/ext/libyajl2/vendored/test/cases/ap_array_open.json.gold +0 -2
  103. data/ext/libyajl2/vendored/test/cases/ap_eof_str.json +0 -1
  104. data/ext/libyajl2/vendored/test/cases/ap_eof_str.json.gold +0 -1
  105. data/ext/libyajl2/vendored/test/cases/ap_map_open.json +0 -1
  106. data/ext/libyajl2/vendored/test/cases/ap_map_open.json.gold +0 -2
  107. data/ext/libyajl2/vendored/test/cases/ap_partial_ok.json +0 -1
  108. data/ext/libyajl2/vendored/test/cases/ap_partial_ok.json.gold +0 -4
  109. data/ext/libyajl2/vendored/test/cases/array.json +0 -6
  110. data/ext/libyajl2/vendored/test/cases/array.json.gold +0 -22
  111. data/ext/libyajl2/vendored/test/cases/array_close.json +0 -1
  112. data/ext/libyajl2/vendored/test/cases/array_close.json.gold +0 -2
  113. data/ext/libyajl2/vendored/test/cases/bignums.json +0 -1
  114. data/ext/libyajl2/vendored/test/cases/bignums.json.gold +0 -5
  115. data/ext/libyajl2/vendored/test/cases/bogus_char.json +0 -4
  116. data/ext/libyajl2/vendored/test/cases/bogus_char.json.gold +0 -10
  117. data/ext/libyajl2/vendored/test/cases/codepoints_from_unicode_org.json +0 -1
  118. data/ext/libyajl2/vendored/test/cases/codepoints_from_unicode_org.json.gold +0 -2
  119. data/ext/libyajl2/vendored/test/cases/deep_arrays.json +0 -1
  120. data/ext/libyajl2/vendored/test/cases/deep_arrays.json.gold +0 -2049
  121. data/ext/libyajl2/vendored/test/cases/difficult_json_c_test_case.json +0 -1
  122. data/ext/libyajl2/vendored/test/cases/difficult_json_c_test_case.json.gold +0 -36
  123. data/ext/libyajl2/vendored/test/cases/doubles.json +0 -1
  124. data/ext/libyajl2/vendored/test/cases/doubles.json.gold +0 -7
  125. data/ext/libyajl2/vendored/test/cases/doubles_in_array.json +0 -1
  126. data/ext/libyajl2/vendored/test/cases/doubles_in_array.json.gold +0 -8
  127. data/ext/libyajl2/vendored/test/cases/empty_array.json +0 -1
  128. data/ext/libyajl2/vendored/test/cases/empty_array.json.gold +0 -3
  129. data/ext/libyajl2/vendored/test/cases/empty_string.json +0 -1
  130. data/ext/libyajl2/vendored/test/cases/empty_string.json.gold +0 -2
  131. data/ext/libyajl2/vendored/test/cases/escaped_bulgarian.json +0 -4
  132. data/ext/libyajl2/vendored/test/cases/escaped_bulgarian.json.gold +0 -7
  133. data/ext/libyajl2/vendored/test/cases/escaped_foobar.json +0 -1
  134. data/ext/libyajl2/vendored/test/cases/escaped_foobar.json.gold +0 -2
  135. data/ext/libyajl2/vendored/test/cases/false.json +0 -1
  136. data/ext/libyajl2/vendored/test/cases/false.json.gold +0 -2
  137. data/ext/libyajl2/vendored/test/cases/fg_false_then_garbage.json +0 -1
  138. data/ext/libyajl2/vendored/test/cases/fg_false_then_garbage.json.gold +0 -3
  139. data/ext/libyajl2/vendored/test/cases/fg_issue_7.json +0 -1
  140. data/ext/libyajl2/vendored/test/cases/fg_issue_7.json.gold +0 -3
  141. data/ext/libyajl2/vendored/test/cases/fg_null_then_garbage.json +0 -1
  142. data/ext/libyajl2/vendored/test/cases/fg_null_then_garbage.json.gold +0 -3
  143. data/ext/libyajl2/vendored/test/cases/fg_true_then_garbage.json +0 -1
  144. data/ext/libyajl2/vendored/test/cases/fg_true_then_garbage.json.gold +0 -3
  145. data/ext/libyajl2/vendored/test/cases/four_byte_utf8.json +0 -2
  146. data/ext/libyajl2/vendored/test/cases/four_byte_utf8.json.gold +0 -5
  147. data/ext/libyajl2/vendored/test/cases/high_overflow.json +0 -1
  148. data/ext/libyajl2/vendored/test/cases/high_overflow.json.gold +0 -2
  149. data/ext/libyajl2/vendored/test/cases/integers.json +0 -3
  150. data/ext/libyajl2/vendored/test/cases/integers.json.gold +0 -14
  151. data/ext/libyajl2/vendored/test/cases/invalid_utf8.json +0 -1
  152. data/ext/libyajl2/vendored/test/cases/invalid_utf8.json.gold +0 -3
  153. data/ext/libyajl2/vendored/test/cases/isolated_surrogate_marker.json +0 -1
  154. data/ext/libyajl2/vendored/test/cases/isolated_surrogate_marker.json.gold +0 -2
  155. data/ext/libyajl2/vendored/test/cases/leading_zero_in_number.json +0 -1
  156. data/ext/libyajl2/vendored/test/cases/leading_zero_in_number.json.gold +0 -5
  157. data/ext/libyajl2/vendored/test/cases/lonely_minus_sign.json +0 -7
  158. data/ext/libyajl2/vendored/test/cases/lonely_minus_sign.json.gold +0 -9
  159. data/ext/libyajl2/vendored/test/cases/lonely_number.json +0 -1
  160. data/ext/libyajl2/vendored/test/cases/lonely_number.json.gold +0 -2
  161. data/ext/libyajl2/vendored/test/cases/low_overflow.json +0 -1
  162. data/ext/libyajl2/vendored/test/cases/low_overflow.json.gold +0 -2
  163. data/ext/libyajl2/vendored/test/cases/map_close.json +0 -1
  164. data/ext/libyajl2/vendored/test/cases/map_close.json.gold +0 -2
  165. data/ext/libyajl2/vendored/test/cases/missing_integer_after_decimal_point.json +0 -1
  166. data/ext/libyajl2/vendored/test/cases/missing_integer_after_decimal_point.json.gold +0 -2
  167. data/ext/libyajl2/vendored/test/cases/missing_integer_after_exponent.json +0 -1
  168. data/ext/libyajl2/vendored/test/cases/missing_integer_after_exponent.json.gold +0 -2
  169. data/ext/libyajl2/vendored/test/cases/multiple.json +0 -3
  170. data/ext/libyajl2/vendored/test/cases/multiple.json.gold +0 -4
  171. data/ext/libyajl2/vendored/test/cases/non_utf8_char_in_string.json +0 -1
  172. data/ext/libyajl2/vendored/test/cases/non_utf8_char_in_string.json.gold +0 -8
  173. data/ext/libyajl2/vendored/test/cases/np_partial_bad.json +0 -1
  174. data/ext/libyajl2/vendored/test/cases/np_partial_bad.json.gold +0 -5
  175. data/ext/libyajl2/vendored/test/cases/null.json +0 -1
  176. data/ext/libyajl2/vendored/test/cases/null.json.gold +0 -2
  177. data/ext/libyajl2/vendored/test/cases/nulls_and_bools.json +0 -5
  178. data/ext/libyajl2/vendored/test/cases/nulls_and_bools.json.gold +0 -9
  179. data/ext/libyajl2/vendored/test/cases/simple.json +0 -5
  180. data/ext/libyajl2/vendored/test/cases/simple.json.gold +0 -9
  181. data/ext/libyajl2/vendored/test/cases/simple_with_comments.json +0 -11
  182. data/ext/libyajl2/vendored/test/cases/simple_with_comments.json.gold +0 -5
  183. data/ext/libyajl2/vendored/test/cases/string_invalid_escape.json +0 -1
  184. data/ext/libyajl2/vendored/test/cases/string_invalid_escape.json.gold +0 -3
  185. data/ext/libyajl2/vendored/test/cases/string_invalid_hex_char.json +0 -1
  186. data/ext/libyajl2/vendored/test/cases/string_invalid_hex_char.json.gold +0 -2
  187. data/ext/libyajl2/vendored/test/cases/string_with_escapes.json +0 -3
  188. data/ext/libyajl2/vendored/test/cases/string_with_escapes.json.gold +0 -7
  189. data/ext/libyajl2/vendored/test/cases/string_with_invalid_newline.json +0 -2
  190. data/ext/libyajl2/vendored/test/cases/string_with_invalid_newline.json.gold +0 -2
  191. data/ext/libyajl2/vendored/test/cases/three_byte_utf8.json +0 -1
  192. data/ext/libyajl2/vendored/test/cases/three_byte_utf8.json.gold +0 -7
  193. data/ext/libyajl2/vendored/test/cases/true.json +0 -1
  194. data/ext/libyajl2/vendored/test/cases/true.json.gold +0 -2
  195. data/ext/libyajl2/vendored/test/cases/unescaped_bulgarian.json +0 -1
  196. data/ext/libyajl2/vendored/test/cases/unescaped_bulgarian.json.gold +0 -4
  197. data/ext/libyajl2/vendored/test/cases/zerobyte.json +0 -1
  198. data/ext/libyajl2/vendored/test/cases/zerobyte.json.gold +0 -0
  199. data/ext/libyajl2/vendored/test/run_tests.sh +0 -94
  200. data/ext/libyajl2/vendored/test/yajl_test.c +0 -281
  201. data/ext/libyajl2/vendored/verify/CMakeLists.txt +0 -39
  202. data/ext/libyajl2/vendored/verify/json_verify.c +0 -116
  203. data/lib/ffi_yajl/json_gem.rb +0 -121
  204. data/lib/libyajl.so +0 -0
  205. data/lib/libyajl.so.2 +0 -0
  206. data/lib/libyajl.so.2.0.5 +0 -0
  207. data/lib/libyajl_s.a +0 -0
  208. data/spec/ffi_yajl/encoder_spec.rb +0 -39
  209. data/spec/ffi_yajl/json_gem_spec.rb +0 -355
  210. data/spec/ffi_yajl/parser_spec.rb +0 -78
  211. data/spec/spec_helper.rb +0 -14
@@ -1,281 +0,0 @@
1
- /*
2
- * Copyright (c) 2007-2011, Lloyd Hilaiel <lloyd@hilaiel.com>
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
- #include <assert.h>
25
-
26
- /* memory debugging routines */
27
- typedef struct
28
- {
29
- unsigned int numFrees;
30
- unsigned int numMallocs;
31
- /* XXX: we really need a hash table here with per-allocation
32
- * information */
33
- } yajlTestMemoryContext;
34
-
35
- /* cast void * into context */
36
- #define TEST_CTX(vptr) ((yajlTestMemoryContext *) (vptr))
37
-
38
- static void yajlTestFree(void * ctx, void * ptr)
39
- {
40
- assert(ptr != NULL);
41
- TEST_CTX(ctx)->numFrees++;
42
- free(ptr);
43
- }
44
-
45
- static void * yajlTestMalloc(void * ctx, size_t sz)
46
- {
47
- assert(sz != 0);
48
- TEST_CTX(ctx)->numMallocs++;
49
- return malloc(sz);
50
- }
51
-
52
- static void * yajlTestRealloc(void * ctx, void * ptr, size_t sz)
53
- {
54
- if (ptr == NULL) {
55
- assert(sz != 0);
56
- TEST_CTX(ctx)->numMallocs++;
57
- } else if (sz == 0) {
58
- TEST_CTX(ctx)->numFrees++;
59
- }
60
-
61
- return realloc(ptr, sz);
62
- }
63
-
64
-
65
- /* begin parsing callback routines */
66
- #define BUF_SIZE 2048
67
-
68
- static int test_yajl_null(void *ctx)
69
- {
70
- printf("null\n");
71
- return 1;
72
- }
73
-
74
- static int test_yajl_boolean(void * ctx, int boolVal)
75
- {
76
- printf("bool: %s\n", boolVal ? "true" : "false");
77
- return 1;
78
- }
79
-
80
- static int test_yajl_integer(void *ctx, long long integerVal)
81
- {
82
- printf("integer: %lld\n", integerVal);
83
- return 1;
84
- }
85
-
86
- static int test_yajl_double(void *ctx, double doubleVal)
87
- {
88
- printf("double: %g\n", doubleVal);
89
- return 1;
90
- }
91
-
92
- static int test_yajl_string(void *ctx, const unsigned char * stringVal,
93
- size_t stringLen)
94
- {
95
- printf("string: '");
96
- fwrite(stringVal, 1, stringLen, stdout);
97
- printf("'\n");
98
- return 1;
99
- }
100
-
101
- static int test_yajl_map_key(void *ctx, const unsigned char * stringVal,
102
- size_t stringLen)
103
- {
104
- char * str = (char *) malloc(stringLen + 1);
105
- str[stringLen] = 0;
106
- memcpy(str, stringVal, stringLen);
107
- printf("key: '%s'\n", str);
108
- free(str);
109
- return 1;
110
- }
111
-
112
- static int test_yajl_start_map(void *ctx)
113
- {
114
- printf("map open '{'\n");
115
- return 1;
116
- }
117
-
118
-
119
- static int test_yajl_end_map(void *ctx)
120
- {
121
- printf("map close '}'\n");
122
- return 1;
123
- }
124
-
125
- static int test_yajl_start_array(void *ctx)
126
- {
127
- printf("array open '['\n");
128
- return 1;
129
- }
130
-
131
- static int test_yajl_end_array(void *ctx)
132
- {
133
- printf("array close ']'\n");
134
- return 1;
135
- }
136
-
137
- static yajl_callbacks callbacks = {
138
- test_yajl_null,
139
- test_yajl_boolean,
140
- test_yajl_integer,
141
- test_yajl_double,
142
- NULL,
143
- test_yajl_string,
144
- test_yajl_start_map,
145
- test_yajl_map_key,
146
- test_yajl_end_map,
147
- test_yajl_start_array,
148
- test_yajl_end_array
149
- };
150
-
151
- static void usage(const char * progname)
152
- {
153
- fprintf(stderr,
154
- "usage: %s [options]\n"
155
- "Parse input from stdin as JSON and ouput parsing details "
156
- "to stdout\n"
157
- " -b set the read buffer size\n"
158
- " -c allow comments\n"
159
- " -g allow *g*arbage after valid JSON text\n"
160
- " -m allows the parser to consume multiple JSON values\n"
161
- " from a single string separated by whitespace\n"
162
- " -p partial JSON documents should not cause errors\n",
163
- progname);
164
- exit(1);
165
- }
166
-
167
- int
168
- main(int argc, char ** argv)
169
- {
170
- yajl_handle hand;
171
- const char * fileName;
172
- static unsigned char * fileData = NULL;
173
- size_t bufSize = BUF_SIZE;
174
- yajl_status stat;
175
- size_t rd;
176
- int i, j;
177
-
178
- /* memory allocation debugging: allocate a structure which collects
179
- * statistics */
180
- yajlTestMemoryContext memCtx = { 0,0 };
181
-
182
- /* memory allocation debugging: allocate a structure which holds
183
- * allocation routines */
184
- yajl_alloc_funcs allocFuncs = {
185
- yajlTestMalloc,
186
- yajlTestRealloc,
187
- yajlTestFree,
188
- (void *) NULL
189
- };
190
-
191
- allocFuncs.ctx = (void *) &memCtx;
192
-
193
- /* allocate the parser */
194
- hand = yajl_alloc(&callbacks, &allocFuncs, NULL);
195
-
196
- /* check arguments. We expect exactly one! */
197
- for (i=1;i<argc;i++) {
198
- if (!strcmp("-c", argv[i])) {
199
- yajl_config(hand, yajl_allow_comments, 1);
200
- } else if (!strcmp("-b", argv[i])) {
201
- if (++i >= argc) usage(argv[0]);
202
-
203
- /* validate integer */
204
- for (j=0;j<(int)strlen(argv[i]);j++) {
205
- if (argv[i][j] <= '9' && argv[i][j] >= '0') continue;
206
- fprintf(stderr, "-b requires an integer argument. '%s' "
207
- "is invalid\n", argv[i]);
208
- usage(argv[0]);
209
- }
210
-
211
- bufSize = atoi(argv[i]);
212
- if (!bufSize) {
213
- fprintf(stderr, "%zu is an invalid buffer size\n",
214
- bufSize);
215
- }
216
- } else if (!strcmp("-g", argv[i])) {
217
- yajl_config(hand, yajl_allow_trailing_garbage, 1);
218
- } else if (!strcmp("-m", argv[i])) {
219
- yajl_config(hand, yajl_allow_multiple_values, 1);
220
- } else if (!strcmp("-p", argv[i])) {
221
- yajl_config(hand, yajl_allow_partial_values, 1);
222
- } else {
223
- fprintf(stderr, "invalid command line option: '%s'\n",
224
- argv[i]);
225
- usage(argv[0]);
226
- }
227
- }
228
-
229
- fileData = (unsigned char *) malloc(bufSize);
230
-
231
- if (fileData == NULL) {
232
- fprintf(stderr,
233
- "failed to allocate read buffer of %zu bytes, exiting.",
234
- bufSize);
235
- yajl_free(hand);
236
- exit(2);
237
- }
238
-
239
- fileName = argv[argc-1];
240
-
241
- for (;;) {
242
- rd = fread((void *) fileData, 1, bufSize, stdin);
243
-
244
- if (rd == 0) {
245
- if (!feof(stdin)) {
246
- fprintf(stderr, "error reading from '%s'\n", fileName);
247
- }
248
- break;
249
- }
250
- /* read file data, now pass to parser */
251
- stat = yajl_parse(hand, fileData, rd);
252
-
253
- if (stat != yajl_status_ok) break;
254
- }
255
-
256
- stat = yajl_complete_parse(hand);
257
- if (stat != yajl_status_ok)
258
- {
259
- unsigned char * str = yajl_get_error(hand, 0, fileData, rd);
260
- fflush(stdout);
261
- fprintf(stderr, "%s", (char *) str);
262
- yajl_free_error(hand, str);
263
- }
264
-
265
- yajl_free(hand);
266
- free(fileData);
267
-
268
- /* finally, print out some memory statistics */
269
-
270
- /* (lth) only print leaks here, as allocations and frees may vary depending
271
- * on read buffer size, causing false failures.
272
- *
273
- * printf("allocations:\t%u\n", memCtx.numMallocs);
274
- * printf("frees:\t\t%u\n", memCtx.numFrees);
275
- */
276
- fflush(stderr);
277
- fflush(stdout);
278
- printf("memory leaks:\t%u\n", memCtx.numMallocs - memCtx.numFrees);
279
-
280
- return 0;
281
- }
@@ -1,39 +0,0 @@
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
- # set up some paths
16
- SET (binDir ${CMAKE_CURRENT_BINARY_DIR}/../${YAJL_DIST_NAME}/bin)
17
-
18
- # create some directories
19
- FILE(MAKE_DIRECTORY ${binDir})
20
-
21
- SET (SRCS json_verify.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_verify ${SRCS})
28
-
29
- TARGET_LINK_LIBRARIES(json_verify yajl_s)
30
-
31
- # copy in the binary
32
- GET_TARGET_PROPERTY(binPath json_verify LOCATION)
33
-
34
- ADD_CUSTOM_COMMAND(TARGET json_verify POST_BUILD
35
- COMMAND ${CMAKE_COMMAND} -E copy_if_different ${binPath} ${binDir})
36
-
37
- IF (NOT WIN32)
38
- INSTALL(TARGETS json_verify RUNTIME DESTINATION bin)
39
- ENDIF ()
@@ -1,116 +0,0 @@
1
- /*
2
- * Copyright (c) 2007-2011, Lloyd Hilaiel <lloyd@hilaiel.com>
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
-
19
- #include <stdio.h>
20
- #include <stdlib.h>
21
- #include <string.h>
22
-
23
- static void
24
- usage(const char * progname)
25
- {
26
- fprintf(stderr, "%s: validate json from stdin\n"
27
- "usage: json_verify [options]\n"
28
- " -q quiet mode\n"
29
- " -c allow comments\n"
30
- " -u allow invalid utf8 inside strings\n",
31
- progname);
32
- exit(1);
33
- }
34
-
35
- int
36
- main(int argc, char ** argv)
37
- {
38
- yajl_status stat;
39
- size_t rd;
40
- yajl_handle hand;
41
- static unsigned char fileData[65536];
42
- int quiet = 0;
43
- int retval = 0;
44
- int a = 1;
45
-
46
- /* allocate a parser */
47
- hand = yajl_alloc(NULL, NULL, NULL);
48
-
49
- /* check arguments.*/
50
- while ((a < argc) && (argv[a][0] == '-') && (strlen(argv[a]) > 1)) {
51
- unsigned int i;
52
- for ( i=1; i < strlen(argv[a]); i++) {
53
- switch (argv[a][i]) {
54
- case 'q':
55
- quiet = 1;
56
- break;
57
- case 'c':
58
- yajl_config(hand, yajl_allow_comments, 1);
59
- break;
60
- case 'u':
61
- yajl_config(hand, yajl_dont_validate_strings, 1);
62
- break;
63
- default:
64
- fprintf(stderr, "unrecognized option: '%c'\n\n", argv[a][i]);
65
- usage(argv[0]);
66
- }
67
- }
68
- ++a;
69
- }
70
- if (a < argc) {
71
- usage(argv[0]);
72
- }
73
-
74
- for (;;) {
75
- rd = fread((void *) fileData, 1, sizeof(fileData) - 1, stdin);
76
-
77
- retval = 0;
78
-
79
- if (rd == 0) {
80
- if (!feof(stdin)) {
81
- if (!quiet) {
82
- fprintf(stderr, "error encountered on file read\n");
83
- }
84
- retval = 1;
85
- }
86
- break;
87
- }
88
- fileData[rd] = 0;
89
-
90
- /* read file data, pass to parser */
91
- stat = yajl_parse(hand, fileData, rd);
92
-
93
- if (stat != yajl_status_ok) break;
94
- }
95
-
96
- /* parse any remaining buffered data */
97
- stat = yajl_complete_parse(hand);
98
-
99
- if (stat != yajl_status_ok)
100
- {
101
- if (!quiet) {
102
- unsigned char * str = yajl_get_error(hand, 1, fileData, rd);
103
- fprintf(stderr, "%s", (const char *) str);
104
- yajl_free_error(hand, str);
105
- }
106
- retval = 1;
107
- }
108
-
109
- yajl_free(hand);
110
-
111
- if (!quiet) {
112
- printf("JSON is %s\n", retval ? "invalid" : "valid");
113
- }
114
-
115
- return retval;
116
- }
@@ -1,121 +0,0 @@
1
-
2
- # JSON compatibility layer, largely plagarized from yajl-ruby
3
-
4
- require 'ffi_yajl' unless defined?(FFI_Yajl::Parser)
5
-
6
- module JSON
7
- class JSONError < StandardError; end unless defined?(JSON::JSONError)
8
- class GeneratorError < JSONError; end unless defined?(JSON::GeneratorError)
9
- class ParserError < JSONError; end unless defined?(JSON::ParserError)
10
-
11
- def self.generate(obj, opts=nil)
12
- opts ||= {}
13
- options_map = {}
14
- if opts.has_key?(:indent)
15
- options_map[:pretty] = true
16
- options_map[:indent] = opts[:indent]
17
- end
18
- FFI_Yajl::Encoder.encode(obj, options_map)
19
- rescue FFI_Yajl::EncodeError => e
20
- raise JSON::GeneratorError, e.message
21
- end
22
-
23
- def self.pretty_generate(obj, opts={})
24
- options_map = {}
25
- options_map[:pretty] = true
26
- options_map[:indent] = opts[:indent] if opts.has_key?(:indent)
27
- FFI_Yajl::Encoder.encode(obj, options_map).chomp
28
- rescue FFI_Yajl::EncodeError => e
29
- raise JSON::GeneratorError, e.message
30
- end
31
-
32
- def self.dump(obj, io=nil, *args)
33
- FFI_Yajl::Encoder.encode(obj, io)
34
- rescue FFI_Yajl::EncodeError => e
35
- raise JSON::GeneratorError, e.message
36
- end
37
-
38
- def self.default_options
39
- #@default_options ||= {:symbolize_keys => false}
40
- @default_options ||= {}
41
- end
42
-
43
- def self.parse(str, opts=JSON.default_options)
44
- FFI_Yajl::Parser.parse(str, opts)
45
- rescue FFI_Yajl::ParseError => e
46
- raise JSON::ParserError, e.message
47
- end
48
-
49
- def self.load(input, *args)
50
- FFI_Yajl::Parser.parse(input, default_options)
51
- rescue FFI_Yajl::ParseError => e
52
- raise JSON::ParserError, e.message
53
- end
54
- end
55
-
56
- class Array
57
- def to_json(*opts, &block)
58
- FFI_Yajl::Encoder.encode(self)
59
- end
60
- end
61
-
62
- class Hash
63
- def to_json(*opts, &block)
64
- FFI_Yajl::Encoder.encode(self)
65
- end
66
- end
67
-
68
- class Fixnum
69
- def to_json(*opts, &block)
70
- FFI_Yajl::Encoder.encode(self)
71
- end
72
- end
73
-
74
- class Float
75
- def to_json(*opts, &block)
76
- FFI_Yajl::Encoder.encode(self)
77
- end
78
- end
79
-
80
- class String
81
- def to_json(*opts, &block)
82
- FFI_Yajl::Encoder.encode(self)
83
- end
84
- end
85
-
86
- class TrueClass
87
- def to_json(*opts, &block)
88
- FFI_Yajl::Encoder.encode(self)
89
- end
90
- end
91
-
92
- class FalseClass
93
- def to_json(*opts, &block)
94
- FFI_Yajl::Encoder.encode(self)
95
- end
96
- end
97
-
98
- class NilClass
99
- def to_json(*opts, &block)
100
- FFI_Yajl::Encoder.encode(self)
101
- end
102
- end
103
-
104
- module ::Kernel
105
- def JSON(object, opts = {})
106
- if object.respond_to? :to_s
107
- JSON.parse(object.to_s, JSON.default_options.merge(opts))
108
- else
109
- JSON.generate(object,opts)
110
- end
111
- end
112
- end
113
-
114
- class Object
115
- unless defined?(ActiveSupport)
116
- def to_json(*args, &block)
117
- "\"#{to_s}\""
118
- end
119
- end
120
- end
121
-
data/lib/libyajl.so DELETED
Binary file
data/lib/libyajl.so.2 DELETED
Binary file
data/lib/libyajl.so.2.0.5 DELETED
Binary file
data/lib/libyajl_s.a DELETED
Binary file
@@ -1,39 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- require 'spec_helper'
4
-
5
- describe "FFI_Yajl::Encoder" do
6
-
7
- let(:encoder) { FFI_Yajl::Encoder.new }
8
-
9
- it "encodes fixnums in keys as strings" do
10
- ruby = {1 => 2}
11
- expect(encoder.encode(ruby)).to eq('{"1":2}')
12
- end
13
-
14
- it "encodes floats in keys as strings" do
15
- ruby = {1.1 => 2}
16
- expect(encoder.encode(ruby)).to eq('{"1.1":2}')
17
- end
18
-
19
- it "encodes bignums in keys as strings" do
20
- ruby = {12345678901234567890 => 2}
21
- expect(encoder.encode(ruby)).to eq('{"12345678901234567890":2}')
22
- end
23
-
24
- # XXX: 127 == YAJL_MAX_DEPTH hardcodedness, zero control for us, it isn't even a twiddleable #define
25
- it "raises an exception for deeply nested arrays" do
26
- root = []
27
- a = root
28
- 127.times { |_| a << []; a = a[0] }
29
- expect{ encoder.encode(root) }.to raise_error(FFI_Yajl::EncodeError)
30
- end
31
-
32
- it "raises an exception for deeply nested hashes" do
33
- root = {}
34
- a = root
35
- 127.times {|_| a["a"] = {}; a = a["a"] }
36
- expect{ encoder.encode(root) }.to raise_error(FFI_Yajl::EncodeError)
37
- end
38
- end
39
-