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

gccgo, encoding/json: Marshal() not encoding struct correctly #11236

Closed
laboger opened this issue Jun 16, 2015 · 6 comments
Closed

gccgo, encoding/json: Marshal() not encoding struct correctly #11236

laboger opened this issue Jun 16, 2015 · 6 comments

Comments

@laboger
Copy link
Contributor

laboger commented Jun 16, 2015

The following problem occurs in the gcc5 branch and trunk. It was found when testing on pp64le Ubuntu 14.04 and 14.10 but the problem also occurs on x86 with gccgo. It works with golang on both platforms.

Here is a testcase that demonstrates the failure:

package main

import (
"encoding/json"
"fmt"
)

type HostConfig struct {
Memory int64
}

type Config struct {
Hostname string
}

type hostConfigWrapper struct {
InnerHostConfig *HostConfig
}

type ContainerConfigWrapper struct {
*Config
*hostConfigWrapper
}

func main() {

    conf := Config{
            Hostname:     "test1",
    }

    hostConf := HostConfig{
            Memory:          2048,
    }

    var hc hostConfigWrapper
    hc.InnerHostConfig = &hostConf
    var cf ContainerConfigWrapper
    cf.Config = &conf
    cf.hostConfigWrapper = &hc
    out1, _ := json.Marshal(cf)
    fmt.Println("marshalled data %v\n",string(out1))

}

Output should be:
marshalled data %v
{"Hostname":"test1","InnerHostConfig":{"Memory":2048}}

Output with gccgo:
marshalled data %v
{"Hostname":"test1"}

@laboger laboger changed the title gccgo, encoding: json.Marshal not encoding struct correctly gccgo, encoding: json.Marshal() not encoding struct correctly Jun 16, 2015
@mikioh mikioh changed the title gccgo, encoding: json.Marshal() not encoding struct correctly gccgo, encoding/json: Marshal() not encoding struct correctly Jun 16, 2015
@mwhudson
Copy link
Contributor

Is this the same problem as #7247 ?

@ianlancetaylor
Copy link
Contributor

Yes, this is another aspect of #7247 .

@ianlancetaylor
Copy link
Contributor

Closing as a duplicate.

@laboger
Copy link
Contributor Author

laboger commented Jul 21, 2015

I don't see why this is considered a duplicate.

The only place it fails is gccgo on both ppc64le and x86.

The testcase passes with golang on go 1.4.2 and 1.5. It is marked as a duplicate of an issue that fails on golang in both 1.4.2 and 1.5.

@ianlancetaylor
Copy link
Contributor

I think it is a duplicate because I think that the reason that this problem occurs is the same reason that #7247 fails. If we fix #7247 in the gc toolchain, then encoding/json will start failing in the same way for gc. In other words, fixing #7247 in gc will force encoding/json to be fixed in such a way that this problem is fixed for gccgo.

@laboger
Copy link
Contributor Author

laboger commented Jul 21, 2015

Based on what I read in #7247 it doesn't sound like it will get fixed for some time (unplanned for go 1.5), and I'm not sure what that means in terms of getting it fixed in gccgo since it is still at 1.4.2.

@golang golang locked and limited conversation to collaborators Jul 20, 2016
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