fix: use pragma for ptr checks

This commit is contained in:
Nicholas Wiersma
2020-06-22 16:40:03 +02:00
committed by GitHub
parent 9627782394
commit c2ad279643
2 changed files with 7 additions and 12 deletions

View File

@@ -1,11 +1,3 @@
GO_VERSION=$(shell go version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f1,2)
RACE_TEST_GCFLAGS=
ifneq ($(GO_VERSION), 1.13)
# support for unsafe means we cannot do unsafe pointer arithmetic checks
RACE_TEST_GCFLAGS=-gcflags=all=-d=checkptr=0
endif
# Static linting of source files. See .golangci.toml for options # Static linting of source files. See .golangci.toml for options
check: check:
golangci-lint run golangci-lint run
@@ -26,6 +18,6 @@ generate: gen_all_syscall
tests: tests:
GO111MODULE=off go test -v ./... GO111MODULE=off go test -v ./...
GO111MODULE=off go test -race $(RACE_TEST_GCFLAGS) -short ./interp GO111MODULE=off go test -race ./interp
.PHONY: check gen_all_syscall gen_tests .PHONY: check gen_all_syscall gen_tests

View File

@@ -27,9 +27,7 @@ func init() {
func convert(from, to reflect.Type) func(src, dest reflect.Value) { func convert(from, to reflect.Type) func(src, dest reflect.Value) {
switch { switch {
case to.Kind() == reflect.UnsafePointer && from.Kind() == reflect.Uintptr: case to.Kind() == reflect.UnsafePointer && from.Kind() == reflect.Uintptr:
return func(src, dest reflect.Value) { return uintptrToUnsafePtr
dest.SetPointer(unsafe.Pointer(src.Interface().(uintptr))) //nolint:govet
}
case to.Kind() == reflect.UnsafePointer: case to.Kind() == reflect.UnsafePointer:
return func(src, dest reflect.Value) { return func(src, dest reflect.Value) {
dest.SetPointer(unsafe.Pointer(src.Pointer())) dest.SetPointer(unsafe.Pointer(src.Pointer()))
@@ -58,4 +56,9 @@ func alignof(i interface{}) uintptr {
return uintptr(reflect.ValueOf(i).Type().Align()) return uintptr(reflect.ValueOf(i).Type().Align())
} }
//go:nocheckptr
func uintptrToUnsafePtr(src, dest reflect.Value) {
dest.SetPointer(unsafe.Pointer(src.Interface().(uintptr))) //nolint:govet
}
//go:generate ../../cmd/goexports/goexports unsafe //go:generate ../../cmd/goexports/goexports unsafe