Skip to content

Commit

Permalink
Turn json_pure into an empty gem
Browse files Browse the repository at this point in the history
Fix: ruby#650
Closes: ruby#682
  • Loading branch information
byroot committed Nov 5, 2024
1 parent f373b8c commit 987f6be
Show file tree
Hide file tree
Showing 15 changed files with 175 additions and 636 deletions.
6 changes: 1 addition & 5 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
source 'https://rubygems.org'

if ENV['JSON'] == 'pure'
gemspec name: 'json_pure'
else
gemspec name: 'json'
end
gemspec name: 'json'

group :development do
gem "ruby_memcheck" if RUBY_PLATFORM =~ /linux/i
Expand Down
12 changes: 3 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,10 @@
## Description

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

* A pure ruby variant, that relies on the `strscan` extensions, which is
part of the ruby standard library.
* The quite a bit faster native extension variant, which is in parts
implemented in C or Java and comes with a parser generated by the [Ragel]
state machine compiler.

Both variants of the JSON generator generate UTF-8 character sequences by
default. If an :ascii\_only option with a true value is given, they escape all
The JSON generator generate UTF-8 character sequences by default.
If an :ascii\_only option with a true value is given, they escape all
non-ASCII and control characters with \uXXXX escape sequences, and support
UTF-16 surrogate pairs in order to be able to generate the whole range of
unicode code points.
Expand Down
51 changes: 10 additions & 41 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,8 @@ else
RAGEL_DOTGEN = %w[rlgen-dot rlgen-cd ragel].find(&which)
end

desc "Installing library (pure)"
task :install_pure do
ruby 'install.rb'
end

task :install_ext_really do
desc "Installing library (extension)"
task :install => [ :compile ] do
sitearchdir = CONFIG["sitearchdir"]
cd 'ext' do
for file in Dir["json/ext/*.#{CONFIG['DLEXT']}"]
Expand All @@ -73,30 +69,6 @@ task :install_ext_really do
end
end

desc "Installing library (extension)"
task :install_ext => [ :compile, :install_pure, :install_ext_really ]

desc "Installing library (extension)"
task :install => :install_ext

task :check_env do
ENV.key?('JSON') or fail "JSON env var is required"
end

desc "Testing library (pure ruby)"
task :test_pure => [ :set_env_pure, :check_env, :do_test_pure ]
task(:set_env_pure) { ENV['JSON'] = 'pure' }

UndocumentedTestTask.new do |t|
t.name = 'do_test_pure'
t.test_files = FileList['test/json/*_test.rb']
t.verbose = true
t.options = '-v'
end

desc "Testing library (pure ruby and extension)"
task :test => [ :test_pure, :test_ext ]

namespace :gems do
desc 'Install all development gems'
task :install do
Expand Down Expand Up @@ -177,16 +149,14 @@ if defined?(RUBY_ENGINE) and RUBY_ENGINE == 'jruby'
sh "gem build -o pkg/json-#{PKG_VERSION}-java.gem json.gemspec"
end

desc "Testing library (jruby)"
task :test_ext => [ :set_env_ext, :create_jar, :check_env, :do_test_ext ]
task(:set_env_ext) { ENV['JSON'] = 'ext' }

UndocumentedTestTask.new do |t|
t.name = 'do_test_ext'
t.name = :test
t.test_files = FileList['test/json/*_test.rb']
t.verbose = true
t.options = '-v'
end
desc "Testing library (jruby)"
task :test => [:create_jar ]

file JRUBY_PARSER_JAR => :compile do
cd 'java/src' do
Expand Down Expand Up @@ -239,20 +209,19 @@ else
task :compile => [ :ragel, EXT_PARSER_DL, EXT_GENERATOR_DL ]
end

desc "Testing library (extension)"
task :test_ext => [ :set_env_ext, :check_env, :compile, :do_test_ext ]
task(:set_env_ext) { ENV['JSON'] = 'ext' }

UndocumentedTestTask.new do |t|
t.name = 'do_test_ext'
t.name = :test
t.test_files = FileList['test/json/*_test.rb']
t.verbose = true
t.options = '-v'
end

desc "Testing library (extension)"
task :test => [ :compile ]

