Commits

Max Hauser committed 3076312

Update to go1 and kc 1.2.76

Comments (0)

Files changed (2)

 import "C"
 
 import (
+	"errors"
 	"log"
-	"os"
 	"unsafe"
 )
 
 	return C.GoString(C.kcecodename(C.int32_t(ecode)))
 }
 
-func (kc *KCDB) error() os.Error {
-	return os.NewError(EcodeName(kc.Ecode()))
+func (kc *KCDB) error() error {
+	return errors.New(EcodeName(kc.Ecode()))
 }
 
-func (kc *KCDB) Open(filename string, mode int) (err os.Error) {
+func (kc *KCDB) Open(filename string, mode int) (err error) {
 	name := C.CString(filename)
 	defer C.free(unsafe.Pointer(name))
 	if C.kcdbopen(kc.db, name, C.uint32_t(mode)) == 0 {
 	return
 }
 
-func (kc *KCDB) Close() (err os.Error) {
+func (kc *KCDB) Close() (err error) {
 	if C.kcdbclose(kc.db) == 0 {
 		err = kc.error()
 	}
 	C.kcdbdel(kc.db)
 }
 
-func (kc *KCDB) Path() (path string, err os.Error) {
+func (kc *KCDB) Path() (path string, err error) {
 	cpath := C.kcdbpath(kc.db)
 	defer C.kcfree(unsafe.Pointer(cpath))
 	path = C.GoString(cpath)
 	return
 }
 
-func (kc *KCDB) Status() (status string, err os.Error) {
+func (kc *KCDB) Status() (status string, err error) {
 	cstatus := C.kcdbstatus(kc.db)
 	if cstatus == nil {
 		err = kc.error()
 	return
 }
 
-func (kc *KCDB) Count() (count uint64, err os.Error) {
+func (kc *KCDB) Count() (count uint64, err error) {
 	ccount := C.kcdbcount(kc.db)
 	if ccount == -1 {
 		err = kc.error()
 	return
 }
 
-func (kc *KCDB) Size() (size uint64, err os.Error) {
+func (kc *KCDB) Size() (size uint64, err error) {
 	csize := C.kcdbsize(kc.db)
 	if csize == -1 {
 		err = kc.error()
 	return
 }
 
-func (kc *KCDB) Clear() (err os.Error) {
+func (kc *KCDB) Clear() (err error) {
 	if C.kcdbclear(kc.db) == 0 {
 		err = kc.error()
 	}
 	return
 }
 
-func (kc *KCDB) Sync(hard bool) (err os.Error) {
+func (kc *KCDB) Sync(hard bool) (err error) {
 	var chard C.int32_t
 	if hard {
 		chard = 1
 	return
 }
 
-func (kc *KCDB) Copy(filename string) (err os.Error) {
+func (kc *KCDB) Copy(filename string) (err error) {
 	name := C.CString(filename)
 	defer C.free(unsafe.Pointer(name))
 	if C.kcdbcopy(kc.db, name) == 0 {
 	return
 }
 
-func (kc *KCDB) Merge(sdbs []*KCDB, mode int) (err os.Error) {
+func (kc *KCDB) Merge(sdbs []*KCDB, mode int) (err error) {
 	count := len(sdbs)
 	csdbs := make([]*C.KCDB, count)
 	for i, db := range sdbs {
 	return
 }
 
-func (kc *KCDB) Dump(filename string) (err os.Error) {
+func (kc *KCDB) Dump(filename string) (err error) {
 	name := C.CString(filename)
 	defer C.free(unsafe.Pointer(name))
 	if C.kcdbdumpsnap(kc.db, name) == 0 {
 	}
 	return
 }
-func (kc *KCDB) Load(filename string) (err os.Error) {
+func (kc *KCDB) Load(filename string) (err error) {
 	name := C.CString(filename)
 	defer C.free(unsafe.Pointer(name))
 	if C.kcdbcopy(kc.db, name) == 0 {
 	return
 }
 
-func (kc *KCDB) BeginTran(hard bool) (err os.Error) {
+func (kc *KCDB) BeginTran(hard bool) (err error) {
 	var chard C.int32_t
 	if hard {
 		chard = 1
 	return
 }
 
-func (kc *KCDB) BeginTranTry(hard bool) (err os.Error) {
+func (kc *KCDB) BeginTranTry(hard bool) (err error) {
 	var chard C.int32_t
 	if hard {
 		chard = 1
 	return
 }
 
-func (kc *KCDB) EndTran(commit bool) (err os.Error) {
+func (kc *KCDB) EndTran(commit bool) (err error) {
 	var ccommit C.int32_t
 	if commit {
 		ccommit = 1
 	return
 }
 
-func (kc *KCDB) Set(key, value []byte) (err os.Error) {
+func (kc *KCDB) Set(key, value []byte) (err error) {
 	ckey := (*C.char)(unsafe.Pointer(&key[0]))
 	cvalue := (*C.char)(unsafe.Pointer(&value[0]))
 	if C.kcdbset(kc.db, ckey, C.size_t(len(key)), cvalue, C.size_t(len(value))) == 0 {
 	return
 }
 
-func (kc *KCDB) Add(key, value []byte) (err os.Error) {
+func (kc *KCDB) Add(key, value []byte) (err error) {
 	ckey := (*C.char)(unsafe.Pointer(&key[0]))
 	cvalue := (*C.char)(unsafe.Pointer(&value[0]))
 	if C.kcdbadd(kc.db, ckey, C.size_t(len(key)), cvalue, C.size_t(len(value))) == 0 {
 	return
 }
 
-func (kc *KCDB) Replace(key, value []byte) (err os.Error) {
+func (kc *KCDB) Replace(key, value []byte) (err error) {
 	ckey := (*C.char)(unsafe.Pointer(&key[0]))
 	cvalue := (*C.char)(unsafe.Pointer(&value[0]))
 	if C.kcdbreplace(kc.db, ckey, C.size_t(len(key)), cvalue, C.size_t(len(value))) == 0 {
 	return
 }
 
-func (kc *KCDB) Append(key, value []byte) (err os.Error) {
+func (kc *KCDB) Append(key, value []byte) (err error) {
 	ckey := (*C.char)(unsafe.Pointer(&key[0]))
 	cvalue := (*C.char)(unsafe.Pointer(&value[0]))
 	if C.kcdbappend(kc.db, ckey, C.size_t(len(key)), cvalue, C.size_t(len(value))) == 0 {
 	return
 }
 
-func (kc *KCDB) Remove(key []byte) (err os.Error) {
+func (kc *KCDB) Remove(key []byte) (err error) {
 	ckey := (*C.char)(unsafe.Pointer(&key[0]))
 	if C.kcdbremove(kc.db, ckey, C.size_t(len(key))) == 0 {
 		err = kc.error()
 	return
 }
 
-func (kc *KCDB) Cas(key, oval, nval []byte) (err os.Error) {
+func (kc *KCDB) Cas(key, oval, nval []byte) (err error) {
 	ckey := (*C.char)(unsafe.Pointer(&key[0]))
 	var coval, cnval *C.char
 	loval, lnval := len(oval), len(nval)
 	return
 }
 
-func (kc *KCDB) IncrInt(key []byte, amount int64) (result int64, err os.Error) {
+func (kc *KCDB) IncrInt(key []byte, amount int64) (result int64, err error) {
 	ckey := (*C.char)(unsafe.Pointer(&key[0]))
-	cresult := C.kcdbincrint(kc.db, ckey, C.size_t(len(key)), C.int64_t(amount))
+	cresult := C.kcdbincrint(kc.db, ckey, C.size_t(len(key)), C.int64_t(amount), 0)
+
 	if cresult == C.INT64_MIN {
 		err = kc.error()
 	} else {
 	return
 }
 
-func (kc *KCDB) IncrDouble(key []byte, amount float64) (err os.Error) {
+func (kc *KCDB) IncrDouble(key []byte, amount float64) (err error) {
 	ckey := (*C.char)(unsafe.Pointer(&key[0]))
-	if C.kcdbincrdouble(kc.db, ckey, C.size_t(len(key)), C.double(amount)) == 0 {
+	if C.kcdbincrdouble(kc.db, ckey, C.size_t(len(key)), C.double(amount), C.double(0.0)) == C.kcnan() {
 		err = kc.error()
 	}
 	return
 }
 
-func (kc *KCDB) Get(key []byte) (value []byte, err os.Error) {
+func (kc *KCDB) Get(key []byte) (value []byte, err error) {
 	ckey := (*C.char)(unsafe.Pointer(&key[0]))
 	var vlen C.size_t
 	cval := C.kcdbget(kc.db, ckey, C.size_t(len(key)), &vlen)
 	return C.GoString(err)
 }
 
-func (kcc *KCCUR) error() os.Error {
-	return os.NewError(kcc.Emsg())
+func (kcc *KCCUR) error() error {
+	return errors.New(kcc.Emsg())
 }
 
 func (kcc *KCCUR) Del() {
 	return
 }
 
-func (kcc *KCCUR) Jump() (err os.Error) {
+func (kcc *KCCUR) Jump() (err error) {
 	if C.kccurjump(kcc.cur) == 0 {
 		err = kcc.error()
 	}
 	return
 }
 
-func (kcc *KCCUR) JumpKey(key []byte) (err os.Error) {
+func (kcc *KCCUR) JumpKey(key []byte) (err error) {
 	ckey := (*C.char)(unsafe.Pointer(&key[0]))
 	if C.kccurjumpkey(kcc.cur, ckey, C.size_t(len(key))) == 0 {
 		err = kcc.error()
 	return
 }
 
-func (kcc *KCCUR) JumpBack() (err os.Error) {
+func (kcc *KCCUR) JumpBack() (err error) {
 	if C.kccurjumpback(kcc.cur) == 0 {
 		err = kcc.error()
 	}
 	return
 }
 
-func (kcc *KCCUR) JumpBackKey(key []byte) (err os.Error) {
+func (kcc *KCCUR) JumpBackKey(key []byte) (err error) {
 	ckey := (*C.char)(unsafe.Pointer(&key[0]))
 	if C.kccurjumpbackkey(kcc.cur, ckey, C.size_t(len(key))) == 0 {
 		err = kcc.error()
 	return
 }
 
-func (kcc *KCCUR) Step() (err os.Error) {
+func (kcc *KCCUR) Step() (err error) {
 	if C.kccurstep(kcc.cur) == 0 {
 		err = kcc.error()
 	}
 	return
 }
 
-func (kcc *KCCUR) StepBack() (err os.Error) {
+func (kcc *KCCUR) StepBack() (err error) {
 	if C.kccurstepback(kcc.cur) == 0 {
 		err = kcc.error()
 	}
 	return
 }
 
-func (kcc *KCCUR) Remove() (err os.Error) {
+func (kcc *KCCUR) Remove() (err error) {
 	if C.kccurremove(kcc.cur) == 0 {
 		err = kcc.error()
 	}
 	return
 }
 
-func (kcc *KCCUR) SetValue(value []byte, advance bool) (err os.Error) {
+func (kcc *KCCUR) SetValue(value []byte, advance bool) (err error) {
 	cvalue := (*C.char)(unsafe.Pointer(&value[0]))
 	var cadvance C.int32_t
 	if advance {
 	return
 }
 
-func (kcc *KCCUR) GetKey(advance bool) (k []byte, err os.Error) {
+func (kcc *KCCUR) GetKey(advance bool) (k []byte, err error) {
 	var ksiz C.size_t
 	var cadvance C.int32_t
 	if advance {
 	return
 }
 
-func (kcc *KCCUR) GetValue(advance bool) (v []byte, err os.Error) {
+func (kcc *KCCUR) GetValue(advance bool) (v []byte, err error) {
 	var vsiz C.size_t
 	var cadvance C.int32_t
 	if advance {
 	return
 }
 
-func (kcc *KCCUR) Get(advance bool) (k, v []byte, err os.Error) {
+func (kcc *KCCUR) Get(advance bool) (k, v []byte, err error) {
 	var ksiz, vsiz C.size_t
 	var vp *C.char
 	var cadvance C.int32_t
 	return
 }
 
-func (kc *KCDB) MatchPrefix(prefix string, max int) (matches [][]byte, err os.Error) {
+func (kc *KCDB) MatchPrefix(prefix string, max int) (matches [][]byte, err error) {
 	cprefix := C.CString(prefix)
 	strarray := make([]*C.char, max)
 	count := C.kcdbmatchprefix(kc.db, cprefix, &strarray[0], C.size_t(max))
 	return
 }
 
-func (kc *KCDB) MatchRegex(regex string, max int) (matches [][]byte, err os.Error) {
+func (kc *KCDB) MatchRegex(regex string, max int) (matches [][]byte, err error) {
 	cregex := C.CString(regex)
 	strarray := make([]*C.char, max)
 	count := C.kcdbmatchregex(kc.db, cregex, &strarray[0], C.size_t(max))
 package cabinet
 
 import (
-	"fmt"
-	"testing"
-	"os"
 	"bytes"
 	"encoding/binary"
+	"fmt"
+	"os"
+	"testing"
 )
 
 var test_db string = "casket.kch"
 
 func newCabinet(t *testing.T, filename string) *KCDB {
 	kc := New()
-	err := kc.Open(filename, KCOWRITER | KCOCREATE )
+	err := kc.Open(filename, KCOWRITER|KCOCREATE)
 	if err != nil {
 		t.Fatalf("Open(): %s", err)
 	}
 	}
 }
 
-
 func TestIncr(t *testing.T) {
 	kc := newCabinet(t, test_db)
 	defer delCabinet(t, kc)
 
 	_, err := kc.IncrInt([]byte("numbers"), 6)
 	if err != nil {
-		t.Error("IncrInt(6): %s", err)
+		t.Error("IncrInt(6):", err)
 	}
 
 	v, err := kc.Get([]byte("numbers"))
 
 	_, err = kc.IncrInt([]byte("numbers"), 6)
 	if err != nil {
-		t.Error("IncrInt(6): %s", err)
+		t.Error("IncrInt(6):", err)
 	}
 
 	v, err = kc.Get([]byte("numbers"))
 
 	seen := make(map[string]bool)
 	keys := kc.Keys()
-	for {
-		k := <-keys
-		if closed(keys) {
-			break
-		}
+	for k := range keys {
 		seen[string(k)] = true
 	}
 	if len(seen) != int(count) {
 
 	seen = make(map[string]bool)
 	values := kc.Values()
-	for {
-		v := <-values
-		if closed(values) {
-			break
-		}
+	for v := range values {
 		seen[string(v)] = true
 	}
 	if len(seen) != int(count) {
 
 	seeni := make(map[string]string)
 	items := kc.Items()
-	for {
-		i := <-items
-		if closed(items) {
-			break
-		}
+	for i := range items {
 		seeni[string(i.Key)] = string(i.Value)
 	}
 	if len(seen) != int(count) {