aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAnuraag Agrawal <[email protected]>2023-02-17 08:51:51 +0900
committerGitHub <[email protected]>2023-02-17 00:51:51 +0100
commitf6df2761187f1975e35eb43461d735d6e325df85 (patch)
treefd75b6995b6e8448cedd17972891881b9b70929b
parente0a5fc255522933f651a89c071ebd531ad634e7b (diff)
downloadtinygo-f6df2761187f1975e35eb43461d735d6e325df85.tar.gz
tinygo-f6df2761187f1975e35eb43461d735d6e325df85.zip
runtime: allow custom-gc SetFinalizer and clarify KeepAlive
-rw-r--r--src/runtime/gc_blocks.go4
-rw-r--r--src/runtime/gc_custom.go4
-rw-r--r--src/runtime/gc_leaking.go4
-rw-r--r--src/runtime/gc_none.go4
-rw-r--r--src/runtime/runtime.go7
5 files changed, 19 insertions, 4 deletions
diff --git a/src/runtime/gc_blocks.go b/src/runtime/gc_blocks.go
index 59aebb2ec..71e88e4a3 100644
--- a/src/runtime/gc_blocks.go
+++ b/src/runtime/gc_blocks.go
@@ -687,3 +687,7 @@ func ReadMemStats(m *MemStats) {
m.Frees = gcFrees
m.Sys = uint64(heapEnd - heapStart)
}
+
+func SetFinalizer(obj interface{}, finalizer interface{}) {
+ // Unimplemented.
+}
diff --git a/src/runtime/gc_custom.go b/src/runtime/gc_custom.go
index 45857338f..a34b7dce6 100644
--- a/src/runtime/gc_custom.go
+++ b/src/runtime/gc_custom.go
@@ -20,6 +20,7 @@ package runtime
// - func free(ptr unsafe.Pointer)
// - func markRoots(start, end uintptr)
// - func GC()
+// - func SetFinalizer(obj interface{}, finalizer interface{})
// - func ReadMemStats(ms *runtime.MemStats)
//
//
@@ -51,6 +52,9 @@ func markRoots(start, end uintptr)
// GC is called to explicitly run garbage collection.
func GC()
+// SetFinalizer registers a finalizer.
+func SetFinalizer(obj interface{}, finalizer interface{})
+
// ReadMemStats populates m with memory statistics.
func ReadMemStats(ms *MemStats)
diff --git a/src/runtime/gc_leaking.go b/src/runtime/gc_leaking.go
index 2f2bdff17..d99b8d125 100644
--- a/src/runtime/gc_leaking.go
+++ b/src/runtime/gc_leaking.go
@@ -85,6 +85,10 @@ func GC() {
// No-op.
}
+func SetFinalizer(obj interface{}, finalizer interface{}) {
+ // No-op.
+}
+
func initHeap() {
// preinit() may have moved heapStart; reset heapptr
heapptr = heapStart
diff --git a/src/runtime/gc_none.go b/src/runtime/gc_none.go
index 859c0b5db..98636f5c4 100644
--- a/src/runtime/gc_none.go
+++ b/src/runtime/gc_none.go
@@ -26,6 +26,10 @@ func GC() {
// Unimplemented.
}
+func SetFinalizer(obj interface{}, finalizer interface{}) {
+ // Unimplemented.
+}
+
func initHeap() {
// Nothing to initialize.
}
diff --git a/src/runtime/runtime.go b/src/runtime/runtime.go
index a9778eaeb..586a610ae 100644
--- a/src/runtime/runtime.go
+++ b/src/runtime/runtime.go
@@ -89,11 +89,10 @@ func UnlockOSThread() {
}
func KeepAlive(x interface{}) {
- // Unimplemented. Only required with SetFinalizer().
-}
-
-func SetFinalizer(obj interface{}, finalizer interface{}) {
// Unimplemented.
+ // TODO: This function needs to be implemented in a way that LLVM doesn't optimize away the x
+ // parameter. This will likely need either a volatile operation or calling an assembly stub
+ // that simply returns.
}
var godebugUpdate func(string, string)