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.
- checksums.yaml +5 -5
- data/LICENSE +21 -201
- data/README.md +105 -10
- data/bin/ffi-yajl-bench +11 -11
- data/ext/ffi_yajl/ext/dlopen/dlopen.c +40 -0
- data/ext/ffi_yajl/ext/dlopen/extconf.rb +16 -0
- data/ext/ffi_yajl/ext/dlopen/yajl.sym +18 -0
- data/ext/ffi_yajl/ext/encoder/encoder.c +270 -115
- data/ext/ffi_yajl/ext/encoder/extconf.rb +71 -14
- data/ext/ffi_yajl/ext/parser/extconf.rb +71 -14
- data/ext/ffi_yajl/ext/parser/parser.c +85 -44
- data/lib/ffi_yajl/benchmark/encode.rb +39 -92
- data/lib/ffi_yajl/benchmark/encode_json_and_marshal.rb +23 -23
- data/lib/ffi_yajl/benchmark/encode_json_and_yaml.rb +24 -30
- data/lib/ffi_yajl/benchmark/encode_profile.rb +15 -19
- data/lib/ffi_yajl/benchmark/http.rb +21 -25
- data/lib/ffi_yajl/benchmark/parse.rb +77 -117
- data/lib/ffi_yajl/benchmark/parse_json_and_marshal.rb +27 -27
- data/lib/ffi_yajl/benchmark/parse_json_and_yaml.rb +30 -30
- data/lib/ffi_yajl/benchmark/parse_profile.rb +14 -18
- data/lib/ffi_yajl/benchmark/parse_profile_ruby_prof.rb +14 -19
- data/lib/ffi_yajl/benchmark/parse_stream.rb +28 -28
- data/lib/ffi_yajl/benchmark.rb +26 -6
- data/lib/ffi_yajl/encoder.rb +47 -6
- data/lib/ffi_yajl/ext.rb +37 -10
- data/lib/ffi_yajl/ffi/encoder.rb +150 -63
- data/lib/ffi_yajl/ffi/parser.rb +82 -64
- data/lib/ffi_yajl/ffi.rb +70 -46
- data/lib/ffi_yajl/map_library_name.rb +109 -0
- data/lib/ffi_yajl/parser.rb +69 -1
- data/lib/ffi_yajl/platform.rb +29 -0
- data/lib/ffi_yajl/version.rb +23 -1
- data/lib/ffi_yajl.rb +44 -8
- metadata +25 -238
- data/Rakefile +0 -62
- data/ext/libyajl2/extconf.rb +0 -65
- data/ext/libyajl2/vendored/.git +0 -1
- data/ext/libyajl2/vendored/.gitignore +0 -3
- data/ext/libyajl2/vendored/BUILDING +0 -23
- data/ext/libyajl2/vendored/BUILDING.win32 +0 -27
- data/ext/libyajl2/vendored/CMakeLists.txt +0 -79
- data/ext/libyajl2/vendored/COPYING +0 -13
- data/ext/libyajl2/vendored/ChangeLog +0 -175
- data/ext/libyajl2/vendored/README +0 -74
- data/ext/libyajl2/vendored/TODO +0 -9
- data/ext/libyajl2/vendored/YAJLDoc.cmake +0 -26
- data/ext/libyajl2/vendored/configure +0 -79
- data/ext/libyajl2/vendored/example/CMakeLists.txt +0 -23
- data/ext/libyajl2/vendored/example/README.md +0 -7
- data/ext/libyajl2/vendored/example/parse_config.c +0 -69
- data/ext/libyajl2/vendored/example/sample.config +0 -101
- data/ext/libyajl2/vendored/perf/CMakeLists.txt +0 -23
- data/ext/libyajl2/vendored/perf/documents.c +0 -1418
- data/ext/libyajl2/vendored/perf/documents.h +0 -28
- data/ext/libyajl2/vendored/perf/perftest.c +0 -134
- data/ext/libyajl2/vendored/reformatter/CMakeLists.txt +0 -39
- data/ext/libyajl2/vendored/reformatter/json_reformat.c +0 -194
- data/ext/libyajl2/vendored/src/CMakeLists.txt +0 -86
- data/ext/libyajl2/vendored/src/YAJL.dxy +0 -1258
- data/ext/libyajl2/vendored/src/api/yajl_common.h +0 -75
- data/ext/libyajl2/vendored/src/api/yajl_gen.h +0 -157
- data/ext/libyajl2/vendored/src/api/yajl_parse.h +0 -226
- data/ext/libyajl2/vendored/src/api/yajl_tree.h +0 -185
- data/ext/libyajl2/vendored/src/api/yajl_version.h.cmake +0 -23
- data/ext/libyajl2/vendored/src/yajl +0 -33
- data/ext/libyajl2/vendored/src/yajl.c +0 -175
- data/ext/libyajl2/vendored/src/yajl.pc.cmake +0 -9
- data/ext/libyajl2/vendored/src/yajl_alloc.c +0 -52
- data/ext/libyajl2/vendored/src/yajl_alloc.h +0 -34
- data/ext/libyajl2/vendored/src/yajl_buf.c +0 -103
- data/ext/libyajl2/vendored/src/yajl_buf.h +0 -57
- data/ext/libyajl2/vendored/src/yajl_bytestack.h +0 -69
- data/ext/libyajl2/vendored/src/yajl_encode.c +0 -220
- data/ext/libyajl2/vendored/src/yajl_encode.h +0 -34
- data/ext/libyajl2/vendored/src/yajl_gen.c +0 -354
- data/ext/libyajl2/vendored/src/yajl_lex.c +0 -763
- data/ext/libyajl2/vendored/src/yajl_lex.h +0 -117
- data/ext/libyajl2/vendored/src/yajl_parser.c +0 -498
- data/ext/libyajl2/vendored/src/yajl_parser.h +0 -78
- data/ext/libyajl2/vendored/src/yajl_tree.c +0 -503
- data/ext/libyajl2/vendored/src/yajl_version.c +0 -7
- data/ext/libyajl2/vendored/test/CMakeLists.txt +0 -23
- data/ext/libyajl2/vendored/test/cases/ac_difficult_json_c_test_case_with_comments.json +0 -1
- data/ext/libyajl2/vendored/test/cases/ac_difficult_json_c_test_case_with_comments.json.gold +0 -36
- data/ext/libyajl2/vendored/test/cases/ac_simple_with_comments.json +0 -11
- data/ext/libyajl2/vendored/test/cases/ac_simple_with_comments.json.gold +0 -9
- data/ext/libyajl2/vendored/test/cases/ag_false_then_garbage.json +0 -1
- data/ext/libyajl2/vendored/test/cases/ag_false_then_garbage.json.gold +0 -2
- data/ext/libyajl2/vendored/test/cases/ag_null_then_garbage.json +0 -1
- data/ext/libyajl2/vendored/test/cases/ag_null_then_garbage.json.gold +0 -2
- data/ext/libyajl2/vendored/test/cases/ag_true_then_garbage.json +0 -1
- data/ext/libyajl2/vendored/test/cases/ag_true_then_garbage.json.gold +0 -2
- data/ext/libyajl2/vendored/test/cases/am_eof.json +0 -1
- data/ext/libyajl2/vendored/test/cases/am_eof.json.gold +0 -4
- data/ext/libyajl2/vendored/test/cases/am_integers.json +0 -1
- data/ext/libyajl2/vendored/test/cases/am_integers.json.gold +0 -3
- data/ext/libyajl2/vendored/test/cases/am_multiple.json +0 -3
- data/ext/libyajl2/vendored/test/cases/am_multiple.json.gold +0 -5
- data/ext/libyajl2/vendored/test/cases/am_stuff.json +0 -7
- data/ext/libyajl2/vendored/test/cases/am_stuff.json.gold +0 -14
- data/ext/libyajl2/vendored/test/cases/ap_array_open.json +0 -1
- data/ext/libyajl2/vendored/test/cases/ap_array_open.json.gold +0 -2
- data/ext/libyajl2/vendored/test/cases/ap_eof_str.json +0 -1
- data/ext/libyajl2/vendored/test/cases/ap_eof_str.json.gold +0 -1
- data/ext/libyajl2/vendored/test/cases/ap_map_open.json +0 -1
- data/ext/libyajl2/vendored/test/cases/ap_map_open.json.gold +0 -2
- data/ext/libyajl2/vendored/test/cases/ap_partial_ok.json +0 -1
- data/ext/libyajl2/vendored/test/cases/ap_partial_ok.json.gold +0 -4
- data/ext/libyajl2/vendored/test/cases/array.json +0 -6
- data/ext/libyajl2/vendored/test/cases/array.json.gold +0 -22
- data/ext/libyajl2/vendored/test/cases/array_close.json +0 -1
- data/ext/libyajl2/vendored/test/cases/array_close.json.gold +0 -2
- data/ext/libyajl2/vendored/test/cases/bignums.json +0 -1
- data/ext/libyajl2/vendored/test/cases/bignums.json.gold +0 -5
- data/ext/libyajl2/vendored/test/cases/bogus_char.json +0 -4
- data/ext/libyajl2/vendored/test/cases/bogus_char.json.gold +0 -10
- data/ext/libyajl2/vendored/test/cases/codepoints_from_unicode_org.json +0 -1
- data/ext/libyajl2/vendored/test/cases/codepoints_from_unicode_org.json.gold +0 -2
- data/ext/libyajl2/vendored/test/cases/deep_arrays.json +0 -1
- data/ext/libyajl2/vendored/test/cases/deep_arrays.json.gold +0 -2049
- data/ext/libyajl2/vendored/test/cases/difficult_json_c_test_case.json +0 -1
- data/ext/libyajl2/vendored/test/cases/difficult_json_c_test_case.json.gold +0 -36
- data/ext/libyajl2/vendored/test/cases/doubles.json +0 -1
- data/ext/libyajl2/vendored/test/cases/doubles.json.gold +0 -7
- data/ext/libyajl2/vendored/test/cases/doubles_in_array.json +0 -1
- data/ext/libyajl2/vendored/test/cases/doubles_in_array.json.gold +0 -8
- data/ext/libyajl2/vendored/test/cases/empty_array.json +0 -1
- data/ext/libyajl2/vendored/test/cases/empty_array.json.gold +0 -3
- data/ext/libyajl2/vendored/test/cases/empty_string.json +0 -1
- data/ext/libyajl2/vendored/test/cases/empty_string.json.gold +0 -2
- data/ext/libyajl2/vendored/test/cases/escaped_bulgarian.json +0 -4
- data/ext/libyajl2/vendored/test/cases/escaped_bulgarian.json.gold +0 -7
- data/ext/libyajl2/vendored/test/cases/escaped_foobar.json +0 -1
- data/ext/libyajl2/vendored/test/cases/escaped_foobar.json.gold +0 -2
- data/ext/libyajl2/vendored/test/cases/false.json +0 -1
- data/ext/libyajl2/vendored/test/cases/false.json.gold +0 -2
- data/ext/libyajl2/vendored/test/cases/fg_false_then_garbage.json +0 -1
- data/ext/libyajl2/vendored/test/cases/fg_false_then_garbage.json.gold +0 -3
- data/ext/libyajl2/vendored/test/cases/fg_issue_7.json +0 -1
- data/ext/libyajl2/vendored/test/cases/fg_issue_7.json.gold +0 -3
- data/ext/libyajl2/vendored/test/cases/fg_null_then_garbage.json +0 -1
- data/ext/libyajl2/vendored/test/cases/fg_null_then_garbage.json.gold +0 -3
- data/ext/libyajl2/vendored/test/cases/fg_true_then_garbage.json +0 -1
- data/ext/libyajl2/vendored/test/cases/fg_true_then_garbage.json.gold +0 -3
- data/ext/libyajl2/vendored/test/cases/four_byte_utf8.json +0 -2
- data/ext/libyajl2/vendored/test/cases/four_byte_utf8.json.gold +0 -5
- data/ext/libyajl2/vendored/test/cases/high_overflow.json +0 -1
- data/ext/libyajl2/vendored/test/cases/high_overflow.json.gold +0 -2
- data/ext/libyajl2/vendored/test/cases/integers.json +0 -3
- data/ext/libyajl2/vendored/test/cases/integers.json.gold +0 -14
- data/ext/libyajl2/vendored/test/cases/invalid_utf8.json +0 -1
- data/ext/libyajl2/vendored/test/cases/invalid_utf8.json.gold +0 -3
- data/ext/libyajl2/vendored/test/cases/isolated_surrogate_marker.json +0 -1
- data/ext/libyajl2/vendored/test/cases/isolated_surrogate_marker.json.gold +0 -2
- data/ext/libyajl2/vendored/test/cases/leading_zero_in_number.json +0 -1
- data/ext/libyajl2/vendored/test/cases/leading_zero_in_number.json.gold +0 -5
- data/ext/libyajl2/vendored/test/cases/lonely_minus_sign.json +0 -7
- data/ext/libyajl2/vendored/test/cases/lonely_minus_sign.json.gold +0 -9
- data/ext/libyajl2/vendored/test/cases/lonely_number.json +0 -1
- data/ext/libyajl2/vendored/test/cases/lonely_number.json.gold +0 -2
- data/ext/libyajl2/vendored/test/cases/low_overflow.json +0 -1
- data/ext/libyajl2/vendored/test/cases/low_overflow.json.gold +0 -2
- data/ext/libyajl2/vendored/test/cases/map_close.json +0 -1
- data/ext/libyajl2/vendored/test/cases/map_close.json.gold +0 -2
- data/ext/libyajl2/vendored/test/cases/missing_integer_after_decimal_point.json +0 -1
- data/ext/libyajl2/vendored/test/cases/missing_integer_after_decimal_point.json.gold +0 -2
- data/ext/libyajl2/vendored/test/cases/missing_integer_after_exponent.json +0 -1
- data/ext/libyajl2/vendored/test/cases/missing_integer_after_exponent.json.gold +0 -2
- data/ext/libyajl2/vendored/test/cases/multiple.json +0 -3
- data/ext/libyajl2/vendored/test/cases/multiple.json.gold +0 -4
- data/ext/libyajl2/vendored/test/cases/non_utf8_char_in_string.json +0 -1
- data/ext/libyajl2/vendored/test/cases/non_utf8_char_in_string.json.gold +0 -8
- data/ext/libyajl2/vendored/test/cases/np_partial_bad.json +0 -1
- data/ext/libyajl2/vendored/test/cases/np_partial_bad.json.gold +0 -5
- data/ext/libyajl2/vendored/test/cases/null.json +0 -1
- data/ext/libyajl2/vendored/test/cases/null.json.gold +0 -2
- data/ext/libyajl2/vendored/test/cases/nulls_and_bools.json +0 -5
- data/ext/libyajl2/vendored/test/cases/nulls_and_bools.json.gold +0 -9
- data/ext/libyajl2/vendored/test/cases/simple.json +0 -5
- data/ext/libyajl2/vendored/test/cases/simple.json.gold +0 -9
- data/ext/libyajl2/vendored/test/cases/simple_with_comments.json +0 -11
- data/ext/libyajl2/vendored/test/cases/simple_with_comments.json.gold +0 -5
- data/ext/libyajl2/vendored/test/cases/string_invalid_escape.json +0 -1
- data/ext/libyajl2/vendored/test/cases/string_invalid_escape.json.gold +0 -3
- data/ext/libyajl2/vendored/test/cases/string_invalid_hex_char.json +0 -1
- data/ext/libyajl2/vendored/test/cases/string_invalid_hex_char.json.gold +0 -2
- data/ext/libyajl2/vendored/test/cases/string_with_escapes.json +0 -3
- data/ext/libyajl2/vendored/test/cases/string_with_escapes.json.gold +0 -7
- data/ext/libyajl2/vendored/test/cases/string_with_invalid_newline.json +0 -2
- data/ext/libyajl2/vendored/test/cases/string_with_invalid_newline.json.gold +0 -2
- data/ext/libyajl2/vendored/test/cases/three_byte_utf8.json +0 -1
- data/ext/libyajl2/vendored/test/cases/three_byte_utf8.json.gold +0 -7
- data/ext/libyajl2/vendored/test/cases/true.json +0 -1
- data/ext/libyajl2/vendored/test/cases/true.json.gold +0 -2
- data/ext/libyajl2/vendored/test/cases/unescaped_bulgarian.json +0 -1
- data/ext/libyajl2/vendored/test/cases/unescaped_bulgarian.json.gold +0 -4
- data/ext/libyajl2/vendored/test/cases/zerobyte.json +0 -1
- data/ext/libyajl2/vendored/test/cases/zerobyte.json.gold +0 -0
- data/ext/libyajl2/vendored/test/run_tests.sh +0 -94
- data/ext/libyajl2/vendored/test/yajl_test.c +0 -281
- data/ext/libyajl2/vendored/verify/CMakeLists.txt +0 -39
- data/ext/libyajl2/vendored/verify/json_verify.c +0 -116
- data/lib/ffi_yajl/json_gem.rb +0 -121
- data/lib/libyajl.so +0 -0
- data/lib/libyajl.so.2 +0 -0
- data/lib/libyajl.so.2.0.5 +0 -0
- data/lib/libyajl_s.a +0 -0
- data/spec/ffi_yajl/encoder_spec.rb +0 -39
- data/spec/ffi_yajl/json_gem_spec.rb +0 -355
- data/spec/ffi_yajl/parser_spec.rb +0 -78
- data/spec/spec_helper.rb +0 -14
data/lib/ffi_yajl/ffi/parser.rb
CHANGED
|
@@ -1,94 +1,96 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
# Copyright (c) 2015 Lamont Granquist
|
|
2
|
+
# Copyright (c) 2013-2025 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
|
|
3
|
+
#
|
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
|
5
|
+
# a copy of this software and associated documentation files (the
|
|
6
|
+
# "Software"), to deal in the Software without restriction, including
|
|
7
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
|
8
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
|
9
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
|
10
|
+
# the following conditions:
|
|
11
|
+
#
|
|
12
|
+
# The above copyright notice and this permission notice shall be
|
|
13
|
+
# included in all copies or substantial portions of the Software.
|
|
14
|
+
#
|
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
17
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
19
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
20
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
21
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
3
22
|
|
|
4
23
|
module FFI_Yajl
|
|
5
24
|
module FFI
|
|
6
25
|
module Parser
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
@stack ||= Array.new
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def set_value(val)
|
|
17
|
-
case stack.last
|
|
18
|
-
when Hash
|
|
19
|
-
raise FFI_Yajl::ParseError.new("internal error: missing key in parse") if key.nil?
|
|
20
|
-
stack.last[key] = val
|
|
21
|
-
when Array
|
|
22
|
-
stack.last.push(val)
|
|
23
|
-
else
|
|
24
|
-
raise FFI_Yajl::ParseError.new("internal error: object not a hash or array")
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def stack_pop
|
|
29
|
-
if stack.length > 1
|
|
30
|
-
set_value( stack.pop )
|
|
31
|
-
else
|
|
32
|
-
@finished = stack.pop
|
|
26
|
+
def set_value(val) # rubocop:disable Naming/AccessorMethodName
|
|
27
|
+
case stack.last
|
|
28
|
+
when Hash
|
|
29
|
+
raise FFI_Yajl::ParseError, "internal error: missing key in parse" if key.nil?
|
|
30
|
+
if @opts[:unique_key_checking] && stack.last.key?(key)
|
|
31
|
+
raise FFI_Yajl::ParseError, "repeated key: #{key}"
|
|
33
32
|
end
|
|
34
|
-
end
|
|
35
33
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
34
|
+
stack.last[key] = val
|
|
35
|
+
when Array
|
|
36
|
+
stack.last.push(val)
|
|
37
|
+
else
|
|
38
|
+
stack.push(val)
|
|
41
39
|
end
|
|
40
|
+
end
|
|
42
41
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
def stack_pop
|
|
43
|
+
set_value( stack.pop ) if stack.length > 1
|
|
44
|
+
end
|
|
46
45
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
46
|
+
def key_push
|
|
47
|
+
key_stack.push(key)
|
|
48
|
+
end
|
|
50
49
|
|
|
50
|
+
def key_pop
|
|
51
|
+
@key = key_stack.pop
|
|
52
|
+
end
|
|
51
53
|
|
|
52
54
|
def setup_callbacks
|
|
53
55
|
@null_callback = ::FFI::Function.new(:int, [:pointer]) do |ctx|
|
|
54
56
|
set_value(nil)
|
|
55
57
|
1
|
|
56
58
|
end
|
|
57
|
-
@boolean_callback = ::FFI::Function.new(:int,
|
|
59
|
+
@boolean_callback = ::FFI::Function.new(:int, %i{pointer int}) do |ctx, boolval|
|
|
58
60
|
set_value(boolval == 1 ? true : false)
|
|
59
61
|
1
|
|
60
62
|
end
|
|
61
|
-
@integer_callback = ::FFI::Function.new(:int,
|
|
63
|
+
@integer_callback = ::FFI::Function.new(:int, %i{pointer long_long}) do |ctx, intval|
|
|
62
64
|
set_value(intval)
|
|
63
65
|
1
|
|
64
66
|
end
|
|
65
|
-
@number_callback = ::FFI::Function.new(:int,
|
|
66
|
-
s = stringval.slice(0,stringlen)
|
|
67
|
-
s.force_encoding(
|
|
67
|
+
@number_callback = ::FFI::Function.new(:int, %i{pointer string size_t}) do |ctx, stringval, stringlen|
|
|
68
|
+
s = stringval.slice(0, stringlen)
|
|
69
|
+
s.force_encoding("UTF-8") if defined? Encoding
|
|
68
70
|
# XXX: I can't think of a better way to do this right now. need to call to_f if and only if its a float.
|
|
69
|
-
v = ( s =~
|
|
71
|
+
v = ( s =~ /[\.eE]/ ) ? s.to_f : s.to_i
|
|
70
72
|
set_value(v)
|
|
71
73
|
1
|
|
72
74
|
end
|
|
73
|
-
@double_callback = ::FFI::Function.new(:int,
|
|
75
|
+
@double_callback = ::FFI::Function.new(:int, %i{pointer double}) do |ctx, doubleval|
|
|
74
76
|
set_value(doubleval)
|
|
75
77
|
1
|
|
76
78
|
end
|
|
77
|
-
@string_callback = ::FFI::Function.new(:int,
|
|
78
|
-
s = stringval.slice(0,stringlen)
|
|
79
|
-
s.force_encoding(
|
|
79
|
+
@string_callback = ::FFI::Function.new(:int, %i{pointer string size_t}) do |ctx, stringval, stringlen|
|
|
80
|
+
s = stringval.slice(0, stringlen)
|
|
81
|
+
s.force_encoding("UTF-8") if defined? Encoding
|
|
80
82
|
set_value(s)
|
|
81
83
|
1
|
|
82
84
|
end
|
|
83
85
|
@start_map_callback = ::FFI::Function.new(:int, [:pointer]) do |ctx|
|
|
84
86
|
key_push # for key => { } case, save the key
|
|
85
|
-
stack.push(
|
|
87
|
+
stack.push({})
|
|
86
88
|
1
|
|
87
89
|
end
|
|
88
|
-
@map_key_callback = ::FFI::Function.new(:int,
|
|
89
|
-
s = key.slice(0,keylen)
|
|
90
|
-
s.force_encoding(
|
|
91
|
-
self.key = s
|
|
90
|
+
@map_key_callback = ::FFI::Function.new(:int, %i{pointer string size_t}) do |ctx, key, keylen|
|
|
91
|
+
s = key.slice(0, keylen)
|
|
92
|
+
s.force_encoding("UTF-8") if defined? Encoding
|
|
93
|
+
self.key = @opts[:symbolize_keys] ? s.to_sym : s
|
|
92
94
|
1
|
|
93
95
|
end
|
|
94
96
|
@end_map_callback = ::FFI::Function.new(:int, [:pointer]) do |ctx|
|
|
@@ -98,7 +100,7 @@ module FFI_Yajl
|
|
|
98
100
|
end
|
|
99
101
|
@start_array_callback = ::FFI::Function.new(:int, [:pointer]) do |ctx|
|
|
100
102
|
key_push # for key => [ ] case, save the key
|
|
101
|
-
stack.push(
|
|
103
|
+
stack.push([])
|
|
102
104
|
1
|
|
103
105
|
end
|
|
104
106
|
@end_array_callback = ::FFI::Function.new(:int, [:pointer]) do |ctx|
|
|
@@ -108,8 +110,7 @@ module FFI_Yajl
|
|
|
108
110
|
end
|
|
109
111
|
end
|
|
110
112
|
|
|
111
|
-
|
|
112
|
-
def do_yajl_parse(str, opts = {})
|
|
113
|
+
def do_yajl_parse(str, yajl_opts = {})
|
|
113
114
|
setup_callbacks
|
|
114
115
|
callback_ptr = ::FFI::MemoryPointer.new(::FFI_Yajl::YajlCallbacks)
|
|
115
116
|
callbacks = ::FFI_Yajl::YajlCallbacks.new(callback_ptr)
|
|
@@ -125,21 +126,38 @@ module FFI_Yajl
|
|
|
125
126
|
callbacks[:yajl_start_array] = @start_array_callback
|
|
126
127
|
callbacks[:yajl_end_array] = @end_array_callback
|
|
127
128
|
yajl_handle = ::FFI_Yajl.yajl_alloc(callback_ptr, nil, nil)
|
|
128
|
-
|
|
129
|
+
|
|
130
|
+
# configure the yajl parser
|
|
131
|
+
if yajl_opts[:yajl_allow_comments]
|
|
132
|
+
::FFI_Yajl.yajl_config(yajl_handle, :yajl_allow_comments, :int, 1)
|
|
133
|
+
end
|
|
134
|
+
if yajl_opts[:yajl_dont_validate_strings]
|
|
135
|
+
::FFI_Yajl.yajl_config(yajl_handle, :yajl_dont_validate_strings, :int, 1)
|
|
136
|
+
end
|
|
137
|
+
if yajl_opts[:yajl_allow_trailing_garbage]
|
|
138
|
+
::FFI_Yajl.yajl_config(yajl_handle, :yajl_allow_trailing_garbage, :int, 1)
|
|
139
|
+
end
|
|
140
|
+
if yajl_opts[:yajl_allow_multiple_values]
|
|
141
|
+
::FFI_Yajl.yajl_config(yajl_handle, :yajl_allow_multiple_values, :int, 1)
|
|
142
|
+
end
|
|
143
|
+
if yajl_opts[:yajl_allow_partial_values]
|
|
144
|
+
::FFI_Yajl.yajl_config(yajl_handle, :yajl_allow_partial_values, :int, 1)
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
if ::FFI_Yajl.yajl_parse(yajl_handle, str, str.bytesize) != :yajl_status_ok
|
|
129
148
|
# FIXME: dup the error and call yajl_free_error?
|
|
130
149
|
error = ::FFI_Yajl.yajl_get_error(yajl_handle, 1, str, str.bytesize)
|
|
131
|
-
raise ::FFI_Yajl::ParseError
|
|
150
|
+
raise ::FFI_Yajl::ParseError, error
|
|
132
151
|
end
|
|
133
|
-
if
|
|
152
|
+
if ::FFI_Yajl.yajl_complete_parse(yajl_handle) != :yajl_status_ok
|
|
134
153
|
# FIXME: dup the error and call yajl_free_error?
|
|
135
154
|
error = ::FFI_Yajl.yajl_get_error(yajl_handle, 1, str, str.bytesize)
|
|
136
|
-
raise ::FFI_Yajl::ParseError
|
|
155
|
+
raise ::FFI_Yajl::ParseError, error
|
|
137
156
|
end
|
|
138
|
-
|
|
157
|
+
stack.pop
|
|
139
158
|
ensure
|
|
140
159
|
::FFI_Yajl.yajl_free(yajl_handle) if yajl_handle
|
|
141
160
|
end
|
|
142
161
|
end
|
|
143
162
|
end
|
|
144
163
|
end
|
|
145
|
-
|
data/lib/ffi_yajl/ffi.rb
CHANGED
|
@@ -1,19 +1,44 @@
|
|
|
1
|
-
|
|
1
|
+
# Copyright (c) 2015 Lamont Granquist
|
|
2
|
+
# Copyright (c) 2013-2025 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
|
|
3
|
+
#
|
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
|
5
|
+
# a copy of this software and associated documentation files (the
|
|
6
|
+
# "Software"), to deal in the Software without restriction, including
|
|
7
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
|
8
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
|
9
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
|
10
|
+
# the following conditions:
|
|
11
|
+
#
|
|
12
|
+
# The above copyright notice and this permission notice shall be
|
|
13
|
+
# included in all copies or substantial portions of the Software.
|
|
14
|
+
#
|
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
17
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
19
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
20
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
21
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
22
|
+
|
|
23
|
+
require "rubygems" unless defined?(Gem)
|
|
24
|
+
|
|
25
|
+
require "libyajl2"
|
|
26
|
+
begin
|
|
27
|
+
require "ffi" unless defined?(FFI)
|
|
28
|
+
rescue LoadError
|
|
29
|
+
$stderr.puts "FATAL: to use the ffi extension instead of the compiled C extension, the ffi gem must be installed"
|
|
30
|
+
$stderr.puts " (it is optional, so you must include it in your bundle manually)"
|
|
31
|
+
exit 1
|
|
32
|
+
end
|
|
2
33
|
|
|
3
|
-
|
|
34
|
+
require_relative "map_library_name"
|
|
4
35
|
|
|
5
36
|
module FFI_Yajl
|
|
6
37
|
extend ::FFI::Library
|
|
7
38
|
|
|
8
|
-
|
|
9
|
-
libpath = File.expand_path(File.join(File.dirname(__FILE__), "..", libname))
|
|
39
|
+
extend FFI_Yajl::MapLibraryName
|
|
10
40
|
|
|
11
|
-
|
|
12
|
-
# use our vendored version of libyajl2 if we find it installed
|
|
13
|
-
ffi_lib libpath
|
|
14
|
-
else
|
|
15
|
-
ffi_lib 'yajl'
|
|
16
|
-
end
|
|
41
|
+
ffi_open_yajl_library
|
|
17
42
|
|
|
18
43
|
class YajlCallbacks < ::FFI::Struct
|
|
19
44
|
layout :yajl_null, :pointer,
|
|
@@ -29,37 +54,37 @@ module FFI_Yajl
|
|
|
29
54
|
:yajl_end_array, :pointer
|
|
30
55
|
end
|
|
31
56
|
|
|
32
|
-
enum :yajl_status,
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
# FFI::Enums are slow, should remove the rest
|
|
40
|
-
# enum :yajl_gen_status, [
|
|
41
|
-
# :yajl_gen_status_ok,
|
|
42
|
-
# :yajl_gen_keys_must_be_strings,
|
|
43
|
-
# :yajl_max_depth_exceeded,
|
|
44
|
-
# :yajl_gen_in_error_state,
|
|
45
|
-
# :yajl_gen_generation_complete,
|
|
46
|
-
# :yajl_gen_invalid_number,
|
|
47
|
-
# :yajl_gen_no_buf,
|
|
48
|
-
# ]
|
|
57
|
+
enum :yajl_status, %i{
|
|
58
|
+
yajl_status_ok
|
|
59
|
+
yajl_status_client_canceled
|
|
60
|
+
yajl_status_insufficient_data
|
|
61
|
+
yajl_status_error
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
# FFI::Enums are slow, should remove the rest
|
|
65
|
+
# enum :yajl_gen_status, [
|
|
66
|
+
# :yajl_gen_status_ok,
|
|
67
|
+
# :yajl_gen_keys_must_be_strings,
|
|
68
|
+
# :yajl_max_depth_exceeded,
|
|
69
|
+
# :yajl_gen_in_error_state,
|
|
70
|
+
# :yajl_gen_generation_complete,
|
|
71
|
+
# :yajl_gen_invalid_number,
|
|
72
|
+
# :yajl_gen_no_buf,
|
|
73
|
+
# ]
|
|
49
74
|
|
|
50
75
|
enum :yajl_option, [
|
|
51
76
|
:yajl_allow_comments, 0x01,
|
|
52
77
|
:yajl_dont_validate_strings, 0x02,
|
|
53
78
|
:yajl_allow_trailing_garbage, 0x04,
|
|
54
79
|
:yajl_allow_multiple_values, 0x08,
|
|
55
|
-
:yajl_allow_partial_values, 0x10
|
|
80
|
+
:yajl_allow_partial_values, 0x10
|
|
56
81
|
]
|
|
57
82
|
|
|
58
83
|
enum :yajl_gen_option, [
|
|
59
84
|
:yajl_gen_beautify, 0x01,
|
|
60
85
|
:yajl_gen_indent_string, 0x02,
|
|
61
86
|
:yajl_gen_print_callback, 0x04,
|
|
62
|
-
:yajl_gen_validate_utf8, 0x08
|
|
87
|
+
:yajl_gen_validate_utf8, 0x08
|
|
63
88
|
]
|
|
64
89
|
|
|
65
90
|
typedef :pointer, :yajl_handle
|
|
@@ -72,22 +97,22 @@ module FFI_Yajl
|
|
|
72
97
|
# const char *yajl_status_to_string (yajl_status code)
|
|
73
98
|
attach_function :yajl_status_to_string, [ :yajl_status ], :string
|
|
74
99
|
# yajl_handle yajl_alloc(const yajl_callbacks * callbacks, yajl_alloc_funcs * afs, void * ctx)
|
|
75
|
-
attach_function :yajl_alloc,
|
|
100
|
+
attach_function :yajl_alloc, %i{pointer pointer pointer}, :yajl_handle
|
|
76
101
|
# void yajl_free (yajl_handle handle)
|
|
77
102
|
attach_function :yajl_free, [:yajl_handle], :void
|
|
78
103
|
# yajl_status yajl_parse (yajl_handle hand, const unsigned char *jsonText, unsigned int jsonTextLength)
|
|
79
|
-
attach_function :yajl_parse,
|
|
104
|
+
attach_function :yajl_parse, %i{yajl_handle ustring uint}, :yajl_status
|
|
80
105
|
# yajl_status yajl_parse_complete (yajl_handle hand)
|
|
81
106
|
attach_function :yajl_complete_parse, [:yajl_handle], :yajl_status
|
|
82
107
|
# unsigned char *yajl_get_error (yajl_handle hand, int verbose, const unsigned char *jsonText, unsigned int jsonTextLength)
|
|
83
|
-
attach_function :yajl_get_error,
|
|
108
|
+
attach_function :yajl_get_error, %i{yajl_handle int ustring int}, :ustring
|
|
84
109
|
# void yajl_free_error (yajl_handle hand, unsigned char *str)
|
|
85
|
-
attach_function :yajl_free_error,
|
|
110
|
+
attach_function :yajl_free_error, %i{yajl_handle ustring}, :void
|
|
86
111
|
|
|
87
112
|
#
|
|
88
|
-
attach_function :yajl_config,
|
|
113
|
+
attach_function :yajl_config, %i{yajl_handle yajl_option varargs}, :int
|
|
89
114
|
|
|
90
|
-
attach_function :yajl_gen_config,
|
|
115
|
+
attach_function :yajl_gen_config, %i{yajl_gen yajl_gen_option varargs}, :int
|
|
91
116
|
|
|
92
117
|
# yajl_gen yajl_gen_alloc (const yajl_alloc_funcs *allocFuncs)
|
|
93
118
|
attach_function :yajl_gen_alloc, [:pointer], :yajl_gen
|
|
@@ -96,34 +121,33 @@ module FFI_Yajl
|
|
|
96
121
|
# void yajl_gen_free (yajl_gen handle)
|
|
97
122
|
attach_function :yajl_gen_free, [:yajl_gen], :void
|
|
98
123
|
|
|
99
|
-
attach_function :yajl_gen_integer,
|
|
100
|
-
attach_function :yajl_gen_double,
|
|
101
|
-
attach_function :yajl_gen_number,
|
|
102
|
-
attach_function :yajl_gen_string,
|
|
124
|
+
attach_function :yajl_gen_integer, %i{yajl_gen long_long}, :int
|
|
125
|
+
attach_function :yajl_gen_double, %i{yajl_gen double}, :int
|
|
126
|
+
attach_function :yajl_gen_number, %i{yajl_gen ustring int}, :int
|
|
127
|
+
attach_function :yajl_gen_string, %i{yajl_gen ustring int}, :int
|
|
103
128
|
attach_function :yajl_gen_null, [:yajl_gen], :int
|
|
104
|
-
attach_function :yajl_gen_bool,
|
|
129
|
+
attach_function :yajl_gen_bool, %i{yajl_gen int}, :int
|
|
105
130
|
attach_function :yajl_gen_map_open, [:yajl_gen], :int
|
|
106
131
|
attach_function :yajl_gen_map_close, [:yajl_gen], :int
|
|
107
132
|
attach_function :yajl_gen_array_open, [:yajl_gen], :int
|
|
108
133
|
attach_function :yajl_gen_array_close, [:yajl_gen], :int
|
|
109
134
|
# yajl_gen_status yajl_gen_get_buf (yajl_gen hand, const unsigned char **buf, unsigned int *len)
|
|
110
|
-
attach_function :yajl_gen_get_buf,
|
|
135
|
+
attach_function :yajl_gen_get_buf, %i{yajl_gen pointer pointer}, :int
|
|
111
136
|
# void yajl_gen_clear (yajl_gen hand)
|
|
112
137
|
attach_function :yajl_gen_clear, [:yajl_gen], :void
|
|
113
|
-
|
|
114
138
|
end
|
|
115
139
|
|
|
116
|
-
|
|
117
|
-
|
|
140
|
+
require_relative "encoder"
|
|
141
|
+
require_relative "parser"
|
|
118
142
|
|
|
119
143
|
module FFI_Yajl
|
|
120
144
|
class Parser
|
|
121
|
-
|
|
145
|
+
require_relative "ffi/parser"
|
|
122
146
|
include FFI_Yajl::FFI::Parser
|
|
123
147
|
end
|
|
124
148
|
|
|
125
149
|
class Encoder
|
|
126
|
-
|
|
150
|
+
require_relative "ffi/encoder"
|
|
127
151
|
include FFI_Yajl::FFI::Encoder
|
|
128
152
|
end
|
|
129
153
|
end
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
# Copyright (c) 2015 Lamont Granquist
|
|
2
|
+
# Copyright (c) 2013-2025 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
|
|
3
|
+
#
|
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
|
5
|
+
# a copy of this software and associated documentation files (the
|
|
6
|
+
# "Software"), to deal in the Software without restriction, including
|
|
7
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
|
8
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
|
9
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
|
10
|
+
# the following conditions:
|
|
11
|
+
#
|
|
12
|
+
# The above copyright notice and this permission notice shall be
|
|
13
|
+
# included in all copies or substantial portions of the Software.
|
|
14
|
+
#
|
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
17
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
19
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
20
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
21
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
22
|
+
|
|
23
|
+
require "libyajl2"
|
|
24
|
+
|
|
25
|
+
# Mixin for use in finding the right yajl library on the system. The 'caller'
|
|
26
|
+
# needs to also mixin either the FFI module or the DLopen module. Those are
|
|
27
|
+
# deliberately not mixed in to avoid loading the dlopen module in the ffi
|
|
28
|
+
# codepath (which fails on jruby which does not have that C extension).
|
|
29
|
+
|
|
30
|
+
module FFI_Yajl
|
|
31
|
+
module MapLibraryName
|
|
32
|
+
private
|
|
33
|
+
|
|
34
|
+
# Stub for tests to override the host_os
|
|
35
|
+
#
|
|
36
|
+
# @api private
|
|
37
|
+
# @return [Array<String>] lower case ruby host_os string
|
|
38
|
+
def host_os
|
|
39
|
+
RbConfig::CONFIG["host_os"].downcase
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# Array of yajl library names on the platform. Some platforms like Windows
|
|
43
|
+
# and Mac may have different names/extensions.
|
|
44
|
+
#
|
|
45
|
+
# @api private
|
|
46
|
+
# @return [Array<String>] Array of yajl library names for platform
|
|
47
|
+
def library_names
|
|
48
|
+
case host_os
|
|
49
|
+
when /mingw|mswin/
|
|
50
|
+
[ "libyajl.so", "yajl.dll" ]
|
|
51
|
+
when /cygwin/
|
|
52
|
+
[ "libyajl.so", "cygyajl.dll" ]
|
|
53
|
+
when /darwin/
|
|
54
|
+
[ "libyajl.bundle", "libyajl.dylib" ]
|
|
55
|
+
else
|
|
56
|
+
[ "libyajl.so" ]
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# Array of yajl library names prepended with the libyajl2 path to use to
|
|
61
|
+
# load those directly and bypass the system libyajl by default. Since
|
|
62
|
+
# these are full paths, this API checks to ensure that the file exists on
|
|
63
|
+
# the filesystem. May return an empty array.
|
|
64
|
+
#
|
|
65
|
+
# @api private
|
|
66
|
+
# @return [Array<String>] Array of full paths to libyajl2 gem libraries
|
|
67
|
+
def expanded_library_names
|
|
68
|
+
library_names.map do |libname|
|
|
69
|
+
pathname = File.expand_path(File.join(Libyajl2.opt_path, libname))
|
|
70
|
+
pathname if File.file?(pathname)
|
|
71
|
+
end.compact
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
# Iterate across the expanded library names in the libyajl2-gem and then
|
|
75
|
+
# attempt to load the system libraries. Uses the native dlopen extension
|
|
76
|
+
# that ships in this gem.
|
|
77
|
+
#
|
|
78
|
+
# @api private
|
|
79
|
+
def dlopen_yajl_library
|
|
80
|
+
found = false
|
|
81
|
+
( expanded_library_names + library_names ).each do |libname|
|
|
82
|
+
|
|
83
|
+
dlopen(libname)
|
|
84
|
+
found = true
|
|
85
|
+
break
|
|
86
|
+
rescue ArgumentError
|
|
87
|
+
|
|
88
|
+
end
|
|
89
|
+
raise "cannot find yajl library for platform" unless found
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
# Iterate across the expanded library names in the libyajl2-gem and attempt
|
|
93
|
+
# to load them. If they are missing just use `ffi_lib 'yajl'` to accept
|
|
94
|
+
# the FFI default algorithm to find the library.
|
|
95
|
+
#
|
|
96
|
+
# @api private
|
|
97
|
+
def ffi_open_yajl_library
|
|
98
|
+
found = false
|
|
99
|
+
expanded_library_names.each do |libname|
|
|
100
|
+
|
|
101
|
+
ffi_lib libname
|
|
102
|
+
found = true
|
|
103
|
+
rescue LoadError
|
|
104
|
+
|
|
105
|
+
end
|
|
106
|
+
ffi_lib "yajl" unless found
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
end
|
data/lib/ffi_yajl/parser.rb
CHANGED
|
@@ -1,21 +1,89 @@
|
|
|
1
|
+
# Copyright (c) 2015 Lamont Granquist
|
|
2
|
+
# Copyright (c) 2013-2025 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
|
|
3
|
+
#
|
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
|
5
|
+
# a copy of this software and associated documentation files (the
|
|
6
|
+
# "Software"), to deal in the Software without restriction, including
|
|
7
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
|
8
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
|
9
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
|
10
|
+
# the following conditions:
|
|
11
|
+
#
|
|
12
|
+
# The above copyright notice and this permission notice shall be
|
|
13
|
+
# included in all copies or substantial portions of the Software.
|
|
14
|
+
#
|
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
17
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
19
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
20
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
21
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
1
22
|
|
|
2
23
|
module FFI_Yajl
|
|
3
24
|
class ParseError < StandardError; end
|
|
25
|
+
|
|
4
26
|
class Parser
|
|
27
|
+
attr_writer :stack, :key_stack
|
|
28
|
+
attr_accessor :key, :finished
|
|
29
|
+
|
|
5
30
|
attr_accessor :opts
|
|
6
31
|
|
|
32
|
+
#
|
|
33
|
+
# stack used to build up our complex object
|
|
34
|
+
#
|
|
35
|
+
def stack
|
|
36
|
+
@stack ||= []
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
#
|
|
40
|
+
# stack to keep track of keys as we create nested hashes
|
|
41
|
+
#
|
|
42
|
+
def key_stack
|
|
43
|
+
@key_stack ||= []
|
|
44
|
+
end
|
|
45
|
+
|
|
7
46
|
def self.parse(obj, *args)
|
|
8
47
|
new(*args).parse(obj)
|
|
9
48
|
end
|
|
10
49
|
|
|
11
50
|
def initialize(opts = {})
|
|
12
|
-
@opts = opts
|
|
51
|
+
@opts = opts ? opts.dup : {}
|
|
52
|
+
# JSON gem uses 'symbolize_names' and ruby-yajl supports this as well
|
|
53
|
+
@opts[:symbolize_keys] = true if @opts[:symbolize_names]
|
|
13
54
|
end
|
|
14
55
|
|
|
15
56
|
def parse(str)
|
|
57
|
+
raise FFI_Yajl::ParseError, "input must be a string or IO" unless str.is_a?(String) || str.respond_to?(:read)
|
|
58
|
+
|
|
16
59
|
# initialization that we can do in pure ruby
|
|
17
60
|
yajl_opts = {}
|
|
18
61
|
|
|
62
|
+
if @opts[:check_utf8] == false && @opts[:dont_validate_strings] == false
|
|
63
|
+
raise ArgumentError, "options check_utf8 and dont_validate_strings are both false which conflict"
|
|
64
|
+
end
|
|
65
|
+
if @opts[:check_utf8] == true && @opts[:dont_validate_strings] == true
|
|
66
|
+
raise ArgumentError, "options check_utf8 and dont_validate_strings are both true which conflict"
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
yajl_opts[:yajl_allow_comments] = true
|
|
70
|
+
|
|
71
|
+
if @opts.key?(:allow_comments)
|
|
72
|
+
yajl_opts[:yajl_allow_comments] = @opts[:allow_comments]
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
yajl_opts[:yajl_dont_validate_strings] = (@opts[:check_utf8] == false || @opts[:dont_validate_strings])
|
|
76
|
+
yajl_opts[:yajl_allow_trailing_garbage] = @opts[:allow_trailing_garbage]
|
|
77
|
+
yajl_opts[:yajl_allow_multiple_values] = @opts[:allow_multiple_values]
|
|
78
|
+
yajl_opts[:yajl_allow_partial_values] = @opts[:allow_partial_values]
|
|
79
|
+
|
|
80
|
+
yajl_opts[:unique_key_checking] = @opts[:unique_key_checking]
|
|
81
|
+
|
|
82
|
+
# XXX: bug-compat with ruby-yajl
|
|
83
|
+
return nil if str == ""
|
|
84
|
+
|
|
85
|
+
str = str.read if str.respond_to?(:read)
|
|
86
|
+
|
|
19
87
|
# call either the ext or ffi hook
|
|
20
88
|
do_yajl_parse(str, yajl_opts)
|
|
21
89
|
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Copyright (c) 2015 Lamont Granquist
|
|
2
|
+
# Copyright (c) 2013-2025 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
|
|
3
|
+
#
|
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
|
5
|
+
# a copy of this software and associated documentation files (the
|
|
6
|
+
# "Software"), to deal in the Software without restriction, including
|
|
7
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
|
8
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
|
9
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
|
10
|
+
# the following conditions:
|
|
11
|
+
#
|
|
12
|
+
# The above copyright notice and this permission notice shall be
|
|
13
|
+
# included in all copies or substantial portions of the Software.
|
|
14
|
+
#
|
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
17
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
19
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
20
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
21
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
22
|
+
|
|
23
|
+
module FFI_Yajl
|
|
24
|
+
module Platform
|
|
25
|
+
def windows?
|
|
26
|
+
!!(RUBY_PLATFORM =~ /mswin|mingw|cygwin|windows/)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
data/lib/ffi_yajl/version.rb
CHANGED
|
@@ -1,3 +1,25 @@
|
|
|
1
|
+
# Copyright (c) 2015 Lamont Granquist
|
|
2
|
+
# Copyright:: Copyright (c) 2013-2025 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
|
|
3
|
+
#
|
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
|
5
|
+
# a copy of this software and associated documentation files (the
|
|
6
|
+
# "Software"), to deal in the Software without restriction, including
|
|
7
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
|
8
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
|
9
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
|
10
|
+
# the following conditions:
|
|
11
|
+
#
|
|
12
|
+
# The above copyright notice and this permission notice shall be
|
|
13
|
+
# included in all copies or substantial portions of the Software.
|
|
14
|
+
#
|
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
17
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
19
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
20
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
21
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
22
|
+
|
|
1
23
|
module FFI_Yajl
|
|
2
|
-
VERSION = "
|
|
24
|
+
VERSION = "3.0.1".freeze
|
|
3
25
|
end
|