Skip to content

Commit

Permalink
* include/ruby/ruby.h (OBJ_WRITE): cast to (VALUE *) for second
Browse files Browse the repository at this point in the history
  parameter `slot'. You don't need to write a cast (VALUE *) any more.
* class.c, compile.c, hash.c, iseq.c, proc.c, re.c, variable.c,
  vm.c, vm_method.c: remove cast expressions for OBJ_WRITE().



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41548 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
ko1 committed Jun 21, 2013
1 parent 671c196 commit 4223f00
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 43 deletions.
8 changes: 8 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
Sat Jun 22 04:48:53 2013 Koichi Sasada <ko1@atdot.net>

* include/ruby/ruby.h (OBJ_WRITE): cast to (VALUE *) for second
parameter `slot'. You don't need to write a cast (VALUE *) any more.

* class.c, compile.c, hash.c, iseq.c, proc.c, re.c, variable.c,
vm.c, vm_method.c: remove cast expressions for OBJ_WRITE().

Sat Jun 22 04:37:08 2013 Koichi Sasada <ko1@atdot.net>

* gc.c (slot_sweep_body): rename to slot_sweep().
Expand Down
2 changes: 1 addition & 1 deletion class.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ clone_method(VALUE klass, ID mid, const rb_method_entry_t *me)
rb_iseq_t *iseq;
newiseqval = rb_iseq_clone(me->def->body.iseq->self, klass);
GetISeqPtr(newiseqval, iseq);
OBJ_WRITE(iseq->self, (VALUE *)&iseq->cref_stack, rewrite_cref_stack(me->def->body.iseq->cref_stack, me->klass, klass));
OBJ_WRITE(iseq->self, &iseq->cref_stack, rewrite_cref_stack(me->def->body.iseq->cref_stack, me->klass, klass));
rb_add_method(klass, mid, VM_METHOD_TYPE_ISEQ, iseq, me->flag);
RB_GC_GUARD(newiseqval);
}
Expand Down
4 changes: 2 additions & 2 deletions compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ r_value(VALUE value)
if (compile_debug) rb_compile_bug strs; \
GET_THREAD()->errinfo = iseq->compile_data->err_info; \
rb_compile_error strs; \
OBJ_WRITE(iseq->self, (VALUE *)&iseq->compile_data->err_info, GET_THREAD()->errinfo); \
OBJ_WRITE(iseq->self, &iseq->compile_data->err_info, GET_THREAD()->errinfo); \
GET_THREAD()->errinfo = tmp; \
ret = 0; \
break; \
Expand Down Expand Up @@ -1706,7 +1706,7 @@ iseq_set_exception_table(rb_iseq_t *iseq)
}
}

OBJ_WRITE(iseq->self, (VALUE *)&iseq->compile_data->catch_table_ary, 0); /* free */
OBJ_WRITE(iseq->self, &iseq->compile_data->catch_table_ary, 0); /* free */
return COMPILE_OK;
}

Expand Down
2 changes: 1 addition & 1 deletion hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ static ID id_hash, id_yield, id_default;
VALUE
rb_hash_set_ifnone(VALUE hash, VALUE ifnone)
{
OBJ_WRITE(hash, (VALUE *)(&RHASH(hash)->ifnone), ifnone);
OBJ_WRITE(hash, (&RHASH(hash)->ifnone), ifnone);
return hash;
}

Expand Down
14 changes: 7 additions & 7 deletions include/ruby/ruby.h
Original file line number Diff line number Diff line change
Expand Up @@ -969,7 +969,7 @@ struct RArray {
#define RARRAY_AREF(a, i) (RARRAY_RAWPTR(a)[i])
#define RARRAY_ASET(a, i, v) do { \
const VALUE _ary_ = (a); \
OBJ_WRITE(_ary_, (VALUE *)&RARRAY_RAWPTR(_ary_)[i], (v)); \
OBJ_WRITE(_ary_, &RARRAY_RAWPTR(_ary_)[i], (v)); \
} while (0)

#define RARRAY_PTR(a) ((VALUE *)RARRAY_RAWPTR(RGENGC_WB_PROTECTED_ARRAY ? OBJ_WB_GIVEUP((VALUE)a) : ((VALUE)a)))
Expand Down Expand Up @@ -1010,17 +1010,17 @@ struct RRational {
const VALUE den;
};

