diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2012-10-22 07:08:29 -0700 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2012-10-22 07:08:29 -0700 |
| commit | 02f703701bc5a4be2673854f272680e9d3d8605b (patch) | |
| tree | eee684045d72d56d0e1b8a14437c2b193cf1f0ee /src | |
| parent | 0debca9bdf7d1436fb4fa86f4b36bf940892c1a2 (diff) | |
| parent | 2cb183f1831d7949130ab8ecbca0630a08a1ba60 (diff) | |
| download | mruby-02f703701bc5a4be2673854f272680e9d3d8605b.tar.gz mruby-02f703701bc5a4be2673854f272680e9d3d8605b.zip | |
Merge pull request #501 from monaka/pr-avoid-memcpy-on-copying-structure2
Avoid memcpy() on copying structures.
Diffstat (limited to 'src')
| -rw-r--r-- | src/struct.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/struct.c b/src/struct.c index a1ad2e1c0..64f0e8a4a 100644 --- a/src/struct.c +++ b/src/struct.c @@ -94,6 +94,16 @@ mrb_struct_s_members_m(mrb_state *mrb, mrb_value klass) return ary; } +static inline void +struct_copy(mrb_value *dst, const mrb_value *src, size_t size) +{ + size_t i; + + for (i = 0; i < size; i++) { + dst[i] = src[i]; + } +} + /* 15.2.18.4.6 */ /* * call-seq: @@ -431,7 +441,7 @@ mrb_struct_initialize_withArg(mrb_state *mrb, int argc, mrb_value *argv, mrb_val st = RSTRUCT(self); st->ptr = (mrb_value *)mrb_calloc(mrb, sizeof(mrb_value), n); st->len = n; - memcpy(st->ptr, argv, sizeof(mrb_value)*argc); + struct_copy(st->ptr, argv, argc); return self; } @@ -530,7 +540,7 @@ mrb_struct_init_copy(mrb_state *mrb, mrb_value copy) 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)); + struct_copy(RSTRUCT_PTR(copy), RSTRUCT_PTR(s), RSTRUCT_LEN(copy)); return copy; } |
