ruby-changes:38512
From: ko1 <ko1@a...>
Date: Thu, 21 May 2015 18:01:58 +0900 (JST)
Subject: [ruby-changes:38512] ko1:r50593 (trunk): * iseq.c: constify.
ko1 2015-05-21 18:01:44 +0900 (Thu, 21 May 2015) New Revision: 50593 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=50593 Log: * iseq.c: constify. * iseq.h: ditto. * method.h: ditto. * proc.c: ditto. * vm_method.c: ditto. Modified files: trunk/ChangeLog trunk/iseq.c trunk/iseq.h trunk/method.h trunk/proc.c trunk/vm_method.c Index: method.h =================================================================== --- method.h (revision 50592) +++ method.h (revision 50593) @@ -135,7 +135,7 @@ int rb_method_entry_arity(const rb_metho https://github.com/ruby/ruby/blob/trunk/method.h#L135 int rb_method_entry_eq(const rb_method_entry_t *m1, const rb_method_entry_t *m2); st_index_t rb_hash_method_entry(st_index_t hash, const rb_method_entry_t *me); -VALUE rb_method_entry_location(rb_method_entry_t *me); +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); Index: ChangeLog =================================================================== --- ChangeLog (revision 50592) +++ ChangeLog (revision 50593) @@ -1,3 +1,15 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Thu May 21 18:00:19 2015 Koichi Sasada <ko1@a...> + + * iseq.c: constify. + + * iseq.h: ditto. + + * method.h: ditto. + + * proc.c: ditto. + + * vm_method.c: ditto. + Thu May 21 17:44:53 2015 Koichi Sasada <ko1@a...> * proc.c: fix issues caused by binding created from Method#to_proc. Index: iseq.c =================================================================== --- iseq.c (revision 50592) +++ iseq.c (revision 50593) @@ -1508,7 +1508,7 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/iseq.c#L1508 iseq_s_of(VALUE klass, VALUE body) { VALUE ret = Qnil; - rb_iseq_t *iseq; + const rb_iseq_t *iseq; rb_secure(1); Index: iseq.h =================================================================== --- iseq.h (revision 50592) +++ iseq.h (revision 50593) @@ -34,8 +34,8 @@ VALUE rb_iseq_line_trace_all(VALUE iseqv https://github.com/ruby/ruby/blob/trunk/iseq.h#L34 VALUE rb_iseq_line_trace_specify(VALUE iseqval, VALUE pos, VALUE set); /* proc.c */ -rb_iseq_t *rb_method_iseq(VALUE body); -rb_iseq_t *rb_proc_get_iseq(VALUE proc, int *is_proc); +const rb_iseq_t *rb_method_iseq(VALUE body); +const rb_iseq_t *rb_proc_get_iseq(VALUE proc, int *is_proc); struct rb_compile_option_struct { int inline_const_cache; Index: proc.c =================================================================== --- proc.c (revision 50592) +++ proc.c (revision 50593) @@ -722,9 +722,9 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/proc.c#L722 proc_call(int argc, VALUE *argv, VALUE procval) { VALUE vret; + const rb_block_t *blockptr = 0; + const rb_iseq_t *iseq; rb_proc_t *proc; - rb_block_t *blockptr = 0; - rb_iseq_t *iseq; VALUE passed_procval; GetProcPtr(procval, proc); @@ -851,7 +851,8 @@ rb_iseq_min_max_arity(const rb_iseq_t *i https://github.com/ruby/ruby/blob/trunk/proc.c#L851 static int rb_block_min_max_arity(rb_block_t *block, int *max) { - rb_iseq_t *iseq = block->iseq; + const rb_iseq_t *iseq = block->iseq; + if (iseq) { if (!RUBY_VM_IFUNC_P(iseq)) { return rb_iseq_min_max_arity(iseq, max); @@ -916,11 +917,11 @@ rb_block_arity(void) https://github.com/ruby/ruby/blob/trunk/proc.c#L917 #define get_proc_iseq rb_proc_get_iseq -rb_iseq_t * +const rb_iseq_t * rb_proc_get_iseq(VALUE self, int *is_proc) { - rb_proc_t *proc; - rb_iseq_t *iseq; + const rb_proc_t *proc; + const rb_iseq_t *iseq; GetProcPtr(self, proc); iseq = proc->block.iseq; @@ -938,7 +939,7 @@ rb_proc_get_iseq(VALUE self, int *is_pro https://github.com/ruby/ruby/blob/trunk/proc.c#L939 } static VALUE -iseq_location(rb_iseq_t *iseq) +iseq_location(const rb_iseq_t *iseq) { VALUE loc[2]; @@ -1000,7 +1001,7 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/proc.c#L1001 rb_proc_parameters(VALUE self) { int is_proc; - rb_iseq_t *iseq = get_proc_iseq(self, &is_proc); + const rb_iseq_t *iseq = get_proc_iseq(self, &is_proc); if (!iseq) { return unnamed_parameters(rb_proc_arity(self)); } @@ -1050,7 +1051,7 @@ proc_to_s(VALUE self) https://github.com/ruby/ruby/blob/trunk/proc.c#L1051 VALUE str = 0; rb_proc_t *proc; const char *cname = rb_obj_classname(self); - rb_iseq_t *iseq; + const rb_iseq_t *iseq; const char *is_lambda; GetProcPtr(self, proc); @@ -1189,7 +1190,7 @@ mnew_missing(VALUE rclass, VALUE klass, https://github.com/ruby/ruby/blob/trunk/proc.c#L1190 } static VALUE -mnew_internal(rb_method_entry_t *me, VALUE defined_class, VALUE klass, +mnew_internal(const rb_method_entry_t *me, VALUE defined_class, VALUE klass, VALUE obj, ID id, VALUE mclass, int scope, int error) { struct METHOD *data; @@ -1246,7 +1247,7 @@ mnew_internal(rb_method_entry_t *me, VAL https://github.com/ruby/ruby/blob/trunk/proc.c#L1247 } static VALUE -mnew_from_me(rb_method_entry_t *me, VALUE defined_class, VALUE klass, +mnew_from_me(const rb_method_entry_t *me, VALUE defined_class, VALUE klass, VALUE obj, ID id, VALUE mclass, int scope) { return mnew_internal(me, defined_class, klass, obj, id, mclass, scope, TRUE); @@ -1256,7 +1257,7 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/proc.c#L1257 mnew(VALUE klass, VALUE obj, ID id, VALUE mclass, int scope) { VALUE defined_class; - rb_method_entry_t *me = + const rb_method_entry_t *me = rb_method_entry_without_refinements(klass, id, &defined_class); return mnew_from_me(me, defined_class, klass, obj, id, mclass, scope); } @@ -1559,9 +1560,10 @@ rb_obj_public_method(VALUE obj, VALUE vi https://github.com/ruby/ruby/blob/trunk/proc.c#L1560 VALUE rb_obj_singleton_method(VALUE obj, VALUE vid) { - rb_method_entry_t *me; + const rb_method_entry_t *me; VALUE klass; ID id = rb_check_id(&vid); + if (!id) { if (!NIL_P(klass = rb_singleton_class_get(obj)) && respond_to_missing_p(klass, obj, vid, FALSE)) { @@ -2048,6 +2050,7 @@ static int https://github.com/ruby/ruby/blob/trunk/proc.c#L2050 rb_method_entry_min_max_arity(const rb_method_entry_t *me, int *max) { const rb_method_definition_t *def = me->def; + if (!def) return *max = 0; switch (def->type) { case VM_METHOD_TYPE_CFUNC: @@ -2149,13 +2152,14 @@ method_arity(VALUE method) https://github.com/ruby/ruby/blob/trunk/proc.c#L2152 return rb_method_entry_arity(data->me); } -static rb_method_entry_t * +static const rb_method_entry_t * original_method_entry(VALUE mod, ID id) { VALUE rclass; - rb_method_entry_t *me; + const rb_method_entry_t *me; + while ((me = rb_method_entry(mod, id, &rclass)) != 0) { - rb_method_definition_t *def = me->def; + const rb_method_definition_t *def = me->def; if (!def) break; if (def->type != VM_METHOD_TYPE_ZSUPER) break; mod = RCLASS_SUPER(rclass); @@ -2167,7 +2171,7 @@ original_method_entry(VALUE mod, ID id) https://github.com/ruby/ruby/blob/trunk/proc.c#L2171 static int method_min_max_arity(VALUE method, int *max) { - struct METHOD *data; + const struct METHOD *data; TypedData_Get_Struct(method, struct METHOD, &method_data_type, data); return rb_method_entry_min_max_arity(data->me, max); @@ -2176,7 +2180,7 @@ method_min_max_arity(VALUE method, int * https://github.com/ruby/ruby/blob/trunk/proc.c#L2180 int rb_mod_method_arity(VALUE mod, ID id) { - rb_method_entry_t *me = original_method_entry(mod, id); + const rb_method_entry_t *me = original_method_entry(mod, id); if (!me) return 0; /* should raise? */ return rb_method_entry_arity(me); } @@ -2187,17 +2191,17 @@ rb_obj_method_arity(VALUE obj, ID id) https://github.com/ruby/ruby/blob/trunk/proc.c#L2191 return rb_mod_method_arity(CLASS_OF(obj), id); } -static inline rb_method_definition_t * +static inline const rb_method_definition_t * method_def(VALUE method) { - struct METHOD *data; + const struct METHOD *data; TypedData_Get_Struct(method, struct METHOD, &method_data_type, data); return data->me->def; } -static rb_iseq_t * -method_def_iseq(rb_method_definition_t *def) +static const rb_iseq_t * +method_def_iseq(const rb_method_definition_t *def) { switch (def->type) { case VM_METHOD_TYPE_BMETHOD: @@ -2209,7 +2213,7 @@ method_def_iseq(rb_method_definition_t * https://github.com/ruby/ruby/blob/trunk/proc.c#L2213 } } -rb_iseq_t * +const rb_iseq_t * rb_method_iseq(VALUE method) { return method_def_iseq(method_def(method)); @@ -2218,7 +2222,7 @@ rb_method_iseq(VALUE method) https://github.com/ruby/ruby/blob/trunk/proc.c#L2222 static const rb_cref_t * method_cref(VALUE method) { - rb_method_definition_t *def = method_def(method); + const rb_method_definition_t *def = method_def(method); switch (def->type) { case VM_METHOD_TYPE_ISEQ: @@ -2229,7 +2233,7 @@ method_cref(VALUE method) https://github.com/ruby/ruby/blob/trunk/proc.c#L2233 } static VALUE -method_def_location(rb_method_definition_t *def) +method_def_location(const rb_method_definition_t *def) { if (def->type == VM_METHOD_TYPE_ATTRSET || def->type == VM_METHOD_TYPE_IVAR) { if (!def->body.attr.location) @@ -2240,7 +2244,7 @@ method_def_location(rb_method_definition https://github.com/ruby/ruby/blob/trunk/proc.c#L2244 } VALUE -rb_method_entry_location(rb_method_entry_t *me) +rb_method_entry_location(const rb_method_entry_t *me) { if (!me || !me->def) return Qnil; return method_def_location(me->def); @@ -2249,7 +2253,7 @@ rb_method_entry_location(rb_method_entry https://github.com/ruby/ruby/blob/trunk/proc.c#L2253 VALUE rb_mod_method_location(VALUE mod, ID id) { - rb_method_entry_t *me = original_method_entry(mod, id); + const rb_method_entry_t *me = original_method_entry(mod, id); return rb_method_entry_location(me); } @@ -2270,8 +2274,7 @@ rb_obj_method_location(VALUE obj, ID id) https://github.com/ruby/ruby/blob/trunk/proc.c#L2274 VALUE rb_method_location(VALUE method) { - rb_method_definition_t *def = method_def(method); - return method_def_location(def); + return method_def_location(method_def(method)); } /* @@ -2284,7 +2287,7 @@ rb_method_location(VALUE method) https://github.com/ruby/ruby/blob/trunk/proc.c#L2287 static VALUE rb_method_parameters(VALUE method) { - rb_iseq_t *iseq = rb_method_iseq(method); + const rb_iseq_t *iseq = rb_method_iseq(method); if (!iseq) { return unnamed_parameters(method_arity(method)); } @@ -2430,9 +2433,9 @@ method_to_proc(VALUE method) https://github.com/ruby/ruby/blob/trunk/proc.c#L2433 static VALUE method_super_method(VALUE method) { - struct METHOD *data; + const struct METHOD *data; VALUE defined_class, super_class; - rb_method_entry_t *me; + const rb_method_entry_t *me; TypedData_Get_Struct(method, struct METHOD, &method_data_type, data); defined_class = data->defined_class; @@ -2513,10 +2516,10 @@ env_clone(VALUE envval, VALUE receiver, https://github.com/ruby/ruby/blob/trunk/proc.c#L2516 static VALUE proc_binding(VALUE self) { - rb_proc_t *proc; VALUE bindval, envval; + const rb_proc_t *proc; + const rb_iseq_t *iseq; rb_binding_t *bind; - rb_iseq_t *iseq; GetProcPtr(self, proc); envval = proc->envval; Index: vm_method.c =================================================================== --- vm_method.c (revision 50592) +++ vm_method.c (revision 50593) @@ -319,7 +319,7 @@ rb_method_entry_make(VALUE klass, ID mid https://github.com/ruby/ruby/blob/trunk/vm_method.c#L319 old_def->alias_count == 0 && old_def->type != VM_METHOD_TYPE_UNDEF && old_def->type != VM_METHOD_TYPE_ZSUPER) { - rb_iseq_t *iseq = 0; + const rb_iseq_t *iseq = 0; rb_warning("method redefined; discarding old %"PRIsVALUE, rb_id2str(mid)); switch (old_def->type) { -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/