Browse thread
[Caml-list] 3.07+2 - Constants immediatelly disappear from the Weak array?
- Aleksey Nogin
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Aleksey Nogin <aleksey@n...> |
| Subject: | [Caml-list] 3.07+2 - Constants immediatelly disappear from the Weak array? |
When trying to switch from 3.06 to 3.07+2 I've noticed the following
difference in how the Weak module works:
----
Objective Caml version 3.07+2
# type 'a anchored_entry = { anchor : 'a; index: int };;
type 'a anchored_entry = { anchor : 'a; index : int; }
# let memo = Weak.create 34;;
val memo : '_a Weak.t = <abstr>
# let make =
let count = ref (-1) in
fun data ->
incr count;
Weak.set memo !count (Some data);
{ anchor = data; index = !count };;
val make : '_a -> '_a anchored_entry = <fun>
# let test ae =
match Weak.get memo ae.index with
Some data -> if ae.anchor != data then invalid_arg "Got a copy"
else data
| None -> invalid_arg "Entry went away";;
val test : '_a anchored_entry -> '_a = <fun>
# test (make []);;
Exception: Invalid_argument "Entry went away".
# test (make [1]);;
- : int list = [1]
----
Objective Caml version 3.06
# type 'a anchored_entry = { anchor : 'a; index: int };;
type 'a anchored_entry = { anchor : 'a; index : int; }
# let memo = Weak.create 34;;
val memo : '_a Weak.t = <abstr>
# let make =
let count = ref (-1) in
fun data ->
incr count;
Weak.set memo !count (Some data);
{ anchor = data; index = !count };;
val make : '_a -> '_a anchored_entry = <fun>
# let test ae =
match Weak.get memo ae.index with
Some data -> if ae.anchor != data then invalid_arg "Got a copy"
else data
| None -> invalid_arg "Entry went away";;
val test : '_a anchored_entry -> '_a = <fun>
# test (make []);;
- : '_a list = []
# test (make [1]);;
- : int list = [1]
----
Basically, in 3.07+2, the empty list disappears from the weak array as
soon as it is added into it. Is this a bug or a feature?
The old behavior is useful because it allows to assume that while a
value is referenced somewhere, Weak.get will always return Some. This
allowed using Weak.get as an indicator of whether it was OK to discard
some "helper" data (which should be only discarded after the primary
data is no longer in use).
I've reported this to http://caml.inria.fr/bin/caml-bugs - see #1925
--
Aleksey Nogin
Home Page: http://nogin.org/
E-Mail: nogin@cs.caltech.edu (office), aleksey@nogin.org (personal)
Office: Jorgensen 70, tel: (626) 395-2907
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners