forked from wasmerio/wasmer-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes wasmerio#415 As documented in wasmerio#415, the memory mode exposed by wasmer-go is error prone and hard to use. Introduce a `CPtrBase[T]` helper struct to attempt to surface errors often and early. The `CPtrBase` is meant to store a CGo pointer. Then, through conditional compilation, a debug implementation, enabled via `-tags memcheck` tag, is used, which adds expensive pointer access checks as well as forces calls to `runtime.GC()` whenever underlying pointer accessed. These access are very slow -- however, they cause almost immediate crashes to surface in tests. It's possible that some issues still remain; The fixes were applied in order to ensure that the tests pass 5000 times. Beyond that, there could still be remaining issues. Release note (<category, see below>): <what> <show> <why>
- Loading branch information
Yevgeniy Miretskiy
committed
Jan 14, 2025
1 parent
f09913d
commit 1f78846
Showing
26 changed files
with
704 additions
and
408 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package wasmer | ||
|
||
// CPtrBase is a based struct for a C pointer. | ||
// It is intended to be embedded into any structure | ||
// that stores a C pointer. | ||
// While this based is parameterized on type any, using any | ||
// type other than *C.xxx pointer should be considered an undefined behavior. | ||
type CPtrBase[T comparable] struct { | ||
_ptr T | ||
maybeStack // stack of the creating goroutine (if enabled via memcheck) | ||
maybeNil[T] // indicates if initial value of _ptr was nil (if enabled via memcheck) | ||
} | ||
|
||
// release returns the C pointer stored in this base and clears the finalizer. | ||
func (b *CPtrBase[T]) release() T { | ||
var zero T | ||
v := b.ptr() | ||
b._ptr = zero | ||
b.ClearFinalizer() | ||
return v | ||
} | ||
|
||
func (b *CPtrBase[T]) SetFinalizer(free func(v T)) { | ||
doSetFinalizer(b, free) | ||
} | ||
|
||
func (b *CPtrBase[T]) ClearFinalizer() { | ||
doClearFinalizer(b) | ||
} | ||
|
||
func mkPtr[T comparable](ptr T) CPtrBase[T] { | ||
return doMkPtr(ptr) | ||
} |
Oops, something went wrong.