diff --git a/lattice.go b/lattice.go index 38021a8..e10c685 100644 --- a/lattice.go +++ b/lattice.go @@ -5,6 +5,7 @@ package mecab import "C" import ( "errors" + "reflect" "unsafe" ) @@ -59,7 +60,9 @@ func (l Lattice) SetSentence(s string) { if s == "" { s = "dummy" } - input := *(**C.char)(unsafe.Pointer(&s)) + header := (*reflect.StringHeader)(unsafe.Pointer(&s)) + input := (*C.char)(unsafe.Pointer(header.Data)) + C.mecab_lattice_add_request_type(l.lattice, 64) // MECAB_ALLOCATE_SENTENCE = 64 C.mecab_lattice_set_sentence2(l.lattice, input, length) } diff --git a/mecab.go b/mecab.go index 3fc2ac6..44e470f 100644 --- a/mecab.go +++ b/mecab.go @@ -7,6 +7,7 @@ import "C" import ( "errors" "fmt" + "reflect" "unsafe" ) @@ -59,7 +60,9 @@ func (m MeCab) Parse(s string) (string, error) { if s == "" { s = "dummy" } - input := *(**C.char)(unsafe.Pointer(&s)) + header := (*reflect.StringHeader)(unsafe.Pointer(&s)) + input := (*C.char)(unsafe.Pointer(header.Data)) + result := C.mecab_sparse_tostr2(m.mecab, input, length) if result == nil { return "", m.Error() @@ -86,7 +89,8 @@ func (m MeCab) ParseToNode(s string) (Node, error) { if s == "" { s = "dummy" } - input := *(**C.char)(unsafe.Pointer(&s)) + header := (*reflect.StringHeader)(unsafe.Pointer(&s)) + input := (*C.char)(unsafe.Pointer(header.Data)) node := C.mecab_sparse_tonode2(m.mecab, input, length) if node == nil {