Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
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
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
6850dba0
Commit
6850dba0
authored
Apr 27, 2011
by
Gustavo Niemeyer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
reflect: Fix Copy of arrays
R=golang-dev, rsc1 CC=golang-dev
https://golang.org/cl/4438077
parent
b477a79c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
1 deletion
+28
-1
src/pkg/reflect/all_test.go
src/pkg/reflect/all_test.go
+27
-0
src/pkg/reflect/value.go
src/pkg/reflect/value.go
+1
-1
No files found.
src/pkg/reflect/all_test.go
View file @
6850dba0
...
...
@@ -565,6 +565,33 @@ func TestCopy(t *testing.T) {
}
}
func
TestCopyArray
(
t
*
testing
.
T
)
{
a
:=
[
8
]
int
{
1
,
2
,
3
,
4
,
10
,
9
,
8
,
7
}
b
:=
[
11
]
int
{
11
,
22
,
33
,
44
,
1010
,
99
,
88
,
77
,
66
,
55
,
44
}
c
:=
b
aa
:=
ValueOf
(
&
a
)
.
Elem
()
ab
:=
ValueOf
(
&
b
)
.
Elem
()
Copy
(
ab
,
aa
)
for
i
:=
0
;
i
<
len
(
a
);
i
++
{
if
a
[
i
]
!=
b
[
i
]
{
t
.
Errorf
(
"(i) a[%d]=%d, b[%d]=%d"
,
i
,
a
[
i
],
i
,
b
[
i
])
}
}
for
i
:=
len
(
a
);
i
<
len
(
b
);
i
++
{
if
b
[
i
]
!=
c
[
i
]
{
if
i
<
len
(
a
)
{
t
.
Errorf
(
"(ii) a[%d]=%d, b[%d]=%d, c[%d]=%d"
,
i
,
a
[
i
],
i
,
b
[
i
],
i
,
c
[
i
])
}
else
{
t
.
Errorf
(
"(iii) b[%d]=%d, c[%d]=%d"
,
i
,
b
[
i
],
i
,
c
[
i
])
}
}
else
{
t
.
Logf
(
"elem %d is okay
\n
"
,
i
)
}
}
}
func
TestBigUnnamedStruct
(
t
*
testing
.
T
)
{
b
:=
struct
{
a
,
b
,
c
,
d
int64
}{
1
,
2
,
3
,
4
}
v
:=
ValueOf
(
b
)
...
...
src/pkg/reflect/value.go
View file @
6850dba0
...
...
@@ -1546,7 +1546,7 @@ func Copy(dst, src Value) int {
// Copy via memmove.
var
da
,
sa
unsafe
.
Pointer
if
idst
.
kind
==
Array
{
da
=
i
src
.
addr
da
=
i
dst
.
addr
}
else
{
da
=
unsafe
.
Pointer
((
*
SliceHeader
)(
idst
.
addr
)
.
Data
)
}
...
...
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