You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Original bug ID: 1925 Reporter: administrator Status: closed Resolution: fixed Priority: normal Severity: feature Category: ~DO NOT USE (was: OCaml general)
Bug description
Full_Name: Aleksey Nogin
Version: 3.07+2
OS: Red Hat Linux
Submission from: charter-182-203.caltech.edu (131.215.182.203)
Compare the following on 3.07+2 and 3.06:
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 ancored_entry = { ancor : 'a; index: int };;
type 'a ancored_entry = { ancor : 'a; index : int; }
let memo = Weak.create 34;;
val memo : '_a Weak.t =
mojave2:~> ocaml
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 = <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 =
test (make []);;
: '_a list = []
test (make [1]);;
: int list = [1]
Basically, in 3.07+2 [] 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).
The text was updated successfully, but these errors were encountered:
On Wednesday, November 12, 2003, at 10:13 AM, Aleksey Nogin wrote:
When trying to switch from 3.06 to 3.07+2 I've noticed the following
difference in how the Weak module works:
[
In 3.06, an empty list [] does not disappear from a weak array;
in 3.07+2 it disappears immediately
]
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?
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).
Yes, but. In 3.06, [] will never be removed from the weak array, and
you will keep your helper data forever.
The source your the problem is that [] is not allocated in the heap.
It is represented by an integer value. Hence, there is no sharing
between various occurrences of [] in your data and the notion of a
weak pointer to [] does not make sense.
If you really want to make sure that you are manipulating pointers,
you should use a record or a list ref.
Original bug ID: 1925
Reporter: administrator
Status: closed
Resolution: fixed
Priority: normal
Severity: feature
Category: ~DO NOT USE (was: OCaml general)
Bug description
Full_Name: Aleksey Nogin
Version: 3.07+2
OS: Red Hat Linux
Submission from: charter-182-203.caltech.edu (131.215.182.203)
Compare the following on 3.07+2 and 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 =
val make : '_a -> '_a anchored_entry =
let test ae =
data
| None -> invalid_arg "Entry went away";;
val test : '_a anchored_entry -> '_a =
test (make []);;
Exception: Invalid_argument "Entry went away".
test (make [1]);;
type 'a ancored_entry = { ancor : 'a; index: int };;
type 'a ancored_entry = { ancor : 'a; index : int; }
let memo = Weak.create 34;;
val memo : '_a Weak.t =
mojave2:~> ocaml
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 test ae =
data
| None -> invalid_arg "Entry went away";;
val test : '_a anchored_entry -> '_a =
test (make []);;
test (make [1]);;
Basically, in 3.07+2 [] 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).
The text was updated successfully, but these errors were encountered: