1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

vm_args.c (rb_warn_check): Use iseq_unique_id instead of its pointer

If iseq is GC'ed, the pointer of iseq may be reused, which may hide a
deprecation warning of keyword argument change.

http://ci.rvm.jp/results/trunk-test1@phosphorus-docker/2474221

```
  1) Failure:
TestKeywordArguments#test_explicit_super_kwsplat [/tmp/ruby/v2/src/trunk-test1/test/ruby/test_keyword.rb:549]:
--- expected
+++ actual
@@ -1 +1 @@
-/The keyword argument is passed as the last hash parameter.* for `m'/m
+""
```

This change ad-hocly adds iseq_unique_id for each iseq, and use it
instead of iseq pointer.  This covers the case where caller is GC'ed.
Still, the case where callee is GC'ed, is not covered.

But anyway, it is very rare that iseq is GC'ed.  Even when it occurs, it
just hides some warnings.  It's no big deal.
This commit is contained in:
Yusuke Endoh 2019-12-09 12:04:58 +09:00
parent 0e71fbc18e
commit 036bc1da6c
3 changed files with 10 additions and 1 deletions

3
iseq.c
View file

@ -427,11 +427,14 @@ rb_iseq_memsize(const rb_iseq_t *iseq)
return size;
}
static unsigned long fresh_iseq_unique_id = 0; /* -- Remove In 3.0 -- */
static rb_iseq_t *
iseq_alloc(void)
{
rb_iseq_t *iseq = iseq_imemo_alloc();
iseq->body = ZALLOC(struct rb_iseq_constant_body);
iseq->body->iseq_unique_id = fresh_iseq_unique_id++; /* -- Remove In 3.0 -- */
return iseq;
}

View file

@ -593,8 +593,12 @@ VALUE rb_iseq_location(const rb_iseq_t *iseq);
*/
static st_table *caller_to_callees = 0;
static VALUE rb_warn_check(const rb_execution_context_t * const ec, const void *const callee)
static VALUE rb_warn_check(const rb_execution_context_t * const ec, const rb_iseq_t *const iseq)
{
if (!iseq) return 0;
const void *const callee = (void *)iseq->body->iseq_unique_id;
const rb_control_frame_t * const cfp = rb_vm_get_ruby_level_next_cfp(ec, ec->cfp);
if (!cfp) return 0;

View file

@ -447,6 +447,8 @@ struct rb_iseq_constant_body {
long unsigned total_calls; /* number of total calls with `mjit_exec()` */
struct rb_mjit_unit *jit_unit;
#endif
unsigned long iseq_unique_id; /* -- Remove In 3.0 -- */
};
/* T_IMEMO/iseq */