Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/compile, reflect: StructField.PkgPath is not correctly set for unnamed struct fields #15026

Closed
kylelemons opened this issue Mar 30, 2016 · 1 comment
Milestone

Comments

@kylelemons
Copy link
Contributor

  1. What version of Go are you using (go version)?
    go version devel +897dcdb Wed Mar 30 06:56:25 2016 +0000 linux/amd64
  2. What operating system and processor architecture are you using (go env)?
    linux/amd64

This is a regression at tip. Here is a short repro:

kyle@eros-ubuntu-vm /tmp/go $ cat reflect_test.go
package foo

import (
        "reflect"
        "testing"
)

func TestReflect(t *testing.T) {
        typ := reflect.TypeOf(struct{ Exported, unexported string }{})
        for _, test := range []struct {
                index          int
                field, pkgPath string
        }{
                {0, "Exported", ""},
                {1, "unexported", "_/tmp/go"},
        } {
                f := typ.Field(test.index)
                if got, want := f.PkgPath, test.pkgPath; got != want {
                        t.Errorf("Field(%d) (%q).PkgPath = %q, want %q", test.index, test.field, got, want)
                } else {
                        t.Logf("Field(%d) (%q).PkgPath = %q [OK]", test.index, test.field, f.PkgPath)
                }
        }
}

Here is the behavior at head:

kyle@eros-ubuntu-vm /tmp/go $ go version
go version go1.6 linux/amd64
kyle@eros-ubuntu-vm /tmp/go $ go test -test.v .
=== RUN   TestReflect
--- PASS: TestReflect (0.00s)
        reflect_test.go:25: Field(0) ("Exported").PkgPath = "" [OK]
        reflect_test.go:25: Field(1) ("unexported").PkgPath = "_/tmp/go" [OK]
PASS
ok      _/tmp/go        0.002s

(notice that the unexported field has a non-zero PkgPath)

Here is the behavior at tip:

kyle@eros-ubuntu-vm /tmp/go $ ~/gotip/bin/go version
go version devel +897dcdb Wed Mar 30 06:56:25 2016 +0000 linux/amd64
kyle@eros-ubuntu-vm /tmp/go $ ~/gotip/bin/go test -test.v .
=== RUN   TestReflect
--- FAIL: TestReflect (0.00s)
        reflect_test.go:25: Field(0) ("Exported").PkgPath = "" [OK]
        reflect_test.go:23: Field(1) ("unexported").PkgPath = "", want "_/tmp/go"
FAIL
exit status 1
FAIL    _/tmp/go        0.001s

(notice that the unexported field has a zero PkgPath)

It works fine for named structs even at tip. So far a quick skim of the changes to the reflect library didn't turn up any likely suspects, though there are quite a number of them.

@ianlancetaylor ianlancetaylor changed the title [reflect] StructField.PkgPath is not correctly set for unnamed struct fields cmd/compile, reflect: StructField.PkgPath is not correctly set for unnamed struct fields Mar 30, 2016
@ianlancetaylor ianlancetaylor added this to the Go1.7 milestone Mar 30, 2016
@gopherbot
Copy link

CL https://golang.org/cl/21286 mentions this issue.

wheelcomplex pushed a commit to wheelcomplex/smith-go that referenced this issue Aug 31, 2016
In FreeBSD when run Go proc under a given sub-list of processors(e.g. 'cpuset -l 0 ./goutil' in multicore system),
runtime.NumCPU() still return all actived CPUs instead of the number of sub-list.

Fix by use syscall cpuset_getaffinity to account the number of sub-list.

Fixes golang#15026

Tested on:
FreeBSD amd64 10/11/12
FreeBSD i386 10/11/12
FreeBSD arm 10/11/12

This is inspired by golang@4f308ed
(runtime: use sched_getaffinity for runtime.NumCPU() on Linux)
@golang golang locked and limited conversation to collaborators Mar 31, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants