Skip to content

Commit 70b1ff4

Browse files
authored
Merge branch 'master' into zjit-stackmap-base-ptr-anchor
2 parents f8386f0 + 435f43b commit 70b1ff4

59 files changed

Lines changed: 1308 additions & 2700 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

NEWS.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,11 @@ They are still available on rubygems.org and can be installed with
168168
* 6.0.1 to [v6.0.1.1][erb-v6.0.1.1], [v6.0.2][erb-v6.0.2], [v6.0.3][erb-v6.0.3], [v6.0.4][erb-v6.0.4], [v6.0.5][erb-v6.0.5], [v6.0.6][erb-v6.0.6], [v6.0.7][erb-v6.0.7]
169169
* error_highlight 0.7.2
170170
* io-console 0.9.2
171-
* 0.8.2 to [v0.9.0][io-console-v0.9.0], [v0.9.1][io-console-v0.9.1]
171+
* 0.8.2 to [v0.9.0][io-console-v0.9.0], [v0.9.1][io-console-v0.9.1], [v0.9.2][io-console-v0.9.2]
172172
* ipaddr 1.2.9
173173
* 1.2.8 to [v1.2.9][ipaddr-v1.2.9]
174-
* json 2.21.2
175-
* 2.18.0 to [v2.18.1][json-v2.18.1], [v2.19.0][json-v2.19.0], [v2.19.1][json-v2.19.1], [v2.19.2][json-v2.19.2], [v2.19.3][json-v2.19.3], [v2.19.4][json-v2.19.4], [v2.19.5][json-v2.19.5], [v2.19.6][json-v2.19.6], [v2.19.7][json-v2.19.7], [v2.19.8][json-v2.19.8], [v2.19.9][json-v2.19.9], [v2.20.0][json-v2.20.0], [v2.21.0][json-v2.21.0], [v2.21.2][json-v2.21.2]
174+
* json 3.0.0.rc1
175+
* 2.18.0 to [v2.18.1][json-v2.18.1], [v2.19.0][json-v2.19.0], [v2.19.1][json-v2.19.1], [v2.19.2][json-v2.19.2], [v2.19.3][json-v2.19.3], [v2.19.4][json-v2.19.4], [v2.19.5][json-v2.19.5], [v2.19.6][json-v2.19.6], [v2.19.7][json-v2.19.7], [v2.19.8][json-v2.19.8], [v2.19.9][json-v2.19.9], [v2.20.0][json-v2.20.0], [v2.21.0][json-v2.21.0], [v2.21.2][json-v2.21.2], [v3.0.0.rc1][json-v3.0.0.rc1]
176176
* openssl 4.0.2
177177
* 4.0.0 to [v4.0.1][openssl-v4.0.1], [v4.0.2][openssl-v4.0.2]
178178
* pp 0.6.4
@@ -389,6 +389,7 @@ A lot of work has gone into making Ractors more stable, performant, and usable.
389389
[erb-v6.0.7]: https://github.com/ruby/erb/releases/tag/v6.0.7
390390
[io-console-v0.9.0]: https://github.com/ruby/io-console/releases/tag/v0.9.0
391391
[io-console-v0.9.1]: https://github.com/ruby/io-console/releases/tag/v0.9.1
392+
[io-console-v0.9.2]: https://github.com/ruby/io-console/releases/tag/v0.9.2
392393
[ipaddr-v1.2.9]: https://github.com/ruby/ipaddr/releases/tag/v1.2.9
393394
[json-v2.18.1]: https://github.com/ruby/json/releases/tag/v2.18.1
394395
[json-v2.19.0]: https://github.com/ruby/json/releases/tag/v2.19.0
@@ -404,6 +405,7 @@ A lot of work has gone into making Ractors more stable, performant, and usable.
404405
[json-v2.20.0]: https://github.com/ruby/json/releases/tag/v2.20.0
405406
[json-v2.21.0]: https://github.com/ruby/json/releases/tag/v2.21.0
406407
[json-v2.21.2]: https://github.com/ruby/json/releases/tag/v2.21.2
408+
[json-v3.0.0.rc1]: https://github.com/ruby/json/releases/tag/v3.0.0.rc1
407409
[openssl-v4.0.1]: https://github.com/ruby/openssl/releases/tag/v4.0.1
408410
[openssl-v4.0.2]: https://github.com/ruby/openssl/releases/tag/v4.0.2
409411
[pp-v0.6.4]: https://github.com/ruby/pp/releases/tag/v0.6.4