begin
require "ruby_memcheck"
RubyMemcheck::TestTask.new(valgrind: [ :set_env_ext, :check_env, :compile, :do_test_ext ]) do |t|
RubyMemcheck::TestTask.new(valgrind: [ :compile, :test ]) do |t|
t.test_files = FileList['test/json/*_test.rb']
t.verbose = true
t.options = '-v'
Expand Down
23 changes: 2 additions & 21 deletions json_pure.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,7 @@ Gem::Specification.new do |s|
"LEGAL",
"README.md",
"json_pure.gemspec",
"lib/json.rb",
"lib/json/add/bigdecimal.rb",
"lib/json/add/complex.rb",
"lib/json/add/core.rb",
"lib/json/add/date.rb",
"lib/json/add/date_time.rb",
"lib/json/add/exception.rb",
"lib/json/add/ostruct.rb",
"lib/json/add/range.rb",
"lib/json/add/rational.rb",
"lib/json/add/regexp.rb",
"lib/json/add/set.rb",
"lib/json/add/struct.rb",
"lib/json/add/symbol.rb",
"lib/json/add/time.rb",
"lib/json/common.rb",
"lib/json/ext.rb",
"lib/json/generic_object.rb",
"lib/json/pure.rb",
"lib/json/pure/generator.rb",
"lib/json/pure/parser.rb",
"lib/json/version.rb",
]
s.homepage = "https://ruby.github.io/json"
s.metadata = {
Expand All @@ -56,5 +35,7 @@ Gem::Specification.new do |s|
'wiki_uri' => 'https://github.com/ruby/json/wiki'
}

s.add_dependency "json"

s.required_ruby_version = Gem::Requirement.new(">= 2.7")
end
7 changes: 1 addition & 6 deletions lib/json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -583,10 +583,5 @@
#
module JSON
require 'json/version'

begin
require 'json/ext'
rescue LoadError
require 'json/pure'
end
require 'json/ext'
end
12 changes: 3 additions & 9 deletions lib/json/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ def [](object, opts = {})
JSON.generate(object, opts)
end

# Returns the JSON parser class that is used by JSON. This is either
# JSON::Ext::Parser or JSON::Pure::Parser:
# JSON.parser # => JSON::Ext::Parser
# Returns the JSON parser class that is used by JSON.
attr_reader :parser

# Set the JSON parser class _parser_ to be used by JSON.
Expand Down Expand Up @@ -97,14 +95,10 @@ def create_pretty_state
)
end

# Returns the JSON generator module that is used by JSON. This is
# either JSON::Ext::Generator or JSON::Pure::Generator:
# JSON.generator # => JSON::Ext::Generator
# Returns the JSON generator module that is used by JSON.
attr_reader :generator

# Sets or Returns the JSON generator state class that is used by JSON. This is
# either JSON::Ext::Generator::State or JSON::Pure::Generator::State:
# JSON.state # => JSON::Ext::Generator::State
# Sets or Returns the JSON generator state class that is used by JSON.
attr_accessor :state
end

Expand Down
6 changes: 2 additions & 4 deletions lib/json/ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@ module JSON
module Ext
if RUBY_ENGINE == 'truffleruby'
require 'json/ext/parser'
require 'json/pure'
$DEBUG and warn "Using Ext extension for JSON parser and Pure library for JSON generator."
require 'json/truffle_ruby/generator'
JSON.parser = Parser
JSON.generator = JSON::Pure::Generator
JSON.generator = ::JSON::TruffleRuby::Generator
else
require 'json/ext/parser'
require 'json/ext/generator'
$DEBUG and warn "Using Ext extension for JSON."
JSON.parser = Parser
JSON.generator = Generator
end
Expand Down
16 changes: 2 additions & 14 deletions lib/json/pure.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
# frozen_string_literal: true
require 'json/common'

module JSON
# This module holds all the modules/classes that implement JSON's
# functionality in pure ruby.
module Pure
require 'json/pure/parser'
require 'json/pure/generator'
$DEBUG and warn "Using Pure library for JSON."
JSON.parser = Parser
JSON.generator = Generator
end

JSON_LOADED = true unless defined?(::JSON::JSON_LOADED)
end
warn "`json_pure` is deprecated and has no effect, just use `json`"
require "json"
Loading

0 comments on commit 987f6be

Please sign in to comment.