#define RRATIONAL_SET_NUM(rat, n) OBJ_WRITE((rat), ((VALUE *)(&((struct RRational *)(rat))->num)),(n))
#define RRATIONAL_SET_DEN(rat, d) OBJ_WRITE((rat), ((VALUE *)(&((struct RRational *)(rat))->den)),(d))
#define RRATIONAL_SET_NUM(rat, n) OBJ_WRITE((rat), &((struct RRational *)(rat))->num,(n))
#define RRATIONAL_SET_DEN(rat, d) OBJ_WRITE((rat), &((struct RRational *)(rat))->den,(d))

struct RComplex {
struct RBasic basic;
const VALUE real;
const VALUE imag;
};

#define RCOMPLEX_SET_REAL(cmp, r) OBJ_WRITE((cmp), ((VALUE *)(&((struct RComplex *)(cmp))->real)),(r))
#define RCOMPLEX_SET_IMAG(cmp, i) OBJ_WRITE((cmp), ((VALUE *)(&((struct RComplex *)(cmp))->imag)),(i))
#define RCOMPLEX_SET_REAL(cmp, r) OBJ_WRITE((cmp), &((struct RComplex *)(cmp))->real,(r))
#define RCOMPLEX_SET_IMAG(cmp, i) OBJ_WRITE((cmp), &((struct RComplex *)(cmp))->imag,(i))

