ffi-yajl 2.2.3-universal-java → 2.4.0-universal-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +37 -74
- 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 +14 -14
- data/ext/ffi_yajl/ext/parser/extconf.rb +14 -14
- data/lib/ffi_yajl.rb +7 -7
- data/lib/ffi_yajl/benchmark.rb +5 -5
- 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 +11 -11
- data/lib/ffi_yajl/encoder.rb +2 -2
- data/lib/ffi_yajl/ext.rb +9 -9
- data/lib/ffi_yajl/ffi.rb +36 -36
- data/lib/ffi_yajl/ffi/encoder.rb +10 -26
- data/lib/ffi_yajl/ffi/parser.rb +14 -13
- data/lib/ffi_yajl/map_library_name.rb +6 -6
- data/lib/ffi_yajl/parser.rb +2 -2
- data/lib/ffi_yajl/version.rb +2 -2
- metadata +11 -87
- data/Rakefile +0 -179
- data/spec/ffi_yajl/encoder_spec.rb +0 -221
- data/spec/ffi_yajl/map_library_name_spec.rb +0 -115
- data/spec/ffi_yajl/parser_spec.rb +0 -569
- data/spec/spec_helper.rb +0 -45
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1735649f4c5cfe623d86b3880367ed921466a9987b3650dacb16e60ad9ed7493
|
4
|
+
data.tar.gz: e4203b9546f527955f0837487c8c4bfec79d86d622faef07002f16a8337cea19
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: af296ac8b967bc93b1dddc16ea3c60e8581e09649b59fda348784bb480898d16280f05aae197de693e292fc678a0f9a06650e5f21cc8b673eb89f1e3e16c12a8
|
7
|
+
data.tar.gz: e495c095604c93143f0fc030ed0390a2309998e0ab629f6a6c1f9586acac2a26dd738268c7551ed33564acdc0603f86c1e6c980be81cabc5990aa278d4ba5cff
|
data/README.md
CHANGED
@@ -1,13 +1,17 @@
|
|
1
|
+
# FFI YAJL
|
1
2
|
|
2
|
-
[![Build
|
3
|
+
[![Build status](https://badge.buildkite.com/35c43155d637f5201a5030cd4e7d8025573c0042094e00bbb3.svg?branch=master)](https://buildkite.com/chef-oss/chef-ffi-yajl-master-verify) [![Gem Version](https://badge.fury.io/rb/ffi-yajl.svg)](https://badge.fury.io/rb/ffi-yajl)
|
3
4
|
|
4
|
-
|
5
|
+
**Umbrella Project**: [Chef Foundation](https://github.com/chef/chef-oss-practices/blob/master/projects/chef-foundation.md)
|
6
|
+
|
7
|
+
**Project State**: [Active](https://github.com/chef/chef-oss-practices/blob/master/repo-management/repo-states.md#active)
|
8
|
+
|
9
|
+
**Issues [Response Time Maximum](https://github.com/chef/chef-oss-practices/blob/master/repo-management/repo-states.md)**: 14 days
|
5
10
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
order to be compatible with as many Ruby implementations as possible
|
10
|
-
while providing good performance where possible.
|
11
|
+
**Pull Request [Response Time Maximum](https://github.com/chef/chef-oss-practices/blob/master/repo-management/repo-states.md)**: 14 days
|
12
|
+
|
13
|
+
|
14
|
+
ffi-yajl is a Ruby adapter for the [yajl](http://lloyd.github.io/yajl/) JSON parser/generator library. ffi-yajl supports multiple Ruby C extension mechanisms, including both MRI native extensions and FFI in order to be compatible with as many Ruby implementations as possible while providing good performance where possible.
|
11
15
|
|
12
16
|
## How to Install
|
13
17
|
|
@@ -25,20 +29,16 @@ gem 'ffi-yajl'
|
|
25
29
|
|
26
30
|
## Supported Ruby VMs:
|
27
31
|
|
28
|
-
|
29
|
-
* rbx 2.2.x (possibly earlier)
|
30
|
-
* Jruby 1.7.x (possibly earlier)
|
31
|
-
|
32
|
-
Ruby 1.8.7 support was dropped in 2.2.0
|
32
|
+
- Ruby 2.2+ and compatible rbx or jruby
|
33
33
|
|
34
34
|
## Supported Distros:
|
35
35
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
36
|
+
- Ubuntu 10.04 through 14.10
|
37
|
+
- Debian 7.x
|
38
|
+
- RHEL/CentOS/Oracle 5.x/6.x/7.x
|
39
|
+
- Solaris 9/10/11 (gcc, sun compiler untested)
|
40
|
+
- AIX 6.x/7.x (gcc or xlc)
|
41
|
+
- Windows 2008r2/2012 (and Win2k/2k3 and consumer versions should work)
|
42
42
|
|
43
43
|
## Basic Usage
|
44
44
|
|
@@ -68,81 +68,44 @@ hash = parser.parse( json )
|
|
68
68
|
|
69
69
|
## Parser Options
|
70
70
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
are repeated in hashes in the input JSON. Without this, repeated keys will
|
80
|
-
silently replace the previous key.
|
71
|
+
- `:check_utf8`
|
72
|
+
- `:dont_validate_strings`
|
73
|
+
- `:symbolize_keys` (default = false): JSON keys are parsed into symbols instead of strings.
|
74
|
+
- `:symbolize_names` (default = false): Alias for `:symbolize_keys`.
|
75
|
+
- `:allow_trailing_garbage`
|
76
|
+
- `:allow_multiple_values`
|
77
|
+
- `:allow_partial_values`
|
78
|
+
- `:unique_key_checking` (default = false): Will raise an exception if keys are repeated in hashes in the input JSON. Without this, repeated keys will silently replace the previous key.
|
81
79
|
|
82
80
|
## Encoder Options
|
83
81
|
|
84
|
-
|
85
|
-
|
86
|
-
encode strings that are invalid UTF-8. When set to false this still will
|
87
|
-
produce valid UTF-8 JSON but will replace invalid characters.
|
82
|
+
- `:pretty` (default = false): Produces more human readable 'pretty' output.
|
83
|
+
- `:validate_utf8` (default = true): Will raise an exception when trying to encode strings that are invalid UTF-8\. When set to false this still will produce valid UTF-8 JSON but will replace invalid characters.
|
88
84
|
|
89
85
|
## Forcing FFI or C Extension
|
90
86
|
|
91
|
-
You can set the environment variable `FORCE_FFI_YAJL` to `ext` or `ffi` to
|
92
|
-
control if the C extension or FFI bindings are used.
|
87
|
+
You can set the environment variable `FORCE_FFI_YAJL` to `ext` or `ffi` to control if the C extension or FFI bindings are used.
|
93
88
|
|
94
89
|
## Yajl Library Packaging
|
95
90
|
|
96
|
-
This library prefers to use the embedded yajl 2.x C library packaged in the
|
97
|
-
libyajl2 gem. In order to use the operating system yajl library (which must be
|
98
|
-
yajl 2.x) the environment variable `USE_SYSTEM_LIBYAJL2` can be set before
|
99
|
-
installing or bundling libyajl2. This will force the libyajl2 gem to skip
|
100
|
-
compiling its embedded library and the ffi-yajl gem will fallback to using the
|
101
|
-
system yajl library.
|
91
|
+
This library prefers to use the embedded yajl 2.x C library packaged in the libyajl2 gem. In order to use the operating system yajl library (which must be yajl 2.x) the environment variable `USE_SYSTEM_LIBYAJL2` can be set before installing or bundling libyajl2\. This will force the libyajl2 gem to skip compiling its embedded library and the ffi-yajl gem will fallback to using the system yajl library.
|
102
92
|
|
103
93
|
## No JSON Gem Compatiblity layer
|
104
94
|
|
105
|
-
This library does not offer a feature to patch `#to_json` methods into all
|
106
|
-
the ruby classes similarly to the JSON gem or yajl-ruby's `yajl/json_gem`
|
107
|
-
compatibility API. The differences in encoding between the JSON gem and the
|
108
|
-
Yajl C library can produce different output on different systems and makes
|
109
|
-
testing brittle. Such a feature will not be included. It was removed in
|
110
|
-
this pull request and could be easily extracted to its own gem (we have
|
111
|
-
no interest in maintaining that gem):
|
95
|
+
This library does not offer a feature to patch `#to_json` methods into all the ruby classes similarly to the JSON gem or yajl-ruby's `yajl/json_gem` compatibility API. The differences in encoding between the JSON gem and the Yajl C library can produce different output on different systems and makes testing brittle. Such a feature will not be included. It was removed in this pull request and could be easily extracted to its own gem (we have no interest in maintaining that gem):
|
112
96
|
|
113
|
-
https://github.com/chef/ffi-yajl/pull/47/files
|
97
|
+
<https://github.com/chef/ffi-yajl/pull/47/files>
|
114
98
|
|
115
99
|
## Why This Instead of X?
|
116
100
|
|
117
|
-
yajl is the only JSON library we've found that has error messages that
|
118
|
-
|
119
|
-
|
120
|
-
1234," which are probably fine for server use, but in
|
121
|
-
[chef](https://github.com/chef/chef) we frequently deal with
|
122
|
-
user-written JSON documents, which means we need a good user experience
|
123
|
-
when encountering malformed JSON.
|
124
|
-
|
125
|
-
We previously used brianmario's
|
126
|
-
[yajl-ruby](https://github.com/brianmario/yajl-ruby) project, but we
|
127
|
-
wanted to be able to fallback to using FFI bindings to the C code (so we
|
128
|
-
could support non-MRI rubies) and we also needed some bug fixes in
|
129
|
-
yajl2, but the maintainer wasn't able to devote enough time to the
|
130
|
-
project to make these updates in a timeframe that worked for us.
|
101
|
+
yajl is the only JSON library we've found that has error messages that meet our requirements. The stdlib json gem and oj (at the time we started this project) have error messages like "invalid token at byte 1234," which are probably fine for server use, but in [chef](https://github.com/chef/chef) we frequently deal with user-written JSON documents, which means we need a good user experience when encountering malformed JSON.
|
102
|
+
|
103
|
+
We previously used brianmario's [yajl-ruby](https://github.com/brianmario/yajl-ruby) project, but we wanted to be able to fallback to using FFI bindings to the C code (so we could support non-MRI rubies) and we also needed some bug fixes in yajl2, but the maintainer wasn't able to devote enough time to the project to make these updates in a timeframe that worked for us.
|
131
104
|
|
132
105
|
## Thanks
|
133
106
|
|
134
|
-
This was initially going to be a clean rewrite of an ffi ruby wrapper around
|
135
|
-
yajl2, but as it progressed more and more code was pulled in from brianmario's
|
136
|
-
existing yajl-ruby gem, particularly all the c extension code, lots of specs
|
137
|
-
and the benchmarks. And the process of writing this would have been much more
|
138
|
-
difficult without being able to draw heavily from already solved problems in
|
139
|
-
yajl-ruby.
|
107
|
+
This was initially going to be a clean rewrite of an ffi ruby wrapper around yajl2, but as it progressed more and more code was pulled in from brianmario's existing yajl-ruby gem, particularly all the c extension code, lots of specs and the benchmarks. And the process of writing this would have been much more difficult without being able to draw heavily from already solved problems in yajl-ruby.
|
140
108
|
|
141
109
|
## License
|
142
110
|
|
143
|
-
Given that this draws heavily from the yajl-ruby sources, and could be
|
144
|
-
considered a derivative work, the MIT License from that project has been
|
145
|
-
preserved and this source code has deliberately not been dual licensed under
|
146
|
-
Chef's typical Apache License. See the
|
147
|
-
[LICENSE](https://github.com/chef/ffi-yajl/blob/master/LICENSE) file in this
|
148
|
-
project.
|
111
|
+
Given that this draws heavily from the yajl-ruby sources, and could be considered a derivative work, the MIT License from that project has been preserved and this source code has deliberately not been dual licensed under Chef's typical Apache License. See the [LICENSE](https://github.com/chef/ffi-yajl/blob/master/LICENSE) file in this project.
|
data/bin/ffi-yajl-bench
CHANGED
@@ -2,31 +2,31 @@
|
|
2
2
|
|
3
3
|
$LOAD_PATH << File.expand_path(File.join(File.dirname( File.symlink?(__FILE__) ? File.readlink(__FILE__) : __FILE__ ), "../lib"))
|
4
4
|
|
5
|
-
require
|
6
|
-
require
|
5
|
+
require "optparse"
|
6
|
+
require "ffi_yajl/benchmark"
|
7
7
|
|
8
8
|
opts = {}
|
9
9
|
optparse = OptionParser.new do |o|
|
10
10
|
o.banner = "Usage: ffi-yajl-bench"
|
11
11
|
|
12
12
|
opts[:profile] = false
|
13
|
-
o.on(
|
13
|
+
o.on( "-p", "--profile", "Run perftools.rb profiling" ) do
|
14
14
|
opts[:profile] = true
|
15
15
|
end
|
16
16
|
|
17
|
-
o.on(
|
17
|
+
o.on( "-F", "--ffi", "Force using FFI" ) do
|
18
18
|
opts[:ffi] = true
|
19
19
|
end
|
20
20
|
|
21
|
-
o.on(
|
21
|
+
o.on( "-E", "--ext", "Force using C ext" ) do
|
22
22
|
opts[:ext] = true
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
26
|
optparse.parse!
|
27
27
|
|
28
|
-
ENV[
|
29
|
-
ENV[
|
28
|
+
ENV["FORCE_FFI_YAJL"] = "ffi" if opts[:ffi]
|
29
|
+
ENV["FORCE_FFI_YAJL"] = "ext" if opts[:ext]
|
30
30
|
|
31
31
|
if opts[:profile]
|
32
32
|
FFI_Yajl::Benchmark::ParseProfileRubyProf.new.run
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# rubocop:disable Style/GlobalVars
|
2
|
-
require
|
3
|
-
require
|
2
|
+
require "mkmf"
|
3
|
+
require "rubygems"
|
4
4
|
|
5
|
-
RbConfig::MAKEFILE_CONFIG[
|
5
|
+
RbConfig::MAKEFILE_CONFIG["CC"] = ENV["CC"] if ENV["CC"]
|
6
6
|
|
7
7
|
puts $CFLAGS
|
8
8
|
puts $LDFLAGS
|
@@ -11,6 +11,6 @@ have_header("dlfcn.h")
|
|
11
11
|
|
12
12
|
have_library("dl", "dlopen")
|
13
13
|
|
14
|
-
dir_config
|
14
|
+
dir_config "dlopen"
|
15
15
|
|
16
|
-
create_makefile
|
16
|
+
create_makefile "ffi_yajl/ext/dlopen"
|
@@ -377,8 +377,12 @@ void Init_encoder() {
|
|
377
377
|
rb_define_method(rb_cNilClass, "ffi_yajl", rb_cNilClass_ffi_yajl, 2);
|
378
378
|
rb_define_method(rb_cTrueClass, "ffi_yajl", rb_cTrueClass_ffi_yajl, 2);
|
379
379
|
rb_define_method(rb_cFalseClass, "ffi_yajl", rb_cFalseClass_ffi_yajl, 2);
|
380
|
+
#ifdef rb_cFixnum /* ruby < 2.4 */
|
380
381
|
rb_define_method(rb_cFixnum, "ffi_yajl", rb_cFixnum_ffi_yajl, 2);
|
381
382
|
rb_define_method(rb_cBignum, "ffi_yajl", rb_cBignum_ffi_yajl, 2);
|
383
|
+
#else
|
384
|
+
rb_define_method(rb_cInteger, "ffi_yajl", rb_cFixnum_ffi_yajl, 2);
|
385
|
+
#endif
|
382
386
|
rb_define_method(rb_cFloat, "ffi_yajl", rb_cFloat_ffi_yajl, 2);
|
383
387
|
rb_define_method(rb_cString, "ffi_yajl", rb_cString_ffi_yajl, 2);
|
384
388
|
rb_define_method(rb_cSymbol, "ffi_yajl", rb_cSymbol_ffi_yajl, 2);
|
@@ -1,9 +1,9 @@
|
|
1
1
|
# rubocop:disable Style/GlobalVars
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
2
|
+
require "mkmf"
|
3
|
+
require "rubygems"
|
4
|
+
require "libyajl2"
|
5
5
|
|
6
|
-
RbConfig::MAKEFILE_CONFIG[
|
6
|
+
RbConfig::MAKEFILE_CONFIG["CC"] = ENV["CC"] if ENV["CC"]
|
7
7
|
|
8
8
|
# pick up the vendored libyajl2 out of the libyajl2 gem
|
9
9
|
$CFLAGS = " -I#{Libyajl2.include_path} #{$CFLAGS}"
|
@@ -16,7 +16,7 @@ puts $CFLAGS
|
|
16
16
|
puts $LDFLAGS
|
17
17
|
|
18
18
|
# except if you're doing an unoptimized gcc install we're going to help you out a bit
|
19
|
-
if RbConfig::MAKEFILE_CONFIG[
|
19
|
+
if RbConfig::MAKEFILE_CONFIG["CC"] =~ /gcc|clang/
|
20
20
|
$CFLAGS << " -O3" unless $CFLAGS[/-O\d/]
|
21
21
|
# how many people realize that -Wall is a compiler-specific flag???
|
22
22
|
# apparently not many based on reading lots of shitty extconf.rb's out there
|
@@ -34,32 +34,32 @@ end
|
|
34
34
|
|
35
35
|
# NOTE: find_library has the side effect of adding -lyajl to the flags which we are deliberately
|
36
36
|
# avoiding doing with the libyajl2-gem (allowing it to be lazily loaded with dlopen)
|
37
|
-
if !windows? && !find_header(
|
37
|
+
if !windows? && !find_header("yajl/yajl_tree.h")
|
38
38
|
puts "libyajl2 headers not found in libyajl2-gem, searching for system libraries..."
|
39
39
|
|
40
40
|
HEADER_DIRS = [
|
41
41
|
"/opt/local/include", # MacPorts
|
42
42
|
"/usr/local/include", # /usr/local
|
43
|
-
RbConfig::CONFIG[
|
43
|
+
RbConfig::CONFIG["includedir"], # Ruby
|
44
44
|
"/usr/include", # (default)
|
45
|
-
]
|
45
|
+
].freeze
|
46
46
|
|
47
47
|
LIB_DIRS = [
|
48
48
|
"/opt/local/lib", # MacPorts
|
49
49
|
"/usr/local/lib", # /usr/local + Homebrew
|
50
|
-
RbConfig::CONFIG[
|
50
|
+
RbConfig::CONFIG["libdir"], # Ruby
|
51
51
|
"/usr/lib", # (default)
|
52
|
-
]
|
52
|
+
].freeze
|
53
53
|
|
54
54
|
# add --with-yajl-dir, --with-yajl-include, --with-yajl-lib
|
55
|
-
dir_config(
|
55
|
+
dir_config("yajl", HEADER_DIRS, LIB_DIRS)
|
56
56
|
|
57
57
|
# here we use find_library in order to deliberately link with -lyajl as a useful side-effect
|
58
|
-
unless find_header(
|
58
|
+
unless find_header("yajl/yajl_tree.h") && find_library("yajl", "yajl_complete_parse")
|
59
59
|
abort "libyajl2 is missing. please install libyajl2"
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
|
-
dir_config
|
63
|
+
dir_config "encoder"
|
64
64
|
|
65
|
-
create_makefile
|
65
|
+
create_makefile "ffi_yajl/ext/encoder"
|
@@ -1,9 +1,9 @@
|
|
1
1
|
# rubocop:disable Style/GlobalVars
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
2
|
+
require "mkmf"
|
3
|
+
require "rubygems"
|
4
|
+
require "libyajl2"
|
5
5
|
|
6
|
-
RbConfig::MAKEFILE_CONFIG[
|
6
|
+
RbConfig::MAKEFILE_CONFIG["CC"] = ENV["CC"] if ENV["CC"]
|
7
7
|
|
8
8
|
# pick up the vendored libyajl2 out of the libyajl2 gem
|
9
9
|
$CFLAGS = "-I#{Libyajl2.include_path} #{$CFLAGS}"
|
@@ -16,7 +16,7 @@ puts $CFLAGS
|
|
16
16
|
puts $LDFLAGS
|
17
17
|
|
18
18
|
# except if you're doing an unoptimized gcc install we're going to help you out a bit
|
19
|
-
if RbConfig::MAKEFILE_CONFIG[
|
19
|
+
if RbConfig::MAKEFILE_CONFIG["CC"] =~ /gcc|clang/
|
20
20
|
$CFLAGS << " -O3" unless $CFLAGS[/-O\d/]
|
21
21
|
# how many people realize that -Wall is a compiler-specific flag???
|
22
22
|
# apparently not many based on reading lots of shitty extconf.rb's out there
|
@@ -34,32 +34,32 @@ end
|
|
34
34
|
|
35
35
|
# NOTE: find_library has the side effect of adding -lyajl to the flags which we are deliberately
|
36
36
|
# avoiding doing with the libyajl2-gem (allowing it to be lazily loaded with dlopen)
|
37
|
-
if !windows? && !find_header(
|
37
|
+
if !windows? && !find_header("yajl/yajl_tree.h")
|
38
38
|
puts "libyajl2 headers not found in libyajl2-gem, searching for system libraries..."
|
39
39
|
|
40
40
|
HEADER_DIRS = [
|
41
41
|
"/opt/local/include", # MacPorts
|
42
42
|
"/usr/local/include", # /usr/local
|
43
|
-
RbConfig::CONFIG[
|
43
|
+
RbConfig::CONFIG["includedir"], # Ruby
|
44
44
|
"/usr/include", # (default)
|
45
|
-
]
|
45
|
+
].freeze
|
46
46
|
|
47
47
|
LIB_DIRS = [
|
48
48
|
"/opt/local/lib", # MacPorts
|
49
49
|
"/usr/local/lib", # /usr/local + Homebrew
|
50
|
-
RbConfig::CONFIG[
|
50
|
+
RbConfig::CONFIG["libdir"], # Ruby
|
51
51
|
"/usr/lib", # (default)
|
52
|
-
]
|
52
|
+
].freeze
|
53
53
|
|
54
54
|
# add --with-yajl-dir, --with-yajl-include, --with-yajl-lib
|
55
|
-
dir_config(
|
55
|
+
dir_config("yajl", HEADER_DIRS, LIB_DIRS)
|
56
56
|
|
57
57
|
# here we use find_library in order to deliberately link with -lyajl as a useful side-effect
|
58
|
-
unless find_header(
|
58
|
+
unless find_header("yajl/yajl_tree.h") && find_library("yajl", "yajl_complete_parse")
|
59
59
|
abort "libyajl2 is missing. please install libyajl2"
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
|
-
dir_config
|
63
|
+
dir_config "parser"
|
64
64
|
|
65
|
-
create_makefile
|
65
|
+
create_makefile "ffi_yajl/ext/parser"
|
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
|
-
|
39
|
-
elsif ENV[
|
40
|
-
|
37
|
+
if ENV["FORCE_FFI_YAJL"] == "ext"
|
38
|
+
require_relative "ffi_yajl/ext"
|
39
|
+
elsif ENV["FORCE_FFI_YAJL"] == "ffi"
|
40
|
+
require_relative "ffi_yajl/ffi"
|
41
41
|
elsif RUBY_PLATFORM == "java"
|
42
|
-
|
42
|
+
require_relative "ffi_yajl/ffi"
|
43
43
|
else
|
44
44
|
begin
|
45
|
-
|
45
|
+
require_relative "ffi_yajl/ext"
|
46
46
|
rescue LoadError
|
47
47
|
warn "failed to load the ffi-yajl c-extension, falling back to ffi interface"
|
48
|
-
|
48
|
+
require_relative "ffi_yajl/ffi"
|
49
49
|
end
|
50
50
|
end
|
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"
|
@@ -1,26 +1,26 @@
|
|
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
|
6
|
-
require
|
4
|
+
require "rubygems" unless defined?(Gem)
|
5
|
+
require "benchmark" unless defined?(Benchmark)
|
6
|
+
require "stringio" unless defined?(StringIO)
|
7
7
|
if !defined?(RUBY_ENGINE) || RUBY_ENGINE !~ /jruby/
|
8
8
|
begin
|
9
|
-
require
|
9
|
+
require "yajl"
|
10
10
|
rescue LoadError
|
11
11
|
puts "INFO: yajl-ruby not installed"
|
12
12
|
end
|
13
13
|
else
|
14
14
|
puts "INFO: skipping yajl-ruby on jruby"
|
15
15
|
end
|
16
|
-
|
16
|
+
require_relative "../../ffi_yajl"
|
17
17
|
begin
|
18
|
-
require
|
18
|
+
require "json" unless defined?(JSON)
|
19
19
|
rescue LoadError
|
20
20
|
puts "INFO: json gem not installed"
|
21
21
|
end
|
22
22
|
begin
|
23
|
-
require
|
23
|
+
require "oj"
|
24
24
|
rescue LoadError
|
25
25
|
puts "INFO: oj gem not installed"
|
26
26
|
end
|
@@ -31,7 +31,7 @@ module FFI_Yajl
|
|
31
31
|
def run
|
32
32
|
# filename = ARGV[0] || 'benchmark/subjects/ohai.json'
|
33
33
|
filename = File.expand_path(File.join(File.dirname(__FILE__), "subjects", "ohai.json"))
|
34
|
-
hash = File.open(filename,
|
34
|
+
hash = File.open(filename, "rb") { |f| FFI_Yajl::Parser.parse(f.read) }
|
35
35
|
|
36
36
|
times = ARGV[1] ? ARGV[1].to_i : 1000
|
37
37
|
puts "Starting benchmark encoding #{filename} #{times} times\n\n"
|