Skip to content

Commit

Permalink
Clean up additions to struct.c to match MacRuby coding guidelines
Browse files Browse the repository at this point in the history
  • Loading branch information
macrotis committed May 23, 2012
1 parent a8382a2 commit 0625753
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions struct.c
Expand Up @@ -165,22 +165,26 @@ make_struct(VALUE name, VALUE members, VALUE klass)
for (i=0; i< len; i++) {
ID id = SYM2ID(RARRAY_AT(members, i));
if (rb_is_local_id(id) || rb_is_const_id(id)) {
long j = i; /* Needed for block data reference. */
VALUE (^struct_ref)(VALUE) =
^(VALUE obj) {
return RSTRUCT_PTR(obj)[j];
};
VALUE (^struct_set)(VALUE, VALUE) =
^(VALUE obj, VALUE val) {
VALUE *ptr = RSTRUCT_PTR(obj);
rb_struct_modify(obj);
GC_WB(&ptr[j], val);
return val;
};
rb_objc_define_method(nstr, rb_id2name(id),
imp_implementationWithBlock(Block_copy(struct_ref)), 0);
rb_objc_define_method(nstr, rb_id2name(rb_id_attrset(id)),
imp_implementationWithBlock(Block_copy(struct_set)), 1);
long j = i; /* Needed for block data reference. */
VALUE
(^struct_ref)(VALUE)
= ^(VALUE obj)
{
return RSTRUCT_PTR(obj)[j];
};
VALUE
(^struct_set)(VALUE, VALUE)
= ^(VALUE obj, VALUE val)
{
VALUE *ptr = RSTRUCT_PTR(obj);
rb_struct_modify(obj);
GC_WB(&ptr[j], val);
return val;
};
rb_objc_define_method(nstr, rb_id2name(id),
imp_implementationWithBlock(Block_copy(struct_ref)), 0);
rb_objc_define_method(nstr, rb_id2name(rb_id_attrset(id)),
imp_implementationWithBlock(Block_copy(struct_set)), 1);
}
}

Expand Down

0 comments on commit 0625753

Please sign in to comment.