struct RData {
struct RBasic basic;
Expand Down Expand Up @@ -1131,7 +1131,7 @@ struct RStruct {
RSTRUCT(st)->as.heap.ptr)
#define RSTRUCT_PTR(st) ((VALUE *)RSTRUCT_RAWPTR(RGENGC_WB_PROTECTED_STRUCT ? OBJ_WB_GIVEUP((VALUE)st) : (VALUE)st))

#define RSTRUCT_SET(st, idx, v) OBJ_WRITE(st, (VALUE *)&RSTRUCT_RAWPTR(st)[idx], v)
#define RSTRUCT_SET(st, idx, v) OBJ_WRITE(st, &RSTRUCT_RAWPTR(st)[idx], (v))
#define RSTRUCT_GET(st, idx) (RSTRUCT_RAWPTR(st)[idx])

#define RBIGNUM_EMBED_LEN_MAX ((int)((sizeof(VALUE)*3)/sizeof(BDIGIT)))
Expand Down Expand Up @@ -1258,7 +1258,7 @@ void rb_gc_giveup_promoted_writebarrier(VALUE obj);
#define OBJ_SHADE(x) OBJ_WB_GIVEUP(x) /* RGENGC terminology */
#endif

#define OBJ_WRITE(a, slot, b) rb_obj_write((VALUE)(a), (slot), (VALUE)(b), __FILE__, __LINE__)
#define OBJ_WRITE(a, slot, b) rb_obj_write((VALUE)(a), (VALUE *)(slot), (VALUE)(b), __FILE__, __LINE__)
#define OBJ_WRITTEN(a, oldv, b) rb_obj_written((VALUE)(a), (VALUE)(oldv), (VALUE)(b), __FILE__, __LINE__)

static inline VALUE
Expand Down
44 changes: 22 additions & 22 deletions iseq.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,20 +184,20 @@ static rb_iseq_location_t *
iseq_location_setup(rb_iseq_t *iseq, VALUE path, VALUE absolute_path, VALUE name, size_t first_lineno)
{
rb_iseq_location_t *loc = &iseq->location;
OBJ_WRITE(iseq->self, (VALUE *)&loc->path, path);
OBJ_WRITE(iseq->self, &loc->path, path);
if (RTEST(absolute_path) && rb_str_cmp(path, absolute_path) == 0) {
OBJ_WRITE(iseq->self, (VALUE *)&loc->absolute_path, path);
OBJ_WRITE(iseq->self, &loc->absolute_path, path);
}
else {
OBJ_WRITE(iseq->self, (VALUE *)&loc->absolute_path, absolute_path);
OBJ_WRITE(iseq->self, &loc->absolute_path, absolute_path);
}
OBJ_WRITE(iseq->self, (VALUE *)&loc->label, name);
OBJ_WRITE(iseq->self, (VALUE *)&loc->base_label, name);
OBJ_WRITE(iseq->self, &loc->label, name);
OBJ_WRITE(iseq->self, &loc->base_label, name);
loc->first_lineno = first_lineno;
return loc;
}

#define ISEQ_SET_CREF(iseq, cref) OBJ_WRITE((iseq)->self, (VALUE *)&(iseq)->cref_stack, (cref))
#define ISEQ_SET_CREF(iseq, cref) OBJ_WRITE((iseq)->self, &(iseq)->cref_stack, (cref))

static void
set_relation(rb_iseq_t *iseq, const VALUE parent)
Expand All @@ -209,7 +209,7 @@ set_relation(rb_iseq_t *iseq, const VALUE parent)
/* set class nest stack */
if (type == ISEQ_TYPE_TOP) {
/* toplevel is private */
OBJ_WRITE(iseq->self, (VALUE *)&iseq->cref_stack, NEW_CREF(rb_cObject));
OBJ_WRITE(iseq->self, &iseq->cref_stack, NEW_CREF(rb_cObject));
iseq->cref_stack->nd_refinements = Qnil;
iseq->cref_stack->nd_visi = NOEX_PRIVATE;
if (th->top_wrapper) {
Expand Down Expand Up @@ -246,7 +246,7 @@ void
rb_iseq_add_mark_object(rb_iseq_t *iseq, VALUE obj)
{
if (!RTEST(iseq->mark_ary)) {
OBJ_WRITE(iseq->self, (VALUE *)&iseq->mark_ary, rb_ary_tmp_new(3));
OBJ_WRITE(iseq->self, &iseq->mark_ary, rb_ary_tmp_new(3));
RBASIC_CLEAR_CLASS(iseq->mark_ary);
}
rb_ary_push(iseq->mark_ary, obj);
Expand All @@ -262,19 +262,19 @@ prepare_iseq_build(rb_iseq_t *iseq,
iseq->arg_rest = -1;
iseq->arg_block = -1;
iseq->arg_keyword = -1;
OBJ_WRITE(iseq->self, (VALUE *)&iseq->klass, 0);
OBJ_WRITE(iseq->self, &iseq->klass, 0);
set_relation(iseq, parent);

OBJ_FREEZE(name);
OBJ_FREEZE(path);

iseq_location_setup(iseq, path, absolute_path, name, first_lineno);
if (iseq != iseq->local_iseq) {
OBJ_WRITE(iseq->self, (VALUE *)&iseq->location.base_label, iseq->local_iseq->location.label);
OBJ_WRITE(iseq->self, &iseq->location.base_label, iseq->local_iseq->location.label);
}

iseq->defined_method_id = 0;
OBJ_WRITE(iseq->self, (VALUE *)&iseq->mark_ary, 0);
OBJ_WRITE(iseq->self, &iseq->mark_ary, 0);

/*
* iseq->special_block_builder = GC_GUARDED_PTR_REF(block_opt);
Expand All @@ -284,15 +284,15 @@ prepare_iseq_build(rb_iseq_t *iseq,

iseq->compile_data = ALLOC(struct iseq_compile_data);
MEMZERO(iseq->compile_data, struct iseq_compile_data, 1);
OBJ_WRITE(iseq->self, (VALUE *)&iseq->compile_data->err_info, Qnil);
OBJ_WRITE(iseq->self, (VALUE *)&iseq->compile_data->mark_ary, rb_ary_tmp_new(3));
OBJ_WRITE(iseq->self, &iseq->compile_data->err_info, Qnil);
OBJ_WRITE(iseq->self, &iseq->compile_data->mark_ary, rb_ary_tmp_new(3));

iseq->compile_data->storage_head = iseq->compile_data->storage_current =
(struct iseq_compile_data_storage *)
ALLOC_N(char, INITIAL_ISEQ_COMPILE_DATA_STORAGE_BUFF_SIZE +
sizeof(struct iseq_compile_data_storage));

OBJ_WRITE(iseq->self, (VALUE *)&iseq->compile_data->catch_table_ary, rb_ary_new());
OBJ_WRITE(iseq->self, &iseq->compile_data->catch_table_ary, rb_ary_new());
iseq->compile_data->storage_head->pos = 0;
iseq->compile_data->storage_head->next = 0;
iseq->compile_data->storage_head->size =
Expand All @@ -302,12 +302,12 @@ prepare_iseq_build(rb_iseq_t *iseq,
iseq->compile_data->option = option;
iseq->compile_data->last_coverable_line = -1;

OBJ_WRITE(iseq->self, (VALUE *)&iseq->coverage, Qfalse);
OBJ_WRITE(iseq->self, &iseq->coverage, Qfalse);
if (!GET_THREAD()->parse_in_eval) {
VALUE coverages = rb_get_coverages();
if (RTEST(coverages)) {
OBJ_WRITE(iseq->self, (VALUE *)&iseq->coverage, rb_hash_lookup(coverages, path));
if (NIL_P(iseq->coverage)) OBJ_WRITE(iseq->self, (VALUE *)&iseq->coverage, Qfalse);
OBJ_WRITE(iseq->self, &iseq->coverage, rb_hash_lookup(coverages, path));
if (NIL_P(iseq->coverage)) OBJ_WRITE(iseq->self, &iseq->coverage, Qfalse);
}
}

Expand Down Expand Up @@ -1907,7 +1907,7 @@ rb_iseq_clone(VALUE iseqval, VALUE newcbase)

iseq1->self = newiseq;
if (!iseq1->orig) {
OBJ_WRITE(iseq1->self, (VALUE *)&iseq1->orig, iseqval);
OBJ_WRITE(iseq1->self, &iseq1->orig, iseqval);
}
if (iseq0->local_iseq == iseq0) {
iseq1->local_iseq = iseq1;
Expand All @@ -1919,7 +1919,7 @@ rb_iseq_clone(VALUE iseqval, VALUE newcbase)
if (iseq0->cref_stack->nd_next) {
iseq1->cref_stack->nd_next = iseq0->cref_stack->nd_next;
}
OBJ_WRITE(iseq1, (VALUE *)&iseq1->klass, newcbase);
OBJ_WRITE(iseq1, &iseq1->klass, newcbase);
}

return newiseq;
Expand Down Expand Up @@ -2071,10 +2071,10 @@ rb_iseq_build_for_ruby2cext(

/* copy iseq */
MEMCPY(iseq, iseq_template, rb_iseq_t, 1); /* TODO: write barrier, *iseq = *iseq_template; */
OBJ_WRITE(iseq->self, (VALUE *)&iseq->location.label, rb_str_new2(name));
OBJ_WRITE(iseq->self, (VALUE *)&iseq->location.path, rb_str_new2(path));
OBJ_WRITE(iseq->self, &iseq->location.label, rb_str_new2(name));
OBJ_WRITE(iseq->self, &iseq->location.path, rb_str_new2(path));
iseq->location.first_lineno = first_lineno;
OBJ_WRITE(iseq->self, (VALUE *)&iseq->mark_ary, 0);
OBJ_WRITE(iseq->self, &iseq->mark_ary, 0);
iseq->self = iseqval;

iseq->iseq = ALLOC_N(VALUE, iseq->iseq_size);
Expand Down
2 changes: 1 addition & 1 deletion proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1467,7 +1467,7 @@ rb_mod_define_method(int argc, VALUE *argv, VALUE mod)
GetProcPtr(body, proc);
if (BUILTIN_TYPE(proc->block.iseq) != T_NODE) {
proc->block.iseq->defined_method_id = id;
OBJ_WRITE(proc->block.iseq->self, (VALUE *)&proc->block.iseq->klass, mod);
OBJ_WRITE(proc->block.iseq->self, &proc->block.iseq->klass, mod);
proc->is_lambda = TRUE;
proc->is_from_method = TRUE;
proc->block.klass = mod;
Expand Down
4 changes: 2 additions & 2 deletions re.c
Original file line number Diff line number Diff line change
Expand Up @@ -2438,7 +2438,7 @@ rb_reg_initialize(VALUE obj, const char *s, long len, rb_encoding *enc,
options & ARG_REG_OPTION_MASK, err,
sourcefile, sourceline);
if (!re->ptr) return -1;
OBJ_WRITE(obj, (VALUE *)&re->src, rb_enc_str_new(s, len, enc));
OBJ_WRITE(obj, &re->src, rb_enc_str_new(s, len, enc));
OBJ_FREEZE(re->src);
RB_GC_GUARD(unescaped);
return 0;
Expand Down Expand Up @@ -2473,7 +2473,7 @@ rb_reg_s_alloc(VALUE klass)
NEWOBJ_OF(re, struct RRegexp, klass, T_REGEXP | (RGENGC_WB_PROTECTED_REGEXP ? FL_WB_PROTECTED : 0));

re->ptr = 0;
OBJ_WRITE(re, (VALUE *)&re->src, 0);
OBJ_WRITE(re, &re->src, 0);
re->usecnt = 0;

return (VALUE)re;
Expand Down
4 changes: 2 additions & 2 deletions variable.c
Original file line number Diff line number Diff line change
Expand Up @@ -2184,8 +2184,8 @@ rb_const_set(VALUE klass, ID id, VALUE val)
ce->flag = visibility;
ce->line = rb_sourceline();
st_insert(RCLASS_CONST_TBL(klass), (st_data_t)id, (st_data_t)ce);
OBJ_WRITE(klass, (VALUE *)&ce->value, val);
OBJ_WRITE(klass, (VALUE *)&ce->file, rb_sourcefilename());
OBJ_WRITE(klass, &ce->value, val);
OBJ_WRITE(klass, &ce->file, rb_sourcefilename());
}

void
Expand Down
4 changes: 2 additions & 2 deletions vm.c
Original file line number Diff line number Diff line change
Expand Up @@ -2031,7 +2031,7 @@ vm_define_method(rb_thread_t *th, VALUE obj, ID id, VALUE iseqval,
/* dup */
COPY_CREF(miseq->cref_stack, cref);
miseq->cref_stack->nd_visi = NOEX_PUBLIC;
OBJ_WRITE(miseq->self, (VALUE *)&miseq->klass, klass);
OBJ_WRITE(miseq->self, &miseq->klass, klass);
miseq->defined_method_id = id;
rb_add_method(klass, id, VM_METHOD_TYPE_ISEQ, miseq, noex);

Expand Down Expand Up @@ -2532,7 +2532,7 @@ rb_vm_set_progname(VALUE filename)
rb_thread_t *th = GET_VM()->main_thread;
rb_control_frame_t *cfp = (void *)(th->stack + th->stack_size);
--cfp;
OBJ_WRITE(cfp->iseq->self, (VALUE *)&cfp->iseq->location.path, filename);
OBJ_WRITE(cfp->iseq->self, &cfp->iseq->location.path, filename);
}

#if defined(ENABLE_VM_OBJSPACE) && ENABLE_VM_OBJSPACE
Expand Down
6 changes: 3 additions & 3 deletions vm_method.c
Original file line number Diff line number Diff line change
Expand Up @@ -426,16 +426,16 @@ rb_add_method(VALUE klass, ID mid, rb_method_type_t type, void *opts, rb_method_
case VM_METHOD_TYPE_ATTRSET:
case VM_METHOD_TYPE_IVAR:
def->body.attr.id = (ID)opts;
OBJ_WRITE(klass, (VALUE *)&def->body.attr.location, Qfalse);
OBJ_WRITE(klass, &def->body.attr.location, Qfalse);
th = GET_THREAD();
cfp = rb_vm_get_ruby_level_next_cfp(th, th->cfp);
if (cfp && (line = rb_vm_get_sourceline(cfp))) {
VALUE location = rb_ary_new3(2, cfp->iseq->location.path, INT2FIX(line));
OBJ_WRITE(klass, (VALUE *)&def->body.attr.location, rb_ary_freeze(location));
OBJ_WRITE(klass, &def->body.attr.location, rb_ary_freeze(location));
}
break;
case VM_METHOD_TYPE_BMETHOD:
OBJ_WRITE(klass, (VALUE *)&def->body.proc, (VALUE)opts);
OBJ_WRITE(klass, &def->body.proc, (VALUE)opts);
break;
case VM_METHOD_TYPE_NOTIMPLEMENTED:
setup_method_cfunc_struct(&def->body.cfunc, rb_f_notimplement, -1);
Expand Down

0 comments on commit 4223f00

Please sign in to comment.