From c8b9aaeb67b051668bb1ef302891698d7fcc788a Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Sun, 3 Sep 2023 13:13:49 +0100 Subject: [PATCH] Only set mobile memory limit on supported Go versions --- contrib/mobile/mobile.go | 3 +-- contrib/mobile/mobile_mem_go120.go | 10 ++++++++++ contrib/mobile/mobile_mem_other.go | 8 ++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 contrib/mobile/mobile_mem_go120.go create mode 100644 contrib/mobile/mobile_mem_other.go diff --git a/contrib/mobile/mobile.go b/contrib/mobile/mobile.go index f4f8c22f..85ff63f1 100644 --- a/contrib/mobile/mobile.go +++ b/contrib/mobile/mobile.go @@ -6,7 +6,6 @@ import ( "fmt" "net" "regexp" - "runtime/debug" "github.com/gologme/log" @@ -45,7 +44,7 @@ func (m *Yggdrasil) StartAutoconfigure() error { // StartJSON starts a node with the given JSON config. You can get JSON config // (rather than HJSON) by using the GenerateConfigJSON() function func (m *Yggdrasil) StartJSON(configjson []byte) error { - debug.SetMemoryLimit(1024 * 1024 * 40) + setMemLimitIfPossible() m.logger = log.New(m.log, "", 0) m.logger.EnableLevel("error") diff --git a/contrib/mobile/mobile_mem_go120.go b/contrib/mobile/mobile_mem_go120.go new file mode 100644 index 00000000..853f1aba --- /dev/null +++ b/contrib/mobile/mobile_mem_go120.go @@ -0,0 +1,10 @@ +//go:build go1.20 +// +build go1.20 + +package mobile + +import "runtime/debug" + +func setMemLimitIfPossible() { + debug.SetMemoryLimit(1024 * 1024 * 40) +} diff --git a/contrib/mobile/mobile_mem_other.go b/contrib/mobile/mobile_mem_other.go new file mode 100644 index 00000000..729d9c2a --- /dev/null +++ b/contrib/mobile/mobile_mem_other.go @@ -0,0 +1,8 @@ +//go:build !go1.20 +// +build !go1.20 + +package mobile + +func setMemLimitIfPossible() { + // not supported by this Go version +}