json 2.13.0 → 2.13.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 41dcbe399cb5dd00e62d93c87f31b356674c1feb9430306902009ebf8f56bd9a
4
- data.tar.gz: f398e819143dc90c162474b5c97241d7a8c8c8209d5a5512c1b081d72a29192a
3
+ metadata.gz: 51746c89475207b2f61cd248e90092dfbc5ede1c57226e3809f972ba83155b03
4
+ data.tar.gz: df39f6262a9eacd358a263b5ab00e0c30474115c9ef367132498f385eeb8fc03
5
5
  SHA512:
6
- metadata.gz: ff828416dfb1f4a6ffcb51e02827d948b6c566ce008799cc9a02afb538b8d9a32ff1d6eee5c4e0e609757d1e9cfe1332ea359049a3fd820b199bdc7931a2573e
7
- data.tar.gz: e5ea4c5bd447d2ed5c37b144219cd0cbed1474a5c7976f63b938996687cfc7f422e4e147582e6fee0a2d3f4ba09937496c23f08c42e2a525744a9246bcfcb5df
6
+ metadata.gz: f192e8bd1e2008570805de002e2ee1ff75f5f31929f5f3c719e7dc11a2cb754f97d70655308372275e4eb9c39d5ee16cb85f2fe7823d5a94f71879d87b11d705
7
+ data.tar.gz: 69846485c78975cd38c91e5068f365bc8ee9b41ec761d964a8c2166e3e6e86e72d34634f26764a6532ec1e8a3537d669069774440742c2dec7003de09090041c
data/CHANGES.md CHANGED
@@ -2,7 +2,11 @@
2
2
 
3
3
  ### Unreleased
4
4
 
5
- ### 2025-05-23 (2.13.0)
5
+ ### 2025-07-24 (2.13.1)
6
+
7
+ * Fix support for older compilers without `__builtin_cpu_supports`.
8
+
9
+ ### 2025-07-17 (2.13.0)
6
10
 
7
11
  * Add new `allow_duplicate_key` parsing options. By default a warning is now emitted when a duplicated key is encountered.
8
12
  In `json 3.0` an error will be raised.
@@ -1907,15 +1907,30 @@ static VALUE cState_buffer_initial_length_set(VALUE self, VALUE buffer_initial_l
1907
1907
  return Qnil;
1908
1908
  }
1909
1909
 
1910
+ struct configure_state_data {
1911
+ JSON_Generator_State *state;
1912
+ VALUE vstate; // Ruby object that owns the state, or Qfalse if stack-allocated
1913
+ };
1914
+
1915
+ static inline void state_write_value(struct configure_state_data *data, VALUE *field, VALUE value)
1916
+ {
1917
+ if (RTEST(data->vstate)) {
1918
+ RB_OBJ_WRITE(data->vstate, field, value);
1919
+ } else {
1920
+ *field = value;
1921
+ }
1922
+ }
1923
+
1910
1924
  static int configure_state_i(VALUE key, VALUE val, VALUE _arg)
1911
1925
  {
1912
- JSON_Generator_State *state = (JSON_Generator_State *)_arg;
1926
+ struct configure_state_data *data = (struct configure_state_data *)_arg;
1927
+ JSON_Generator_State *state = data->state;
1913
1928
 
1914
- if (key == sym_indent) { state->indent = string_config(val); }
1915
- else if (key == sym_space) { state->space = string_config(val); }
1916
- else if (key == sym_space_before) { state->space_before = string_config(val); }
1917
- else if (key == sym_object_nl) { state->object_nl = string_config(val); }
1918
- else if (key == sym_array_nl) { state->array_nl = string_config(val); }
1929
+ if (key == sym_indent) { state_write_value(data, &state->indent, string_config(val)); }
1930
+ else if (key == sym_space) { state_write_value(data, &state->space, string_config(val)); }
1931
+ else if (key == sym_space_before) { state_write_value(data, &state->space_before, string_config(val)); }
1932
+ else if (key == sym_object_nl) { state_write_value(data, &state->object_nl, string_config(val)); }
1933
+ else if (key == sym_array_nl) { state_write_value(data, &state->array_nl, string_config(val)); }
1919
1934
  else if (key == sym_max_nesting) { state->max_nesting = long_config(val); }
1920
1935
  else if (key == sym_allow_nan) { state->allow_nan = RTEST(val); }
1921
1936
  else if (key == sym_ascii_only) { state->ascii_only = RTEST(val); }
@@ -1924,11 +1939,14 @@ static int configure_state_i(VALUE key, VALUE val, VALUE _arg)
1924
1939
  else if (key == sym_script_safe) { state->script_safe = RTEST(val); }
1925
1940
  else if (key == sym_escape_slash) { state->script_safe = RTEST(val); }
1926
1941
  else if (key == sym_strict) { state->strict = RTEST(val); }
1927
- else if (key == sym_as_json) { state->as_json = RTEST(val) ? rb_convert_type(val, T_DATA, "Proc", "to_proc") : Qfalse; }
1942
+ else if (key == sym_as_json) {
1943
+ VALUE proc = RTEST(val) ? rb_convert_type(val, T_DATA, "Proc", "to_proc") : Qfalse;
1944
+ state_write_value(data, &state->as_json, proc);
1945
+ }
1928
1946
  return ST_CONTINUE;
1929
1947
  }
