diff options
author | Ian Lance Taylor <iant@golang.org> | 2015-03-02 14:03:33 -0800 |
---|---|---|
committer | Ian Lance Taylor <iant@golang.org> | 2015-03-02 14:03:33 -0800 |
commit | 9ad497c08e012b9fc5431486d982ea4053c53478 (patch) | |
tree | 0e9ddb09680b8085c08c2e5e8a1ff98e1dd466e4 /Lib/go | |
parent | df36d84f1b43cdb9c5aba2277942871d874deecf (diff) | |
download | swig-9ad497c08e012b9fc5431486d982ea4053c53478.tar.gz |
[Go] Add -cgo option, required for Go version 1.5 and later.
Diffstat (limited to 'Lib/go')
-rw-r--r-- | Lib/go/go.swg | 2 | ||||
-rw-r--r-- | Lib/go/goruntime.swg | 65 |
2 files changed, 63 insertions, 4 deletions
diff --git a/Lib/go/go.swg b/Lib/go/go.swg index d38623b4a..35f914c5b 100644 --- a/Lib/go/go.swg +++ b/Lib/go/go.swg @@ -533,7 +533,7 @@ %typemap(directorin) enum SWIGTYPE & (intgo e) %{ e = (intgo)$1; - $input = &e; + $input = ($1_ltype)&e; %} %typemap(godirectorin) enum SWIGTYPE & "" diff --git a/Lib/go/goruntime.swg b/Lib/go/goruntime.swg index f76da9c78..d776e414a 100644 --- a/Lib/go/goruntime.swg +++ b/Lib/go/goruntime.swg @@ -19,21 +19,45 @@ static void Swig_free(void* p) { %} +#if SWIGGO_CGO +%insert(cgo_comment_typedefs) %{ +#include <stdint.h> +%} +#endif + #if SWIGGO_INTGO_SIZE == 32 %insert(runtime) %{ typedef int intgo; typedef unsigned int uintgo; %} +#if SWIGGO_CGO +%insert(cgo_comment_typedefs) %{ +typedef int intgo; +typedef unsigned int uintgo; +%} +#endif #elif SWIGGO_INTGO_SIZE == 64 %insert(runtime) %{ typedef long long intgo; typedef unsigned long long uintgo; %} +#if SWIGGO_CGO +%insert(cgo_comment_typedefs) %{ +typedef long long intgo; +typedef unsigned long long uintgo; +%} +#endif #else %insert(runtime) %{ typedef ptrdiff_t intgo; typedef size_t uintgo; %} +#if SWIGGO_CGO +%insert(cgo_comment_typedefs) %{ +typedef ptrdiff_t intgo; +typedef size_t uintgo; +%} +#endif #endif %insert(runtime) %{ @@ -43,6 +67,17 @@ typedef struct { void* array; intgo len; intgo cap; } _goslice_; %} +#ifdef SWIGGO_CGO + +%insert(cgo_comment_typedefs) %{ + +typedef struct { char *p; intgo n; } _gostring_; +typedef struct { void* array; intgo len; intgo cap; } _goslice_; + +%} + +#endif + #ifndef SWIGGO_GCCGO /* Boilerplate for C/C++ code when using 6g/8g. This code is compiled with gcc. */ @@ -98,6 +133,8 @@ static void _swig_gopanic(const char *p) { %} +#if !SWIGGO_CGO + /* Boilerplate for C code when using 6g/8g. This code is compiled with 6c/8c. */ %insert(gc_header) %{ @@ -111,6 +148,8 @@ void *ยท_cgo_runtime_cgocall = &cgocall; %} +#endif + #else /* Boilerplate for C/C++ code when using gccgo. */ @@ -122,6 +161,17 @@ extern "C" { #endif extern void *_cgo_allocate(size_t); extern void _cgo_panic(const char *); +#ifdef __cplusplus +} +#endif + +#define _swig_goallocate _cgo_allocate +#define _swig_gopanic _cgo_panic +%} + +#if !SWIGGO_CGO + +%insert(runtime) %{ /* Implementations of SwigCgocall and friends for different versions of gccgo. The Go code will call these functions using C names with @@ -130,6 +180,10 @@ extern void _cgo_panic(const char *); version. We assume that the version of gcc used to compile this file is the same as the version of gccgo. */ +#ifdef __cplusplus +extern "C" { +#endif + #define SWIG_GCC_VERSION \ (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) @@ -184,13 +238,12 @@ void SwigCgocallBackDone() { } #endif -#define _swig_goallocate _cgo_allocate -#define _swig_gopanic _cgo_panic - %} #endif +#endif + %insert(runtime) %{ static _gostring_ _swig_makegostring(const char *p, size_t l) { @@ -209,9 +262,11 @@ static _gostring_ _swig_makegostring(const char *p, size_t l) { %go_import("unsafe", _ "runtime/cgo") +#if !SWIGGO_CGO %insert(go_header) %{ var _cgo_runtime_cgocall func(unsafe.Pointer, uintptr) %} +#endif #else @@ -231,6 +286,8 @@ type _ unsafe.Pointer %} +#if !SWIGGO_CGO + /* Swig_always_false is used to conditionally assign parameters to Swig_escape_val so that the compiler thinks that they escape. We only assign them if Swig_always_false is true, which it never is. @@ -241,6 +298,8 @@ var Swig_escape_always_false bool var Swig_escape_val interface{} %} +#endif + /* Function pointers are translated by the code in go.cxx into _swig_fnptr. Member pointers are translated to _swig_memberptr. */ |