From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id KAA11054; Wed, 12 Nov 2003 10:14:43 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id KAA11039 for ; Wed, 12 Nov 2003 10:14:42 +0100 (MET) Received: from dell.nogin.org (charter-182-203.caltech.edu [131.215.182.203]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id hAC9Ea103949 for ; Wed, 12 Nov 2003 10:14:36 +0100 (MET) Received: from nogin.org (localhost.localdomain [127.0.0.1]) by dell.nogin.org (8.12.10/8.12.9) with ESMTP id hAC9DmCg001944 for ; Wed, 12 Nov 2003 01:13:49 -0800 Message-ID: <3FB1F9CC.8070607@nogin.org> Date: Wed, 12 Nov 2003 01:13:48 -0800 From: Aleksey Nogin User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6a) Gecko/20031023 X-Accept-Language: ru, en-us, en MIME-Version: 1.0 To: caml-list@inria.fr Subject: [Caml-list] 3.07+2 - Constants immediatelly disappear from the Weak array? Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Loop: caml-list@inria.fr X-Spam: no; 0.00; 3.07:01 constants:01 3.06:01 3.07:01 memo:01 val:01 memo:01 abstr:01 incr:01 val:01 3.06:01 abstr:01 incr:01 disappears:01 bug:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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 = # 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 = # 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 = # 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 = # 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 = # 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 = # 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