compile.c

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3175,56 +3175,55 @@ find_destination(INSN *i)
31753175
static int
31763176
remove_unreachable_chunk(rb_iseq_t *iseq, LINK_ELEMENT *i)
31773177
{
3178-
LINK_ELEMENT *first = i, *end, *scan;
3178+
LINK_ELEMENT *first = i, *end, *scan, *pending_end = 0;
3179+
LABEL *pending = 0;
31793180
int *unref_counts = 0, nlabels = ISEQ_COMPILE_DATA(iseq)->label_no;
31803181

31813182
if (!i) return 0;
31823183
unref_counts = ALLOCA_N(int, nlabels);
31833184
MEMZERO(unref_counts, int, nlabels);
31843185

3186+
end = i;
31853187
scan = i;
31863188
do {
31873189
LABEL *lab;
31883190
if (IS_INSN(scan)) {
31893191
if (IS_INSN_ID(scan, leave)) {
3192+
if (pending) break;
3193+
end = scan;
31903194
break;
31913195
}
31923196
else if ((lab = find_destination((INSN *)scan)) != 0) {
31933197
unref_counts[lab->label_no]++;
3198+
if (lab == pending && lab->refcnt <= unref_counts[lab->label_no]) {
3199+
pending = 0;
3200+
}
31943201
}
31953202
}
31963203
else if (IS_LABEL(scan)) {
31973204
lab = (LABEL *)scan;
3198-
if (lab->unremovable) return 0;
3199-
}
3200-
else if (IS_ADJUST(scan)) {
3201-
return 0;
3202-
}
3203-
} while ((scan = scan->next) != 0);
3204-
3205-
end = i;
3206-
scan = i;
3207-
do {
3208-
LABEL *lab;
3209-
if (IS_INSN(scan)) {
3210-
if (IS_INSN_ID(scan, leave)) {
3211-
end = scan;
3212-
break;
3205+
if (lab->unremovable) {
3206+
if (pending) break;
3207+
return 0;
32133208
}
3214-
}
3215-
else if (IS_LABEL(scan)) {
3216-
lab = (LABEL *)scan;
32173209
if (lab->refcnt > unref_counts[lab->label_no]) {
3218-
if (scan == first) return 0;
3219-
break;
3210+
if (pending) break;
3211+
pending = lab;
3212+
pending_end = (scan == first) ? 0 : end;
32203213
}
32213214
continue;
32223215
}
32233216
else if (IS_ADJUST(scan)) {
3217+
if (pending) break;
32243218
return 0;
32253219
}
3226-
end = scan;
3220+
if (!pending) end = scan;
32273221
} while ((scan = scan->next) != 0);
3222+
3223+
if (pending) {
3224+
if (!pending_end) return 0;
3225+
end = pending_end;
3226+
}
32283227
i = first;
32293228
do {
32303229
if (IS_INSN(i)) {

doc/NEWS/NEWS-4.0.0.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ Note: We're only listing outstanding class updates.
212212
it returns when a Ractor terminates.
213213

214214
* `Ractor#default_port` was added. Each `Ractor` has a default port,
215-
which is used by `Ractor.send`, `Ractor.receive`.
215+
which is used by `Ractor#send`, `Ractor.receive`.
216216

217217
* `Ractor#close_incoming` and `Ractor#close_outgoing` were removed.
218218

ext/json/generator/generator.c

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,6 @@
99

1010
/* ruby api and some helpers */
1111

12-
enum duplicate_key_action {
13-
JSON_DEPRECATED = 0,
14-
JSON_IGNORE,
15-
JSON_RAISE,
16-
};
17-
1812
typedef struct JSON_Generator_StateStruct {
1913
VALUE indent;
2014
VALUE space;
@@ -27,8 +21,7 @@ typedef struct JSON_Generator_StateStruct {
2721
long depth;
2822
long buffer_initial_length;
2923

30-
enum duplicate_key_action on_duplicate_key;
31-
24+
bool allow_duplicate_key;
3225
bool as_json_single_arg;
3326
bool allow_nan;
3427
bool ascii_only;
@@ -41,7 +34,7 @@ static VALUE mJSON, cState, cFragment, eGeneratorError, eNestingError, Encoding_
4134

4235
static ID i_to_s, i_to_json, i_new, i_encode;
4336
static VALUE sym_indent, sym_space, sym_space_before, sym_object_nl, sym_array_nl, sym_max_nesting, sym_allow_nan, sym_allow_duplicate_key,
44-
sym_ascii_only, sym_depth, sym_buffer_initial_length, sym_script_safe, sym_escape_slash, sym_strict, sym_as_json, sym_sort_keys;
37+
sym_ascii_only, sym_depth, sym_buffer_initial_length, sym_script_safe, sym_strict, sym_as_json, sym_sort_keys;
4538

4639

4740
#define GET_STATE_TO(self, state) \
@@ -956,9 +949,8 @@ json_inspect_hash_with_mixed_keys(struct hash_foreach_arg *arg)
956949
arg->mixed_keys_encountered = true;
957950

958951
JSON_Generator_State *state = arg->data->state;
959-
if (state->on_duplicate_key != JSON_IGNORE) {
960-
VALUE do_raise = state->on_duplicate_key == JSON_RAISE ? Qtrue : Qfalse;
961-
rb_funcall(mJSON, rb_intern("on_mixed_keys_hash"), 2, arg->hash, do_raise);
952+
if (!state->allow_duplicate_key) {
953+
rb_funcall(mJSON, rb_intern("on_mixed_keys_hash"), 1, arg->hash);
962954
}
963955
}
964956

@@ -1784,14 +1776,7 @@ static VALUE cState_sort_keys_set(VALUE self, VALUE value)
17841776
static VALUE cState_allow_duplicate_key_p(VALUE self)
17851777
{
17861778
GET_STATE(self);
1787-
switch (state->on_duplicate_key) {
1788-
case JSON_IGNORE:
1789-
return Qtrue;
1790-
case JSON_DEPRECATED:
1791-
return Qnil;
1792-
default:
1793-
return Qfalse;
1794-
}
1779+
return state->allow_duplicate_key ? Qtrue : Qfalse;
17951780
}
17961781

17971782
/*
@@ -1856,6 +1841,7 @@ static VALUE cState_buffer_initial_length_set(VALUE self, VALUE buffer_initial_l
18561841
struct configure_state_data {
18571842
JSON_Generator_State *state;
18581843
VALUE vstate; // Ruby object that owns the state, or Qfalse if stack-allocated
1844+
VALUE unknown_keywords;
18591845
};
18601846

18611847
static inline void state_write_value(struct configure_state_data *data, VALUE *field, VALUE value)
@@ -1883,9 +1869,8 @@ static int configure_state_i(VALUE key, VALUE val, VALUE _arg)
18831869
else if (key == sym_depth) { state->depth = depth_config(val); }
18841870
else if (key == sym_buffer_initial_length) { buffer_initial_length_set(state, val); }
18851871
else if (key == sym_script_safe) { state->script_safe = RTEST(val); }
1886-
else if (key == sym_escape_slash) { state->script_safe = RTEST(val); }
18871872
else if (key == sym_strict) { state->strict = RTEST(val); }
1888-
else if (key == sym_allow_duplicate_key) { state->on_duplicate_key = RTEST(val) ? JSON_IGNORE : JSON_RAISE; }
1873+
else if (key == sym_allow_duplicate_key) { state->allow_duplicate_key = RTEST(val); }
18891874
else if (key == sym_as_json) {
18901875
VALUE proc = RTEST(val) ? rb_convert_type(val, T_DATA, "Proc", "to_proc") : Qfalse;
18911876
state->as_json_single_arg = proc && rb_proc_arity(proc) == 1;
@@ -1894,6 +1879,12 @@ static int configure_state_i(VALUE key, VALUE val, VALUE _arg)
18941879
else if (key == sym_sort_keys) {
18951880
state_write_value(data, &state->sort_keys, normalize_sort_keys(val));
18961881
}
1882+
else {
1883+
if (!data->unknown_keywords) {
1884+
data->unknown_keywords = rb_obj_hide(rb_ary_new());
1885+
}
1886+
rb_ary_push(data->unknown_keywords, key);
1887+
}
18971888
return ST_CONTINUE;
18981889
}
18991890

@@ -1907,12 +1898,15 @@ static void configure_state(JSON_Generator_State *state, VALUE vstate, VALUE con
19071898

19081899
struct configure_state_data data = {
19091900
.state = state,
1910-
.vstate = vstate
1901+
.vstate = vstate,
1902+
.unknown_keywords = Qfalse,
19111903
};
19121904

19131905
// We assume in most cases few keys are set so it's faster to go over
19141906
// the provided keys than to check all possible keys.
19151907
rb_hash_foreach(config, configure_state_i, (VALUE)&data);
1908+
1909+
raise_argument_error_on_unknown_keywords(data.unknown_keywords);
19161910
}
19171911

19181912
static VALUE cState_configure(VALUE self, VALUE opts)
@@ -2006,9 +2000,6 @@ void Init_generator(void)
20062000
rb_define_method(cState, "script_safe", cState_script_safe, 0);
20072001
rb_define_method(cState, "script_safe?", cState_script_safe, 0);
20082002
rb_define_method(cState, "script_safe=", cState_script_safe_set, 1);
2009-
rb_define_alias(cState, "escape_slash", "script_safe");
2010-
rb_define_alias(cState, "escape_slash?", "script_safe?");
2011-
rb_define_alias(cState, "escape_slash=", "script_safe=");
20122003
rb_define_method(cState, "strict", cState_strict, 0);
20132004
rb_define_method(cState, "strict?", cState_strict, 0);
20142005
rb_define_method(cState, "strict=", cState_strict_set, 1);
@@ -2050,7 +2041,6 @@ void Init_generator(void)
20502041
sym_depth = ID2SYM(rb_intern("depth"));
20512042
sym_buffer_initial_length = ID2SYM(rb_intern("buffer_initial_length"));
20522043
sym_script_safe = ID2SYM(rb_intern("script_safe"));
2053-
sym_escape_slash = ID2SYM(rb_intern("escape_slash"));
20542044
sym_strict = ID2SYM(rb_intern("strict"));
20552045
sym_as_json = ID2SYM(rb_intern("as_json"));
20562046
sym_allow_duplicate_key = ID2SYM(rb_intern("allow_duplicate_key"));

ext/json/json.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,4 +180,17 @@ static inline VALUE json_rb_catch_obj(VALUE tag, VALUE (*func)(VALUE args), VALU
180180

181181
#endif // JSON_TRUFFLERUBY_RB_CATCH_BUG
182182

183+
static inline void raise_argument_error_on_unknown_keywords(VALUE unknown_keywords)
184+
{
185+
if (RB_UNLIKELY(unknown_keywords)) {
186+
if (RARRAY_LEN(unknown_keywords) == 1) {
187+
rb_raise(rb_eArgError, "unknown keyword: %" PRIsVALUE, RARRAY_AREF(unknown_keywords, 0));
188+
}
189+
else {
190+
VALUE keywords = rb_ary_join(unknown_keywords, rb_utf8_str_new_cstr(", "));
191+
rb_raise(rb_eArgError, "unknown keywords: %" PRIsVALUE, keywords);
192+
}
193+
}
194+
}
195+
183196
#endif // _JSON_H_

0 commit comments

Comments
 (0)