summaryrefslogtreecommitdiff
path: root/ext/json
Commit message (Collapse)AuthorAgeFilesLines
* Implement a freeze: parser optionJean Boussier2020-09-155-45/+126
| | | | | | | If set to true all parsed objects will be immediately frozen, and strings will be deduplicated if the Ruby implementation allows it.
* Add an option to escape forward slash characterJean Boussier2020-07-042-7/+53
| | | | | | | | | | | | | | | | Squashed commit of the following: commit 26d181059989279a79c433cedcd893b4f52e42ee Author: Francois Chagnon <francois.chagnon@jadedpixel.com> Date: Tue Sep 15 21:17:34 2015 +0000 add config options for escape_slash commit fa282334051b16df91ca097dd7304b46f3bc7719 Author: Francois Chagnon <francois.chagnon@jadedpixel.com> Date: Mon Feb 9 21:09:33 2015 +0000 add forward slash to escape character
* Typo fixMarc-Andre Lafortune2020-06-301-1/+1
|
* Merge pull request #420 from marcandre/performance_345Hiroshi SHIBATA2020-06-262-67/+69
|\ | | | | Use frozen string for hash key
| * Use frozen string for hash keyWatson2020-06-252-67/+69
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When use non-frozen string for hash key with `rb_hash_aset()`, it will duplicate and freeze it internally. To avoid duplicate and freeze, this patch will give a frozen string in `rb_hash_aset()`. ``` Warming up -------------------------------------- json 14.000 i/100ms Calculating ------------------------------------- json 148.844 (± 1.3%) i/s - 756.000 in 5.079969s ``` ``` Warming up -------------------------------------- json 16.000 i/100ms Calculating ------------------------------------- json 165.608 (± 1.8%) i/s - 832.000 in 5.025367s ``` ``` require 'json' require 'securerandom' require 'benchmark/ips' obj = [] 1000.times do |i| obj << { "id": i, "uuid": SecureRandom.uuid, "created_at": Time.now } end json = obj.to_json Benchmark.ips do |x| x.report "json" do |iter| count = 0 while count < iter JSON.parse(json) count += 1 end end end ```
* | ext/json/parser/prereq.mk: remove type-limit warning if char is unsignedYusuke Endoh2020-06-251-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Ragel generates a code `0 <= (*p)` where `*p` is char. As char is unsigned by default on arm and RISC-V, it is warned by gcc: ``` compiling parser.c parser.c: In function ‘JSON_parse_string’: parser.c:1566:2: warning: comparison is always true due to limited range of data type [-Wtype-limits] if ( 0 <= (*p) && (*p) <= 31 ) ^ parser.c:1596:2: warning: comparison is always true due to limited range of data type [-Wtype-limits] if ( 0 <= (*p) && (*p) <= 31 ) ^ ``` This change removes the warning by substituting the condition with `0 <= (signed char)(*p)`. ruby/ruby@8bd27c547c3260ce72dc5edbab248bb858c84cf2
* | ext/json/parser/prereq.mk: Add a "automatically generated" headerYusuke Endoh2020-06-251-1/+1
|/ | | | | | | to parser.c. ruby/ruby@5717e55e9a7790c938afa694a9bf558c0e54bb83 ruby/ruby@70e3fda2eb45c841e5fb4574273d20f8df5455e5
* Merge pull request #349 from zverok/nodocSHIBATA Hiroshi2019-12-291-0/+70
|\ | | | | Add :nodoc: for GeneratorMethods
| * Add :nodoc: for GeneratorMethodszverok2018-03-081-0/+70
| |
* | relax test-unit version for old rubyHiroshi SHIBATA2019-11-291-1/+1
| |
* | Add NaN / Infinity / MinusInfinity to mark listAaron Patterson2019-10-311-0/+5
| | | | | | | | This prevents the constants from moving.
* | ext/json/parser/prereq.mk: Add a "automatically generated" headerYusuke Endoh2019-10-311-1/+1
| | | | | | | | to parser.c.
* | ext/json/parser/parser.rl: Use "signed" char to contain negative valuesYusuke Endoh2019-10-312-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | char is not always signed. In fact, it is unsigned in arm. https://rubyci.org/logs/rubyci.s3.amazonaws.com/scw-9d6766/ruby-master/log/20191004T181708Z.log.html.gz ``` compiling parser.c parser.rl: In function ‘unescape_unicode’: parser.rl:50:5: warning: comparison is always false due to limited range of data type [-Wtype-limits] if (b < 0) return UNI_REPLACEMENT_CHAR; ^ ```
* | Add `GC.compact` again.tenderlove2019-10-312-0/+4
| | | | | | | | | | | | 🙏 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67620 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* | ext/json/parser/parser.rl: Update the source code of parser.cYusuke Endoh2019-10-311-1/+8
| | | | | | | | | | | | | | | | | | There have been some direct changes in parser.c which is automatically generated from parser.rl. This updates parser.rl to sync the changes: * 91793b8967e0531bd1159a8ff0cc7e50739c7620 * 79ead821dd4880725c9c6bb9645b3fad71715c5b * 80b5a0ff2a7709367178f29d4ebe1c54122b1c27
* | Suppress uninitialized instance variable warningsNobuyoshi Nakada2019-10-311-1/+1
| |
* | [flori/json] Fixed unexpected illegal/malformed utf-8 errorNobuyoshi Nakada2019-10-311-1/+10
| | | | | | | | | | | | | | | | flori/json@c34d01ff6a18dac04a90b2e0f820cdb1d5c7e1b2 does not consider US-ASCII compatible but non-UTF-8 encodings, and causes an error in RDoc tests. https://github.com/flori/json/commit/4f471bf590
* | Make rb_scan_args handle keywords more similar to Ruby methods (#2460)Jeremy Evans2019-10-311-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Cfuncs that use rb_scan_args with the : entry suffer similar keyword argument separation issues that Ruby methods suffer if the cfuncs accept optional or variable arguments. This makes the following changes to : handling. * Treats as **kw, prompting keyword argument separation warnings if called with a positional hash. * Do not look for an option hash if empty keywords are provided. For backwards compatibility, treat an empty keyword splat as a empty mandatory positional hash argument, but emit a a warning, as this behavior will be removed in Ruby 3. The argument number check needs to be moved lower so it can correctly handle an empty positional argument being added. * If the last argument is nil and it is necessary to treat it as an option hash in order to make sure all arguments are processed, continue to treat the last argument as the option hash. Emit a warning in this case, as this behavior will be removed in Ruby 3. * If splitting the keyword hash into two hashes, issue a warning, as we will not be splitting hashes in Ruby 3. * If the keyword argument is required to fill a mandatory positional argument, continue to do so, but emit a warning as this behavior will be going away in Ruby 3. * If keyword arguments are provided and the last argument is not a hash, that indicates something wrong. This can happen if a cfunc is calling rb_scan_args multiple times, and providing arguments that were not passed to it from Ruby. Callers need to switch to the new rb_scan_args_kw function, which allows passing of whether keywords were provided. This commit fixes all warnings caused by the changes above. It switches some function calls to *_kw versions with appropriate kw_splat flags. If delegating arguments, RB_PASS_CALLED_KEYWORDS is used. If creating new arguments, RB_PASS_KEYWORDS is used if the last argument is a hash to be treated as keywords. In open_key_args in io.c, use rb_scan_args_kw. In this case, the arguments provided come from another C function, not Ruby. The last argument may or may not be a hash, so we can't set keyword argument mode. However, if it is a hash, we don't want to warn when treating it as keywords. In Ruby files, make sure to appropriately use keyword splats or literal keywords when calling Cfuncs that now issue keyword argument separation warnings through rb_scan_args. Also, make sure not to pass nil in place of an option hash. Work around Kernel#warn warnings due to problems in the Rubygems override of the method. There is an open pull request to fix these issues in Rubygems, but part of the Rubygems tests for their override fail on ruby-head due to rb_scan_args not recognizing empty keyword splats, which this commit fixes. Implementation wise, adding rb_scan_args_kw is kind of a pain, because rb_scan_args takes a variable number of arguments. In order to not duplicate all the code, the function internals need to be split into two functions taking a va_list, and to avoid passing in a ton of arguments, a single struct argument is used to handle the variables previously local to the function.
* | Remove unused constant.Aaron Patterson2019-10-311-2/+1
| | | | | | | | This constant isn't used, so lets remove it.
* | Look up constant instead of caching in a globalAaron Patterson2019-10-311-6/+3
| | | | | | | | | | The global can go bad if the compactor runs, so we need to look up the constant instead of caching it in a global.
* | Merge pull request #367 from sho-h/add-ascii_only-documentFlorian Frank2019-07-131-0/+2
|\ \ | | | | | | Add ascii_only option to JSON::Ext::Generator::State.new.
| * | Add ascii_only option to JSON::Ext::Generator::State.new.Sho Hashimoto2019-01-081-0/+2
| | |
* | | Merge branch 'master' of github.com:flori/jsonFlorian Frank2019-04-293-78/+119
|\ \ \
| * \ \ Merge pull request #366 from sho-h/fix-ascii_only-documentFlorian Frank2019-02-211-1/+1
| |\ \ \ | | | | | | | | | | fix JSON::Generator::State#ascii_only? document same as lib/json/pure/generator.rb.
| | * | | fix JSON::Generator::State#ascii_only? document same as ↵Sho Hashimoto2019-01-081-1/+1
| | |/ / | | | | | | | | | | | | lib/json/pure/generator.rb.
| * | | Add some missing ruby 2.6 changesFlorian Frank2019-02-213-88/+94
| |/ /
| * | Merge pull request #362 from mrkn/update_for_bigdecimalSHIBATA Hiroshi2018-12-202-4/+38
| |\ \ | | | | | | | | Fix for bigdecimal updates
| | * | Fix for bigdecimal updatesKenta Murata2018-12-022-4/+38
| | |/ | | | | | | | | | `BigDecimal.new` is no longer available from bigdecimal-1.4.0.
| * | ext/json/parser/parser.c: do not call rb_str_resize() on Time objectpick-ruby-coreeregon2018-10-252-10/+14
| | | | | | | | | | | | | | | | | | * See https://github.com/flori/json/issues/342 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64177 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
| * | Fix missed update of parser source in r62429eregon2018-10-251-0/+1
| |/ | | | | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64175 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* | Does not check whether illegal utf-8 if string has ascii only.Watson2019-04-291-8/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ## Before ``` $ ruby bench_json_generate.rb Warming up -------------------------------------- json 25.000 i/100ms Calculating ------------------------------------- json 250.478 (± 4.8%) i/s - 1.250k in 5.002238s ``` ## After ``` $ ruby bench_json_generate.rb Warming up -------------------------------------- json 32.000 i/100ms Calculating ------------------------------------- json 360.652 (± 3.6%) i/s - 1.824k in 5.064511s ``` ## Test code ``` require 'json' require 'benchmark/ips' obj = [] 1000.times do |i| obj << { :string => "x" * 100, :utf8 => "あ" * 100 } end Benchmark.ips do |x| x.report "json" do |iter| count = 0 while count < iter JSON.generate(obj) count += 1 end end end ```
* | Convert string encoding to UTF-8 only when neededWatson2019-04-291-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ## Before ``` $ ruby bench_json_generate.rb Warming up -------------------------------------- json 129.000 i/100ms Calculating ------------------------------------- json 1.300k (± 2.3%) i/s - 6.579k in 5.064656s ``` ## After ``` $ ruby bench_json_generate.rb Warming up -------------------------------------- json 189.000 i/100ms Calculating ------------------------------------- json 1.964k (± 3.3%) i/s - 9.828k in 5.011237s ``` ## Code ``` require 'json' require 'benchmark/ips' obj = [] 1000.times do |i| obj << { "id" => i, :age => 42, } end Benchmark.ips do |x| x.report "json" do |iter| count = 0 while count < iter JSON.generate(obj) count += 1 end end end ```
* | Convert String encoding using `rb_str_encode()`Watson2019-04-291-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | `rb_funcall` might be slightly heavy to call the Ruby method. This patch will convert String encoding using `rb_str_encode()` instead of `rb_funcall()`. ## Before ``` $ ruby bench_json_generate.rb Warming up -------------------------------------- json 78.000 i/100ms Calculating ------------------------------------- json 789.781 (± 2.7%) i/s - 3.978k in 5.041043s ``` ## After ``` $ ruby bench_json_generate.rb Warming up -------------------------------------- json 129.000 i/100ms Calculating ------------------------------------- json 1.300k (± 2.3%) i/s - 6.579k in 5.064656s ``` ## Code ``` require 'json' require 'benchmark/ips' obj = [] 1000.times do |i| obj << { "id" => i, :age => 42, } end Benchmark.ips do |x| x.report "json" do |iter| count = 0 while count < iter JSON.generate(obj) count += 1 end end end ```
* | Add shortcut converting to StringWatson2019-04-291-2/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In where to convert Hash key to String for json, this patch will add shortcut for String/Symbol in Hash key. ``` $ ruby bench_json_generate.rb Warming up -------------------------------------- json 65.000 i/100ms Calculating ------------------------------------- json 659.576 (± 1.5%) i/s - 3.315k in 5.027127s ``` ``` $ ruby bench_json_generate.rb Warming up -------------------------------------- json 78.000 i/100ms Calculating ------------------------------------- json 789.781 (± 2.7%) i/s - 3.978k in 5.041043s ``` ``` require 'json' require 'benchmark/ips' obj = [] 1000.times do |i| obj << { "id" => i, :age => 42, } end Benchmark.ips do |x| x.report "json" do |iter| count = 0 while count < iter JSON.generate(obj) count += 1 end end end ```
* | Convert Hash object using rb_hash_foreach()Watson2019-04-291-22/+55
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | To convert Hash convert, this part was using following pseudo code ``` obj.keys.each do |key| value = obj[key] ... end ``` and `rb_funcall()` was called for `obj.keys`. It might be slightly heavy to call the Ruby method. This patch will iterate to convert Hash object about key/value using `rb_hash_foreach()` Ruby API instead of `rb_funcall()`. ``` $ ruby bench_json_generate.rb Warming up -------------------------------------- json 55.000 i/100ms Calculating ------------------------------------- json 558.501 (± 1.1%) i/s - 2.805k in 5.022986s ``` ``` $ ruby bench_json_generate.rb Warming up -------------------------------------- json 65.000 i/100ms Calculating ------------------------------------- json 659.576 (± 1.5%) i/s - 3.315k in 5.027127s ``` ``` require 'json' require 'benchmark/ips' obj = [] 1000.times do |i| obj << { "id" => i, :age => 42, } end Benchmark.ips do |x| x.report "json" do |iter| count = 0 while count < iter JSON.generate(obj) count += 1 end end end ```
* | Only attempt to resize strings not other objectsFlorian Frank2019-04-292-2/+2
|/
* Test the new feature and fix problemsFlorian Frank2017-04-182-31/+31
| | | | | | - Initialize i_new - Add to changes - Test on ruby 2.4.1
* Raise exceptionFlorian Frank2017-04-182-21/+37
| | | | for incomplete unicode surrogates/character escape sequences
* Fix arbitrary heap exposure problemFlorian Frank2017-04-182-7/+6
|
* Remove unused macroFlorian Frank2017-01-221-3/+0
|
* Support some older internal Ruby API (<2.0)Florian Frank2017-01-122-1142/+1300
|
* Merge decimal_class patch by Michael JaschobFlorian Frank2016-09-233-1304/+1181
| | | | | | Also: - Avoid some issues with bundler - Avoid some issues with jruby
* Merge branch 'master' of github.com:flori/jsonFlorian Frank2016-07-261-0/+1
|\
| * Suppress a warningNobuyoshi Nakada2016-07-081-0/+1
| | | | | | Suppress a unused-but-set-variable warning by gcc.
* | Fix issue #296 when parsing frozen stringsFlorian Frank2016-07-262-8/+14
|/
* Stores current nesting on stackFlorian Frank2016-07-013-87/+76
|
* RB_GC_GUARD to protect from premature GCPete Johns2016-07-011-0/+1
| | | | https://github.com/ruby/ruby/blob/trunk/doc/extension.rdoc#appendix-e-rb_gc_guard-to-protect-from-premature-gc
* Fix some merge problemsFlorian Frank2016-06-212-124/+0
|
* Optional hash in rb_scan_argsNobuyoshi Nakada2016-06-211-0/+32
| | | | | Use ':' in rb_scan_args to get optional hash, which available since ruby 2.1.
* Exception encodingNobuyoshi Nakada2016-06-212-2/+34
| | | | Raise with messages in UTF-8 encoding.