Created
February 13, 2014 12:43
-
-
Save tecbot/8974445 to your computer and use it in GitHub Desktop.
cgo failing interface pointer
This file contains hidden or 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
package main | |
import ( | |
. "github.com/tecbot/gorocksdb" | |
"fmt" | |
"runtime" | |
) | |
type TestComparatorHandler struct { | |
State string | |
} | |
func (self *TestComparatorHandler) Compare(a []byte, b []byte) int { | |
return 0 | |
} | |
func (self *TestComparatorHandler) Name() string { | |
return "gorocksdb.test" | |
} | |
func main() { | |
dbName := "TestDb" | |
opts := NewDefaultOptions() | |
opts.SetCreateIfMissing(true) | |
cmpHandler := &TestComparatorHandler{} | |
cmp := NewComparator(cmpHandler) | |
opts.SetComparator(cmp) | |
DestroyDb(dbName, opts) | |
db, err := OpenDb(opts, dbName) | |
if err != nil { | |
panic(err) | |
} | |
defer db.Close() | |
wo := NewDefaultWriteOptions() | |
err = db.Put(wo, []byte("foo"), []byte("bar")) | |
if err != nil { | |
panic(err) | |
} | |
fmt.Println("execute GC") | |
runtime.GC() | |
// After call Put the C api will call gorocksdb_comparator_compare | |
// and it crashes at the line https://github.com/tecbot/gorocksdb/blob/master/comparator.go#L49 | |
// with the message "unexpected fault address" | |
// If I print the handler I got a panic with SIGILL: illegal instruction | |
err = db.Put(wo, []byte("foo"), []byte("foo")) | |
if err != nil { | |
panic(err) | |
} | |
ro := NewDefaultReadOptions() | |
value, err := db.Get(ro, []byte("foo")) | |
if err != nil { | |
panic(err) | |
} | |
fmt.Println(string(value.Data())) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment