Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test using cgocheck=2 and fix compaction_filter test for that #127

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ install:
- go get -t ./...

script:
- go test -v ./
- GODEBUG=cgocheck=2 go test -v ./

notifications:
email:
Expand Down
5 changes: 4 additions & 1 deletion compaction_filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ func TestCompactionFilter(t *testing.T) {
var (
changeKey = []byte("change")
changeValOld = []byte("old")
changeValNew = []byte("new")
changeValNew = cBackedBytes([]byte("new"))
deleteKey = []byte("delete")
)

defer freeCBackedBytes(changeValNew)

db := newTestDB(t, "TestCompactionFilter", func(opts *Options) {
opts.SetCompactionFilter(&mockCompactionFilter{
filter: func(level int, key, val []byte) (remove bool, newVal []byte) {
Expand Down
14 changes: 14 additions & 0 deletions util.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package gorocksdb

// #include <stdlib.h>
import "C"
import (
"reflect"
Expand Down Expand Up @@ -30,6 +31,19 @@ func charToByte(data *C.char, len C.size_t) []byte {
return value
}

// cBackedBytes returs a copy of the same byte slice which is backed by
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/returs/returns

// malloced memory. This should be freed using freeCBackedBytes.
func cBackedBytes(data []byte) []byte {
return charToByte(cByteSlice(data), C.size_t(len(data)))
}

// freeCBackedBytes frees a byte slice created by cBackedBytes
func freeCBackedBytes(data []byte) {
sH := (*reflect.SliceHeader)(unsafe.Pointer(&data))
C.free(unsafe.Pointer(sH.Data))

}

// byteToChar returns *C.char from byte slice.
func byteToChar(b []byte) *C.char {
var c *C.char
Expand Down