Skip to content

Commit 6a98f82

Browse files
pointer to pointer v2 (#244)
1 parent ccec524 commit 6a98f82

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

generate/codegen/gen_method.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ func (m *Method) WriteGoCallCode(currentModule *modules.Module, typeName string,
116116
for idx, p := range m.Params {
117117
switch tt := p.Type.(type) {
118118
case *typing.ClassType:
119-
args = append(args, "objc.Ptr("+p.GoName()+")")
119+
args = append(args, p.GoName())
120120
case *typing.ProtocolType:
121121
pvar := fmt.Sprintf("po%d", idx)
122122
cw.WriteLineF("%s := objc.WrapAsProtocol(\"%s\", %s)", pvar, tt.Name, p.GoName())

generate/codegen/gen_param.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,22 @@ type Param struct {
1111
Type typing.Type
1212
FieldName string // objc param field name(part of function name)
1313
Object bool // version of param generalized to IObject for protocols
14+
IsPtrPtr bool
1415
}
1516

1617
func (p *Param) String() string {
1718
return p.FieldName + ":" + p.Name
1819
}
1920

20-
// GoDeclare return go param declare code
21+
// Return Go parameter code
2122
func (p *Param) GoDeclare(currentModule *modules.Module, receiveFromObjc bool) string {
22-
return p.GoName() + " " + p.Type.GoName(currentModule, receiveFromObjc)
23+
returnValue := p.GoName() + " "
24+
if p.IsPtrPtr == true { // Example: NSError **error
25+
returnValue = returnValue + "unsafe.Pointer"
26+
} else {
27+
returnValue = returnValue + p.Type.GoName(currentModule, receiveFromObjc)
28+
}
29+
return returnValue
2330
}
2431

2532
func (p *Param) ObjcDeclare() string {

generate/members.go

+1
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ func (db *Generator) Members(fw string, sym Symbol, covariantTypes []string) (pr
193193
Name: arg.Name,
194194
Type: ptyp,
195195
FieldName: st.Method.NameParts[idx],
196+
IsPtrPtr: arg.Type.IsPtrPtr,
196197
}
197198
params = append(params, param)
198199
}

0 commit comments

Comments
 (0)