This is the mail archive of the
kawa@sourceware.org
mailing list for the Kawa project.
Re: rnrs hashtables
On Apr 10, 2011, at 10:57 PM, Per Bothner wrote:
I checked in a fix.
Thank you, sir. Next, I have found that I can't call hashtable-entries
on a table with more than fifteen elements:
$ cat /tmp/hashtable-test.scm
(import (rnrs hashtables))
(define numbers (make-hashtable string-hash eqv?))
(do ((i 0 (+ i 1)))
((= i 50))
(let ((s (number->string i)))
(hashtable-set! numbers s i)
(let-values (((strs nums) (hashtable-entries numbers)))
(display i) (display ": ")
(display (cons strs nums)) (newline))))
$ java kawa.repl -f /tmp/hashtable-test.scm
0: (#(0) . #(0))
1: (#(1 0) . #(1 0))
2: (#(2 1 0) . #(2 1 0))
3: (#(3 2 1 0) . #(3 2 1 0))
4: (#(4 3 2 1 0) . #(4 3 2 1 0))
5: (#(5 4 3 2 1 0) . #(5 4 3 2 1 0))
6: (#(6 5 4 3 2 1 0) . #(6 5 4 3 2 1 0))
7: (#(7 6 5 4 3 2 1 0) . #(7 6 5 4 3 2 1 0))
8: (#(8 7 6 5 4 3 2 1 0) . #(8 7 6 5 4 3 2 1 0))
9: (#(9 8 7 6 5 4 3 2 1 0) . #(9 8 7 6 5 4 3 2 1 0))
10: (#(9 8 7 6 5 4 3 2 1 0 10) . #(9 8 7 6 5 4 3 2 1 0 10))
11: (#(9 8 7 6 5 4 3 2 1 0 11 10) . #(9 8 7 6 5 4 3 2 1 0 11 10))
12: (#(9 8 7 6 5 4 3 2 1 0 12 11 10) . #(9 8 7 6 5 4 3 2 1 0 12 11 10))
13: (#(9 8 7 6 5 4 3 2 1 0 13 12 11 10) . #(9 8 7 6 5 4 3 2 1 0 13 12
11 10))
14: (#(9 8 7 6 5 4 3 2 1 0 14 13 12 11 10)
. #(9 8 7 6 5 4 3 2 1 0 14 13 12 11 10))
java.lang.ArrayIndexOutOfBoundsException
at java.lang.System.arraycopy(Native Method)
at gnu.lists.FVector.shift(FVector.java:94)
at gnu.lists.SimpleVector.add(SimpleVector.java:244)
at gnu.lists.SimpleVector.add(SimpleVector.java:222)
at kawa.lib.kawa.hashtable$HashTable.entriesVectorPair(hashtable.scm:
59)
at kawa.lib.rnrs.hashtables.hashtableEntries(hashtables.scm:84)
at atInteractiveLevel$3$frame.lambda1(hashtable-test.scm:9)
at atInteractiveLevel$3.apply0(hashtable-test.scm)
at gnu.expr.ModuleMethod.apply0(ModuleMethod.java:186)
at
kawa.standard.call_with_values.callWithValues(call_with_values.java:13)
at atInteractiveLevel$3.run(hashtable-test.scm:9)
at gnu.expr.ModuleExp.evalModule2(ModuleExp.java:286)
at gnu.expr.ModuleExp.evalModule(ModuleExp.java:187)
at kawa.Shell.run(Shell.java:281)
at kawa.Shell.runFile(Shell.java:490)
at kawa.Shell.runFileOrClass(Shell.java:428)
at kawa.repl.processArgs(repl.java:216)
at kawa.repl.main(repl.java:831)
It is apparently a problem with FVector or SimpleVector. I haven't
figured out
the actual bug, but SimpleVector#add(int,E) strikes me as a little
suspicious:
public void add(int index, E o)
{
checkCanWrite();
int newSize = size + 1;
size = newSize; <---- This
is the same
int length = getBufferLength();
if (newSize > length)
setBufferLength(length < 16 ? 16 : 2 * length);
this.size = newSize; <---- as
this.
if (size != index)
shift(index, index + 1, size - index);
set(index, o);
}
A copy/paste error, perhaps? Here's a test case that cuts out the
hashtable stuff:
(define v ::vector (gnu.lists.FVector))
(do ((i 1 (+ i 1)))
((= i 50))
(display "Adding ")
(display i)
(display "...") (newline)
(v:add i))
Adding 1...
Adding 2...
Adding 3...
Adding 4...
Adding 5...
Adding 6...
Adding 7...
Adding 8...
Adding 9...
Adding 10...
Adding 11...
Adding 12...
Adding 13...
Adding 14...
Adding 15...
Adding 16...
java.lang.ArrayIndexOutOfBoundsException
at java.lang.System.arraycopy(Native Method)
at gnu.lists.FVector.shift(FVector.java:94)
at gnu.lists.SimpleVector.add(SimpleVector.java:244)
at gnu.lists.SimpleVector.add(SimpleVector.java:222)
at atInteractiveLevel$2.run(vector-test.scm:8)
at gnu.expr.ModuleExp.evalModule2(ModuleExp.java:286)
at gnu.expr.ModuleExp.evalModule(ModuleExp.java:187)
at kawa.Shell.run(Shell.java:281)
at kawa.Shell.runFile(Shell.java:490)
at kawa.Shell.runFileOrClass(Shell.java:428)
at kawa.repl.processArgs(repl.java:216)
at kawa.repl.main(repl.java:831)
--
Jamison Hope
The PTR Group
www.theptrgroup.com