Fix Go support to use appropriate interface for entering and leaving
C/C++ code, depending on GCC version. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13146 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
8fe63be051
commit
7ec208da05
2 changed files with 76 additions and 13 deletions
|
|
@ -84,6 +84,57 @@ extern "C" {
|
|||
#endif
|
||||
extern void *_cgo_allocate(size_t);
|
||||
extern void _cgo_panic(const char *);
|
||||
|
||||
/* Implementations of SwigCgocall and friends for different versions
|
||||
of gccgo. The Go code will call these functions using C names with
|
||||
a prefix of the module name. The implementations here call the
|
||||
routine in libgo. The routines to call vary depending on the gccgo
|
||||
version. We assume that the version of gcc used to compile this
|
||||
file is the same as the version of gccgo. */
|
||||
|
||||
#define SWIGCONCAT2(s1, s2) s1 ## s2
|
||||
#define SWIGCONCAT1(s1, s2) SWIGCONCAT2(s1, s2)
|
||||
#define SwigCgocall SWIGCONCAT1(SWIGMODULE, SwigCgocall)
|
||||
#define SwigCgocallDone SWIGCONCAT1(SWIGMODULE, SwigCgocallDone)
|
||||
#define SwigCgocallBack SWIGCONCAT1(SWIGMODULE, SwigCgocallBack)
|
||||
#define SwigCgocallBackDone SWIGCONCAT1(SWIGMODULE, SwigCgocallBackDone)
|
||||
|
||||
#define SWIG_GCC_VERSION \
|
||||
(__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC__PATH_LEVEL__)
|
||||
|
||||
#if SWIG_GCC_VERSION < 40700
|
||||
#define SwigDoCgocall()
|
||||
#define SwigDoCgocalldone()
|
||||
#define SwigDoCgocallBack()
|
||||
#define SwigDoCgocallBackDone()
|
||||
#elif SWIG_GCC_VERSION == 40700
|
||||
void SwigDoCgocall(void) __asm__("libgo_syscall.syscall.Entersyscall");
|
||||
void SwigDoCgocallDone(void) __asm__("libgo_syscall.syscall.Exitsyscall");
|
||||
void SwigDoCgocallBack(void) __asm__("libgo_syscall.syscall.Exitsyscall");
|
||||
void SwigDoCgocallBackDone(void) __asm__("libgo_syscall.syscall.Entersyscall");
|
||||
#else
|
||||
void SwigDoCgocall(void) __asm__("syscall.Cgocall");
|
||||
void SwigDoCgocallDone(void) __asm__("syscall.CgocallDone");
|
||||
void SwigDoCgocallBack(void) __asm__("syscall.CgocallBack");
|
||||
void SwigDoCgocallBackDone(void) __asm__("syscall.CgocallBackDone");
|
||||
#endif
|
||||
|
||||
void SwigCgocall() {
|
||||
SwigDoCgocall();
|
||||
}
|
||||
|
||||
void SwigCgocallDone() {
|
||||
SwigDoCgocallDone();
|
||||
}
|
||||
|
||||
void SwigCgocallBack() {
|
||||
SwigDoCgocallBack();
|
||||
}
|
||||
|
||||
void SwigCgocallBackDone() {
|
||||
SwigDoCgocallBackDone();
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -326,6 +326,8 @@ private:
|
|||
|
||||
Swig_banner(f_c_begin);
|
||||
|
||||
Printf(f_c_runtime, "#define SWIGMODULE %s\n", module);
|
||||
|
||||
if (directorsEnabled()) {
|
||||
Printf(f_c_runtime, "#define SWIG_DIRECTORS\n");
|
||||
|
||||
|
|
@ -349,6 +351,15 @@ private:
|
|||
|
||||
Printf(f_go_begin, "\npackage %s\n\n", package);
|
||||
|
||||
Printf(f_go_runtime, "//extern %sSwigCgocall\n", module);
|
||||
Printf(f_go_runtime, "func SwigCgocall()\n");
|
||||
Printf(f_go_runtime, "//extern %sSwigCgocallDone\n", module);
|
||||
Printf(f_go_runtime, "func SwigCgocallDone()\n");
|
||||
Printf(f_go_runtime, "//extern %sSwigCgocallBack\n", module);
|
||||
Printf(f_go_runtime, "func SwigCgocallBack()\n");
|
||||
Printf(f_go_runtime, "//extern %sSwigCgocallBackDone\n", module);
|
||||
Printf(f_go_runtime, "func SwigCgocallBackDone()\n\n");
|
||||
|
||||
// All the C++ wrappers should be extern "C".
|
||||
|
||||
Printv(f_c_wrappers, "#ifdef __cplusplus\n", "extern \"C\" {\n", "#endif\n\n", NULL);
|
||||
|
|
@ -941,8 +952,8 @@ private:
|
|||
}
|
||||
|
||||
if (gccgo_flag) {
|
||||
Printv(f_go_wrappers, "\tsyscall.Entersyscall()\n", NULL);
|
||||
Printv(f_go_wrappers, "\tdefer syscall.Exitsyscall()\n", NULL);
|
||||
Printv(f_go_wrappers, "\tSwigCgocall()\n", NULL);
|
||||
Printv(f_go_wrappers, "\tdefer SwigCgocallDone()\n", NULL);
|
||||
}
|
||||
|
||||
Printv(f_go_wrappers, "\t", NULL);
|
||||
|
|
@ -2538,8 +2549,8 @@ private:
|
|||
Printv(f_go_wrappers, "\tp := &", director_struct_name, "{0, v}\n", NULL);
|
||||
|
||||
if (gccgo_flag) {
|
||||
Printv(f_go_wrappers, "\tsyscall.Entersyscall()\n", NULL);
|
||||
Printv(f_go_wrappers, "\tdefer syscall.Exitsyscall()\n", NULL);
|
||||
Printv(f_go_wrappers, "\tSwigCgocall()\n", NULL);
|
||||
Printv(f_go_wrappers, "\tdefer SwigCgocallDone()\n", NULL);
|
||||
}
|
||||
|
||||
Printv(f_go_wrappers, "\tp.", class_receiver, " = ", fn_name, NULL);
|
||||
|
|
@ -3049,11 +3060,6 @@ private:
|
|||
|
||||
Printv(f_go_wrappers, " {\n", NULL);
|
||||
|
||||
if (gccgo_flag) {
|
||||
Printv(f_go_wrappers, "\tsyscall.Entersyscall()\n", NULL);
|
||||
Printv(f_go_wrappers, "\tdefer syscall.Exitsyscall()\n", NULL);
|
||||
}
|
||||
|
||||
Printv(f_go_wrappers, "\tif swig_g, swig_ok := swig_p.v.(", interface_name, "); swig_ok {\n", NULL);
|
||||
Printv(f_go_wrappers, "\t\t", NULL);
|
||||
if (SwigType_type(result) != T_VOID) {
|
||||
|
|
@ -3076,6 +3082,12 @@ private:
|
|||
Printv(f_go_wrappers, "\t\treturn\n", NULL);
|
||||
}
|
||||
Printv(f_go_wrappers, "\t}\n", NULL);
|
||||
|
||||
if (gccgo_flag) {
|
||||
Printv(f_go_wrappers, "\tSwigCgocall()\n", NULL);
|
||||
Printv(f_go_wrappers, "\tdefer SwigCgocallDone()\n", NULL);
|
||||
}
|
||||
|
||||
Printv(f_go_wrappers, "\t", NULL);
|
||||
if (SwigType_type(result) != T_VOID) {
|
||||
Printv(f_go_wrappers, "return ", NULL);
|
||||
|
|
@ -3222,8 +3234,8 @@ private:
|
|||
Printv(f_go_wrappers, " {\n", NULL);
|
||||
|
||||
if (gccgo_flag) {
|
||||
Printv(f_go_wrappers, "\tsyscall.Entersyscall()\n", NULL);
|
||||
Printv(f_go_wrappers, "\tdefer syscall.Exitsyscall()\n", NULL);
|
||||
Printv(f_go_wrappers, "\tSwigCgocall()\n", NULL);
|
||||
Printv(f_go_wrappers, "\tdefer SwigCgocallDone()\n", NULL);
|
||||
}
|
||||
|
||||
Printv(f_go_wrappers, "\t", NULL);
|
||||
|
|
@ -3269,8 +3281,8 @@ private:
|
|||
Printv(f_go_wrappers, "{\n", NULL);
|
||||
|
||||
if (gccgo_flag) {
|
||||
Printv(f_go_wrappers, "\tsyscall.Exitsyscall()\n", NULL);
|
||||
Printv(f_go_wrappers, "\tdefer syscall.Entersyscall()\n", NULL);
|
||||
Printv(f_go_wrappers, "\tSwigCgocallBack()\n", NULL);
|
||||
Printv(f_go_wrappers, "\tdefer SwigCgocallBackDone()\n", NULL);
|
||||
}
|
||||
|
||||
Printv(f_go_wrappers, "\t", NULL);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue