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

encoding/gob: turns pointers-to-zero into nil pointers #4609

Closed
reinerp opened this issue Jan 4, 2013 · 3 comments
Closed

encoding/gob: turns pointers-to-zero into nil pointers #4609

reinerp opened this issue Jan 4, 2013 · 3 comments
Assignees

Comments

@reinerp
Copy link

@reinerp reinerp commented Jan 4, 2013

See http://play.golang.org/p/0drzUw8O6w. The pointer-to-one gets turned into a
pointer-to-one, but the the pointer-to-zero gets turned into a nil pointer.
@dsymonds
Copy link
Member

@dsymonds dsymonds commented Jan 7, 2013

Comment 2:

I'm not sure this is even considered a bug; I think this is how gobs are supposed to
work. Per http://golang.org/pkg/encoding/gob/, pointers are flattened, so encoding
struct{x *int}{&0} (using "&0" as a notation for pointer to an int with value zero) is
intended to be equivalent to encoding struct{x int}{0}, which is specified to not be
explicitly encoded.
It's a shame that this means that encoding/gob can't preserve things like protocol
buffers, but that's just the way it is. The workaround there is to encode the proto
yourself, and encode []byte via gobs instead.

Labels changed: added priority-later, packagechange, removed priority-triage, go1.1.

Owner changed to @robpike.

Status changed to Thinking.

@robpike
Copy link
Contributor

@robpike robpike commented Feb 13, 2013

Comment 3:

A consequence of the design. Perhaps unfortunate, but not going to change.

Status changed to WorkingAsIntended.

@minux
Copy link
Member

@minux minux commented Apr 12, 2013

Comment 4:

Issue #5275 has been merged into this issue.

@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants
You can’t perform that action at this time.