Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mruby
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
mruby
Commits
2cb183f1
Commit
2cb183f1
authored
Oct 22, 2012
by
Masaki Muranaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Avoid memcpy() on copying structures.
parent
0debca9b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
2 deletions
+12
-2
src/struct.c
src/struct.c
+12
-2
No files found.
src/struct.c
View file @
2cb183f1
...
...
@@ -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
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment