Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions ext/json/fbuffer/fbuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -283,13 +283,10 @@ static VALUE fbuffer_finalize(FBuffer *fb)
{
if (fb->io) {
fbuffer_flush(fb);
fbuffer_free(fb);
rb_io_flush(fb->io);
return fb->io;
} else {
VALUE result = rb_utf8_str_new(FBUFFER_PTR(fb), FBUFFER_LEN(fb));
fbuffer_free(fb);
return result;
return rb_utf8_str_new(FBUFFER_PTR(fb), FBUFFER_LEN(fb));
}
}

Expand Down
18 changes: 5 additions & 13 deletions ext/json/generator/generator.c
Original file line number Diff line number Diff line change
Expand Up @@ -1444,16 +1444,14 @@ static VALUE generate_json_try(VALUE d)

data->func(data->buffer, data, data->obj);

return Qnil;
return fbuffer_finalize(data->buffer);
}

static VALUE generate_json_rescue(VALUE d, VALUE exc)
static VALUE generate_json_ensure(VALUE d)
{
struct generate_json_data *data = (struct generate_json_data *)d;
fbuffer_free(data->buffer);

rb_exc_raise(exc);

return Qundef;
}

Expand All @@ -1474,9 +1472,7 @@ static VALUE cState_partial_generate(VALUE self, VALUE obj, generator_func func,
.obj = obj,
.func = func
};
rb_rescue(generate_json_try, (VALUE)&data, generate_json_rescue, (VALUE)&data);

return fbuffer_finalize(&buffer);
return rb_ensure(generate_json_try, (VALUE)&data, generate_json_ensure, (VALUE)&data);
}

