2019-06-04 11:27:46 -04:00
|
|
|
package types
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func isNil(x interface{}) bool {
|
|
|
|
return x == nil ||
|
|
|
|
(reflect.ValueOf(x).Kind() == reflect.Ptr &&
|
2019-06-11 12:38:22 -04:00
|
|
|
reflect.ValueOf(x).IsNil())
|
2019-06-04 11:27:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestType(t *testing.T) {
|
|
|
|
i := 1
|
|
|
|
|
|
|
|
var str string
|
|
|
|
var n *Node
|
|
|
|
var tp *Type
|
|
|
|
|
|
|
|
chk := func(actual, expected interface{}) {
|
2019-06-11 12:38:22 -04:00
|
|
|
t.Run(fmt.Sprintf("TestType%d", i), func(t *testing.T) {
|
|
|
|
if isNil(actual) && isNil(expected) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if !reflect.DeepEqual(actual, expected) {
|
|
|
|
t.Errorf("Test failed for %s\n", str)
|
|
|
|
fmt.Println("Actual:\n", actual)
|
|
|
|
fmt.Println("Expected:\n", expected)
|
2019-06-04 11:27:46 -04:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
chk_newtype := func() {
|
2019-06-11 12:38:22 -04:00
|
|
|
tp = NewTypeFromString(str, "")
|
|
|
|
chk(tp, &Type{Node: n, Class: ""})
|
2019-06-04 11:27:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
//tests on nil Type pointers:
|
2019-06-11 12:38:22 -04:00
|
|
|
chk(tp.BaseType(), nil)
|
|
|
|
chk(tp.CType(), "")
|
|
|
|
chk(tp.IsFunction(), false)
|
|
|
|
chk(tp.IsPointer(), false)
|
|
|
|
chk(tp.IsFunctionPtr(), false)
|
|
|
|
chk(tp.IsValist(), false)
|
2019-06-04 11:27:46 -04:00
|
|
|
|
|
|
|
str = "int"
|
2019-06-11 12:38:22 -04:00
|
|
|
n = &Node{"TypeName", "", []*Node{
|
|
|
|
&Node{"TypeSpecifier", "int", []*Node{}}}}
|
2019-06-04 11:27:46 -04:00
|
|
|
chk_newtype()
|
|
|
|
tint := tp
|
|
|
|
|
2019-06-13 16:47:36 -04:00
|
|
|
str = "id"
|
|
|
|
n = &Node{"TypeName", "", []*Node{
|
|
|
|
&Node{"TypedefName", "id", []*Node{}}}}
|
|
|
|
chk_newtype()
|
|
|
|
//nsid := tp
|
|
|
|
|
2019-06-04 11:27:46 -04:00
|
|
|
str = "NSObject"
|
2019-06-11 12:38:22 -04:00
|
|
|
n = &Node{"TypeName", "", []*Node{
|
|
|
|
&Node{"TypedefName", "NSObject", []*Node{}}}}
|
2019-06-04 11:27:46 -04:00
|
|
|
chk_newtype()
|
|
|
|
nso := tp
|
|
|
|
|
|
|
|
str = "NSString"
|
2019-06-11 12:38:22 -04:00
|
|
|
n = &Node{"TypeName", "", []*Node{
|
|
|
|
&Node{"TypedefName", "NSString", []*Node{}}}}
|
2019-06-04 11:27:46 -04:00
|
|
|
chk_newtype()
|
|
|
|
nst := tp
|
|
|
|
|
2019-06-13 16:47:36 -04:00
|
|
|
str = "NSString**"
|
|
|
|
n = &Node{"TypeName", "", []*Node{
|
|
|
|
&Node{"TypedefName", "NSString", []*Node{}},
|
2020-06-24 13:03:53 -04:00
|
|
|
&Node{"Pointer", "*", []*Node{}},
|
|
|
|
&Node{"Pointer", "*", []*Node{}}}}
|
2019-06-13 16:47:36 -04:00
|
|
|
chk_newtype()
|
|
|
|
chk(tp.IsPointer(), true)
|
|
|
|
chk(tp.Typedef(), nil)
|
|
|
|
nstpp := tp
|
|
|
|
|
|
|
|
str = "NSObject**"
|
|
|
|
n = &Node{"TypeName", "", []*Node{
|
|
|
|
&Node{"TypedefName", "NSObject", []*Node{}},
|
2020-06-24 13:03:53 -04:00
|
|
|
&Node{"Pointer", "*", []*Node{}},
|
|
|
|
&Node{"Pointer", "*", []*Node{}}}}
|
2019-06-13 16:47:36 -04:00
|
|
|
chk_newtype()
|
|
|
|
chk(tp.IsPointer(), true)
|
|
|
|
nsopp := tp
|
|
|
|
|
|
|
|
str = "NSObject*"
|
|
|
|
n = &Node{"TypeName", "", []*Node{
|
|
|
|
&Node{"TypedefName", "NSObject", []*Node{}},
|
|
|
|
&Node{"Pointer", "*", []*Node{}}}}
|
|
|
|
chk_newtype()
|
|
|
|
chk(tp.IsPointer(), true)
|
|
|
|
nsop := tp
|
|
|
|
|
2019-06-04 11:27:46 -04:00
|
|
|
str = "NSString*"
|
2019-06-11 12:38:22 -04:00
|
|
|
n = &Node{"TypeName", "", []*Node{
|
|
|
|
&Node{"TypedefName", "NSString", []*Node{}},
|
|
|
|
&Node{"Pointer", "*", []*Node{}}}}
|
2019-06-04 11:27:46 -04:00
|
|
|
chk_newtype()
|
2019-06-11 12:38:22 -04:00
|
|
|
chk(tp.IsPointer(), true)
|
|
|
|
chk(tp.Typedef(), nil)
|
2019-06-13 16:47:36 -04:00
|
|
|
nstp := tp
|
2019-06-04 11:27:46 -04:00
|
|
|
|
|
|
|
str = "myTypedef"
|
2019-06-11 12:38:22 -04:00
|
|
|
AddTypedef("myTypedef", tp)
|
|
|
|
n = &Node{"TypeName", "", []*Node{
|
|
|
|
&Node{"TypedefName", "myTypedef", []*Node{}}}}
|
2019-06-04 11:27:46 -04:00
|
|
|
chk_newtype()
|
2019-06-13 16:47:36 -04:00
|
|
|
chk(tp.Typedef(), nstp)
|
2019-06-04 11:27:46 -04:00
|
|
|
|
|
|
|
str = "const NSArray <ObjectType * _Nonnull> *"
|
2019-06-11 12:38:22 -04:00
|
|
|
n = &Node{"TypeName", "", []*Node{
|
|
|
|
&Node{"TypeQualifier", "const", []*Node{}},
|
|
|
|
&Node{"TypedefName", "NSArray", []*Node{}},
|
|
|
|
&Node{"GenericList", "", []*Node{
|
|
|
|
&Node{"Generic", "", []*Node{
|
|
|
|
&Node{"TypedefName", "ObjectType", []*Node{}},
|
|
|
|
&Node{"Pointer", "*", []*Node{}},
|
|
|
|
&Node{"NullableAnnotation", "_Nonnull", []*Node{}}}}}},
|
|
|
|
&Node{"Pointer", "*", []*Node{}}}}
|
2019-06-04 11:27:46 -04:00
|
|
|
chk_newtype()
|
2019-06-11 12:38:22 -04:00
|
|
|
chk(tp.CType(), "NSArray*")
|
|
|
|
chk(tp.CTypeAttrib(), "const NSArray*")
|
|
|
|
chk(tp.CGoType(), "*C.NSArray")
|
|
|
|
chk(tp.GoType(), "*NSArray")
|
2019-06-04 11:27:46 -04:00
|
|
|
|
2019-06-11 12:38:22 -04:00
|
|
|
SetTypeParam("MyClass", "ObjectType", "MyClass")
|
2019-06-04 11:27:46 -04:00
|
|
|
str = "id<ObjectType *>"
|
2019-06-11 12:38:22 -04:00
|
|
|
n = &Node{"TypeName", "", []*Node{
|
|
|
|
&Node{"TypedefName", "id", []*Node{}},
|
|
|
|
&Node{"GenericList", "", []*Node{
|
|
|
|
&Node{"Generic", "", []*Node{
|
|
|
|
&Node{"TypedefName", "ObjectType", []*Node{}},
|
|
|
|
&Node{"Pointer", "*", []*Node{}}}}}}}}
|
2019-06-04 11:27:46 -04:00
|
|
|
chk_newtype()
|
2019-06-11 12:38:22 -04:00
|
|
|
tp = NewType(n, "MyClass")
|
|
|
|
chk(tp.CType(), "NSObject*")
|
2019-06-04 11:27:46 -04:00
|
|
|
chk(tp.String(),
|
2019-06-11 12:38:22 -04:00
|
|
|
`<TypeName> ''
|
2019-06-04 11:27:46 -04:00
|
|
|
-<TypedefName> 'id'
|
|
|
|
-<GenericList> ''
|
|
|
|
--<Generic> ''
|
|
|
|
---<TypedefName> 'MyClass'
|
|
|
|
---<Pointer> '*'
|
|
|
|
`)
|
2019-06-11 12:38:22 -04:00
|
|
|
x, _ := clean(nil, "MyClass")
|
|
|
|
chk(x, nil)
|
|
|
|
SetSuper("NSString", "NSObject")
|
|
|
|
chk(Super("NSString"), "NSObject")
|
2019-06-04 11:27:46 -04:00
|
|
|
|
|
|
|
tp2 := tp.CloneToClass("NSObject")
|
2019-06-11 12:38:22 -04:00
|
|
|
chk(tp2.Class, "NSObject")
|
2019-06-04 11:27:46 -04:00
|
|
|
|
|
|
|
str = "you can't parse this"
|
2019-06-11 12:38:22 -04:00
|
|
|
tp = NewTypeFromString(str, "")
|
2019-06-04 11:27:46 -04:00
|
|
|
tp2 = &Type{}
|
2019-06-11 12:38:22 -04:00
|
|
|
chk(tp, tp2)
|
2019-06-04 11:27:46 -04:00
|
|
|
|
|
|
|
str = "id<ObjectType *>"
|
2019-06-11 12:38:22 -04:00
|
|
|
tp2 = NewTypeFromString(str, "MyClass")
|
|
|
|
chk(tp.BaseType(), tp)
|
2019-06-04 11:27:46 -04:00
|
|
|
|
|
|
|
str = "id<ObjectType *>*"
|
2019-06-11 12:38:22 -04:00
|
|
|
tp = NewTypeFromString(str, "MyClass")
|
|
|
|
chk(tp.BaseType(), tp2)
|
|
|
|
chk(tp.PointsTo(), tp2)
|
|
|
|
AddTypedef("myTypedef", tp)
|
2019-06-04 11:27:46 -04:00
|
|
|
|
|
|
|
str = "myTypedef"
|
2019-06-11 12:38:22 -04:00
|
|
|
n = &Node{"TypeName", "", []*Node{
|
|
|
|
&Node{"TypedefName", "myTypedef", []*Node{}}}}
|
2019-06-04 11:27:46 -04:00
|
|
|
chk_newtype()
|
2019-06-11 12:38:22 -04:00
|
|
|
chk(tp.PointsTo(), tp2)
|
|
|
|
chk(tp2.PointsTo(), nil)
|
2019-06-04 11:27:46 -04:00
|
|
|
|
2019-06-18 09:15:46 -04:00
|
|
|
chk(tp.GoTypeDecl(false), `
|
2019-06-04 11:27:46 -04:00
|
|
|
type MyTypedef **C.NSObject
|
|
|
|
`)
|
|
|
|
str = "void"
|
2019-06-11 12:38:22 -04:00
|
|
|
n = &Node{"TypeName", "", []*Node{
|
|
|
|
&Node{"TypeSpecifier", "void", []*Node{}}}}
|
2019-06-04 11:27:46 -04:00
|
|
|
chk_newtype()
|
2019-06-18 09:15:46 -04:00
|
|
|
chk(tp.GoTypeDecl(false), "")
|
2019-06-04 11:27:46 -04:00
|
|
|
void := tp
|
|
|
|
|
|
|
|
str = "BOOL"
|
2019-06-11 12:38:22 -04:00
|
|
|
n, _ = Parse(str)
|
2019-06-04 11:27:46 -04:00
|
|
|
chk_newtype()
|
|
|
|
bl := tp
|
|
|
|
|
|
|
|
str = "void**"
|
2019-06-11 12:38:22 -04:00
|
|
|
n, _ = Parse(str)
|
2019-06-04 11:27:46 -04:00
|
|
|
chk_newtype()
|
2019-06-11 12:38:22 -04:00
|
|
|
chk(tp.GoType(), "*unsafe.Pointer")
|
|
|
|
chk(tp.CToGo("var"), "(*unsafe.Pointer)(unsafe.Pointer(var))")
|
2019-06-04 11:27:46 -04:00
|
|
|
voidpp := tp
|
|
|
|
|
|
|
|
Wrap("NSObject")
|
|
|
|
str = "NSObject*"
|
2019-06-11 12:38:22 -04:00
|
|
|
n, _ = Parse(str)
|
2019-06-04 11:27:46 -04:00
|
|
|
chk_newtype()
|
2019-06-13 16:47:36 -04:00
|
|
|
chk(tp.GoType(), "*NSObject")
|
2019-06-04 11:27:46 -04:00
|
|
|
|
|
|
|
Wrap("NSString")
|
2019-06-18 09:15:46 -04:00
|
|
|
chk(nso.GoTypeDecl(false), `
|
2019-06-04 11:27:46 -04:00
|
|
|
type NSObject interface {
|
|
|
|
Ptr() unsafe.Pointer
|
|
|
|
}
|
|
|
|
`)
|
2019-06-11 12:38:22 -04:00
|
|
|
chk(nso.GoType(), "NSObject")
|
2019-06-04 11:27:46 -04:00
|
|
|
|
2019-06-18 09:15:46 -04:00
|
|
|
chk(nst.GoTypeDecl(false), `
|
2019-06-04 11:27:46 -04:00
|
|
|
type NSString struct { Id }
|
2019-06-13 16:47:36 -04:00
|
|
|
func (o *NSString) Ptr() unsafe.Pointer { if o == nil { return nil }; return o.ptr }
|
|
|
|
func (o *Id) NSString() *NSString {
|
2019-06-27 11:41:58 -04:00
|
|
|
return (*NSString)(unsafe.Pointer(o))
|
2019-06-04 11:27:46 -04:00
|
|
|
}
|
|
|
|
`)
|
|
|
|
str = "int(void)"
|
2019-06-11 12:38:22 -04:00
|
|
|
n, _ = Parse(str)
|
2019-06-04 11:27:46 -04:00
|
|
|
chk_newtype()
|
2019-06-11 12:38:22 -04:00
|
|
|
chk(tp.IsFunction(), true)
|
|
|
|
chk(tp.IsFunctionPtr(), false)
|
|
|
|
chk(tp.ReturnType().CType(), "int")
|
2019-06-04 11:27:46 -04:00
|
|
|
|
|
|
|
str = "int *(void)"
|
2019-06-11 12:38:22 -04:00
|
|
|
n, _ = Parse(str)
|
2019-06-04 11:27:46 -04:00
|
|
|
chk_newtype()
|
2019-06-11 12:38:22 -04:00
|
|
|
chk(tp.IsFunction(), true)
|
|
|
|
chk(tp.ReturnType().CType(), "int*")
|
|
|
|
chk(tp.ReturnType().GoType(), "*Int")
|
2019-06-04 11:27:46 -04:00
|
|
|
fn := tp
|
|
|
|
|
2019-06-11 12:38:22 -04:00
|
|
|
AddTypedef("myTypedef", fn)
|
2019-06-04 11:27:46 -04:00
|
|
|
str = "myTypedef"
|
2019-06-11 12:38:22 -04:00
|
|
|
n, _ = Parse(str)
|
2019-06-04 11:27:46 -04:00
|
|
|
chk_newtype()
|
2019-06-11 12:38:22 -04:00
|
|
|
chk(tp.IsFunction(), true)
|
|
|
|
chk(tp.IsFunctionPtr(), false)
|
|
|
|
chk(tp.ReturnType().CType(), "int*")
|
2019-06-04 11:27:46 -04:00
|
|
|
|
|
|
|
str = "int (*)(void)"
|
2019-06-11 12:38:22 -04:00
|
|
|
n, _ = Parse(str)
|
2019-06-04 11:27:46 -04:00
|
|
|
chk_newtype()
|
2019-06-11 12:38:22 -04:00
|
|
|
chk(tp.IsFunction(), false)
|
|
|
|
chk(tp.IsPointer(), true)
|
|
|
|
chk(tp.IsFunctionPtr(), true)
|
|
|
|
chk(tp.ReturnType(), nil)
|
2019-06-04 11:27:46 -04:00
|
|
|
fnptr := tp
|
|
|
|
|
2019-06-11 12:38:22 -04:00
|
|
|
AddTypedef("myTypedef", fnptr)
|
2019-06-04 11:27:46 -04:00
|
|
|
str = "myTypedef"
|
2019-06-11 12:38:22 -04:00
|
|
|
n, _ = Parse(str)
|
2019-06-04 11:27:46 -04:00
|
|
|
chk_newtype()
|
2019-06-11 12:38:22 -04:00
|
|
|
chk(tp.IsFunction(), false)
|
|
|
|
chk(tp.IsPointer(), true)
|
|
|
|
chk(tp.IsFunctionPtr(), true)
|
|
|
|
chk(tp.ReturnType(), nil)
|
2019-06-04 11:27:46 -04:00
|
|
|
|
2019-06-11 12:38:22 -04:00
|
|
|
chk(tp.IsValist(), false)
|
2019-06-04 11:27:46 -04:00
|
|
|
str = "__va_list_tag"
|
2019-06-11 12:38:22 -04:00
|
|
|
n, _ = Parse(str)
|
2019-06-04 11:27:46 -04:00
|
|
|
chk_newtype()
|
2019-06-11 12:38:22 -04:00
|
|
|
chk(tp.IsValist(), true)
|
2019-06-04 11:27:46 -04:00
|
|
|
|
|
|
|
str = "GoToC"
|
|
|
|
var rtype *Type
|
2019-06-13 16:47:36 -04:00
|
|
|
ptypes := []*Type{nsop, nstp, tint, voidpp}
|
2019-06-11 12:38:22 -04:00
|
|
|
pnames := []string{"p1", "p2", "p3", "p4"}
|
|
|
|
snames := []string{"", "", "", ""}
|
2020-06-24 13:03:53 -04:00
|
|
|
goImports := make(map[string]bool)
|
2019-06-04 11:27:46 -04:00
|
|
|
|
|
|
|
chk_gotoc := func(expected string) {
|
2020-06-24 13:03:53 -04:00
|
|
|
chk(GoToC("myFun", "myFun", pnames, snames, rtype, ptypes, false, false, false, goImports), expected)
|
2019-06-04 11:27:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
chk_gotoc("")
|
|
|
|
|
|
|
|
rtype = void
|
2020-06-24 13:03:53 -04:00
|
|
|
chk_gotoc(`C.myFun(p1.Ptr(), p2.Ptr(), (C.int)(p3), unsafe.Pointer(p4))
|
|
|
|
runtime.KeepAlive(o)`)
|
2019-06-04 11:27:46 -04:00
|
|
|
|
|
|
|
rtype = bl
|
|
|
|
chk_gotoc(
|
2019-06-11 12:38:22 -04:00
|
|
|
`ret := (C.myFun(p1.Ptr(), p2.Ptr(), (C.int)(p3), unsafe.Pointer(p4))) != 0
|
2020-06-24 13:03:53 -04:00
|
|
|
runtime.KeepAlive(o)
|
2019-06-04 11:27:46 -04:00
|
|
|
return ret`)
|
|
|
|
|
|
|
|
rtype = voidpp
|
|
|
|
chk_gotoc(
|
2019-06-11 12:38:22 -04:00
|
|
|
`ret := (*unsafe.Pointer)(unsafe.Pointer(C.myFun(p1.Ptr(), p2.Ptr(), (C.int)(p3), unsafe.Pointer(p4))))
|
2020-06-24 13:03:53 -04:00
|
|
|
runtime.KeepAlive(o)
|
2019-06-04 11:27:46 -04:00
|
|
|
return ret`)
|
|
|
|
|
2019-06-13 16:47:36 -04:00
|
|
|
rtype = nstp
|
2019-06-04 11:27:46 -04:00
|
|
|
chk_gotoc(
|
2019-06-13 16:47:36 -04:00
|
|
|
`ret := &NSString{}
|
|
|
|
ret.ptr = unsafe.Pointer(C.myFun(p1.Ptr(), p2.Ptr(), (C.int)(p3), unsafe.Pointer(p4)))
|
2020-06-24 13:03:53 -04:00
|
|
|
if ret.ptr == nil { runtime.KeepAlive(o); return ret }
|
|
|
|
if ret.ptr == o.ptr { runtime.KeepAlive(o); return (*NSString)(unsafe.Pointer(o)) }
|
|
|
|
runtime.KeepAlive(o)
|
2019-06-04 11:27:46 -04:00
|
|
|
return ret`)
|
|
|
|
|
2019-06-13 16:47:36 -04:00
|
|
|
rtype = nsop
|
2019-06-04 11:27:46 -04:00
|
|
|
chk_gotoc(
|
2019-06-13 16:47:36 -04:00
|
|
|
`ret := &Id{}
|
|
|
|
ret.ptr = unsafe.Pointer(C.myFun(p1.Ptr(), p2.Ptr(), (C.int)(p3), unsafe.Pointer(p4)))
|
2020-06-24 13:03:53 -04:00
|
|
|
if ret.ptr == nil { runtime.KeepAlive(o); return ret }
|
|
|
|
if ret.ptr == o.ptr { runtime.KeepAlive(o); return (*Id)(unsafe.Pointer(o)) }
|
|
|
|
runtime.KeepAlive(o)
|
2019-06-04 11:27:46 -04:00
|
|
|
return ret`)
|
|
|
|
|
|
|
|
ptypes[1].Variadic = true
|
2019-06-13 16:47:36 -04:00
|
|
|
ptypes[0].Variadic = false
|
2019-06-04 11:27:46 -04:00
|
|
|
chk_gotoc(
|
2019-06-13 16:47:36 -04:00
|
|
|
`ret := &Id{}
|
|
|
|
ret.ptr = unsafe.Pointer(C.myFun(p1.Ptr(), unsafe.Pointer(&p2), (C.int)(p3), unsafe.Pointer(p4)))
|
2020-06-24 13:03:53 -04:00
|
|
|
if ret.ptr == nil { runtime.KeepAlive(o); return ret }
|
|
|
|
if ret.ptr == o.ptr { runtime.KeepAlive(o); return (*Id)(unsafe.Pointer(o)) }
|
|
|
|
runtime.KeepAlive(o)
|
2019-06-04 11:27:46 -04:00
|
|
|
return ret`)
|
|
|
|
|
2019-06-13 16:47:36 -04:00
|
|
|
ptypes[1].Variadic = false
|
2019-06-04 11:27:46 -04:00
|
|
|
snames[1] = "p2p"
|
2019-06-13 16:47:36 -04:00
|
|
|
ptypes[1] = nsopp
|
2019-06-04 11:27:46 -04:00
|
|
|
chk_gotoc(
|
2019-06-13 16:47:36 -04:00
|
|
|
`ret := &Id{}
|
2019-06-27 11:41:58 -04:00
|
|
|
ret.ptr = unsafe.Pointer(C.myFun(p1.Ptr(), (*unsafe.Pointer)(unsafe.Pointer(&p2p[0])), (C.int)(p3), unsafe.Pointer(p4)))
|
2019-06-04 11:27:46 -04:00
|
|
|
(*p2) = (*p2)[:cap(*p2)]
|
|
|
|
for i := 0; i < len(*p2); i++ {
|
|
|
|
if p2p[i] == nil {
|
|
|
|
(*p2) = (*p2)[:i]
|
|
|
|
break
|
|
|
|
}
|
2019-06-13 16:47:36 -04:00
|
|
|
if (*p2)[i] == nil {
|
|
|
|
(*p2)[i] = &Id{}
|
|
|
|
}
|
2019-06-04 11:27:46 -04:00
|
|
|
(*p2)[i].ptr = p2p[i]
|
|
|
|
}
|
2020-06-24 13:03:53 -04:00
|
|
|
if ret.ptr == nil { runtime.KeepAlive(o); return ret }
|
|
|
|
if ret.ptr == o.ptr { runtime.KeepAlive(o); return (*Id)(unsafe.Pointer(o)) }
|
|
|
|
runtime.KeepAlive(o)
|
2019-06-04 11:27:46 -04:00
|
|
|
return ret`)
|
|
|
|
snames[1] = ""
|
|
|
|
snames[2] = "p3p"
|
2019-06-13 16:47:36 -04:00
|
|
|
ptypes[1] = nsop
|
|
|
|
ptypes[2] = nstpp
|
2019-06-04 11:27:46 -04:00
|
|
|
chk_gotoc(
|
2019-06-13 16:47:36 -04:00
|
|
|
`ret := &Id{}
|
2019-06-27 11:41:58 -04:00
|
|
|
ret.ptr = unsafe.Pointer(C.myFun(p1.Ptr(), p2.Ptr(), (*unsafe.Pointer)(unsafe.Pointer(&p3p[0])), unsafe.Pointer(p4)))
|
2019-06-04 11:27:46 -04:00
|
|
|
(*p3) = (*p3)[:cap(*p3)]
|
|
|
|
for i := 0; i < len(*p3); i++ {
|
|
|
|
if p3p[i] == nil {
|
|
|
|
(*p3) = (*p3)[:i]
|
|
|
|
break
|
|
|
|
}
|
2019-06-13 16:47:36 -04:00
|
|
|
if (*p3)[i] == nil {
|
|
|
|
(*p3)[i] = &NSString{}
|
|
|
|
}
|
2019-06-04 11:27:46 -04:00
|
|
|
(*p3)[i].ptr = p3p[i]
|
|
|
|
}
|
2020-06-24 13:03:53 -04:00
|
|
|
if ret.ptr == nil { runtime.KeepAlive(o); return ret }
|
|
|
|
if ret.ptr == o.ptr { runtime.KeepAlive(o); return (*Id)(unsafe.Pointer(o)) }
|
|
|
|
runtime.KeepAlive(o)
|
2019-06-04 11:27:46 -04:00
|
|
|
return ret`)
|
2019-06-13 16:47:36 -04:00
|
|
|
|
2020-06-24 13:03:53 -04:00
|
|
|
chk(GoToC("myFun", "myFun", pnames, snames, rtype, ptypes, true, false, false, goImports),
|
2019-06-13 16:47:36 -04:00
|
|
|
`ret := &Id{}
|
2019-06-27 11:41:58 -04:00
|
|
|
ret.ptr = unsafe.Pointer(C.myFun(p1.Ptr(), p2.Ptr(), (*unsafe.Pointer)(unsafe.Pointer(&p3p[0])), p4))
|
2019-06-04 11:27:46 -04:00
|
|
|
(*p3) = (*p3)[:cap(*p3)]
|
|
|
|
for i := 0; i < len(*p3); i++ {
|
|
|
|
if p3p[i] == nil {
|
|
|
|
(*p3) = (*p3)[:i]
|
|
|
|
break
|
|
|
|
}
|
2019-06-13 16:47:36 -04:00
|
|
|
if (*p3)[i] == nil {
|
|
|
|
(*p3)[i] = &NSString{}
|
|
|
|
}
|
2019-06-04 11:27:46 -04:00
|
|
|
(*p3)[i].ptr = p3p[i]
|
|
|
|
}
|
2020-06-24 13:03:53 -04:00
|
|
|
if ret.ptr == nil { runtime.KeepAlive(o); return ret }
|
|
|
|
if ret.ptr == o.ptr { runtime.KeepAlive(o); return (*Id)(unsafe.Pointer(o)) }
|
|
|
|
runtime.KeepAlive(o)
|
2019-06-04 11:27:46 -04:00
|
|
|
return ret`)
|
|
|
|
}
|