-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
For Go 1.21+, ask the Go runtime about its GC.
For background, see: https://go-review.googlesource.com/c/go/+/498121 and https://go-review.googlesource.com/c/go/+/498261
- Loading branch information
Showing
3 changed files
with
45 additions
and
37 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright 2020 Brad Fitzpatrick. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
//go:build go1.21 | ||
// +build go1.21 | ||
|
||
package assume_no_moving_gc | ||
|
||
import ( | ||
"os" | ||
_ "unsafe" | ||
) | ||
|
||
//go:linkname heapObjectsCanMove runtime.heapObjectsCanMove | ||
func heapObjectsCanMove() bool | ||
|
||
func init() { | ||
if !heapObjectsCanMove() { | ||
// The unsafe assumptions made by the package | ||
// importing this package still hold. All's good. (at | ||
// least unless they made other assumption this | ||
// package doesn't concern itself with) | ||
return | ||
} | ||
if os.Getenv(env) == "play-with-fire" { | ||
return | ||
} | ||
panic(` | ||
Something in this program imports go4.org/unsafe/assume-no-moving-gc to | ||
declare that it assumes a non-moving garbage collector, but the version | ||
of Go you're using declares that its heap objects can now move around. | ||
This program is no longer safe. You should update your packages which import | ||
go4.org/unsafe/assume-no-moving-gc. To risk it and bypass this check, set | ||
ASSUME_NO_MOVING_GC_UNSAFE=play-with-fire and cross your fingers.`) | ||
} |
This file was deleted.
Oops, something went wrong.