@@ -38,7 +38,7 @@ var reservedWords = map[string]bool{
3838 "string" : true ,
3939}
4040
41- var typeMap = map [string ]string {
41+ var goTypeFixupMap = map [string ]string {
4242 "*kernel.Boolean_t" : "*int" ,
4343 "*kernel.UniChar" : "*uint16" ,
4444 "kernel.Boolean_t" : "int" ,
@@ -47,6 +47,12 @@ var typeMap = map[string]string{
4747 "uint8_t" : "byte" ,
4848}
4949
50+ var objCtoCMap = map [string ]string {
51+ "NSInteger" : "int" ,
52+ "NSUInteger" : "uint" ,
53+ "BOOL" : "bool" ,
54+ }
55+
5056// GoArgs return go function args
5157func (f * Function ) GoArgs (currentModule * modules.Module ) string {
5258 // log.Println("rendering function", f.Name)
@@ -64,7 +70,7 @@ func (f *Function) GoArgs(currentModule *modules.Module) string {
6470 p .Name = p .Name + "_"
6571 }
6672 typ := p .Type .GoName (currentModule , true )
67- if v , ok := typeMap [typ ]; ok {
73+ if v , ok := goTypeFixupMap [typ ]; ok {
6874 typ = v
6975 }
7076 args = append (args , fmt .Sprintf ("%s %s" , p .Name , typ ))
@@ -79,7 +85,7 @@ func (f *Function) GoReturn(currentModule *modules.Module) string {
7985 }
8086 // log.Printf("rendering GoReturn function return: %s %T", f.ReturnType, f.ReturnType)
8187 typ := f .ReturnType .GoName (currentModule , true )
82- if v , ok := typeMap [typ ]; ok {
88+ if v , ok := goTypeFixupMap [typ ]; ok {
8389 typ = v
8490 }
8591 return typ
@@ -93,6 +99,7 @@ func (f *Function) CArgs(currentModule *modules.Module) string {
9399 // log.Printf("rendering cfunction arg: %s %s %T", p.Name, p.Type, p.Type)
94100 typ := p .Type .CName ()
95101 if cs , ok := p .Type .(CSignatureer ); ok {
102+ fmt .Printf ("has CSignatureer: %T %v -> %v\n " , p .Type , typ , cs .CSignature ())
96103 typ = cs .CSignature ()
97104 }
98105 // check reserved words
@@ -174,7 +181,12 @@ func (f *Function) WriteGoCallCode(currentModule *modules.Module, cw *CodeWriter
174181 case * typing.PrimitiveType :
175182 sb .WriteString (cw .IndentStr + fmt .Sprintf (" C.%s(%s)" , tt .CName (), p .GoName ()))
176183 case * typing.PointerType :
177- sb .WriteString (cw .IndentStr + fmt .Sprintf (" (*C.%s)(unsafe.Pointer(%s))" , tt .Type .ObjcName (), p .GoName ()))
184+ cTyp := tt .Type .CName ()
185+ if v , ok := objCtoCMap [cTyp ]; ok {
186+ // note: we should drive use of this branch down
187+ cTyp = v
188+ }
189+ sb .WriteString (cw .IndentStr + fmt .Sprintf (" (*C.%s)(unsafe.Pointer(%s))" , cTyp , p .GoName ()))
178190 default :
179191 sb .WriteString (cw .IndentStr + p .GoName ())
180192 }
@@ -192,6 +204,8 @@ func (f *Function) WriteGoCallCode(currentModule *modules.Module, cw *CodeWriter
192204 switch tt := f .ReturnType .(type ) {
193205 case * typing.StructType , * typing.PointerType :
194206 cw .WriteLineF ("return *(*%s)(unsafe.Pointer(&%s))" , tt .GoName (currentModule , true ), resultName )
207+ case * typing.CStringType :
208+ cw .WriteLineF ("return C.GoString(%s)" , resultName )
195209 default :
196210 cw .WriteLineF ("return %s(%s)" , returnTypeStr , resultName )
197211 }
@@ -253,7 +267,10 @@ func (f *Function) WriteObjcWrapper(currentModule *modules.Module, cw *CodeWrite
253267 var conv string
254268 switch tt := p .Type .(type ) {
255269 case * typing.PointerType :
270+ cw .WriteLineF ("// -> %T" , tt .Type )
256271 conv = tt .ObjcName ()
272+ // case *typing.AliasType:
273+ // conv = tt.ObjcName() + "*"
257274 default :
258275 conv = tt .ObjcName ()
259276 }
@@ -279,11 +296,7 @@ func (f *Function) WriteCSignature(currentModule *modules.Module, cw *CodeWriter
279296 var returnTypeStr string
280297 rt := f .Type .ReturnType
281298 returnTypeStr = rt .CName ()
282- if v , ok := map [string ]string {
283- "NSInteger" : "int" ,
284- "NSUInteger" : "uint" ,
285- "BOOL" : "bool" ,
286- }[returnTypeStr ]; ok {
299+ if v , ok := objCtoCMap [returnTypeStr ]; ok {
287300 returnTypeStr = v
288301 }
289302 if hasBlockParam (f .Parameters ) {
0 commit comments