/* call-seq:
Expand Down Expand Up @@ -1522,9 +1518,7 @@ static VALUE cState_generate_new(int argc, VALUE *argv, VALUE self)
.obj = obj,
.func = generate_json
};
rb_rescue(generate_json_try, (VALUE)&data, generate_json_rescue, (VALUE)&data);

return fbuffer_finalize(&buffer);
return rb_ensure(generate_json_try, (VALUE)&data, generate_json_ensure, (VALUE)&data);
}

static VALUE cState_initialize(int argc, VALUE *argv, VALUE self)
Expand Down Expand Up @@ -2030,9 +2024,7 @@ static VALUE cState_m_generate(VALUE klass, VALUE obj, VALUE opts, VALUE io)
.obj = obj,
.func = generate_json,
};
rb_rescue(generate_json_try, (VALUE)&data, generate_json_rescue, (VALUE)&data);

return fbuffer_finalize(&buffer);
return rb_ensure(generate_json_try, (VALUE)&data, generate_json_ensure, (VALUE)&data);
}

/*
Expand Down
12 changes: 7 additions & 5 deletions load.c
Original file line number Diff line number Diff line change
Expand Up @@ -1212,17 +1212,19 @@ load_ext(VALUE path, VALUE fname)
return (VALUE)dln_load_feature(RSTRING_PTR(loaded), RSTRING_PTR(fname));
}

static bool
run_static_ext_init(rb_vm_t *vm, const char *feature)
static VALUE
run_static_ext_init(VALUE vm_ptr, VALUE feature_value)
{
rb_vm_t *vm = (rb_vm_t *)vm_ptr;
const char *feature = RSTRING_PTR(feature_value);
st_data_t key = (st_data_t)feature;
st_data_t init_func;

if (vm->static_ext_inits && st_delete(vm->static_ext_inits, &key, &init_func)) {
((void (*)(void))init_func)();
return true;
return Qtrue;
}
return false;
return Qfalse;
}

static int
Expand Down Expand Up @@ -1331,7 +1333,7 @@ require_internal(rb_execution_context_t *ec, VALUE fname, int exception, bool wa
else if (!*ftptr) {
result = TAG_RETURN;
}
else if (found == 's' && run_static_ext_init(th->vm, RSTRING_PTR(path))) {
else if (found == 's' && RTEST(rb_vm_call_cfunc_in_namespace(Qnil, run_static_ext_init, (VALUE)th->vm, path, path, ns))) {
result = TAG_RETURN;
}
else if (RTEST(rb_hash_aref(realpaths,
Expand Down
4 changes: 2 additions & 2 deletions namespace.c
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,7 @@ Init_enable_namespace(void)
}
}

#ifdef RUBY_DEBUG
#if RUBY_DEBUG > 0

/* :nodoc: */
static VALUE
Expand Down Expand Up @@ -1084,7 +1084,7 @@ Init_Namespace(void)
if (rb_namespace_available()) {
rb_include_module(rb_cObject, rb_mNamespaceLoader);

#ifdef RUBY_DEBUG
#if RUBY_DEBUG > 0
rb_define_singleton_method(rb_cNamespace, "root", rb_namespace_s_root, 0);
rb_define_singleton_method(rb_cNamespace, "main", rb_namespace_s_main, 0);
rb_define_global_function("dump_classext", rb_f_dump_classext, 1);
Expand Down
27 changes: 5 additions & 22 deletions zjit/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2126,23 +2126,6 @@ impl Function {
self.push_insn(block, Insn::GuardType { val, guard_type, state })
}

fn likely_is_fixnum(&self, val: InsnId, profiled_type: ProfiledType) -> bool {
self.is_a(val, types::Fixnum) || profiled_type.is_fixnum()
}

fn coerce_to_fixnum(&mut self, block: BlockId, val: InsnId, state: InsnId) -> InsnId {
if self.is_a(val, types::Fixnum) { return val; }
self.push_insn(block, Insn::GuardType { val, guard_type: types::Fixnum, state })
}

fn arguments_likely_fixnums(&mut self, left: InsnId, right: InsnId, state: InsnId) -> bool {
let frame_state = self.frame_state(state);
let iseq_insn_idx = frame_state.insn_idx;
let left_profiled_type = self.profiled_type_of_at(left, iseq_insn_idx).unwrap_or_default();
let right_profiled_type = self.profiled_type_of_at(right, iseq_insn_idx).unwrap_or_default();
self.likely_is_fixnum(left, left_profiled_type) && self.likely_is_fixnum(right, right_profiled_type)
}

fn count_fancy_call_features(&mut self, block: BlockId, ci_flags: c_uint) {
use Counter::*;
if 0 != ci_flags & VM_CALL_ARGS_SPLAT { self.push_insn(block, Insn::IncrCounter(fancy_arg_pass_caller_splat)); }
Expand All @@ -2161,14 +2144,14 @@ impl Function {
self.push_insn_id(block, orig_insn_id);
return;
}
if self.arguments_likely_fixnums(left, right, state) {
if self.likely_a(left, types::Fixnum, state) && self.likely_a(right, types::Fixnum, state) {
if bop == BOP_NEQ {
// For opt_neq, the interpreter checks that both neq and eq are unchanged.
self.push_insn(block, Insn::PatchPoint { invariant: Invariant::BOPRedefined { klass: INTEGER_REDEFINED_OP_FLAG, bop: BOP_EQ }, state });
}
self.push_insn(block, Insn::PatchPoint { invariant: Invariant::BOPRedefined { klass: INTEGER_REDEFINED_OP_FLAG, bop }, state });
let left = self.coerce_to_fixnum(block, left, state);
let right = self.coerce_to_fixnum(block, right, state);
let left = self.coerce_to(block, left, types::Fixnum, state);
let right = self.coerce_to(block, right, types::Fixnum, state);
let result = self.push_insn(block, f(left, right));
self.make_equal_to(orig_insn_id, result);
self.insn_types[result.0] = self.infer_type(result);
Expand Down Expand Up @@ -2567,8 +2550,8 @@ impl Function {
let high_is_fix = self.is_a(high, types::Fixnum);

if low_is_fix || high_is_fix {
let low_fix = self.coerce_to_fixnum(block, low, state);
let high_fix = self.coerce_to_fixnum(block, high, state);
let low_fix = self.coerce_to(block, low, types::Fixnum, state);
let high_fix = self.coerce_to(block, high, types::Fixnum, state);
let replacement = self.push_insn(block, Insn::NewRangeFixnum { low: low_fix, high: high_fix, flag, state });
self.make_equal_to(insn_id, replacement);
self.insn_types[replacement.0] = self.infer_type(replacement);
Expand Down