Commits

w...@styx.org  committed 7029f46 Merge

merge

  • Participants
  • Parent commits 1ffef34, 661c070
  • Branches release

Comments (0)

Files changed (2)

 	return
 }
 
-func (kc *KCDB) IncrInt(key []byte, amount int64) (err os.Error) {
+func (kc *KCDB) IncrInt(key []byte, amount int64) (result int64, err os.Error) {
 	ckey := (*C.char)(unsafe.Pointer(&key[0]))
-	if C.kcdbincrint(kc.db, ckey, C.size_t(len(key)), C.int64_t(amount)) == 0 {
+	cresult := C.kcdbincrint(kc.db, ckey, C.size_t(len(key)), C.int64_t(amount))
+	if cresult == C.INT64_MIN {
 		err = kc.error()
+	} else {
+		result = int64(cresult)
 	}
 	return
 }
 	out = make(chan []byte)
 	go func() {
 		cur := kc.Cursor()
-		defer func() {
-			cur.Del()
-			close(out)
-		}()
 		for {
 			k, err := cur.GetKey(true)
 			if err != nil {
 			}
 			out <- k
 		}
+		cur.Del()
+		close(out)
 	}()
 	return
 }
 	out = make(chan []byte)
 	go func() {
 		cur := kc.Cursor()
-		defer func() {
-			cur.Del()
-			close(out)
-		}()
 		for {
 			v, err := cur.GetValue(true)
 			if err != nil {
 			}
 			out <- v
 		}
+		cur.Del()
+		close(out)
 	}()
 	return
 }
 	out = make(chan *Item)
 	go func() {
 		cur := kc.Cursor()
-		defer func() {
-			cur.Del()
-			close(out)
-		}()
 		for {
 			k, v, err := cur.Get(true)
 			if err != nil {
 			}
 			out <- &Item{k, v}
 		}
+		cur.Del()
+		close(out)
 	}()
 	return
 }
 
 func (kc *KCDB) MatchPrefix(prefix string, max int) (matches [][]byte, err os.Error) {
 	cprefix := C.CString(prefix)
-	defer C.free(unsafe.Pointer(cprefix))
 	strarray := make([]*C.char, max)
 	count := C.kcdbmatchprefix(kc.db, cprefix, &strarray[0], C.size_t(max))
 	if count == -1 {
 			C.kcfree(unsafe.Pointer(strarray[i]))
 		}
 	}
+	C.free(unsafe.Pointer(cprefix))
 	return
 }
 
 func (kc *KCDB) MatchRegex(regex string, max int) (matches [][]byte, err os.Error) {
 	cregex := C.CString(regex)
-	defer C.free(unsafe.Pointer(cregex))
 	strarray := make([]*C.char, max)
 	count := C.kcdbmatchregex(kc.db, cregex, &strarray[0], C.size_t(max))
 	if count == -1 {
 			C.kcfree(unsafe.Pointer(strarray[i]))
 		}
 	}
+	C.free(unsafe.Pointer(cregex))
 	return
 }

File cabinet_test.go

 	kc := newCabinet(t, test_db)
 	defer delCabinet(t, kc)
 
-	err := kc.IncrInt([]byte("numbers"), 6)
+	_, err := kc.IncrInt([]byte("numbers"), 6)
 	if err != nil {
 		t.Error("IncrInt(6): %s", err)
 	}
 		t.Errorf("IncrInt(6): expected 6 got %d", n)
 	}
 
-	err = kc.IncrInt([]byte("numbers"), 6)
+	_, err = kc.IncrInt([]byte("numbers"), 6)
 	if err != nil {
 		t.Error("IncrInt(6): %s", err)
 	}