From 57b817f4c550e54ff57642b50723cc7c92bdd2fe Mon Sep 17 00:00:00 2001 From: ko1 Date: Tue, 2 Jun 2015 04:20:30 +0000 Subject: * method.h: make rb_method_entry_t a VALUE. Motivation and new data structure are described in [Bug #11203]. This patch also solve the following issues. * [Bug #11200] Memory leak of method entries * [Bug #11046] __callee__ returns incorrect method name in orphan proc * test/ruby/test_method.rb: add a test for [Bug #11046]. * vm_core.h: remvoe rb_control_frame_t::me. me is located at value stack. * vm_core.h, gc.c, vm_method.c: remove unlinked_method... codes because method entries are simple VALUEs. * method.h: Now, all method entries has own independent method definititons. Strictly speaking, this change is not essential, but for future changes. * rb_method_entry_t::flag is move to rb_method_definition_t::flag. * rb_method_definition_t::alias_count is now rb_method_definition_t::alias_count_ptr, a pointer to the counter. * vm_core.h, vm_insnhelper.c (rb_vm_frame_method_entry) added to search the current method entry from value stack. * vm_insnhelper.c (VM_CHECK_MODE): introduced to enable/disable assertions. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50728 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- method.h | 48 +++++++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 23 deletions(-) (limited to 'method.h') diff --git a/method.h b/method.h index 79f72ec5ff..05db08511c 100644 --- a/method.h +++ b/method.h @@ -44,6 +44,14 @@ typedef enum { /* method data type */ +typedef struct rb_method_entry_struct { + VALUE flags; + VALUE reserved; + struct rb_method_definition_struct * const def; + ID called_id; + const VALUE klass; /* should be marked */ +} rb_method_entry_t; + typedef enum { VM_METHOD_TYPE_ISEQ, VM_METHOD_TYPE_CFUNC, @@ -61,6 +69,14 @@ typedef enum { END_OF_ENUMERATION(VM_METHOD_TYPE) } rb_method_type_t; +typedef struct rb_iseq_struct rb_iseq_t; + +typedef struct rb_method_iseq_struct { + rb_iseq_t * const iseqptr; /* should be separated from iseqval */ + rb_cref_t * const cref; /* shoudl be marked */ + const VALUE iseqval; /* should be marked */ +} rb_method_iseq_t; + typedef struct rb_method_cfunc_struct { VALUE (*func)(ANYARGS); VALUE (*invoker)(VALUE (*func)(ANYARGS), VALUE recv, int argc, const VALUE *argv); @@ -69,25 +85,21 @@ typedef struct rb_method_cfunc_struct { typedef struct rb_method_attr_struct { ID id; - const VALUE location; + const VALUE location; /* sould be marked */ } rb_method_attr_t; typedef struct rb_method_alias_struct { const struct rb_method_entry_struct *original_me; /* original_me->klass is original owner */ } rb_method_alias_t; -typedef struct rb_iseq_struct rb_iseq_t; - typedef struct rb_method_definition_struct { + rb_method_flag_t flag; rb_method_type_t type; /* method type */ - int alias_count; + int *alias_count_ptr; ID original_id; union { - struct { - rb_iseq_t *const iseq; /* should be marked */ - rb_cref_t *cref; - } iseq_body; + rb_method_iseq_t iseq; rb_method_cfunc_t cfunc; rb_method_attr_t attr; rb_method_alias_t alias; @@ -102,26 +114,13 @@ typedef struct rb_method_definition_struct { } body; } rb_method_definition_t; -typedef struct rb_method_entry_struct { - rb_method_flag_t flag; - char mark; - rb_method_definition_t *def; - ID called_id; - VALUE klass; /* should be marked */ -} rb_method_entry_t; - -struct unlinked_method_entry_list_entry { - struct unlinked_method_entry_list_entry *next; - rb_method_entry_t *me; -}; - #define UNDEFINED_METHOD_ENTRY_P(me) (!(me) || !(me)->def || (me)->def->type == VM_METHOD_TYPE_UNDEF) #define UNDEFINED_REFINED_METHOD_P(def) \ ((def)->type == VM_METHOD_TYPE_REFINED && \ UNDEFINED_METHOD_ENTRY_P((def)->body.orig_me)) void rb_add_method_cfunc(VALUE klass, ID mid, VALUE (*func)(ANYARGS), int argc, rb_method_flag_t noex); -void rb_add_method_iseq(VALUE klass, ID mid, rb_iseq_t *iseq, rb_cref_t *cref, rb_method_flag_t noex); +void rb_add_method_iseq(VALUE klass, ID mid, VALUE iseq, rb_cref_t *cref, rb_method_flag_t noex); rb_method_entry_t *rb_add_method(VALUE klass, ID mid, rb_method_type_t type, void *option, rb_method_flag_t noex); rb_method_entry_t *rb_method_entry(VALUE klass, ID id, VALUE *define_class_ptr); rb_method_entry_t *rb_method_entry_at(VALUE obj, ID id); @@ -145,8 +144,11 @@ VALUE rb_method_entry_location(const rb_method_entry_t *me); VALUE rb_mod_method_location(VALUE mod, ID id); VALUE rb_obj_method_location(VALUE obj, ID id); -void rb_mark_method_entry(const rb_method_entry_t *me); void rb_free_method_entry(const rb_method_entry_t *me); void rb_sweep_method_entry(void *vm); +rb_method_entry_t *rb_method_entry_create(ID called_id, VALUE klass, rb_method_definition_t *def); +rb_method_entry_t *rb_method_entry_clone(const rb_method_entry_t *me); +void rb_method_entry_copy(rb_method_entry_t *dst, rb_method_entry_t *src); + #endif /* METHOD_H */ -- cgit v1.2.3