refactor rb_method_definition_create take opts
Before this changeset rb_method_definition_create only allocated a memory region and we had to destructively initialize it later. That is not a good design so we change the API to return a complete struct instead.
This commit is contained in:
parent
1521f7cf89
commit
595b3c4fdd
Notes:
git
2019-09-30 10:27:06 +09:00
4
proc.c
4
proc.c
@ -15,7 +15,7 @@
|
|||||||
#include "vm_core.h"
|
#include "vm_core.h"
|
||||||
#include "iseq.h"
|
#include "iseq.h"
|
||||||
|
|
||||||
extern const rb_method_definition_t *rb_method_definition_create(rb_method_type_t type, ID mid);
|
extern const rb_method_definition_t *rb_method_definition_create(rb_method_type_t type, ID mid, const void *opts);
|
||||||
|
|
||||||
/* Proc.new with no block will raise an exception in the future
|
/* Proc.new with no block will raise an exception in the future
|
||||||
* versions */
|
* versions */
|
||||||
@ -1482,7 +1482,7 @@ mnew_missing(VALUE klass, VALUE obj, ID id, VALUE mclass)
|
|||||||
RB_OBJ_WRITE(method, &data->recv, obj);
|
RB_OBJ_WRITE(method, &data->recv, obj);
|
||||||
RB_OBJ_WRITE(method, &data->klass, klass);
|
RB_OBJ_WRITE(method, &data->klass, klass);
|
||||||
|
|
||||||
def = rb_method_definition_create(VM_METHOD_TYPE_MISSING, id);
|
def = rb_method_definition_create(VM_METHOD_TYPE_MISSING, id, NULL);
|
||||||
me = rb_method_entry_create(id, klass, METHOD_VISI_UNDEF, def);
|
me = rb_method_entry_create(id, klass, METHOD_VISI_UNDEF, def);
|
||||||
|
|
||||||
RB_OBJ_WRITE(method, &data->me, me);
|
RB_OBJ_WRITE(method, &data->me, me);
|
||||||
|
@ -19,8 +19,8 @@
|
|||||||
#include "ruby/config.h"
|
#include "ruby/config.h"
|
||||||
#include "debug_counter.h"
|
#include "debug_counter.h"
|
||||||
|
|
||||||
extern const rb_method_definition_t *rb_method_definition_create(rb_method_type_t type, ID mid);
|
extern const rb_method_definition_t *rb_method_definition_create(rb_method_type_t type, ID mid, const void *opts);
|
||||||
extern void rb_method_definition_set(const rb_method_entry_t *me, rb_method_definition_t *def, void *opts);
|
extern void rb_method_definition_set(const rb_method_entry_t *me, const rb_method_definition_t *def);
|
||||||
extern int rb_method_definition_eq(const rb_method_definition_t *d1, const rb_method_definition_t *d2);
|
extern int rb_method_definition_eq(const rb_method_definition_t *d1, const rb_method_definition_t *d2);
|
||||||
extern VALUE rb_make_no_method_exception(VALUE exc, VALUE format, VALUE obj,
|
extern VALUE rb_make_no_method_exception(VALUE exc, VALUE format, VALUE obj,
|
||||||
int argc, const VALUE *argv, int priv);
|
int argc, const VALUE *argv, int priv);
|
||||||
@ -2590,8 +2590,8 @@ aliased_callable_method_entry(const rb_callable_method_entry_t *me)
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
const rb_method_definition_t *def =
|
const rb_method_definition_t *def =
|
||||||
rb_method_definition_create(VM_METHOD_TYPE_ALIAS, me->def->original_id);
|
rb_method_definition_create(VM_METHOD_TYPE_ALIAS, me->def->original_id, cme);
|
||||||
rb_method_definition_set((rb_method_entry_t *)me, (void *)def, (void *)cme);
|
rb_method_definition_set((rb_method_entry_t *)me, def);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
76
vm_method.c
76
vm_method.c
@ -334,10 +334,15 @@ the_method_optimized(const void *p)
|
|||||||
static rb_method_refined_t
|
static rb_method_refined_t
|
||||||
the_method_refined(const rb_method_refined_t *p)
|
the_method_refined(const rb_method_refined_t *p)
|
||||||
{
|
{
|
||||||
return (rb_method_refined_t) {
|
if (!p) {
|
||||||
.orig_me = p->orig_me,
|
return (rb_method_refined_t) { 0, };
|
||||||
.owner = p->owner,
|
}
|
||||||
};
|
else {
|
||||||
|
return (rb_method_refined_t) {
|
||||||
|
.orig_me = p->orig_me,
|
||||||
|
.owner = p->owner,
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static rb_method_alias_t
|
static rb_method_alias_t
|
||||||
@ -438,24 +443,16 @@ rb_method_definition_new(rb_method_type_t type, ID mid, const void *opts)
|
|||||||
}
|
}
|
||||||
|
|
||||||
MJIT_FUNC_EXPORTED void
|
MJIT_FUNC_EXPORTED void
|
||||||
rb_method_definition_set(const rb_method_entry_t *me, rb_method_definition_t *def, void *opts)
|
rb_method_definition_set(const rb_method_entry_t *me, const rb_method_definition_t *def)
|
||||||
{
|
{
|
||||||
if (opts) {
|
|
||||||
rb_method_definition_t template =
|
|
||||||
rb_method_definition_new(def->type, def->original_id, opts);
|
|
||||||
memcpy(def, &template, sizeof template);
|
|
||||||
}
|
|
||||||
memcpy((void *)&me->def, &def, sizeof def);
|
memcpy((void *)&me->def, &def, sizeof def);
|
||||||
method_definition_reset(me);
|
method_definition_reset(me);
|
||||||
}
|
}
|
||||||
|
|
||||||
MJIT_FUNC_EXPORTED const rb_method_definition_t *
|
MJIT_FUNC_EXPORTED const rb_method_definition_t *
|
||||||
rb_method_definition_create(rb_method_type_t type, ID mid)
|
rb_method_definition_create(rb_method_type_t type, ID mid, const void *opts)
|
||||||
{
|
{
|
||||||
rb_method_definition_t template = {
|
rb_method_definition_t template = rb_method_definition_new(type, mid, opts);
|
||||||
.type = type,
|
|
||||||
.original_id = mid,
|
|
||||||
};
|
|
||||||
void *ptr = ALLOC(rb_method_definition_t);
|
void *ptr = ALLOC(rb_method_definition_t);
|
||||||
memcpy(ptr, &template, sizeof template);
|
memcpy(ptr, &template, sizeof template);
|
||||||
return ptr;
|
return ptr;
|
||||||
@ -521,10 +518,6 @@ rb_method_entry_complement_defined_class(const rb_method_entry_t *src_me, ID cal
|
|||||||
{
|
{
|
||||||
const rb_method_definition_t *def = src_me->def;
|
const rb_method_definition_t *def = src_me->def;
|
||||||
rb_method_entry_t *me;
|
rb_method_entry_t *me;
|
||||||
struct {
|
|
||||||
const struct rb_method_entry_struct *orig_me;
|
|
||||||
VALUE owner;
|
|
||||||
} refined = {0};
|
|
||||||
|
|
||||||
if (!src_me->defined_class &&
|
if (!src_me->defined_class &&
|
||||||
def->type == VM_METHOD_TYPE_REFINED &&
|
def->type == VM_METHOD_TYPE_REFINED &&
|
||||||
@ -532,19 +525,18 @@ rb_method_entry_complement_defined_class(const rb_method_entry_t *src_me, ID cal
|
|||||||
const rb_method_entry_t *orig_me =
|
const rb_method_entry_t *orig_me =
|
||||||
rb_method_entry_clone(def->body.refined.orig_me);
|
rb_method_entry_clone(def->body.refined.orig_me);
|
||||||
RB_OBJ_WRITE((VALUE)orig_me, &orig_me->defined_class, defined_class);
|
RB_OBJ_WRITE((VALUE)orig_me, &orig_me->defined_class, defined_class);
|
||||||
refined.orig_me = orig_me;
|
def = rb_method_definition_create(
|
||||||
refined.owner = orig_me->owner;
|
VM_METHOD_TYPE_REFINED,
|
||||||
def = NULL;
|
called_id,
|
||||||
|
&(rb_method_refined_t) {
|
||||||
|
.orig_me = orig_me,
|
||||||
|
.owner = orig_me->owner});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
def = method_definition_addref_complement((rb_method_definition_t *)def);
|
def = method_definition_addref_complement((rb_method_definition_t *)def);
|
||||||
}
|
}
|
||||||
me = rb_method_entry_alloc(called_id, src_me->owner, defined_class, def);
|
me = rb_method_entry_alloc(called_id, src_me->owner, defined_class, def);
|
||||||
METHOD_ENTRY_FLAGS_COPY(me, src_me);
|
METHOD_ENTRY_FLAGS_COPY(me, src_me);
|
||||||
if (!def) {
|
|
||||||
def = rb_method_definition_create(VM_METHOD_TYPE_REFINED, called_id);
|
|
||||||
rb_method_definition_set(me, (rb_method_definition_t *)def, &refined);
|
|
||||||
}
|
|
||||||
|
|
||||||
VM_ASSERT(RB_TYPE_P(me->owner, T_MODULE));
|
VM_ASSERT(RB_TYPE_P(me->owner, T_MODULE));
|
||||||
|
|
||||||
@ -569,24 +561,23 @@ make_method_entry_refined(VALUE owner, rb_method_entry_t *me)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
struct {
|
|
||||||
struct rb_method_entry_struct *orig_me;
|
|
||||||
VALUE owner;
|
|
||||||
} refined;
|
|
||||||
const rb_method_definition_t *def;
|
|
||||||
|
|
||||||
rb_vm_check_redefinition_opt_method(me, me->owner);
|
rb_vm_check_redefinition_opt_method(me, me->owner);
|
||||||
|
rb_method_entry_t *orig_me =
|
||||||
refined.orig_me =
|
|
||||||
rb_method_entry_alloc(me->called_id, me->owner,
|
rb_method_entry_alloc(me->called_id, me->owner,
|
||||||
me->defined_class ?
|
me->defined_class ?
|
||||||
me->defined_class : owner,
|
me->defined_class : owner,
|
||||||
method_definition_addref(me->def));
|
method_definition_addref(me->def));
|
||||||
METHOD_ENTRY_FLAGS_COPY(refined.orig_me, me);
|
METHOD_ENTRY_FLAGS_COPY(orig_me, me);
|
||||||
refined.owner = owner;
|
const rb_method_definition_t *def =
|
||||||
|
rb_method_definition_create(
|
||||||
def = rb_method_definition_create(VM_METHOD_TYPE_REFINED, me->called_id);
|
VM_METHOD_TYPE_REFINED,
|
||||||
rb_method_definition_set(me, (void *)def, (void *)&refined);
|
me->called_id,
|
||||||
|
&(rb_method_refined_t) {
|
||||||
|
.orig_me = orig_me,
|
||||||
|
.owner = owner,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
rb_method_definition_set(me, def);
|
||||||
METHOD_ENTRY_VISI_SET(me, METHOD_VISI_PUBLIC);
|
METHOD_ENTRY_VISI_SET(me, METHOD_VISI_PUBLIC);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -707,9 +698,10 @@ rb_method_entry_make(VALUE klass, ID mid, VALUE defined_class, rb_method_visibil
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* create method entry */
|
/* create method entry */
|
||||||
me = rb_method_entry_create(mid, defined_class, visi, NULL);
|
if (!def) {
|
||||||
if (def == NULL) def = rb_method_definition_create(type, original_id);
|
def = rb_method_definition_create(type, original_id, opts);
|
||||||
rb_method_definition_set(me, (void *)def, opts);
|
}
|
||||||
|
me = rb_method_entry_create(mid, defined_class, visi, def);
|
||||||
|
|
||||||
rb_clear_method_cache_by_class(klass);
|
rb_clear_method_cache_by_class(klass);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user