1930
1948
 
1931
- static void configure_state(JSON_Generator_State *state, VALUE config)
1949
+ static void configure_state(JSON_Generator_State *state, VALUE vstate, VALUE config)
1932
1950
  {
1933
1951
  if (!RTEST(config)) return;
1934
1952
 
@@ -1936,15 +1954,20 @@ static void configure_state(JSON_Generator_State *state, VALUE config)
1936
1954
 
1937
1955
  if (!RHASH_SIZE(config)) return;
1938
1956
 
1957
+ struct configure_state_data data = {
1958
+ .state = state,
1959
+ .vstate = vstate
1960
+ };
1961
+
1939
1962
  // We assume in most cases few keys are set so it's faster to go over
1940
1963
  // the provided keys than to check all possible keys.
1941
- rb_hash_foreach(config, configure_state_i, (VALUE)state);
1964
+ rb_hash_foreach(config, configure_state_i, (VALUE)&data);
1942
1965
  }
1943
1966
 
1944
1967
  static VALUE cState_configure(VALUE self, VALUE opts)
1945
1968
  {
1946
1969
  GET_STATE(self);
1947
- configure_state(state, opts);
1970
+ configure_state(state, self, opts);
1948
1971
  return self;
1949
1972
  }
1950
1973
 
@@ -1952,7 +1975,7 @@ static VALUE cState_m_generate(VALUE klass, VALUE obj, VALUE opts, VALUE io)
1952
1975
  {
1953
1976
  JSON_Generator_State state = {0};
1954
1977
  state_init(&state);
1955
- configure_state(&state, opts);
1978
+ configure_state(&state, Qfalse, opts);
1956
1979
 
1957
1980
  char stack_buffer[FBUFFER_STACK_SIZE];
1958
1981
  FBuffer buffer = {
@@ -1,20 +1,24 @@
1
1
  case RbConfig::CONFIG['host_cpu']
2
2
  when /^(arm|aarch64)/
3
3
  # Try to compile a small program using NEON instructions
4
- header, type, init = 'arm_neon.h', 'uint8x16_t', 'vdupq_n_u8(32)'
4
+ header, type, init, extra = 'arm_neon.h', 'uint8x16_t', 'vdupq_n_u8(32)', nil
5
5
  when /^(x86_64|x64)/
6
- header, type, init = 'x86intrin.h', '__m128i', '_mm_set1_epi8(32)'
6
+ header, type, init, extra = 'x86intrin.h', '__m128i', '_mm_set1_epi8(32)', 'if (__builtin_cpu_supports("sse2")) { printf("OK"); }'
7
7
  end
8
8
  if header
9
- have_header(header) && try_compile(<<~SRC)
10
- #{cpp_include(header)}
11
- int main(int argc, char **argv) {
12
- #{type} test = #{init};
13
- if (argc > 100000) printf("%p", &test);
14
- return 0;
15
- }
16
- SRC
17
- $defs.push("-DJSON_ENABLE_SIMD")
9
+ if have_header(header) && try_compile(<<~SRC, '-Werror=implicit-function-declaration')
10
+ #{cpp_include(header)}
11
+ int main(int argc, char **argv) {
12
+ #{type} test = #{init};
13
+ #{extra}
14
+ if (argc > 100000) printf("%p", &test);
15
+ return 0;
16
+ }
17
+ SRC
18
+ $defs.push("-DJSON_ENABLE_SIMD")
19
+ else
20
+ puts "Disable SIMD"
21
+ end
18
22
  end
19
23
 
20
24
  have_header('cpuid.h')
data/lib/json/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JSON
4
- VERSION = '2.13.0'
4
+ VERSION = '2.13.1'
5
5
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.13.0
4
+ version: 2.13.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Frank
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-07-17 00:00:00.000000000 Z
10
+ date: 2025-07-24 00:00:00.000000000 Z
11
11
  dependencies: []
12
12
  description: This is a JSON implementation as a Ruby extension in C.
13
13
  email: flori@ping.de