Skip to content

Commit 1927b40

Browse files
runtime: correct runtime structfield type to match reflect
The offset field in structfield has changed to offsetAnon, and now requires a shift to get the actual offset value. Fixes golang/go#23391 Change-Id: I663997eb4a6e73c6e8333e29c305df469db94954 Reviewed-on: https://go-review.googlesource.com/92275 Reviewed-by: Than McIntosh <[email protected]>
1 parent c02c711 commit 1927b40

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

libgo/go/runtime/cgocall.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ func cgoCheckArg(t *_type, p unsafe.Pointer, indir, top bool, msg string) {
189189
return
190190
}
191191
for _, f := range st.fields {
192-
cgoCheckArg(f.typ, add(p, f.offset), true, top, msg)
192+
cgoCheckArg(f.typ, add(p, f.offset()), true, top, msg)
193193
}
194194
case kindPtr, kindUnsafePointer:
195195
if indir {

libgo/go/runtime/type.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,19 @@ type ptrtype struct {
113113
}
114114

115115
type structfield struct {
116-
name *string // nil for embedded fields
117-
pkgPath *string // nil for exported Names; otherwise import path
118-
typ *_type // type of field
119-
tag *string // nil if no tag
120-
offset uintptr // byte offset of field within struct
116+
name *string // nil for embedded fields
117+
pkgPath *string // nil for exported Names; otherwise import path
118+
typ *_type // type of field
119+
tag *string // nil if no tag
120+
offsetAnon uintptr // byte offset of field<<1 | isAnonymous
121+
}
122+
123+
func (f *structfield) offset() uintptr {
124+
return f.offsetAnon >> 1
125+
}
126+
127+
func (f *structfield) anon() bool {
128+
return f.offsetAnon&1 != 0
121129
}
122130

123131
type structtype struct {

0 commit comments

Comments
 (0)