ffi-yajl 2.2.3 → 2.3.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 +4 -4
- data/README.md +31 -73
- data/Rakefile +55 -95
- data/bin/ffi-yajl-bench +7 -7
- data/ext/ffi_yajl/ext/dlopen/extconf.rb +5 -5
- data/ext/ffi_yajl/ext/encoder/encoder.c +4 -0
- data/ext/ffi_yajl/ext/encoder/extconf.rb +12 -12
- data/ext/ffi_yajl/ext/parser/extconf.rb +12 -12
- data/lib/ffi_yajl/benchmark/encode.rb +8 -8
- data/lib/ffi_yajl/benchmark/encode_json_and_marshal.rb +9 -9
- data/lib/ffi_yajl/benchmark/encode_json_and_yaml.rb +11 -11
- data/lib/ffi_yajl/benchmark/encode_profile.rb +5 -5
- data/lib/ffi_yajl/benchmark/http.rb +12 -12
- data/lib/ffi_yajl/benchmark/parse.rb +8 -8
- data/lib/ffi_yajl/benchmark/parse_json_and_marshal.rb +10 -10
- data/lib/ffi_yajl/benchmark/parse_json_and_yaml.rb +11 -11
- data/lib/ffi_yajl/benchmark/parse_profile.rb +5 -5
- data/lib/ffi_yajl/benchmark/parse_profile_ruby_prof.rb +4 -4
- data/lib/ffi_yajl/benchmark/parse_stream.rb +9 -9
- data/lib/ffi_yajl/benchmark.rb +5 -5
- data/lib/ffi_yajl/encoder.rb +2 -2
- data/lib/ffi_yajl/ext.rb +9 -9
- data/lib/ffi_yajl/ffi/encoder.rb +9 -27
- data/lib/ffi_yajl/ffi/parser.rb +5 -5
- data/lib/ffi_yajl/ffi.rb +8 -8
- data/lib/ffi_yajl/map_library_name.rb +3 -3
- data/lib/ffi_yajl/parser.rb +2 -2
- data/lib/ffi_yajl/version.rb +2 -2
- data/lib/ffi_yajl.rb +7 -7
- data/spec/ffi_yajl/encoder_spec.rb +10 -10
- data/spec/ffi_yajl/map_library_name_spec.rb +2 -2
- data/spec/ffi_yajl/parser_spec.rb +7 -7
- data/spec/spec_helper.rb +4 -4
- metadata +15 -15
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) +
|
|
2
|
-
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) +
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + "/..")
|
|
2
|
+
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + "/../lib")
|
|
3
3
|
|
|
4
|
-
require
|
|
5
|
-
require
|
|
6
|
-
require
|
|
4
|
+
require "rubygems"
|
|
5
|
+
require "benchmark"
|
|
6
|
+
require "yajl"
|
|
7
7
|
begin
|
|
8
|
-
require
|
|
8
|
+
require "json"
|
|
9
9
|
rescue LoadError
|
|
10
10
|
end
|
|
11
|
-
require
|
|
11
|
+
require "yaml"
|
|
12
12
|
|
|
13
13
|
# JSON Section
|
|
14
|
-
filename =
|
|
15
|
-
json = File.new(filename,
|
|
14
|
+
filename = "benchmark/subjects/ohai.json"
|
|
15
|
+
json = File.new(filename, "r")
|
|
16
16
|
hash = Yajl::Parser.new.parse(json)
|
|
17
17
|
json.close
|
|
18
18
|
|
|
@@ -33,8 +33,8 @@ Benchmark.bmbm do |x|
|
|
|
33
33
|
end
|
|
34
34
|
|
|
35
35
|
# YAML Section
|
|
36
|
-
filename =
|
|
37
|
-
yml = File.new(filename,
|
|
36
|
+
filename = "benchmark/subjects/ohai.yml"
|
|
37
|
+
yml = File.new(filename, "r")
|
|
38
38
|
data = YAML.load_stream(yml)
|
|
39
39
|
yml.close
|
|
40
40
|
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
# Portions Originally Copyright (c) 2008-2011 Brian Lopez - http://github.com/brianmario
|
|
2
2
|
# See MIT-LICENSE
|
|
3
3
|
|
|
4
|
-
require
|
|
5
|
-
require
|
|
4
|
+
require "rubygems"
|
|
5
|
+
require "ffi_yajl"
|
|
6
6
|
begin
|
|
7
|
-
require
|
|
7
|
+
require "perftools"
|
|
8
8
|
rescue LoadError
|
|
9
9
|
puts "INFO: perftools.rb gem not installed"
|
|
10
10
|
end
|
|
11
11
|
|
|
12
|
-
ENV[
|
|
12
|
+
ENV["CPUPROFILE_FREQUENCY"] = "4000"
|
|
13
13
|
|
|
14
14
|
module FFI_Yajl
|
|
15
15
|
class Benchmark
|
|
@@ -18,7 +18,7 @@ module FFI_Yajl
|
|
|
18
18
|
return unless defined?(PerfTools)
|
|
19
19
|
|
|
20
20
|
filename = File.expand_path(File.join(File.dirname(__FILE__), "subjects", "ohai.json"))
|
|
21
|
-
hash = File.open(filename,
|
|
21
|
+
hash = File.open(filename, "rb") { |f| FFI_Yajl::Parser.parse(f.read) }
|
|
22
22
|
|
|
23
23
|
times = 1000
|
|
24
24
|
puts "Starting profiling encoding #{filename} #{times} times\n\n"
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) +
|
|
2
|
-
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) +
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + "/..")
|
|
2
|
+
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + "/../lib")
|
|
3
3
|
|
|
4
|
-
require
|
|
5
|
-
require
|
|
6
|
-
require
|
|
7
|
-
require
|
|
8
|
-
require
|
|
9
|
-
require
|
|
10
|
-
require
|
|
11
|
-
require
|
|
12
|
-
require
|
|
4
|
+
require "rubygems"
|
|
5
|
+
require "benchmark"
|
|
6
|
+
require "yajl/http_stream"
|
|
7
|
+
require "yajl/gzip"
|
|
8
|
+
require "yajl/deflate"
|
|
9
|
+
require "yajl/bzip2" unless defined?(Bzip2)
|
|
10
|
+
require "json"
|
|
11
|
+
require "uri"
|
|
12
|
+
require "net/http"
|
|
13
13
|
|
|
14
|
-
uri = URI.parse(
|
|
14
|
+
uri = URI.parse("http://search.twitter.com/search.json?q=github")
|
|
15
15
|
# uri = URI.parse('http://localhost/yajl-ruby.git/benchmark/subjects/contacts.json')
|
|
16
16
|
|
|
17
17
|
times = ARGV[0] ? ARGV[0].to_i : 1
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
require
|
|
2
|
-
require
|
|
3
|
-
require
|
|
4
|
-
require
|
|
1
|
+
require "rubygems"
|
|
2
|
+
require "benchmark"
|
|
3
|
+
require "yajl"
|
|
4
|
+
require "ffi_yajl"
|
|
5
5
|
if !defined?(RUBY_ENGINE) || RUBY_ENGINE !~ /jruby/
|
|
6
6
|
begin
|
|
7
|
-
require
|
|
7
|
+
require "yajl"
|
|
8
8
|
rescue LoadError
|
|
9
9
|
puts "INFO: yajl-ruby not installed"
|
|
10
10
|
end
|
|
@@ -12,11 +12,11 @@ else
|
|
|
12
12
|
puts "INFO: skipping yajl-ruby on jruby"
|
|
13
13
|
end
|
|
14
14
|
begin
|
|
15
|
-
require
|
|
15
|
+
require "json"
|
|
16
16
|
rescue LoadError
|
|
17
17
|
end
|
|
18
18
|
begin
|
|
19
|
-
require
|
|
19
|
+
require "oj"
|
|
20
20
|
rescue LoadError
|
|
21
21
|
end
|
|
22
22
|
|
|
@@ -25,7 +25,7 @@ module FFI_Yajl
|
|
|
25
25
|
class Parse
|
|
26
26
|
def run
|
|
27
27
|
filename = File.expand_path(File.join(File.dirname(__FILE__), "subjects", "item.json"))
|
|
28
|
-
json = File.new(filename,
|
|
28
|
+
json = File.new(filename, "r")
|
|
29
29
|
json_str = json.read
|
|
30
30
|
|
|
31
31
|
times = ARGV[1] ? ARGV[1].to_i : 10_000
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) +
|
|
2
|
-
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) +
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + "/..")
|
|
2
|
+
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + "/../lib")
|
|
3
3
|
|
|
4
|
-
require
|
|
5
|
-
require
|
|
6
|
-
require
|
|
4
|
+
require "rubygems"
|
|
5
|
+
require "benchmark"
|
|
6
|
+
require "yajl"
|
|
7
7
|
begin
|
|
8
|
-
require
|
|
8
|
+
require "json"
|
|
9
9
|
rescue LoadError
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
# JSON section
|
|
13
|
-
filename =
|
|
14
|
-
marshal_filename =
|
|
15
|
-
json = File.new(filename,
|
|
16
|
-
marshal_file = File.new(marshal_filename,
|
|
13
|
+
filename = "benchmark/subjects/ohai.json"
|
|
14
|
+
marshal_filename = "benchmark/subjects/ohai.marshal_dump"
|
|
15
|
+
json = File.new(filename, "r")
|
|
16
|
+
marshal_file = File.new(marshal_filename, "r")
|
|
17
17
|
|
|
18
18
|
hash = {}
|
|
19
19
|
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) +
|
|
2
|
-
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) +
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + "/..")
|
|
2
|
+
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + "/../lib")
|
|
3
3
|
|
|
4
|
-
require
|
|
5
|
-
require
|
|
6
|
-
require
|
|
4
|
+
require "rubygems"
|
|
5
|
+
require "benchmark"
|
|
6
|
+
require "yajl"
|
|
7
7
|
begin
|
|
8
|
-
require
|
|
8
|
+
require "json"
|
|
9
9
|
rescue LoadError
|
|
10
10
|
end
|
|
11
|
-
require
|
|
11
|
+
require "yaml"
|
|
12
12
|
|
|
13
13
|
# JSON section
|
|
14
|
-
filename =
|
|
15
|
-
json = File.new(filename,
|
|
14
|
+
filename = "benchmark/subjects/ohai.json"
|
|
15
|
+
json = File.new(filename, "r")
|
|
16
16
|
|
|
17
17
|
times = ARGV[0] ? ARGV[0].to_i : 1000
|
|
18
18
|
puts "Starting benchmark parsing #{File.size(filename)} bytes of JSON data #{times} times\n\n"
|
|
@@ -39,8 +39,8 @@ end
|
|
|
39
39
|
json.close
|
|
40
40
|
|
|
41
41
|
# YAML section
|
|
42
|
-
filename =
|
|
43
|
-
yaml = File.new(filename,
|
|
42
|
+
filename = "benchmark/subjects/ohai.yml"
|
|
43
|
+
yaml = File.new(filename, "r")
|
|
44
44
|
|
|
45
45
|
puts "Starting benchmark parsing #{File.size(filename)} bytes of YAML data #{times} times\n\n"
|
|
46
46
|
Benchmark.bmbm do |x|
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
# Portions Originally Copyright (c) 2008-2011 Brian Lopez - http://github.com/brianmario
|
|
2
2
|
# See MIT-LICENSE
|
|
3
3
|
|
|
4
|
-
require
|
|
5
|
-
require
|
|
4
|
+
require "rubygems"
|
|
5
|
+
require "ffi_yajl"
|
|
6
6
|
begin
|
|
7
|
-
require
|
|
7
|
+
require "perftools"
|
|
8
8
|
rescue LoadError
|
|
9
9
|
puts "INFO: perftools.rb gem not installed"
|
|
10
10
|
end
|
|
11
11
|
|
|
12
|
-
ENV[
|
|
12
|
+
ENV["CPUPROFILE_FREQUENCY"] = "4000"
|
|
13
13
|
|
|
14
14
|
module FFI_Yajl
|
|
15
15
|
class Benchmark
|
|
@@ -18,7 +18,7 @@ module FFI_Yajl
|
|
|
18
18
|
return if defined?(PerfTools)
|
|
19
19
|
|
|
20
20
|
filename = File.expand_path(File.join(File.dirname(__FILE__), "subjects", "ohai.json"))
|
|
21
|
-
json = File.new(filename,
|
|
21
|
+
json = File.new(filename, "r").read
|
|
22
22
|
|
|
23
23
|
times = 1000
|
|
24
24
|
puts "Starting profiling encoding #{filename} #{times} times\n\n"
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
# Portions Originally Copyright (c) 2008-2011 Brian Lopez - http://github.com/brianmario
|
|
2
2
|
# See MIT-LICENSE
|
|
3
3
|
|
|
4
|
-
require
|
|
5
|
-
require
|
|
4
|
+
require "rubygems"
|
|
5
|
+
require "ffi_yajl"
|
|
6
6
|
|
|
7
7
|
module FFI_Yajl
|
|
8
8
|
class Benchmark
|
|
9
9
|
class ParseProfileRubyProf
|
|
10
10
|
def run
|
|
11
11
|
begin
|
|
12
|
-
require
|
|
12
|
+
require "ruby-prof"
|
|
13
13
|
rescue LoadError
|
|
14
14
|
puts "INFO: perftools.rb gem not installed"
|
|
15
15
|
end
|
|
@@ -17,7 +17,7 @@ module FFI_Yajl
|
|
|
17
17
|
return if defined?(RubyProf)
|
|
18
18
|
|
|
19
19
|
filename = File.expand_path(File.join(File.dirname(__FILE__), "subjects", "ohai.json"))
|
|
20
|
-
json = File.new(filename,
|
|
20
|
+
json = File.new(filename, "r").read
|
|
21
21
|
|
|
22
22
|
times = 1000
|
|
23
23
|
puts "Starting profiling encoding #{filename} #{times} times\n\n"
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) +
|
|
2
|
-
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) +
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + "/..")
|
|
2
|
+
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + "/../lib")
|
|
3
3
|
|
|
4
|
-
require
|
|
5
|
-
require
|
|
6
|
-
require
|
|
4
|
+
require "rubygems"
|
|
5
|
+
require "benchmark"
|
|
6
|
+
require "yajl"
|
|
7
7
|
begin
|
|
8
|
-
require
|
|
8
|
+
require "json"
|
|
9
9
|
rescue LoadError
|
|
10
10
|
end
|
|
11
11
|
begin
|
|
12
|
-
require
|
|
12
|
+
require "active_support"
|
|
13
13
|
rescue LoadError
|
|
14
14
|
end
|
|
15
15
|
|
|
16
|
-
filename =
|
|
17
|
-
json = File.new(filename,
|
|
16
|
+
filename = "benchmark/subjects/twitter_stream.json"
|
|
17
|
+
json = File.new(filename, "r")
|
|
18
18
|
|
|
19
19
|
times = ARGV[0] ? ARGV[0].to_i : 100
|
|
20
20
|
puts "Starting benchmark parsing JSON stream (#{File.size(filename)} bytes of JSON data with 430 JSON separate strings) #{times} times\n\n"
|
data/lib/ffi_yajl/benchmark.rb
CHANGED
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
21
21
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
22
22
|
|
|
23
|
-
require
|
|
24
|
-
require
|
|
25
|
-
require
|
|
26
|
-
require
|
|
27
|
-
require
|
|
23
|
+
require "ffi_yajl/benchmark/encode.rb"
|
|
24
|
+
require "ffi_yajl/benchmark/encode_profile.rb"
|
|
25
|
+
require "ffi_yajl/benchmark/parse.rb"
|
|
26
|
+
require "ffi_yajl/benchmark/parse_profile.rb"
|
|
27
|
+
require "ffi_yajl/benchmark/parse_profile_ruby_prof.rb"
|
data/lib/ffi_yajl/encoder.rb
CHANGED
|
@@ -47,7 +47,7 @@ module FFI_Yajl
|
|
|
47
47
|
if str.respond_to?(:scrub)
|
|
48
48
|
str.scrub!
|
|
49
49
|
else
|
|
50
|
-
str.encode!("UTF-16le", undef: :replace, invalid: :replace).encode!(
|
|
50
|
+
str.encode!("UTF-16le", undef: :replace, invalid: :replace).encode!("UTF-8")
|
|
51
51
|
end
|
|
52
52
|
end
|
|
53
53
|
str
|
|
@@ -68,7 +68,7 @@ module FFI_Yajl
|
|
|
68
68
|
if token.respond_to?(:scrub)
|
|
69
69
|
token.scrub!
|
|
70
70
|
else
|
|
71
|
-
token.encode!("UTF-16le", undef: :replace, invalid: :replace).encode!(
|
|
71
|
+
token.encode!("UTF-16le", undef: :replace, invalid: :replace).encode!("UTF-8")
|
|
72
72
|
end
|
|
73
73
|
case status
|
|
74
74
|
when 1 # yajl_gen_keys_must_be_strings
|
data/lib/ffi_yajl/ext.rb
CHANGED
|
@@ -20,16 +20,16 @@
|
|
|
20
20
|
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
21
21
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
22
22
|
|
|
23
|
-
require
|
|
23
|
+
require "rubygems"
|
|
24
24
|
|
|
25
|
-
require
|
|
26
|
-
require
|
|
27
|
-
require
|
|
28
|
-
require
|
|
25
|
+
require "ffi_yajl/encoder"
|
|
26
|
+
require "ffi_yajl/parser"
|
|
27
|
+
require "ffi_yajl/ext/dlopen"
|
|
28
|
+
require "ffi_yajl/map_library_name"
|
|
29
29
|
|
|
30
30
|
# needed so the encoder c-code can find these symbols
|
|
31
|
-
require
|
|
32
|
-
require
|
|
31
|
+
require "stringio"
|
|
32
|
+
require "date"
|
|
33
33
|
|
|
34
34
|
module FFI_Yajl
|
|
35
35
|
extend FFI_Yajl::MapLibraryName
|
|
@@ -38,12 +38,12 @@ module FFI_Yajl
|
|
|
38
38
|
dlopen_yajl_library
|
|
39
39
|
|
|
40
40
|
class Parser
|
|
41
|
-
require
|
|
41
|
+
require "ffi_yajl/ext/parser"
|
|
42
42
|
include FFI_Yajl::Ext::Parser
|
|
43
43
|
end
|
|
44
44
|
|
|
45
45
|
class Encoder
|
|
46
|
-
require
|
|
46
|
+
require "ffi_yajl/ext/encoder"
|
|
47
47
|
include FFI_Yajl::Ext::Encoder
|
|
48
48
|
end
|
|
49
49
|
end
|
data/lib/ffi_yajl/ffi/encoder.rb
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# Copyright (c) 2015 Lamont Granquist
|
|
2
|
-
# Copyright (c) 2015 Chef Software
|
|
2
|
+
# Copyright (c) 2015-2017, Chef Software Inc.
|
|
3
3
|
#
|
|
4
4
|
# Permission is hereby granted, free of charge, to any person obtaining
|
|
5
5
|
# a copy of this software and associated documentation files (the
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
21
21
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
22
22
|
|
|
23
|
-
require
|
|
24
|
-
require
|
|
23
|
+
require "date"
|
|
24
|
+
require "stringio"
|
|
25
25
|
|
|
26
26
|
module FFI_Yajl
|
|
27
27
|
module FFI
|
|
@@ -73,7 +73,7 @@ class Hash
|
|
|
73
73
|
end
|
|
74
74
|
else
|
|
75
75
|
if ( status = FFI_Yajl.yajl_gen_map_open(yajl_gen) ) != 0
|
|
76
|
-
FFI_Yajl::Encoder.raise_error_for_status(status,
|
|
76
|
+
FFI_Yajl::Encoder.raise_error_for_status(status, "{")
|
|
77
77
|
end
|
|
78
78
|
each do |key, value|
|
|
79
79
|
# Perf Fix: mutate state hash rather than creating new copy
|
|
@@ -83,7 +83,7 @@ class Hash
|
|
|
83
83
|
value.ffi_yajl(yajl_gen, state)
|
|
84
84
|
end
|
|
85
85
|
if ( status = FFI_Yajl.yajl_gen_map_close(yajl_gen) ) != 0
|
|
86
|
-
FFI_Yajl::Encoder.raise_error_for_status(status,
|
|
86
|
+
FFI_Yajl::Encoder.raise_error_for_status(status, "}")
|
|
87
87
|
end
|
|
88
88
|
end
|
|
89
89
|
end
|
|
@@ -98,13 +98,13 @@ class Array
|
|
|
98
98
|
end
|
|
99
99
|
else
|
|
100
100
|
if ( status = FFI_Yajl.yajl_gen_array_open(yajl_gen) ) != 0
|
|
101
|
-
FFI_Yajl::Encoder.raise_error_for_status(status,
|
|
101
|
+
FFI_Yajl::Encoder.raise_error_for_status(status, "[")
|
|
102
102
|
end
|
|
103
103
|
each do |value|
|
|
104
104
|
value.ffi_yajl(yajl_gen, state)
|
|
105
105
|
end
|
|
106
106
|
if ( status = FFI_Yajl.yajl_gen_array_close(yajl_gen) ) != 0
|
|
107
|
-
FFI_Yajl::Encoder.raise_error_for_status(status,
|
|
107
|
+
FFI_Yajl::Encoder.raise_error_for_status(status, "]")
|
|
108
108
|
end
|
|
109
109
|
end
|
|
110
110
|
end
|
|
@@ -155,25 +155,7 @@ class FalseClass
|
|
|
155
155
|
end
|
|
156
156
|
end
|
|
157
157
|
|
|
158
|
-
class
|
|
159
|
-
def ffi_yajl(yajl_gen, state)
|
|
160
|
-
str = to_s
|
|
161
|
-
if str == "NaN" || str == "Infinity" || str == "-Infinity"
|
|
162
|
-
raise ::FFI_Yajl::EncodeError, "'#{str}' is an invalid number"
|
|
163
|
-
end
|
|
164
|
-
if state[:processing_key]
|
|
165
|
-
if ( status = FFI_Yajl.yajl_gen_string(yajl_gen, str, str.bytesize) ) != 0
|
|
166
|
-
FFI_Yajl::Encoder.raise_error_for_status(status, str)
|
|
167
|
-
end
|
|
168
|
-
else
|
|
169
|
-
if ( status = FFI_Yajl.yajl_gen_integer(yajl_gen, self) ) != 0
|
|
170
|
-
FFI_Yajl::Encoder.raise_error_for_status(status, str)
|
|
171
|
-
end
|
|
172
|
-
end
|
|
173
|
-
end
|
|
174
|
-
end
|
|
175
|
-
|
|
176
|
-
class Bignum
|
|
158
|
+
class Integer
|
|
177
159
|
def ffi_yajl(yajl_gen, state)
|
|
178
160
|
str = to_s
|
|
179
161
|
if str == "NaN" || str == "Infinity" || str == "-Infinity"
|
|
@@ -265,7 +247,7 @@ end
|
|
|
265
247
|
# I feel dirty
|
|
266
248
|
class Object
|
|
267
249
|
def ffi_yajl(yajl_gen, state)
|
|
268
|
-
if !state[:processing_key] &&
|
|
250
|
+
if !state[:processing_key] && respond_to?(:to_json)
|
|
269
251
|
str = to_json(state[:json_opts])
|
|
270
252
|
# #yajl_gen_number outputs a string without quotes around it
|
|
271
253
|
status = FFI_Yajl.yajl_gen_number(yajl_gen, str, str.bytesize)
|
data/lib/ffi_yajl/ffi/parser.rb
CHANGED
|
@@ -65,7 +65,7 @@ module FFI_Yajl
|
|
|
65
65
|
end
|
|
66
66
|
@number_callback = ::FFI::Function.new(:int, [:pointer, :string, :size_t ]) do |ctx, stringval, stringlen|
|
|
67
67
|
s = stringval.slice(0, stringlen)
|
|
68
|
-
s.force_encoding(
|
|
68
|
+
s.force_encoding("UTF-8") if defined? Encoding
|
|
69
69
|
# 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.
|
|
70
70
|
v = ( s =~ /[\.eE]/ ) ? s.to_f : s.to_i
|
|
71
71
|
set_value(v)
|
|
@@ -77,7 +77,7 @@ module FFI_Yajl
|
|
|
77
77
|
end
|
|
78
78
|
@string_callback = ::FFI::Function.new(:int, [:pointer, :string, :size_t]) do |ctx, stringval, stringlen|
|
|
79
79
|
s = stringval.slice(0, stringlen)
|
|
80
|
-
s.force_encoding(
|
|
80
|
+
s.force_encoding("UTF-8") if defined? Encoding
|
|
81
81
|
set_value(s)
|
|
82
82
|
1
|
|
83
83
|
end
|
|
@@ -88,7 +88,7 @@ module FFI_Yajl
|
|
|
88
88
|
end
|
|
89
89
|
@map_key_callback = ::FFI::Function.new(:int, [:pointer, :string, :size_t]) do |ctx, key, keylen|
|
|
90
90
|
s = key.slice(0, keylen)
|
|
91
|
-
s.force_encoding(
|
|
91
|
+
s.force_encoding("UTF-8") if defined? Encoding
|
|
92
92
|
self.key = @opts[:symbolize_keys] ? s.to_sym : s
|
|
93
93
|
1
|
|
94
94
|
end
|
|
@@ -143,12 +143,12 @@ module FFI_Yajl
|
|
|
143
143
|
::FFI_Yajl.yajl_config(yajl_handle, :yajl_allow_partial_values, :int, 1)
|
|
144
144
|
end
|
|
145
145
|
|
|
146
|
-
if
|
|
146
|
+
if ::FFI_Yajl.yajl_parse(yajl_handle, str, str.bytesize) != :yajl_status_ok
|
|
147
147
|
# FIXME: dup the error and call yajl_free_error?
|
|
148
148
|
error = ::FFI_Yajl.yajl_get_error(yajl_handle, 1, str, str.bytesize)
|
|
149
149
|
raise ::FFI_Yajl::ParseError, error
|
|
150
150
|
end
|
|
151
|
-
if
|
|
151
|
+
if ::FFI_Yajl.yajl_complete_parse(yajl_handle) != :yajl_status_ok
|
|
152
152
|
# FIXME: dup the error and call yajl_free_error?
|
|
153
153
|
error = ::FFI_Yajl.yajl_get_error(yajl_handle, 1, str, str.bytesize)
|
|
154
154
|
raise ::FFI_Yajl::ParseError, error
|
data/lib/ffi_yajl/ffi.rb
CHANGED
|
@@ -20,18 +20,18 @@
|
|
|
20
20
|
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
21
21
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
22
22
|
|
|
23
|
-
require
|
|
23
|
+
require "rubygems"
|
|
24
24
|
|
|
25
|
-
require
|
|
25
|
+
require "libyajl2"
|
|
26
26
|
begin
|
|
27
|
-
require
|
|
27
|
+
require "ffi"
|
|
28
28
|
rescue LoadError
|
|
29
29
|
$stderr.puts "FATAL: to use the ffi extension instead of the compiled C extension, the ffi gem must be installed"
|
|
30
30
|
$stderr.puts " (it is optional, so you must include it in your bundle manually)"
|
|
31
31
|
exit 1
|
|
32
32
|
end
|
|
33
33
|
|
|
34
|
-
require
|
|
34
|
+
require "ffi_yajl/map_library_name"
|
|
35
35
|
|
|
36
36
|
module FFI_Yajl
|
|
37
37
|
extend ::FFI::Library
|
|
@@ -137,17 +137,17 @@ module FFI_Yajl
|
|
|
137
137
|
attach_function :yajl_gen_clear, [:yajl_gen], :void
|
|
138
138
|
end
|
|
139
139
|
|
|
140
|
-
require
|
|
141
|
-
require
|
|
140
|
+
require "ffi_yajl/encoder"
|
|
141
|
+
require "ffi_yajl/parser"
|
|
142
142
|
|
|
143
143
|
module FFI_Yajl
|
|
144
144
|
class Parser
|
|
145
|
-
require
|
|
145
|
+
require "ffi_yajl/ffi/parser"
|
|
146
146
|
include FFI_Yajl::FFI::Parser
|
|
147
147
|
end
|
|
148
148
|
|
|
149
149
|
class Encoder
|
|
150
|
-
require
|
|
150
|
+
require "ffi_yajl/ffi/encoder"
|
|
151
151
|
include FFI_Yajl::FFI::Encoder
|
|
152
152
|
end
|
|
153
153
|
end
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
21
21
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
22
22
|
|
|
23
|
-
require
|
|
23
|
+
require "libyajl2"
|
|
24
24
|
|
|
25
25
|
# Mixin for use in finding the right yajl library on the system. The 'caller'
|
|
26
26
|
# needs to also mixin either the FFI module or the DLopen module. Those are
|
|
@@ -36,7 +36,7 @@ module FFI_Yajl
|
|
|
36
36
|
# @api private
|
|
37
37
|
# @return Array<String> lower case ruby host_os string
|
|
38
38
|
def host_os
|
|
39
|
-
RbConfig::CONFIG[
|
|
39
|
+
RbConfig::CONFIG["host_os"].downcase
|
|
40
40
|
end
|
|
41
41
|
|
|
42
42
|
# Array of yajl library names on the platform. Some platforms like Windows
|
|
@@ -103,7 +103,7 @@ module FFI_Yajl
|
|
|
103
103
|
rescue LoadError
|
|
104
104
|
end
|
|
105
105
|
end
|
|
106
|
-
ffi_lib
|
|
106
|
+
ffi_lib "yajl" unless found
|
|
107
107
|
end
|
|
108
108
|
end
|
|
109
109
|
end
|
data/lib/ffi_yajl/parser.rb
CHANGED
|
@@ -65,10 +65,10 @@ module FFI_Yajl
|
|
|
65
65
|
raise ArgumentError, "options check_utf8 and dont_validate_strings are both true which conflict"
|
|
66
66
|
end
|
|
67
67
|
|
|
68
|
-
yajl_opts[:yajl_allow_comments]
|
|
68
|
+
yajl_opts[:yajl_allow_comments] = true
|
|
69
69
|
|
|
70
70
|
if @opts.key?(:allow_comments)
|
|
71
|
-
yajl_opts[:yajl_allow_comments]
|
|
71
|
+
yajl_opts[:yajl_allow_comments] = @opts[:allow_comments]
|
|
72
72
|
end
|
|
73
73
|
|
|
74
74
|
yajl_opts[:yajl_dont_validate_strings] = (@opts[:check_utf8] == false || @opts[:dont_validate_strings])
|
data/lib/ffi_yajl/version.rb
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# Copyright (c) 2015 Lamont Granquist
|
|
2
|
-
# Copyright (c) 2015 Chef Software
|
|
2
|
+
# Copyright (c) 2015-2017, Chef Software Inc.
|
|
3
3
|
#
|
|
4
4
|
# Permission is hereby granted, free of charge, to any person obtaining
|
|
5
5
|
# a copy of this software and associated documentation files (the
|
|
@@ -21,5 +21,5 @@
|
|
|
21
21
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
22
22
|
|
|
23
23
|
module FFI_Yajl
|
|
24
|
-
VERSION = "2.
|
|
24
|
+
VERSION = "2.3.1"
|
|
25
25
|
end
|
data/lib/ffi_yajl.rb
CHANGED
|
@@ -34,17 +34,17 @@
|
|
|
34
34
|
# dropped, so don't bother asking for that.
|
|
35
35
|
# - Then we try the c-ext and rescue into ffi that fails
|
|
36
36
|
#
|
|
37
|
-
if ENV[
|
|
38
|
-
require
|
|
39
|
-
elsif ENV[
|
|
40
|
-
require
|
|
37
|
+
if ENV["FORCE_FFI_YAJL"] == "ext"
|
|
38
|
+
require "ffi_yajl/ext"
|
|
39
|
+
elsif ENV["FORCE_FFI_YAJL"] == "ffi"
|
|
40
|
+
require "ffi_yajl/ffi"
|
|
41
41
|
elsif RUBY_PLATFORM == "java"
|
|
42
|
-
require
|
|
42
|
+
require "ffi_yajl/ffi"
|
|
43
43
|
else
|
|
44
44
|
begin
|
|
45
|
-
require
|
|
45
|
+
require "ffi_yajl/ext"
|
|
46
46
|
rescue LoadError
|
|
47
47
|
warn "failed to load the ffi-yajl c-extension, falling back to ffi interface"
|
|
48
|
-
require
|
|
48
|
+
require "ffi_yajl/ffi"
|
|
49
49
|
end
|
|
50
50
|
end
|