[Go] Fix use of goout typemap when calling base method by
forcing the "type" attribute to the value we need.
This commit is contained in:
parent
9cd3e28c4e
commit
0f54384ee3
4 changed files with 55 additions and 0 deletions
|
|
@ -40,4 +40,14 @@ func main() {
|
|||
fmt.Println("got", a, "want", dwant)
|
||||
panic(a)
|
||||
}
|
||||
|
||||
c2 := go_inout.NewC2()
|
||||
pm := c2.M()
|
||||
want = map[string]interface{}{
|
||||
"ID": float64(1),
|
||||
}
|
||||
if !reflect.DeepEqual(*pm, want) {
|
||||
fmt.Println("for c2.M got", pm, "want", want)
|
||||
panic(pm)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -68,6 +68,26 @@ type In json.Marshaler
|
|||
}
|
||||
%}
|
||||
|
||||
%typemap(gotype) RetStruct* "*map[string]interface{}"
|
||||
|
||||
%typemap(imtype) RetStruct* "*string"
|
||||
|
||||
%typemap(out,fragment="AllocateString") RetStruct*
|
||||
%{
|
||||
$result = (_gostring_*)malloc(sizeof(_gostring_));
|
||||
*$result = Swig_AllocateString($1->str.data(), $1->str.length());
|
||||
%}
|
||||
|
||||
%typemap(goout,fragment="CopyString") RetStruct*
|
||||
%{
|
||||
defer Swig_free(uintptr(unsafe.Pointer($1)))
|
||||
var rm map[string]interface{}
|
||||
if err := json.Unmarshal([]byte(swigCopyString(*$1)), &rm); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
$result = &rm
|
||||
%}
|
||||
|
||||
%inline
|
||||
%{
|
||||
|
||||
|
|
@ -206,3 +226,18 @@ void DoubleArray(MyArray* v) {
|
|||
}
|
||||
}
|
||||
%}
|
||||
|
||||
%inline
|
||||
%{
|
||||
class C1 {
|
||||
public:
|
||||
RetStruct* M() {
|
||||
RetStruct* r = new RetStruct;
|
||||
r->str = "{\"ID\":1}";
|
||||
return r;
|
||||
}
|
||||
};
|
||||
|
||||
class C2 : public C1 {
|
||||
};
|
||||
%}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue