Permalink
Browse files

[fix] database: Fixed problem with signed ints in Encode_light.

  • Loading branch information...
1 parent a9a6c3f commit 1db6f11689c4714d5fdb9146d598c41582aee9e7 @nrs135 nrs135 committed with Louis Gesbert Jun 24, 2011
Showing with 19 additions and 5 deletions.
  1. +5 −0 database/badop.ml
  2. +14 −5 database/light/encode_light.ml
View
@@ -230,6 +230,11 @@ module Aux : sig
('which, 'revision1) generic_read_op ->
('which, 'revision2) generic_read_op Cps.t
+ val map_read_list_op:
+ revision:('revision1 -> 'revision2 Cps.t) ->
+ ('which, 'revision1) generic_read_op list ->
+ ('which, 'revision2) generic_read_op list Cps.t
+
val map_write_op:
transaction:('transaction1 -> 'transaction2 Cps.t) ->
revision:('revision1 -> 'revision2 Cps.t) ->
@@ -109,9 +109,9 @@ let tstf f = f = dif (eif f) 0
*)
let put_len c1 c2 c3 c4 i =
- if i <= 0xff then sprintf "%c%s" c1 (ei8 i)
- else if i <= 0xffff then sprintf "%c%s" c2 (ei16 i)
- else if i <= 0xffffffff then sprintf "%c%s" c3 (ei32 i)
+ if i >= 0 && i <= 255 then sprintf "%c%s" c1 (ei8 i)
+ else if i >= 0 && i <= 65535 then sprintf "%c%s" c2 (ei16 i)
+ else if i >= 0 && i <= 4294967295 then sprintf "%c%s" c3 (ei32 i)
else sprintf "%c%s" c4 (ei64 i)
let rec encode_key = function
@@ -157,6 +157,7 @@ let rec decode_key s i =
| _ -> assert false
(*
+let km1 = Keys.IntKey (-1)
let k1 = Keys.IntKey 123
let k2 = Keys.IntKey 0x100
let k3 = Keys.IntKey 0x10000
@@ -170,7 +171,7 @@ let k10 = Keys.VariableKey 0x100000000
let k11 = Keys.ListKey (Array.of_list [k1;k2;k3;k4;k5;k6;k7;k8;k9;k10])
let k12 = Keys.ListKey (Array.of_list [k11;k11])
let tstk k = k = snd (decode_key (encode_key k) 0)
-let allk = [k1;k2;k3;k4;k5;k6;k7;k8;k9;k10;k11;k12]
+let allk = [km1;k1;k2;k3;k4;k5;k6;k7;k8;k9;k10;k11;k12]
let good = List.for_all tstk allk
*)
@@ -265,7 +266,15 @@ let alld = [d1;d2;d3;d4;d5]
let tstd d = d = snd (decode_datas (encode_datas d) 0)
let good = List.for_all tstd alld
let db = Dbm.opendbm ("/home/norman/.mlstate/"^(Filename.basename Sys.argv.(0))^"/db_light") [Dbm.Dbm_rdwr] 0O664;;
-Dbm.iter (fun k d -> print_endline (String.escaped (Printf.sprintf "%s -> %s" k d))) db;;
+let db = Dbm.opendbm "/tmp/opadb1" [Dbm.Dbm_rdwr] 0O664;;
+let dbl = ref [];;
+Dbm.iter (fun k d ->
+ (match k with
+ | "version" -> ()
+ | "timestamp" -> ()
+ | _ -> dbl := (Path.to_string (snd (Encode_light.decode_path k 0)),
+ snd (Encode_light.decode_datas d 0))::!dbl);
+ print_endline (String.escaped (Printf.sprintf "%s -> %s" k d))) db;;
Dbm.close db;;
*)

0 comments on commit 1db6f11

Please sign in to comment.