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

constify again.

Same as last commit, make some fields `const`.

include/ruby/ruby.h:
* Rasic::klass
* RArray::heap::aux::shared_root
* RRegexp::src
internal.h:
* rb_classext_struct::origin_, redefined_class
* vm_svar::cref_or_me, lastline, backref, others
* vm_throw_data::throw_obj
* vm_ifunc::data
* MEMO::v1, v2, u3::value

While modifying this patch, I found write-barrier miss on
rb_classext_struct::redefined_class.

Also vm_throw_data::throw_state is only `int` so change the type.
This commit is contained in:
Koichi Sasada 2019-07-22 17:44:58 +09:00
parent 9095ff53cf
commit 1feda1c2b0
5 changed files with 23 additions and 23 deletions

View file

@ -176,7 +176,7 @@ class_alloc(VALUE flags, VALUE klass)
*/
RCLASS_SET_ORIGIN((VALUE)obj, (VALUE)obj);
RCLASS_SERIAL(obj) = rb_next_class_serial();
RCLASS_REFINED_CLASS(obj) = Qnil;
RB_OBJ_WRITE(obj, &RCLASS_REFINED_CLASS(obj), Qnil);
RCLASS_EXT(obj)->allocator = 0;
return (VALUE)obj;

10
eval.c
View file

@ -1356,7 +1356,7 @@ rb_using_refinement(rb_cref_t *cref, VALUE klass, VALUE module)
FL_SET(module, RMODULE_IS_OVERLAID);
superclass = refinement_superclass(superclass);
c = iclass = rb_include_class_new(module, superclass);
RCLASS_REFINED_CLASS(c) = klass;
RB_OBJ_WRITE(c, &RCLASS_REFINED_CLASS(c), klass);
RCLASS_M_TBL(OBJ_WB_UNPROTECT(c)) =
RCLASS_M_TBL(OBJ_WB_UNPROTECT(module)); /* TODO: check unprotecting */
@ -1365,8 +1365,8 @@ rb_using_refinement(rb_cref_t *cref, VALUE klass, VALUE module)
while (module && module != klass) {
FL_SET(module, RMODULE_IS_OVERLAID);
c = RCLASS_SET_SUPER(c, rb_include_class_new(module, RCLASS_SUPER(c)));
RCLASS_REFINED_CLASS(c) = klass;
module = RCLASS_SUPER(module);
RB_OBJ_WRITE(c, &RCLASS_REFINED_CLASS(c), klass);
module = RCLASS_SUPER(module);
}
rb_hash_aset(CREF_REFINEMENTS(cref), klass, iclass);
}
@ -1451,12 +1451,12 @@ add_activated_refinement(VALUE activated_refinements,
FL_SET(refinement, RMODULE_IS_OVERLAID);
superclass = refinement_superclass(superclass);
c = iclass = rb_include_class_new(refinement, superclass);
RCLASS_REFINED_CLASS(c) = klass;
RB_OBJ_WRITE(c, &RCLASS_REFINED_CLASS(c), klass);
refinement = RCLASS_SUPER(refinement);
while (refinement && refinement != klass) {
FL_SET(refinement, RMODULE_IS_OVERLAID);
c = RCLASS_SET_SUPER(c, rb_include_class_new(refinement, RCLASS_SUPER(c)));
RCLASS_REFINED_CLASS(c) = klass;
RB_OBJ_WRITE(c, &RCLASS_REFINED_CLASS(c), klass);
refinement = RCLASS_SUPER(refinement);
}
rb_hash_aset(activated_refinements, klass, iclass);

View file

@ -887,7 +887,7 @@ enum ruby_fl_type {
struct RUBY_ALIGNAS(SIZEOF_VALUE) RBasic {
VALUE flags;
VALUE klass;
const VALUE klass;
};
VALUE rb_obj_hide(VALUE obj);
@ -1054,7 +1054,7 @@ struct RArray {
long len;
union {
long capa;
VALUE shared_root;
const VALUE shared_root;
} aux;
const VALUE *ptr;
} heap;
@ -1109,7 +1109,7 @@ struct RArray {
struct RRegexp {
struct RBasic basic;
struct re_pattern_buffer *ptr;
VALUE src;
const VALUE src;
unsigned long usecnt;
};
#define RREGEXP_PTR(r) (RREGEXP(r)->ptr)

View file

@ -1009,8 +1009,8 @@ struct rb_classext_struct {
*/
rb_subclass_entry_t **module_subclasses;
rb_serial_t class_serial;
VALUE origin_;
VALUE refined_class;
const VALUE origin_;
const VALUE refined_class;
rb_alloc_func_t allocator;
};
@ -1127,10 +1127,10 @@ imemo_type_p(VALUE imemo, enum imemo_type imemo_type)
/*! SVAR (Special VARiable) */
struct vm_svar {
VALUE flags;
VALUE cref_or_me; /*!< class reference or rb_method_entry_t */
VALUE lastline;
VALUE backref;
VALUE others;
const VALUE cref_or_me; /*!< class reference or rb_method_entry_t */
const VALUE lastline;
const VALUE backref;
const VALUE others;
};
@ -1140,9 +1140,9 @@ struct vm_svar {
struct vm_throw_data {
VALUE flags;
VALUE reserved;
VALUE throw_obj;
const VALUE throw_obj;
const struct rb_control_frame_struct *catch_frame;
VALUE throw_state;
int throw_state;
};
#define THROW_DATA_P(err) RB_TYPE_P((VALUE)(err), T_IMEMO)
@ -1163,7 +1163,7 @@ struct vm_ifunc {
VALUE flags;
VALUE reserved;
VALUE (*func)(ANYARGS);
void *data;
const void *data;
struct vm_ifunc_argc argc;
};
@ -1220,12 +1220,12 @@ void rb_strterm_mark(VALUE obj);
struct MEMO {
VALUE flags;
VALUE reserved;
VALUE v1;
VALUE v2;
const VALUE v1;
const VALUE v2;
union {
long cnt;
long state;
VALUE value;
const VALUE value;
VALUE (*func)(ANYARGS);
} u3;
};

View file

@ -203,7 +203,7 @@ static inline int
THROW_DATA_STATE(const struct vm_throw_data *obj)
{
VM_ASSERT(THROW_DATA_P(obj));
return (int)obj->throw_state;
return obj->throw_state;
}
static inline int
@ -224,7 +224,7 @@ static inline void
THROW_DATA_STATE_SET(struct vm_throw_data *obj, int st)
{
VM_ASSERT(THROW_DATA_P(obj));
obj->throw_state = (VALUE)st;
obj->throw_state = st;
}
static inline void