Skip to content

Commit

Permalink
Merge pull request #25 from goccy/fix-checkptr-error
Browse files Browse the repository at this point in the history
Fix checkptr error
  • Loading branch information
goccy authored Dec 6, 2022
2 parents b6d23c3 + c9b6bcb commit 234d8c6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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++
4 changes: 4 additions & 0 deletions internal/helper/bind.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}))))
Expand Down
4 changes: 2 additions & 2 deletions language_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]))
}))
}

Expand Down Expand Up @@ -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]))
}))
}

Expand Down

0 comments on commit 234d8c6

Please sign in to comment.