diff options
| author | MatthieuCoder <matthieu@matthieu-dev.xyz> | 2023-01-16 12:06:41 +0400 | 
|---|---|---|
| committer | MatthieuCoder <matthieu@matthieu-dev.xyz> | 2023-01-16 12:06:41 +0400 | 
| commit | a5964c91e018acaef22896f1e4357181df838dd2 (patch) | |
| tree | 6d76171af40a7073f1161d2f7a44213c868e9d39 | |
| parent | c599e7cee33f177d7505e553cf948055930a55c0 (diff) | |
fix go linking
| -rw-r--r-- | .github/workflows/build.yml | 1 | ||||
| -rw-r--r-- | internal/pkg/all-in-one/all-in-one.go | 10 | ||||
| -rw-r--r-- | internal/pkg/all-in-one/error_handler.h | 1 | ||||
| -rw-r--r-- | internal/pkg/all-in-one/handler.go | 13 | 
4 files changed, 15 insertions, 10 deletions
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a2bb06e..1f9073f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -130,6 +130,7 @@ jobs:          env:            CC: clang          run: | +          update-alternatives --set ld /usr/bin/lld            make all        - uses: actions/upload-artifact@v3          with: diff --git a/internal/pkg/all-in-one/all-in-one.go b/internal/pkg/all-in-one/all-in-one.go index 76c11f2..b95d515 100644 --- a/internal/pkg/all-in-one/all-in-one.go +++ b/internal/pkg/all-in-one/all-in-one.go @@ -9,7 +9,6 @@ import "C"  import (  	"fmt"  	"time" -	"unsafe"  	"github.com/Jeffail/gabs"  	"github.com/alicebob/miniredis/v2" @@ -22,14 +21,6 @@ type AllInOne struct {  	instance *C.AllInOneInstance  } -//export goErrorHandler -func goErrorHandler(size C.int, start *C.char) { -	dest := make([]byte, size) -	copy(dest, (*(*[1024]byte)(unsafe.Pointer(start)))[:size:size]) - -	println("Error from all in one runner: %s", string(dest)) -} -  func NewAllInOne() (*AllInOne, error) {  	redis := miniredis.NewMiniRedis()  	nats, err := server.NewServer(&server.Options{}) @@ -55,6 +46,7 @@ func (s *AllInOne) Start() error {  	if !s.nats.ReadyForConnections(5 * time.Second) {  		return fmt.Errorf("nats server didn't start after 5 seconds, please check if there is another service listening on the same port as nats")  	} +  	handler := C.ErrorHandler(C.allInOneErrorHandler)  	// Set the error handler  	C.set_error_handler(handler) diff --git a/internal/pkg/all-in-one/error_handler.h b/internal/pkg/all-in-one/error_handler.h index e04f68d..8fe1a60 100644 --- a/internal/pkg/all-in-one/error_handler.h +++ b/internal/pkg/all-in-one/error_handler.h @@ -2,7 +2,6 @@ extern void goErrorHandler(int, char*);  typedef void (*ErrorHandler)(int, char*); -__attribute__((weak))  void allInOneErrorHandler(int size, char* string) {    goErrorHandler(size, string);  }
\ No newline at end of file diff --git a/internal/pkg/all-in-one/handler.go b/internal/pkg/all-in-one/handler.go new file mode 100644 index 0000000..b92493e --- /dev/null +++ b/internal/pkg/all-in-one/handler.go @@ -0,0 +1,13 @@ +package allinone + +import "C" +import "unsafe" + +//go:linkname goErrorHandler c.goErrorHandler +//export goErrorHandler +func goErrorHandler(size C.int, start *C.char) { +	dest := make([]byte, size) +	copy(dest, (*(*[1024]byte)(unsafe.Pointer(start)))[:size:size]) + +	println("Error from all in one runner: %s", string(dest)) +}  | 
