summaryrefslogtreecommitdiff
path: root/ext/json/generator
AgeCommit message (Collapse)Author
28 hours[ruby/json] Remove trailing spaces [ci skip]Nobuyoshi Nakada
https://github.com/ruby/json/commit/15eb40dbdf
32 hours[ruby/json] initialize search.chunk_end to silence a warning about it being ↵Scott Myron
potentially uninitialized https://github.com/ruby/json/commit/73818b80c8
32 hours[ruby/json] use a conditional to select SIMD implementation rather than pointerScott Myron
https://github.com/ruby/json/commit/86a5cce405
2025-12-03[ruby/json] Fix handling of depthÉtienne Barrié
https://github.com/ruby/json/commit/ccca602274
2025-12-03[ruby/json] Test and restore behavior around to_json changing depthÉtienne Barrié
When serializing an Array, and one of the elements of the Array requires calling `to_json`, if the depth is changed, it will be used for the next entries, which wasn't the case before https://github.com/ruby/json/commit/5abd43490714, and is not the case with TruffleRuby and JRuby. Additionally, with TruffleRuby and JRuby the state's depth after the `to_json` call is used to close the Array, which isn't the case with CRuby. https://github.com/ruby/json/commit/386b36fde5
2025-12-03[ruby/json] Fix macro argumentsNobuyoshi Nakada
`ALWAYS_INLINE()` and `NOINLINE()` are defined with one argument. https://github.com/ruby/json/commit/8fb727901e
2025-11-27[ruby/json] Respect Coder depth when generatingÉtienne Barrié
https://github.com/ruby/json/commit/9c36681b17
2025-11-26[ruby/json] Don't copy JSON_Generator_State in generate_newÉtienne Barrié
Now that the state isn't mutated in generate_new, we no longer need to copy the struct, we can just use it. https://github.com/ruby/json/commit/d7964f8892
2025-11-26[ruby/json] Don't write depth to JSON_Generator_State in some casesÉtienne Barrié
For `JSON.generate` and `JSON::State#generate_new`, don't copy generate_json_data::depth to JSON_Generator_State::depth. In `JSON.generate`, the JSON_Generator_State is on the stack and discarded anyway. In `JSON::State#generate_new`, we copy the struct to avoid mutating the original one. https://github.com/ruby/json/commit/873b29ea34
2025-11-26[ruby/json] Add depth to struct generate_json_dataÉtienne Barrié
Instead of incrementing JSON_Generator_State::depth, we now increment generate_json_data::depth, and only copied at the end. https://github.com/ruby/json/commit/5abd434907
2025-11-21[ruby/json] Move RUBY_TYPED_FROZEN_SHAREABLE macro to json.hÉtienne Barrié
https://github.com/ruby/json/commit/2a4ebe8250
2025-11-21[ruby/json] Ractor-shareable JSON::CoderÉtienne Barrié
https://github.com/ruby/json/commit/58d60d6b76
2025-11-20[ruby/json] Remove unused symbolsÉtienne Barrié
https://github.com/ruby/json/commit/9364d0c761
2025-11-18[ruby/json] Use #if instead of #ifdef when checking for JSON_DEBUG so ↵Scott Myron
debugging code is not generated when JSON_DEBUG=0. https://github.com/ruby/json/commit/4f1adb10d3
2025-11-03[ruby/json] Fix duplicate 'inline' declaration specifierJean Boussier
Followup: https://github.com/ruby/json/pull/889 https://github.com/ruby/json/commit/591510392a
2025-11-03[ruby/json] Fix check_dependencyTakashi Kokubun
2025-11-03[ruby/json] Centralize macro definitionsJean Boussier
https://github.com/ruby/json/commit/1576ea7d47
2025-11-02[ruby/json] Invoke `as_json` callback for strings with invalid encodingJean Boussier
Fix: https://github.com/ruby/json/issues/873 This allow users to encode binary strings if they so wish. e.g. they can use Base64 or similar, or chose to replace invalid characters with something else. https://github.com/ruby/json/commit/b1b16c416f
2025-10-31[ruby/json] Fix memory leak when exception is raised during JSON generation ↵Kazuki Yamaguchi
part 2 Commit https://github.com/ruby/json/commit/44df509dc2de fixed it for StandardError, but other exceptions and jumps are also possible. Use rb_ensure() to release FBuffer instead of rb_rescue(). A reproducer: o = Object.new def o.to_json(a) = throw :a a = ["make heap allocation"*100, o] 10.times do 100_000.times do catch(:a) { JSON(a) } end puts `ps -o rss= -p #{$$}` end https://github.com/ruby/json/commit/9b7b648ecd
2025-10-30[ruby/json] Fix GeneratorError messages to be UTF-8 encodedJean Boussier
https://github.com/ruby/json/commit/965ba6c5d4
2025-10-25[ruby/json] Fix concurrent usage of JSON::Coder#dumpJean Boussier
Fix: https://github.com/rails/rails/commit/90616277e3d8fc46c9cf35d6a7470ff1ea0092f7#r168784389 Because the `depth` counter is inside `JSON::State` it can't be used concurrently, and in case of a circular reference the counter may be left at the max value. The depth counter should be moved outside `JSON_Generator_State` and into `struct generate_json_data`, but it's a larger refactor. In the meantime, `JSON::Coder` calls `State#generate_new` so I changed that method so that it first copy the state on the stack. https://github.com/ruby/json/commit/aefa671eca
2025-09-19`JSON::Coder` callback now recieve a second argument to mark object keysJean Boussier
e.g. ```ruby { 1 => 2 } ``` The callback will be invoked for `1` as while it has a native JSON equivalent, it's not legal as an object name.
2025-09-19[ruby/json] Avoid scientific notation before exponent 15Jean Boussier
Fix: https://github.com/ruby/json/issues/861 It's not incorrect to use scientific notation, but it tend to throw people off a bit, so it's best to keep it for very large numbers. https://github.com/ruby/json/commit/1566cd01a6
2025-09-03[ruby/json] Fix a -Wreturn-type warningJean Boussier
Fix: https://github.com/ruby/json/pull/843 https://github.com/ruby/json/commit/d3f7f0452b Co-Authored-By: Takashi Kokubun <takashikkbn@gmail.com>
2025-08-27JSON.generate: warn or raise on duplicated keyJean Boussier
Because both strings and symbols keys are serialized the same, it always has been possible to generate documents with duplicated keys: ```ruby >> puts JSON.generate({ foo: 1, "foo" => 2 }) {"foo":1,"foo":2} ``` This is pretty much always a mistake and can cause various issues because it's not guaranteed how various JSON parsers will handle this. Until now I didn't think it was possible to catch such case without tanking performance, hence why I only made the parser more strict. But I finally found a way to check for duplicated keys cheaply enough.
2025-08-27Fix `JSON::Coder` to cast non-string keys.Jean Boussier
2025-08-27Fix `JSON.generate` `strict: true` mode to also restrict hash keysJean Boussier
2025-08-27[ruby/json] Extract `fbuffer_append_str_repeat` functionJean Boussier
https://github.com/ruby/json/commit/12656777dc
2025-08-18Fix typosDouglas Eichelberger
2025-08-04Only define `String.json_create` & al when `json/add` is requiredJean Boussier
All the `json/add` related methods for string were always defined unconditionally from the generators. It's preferable to only define them if `json/add` is actually used.
2025-07-25[ruby/json] Fix missing write barrier on Generator StateJohn Hawthorn
Found by wbcheck WBCHECK ERROR: Missed write barrier detected! Parent object: 0x7b7b8487c450 (wb_protected: true) rb_obj_info_dump: 0x00007b7b8487c450 JSON/Generator/State/JSON::Ext::Generator::State JSON/Generator/State Reference counts - snapshot: 1, writebarrier: 0, current: 6, missed: 5 Missing reference to: 0x7b7b82f35a10 rb_obj_info_dump: 0x00007b7b82f35a10 T_STRING/String len: 1, capa: 15 "1" Missing reference to: 0x7b7b82f35e90 rb_obj_info_dump: 0x00007b7b82f35e90 T_STRING/String len: 1, capa: 15 "2" Missing reference to: 0x7b7b83629e50 rb_obj_info_dump: 0x00007b7b83629e50 T_STRING/String len: 1, capa: 15 "3" Missing reference to: 0x7b7b83b62190 rb_obj_info_dump: 0x00007b7b83b62190 T_STRING/String len: 1, capa: 15 "4" Missing reference to: 0x7b7b83629490 rb_obj_info_dump: 0x00007b7b83629490 T_STRING/String len: 1, capa: 15 "5" https://github.com/ruby/json/commit/c24342d801
2025-07-11Update dependencies for addition of set.h to public headersJeremy Evans
2025-07-07[ruby/json] Improve consistency of code styleJean Boussier
https://github.com/ruby/json/commit/a497c71960
2025-07-01[ruby/json] Use `load` simd/conf.rbNobuyoshi Nakada
When both extconf.rb of generator and parser are run in one process, the second `require_relative` does nothing. https://github.com/ruby/json/commit/8e775320b7
2025-06-30ruby tool/update-deps --fixHiroshi SHIBATA
2025-06-30[ruby/json] Reduce duplication in extconf.rbJean Boussier
https://github.com/ruby/json/commit/3ae3eeb9d3
2025-06-30Optimize 'json_parse_string' using SIMD.Scott Myron
2025-06-24[ruby/json] Remove trailing spaces [ci skip]Nobuyoshi Nakada
https://github.com/ruby/json/commit/6c41162522
2025-05-26[ruby/json] Release 2.12.2Jean Boussier
https://github.com/ruby/json/commit/a29cb77d52
2025-05-26[ruby/json] fbuffer.c: add debug mode with bound checks.Jean Boussier
This would have caught https://github.com/ruby/json/pull/808 on CI. https://github.com/ruby/json/commit/8109421fb4
2025-05-26[ruby/json] Fix: generate_json_float to reserve enough memory for large ↵Jean Boussier
negative floats. Fix: https://github.com/ruby/json/issues/807 Since https://github.com/ruby/json/pull/800, `fpconv_dtoa` can actually generate up to 28 chars. https://github.com/ruby/json/commit/d73ae93d3c
2025-05-01Sync ruby/jsonJean Boussier
Fix: https://github.com/ruby/json/issues/796 Notes: Merged: https://github.com/ruby/ruby/pull/13227
2025-04-30[ruby/json] Remove explicit include of extconf.hJean Boussier
https://github.com/ruby/json/commit/6b059900de .
2025-04-30[ruby/json] Fix --with-static-linked-ext buildsJean Boussier
https://github.com/ruby/json/commit/d7d60cccb0
2025-04-30[ruby/json] Fix i686 buildsJean Boussier
We should test compilation with `-msse2` because we need to test with whatever arguments Ruby will be compiled with. https://github.com/ruby/json/commit/0a871365db
2025-04-30[ruby/json] SIMD: Match control char and double quote in one passJean Boussier
`c < 32 || c == 34` is equivalent to `c ^ 2 < 33`. Found in: https://lemire.me/blog/2025/04/13/detect-control-characters-quotes-and-backslashes-efficiently-using-swar/ The gain seem mostly present on micro-benchmark, and even there aren't very consistent, but it's never slower. ``` == Encoding long string (124001 bytes) ruby 3.4.2 (2025-02-15 revision https://github.com/ruby/json/commit/d2930f8e7a) +YJIT +PRISM [arm64-darwin24] Warming up -------------------------------------- after 5.295k i/100ms Calculating ------------------------------------- after 55.796k (± 3.4%) i/s (17.92 μs/i) - 280.635k in 5.035690s Comparison: before: 49840.7 i/s after: 55795.8 i/s - 1.12x faster ``` https://github.com/ruby/json/commit/034c5debd8
2025-04-30Update ext/json/generator/dependJean Boussier
2025-04-30[ruby/json] Introduce ARM Neon and SSE2 SIMD.Scott Myron
(https://github.com/ruby/json/pull/743) See the pull request for the long development history: https://github.com/ruby/json/pull/743 ``` == Encoding activitypub.json (52595 bytes) ruby 3.4.2 (2025-02-15 revision https://github.com/ruby/json/commit/d2930f8e7a) +YJIT +PRISM [arm64-darwin24] Warming up -------------------------------------- after 2.913k i/100ms Calculating ------------------------------------- after 29.377k (± 2.0%) i/s (34.04 μs/i) - 148.563k in 5.059169s Comparison: before: 23314.1 i/s after: 29377.3 i/s - 1.26x faster == Encoding citm_catalog.json (500298 bytes) ruby 3.4.2 (2025-02-15 revision https://github.com/ruby/json/commit/d2930f8e7a) +YJIT +PRISM [arm64-darwin24] Warming up -------------------------------------- after 152.000 i/100ms Calculating ------------------------------------- after 1.569k (± 0.8%) i/s (637.49 μs/i) - 7.904k in 5.039001s Comparison: before: 1485.6 i/s after: 1568.7 i/s - 1.06x faster == Encoding twitter.json (466906 bytes) ruby 3.4.2 (2025-02-15 revision https://github.com/ruby/json/commit/d2930f8e7a) +YJIT +PRISM [arm64-darwin24] Warming up -------------------------------------- after 309.000 i/100ms Calculating ------------------------------------- after 3.115k (± 3.1%) i/s (321.01 μs/i) - 15.759k in 5.063776s Comparison: before: 2508.3 i/s after: 3115.2 i/s - 1.24x faster ``` https://github.com/ruby/json/commit/49003523da
2025-04-30[ruby/json] Use RB_TYPE_PJean Boussier
https://github.com/ruby/json/commit/b14250f1da
2025-04-30[ruby/json] Handle non-string keys returning immediate values via `to_s`Jean Boussier
We can't directly call `RBASIC_CLASS` as the return value of `to_s` may be an immediate. https://github.com/ruby/json/commit/12dc394d11