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/cgo: panic in enum #3368

Closed
gopherbot opened this issue Mar 21, 2012 · 16 comments

Comments

@gopherbot
Copy link

commented Mar 21, 2012

by RMiB.email:

What steps will reproduce the problem?
1. build test.go

What is the expected output?
possible error type mismatch

What do you see instead?
go build ./...
# test
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x18 pc=0x40c6f8]

goroutine 1 [running]:
main.(*Package).rewriteRef(0xf84006b0b0, 0xf84004ba80, 0xf840060820, 0x200000002)
        /home/rmib/docs/develop/go/src/cmd/cgo/gcc.go:658 +0xa77
main.(*Package).Translate(0xf84006b0b0, 0xf84004ba80, 0x21, 0x56d1cc)
        /home/rmib/docs/develop/go/src/cmd/cgo/gcc.go:271 +0x129
main.main()
        /home/rmib/docs/develop/go/src/cmd/cgo/main.go:228 +0x905

goroutine 2 [syscall]:
created by runtime.main
        /home/rmib/docs/develop/go/src/pkg/runtime/proc.c:221

Which compiler are you using (5g, 6g, 8g, gccgo)?
6g, cgo

Which operating system are you using?
x86_64 GNU/Linux

Which revision are you using?  (hg identify)
0002f1f792e0 tip

http://groups.google.com/group/golang-nuts/browse_thread/thread/e941d48c1ab00e92

Attachments:

  1. test.go (300 bytes)
@gopherbot

This comment has been minimized.

Copy link
Author

commented Mar 21, 2012

Comment 1 by RMiB.email:

Sorry,
What is the expected output?
undefined C enum 'cairo_hint_style'
@griesemer

This comment has been minimized.

Copy link
Contributor

commented Mar 21, 2012

Comment 2:

Labels changed: added priority-go1, go1-must, removed priority-triage.

Status changed to Accepted.

@griesemer

This comment has been minimized.

Copy link
Contributor

commented Mar 21, 2012

Comment 3:

This appears to be an error due to invalid input: The enum is called _cairo_hint_style,
so it should be C.enum__cairo_hint_style:
package test
/*
typedef enum _cairo_hint_style {
    CAIRO_HINT_STYLE_DEFAULT,
    CAIRO_HINT_STYLE_NONE,
} cairo_hint_style_t;
int test(cairo_hint_style_t st) {
    return st;
}
*/
import "C" 
type CairoHintStyle int
func testfunc(st CairoHintStyle) {
    C.test(C.enum__cairo_hint_style(st))
}
No clear that we need to fix this for Go 1.
The crash is on line src/cmd/cgo/gcc.go:658 is due to r.Name.Type being nil.

Labels changed: added priority-triage, cgo, removed priority-go1, go1-must.

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Mar 22, 2012

Comment 4:

Adjusting priority--crash on invalid input needs to be fixed, but not right away.

Labels changed: added priority-later, removed priority-triage.

@minux

This comment has been minimized.

Copy link
Member

commented Aug 18, 2012

Comment 5:

Update: the panic doesn't occur now, but apparently cgo still can't diagnose this
problem:
cgo.go:19[/tmp/.../_obj/cgo.cgo1.go:13]: cannot convert st (type CairoHintStyle) to type
[0]byte
cgo.go:19[/tmp/.../_obj/cgo.cgo1.go:13]: cannot use ([0]byte)(st) (type [0]byte) as type
_Ctype_cairo_hint_style_t in function argument
a corrected version could be:
package main
/*
typedef enum _cairo_hint_style {
    CAIRO_HINT_STYLE_DEFAULT,
    CAIRO_HINT_STYLE_NONE,
} cairo_hint_style_t;
int test(cairo_hint_style_t st) {
    return st;
}
*/
import "C"
type CairoHintStyle int
func f(st CairoHintStyle) {
    C.test(C.cairo_hint_style_t(st))
}
@rsc

This comment has been minimized.

Copy link
Contributor

commented Sep 12, 2012

Comment 6:

Labels changed: added go1.1.

@rsc

This comment has been minimized.

Copy link
Contributor

commented Dec 10, 2012

Comment 8:

Labels changed: added size-m.

@rsc

This comment has been minimized.

Copy link
Contributor

commented Mar 12, 2013

Comment 9:

Labels changed: added go1.1maybe, removed go1.1.

@robpike

This comment has been minimized.

Copy link
Contributor

commented May 18, 2013

Comment 10:

Labels changed: added go1.2maybe, removed go1.1maybe.

@robpike

This comment has been minimized.

Copy link
Contributor

commented Aug 19, 2013

Comment 11:

Labels changed: added go1.3maybe, removed go1.2maybe.

@robpike

This comment has been minimized.

Copy link
Contributor

commented Aug 20, 2013

Comment 12:

Labels changed: removed go1.3maybe.

@rsc

This comment has been minimized.

Copy link
Contributor

commented Nov 27, 2013

Comment 13:

Labels changed: added go1.3maybe.

@rsc

This comment has been minimized.

Copy link
Contributor

commented Dec 4, 2013

Comment 14:

Labels changed: added release-none, removed go1.3maybe.

@rsc

This comment has been minimized.

Copy link
Contributor

commented Dec 4, 2013

Comment 15:

Labels changed: added repo-main.

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Mar 26, 2014

Comment 16:

go build now reports
# _/home/iant/tmp
./test.go:19:12: unexpected: -1-byte enum type - enum cairo_hint_style {}
Marking this as fixed.

Status changed to Fixed.

@9yx

This comment has been minimized.

Copy link

commented Jun 6, 2015

When you compile the example from the first post (go version devel +5dbe071 Sat Jun 6 02:17:49 2015 +0000 linux/amd64
):

# test1
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x0 pc=0x40ec96]

goroutine 1 [running]:
main.(*Package).rewriteRef(0xc20808e2a0, 0xc2080a0000)
        /opt/go.1.5/src/cmd/cgo/gcc.go:610 +0x1466
main.(*Package).Translate(0xc20808e2a0, 0xc2080a0000)
        /opt/go.1.5/src/cmd/cgo/gcc.go:170 +0x197
main.main()
        /opt/go.1.5/src/cmd/cgo/main.go:269 +0x1059

other code that reproduces the error:

package main

/**/
import "C" 

func main() {
    var a = C.enum_test(1)
} 

@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
7 participants
You can’t perform that action at this time.