From 7ac265ff3d8638acf2df4fbfff072d3aed7504b3 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Sun, 20 Feb 2011 05:48:25 +0000 Subject: [PATCH] For Go: Fix handling of INPUT variables when using typemaps.i. This fixes cases where the gotype typemap is used to produce a simple Go type for a non-simple C/C++ type. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12498 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/go/pointer/runme.go | 2 +- Source/Modules/go.cxx | 30 +++++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/Examples/go/pointer/runme.go b/Examples/go/pointer/runme.go index 9cbcda489..63deb11b7 100644 --- a/Examples/go/pointer/runme.go +++ b/Examples/go/pointer/runme.go @@ -32,7 +32,7 @@ func main() { // Now try the typemap library // Now it is no longer necessary to manufacture pointers. - // Instead we use a single element array which in Java is modifiable. + // Instead we use a single element slice which in Go is modifiable. fmt.Println("Trying the typemap library") r := []int{0} diff --git a/Source/Modules/go.cxx b/Source/Modules/go.cxx index 0bb1f4f32..6e320ff53 100644 --- a/Source/Modules/go.cxx +++ b/Source/Modules/go.cxx @@ -4533,6 +4533,20 @@ private: bool is_member = Strcmp(gt, "_swig_memberptr") == 0; bool is_complex64 = Strcmp(gt, "complex64") == 0; bool is_complex128 = Strcmp(gt, "complex128") == 0; + bool is_char = false; + bool is_short = false; + bool is_int = false; + bool is_long = false; + bool is_float = false; + bool is_double = false; + if ((n != NULL && Getattr(n, "tmap:gotype") != NULL) || hasGoTypemap(type)) { + is_char = Strcmp(gt, "int8") == 0 || Strcmp(gt, "uint8") == 0 || Strcmp(gt, "byte") == 0; + is_short = Strcmp(gt, "int16") == 0 || Strcmp(gt, "uint16") == 0; + is_int = Strcmp(gt, "int") == 0 || Strcmp(gt, "int32") == 0 || Strcmp(gt, "uint32") == 0; + is_long = Strcmp(gt, "int64") == 0 || Strcmp(gt, "uint64") == 0; + is_float = Strcmp(gt, "float32") == 0; + is_double = Strcmp(gt, "float64") == 0; + } Delete(gt); String *ret; @@ -4588,7 +4602,21 @@ private: } } Delete(t); - return SwigType_lstr(type, name); + if (is_char) { + ret = NewString("char "); + } else if (is_short) { + ret = NewString("short "); + } else if (is_int) { + ret = NewString("int "); + } else if (is_long) { + ret = NewString("long long "); + } else if (is_float) { + ret = NewString("float "); + } else if (is_double) { + ret = NewString("double "); + } else { + return SwigType_lstr(type, name); + } } if (SwigType_isreference(type)) {