From c9b6bcbd277c744b5be123a03836ea661c254e35 Mon Sep 17 00:00:00 2001 From: Masaaki Goshima Date: Tue, 6 Dec 2022 13:48:45 +0900 Subject: [PATCH] fix checkptr error --- .github/workflows/go.yml | 2 +- internal/helper/bind.go | 4 ++++ language_options.go | 4 ++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index a4f71245..2012f721 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -20,7 +20,7 @@ jobs: - name: checkout uses: actions/checkout@v2 - name: test - run: go test -v ./ -count=1 + run: go test -race -v ./ -count=1 env: CC: clang CXX: clang++ diff --git a/internal/helper/bind.go b/internal/helper/bind.go index 02523968..df488493 100644 --- a/internal/helper/bind.go +++ b/internal/helper/bind.go @@ -55,6 +55,10 @@ func PtrToSlice(p unsafe.Pointer, cb func(unsafe.Pointer)) { } } +func IntPtr(v int) unsafe.Pointer { + return *(*unsafe.Pointer)(unsafe.Pointer(&v)) +} + func SliceToPtr(v interface{}, cb func(int) unsafe.Pointer) unsafe.Pointer { rv := reflect.ValueOf(v) slice := (*reflect.SliceHeader)(C.malloc(C.ulong(unsafe.Sizeof(reflect.SliceHeader{})))) diff --git a/language_options.go b/language_options.go index 50c9f039..a336f2fb 100644 --- a/language_options.go +++ b/language_options.go @@ -52,7 +52,7 @@ func (o *LanguageOptions) SupportsStatementKind(kind resolved_ast.Kind) bool { // explicitly opt in to support other statements. func (o *LanguageOptions) SetSupportedStatementKinds(kinds []resolved_ast.Kind) { internal.LanguageOptions_SetSupportedStatementKinds(o.raw, helper.SliceToPtr(kinds, func(i int) unsafe.Pointer { - return unsafe.Pointer(uintptr(int(kinds[i]))) + return helper.IntPtr(int(kinds[i])) })) } @@ -91,7 +91,7 @@ func (o *LanguageOptions) EnableLanguageFeature(feature LanguageFeature) { func (o *LanguageOptions) SetEnabledLanguageFeatures(features []LanguageFeature) { internal.LanguageOptions_SetEnabledLanguageFeatures(o.raw, helper.SliceToPtr(features, func(i int) unsafe.Pointer { - return unsafe.Pointer(uintptr(int(features[i]))) + return helper.IntPtr(int(features[i])) })) }