You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If a C header contains a function declaration such as
extern const char *class_getName(Class cls);
where Class is the typedef name for struct objc_class * then the C wrapper code
generated by cgo uses type struct objc_class * for unmarshalling the function argument
rather than type Class. Normally this is fine but in this case the definition of struct
objc_class has the 'unavailable' attribute attached to it, so the generated code fails
to compile.
What steps will reproduce the problem?
1. Unzip/untar attached cgo_example.tar.gz and cd to cgo_example.
2. cgo main.go
3. gcc -c -I. _obj/main.cgo2.c
What is the expected output?
No output - compilation succeeds silently.
What do you see instead?
main.go: In function ‘_cgo_451c23f32582_Cfunc_class_getName’:
main.go:30: error: ‘objc_class’ is unavailable (declared at ./c_header.h:1)
Which compiler are you using (5g, 6g, 8g, gccgo)?
cgo
Which operating system are you using?
Mac OS X 10.7.3
Which revision are you using? (hg identify)
weekly.2012-01-27 11507
Please provide any additional information below.
I produced a modified version of cgo by deleting the *dwarf.TypedefType switch case in
func (c *typeConv) FuncArg() at approx line 1275 in src/cmd/cgo/gcc.go . This had the
effect of using the argument type as given in the C header and allowed compilation of
the generated wrapper code to succeed.
Single-file test:
package main
/*
typedef struct objc_class *Class;
struct objc_class {
Class isa;
} __attribute__((unavailable));
extern __attribute__((visibility("default")))
const char *class_getName(Class cls)
__attribute__((visibility("default")));
const char *class_getName(Class cls) { return "foo"; }
*/
import "C"
import "fmt"
func main() {
class := C.Class(nil)
fmt.Println(C.GoString(C.class_getName(class)))
}
Attribute unavailable seems like a terrible idea, but I think we can work around it by
using typedef names when possible in the generated C code.
by mcphail_colin@hotmail.com:
Attachments:
The text was updated successfully, but these errors were encountered: