[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-janitors] #1293: eq?-hash tables calculcate different value
From: |
Chicken Trac |
Subject: |
Re: [Chicken-janitors] #1293: eq?-hash tables calculcate different value for objects after they're mutated and lose locatives after GC |
Date: |
Tue, 23 Aug 2016 19:19:21 -0000 |
#1293: eq?-hash tables calculcate different value for objects after they're
mutated and lose locatives after GC
-----------------------------+---------------------------------------------
Reporter: sjamaan | Owner:
Type: defect | Status: new
Priority: critical | Milestone: 4.12.0
Component: core libraries | Version: 4.10.x
Resolution: | Keywords: srfi-69, hash tables, locatives
-----------------------------+---------------------------------------------
Description changed by sjamaan:
Old description:
> As [[http://paste.call-
> cc.org/paste?id=982e393227789ab1a6c471ada66e729eb28f83b8|pointed out by
> John Croisant]]:
>
> {{{#!scm
>
> ;; Even though the filler slots are not used, if you remove any of
> ;; them, the hash of the instance will change after GC, causing the
> ;; hash table lookup to fail.
>
> (use srfi-69 lolevel)
>
> (define table (make-hash-table test: eq? hash: eq?-hash))
>
> (define-record-type box
> (make-box contents)
> box?
> ;; Remove or comment out any of the next three lines:
> (filler1 box-filler1)
> (filler2 box-filler2)
> (filler3 box-filler3)
> (contents box-contents))
>
> (define my-box (make-box (make-locative "foo")))
>
> (hash-table-set! table my-box #t)
>
> (printf "before gc, hash table contains ~S? ~S~N"
> my-box
> (hash-table-exists? table my-box))
>
> (gc)
>
> (printf "after gc, hash table contains ~S? ~S~N"
> my-box
> (hash-table-exists? table my-box))
>
> (printf "hash table as alist: ~S~N"
> (hash-table->alist table))
> }}}
New description:
If you mutate a pair, it's still `eq?` to itself, but the `hash-by-
identity` / `eq?-hash` doesn't calculate the same hash anymore, which
means the hash table cannot find the key, unless the randomization factor
happens to be such that it finds the same bucket, of course, but that's
highly unlikely for simple cases like the one below:
{{{
#;1> (use srfi-69)
; loading /home/sjamaan/chickens/4.11.0/lib/chicken/8/srfi-69.import.so
...
; loading library srfi-69 ...
#;2> (define x (cons 1 2))
#;3> (hash-by-identity x)
380849329
#;4> (set-car! x 3)
#;5> (hash-by-identity x)
380718257
#;6> (= #3 #5)
#f
#;7>
}}}
Originally [[http://paste.call-
cc.org/paste?id=982e393227789ab1a6c471ada66e729eb28f83b8|pointed out by
John Croisant]]:
{{{#!scm
;; Even though the filler slots are not used, if you remove any of
;; them, the hash of the instance will change after GC, causing the
;; hash table lookup to fail.
(use srfi-69 lolevel)
(define table (make-hash-table test: eq? hash: eq?-hash))
(define-record-type box
(make-box contents)
box?
;; Remove or comment out any of the next three lines:
(filler1 box-filler1)
(filler2 box-filler2)
(filler3 box-filler3)
(contents box-contents))
(define my-box (make-box (make-locative "foo")))
(hash-table-set! table my-box #t)
(printf "before gc, hash table contains ~S? ~S~N"
my-box
(hash-table-exists? table my-box))
(gc)
(printf "after gc, hash table contains ~S? ~S~N"
my-box
(hash-table-exists? table my-box))
(printf "hash table as alist: ~S~N"
(hash-table->alist table))
}}}
--
--
Ticket URL: <http://bugs.call-cc.org/ticket/1293#comment:4>
CHICKEN Scheme <https://www.call-cc.org/>
CHICKEN Scheme is a compiler for the Scheme programming language.
- Re: [Chicken-janitors] #1293: eq?-hash tables calculcate different value for objects after they're mutated and lose locatives after GC,
Chicken Trac <=
- Re: [Chicken-janitors] #1293: eq?-hash tables calculcate different value for objects after they're mutated and lose locatives after GC, Chicken Trac, 2016/08/23
- Re: [Chicken-janitors] #1293: eq?-hash tables calculcate different value for objects after they're mutated and lose locatives after GC, Chicken Trac, 2016/08/23
- Re: [Chicken-janitors] #1293: eq?-hash tables calculcate different value for objects after they're mutated and lose locatives after GC, Chicken Trac, 2016/08/23
- Re: [Chicken-janitors] #1293: eq?-hash tables calculcate different value for objects after they're mutated and lose locatives after GC, Chicken Trac, 2016/08/23
- Re: [Chicken-janitors] #1293: eq?-hash tables calculcate different value for objects after they're mutated and lose locatives after GC, Chicken Trac, 2016/08/25