summaryrefslogtreecommitdiffhomepage
path: root/src/struct.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/struct.c')
-rw-r--r--src/struct.c52
1 files changed, 27 insertions, 25 deletions
diff --git a/src/struct.c b/src/struct.c
index ff66b19a2..699825cff 100644
--- a/src/struct.c
+++ b/src/struct.c
@@ -533,19 +533,20 @@ mrb_value
mrb_struct_init_copy(mrb_state *mrb, mrb_value copy)
{
mrb_value s;
+
mrb_get_args(mrb, "o", &s);
- if (mrb_obj_equal(mrb, copy, s)) return copy;
- //mrb_check_frozen(copy);
- if (!mrb_obj_is_instance_of(mrb, s, mrb_obj_class(mrb, copy))) {
- mrb_raise(mrb, E_TYPE_ERROR, "wrong argument class");
- }
- if (RSTRUCT_LEN(copy) != RSTRUCT_LEN(s)) {
- mrb_raise(mrb, E_TYPE_ERROR, "struct size mismatch");
- }
- memcpy(RSTRUCT_PTR(copy), RSTRUCT_PTR(s), sizeof(mrb_value)*RSTRUCT_LEN(copy));
+ if (mrb_obj_equal(mrb, copy, s)) return copy;
+ //mrb_check_frozen(copy);
+ if (!mrb_obj_is_instance_of(mrb, s, mrb_obj_class(mrb, copy))) {
+ mrb_raise(mrb, E_TYPE_ERROR, "wrong argument class");
+ }
+ if (RSTRUCT_LEN(copy) != RSTRUCT_LEN(s)) {
+ mrb_raise(mrb, E_TYPE_ERROR, "struct size mismatch");
+ }
+ memcpy(RSTRUCT_PTR(copy), RSTRUCT_PTR(s), sizeof(mrb_value)*RSTRUCT_LEN(copy));
- return copy;
+ return copy;
}
static mrb_value
@@ -668,24 +669,25 @@ mrb_struct_aset(mrb_state *mrb, mrb_value s)
long i;
mrb_value idx;
mrb_value val;
+
mrb_get_args(mrb, "oo", &idx, &val);
- if (mrb_type(idx) == MRB_TT_STRING || mrb_type(idx) == MRB_TT_SYMBOL) {
- return mrb_struct_aset_id(mrb, s, mrb_to_id(mrb, idx), val);
- }
+ if (mrb_type(idx) == MRB_TT_STRING || mrb_type(idx) == MRB_TT_SYMBOL) {
+ return mrb_struct_aset_id(mrb, s, mrb_to_id(mrb, idx), val);
+ }
- i = mrb_fixnum(idx);
- if (i < 0) i = RSTRUCT_LEN(s) + i;
- if (i < 0) {
- mrb_raise(mrb, E_INDEX_ERROR, "offset %ld too small for struct(size:%ld)",
- i, RSTRUCT_LEN(s));
- }
- if (RSTRUCT_LEN(s) <= i) {
- mrb_raise(mrb, E_INDEX_ERROR, "offset %ld too large for struct(size:%ld)",
- i, RSTRUCT_LEN(s));
- }
- mrb_struct_modify(s);
- return RSTRUCT_PTR(s)[i] = val;
+ i = mrb_fixnum(idx);
+ if (i < 0) i = RSTRUCT_LEN(s) + i;
+ if (i < 0) {
+ mrb_raise(mrb, E_INDEX_ERROR, "offset %ld too small for struct(size:%ld)",
+ i, RSTRUCT_LEN(s));
+ }
+ if (RSTRUCT_LEN(s) <= i) {
+ mrb_raise(mrb, E_INDEX_ERROR, "offset %ld too large for struct(size:%ld)",
+ i, RSTRUCT_LEN(s));
+ }
+ mrb_struct_modify(s);
+ return RSTRUCT_PTR(s)[i] = val;
}
static mrb_value