Skip to content

Commit 6fdcacb

Browse files
committed
Turn json_pure into an empty gem
Fix: ruby#650 Closes: ruby#682
1 parent f373b8c commit 6fdcacb

16 files changed

+701
-1164
lines changed

Gemfile

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
source 'https://rubygems.org'
22

3-
if ENV['JSON'] == 'pure'
4-
gemspec name: 'json_pure'
5-
else
6-
gemspec name: 'json'
7-
end
3+
gemspec name: 'json'
84

95
group :development do
106
gem "ruby_memcheck" if RUBY_PLATFORM =~ /linux/i

README.md

+3-9
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,10 @@
55
## Description
66

77
This is an implementation of the JSON specification according to RFC 7159
8-
http://www.ietf.org/rfc/rfc7159.txt . There is two variants available:
8+
http://www.ietf.org/rfc/rfc7159.txt .
99

10-
* A pure ruby variant, that relies on the `strscan` extensions, which is
11-
part of the ruby standard library.
12-
* The quite a bit faster native extension variant, which is in parts
13-
implemented in C or Java and comes with a parser generated by the [Ragel]
14-
state machine compiler.
15-
16-
Both variants of the JSON generator generate UTF-8 character sequences by
17-
default. If an :ascii\_only option with a true value is given, they escape all
10+
The JSON generator generate UTF-8 character sequences by default.
11+
If an :ascii\_only option with a true value is given, they escape all
1812
non-ASCII and control characters with \uXXXX escape sequences, and support
1913
UTF-16 surrogate pairs in order to be able to generate the whole range of
2014
unicode code points.

Rakefile

+10-41
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,8 @@ else
5656
RAGEL_DOTGEN = %w[rlgen-dot rlgen-cd ragel].find(&which)
5757
end
5858

59-
desc "Installing library (pure)"
60-
task :install_pure do
61-
ruby 'install.rb'
62-
end
63-
64-
task :install_ext_really do
59+
desc "Installing library (extension)"
60+
task :install => [ :compile ] do
6561
sitearchdir = CONFIG["sitearchdir"]
6662
cd 'ext' do
6763
for file in Dir["json/ext/*.#{CONFIG['DLEXT']}"]
@@ -73,30 +69,6 @@ task :install_ext_really do
7369
end
7470
end
7571

76-
desc "Installing library (extension)"
77-
task :install_ext => [ :compile, :install_pure, :install_ext_really ]
78-
79-
desc "Installing library (extension)"
80-
task :install => :install_ext
81-
82-
task :check_env do
83-
ENV.key?('JSON') or fail "JSON env var is required"
84-
end
85-
86-
desc "Testing library (pure ruby)"
87-
task :test_pure => [ :set_env_pure, :check_env, :do_test_pure ]
88-
task(:set_env_pure) { ENV['JSON'] = 'pure' }
89-
90-
UndocumentedTestTask.new do |t|
91-
t.name = 'do_test_pure'
92-
t.test_files = FileList['test/json/*_test.rb']
93-
t.verbose = true
94-
t.options = '-v'
95-
end
96-
97-
desc "Testing library (pure ruby and extension)"
98-
task :test => [ :test_pure, :test_ext ]
99-
10072
namespace :gems do
10173
desc 'Install all development gems'
10274
task :install do
@@ -177,16 +149,14 @@ if defined?(RUBY_ENGINE) and RUBY_ENGINE == 'jruby'
177149
sh "gem build -o pkg/json-#{PKG_VERSION}-java.gem json.gemspec"
178150
end
179151

180-
desc "Testing library (jruby)"
181-
task :test_ext => [ :set_env_ext, :create_jar, :check_env, :do_test_ext ]
182-
task(:set_env_ext) { ENV['JSON'] = 'ext' }
183-
184152
UndocumentedTestTask.new do |t|
185-
t.name = 'do_test_ext'
153+
t.name = :test
186154
t.test_files = FileList['test/json/*_test.rb']
187155
t.verbose = true
188156
t.options = '-v'
189157
end
158+
desc "Testing library (jruby)"
159+
task :test => [:create_jar ]
190160

191161
file JRUBY_PARSER_JAR => :compile do
192162
cd 'java/src' do
@@ -239,20 +209,19 @@ else
239209
task :compile => [ :ragel, EXT_PARSER_DL, EXT_GENERATOR_DL ]
240210
end
241211

242-
desc "Testing library (extension)"
243-
task :test_ext => [ :set_env_ext, :check_env, :compile, :do_test_ext ]
244-
task(:set_env_ext) { ENV['JSON'] = 'ext' }
245-
246212
UndocumentedTestTask.new do |t|
247-
t.name = 'do_test_ext'
213+
t.name = :test
248214
t.test_files = FileList['test/json/*_test.rb']
249215
t.verbose = true
250216
t.options = '-v'
251217
end
252218

