зеркало из https://github.com/github/ruby.git
refactor constify most of rb_method_entry_t
Now that we have eliminated most destructive operations over the rb_method_entry_t / rb_callable_method_entry_t, let's make them mostly immutabe and mark them const. One exception is rb_export_method(), which destructively modifies visibilities of method entries. I have left that operation as is because I suspect that destructiveness is the nature of that function.
This commit is contained in:
Родитель
6c6a25feca
Коммит
dd883de5ba
4
class.c
4
class.c
|
@ -965,7 +965,7 @@ static enum rb_id_table_iterator_result
|
||||||
inject_refined_method(ID *key, VALUE *value, void *data, int _)
|
inject_refined_method(ID *key, VALUE *value, void *data, int _)
|
||||||
{
|
{
|
||||||
const tuple *ptr = data;
|
const tuple *ptr = data;
|
||||||
const rb_method_entry_t *me = *(rb_method_entry_t **) value;
|
const rb_method_entry_t *me = *(const rb_method_entry_t **) value;
|
||||||
const rb_method_entry_t *orig_me = me->def->body.refined.orig_me;
|
const rb_method_entry_t *orig_me = me->def->body.refined.orig_me;
|
||||||
const rb_method_entry_t *new_me =
|
const rb_method_entry_t *new_me =
|
||||||
rb_method_entry_from_template(
|
rb_method_entry_from_template(
|
||||||
|
@ -983,7 +983,7 @@ static enum rb_id_table_iterator_result
|
||||||
move_refined_method(ID key, VALUE value, void *data)
|
move_refined_method(ID key, VALUE value, void *data)
|
||||||
{
|
{
|
||||||
const tuple *ptr = data;
|
const tuple *ptr = data;
|
||||||
rb_method_entry_t *me = (rb_method_entry_t *) value;
|
const rb_method_entry_t *me = (const rb_method_entry_t *) value;
|
||||||
|
|
||||||
if (me->def->type == VM_METHOD_TYPE_REFINED) {
|
if (me->def->type == VM_METHOD_TYPE_REFINED) {
|
||||||
if (me->def->body.refined.orig_me) {
|
if (me->def->body.refined.orig_me) {
|
||||||
|
|
|
@ -123,7 +123,7 @@ method_coverage_i(void *vstart, void *vend, size_t stride, void *data)
|
||||||
|
|
||||||
for (v = (VALUE)vstart; v != (VALUE)vend; v += stride) {
|
for (v = (VALUE)vstart; v != (VALUE)vend; v += stride) {
|
||||||
if (RB_TYPE_P(v, T_IMEMO) && imemo_type(v) == imemo_ment) {
|
if (RB_TYPE_P(v, T_IMEMO) && imemo_type(v) == imemo_ment) {
|
||||||
const rb_method_entry_t *me = (rb_method_entry_t *) v;
|
const rb_method_entry_t *me = (const rb_method_entry_t *) v;
|
||||||
VALUE path, first_lineno, first_column, last_lineno, last_column;
|
VALUE path, first_lineno, first_column, last_lineno, last_column;
|
||||||
VALUE data[5], ncoverage, methods;
|
VALUE data[5], ncoverage, methods;
|
||||||
VALUE methods_id = ID2SYM(rb_intern("methods"));
|
VALUE methods_id = ID2SYM(rb_intern("methods"));
|
||||||
|
|
2
gc.c
2
gc.c
|
@ -7829,7 +7829,7 @@ void rb_update_st_references(struct st_table *ht)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gc_ref_update_method_entry(rb_objspace_t *objspace, rb_method_entry_t *me)
|
gc_ref_update_method_entry(rb_objspace_t *objspace, const rb_method_entry_t *me)
|
||||||
{
|
{
|
||||||
const rb_method_definition_t *def = me->def;
|
const rb_method_definition_t *def = me->def;
|
||||||
|
|
||||||
|
|
43
method.h
43
method.h
|
@ -49,53 +49,24 @@ typedef struct rb_cref_struct {
|
||||||
/* method data type */
|
/* method data type */
|
||||||
|
|
||||||
typedef struct rb_method_entry_struct {
|
typedef struct rb_method_entry_struct {
|
||||||
VALUE flags;
|
const VALUE flags;
|
||||||
VALUE defined_class;
|
const VALUE defined_class;
|
||||||
struct rb_method_definition_struct * const def;
|
struct rb_method_definition_struct * const def;
|
||||||
ID called_id;
|
const ID called_id;
|
||||||
VALUE owner;
|
const VALUE owner;
|
||||||
} rb_method_entry_t;
|
} rb_method_entry_t;
|
||||||
|
|
||||||
typedef struct rb_callable_method_entry_struct { /* same fields with rb_method_entry_t */
|
typedef struct rb_callable_method_entry_struct { /* same fields with rb_method_entry_t */
|
||||||
VALUE flags;
|
const VALUE flags;
|
||||||
const VALUE defined_class;
|
const VALUE defined_class;
|
||||||
struct rb_method_definition_struct * const def;
|
struct rb_method_definition_struct * const def;
|
||||||
ID called_id;
|
const ID called_id;
|
||||||
const VALUE owner;
|
const VALUE owner;
|
||||||
} rb_callable_method_entry_t;
|
} rb_callable_method_entry_t;
|
||||||
|
|
||||||
#define METHOD_ENTRY_VISI(me) (rb_method_visibility_t)(((me)->flags & (IMEMO_FL_USER0 | IMEMO_FL_USER1)) >> (IMEMO_FL_USHIFT+0))
|
#define METHOD_ENTRY_VISI(me) (rb_method_visibility_t)(((me)->flags & (IMEMO_FL_USER0 | IMEMO_FL_USER1)) >> (IMEMO_FL_USHIFT+0))
|
||||||
#define METHOD_ENTRY_BASIC(me) (int) (((me)->flags & (IMEMO_FL_USER2 )) >> (IMEMO_FL_USHIFT+2))
|
#define METHOD_ENTRY_BASIC(me) (int) (((me)->flags & (IMEMO_FL_USER2 )) >> (IMEMO_FL_USHIFT+2))
|
||||||
|
|
||||||
static inline void
|
|
||||||
METHOD_ENTRY_VISI_SET(rb_method_entry_t *me, rb_method_visibility_t visi)
|
|
||||||
{
|
|
||||||
VM_ASSERT((int)visi >= 0 && visi <= 3);
|
|
||||||
me->flags = (me->flags & ~(IMEMO_FL_USER0 | IMEMO_FL_USER1)) | (visi << (IMEMO_FL_USHIFT+0));
|
|
||||||
}
|
|
||||||
static inline void
|
|
||||||
METHOD_ENTRY_BASIC_SET(rb_method_entry_t *me, unsigned int basic)
|
|
||||||
{
|
|
||||||
VM_ASSERT(basic <= 1);
|
|
||||||
me->flags = (me->flags & ~(IMEMO_FL_USER2 )) | (basic << (IMEMO_FL_USHIFT+2));
|
|
||||||
}
|
|
||||||
static inline void
|
|
||||||
METHOD_ENTRY_FLAGS_SET(rb_method_entry_t *me, rb_method_visibility_t visi, unsigned int basic)
|
|
||||||
{
|
|
||||||
VM_ASSERT((int)visi >= 0 && visi <= 3);
|
|
||||||
VM_ASSERT(basic <= 1);
|
|
||||||
me->flags =
|
|
||||||
(me->flags & ~(IMEMO_FL_USER0|IMEMO_FL_USER1|IMEMO_FL_USER2)) |
|
|
||||||
((visi << (IMEMO_FL_USHIFT+0)) | (basic << (IMEMO_FL_USHIFT+2)));
|
|
||||||
}
|
|
||||||
static inline void
|
|
||||||
METHOD_ENTRY_FLAGS_COPY(rb_method_entry_t *dst, const rb_method_entry_t *src)
|
|
||||||
{
|
|
||||||
dst->flags =
|
|
||||||
(dst->flags & ~(IMEMO_FL_USER0|IMEMO_FL_USER1|IMEMO_FL_USER2)) |
|
|
||||||
(src->flags & (IMEMO_FL_USER0|IMEMO_FL_USER1|IMEMO_FL_USER2));
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
VM_METHOD_TYPE_ISEQ, /*!< Ruby method */
|
VM_METHOD_TYPE_ISEQ, /*!< Ruby method */
|
||||||
VM_METHOD_TYPE_CFUNC, /*!< C method */
|
VM_METHOD_TYPE_CFUNC, /*!< C method */
|
||||||
|
@ -190,7 +161,7 @@ void rb_add_method_iseq(VALUE klass, ID mid, const rb_iseq_t *iseq, rb_cref_t *c
|
||||||
void rb_add_refined_method_entry(VALUE refined_class, ID mid);
|
void rb_add_refined_method_entry(VALUE refined_class, ID mid);
|
||||||
void rb_add_method(VALUE klass, ID mid, rb_method_type_t type, void *option, rb_method_visibility_t visi);
|
void rb_add_method(VALUE klass, ID mid, rb_method_type_t type, void *option, rb_method_visibility_t visi);
|
||||||
|
|
||||||
rb_method_entry_t *rb_method_entry_set(VALUE klass, ID mid, const rb_method_entry_t *, rb_method_visibility_t noex);
|
const rb_method_entry_t *rb_method_entry_set(VALUE klass, ID mid, const rb_method_entry_t *, rb_method_visibility_t noex);
|
||||||
const rb_method_entry_t *rb_method_entry_from_template(const rb_method_entry_t *template, const void *opts);
|
const rb_method_entry_t *rb_method_entry_from_template(const rb_method_entry_t *template, const void *opts);
|
||||||
const rb_method_entry_t *rb_method_entry_for_missing(ID mid, VALUE klass);
|
const rb_method_entry_t *rb_method_entry_for_missing(ID mid, VALUE klass);
|
||||||
|
|
||||||
|
|
8
proc.c
8
proc.c
|
@ -1426,7 +1426,7 @@ bm_compact(void *ptr)
|
||||||
UPDATE_REFERENCE(data->recv);
|
UPDATE_REFERENCE(data->recv);
|
||||||
UPDATE_REFERENCE(data->klass);
|
UPDATE_REFERENCE(data->klass);
|
||||||
UPDATE_REFERENCE(data->iclass);
|
UPDATE_REFERENCE(data->iclass);
|
||||||
UPDATE_TYPED_REFERENCE(rb_method_entry_t *, data->me);
|
UPDATE_TYPED_REFERENCE(const rb_method_entry_t *, data->me);
|
||||||
}
|
}
|
||||||
|
|
||||||
static size_t
|
static size_t
|
||||||
|
@ -1519,7 +1519,7 @@ mnew_internal(const rb_method_entry_t *me, VALUE klass, VALUE iclass,
|
||||||
if (me->defined_class) {
|
if (me->defined_class) {
|
||||||
VALUE klass = RCLASS_SUPER(RCLASS_ORIGIN(me->defined_class));
|
VALUE klass = RCLASS_SUPER(RCLASS_ORIGIN(me->defined_class));
|
||||||
id = me->def->original_id;
|
id = me->def->original_id;
|
||||||
me = (rb_method_entry_t *)rb_callable_method_entry_with_refinements(klass, id, &iclass);
|
me = (const rb_method_entry_t *)rb_callable_method_entry_with_refinements(klass, id, &iclass);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
VALUE klass = RCLASS_SUPER(me->owner);
|
VALUE klass = RCLASS_SUPER(me->owner);
|
||||||
|
@ -1557,7 +1557,7 @@ mnew(VALUE klass, VALUE obj, ID id, VALUE mclass, int scope)
|
||||||
me = rb_method_entry_with_refinements(klass, id, &iclass);
|
me = rb_method_entry_with_refinements(klass, id, &iclass);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
me = (rb_method_entry_t *)rb_callable_method_entry_with_refinements(klass, id, &iclass);
|
me = (const rb_method_entry_t *)rb_callable_method_entry_with_refinements(klass, id, &iclass);
|
||||||
}
|
}
|
||||||
return mnew_from_me(me, klass, iclass, obj, id, mclass, scope);
|
return mnew_from_me(me, klass, iclass, obj, id, mclass, scope);
|
||||||
}
|
}
|
||||||
|
@ -2947,7 +2947,7 @@ method_super_method(VALUE method)
|
||||||
super_class = RCLASS_SUPER(RCLASS_ORIGIN(iclass));
|
super_class = RCLASS_SUPER(RCLASS_ORIGIN(iclass));
|
||||||
mid = data->me->called_id;
|
mid = data->me->called_id;
|
||||||
if (!super_class) return Qnil;
|
if (!super_class) return Qnil;
|
||||||
me = (rb_method_entry_t *)rb_callable_method_entry_with_refinements(super_class, mid, &iclass);
|
me = (const rb_method_entry_t *)rb_callable_method_entry_with_refinements(super_class, mid, &iclass);
|
||||||
if (!me) return Qnil;
|
if (!me) return Qnil;
|
||||||
return mnew_internal(me, me->owner, iclass, data->recv, mid, rb_obj_class(method), FALSE, FALSE);
|
return mnew_internal(me, me->owner, iclass, data->recv, mid, rb_obj_class(method), FALSE, FALSE);
|
||||||
}
|
}
|
||||||
|
|
2
vm.c
2
vm.c
|
@ -1595,7 +1595,7 @@ static enum rb_id_table_iterator_result
|
||||||
check_redefined_method(ID mid, VALUE value, void *data)
|
check_redefined_method(ID mid, VALUE value, void *data)
|
||||||
{
|
{
|
||||||
VALUE klass = (VALUE)data;
|
VALUE klass = (VALUE)data;
|
||||||
const rb_method_entry_t *me = (rb_method_entry_t *)value;
|
const rb_method_entry_t *me = (const rb_method_entry_t *)value;
|
||||||
const rb_method_entry_t *newme = rb_method_entry(klass, mid);
|
const rb_method_entry_t *newme = rb_method_entry(klass, mid);
|
||||||
|
|
||||||
if (newme != me) rb_vm_check_redefinition_opt_method(me, me->owner);
|
if (newme != me) rb_vm_check_redefinition_opt_method(me, me->owner);
|
||||||
|
|
|
@ -1349,7 +1349,7 @@ frame2iseq(VALUE frame)
|
||||||
return (const rb_iseq_t *)frame;
|
return (const rb_iseq_t *)frame;
|
||||||
case imemo_ment:
|
case imemo_ment:
|
||||||
{
|
{
|
||||||
const rb_callable_method_entry_t *cme = (rb_callable_method_entry_t *)frame;
|
const rb_callable_method_entry_t *cme = (const rb_callable_method_entry_t *)frame;
|
||||||
switch (cme->def->type) {
|
switch (cme->def->type) {
|
||||||
case VM_METHOD_TYPE_ISEQ:
|
case VM_METHOD_TYPE_ISEQ:
|
||||||
return cme->def->body.iseq.iseqptr;
|
return cme->def->body.iseq.iseqptr;
|
||||||
|
@ -1405,7 +1405,7 @@ frame2klass(VALUE frame)
|
||||||
if (frame == Qnil) return Qnil;
|
if (frame == Qnil) return Qnil;
|
||||||
|
|
||||||
if (RB_TYPE_P(frame, T_IMEMO)) {
|
if (RB_TYPE_P(frame, T_IMEMO)) {
|
||||||
const rb_callable_method_entry_t *cme = (rb_callable_method_entry_t *)frame;
|
const rb_callable_method_entry_t *cme = (const rb_callable_method_entry_t *)frame;
|
||||||
|
|
||||||
if (imemo_type(frame) == imemo_ment) {
|
if (imemo_type(frame) == imemo_ment) {
|
||||||
return cme->defined_class;
|
return cme->defined_class;
|
||||||
|
|
|
@ -578,8 +578,8 @@ vm_getspecial(const rb_execution_context_t *ec, const VALUE *lep, rb_num_t key,
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
PUREFUNC(static rb_callable_method_entry_t *check_method_entry(VALUE obj, int can_be_svar));
|
PUREFUNC(static const rb_callable_method_entry_t *check_method_entry(VALUE obj, int can_be_svar));
|
||||||
static rb_callable_method_entry_t *
|
static const rb_callable_method_entry_t *
|
||||||
check_method_entry(VALUE obj, int can_be_svar)
|
check_method_entry(VALUE obj, int can_be_svar)
|
||||||
{
|
{
|
||||||
if (obj == Qfalse) return NULL;
|
if (obj == Qfalse) return NULL;
|
||||||
|
@ -590,7 +590,7 @@ check_method_entry(VALUE obj, int can_be_svar)
|
||||||
|
|
||||||
switch (imemo_type(obj)) {
|
switch (imemo_type(obj)) {
|
||||||
case imemo_ment:
|
case imemo_ment:
|
||||||
return (rb_callable_method_entry_t *)obj;
|
return (const rb_callable_method_entry_t *)obj;
|
||||||
case imemo_cref:
|
case imemo_cref:
|
||||||
return NULL;
|
return NULL;
|
||||||
case imemo_svar:
|
case imemo_svar:
|
||||||
|
@ -609,7 +609,7 @@ MJIT_STATIC const rb_callable_method_entry_t *
|
||||||
rb_vm_frame_method_entry(const rb_control_frame_t *cfp)
|
rb_vm_frame_method_entry(const rb_control_frame_t *cfp)
|
||||||
{
|
{
|
||||||
const VALUE *ep = cfp->ep;
|
const VALUE *ep = cfp->ep;
|
||||||
rb_callable_method_entry_t *me;
|
const rb_callable_method_entry_t *me;
|
||||||
|
|
||||||
while (!VM_ENV_LOCAL_P(ep)) {
|
while (!VM_ENV_LOCAL_P(ep)) {
|
||||||
if ((me = check_method_entry(ep[VM_ENV_DATA_INDEX_ME_CREF], FALSE)) != NULL) return me;
|
if ((me = check_method_entry(ep[VM_ENV_DATA_INDEX_ME_CREF], FALSE)) != NULL) return me;
|
||||||
|
@ -620,7 +620,7 @@ rb_vm_frame_method_entry(const rb_control_frame_t *cfp)
|
||||||
}
|
}
|
||||||
|
|
||||||
static rb_cref_t *
|
static rb_cref_t *
|
||||||
method_entry_cref(rb_callable_method_entry_t *me)
|
method_entry_cref(const rb_callable_method_entry_t *me)
|
||||||
{
|
{
|
||||||
switch (me->def->type) {
|
switch (me->def->type) {
|
||||||
case VM_METHOD_TYPE_ISEQ:
|
case VM_METHOD_TYPE_ISEQ:
|
||||||
|
@ -644,7 +644,7 @@ check_cref(VALUE obj, int can_be_svar)
|
||||||
|
|
||||||
switch (imemo_type(obj)) {
|
switch (imemo_type(obj)) {
|
||||||
case imemo_ment:
|
case imemo_ment:
|
||||||
return method_entry_cref((rb_callable_method_entry_t *)obj);
|
return method_entry_cref((const rb_callable_method_entry_t *)obj);
|
||||||
case imemo_cref:
|
case imemo_cref:
|
||||||
return (rb_cref_t *)obj;
|
return (rb_cref_t *)obj;
|
||||||
case imemo_svar:
|
case imemo_svar:
|
||||||
|
|
92
vm_method.c
92
vm_method.c
|
@ -41,7 +41,7 @@ struct cache_entry {
|
||||||
rb_serial_t method_state;
|
rb_serial_t method_state;
|
||||||
rb_serial_t class_serial;
|
rb_serial_t class_serial;
|
||||||
ID mid;
|
ID mid;
|
||||||
rb_method_entry_t* me;
|
const rb_method_entry_t* me;
|
||||||
VALUE defined_class;
|
VALUE defined_class;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -167,17 +167,17 @@ rb_free_method_entry(const rb_method_entry_t *me)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline rb_method_entry_t *search_method(VALUE klass, ID id, VALUE *defined_class_ptr);
|
static inline const rb_method_entry_t *search_method(VALUE klass, ID id, VALUE *defined_class_ptr);
|
||||||
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);
|
||||||
|
|
||||||
static inline rb_method_entry_t *
|
static inline const rb_method_entry_t *
|
||||||
lookup_method_table(VALUE klass, ID id)
|
lookup_method_table(VALUE klass, ID id)
|
||||||
{
|
{
|
||||||
st_data_t body;
|
st_data_t body;
|
||||||
struct rb_id_table *m_tbl = RCLASS_M_TBL(klass);
|
struct rb_id_table *m_tbl = RCLASS_M_TBL(klass);
|
||||||
|
|
||||||
if (rb_id_table_lookup(m_tbl, id, &body)) {
|
if (rb_id_table_lookup(m_tbl, id, &body)) {
|
||||||
return (rb_method_entry_t *) body;
|
return (const rb_method_entry_t *) body;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -477,15 +477,15 @@ method_definition_addref_complement(rb_method_definition_t *def)
|
||||||
return def;
|
return def;
|
||||||
}
|
}
|
||||||
|
|
||||||
static rb_method_entry_t *
|
static const rb_method_entry_t *
|
||||||
rb_method_entry_alloc(VALUE flags, ID called_id, VALUE owner, VALUE defined_class, const rb_method_definition_t *def)
|
rb_method_entry_alloc(VALUE flags, ID called_id, VALUE owner, VALUE defined_class, const rb_method_definition_t *def)
|
||||||
{
|
{
|
||||||
rb_method_entry_t tmp = { flags, };
|
VALUE v = rb_imemo_new(imemo_ment, (VALUE)def, (VALUE)called_id, owner, defined_class);
|
||||||
rb_method_entry_t *me = (rb_method_entry_t *)rb_imemo_new(imemo_ment, (VALUE)def, (VALUE)called_id, owner, defined_class);
|
RBASIC(v)->flags =
|
||||||
METHOD_ENTRY_FLAGS_COPY(me, &tmp);
|
(RBASIC(v)->flags & ~(IMEMO_FL_USER0|IMEMO_FL_USER1|IMEMO_FL_USER2)) |
|
||||||
if (def) {
|
(flags & (IMEMO_FL_USER0|IMEMO_FL_USER1|IMEMO_FL_USER2));
|
||||||
|
const rb_method_entry_t *me = (void *)v;
|
||||||
method_definition_reset(me);
|
method_definition_reset(me);
|
||||||
}
|
|
||||||
return me;
|
return me;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -506,9 +506,8 @@ filter_defined_class(VALUE klass)
|
||||||
static inline VALUE
|
static inline VALUE
|
||||||
method_entry_flags(rb_method_visibility_t visi)
|
method_entry_flags(rb_method_visibility_t visi)
|
||||||
{
|
{
|
||||||
rb_method_entry_t tmp = { 0, };
|
return (visi << (IMEMO_FL_USHIFT+0)) |
|
||||||
METHOD_ENTRY_FLAGS_SET(&tmp, visi, !ruby_running);
|
((!ruby_running) << (IMEMO_FL_USHIFT+2));
|
||||||
return tmp.flags;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MJIT_FUNC_EXPORTED const rb_method_entry_t *
|
MJIT_FUNC_EXPORTED const rb_method_entry_t *
|
||||||
|
@ -556,7 +555,6 @@ MJIT_FUNC_EXPORTED const rb_callable_method_entry_t *
|
||||||
rb_method_entry_complement_defined_class(const rb_method_entry_t *src_me, ID called_id, VALUE defined_class)
|
rb_method_entry_complement_defined_class(const rb_method_entry_t *src_me, ID called_id, VALUE defined_class)
|
||||||
{
|
{
|
||||||
const rb_method_definition_t *def = src_me->def;
|
const rb_method_definition_t *def = src_me->def;
|
||||||
rb_method_entry_t *me;
|
|
||||||
|
|
||||||
if (!src_me->defined_class &&
|
if (!src_me->defined_class &&
|
||||||
def->type == VM_METHOD_TYPE_REFINED &&
|
def->type == VM_METHOD_TYPE_REFINED &&
|
||||||
|
@ -570,11 +568,13 @@ rb_method_entry_complement_defined_class(const rb_method_entry_t *src_me, ID cal
|
||||||
&(rb_method_refined_t) {
|
&(rb_method_refined_t) {
|
||||||
.orig_me = orig_me,
|
.orig_me = orig_me,
|
||||||
.owner = orig_me->owner});
|
.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(
|
const rb_method_entry_t *me =
|
||||||
|
rb_method_entry_alloc(
|
||||||
src_me->flags,
|
src_me->flags,
|
||||||
called_id,
|
called_id,
|
||||||
src_me->owner,
|
src_me->owner,
|
||||||
|
@ -583,11 +583,11 @@ rb_method_entry_complement_defined_class(const rb_method_entry_t *src_me, ID cal
|
||||||
|
|
||||||
VM_ASSERT(RB_TYPE_P(me->owner, T_MODULE));
|
VM_ASSERT(RB_TYPE_P(me->owner, T_MODULE));
|
||||||
|
|
||||||
return (rb_callable_method_entry_t *)me;
|
return (const rb_callable_method_entry_t *)me;
|
||||||
}
|
}
|
||||||
|
|
||||||
static rb_method_entry_t*
|
static const rb_method_entry_t*
|
||||||
make_method_entry_refined(VALUE owner, rb_method_entry_t *me)
|
make_method_entry_refined(VALUE owner, const rb_method_entry_t *me)
|
||||||
{
|
{
|
||||||
if (me->def->type == VM_METHOD_TYPE_REFINED) {
|
if (me->def->type == VM_METHOD_TYPE_REFINED) {
|
||||||
return me;
|
return me;
|
||||||
|
@ -620,7 +620,7 @@ make_method_entry_refined(VALUE owner, rb_method_entry_t *me)
|
||||||
void
|
void
|
||||||
rb_add_refined_method_entry(VALUE refined_class, ID mid)
|
rb_add_refined_method_entry(VALUE refined_class, ID mid)
|
||||||
{
|
{
|
||||||
rb_method_entry_t *me = lookup_method_table(refined_class, mid);
|
const rb_method_entry_t *me = lookup_method_table(refined_class, mid);
|
||||||
|
|
||||||
if (me) {
|
if (me) {
|
||||||
me = make_method_entry_refined(refined_class, me);
|
me = make_method_entry_refined(refined_class, me);
|
||||||
|
@ -654,11 +654,10 @@ check_override_opt_method(VALUE klass, VALUE arg)
|
||||||
* If def is given (!= NULL), then just use it and ignore original_id and otps.
|
* If def is given (!= NULL), then just use it and ignore original_id and otps.
|
||||||
* If not given, then make a new def with original_id and opts.
|
* If not given, then make a new def with original_id and opts.
|
||||||
*/
|
*/
|
||||||
static rb_method_entry_t *
|
static const rb_method_entry_t *
|
||||||
rb_method_entry_make(VALUE klass, ID mid, VALUE defined_class, rb_method_visibility_t visi,
|
rb_method_entry_make(VALUE klass, ID mid, VALUE defined_class, rb_method_visibility_t visi,
|
||||||
rb_method_type_t type, const rb_method_definition_t *def, ID original_id, void *opts)
|
rb_method_type_t type, const rb_method_definition_t *def, ID original_id, void *opts)
|
||||||
{
|
{
|
||||||
rb_method_entry_t *me;
|
|
||||||
struct rb_id_table *mtbl;
|
struct rb_id_table *mtbl;
|
||||||
st_data_t data;
|
st_data_t data;
|
||||||
int make_refined = 0;
|
int make_refined = 0;
|
||||||
|
@ -686,7 +685,7 @@ rb_method_entry_make(VALUE klass, ID mid, VALUE defined_class, rb_method_visibil
|
||||||
rb_add_refined_method_entry(refined_class, mid);
|
rb_add_refined_method_entry(refined_class, mid);
|
||||||
}
|
}
|
||||||
if (type == VM_METHOD_TYPE_REFINED) {
|
if (type == VM_METHOD_TYPE_REFINED) {
|
||||||
rb_method_entry_t *old_me = lookup_method_table(RCLASS_ORIGIN(klass), mid);
|
const rb_method_entry_t *old_me = lookup_method_table(RCLASS_ORIGIN(klass), mid);
|
||||||
if (old_me) rb_vm_check_redefinition_opt_method(old_me, klass);
|
if (old_me) rb_vm_check_redefinition_opt_method(old_me, klass);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -696,7 +695,7 @@ rb_method_entry_make(VALUE klass, ID mid, VALUE defined_class, rb_method_visibil
|
||||||
|
|
||||||
/* check re-definition */
|
/* check re-definition */
|
||||||
if (rb_id_table_lookup(mtbl, mid, &data)) {
|
if (rb_id_table_lookup(mtbl, mid, &data)) {
|
||||||
rb_method_entry_t *old_me = (rb_method_entry_t *)data;
|
const rb_method_entry_t *old_me = (const rb_method_entry_t *)data;
|
||||||
const rb_method_definition_t *old_def = old_me->def;
|
const rb_method_definition_t *old_def = old_me->def;
|
||||||
|
|
||||||
if (rb_method_definition_eq(old_def, def)) return old_me;
|
if (rb_method_definition_eq(old_def, def)) return old_me;
|
||||||
|
@ -737,7 +736,8 @@ rb_method_entry_make(VALUE klass, ID mid, VALUE defined_class, rb_method_visibil
|
||||||
if (!def) {
|
if (!def) {
|
||||||
def = rb_method_definition_create(type, original_id, opts);
|
def = rb_method_definition_create(type, original_id, opts);
|
||||||
}
|
}
|
||||||
me = rb_method_entry_alloc(
|
const rb_method_entry_t *me =
|
||||||
|
rb_method_entry_alloc(
|
||||||
method_entry_flags(visi),
|
method_entry_flags(visi),
|
||||||
mid,
|
mid,
|
||||||
defined_class,
|
defined_class,
|
||||||
|
@ -816,17 +816,17 @@ rb_add_method_iseq(VALUE klass, ID mid, const rb_iseq_t *iseq, rb_cref_t *cref,
|
||||||
rb_add_method(klass, mid, VM_METHOD_TYPE_ISEQ, &iseq_body, visi);
|
rb_add_method(klass, mid, VM_METHOD_TYPE_ISEQ, &iseq_body, visi);
|
||||||
}
|
}
|
||||||
|
|
||||||
static rb_method_entry_t *
|
static const rb_method_entry_t *
|
||||||
method_entry_set(VALUE klass, ID mid, const rb_method_entry_t *me,
|
method_entry_set(VALUE klass, ID mid, const rb_method_entry_t *me,
|
||||||
rb_method_visibility_t visi, VALUE defined_class)
|
rb_method_visibility_t visi, VALUE defined_class)
|
||||||
{
|
{
|
||||||
rb_method_entry_t *newme = rb_method_entry_make(klass, mid, defined_class, visi,
|
const rb_method_entry_t *newme = rb_method_entry_make(klass, mid, defined_class, visi,
|
||||||
me->def->type, method_definition_addref(me->def), 0, NULL);
|
me->def->type, method_definition_addref(me->def), 0, NULL);
|
||||||
method_added(klass, mid);
|
method_added(klass, mid);
|
||||||
return newme;
|
return newme;
|
||||||
}
|
}
|
||||||
|
|
||||||
rb_method_entry_t *
|
const rb_method_entry_t *
|
||||||
rb_method_entry_set(VALUE klass, ID mid, const rb_method_entry_t *me, rb_method_visibility_t visi)
|
rb_method_entry_set(VALUE klass, ID mid, const rb_method_entry_t *me, rb_method_visibility_t visi)
|
||||||
{
|
{
|
||||||
return method_entry_set(klass, mid, me, visi, klass);
|
return method_entry_set(klass, mid, me, visi, klass);
|
||||||
|
@ -860,10 +860,10 @@ rb_get_alloc_func(VALUE klass)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline rb_method_entry_t*
|
static inline const rb_method_entry_t*
|
||||||
search_method(VALUE klass, ID id, VALUE *defined_class_ptr)
|
search_method(VALUE klass, ID id, VALUE *defined_class_ptr)
|
||||||
{
|
{
|
||||||
rb_method_entry_t *me;
|
const rb_method_entry_t *me;
|
||||||
|
|
||||||
for (; klass; klass = RCLASS_SUPER(klass)) {
|
for (; klass; klass = RCLASS_SUPER(klass)) {
|
||||||
RB_DEBUG_COUNTER_INC(mc_search_super);
|
RB_DEBUG_COUNTER_INC(mc_search_super);
|
||||||
|
@ -887,12 +887,12 @@ rb_method_entry_at(VALUE klass, ID id)
|
||||||
* if you need method entry with method cache (normal case), use
|
* if you need method entry with method cache (normal case), use
|
||||||
* rb_method_entry() simply.
|
* rb_method_entry() simply.
|
||||||
*/
|
*/
|
||||||
static rb_method_entry_t *
|
static const rb_method_entry_t *
|
||||||
method_entry_get_without_cache(VALUE klass, ID id,
|
method_entry_get_without_cache(VALUE klass, ID id,
|
||||||
VALUE *defined_class_ptr)
|
VALUE *defined_class_ptr)
|
||||||
{
|
{
|
||||||
VALUE defined_class;
|
VALUE defined_class;
|
||||||
rb_method_entry_t *me = search_method(klass, id, &defined_class);
|
const rb_method_entry_t *me = search_method(klass, id, &defined_class);
|
||||||
|
|
||||||
if (ruby_running) {
|
if (ruby_running) {
|
||||||
if (OPT_GLOBAL_METHOD_CACHE) {
|
if (OPT_GLOBAL_METHOD_CACHE) {
|
||||||
|
@ -924,11 +924,11 @@ method_entry_get_without_cache(VALUE klass, ID id,
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
verify_method_cache(VALUE klass, ID id, VALUE defined_class, rb_method_entry_t *me)
|
verify_method_cache(VALUE klass, ID id, VALUE defined_class, const rb_method_entry_t *me)
|
||||||
{
|
{
|
||||||
if (!VM_DEBUG_VERIFY_METHOD_CACHE) return;
|
if (!VM_DEBUG_VERIFY_METHOD_CACHE) return;
|
||||||
VALUE actual_defined_class;
|
VALUE actual_defined_class;
|
||||||
rb_method_entry_t *actual_me =
|
const rb_method_entry_t *actual_me =
|
||||||
method_entry_get_without_cache(klass, id, &actual_defined_class);
|
method_entry_get_without_cache(klass, id, &actual_defined_class);
|
||||||
|
|
||||||
if (me != actual_me || defined_class != actual_defined_class) {
|
if (me != actual_me || defined_class != actual_defined_class) {
|
||||||
|
@ -936,7 +936,7 @@ verify_method_cache(VALUE klass, ID id, VALUE defined_class, rb_method_entry_t *
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static rb_method_entry_t *
|
static const rb_method_entry_t *
|
||||||
method_entry_get(VALUE klass, ID id, VALUE *defined_class_ptr)
|
method_entry_get(VALUE klass, ID id, VALUE *defined_class_ptr)
|
||||||
{
|
{
|
||||||
struct cache_entry *ent;
|
struct cache_entry *ent;
|
||||||
|
@ -977,7 +977,7 @@ prepare_callable_method_entry(VALUE defined_class, ID id, const rb_method_entry_
|
||||||
|
|
||||||
if (mtbl && rb_id_table_lookup(mtbl, id, (VALUE *)&me)) {
|
if (mtbl && rb_id_table_lookup(mtbl, id, (VALUE *)&me)) {
|
||||||
RB_DEBUG_COUNTER_INC(mc_cme_complement_hit);
|
RB_DEBUG_COUNTER_INC(mc_cme_complement_hit);
|
||||||
cme = (rb_callable_method_entry_t *)me;
|
cme = (const rb_callable_method_entry_t *)me;
|
||||||
VM_ASSERT(callable_method_entry_p(cme));
|
VM_ASSERT(callable_method_entry_p(cme));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -1001,7 +1001,7 @@ MJIT_FUNC_EXPORTED const rb_callable_method_entry_t *
|
||||||
rb_callable_method_entry(VALUE klass, ID id)
|
rb_callable_method_entry(VALUE klass, ID id)
|
||||||
{
|
{
|
||||||
VALUE defined_class;
|
VALUE defined_class;
|
||||||
rb_method_entry_t *me = method_entry_get(klass, id, &defined_class);
|
const rb_method_entry_t *me = method_entry_get(klass, id, &defined_class);
|
||||||
return prepare_callable_method_entry(defined_class, id, me);
|
return prepare_callable_method_entry(defined_class, id, me);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1115,7 +1115,7 @@ static void
|
||||||
remove_method(VALUE klass, ID mid)
|
remove_method(VALUE klass, ID mid)
|
||||||
{
|
{
|
||||||
VALUE data;
|
VALUE data;
|
||||||
rb_method_entry_t *me = 0;
|
const rb_method_entry_t *me = NULL;
|
||||||
VALUE self = klass;
|
VALUE self = klass;
|
||||||
|
|
||||||
klass = RCLASS_ORIGIN(klass);
|
klass = RCLASS_ORIGIN(klass);
|
||||||
|
@ -1125,7 +1125,7 @@ remove_method(VALUE klass, ID mid)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!rb_id_table_lookup(RCLASS_M_TBL(klass), mid, &data) ||
|
if (!rb_id_table_lookup(RCLASS_M_TBL(klass), mid, &data) ||
|
||||||
!(me = (rb_method_entry_t *)data) ||
|
!(me = (const rb_method_entry_t *)data) ||
|
||||||
(!me->def || me->def->type == VM_METHOD_TYPE_UNDEF) ||
|
(!me->def || me->def->type == VM_METHOD_TYPE_UNDEF) ||
|
||||||
UNDEFINED_REFINED_METHOD_P(me->def)) {
|
UNDEFINED_REFINED_METHOD_P(me->def)) {
|
||||||
rb_name_err_raise("method `%1$s' not defined in %2$s",
|
rb_name_err_raise("method `%1$s' not defined in %2$s",
|
||||||
|
@ -1183,10 +1183,18 @@ rb_mod_remove_method(int argc, VALUE *argv, VALUE mod)
|
||||||
return mod;
|
return mod;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void
|
||||||
|
METHOD_ENTRY_VISI_SET(rb_method_entry_t *me, rb_method_visibility_t visi)
|
||||||
|
{
|
||||||
|
VM_ASSERT((int)visi >= 0 && visi <= 3);
|
||||||
|
VALUE flags = (me->flags & ~(IMEMO_FL_USER0 | IMEMO_FL_USER1)) | (visi << (IMEMO_FL_USHIFT+0));
|
||||||
|
memcpy((void *)&me->flags, &flags, sizeof flags);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
rb_export_method(VALUE klass, ID name, rb_method_visibility_t visi)
|
rb_export_method(VALUE klass, ID name, rb_method_visibility_t visi)
|
||||||
{
|
{
|
||||||
rb_method_entry_t *me;
|
const rb_method_entry_t *me;
|
||||||
VALUE defined_class;
|
VALUE defined_class;
|
||||||
VALUE origin_class = RCLASS_ORIGIN(klass);
|
VALUE origin_class = RCLASS_ORIGIN(klass);
|
||||||
|
|
||||||
|
@ -1204,7 +1212,7 @@ rb_export_method(VALUE klass, ID name, rb_method_visibility_t visi)
|
||||||
rb_vm_check_redefinition_opt_method(me, klass);
|
rb_vm_check_redefinition_opt_method(me, klass);
|
||||||
|
|
||||||
if (klass == defined_class || origin_class == defined_class) {
|
if (klass == defined_class || origin_class == defined_class) {
|
||||||
METHOD_ENTRY_VISI_SET(me, visi);
|
METHOD_ENTRY_VISI_SET((rb_method_entry_t *)me, visi);
|
||||||
|
|
||||||
if (me->def->type == VM_METHOD_TYPE_REFINED && me->def->body.refined.orig_me) {
|
if (me->def->type == VM_METHOD_TYPE_REFINED && me->def->body.refined.orig_me) {
|
||||||
METHOD_ENTRY_VISI_SET((rb_method_entry_t *)me->def->body.refined.orig_me, visi);
|
METHOD_ENTRY_VISI_SET((rb_method_entry_t *)me->def->body.refined.orig_me, visi);
|
||||||
|
@ -1732,7 +1740,7 @@ rb_alias(VALUE klass, ID alias_name, ID original_name)
|
||||||
method_added(target_klass, alias_name);
|
method_added(target_klass, alias_name);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
rb_method_entry_t *alias_me;
|
const rb_method_entry_t *alias_me;
|
||||||
|
|
||||||
alias_me = method_entry_set(target_klass, alias_name, orig_me, visi, orig_me->owner);
|
alias_me = method_entry_set(target_klass, alias_name, orig_me, visi, orig_me->owner);
|
||||||
RB_OBJ_WRITE(alias_me, &alias_me->owner, target_klass);
|
RB_OBJ_WRITE(alias_me, &alias_me->owner, target_klass);
|
||||||
|
@ -1923,7 +1931,7 @@ rb_mod_ruby2_keywords(int argc, VALUE *argv, VALUE module)
|
||||||
for (i = 0; i < argc; i++) {
|
for (i = 0; i < argc; i++) {
|
||||||
VALUE v = argv[i];
|
VALUE v = argv[i];
|
||||||
ID name = rb_check_id(&v);
|
ID name = rb_check_id(&v);
|
||||||
rb_method_entry_t *me;
|
const rb_method_entry_t *me;
|
||||||
VALUE defined_class;
|
VALUE defined_class;
|
||||||
|
|
||||||
if (!name) {
|
if (!name) {
|
||||||
|
|
Загрузка…
Ссылка в новой задаче