github.com/kidsbmilk/gofronted_all@v0.0.0-20220701224323-6479d5976c5d/libgo/misc/cgo/testso/testdata/cgoso_c.c (about) 1 // Copyright 2011 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // +build ignore 6 7 #ifdef WIN32 8 // A Windows DLL is unable to call an arbitrary function in 9 // the main executable. Work around that by making the main 10 // executable pass the callback function pointer to us. 11 void (*goCallback)(void); 12 __declspec(dllexport) void setCallback(void *f) 13 { 14 goCallback = (void (*)())f; 15 } 16 __declspec(dllexport) void sofunc(void); 17 #elif defined(_AIX) 18 // AIX doesn't allow the creation of a shared object with an 19 // undefined symbol. It's possible to bypass this problem by 20 // using -Wl,-G and -Wl,-brtl option which allows run-time linking. 21 // However, that's not how most of AIX shared object works. 22 // Therefore, it's better to consider goCallback as a pointer and 23 // to set up during an init function. 24 void (*goCallback)(void); 25 void setCallback(void *f) { goCallback = f; } 26 #else 27 extern void goCallback(void); 28 void setCallback(void *f) { (void)f; } 29 #endif 30 31 // OpenBSD and older Darwin lack TLS support 32 #if !defined(__OpenBSD__) && !defined(__APPLE__) 33 __thread int tlsvar = 12345; 34 #endif 35 36 void sofunc(void) 37 { 38 goCallback(); 39 }