Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
b1d37b74
Commit
b1d37b74
authored
Nov 12, 2008
by
Rob Pike
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
reflect.PtrValue.SetSub() to set pointers
R=rsc OCL=19101 CL=19101
parent
2f4d35ff
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
0 deletions
+21
-0
test.go
src/lib/reflect/test.go
+11
-0
value.go
src/lib/reflect/value.go
+10
-0
No files found.
src/lib/reflect/test.go
View file @
b1d37b74
...
...
@@ -91,6 +91,17 @@ func main() {
var
s
string
;
var
t
reflect
.
Type
;
{
var
ip
*
int32
;
var
i
int32
=
1234
;
vip
:=
reflect
.
NewValue
(
&
ip
);
vi
:=
reflect
.
NewValue
(
i
);
vip
.
(
reflect
.
PtrValue
)
.
Sub
()
.
(
reflect
.
PtrValue
)
.
SetSub
(
vi
);
if
*
ip
!=
1234
{
panicln
(
"SetSub failure"
,
*
ip
);
}
}
// Types
typedump
(
"missing"
,
"$missing$"
);
typedump
(
"int"
,
"int"
);
...
...
src/lib/reflect/value.go
View file @
b1d37b74
...
...
@@ -39,6 +39,7 @@ export type Empty interface {} // TODO(r): Delete when no longer needed?
export
type
Value
interface
{
Kind
()
int
;
Type
()
Type
;
Addr
()
Addr
;
Interface
()
Empty
;
}
...
...
@@ -58,6 +59,10 @@ func (c *Common) Type() Type {
return
c
.
typ
}
func
(
c
*
Common
)
Addr
()
Addr
{
return
c
.
addr
}
func
(
c
*
Common
)
Interface
()
Empty
{
return
sys
.
unreflect
(
*
AddrToPtrAddr
(
c
.
addr
),
c
.
typ
.
String
());
}
...
...
@@ -493,6 +498,7 @@ export type PtrValue interface {
Type
()
Type
;
Sub
()
Value
;
Get
()
Addr
;
SetSub
(
Value
);
}
type
PtrValueStruct
struct
{
...
...
@@ -507,6 +513,10 @@ func (v *PtrValueStruct) Sub() Value {
return
NewValueAddr
(
v
.
typ
.
(
PtrType
)
.
Sub
(),
v
.
Get
());
}
func
(
v
*
PtrValueStruct
)
SetSub
(
subv
Value
)
{
*
AddrToPtrAddr
(
v
.
addr
)
=
subv
.
Addr
();
}
func
PtrCreator
(
typ
Type
,
addr
Addr
)
Value
{
return
&
PtrValueStruct
{
Common
{
PtrKind
,
typ
,
addr
}
};
}
...
...
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