Skip to content

Commit 09913fb

Browse files
committed
fix unused field errors
1 parent da59045 commit 09913fb

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

cmph/lib/cmph.ml

+17-15
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ module Bindings = struct
1717
structure "cmph_io_adapter_t"
1818

1919
let _data = field cmph_io_adapter_t "data" (ptr void)
20-
2120
let nkeys = field cmph_io_adapter_t "nkeys" uint32_t
2221

2322
let read =
@@ -68,9 +67,7 @@ module Bindings = struct
6867
foreign "cmph_search" (cmph_t @-> string @-> int @-> returning int)
6968

7069
let cmph_destroy = foreign "cmph_destroy" (cmph_t @-> returning void)
71-
7270
let cmph_pack = foreign "cmph_pack" (cmph_t @-> ocaml_bytes @-> returning void)
73-
7471
let cmph_packed_size = foreign "cmph_packed_size" (cmph_t @-> returning int)
7572

7673
let cmph_search_packed =
@@ -81,11 +78,12 @@ exception Error of [ `Empty | `Hash_new_failed of string | `Parameter_range | `F
8178
[@@deriving sexp]
8279

8380
module KeySet = struct
81+
(* Unused functions must be retained to prevent garbage collection. *)
8482
type t = {
8583
length : int;
86-
read : unit ptr -> char ptr ptr -> Unsigned.uint32 ptr -> int;
87-
dispose : unit ptr -> char ptr -> Unsigned.uint32 -> unit;
88-
rewind : unit ptr -> unit;
84+
_read : unit ptr -> char ptr ptr -> Unsigned.uint32 ptr -> int;
85+
_dispose : unit ptr -> char ptr -> Unsigned.uint32 -> unit;
86+
_rewind : unit ptr -> unit;
8987
adapter : (Bindings.cmph_io_adapter_t, [ `Struct ]) structured ptr;
9088
}
9189

@@ -121,12 +119,17 @@ module KeySet = struct
121119
setf adapter Bindings.read read;
122120
setf adapter Bindings.dispose dispose;
123121
setf adapter Bindings.rewind rewind;
124-
{ length = Array.length keys; read; dispose; rewind; adapter = addr adapter }
122+
{
123+
length = Array.length keys;
124+
_read = read;
125+
_dispose = dispose;
126+
_rewind = rewind;
127+
adapter = addr adapter;
128+
}
125129
end
126130

127131
module Config = struct
128132
type hash = [ `Jenkins | `Count ] [@@deriving sexp]
129-
130133
type chd_config = { keys_per_bucket : int; keys_per_bin : int } [@@deriving sexp]
131134

132135
type algo =
@@ -143,7 +146,7 @@ module Config = struct
143146

144147
type t = {
145148
config : Bindings.cmph_config_t;
146-
keyset : KeySet.t;
149+
_keyset : KeySet.t;
147150
mutable freed : bool;
148151
}
149152

@@ -166,7 +169,6 @@ module Config = struct
166169
| `Chd _ -> "Chd"
167170

168171
let default_chd = `Chd { keys_per_bucket = 4; keys_per_bin = 1 }
169-
170172
let default_chd_ph = `Chd_ph { keys_per_bucket = 4; keys_per_bin = 1 }
171173

172174
let valid_algo algo keyset =
@@ -193,19 +195,19 @@ module Config = struct
193195
Bindings.cmph_config_set_graphsize config 0.90;
194196
Bindings.cmph_config_set_algo config (algo_value algo);
195197
Bindings.cmph_config_set_verbosity config (if verbose then 1 else 0);
196-
( match algo with
198+
(match algo with
197199
| `Chd c | `Chd_ph c ->
198200
Bindings.cmph_config_set_b config c.keys_per_bucket;
199201
Bindings.cmph_config_set_keys_per_bin config c.keys_per_bin
200-
| _ -> () );
201-
{ config; keyset; freed = false }
202+
| _ -> ());
203+
{ config; _keyset = keyset; freed = false }
202204

203205
let assert_valid { freed; _ } = if freed then raise @@ Error `Freed
204206

205207
let destroy c =
206208
if not c.freed then (
207209
Bindings.cmph_config_destroy c.config;
208-
c.freed <- true )
210+
c.freed <- true)
209211

210212
let with_config ?verbose ?algo ?seed keyset f =
211213
let c = create ?verbose ?algo ?seed keyset in
@@ -257,7 +259,7 @@ module Hash = struct
257259
Config.destroy c.config;
258260
if not c.freed then (
259261
Bindings.cmph_destroy c.hash;
260-
c.freed <- true )
262+
c.freed <- true)
261263

262264
let with_hash c f =
263265
let h = of_config c in

0 commit comments

Comments
 (0)