Skip to content

Commit

Permalink
reflect: implement StructOf
Browse files Browse the repository at this point in the history
This change exposes a facility to create new struct types from a slice of
reflect.StructFields.

- reflect: implement StructOf
- reflect: tests for StructOf
- runtime: generate typelinks for structs

Fixes golang#5748.

Change-Id: I3b8fd4fadd6ce3b1b922e284f0ae72a3a8e3ce44
  • Loading branch information
sbinet committed Mar 5, 2016
1 parent 00da3a6 commit 26e3975
Show file tree
Hide file tree
Showing 3 changed files with 674 additions and 2 deletions.
16 changes: 15 additions & 1 deletion src/cmd/compile/internal/gc/reflect.go
Original file line number Diff line number Diff line change
Expand Up @@ -1199,7 +1199,21 @@ ok:
// we want be able to find.
if t.Sym == nil {
switch t.Etype {
case TPTR32, TPTR64, TARRAY, TCHAN, TFUNC, TMAP:
case TPTR32, TPTR64:
// The ptrto field of the type data cannot be relied on when
// dynamic linking: a type T may be defined in a module that makes
// no use of pointers to that type, but another module can contain
// a package that imports the first one and does use *T pointers.
// The second module will end up defining type data for *T and a
// type.*T symbol pointing at it. It's important that calling
// .PtrTo() on the refect.Type for T returns this type data and
// not some synthesized object, so we need reflect to be able to
// find it!
if !Ctxt.Flag_dynlink {
break
}
fallthrough
case TARRAY, TCHAN, TFUNC, TMAP, TSTRUCT:
slink := typelinksym(t)
dsymptr(slink, 0, s, 0)
ggloblsym(slink, int32(Widthptr), int16(dupok|obj.RODATA))
Expand Down
Loading

0 comments on commit 26e3975

Please sign in to comment.