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

Bad data alignment with nested C structs using amd64 cgo #609

Closed
rsaarelm opened this issue Feb 17, 2010 · 4 comments
Closed

Bad data alignment with nested C structs using amd64 cgo #609

rsaarelm opened this issue Feb 17, 2010 · 4 comments

Comments

@rsaarelm
Copy link
Contributor

Before filing a bug, please check whether it has been fixed since
the latest release: run "hg pull -u" and retry what you did to
reproduce the problem.  Thanks.

What steps will reproduce the problem?
1. Using the attached files, do "make run", the call "./run"

What is the expected output? What do you see instead?

The C code fills a facsimile of SDL's keyboard event structure with
ascending numbers. Then the contents of the structure are printed using a C
function and a Go function. The printout should be

1 2 3 4 5 6 7
1 2 3 4 5 6 7

instead it's 

1 2 3 4 5 6 7
1 2 3 5 6 7 0

The values for the fields in the nested struct that Go sees via cgo are all
off by one position. When told to print the whole struct, Go prints

{1 2 3 [0] {5 [0 0 0] 6 7 0 [0 0]}}

What is your $GOOS?  $GOARCH?

linux amd64

Which revision are you using?  (hg identify)

07fd78fe1d78 tip

Please provide any additional information below.

The test case replicates the issue I had with the actual SDL KeyboardEvent
struct without requiring the SDL headers. I did not have the same issue
with linux/386 Go.

Attachments:

  1. struct.go (1115 bytes)
  2. run.go (59 bytes)
  3. Makefile (203 bytes)
@rsc
Copy link
Contributor

rsc commented May 1, 2010

Comment 1:

Labels changed: added cgo.

@rsc
Copy link
Contributor

rsc commented Jul 2, 2010

Comment 2:

This is not fixed yet, but I tracked it down.  The issue is that 
the alignment for the SDL_Keysym field is apparently 8 instead of 4.
Related to issue #482.

Status changed to Accepted.

@rsc
Copy link
Contributor

rsc commented Dec 9, 2010

Comment 3:

Issue #1221 has been merged into this issue.

@rsc
Copy link
Contributor

rsc commented Dec 13, 2010

Comment 4:

This issue was closed by revision dc9a3b2.

Status changed to Fixed.

This issue was closed.
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

3 participants