From c334b3b2562b3301369d55a8178efa9c40c31897 Mon Sep 17 00:00:00 2001 From: Youssef ahmed Date: Wed, 10 May 2023 12:30:01 +0200 Subject: [PATCH] feat: add windows support --- go.mod | 2 +- malloc/malloc.go | 2 +- malloc/malloc_unix.go | 9 +++++++++ malloc/malloc_windows.go | 10 ++++++++++ 4 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 malloc/malloc_unix.go create mode 100644 malloc/malloc_windows.go diff --git a/go.mod b/go.mod index d160a81..e80caec 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/joetifa2003/mm-go -go 1.19 +go 1.20 require ( github.com/ebitengine/purego v0.4.0-alpha.4 diff --git a/malloc/malloc.go b/malloc/malloc.go index 44c1543..1bef16b 100644 --- a/malloc/malloc.go +++ b/malloc/malloc.go @@ -26,7 +26,7 @@ func getSystemLibrary() string { } func init() { - libc, err := purego.Dlopen(getSystemLibrary(), purego.RTLD_NOW|purego.RTLD_GLOBAL) + libc, err := openLibrary(getSystemLibrary()) if err != nil { panic(err) } diff --git a/malloc/malloc_unix.go b/malloc/malloc_unix.go new file mode 100644 index 0000000..b4e3b63 --- /dev/null +++ b/malloc/malloc_unix.go @@ -0,0 +1,9 @@ +//go:build darwin || linux + +package malloc + +import "github.com/ebitengine/purego" + +func openLibrary(name string) (uintptr, error) { + return purego.Dlopen(name, purego.RTLD_NOW|purego.RTLD_GLOBAL) +} diff --git a/malloc/malloc_windows.go b/malloc/malloc_windows.go new file mode 100644 index 0000000..62bfb23 --- /dev/null +++ b/malloc/malloc_windows.go @@ -0,0 +1,10 @@ +//go:build windows + +package malloc + +import "golang.org/x/sys/windows" + +func openLibrary(name string) (uintptr, error) { + handle, err := windows.LoadLibrary(name) + return uintptr(handle), err +}