219+
desc "Testing library (extension)"
220+
task :test => [ :compile ]
221+
253222
begin
254223
require "ruby_memcheck"
255-
RubyMemcheck::TestTask.new(valgrind: [ :set_env_ext, :check_env, :compile, :do_test_ext ]) do |t|
224+
RubyMemcheck::TestTask.new(valgrind: [ :compile, :test ]) do |t|
256225
t.test_files = FileList['test/json/*_test.rb']
257226
t.verbose = true
258227
t.options = '-v'

json_pure.gemspec

+2-21
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,7 @@ Gem::Specification.new do |s|
2323
"LEGAL",
2424
"README.md",
2525
"json_pure.gemspec",
26-
"lib/json.rb",
27-
"lib/json/add/bigdecimal.rb",
28-
"lib/json/add/complex.rb",
29-
"lib/json/add/core.rb",
30-
"lib/json/add/date.rb",
31-
"lib/json/add/date_time.rb",
32-
"lib/json/add/exception.rb",
33-
"lib/json/add/ostruct.rb",
34-
"lib/json/add/range.rb",
35-
"lib/json/add/rational.rb",
36-
"lib/json/add/regexp.rb",
37-
"lib/json/add/set.rb",
38-
"lib/json/add/struct.rb",
39-
"lib/json/add/symbol.rb",
40-
"lib/json/add/time.rb",
41-
"lib/json/common.rb",
42-
"lib/json/ext.rb",
43-
"lib/json/generic_object.rb",
4426
"lib/json/pure.rb",
45-
"lib/json/pure/generator.rb",
46-
"lib/json/pure/parser.rb",
47-
"lib/json/version.rb",
4827
]
4928
s.homepage = "https://ruby.github.io/json"
5029
s.metadata = {
@@ -56,5 +35,7 @@ Gem::Specification.new do |s|
5635
'wiki_uri' => 'https://github.com/ruby/json/wiki'
5736
}
5837

38+
s.add_dependency "json"
39+
5940
s.required_ruby_version = Gem::Requirement.new(">= 2.7")
6041
end

lib/json.rb

+1-6
Original file line numberDiff line numberDiff line change
@@ -583,10 +583,5 @@
583583
#
584584
module JSON
585585
require 'json/version'
586-
587-
begin
588-
require 'json/ext'
589-
rescue LoadError
590-
require 'json/pure'
591-
end
586+
require 'json/ext'
592587
end

lib/json/common.rb

+3-9
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@ def [](object, opts = {})
3232
JSON.generate(object, opts)
3333
end
3434

35-
# Returns the JSON parser class that is used by JSON. This is either
36-
# JSON::Ext::Parser or JSON::Pure::Parser:
37-
# JSON.parser # => JSON::Ext::Parser
35+
# Returns the JSON parser class that is used by JSON.
3836
attr_reader :parser
3937

4038
# Set the JSON parser class _parser_ to be used by JSON.
@@ -97,14 +95,10 @@ def create_pretty_state
9795
)
9896
end
9997

100-
# Returns the JSON generator module that is used by JSON. This is
101-
# either JSON::Ext::Generator or JSON::Pure::Generator:
102-
# JSON.generator # => JSON::Ext::Generator
98+
# Returns the JSON generator module that is used by JSON.
10399
attr_reader :generator
104100

105-
# Sets or Returns the JSON generator state class that is used by JSON. This is
106-
# either JSON::Ext::Generator::State or JSON::Pure::Generator::State:
107-
# JSON.state # => JSON::Ext::Generator::State
101+
# Sets or Returns the JSON generator state class that is used by JSON.
108102
attr_accessor :state
109103
end
110104

lib/json/ext.rb

+2-4
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,12 @@ module JSON
88
module Ext
99
if RUBY_ENGINE == 'truffleruby'
1010
require 'json/ext/parser'
11-
require 'json/pure'
12-
$DEBUG and warn "Using Ext extension for JSON parser and Pure library for JSON generator."
11+
require 'json/ext/truffle_ruby_generator'
1312
JSON.parser = Parser
14-
JSON.generator = JSON::Pure::Generator
13+
JSON.generator = TruffleRubyGenerator
1514
else
1615
require 'json/ext/parser'
1716
require 'json/ext/generator'
18-
$DEBUG and warn "Using Ext extension for JSON."
1917
JSON.parser = Parser
2018
JSON.generator = Generator
2119
end

0 commit comments

Comments
 (0)