Skip to content

cgo turns typedef void* function arguments into unsafe.Pointer #254

@gopherbot

Description

@gopherbot

by eden.li:

What steps will reproduce the problem?

$ cat <<EOF > lazy_func_arg.go
package cgo_lazy_func_args

/*
struct st { int i; };
typedef struct st *st_st;
typedef void *vptr;
void testArgs(vptr expectVptr, st_st expectStructPtr) { };
*/
import "C"

func main() {
    var (
        a    C.vptr = nil;
        b    C.st_st = nil;
    );
    C.testArgs(a, b)
}
EOF

$ cgo lazy_func_arg.go
$ 6g -o /dev/null lazy_func_arg.cgo[12].go
lazy_func_arg.cgo1.go:18: cannot use a (type _C_vptr) as type unsafe.Pointer

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

Since Go treats unsafe.Pointer in a special way, the lax C rule-emulation
in cgo/gcc.go is too aggressive in this case.  It should leave vptr alone
and render the Go-side declaration as:

  func _C_testArgs(_C_vptr, *_Cstruct_st)

Instead of:

  func _C_testArgs(unsafe.Pointer, *_Cstruct_st)

What is your $GOOS?  $GOARCH?

darwin amd64

Which revision are you sync'ed to?  (hg log -l 1)

changeset:   4110:89320216c4da
date:        Tue Nov 17 20:44:35 2009 -0800

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions