Skip to content

Commit

Permalink
constify again.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ko1 committed Jul 22, 2019
1 parent 9095ff5 commit 1feda1c
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 23 deletions.
2 changes: 1 addition & 1 deletion class.c
Expand Up @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions eval.c
Expand Up @@ -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 */
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions include/ruby/ruby.h
Expand Up @@ -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);
Expand Down Expand Up @@ -1054,7 +1054,7 @@ struct RArray {
long len;
union {
long capa;
VALUE shared_root;
const VALUE shared_root;
} aux;
const VALUE *ptr;
} heap;
Expand Down Expand Up @@ -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)
Expand Down
24 changes: 12 additions & 12 deletions internal.h
Expand Up @@ -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;
};

Expand Down Expand Up @@ -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;
};


Expand All @@ -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)
Expand All @@ -1163,7 +1163,7 @@ struct vm_ifunc {
VALUE flags;
VALUE reserved;
VALUE (*func)(ANYARGS);
void *data;
const void *data;
struct vm_ifunc_argc argc;
};

Expand Down Expand Up @@ -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;
};
Expand Down
4 changes: 2 additions & 2 deletions vm_insnhelper.h
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 1feda1c

Please sign in to comment.