ruby-changes:60160
From: Koichi <ko1@a...>
Date: Sat, 22 Feb 2020 10:28:09 +0900 (JST)
Subject: [ruby-changes:60160] 31748e69c8 (master): CI can be NULL.
https://git.ruby-lang.org/ruby.git/commit/?id=31748e69c8 From 31748e69c84894ac8f042a67d1320db8593c9ce1 Mon Sep 17 00:00:00 2001 From: Koichi Sasada <ko1@a...> Date: Sat, 22 Feb 2020 10:26:15 +0900 Subject: CI can be NULL. Unused CI (introduced from peephole optimization, etc) can be NULL so introduce NULL check. diff --git a/compile.c b/compile.c index 94daa65..b5c84a8 100644 --- a/compile.c +++ b/compile.c @@ -10294,21 +10294,27 @@ ibf_dump_ci_entries(struct ibf_dump *dump, const rb_iseq_t *iseq) https://github.com/ruby/ruby/blob/trunk/compile.c#L10294 for (i = 0; i < ci_size; i++) { const struct rb_callinfo *ci = cds[i].ci; - ibf_dump_write_small_value(dump, ibf_dump_id(dump, vm_ci_mid(ci))); - ibf_dump_write_small_value(dump, vm_ci_flag(ci)); - ibf_dump_write_small_value(dump, vm_ci_argc(ci)); - - const struct rb_callinfo_kwarg *kwarg = vm_ci_kwarg(ci); - if (kwarg) { - int len = kwarg->keyword_len; - ibf_dump_write_small_value(dump, len); - for (int j=0; j<len; j++) { - VALUE keyword = ibf_dump_object(dump, kwarg->keywords[j]); - ibf_dump_write_small_value(dump, keyword); + if (ci != NULL) { + ibf_dump_write_small_value(dump, ibf_dump_id(dump, vm_ci_mid(ci))); + ibf_dump_write_small_value(dump, vm_ci_flag(ci)); + ibf_dump_write_small_value(dump, vm_ci_argc(ci)); + + const struct rb_callinfo_kwarg *kwarg = vm_ci_kwarg(ci); + if (kwarg) { + int len = kwarg->keyword_len; + ibf_dump_write_small_value(dump, len); + for (int j=0; j<len; j++) { + VALUE keyword = ibf_dump_object(dump, kwarg->keywords[j]); + ibf_dump_write_small_value(dump, keyword); + } + } + else { + ibf_dump_write_small_value(dump, 0); } } else { - ibf_dump_write_small_value(dump, 0); + // TODO: truncate NULL ci from call_data. + ibf_dump_write_small_value(dump, (VALUE)-1); } } @@ -10331,24 +10337,31 @@ ibf_load_ci_entries(const struct ibf_load *load, https://github.com/ruby/ruby/blob/trunk/compile.c#L10337 for (i = 0; i < ci_size; i++) { VALUE mid_index = ibf_load_small_value(load, &reading_pos); - ID mid = ibf_load_id(load, mid_index); - unsigned int flag = (unsigned int)ibf_load_small_value(load, &reading_pos); - unsigned int argc = (unsigned int)ibf_load_small_value(load, &reading_pos); - - struct rb_callinfo_kwarg *kwarg = NULL; - int kwlen = (int)ibf_load_small_value(load, &reading_pos); - if (kwlen > 0) { - kwarg = rb_xmalloc_mul_add(kwlen - 1, sizeof(VALUE), sizeof(struct rb_callinfo_kwarg));; - kwarg->keyword_len = kwlen; - for (int j=0; j<kwlen; j++) { - VALUE keyword = ibf_load_small_value(load, &reading_pos); - kwarg->keywords[j] = ibf_load_object(load, keyword); + if (mid_index != (VALUE)-1) { + ID mid = ibf_load_id(load, mid_index); + unsigned int flag = (unsigned int)ibf_load_small_value(load, &reading_pos); + unsigned int argc = (unsigned int)ibf_load_small_value(load, &reading_pos); + + struct rb_callinfo_kwarg *kwarg = NULL; + int kwlen = (int)ibf_load_small_value(load, &reading_pos); + if (kwlen > 0) { + kwarg = rb_xmalloc_mul_add(kwlen - 1, sizeof(VALUE), sizeof(struct rb_callinfo_kwarg));; + kwarg->keyword_len = kwlen; + for (int j=0; j<kwlen; j++) { + VALUE keyword = ibf_load_small_value(load, &reading_pos); + kwarg->keywords[j] = ibf_load_object(load, keyword); + } } - } - cds[i].ci = vm_ci_new(mid, flag, argc, kwarg); - RB_OBJ_WRITTEN(load->iseq, Qundef, cds[i].ci); - cds[i].cc = vm_cc_empty(); + cds[i].ci = vm_ci_new(mid, flag, argc, kwarg); + RB_OBJ_WRITTEN(load->iseq, Qundef, cds[i].ci); + cds[i].cc = vm_cc_empty(); + } + else { + // NULL ci + cds[i].ci = NULL; + cds[i].cc = NULL; + } } } -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/