Mercurial > projects > ldc
comparison tests/mini/aa7.d @ 490:f8c979770af3
Fixed a critical bug in the runtime, where _d_allocmemoryT would mark
the memory block as having pointers (for scanning) opposite of what it
should. So pointers would not be seen and freed. Should fix a bunch of
regressions with AAs.
author | Tomas Lindquist Olsen <tomas.l.olsen@gmail.com> |
---|---|
date | Sun, 10 Aug 2008 17:28:01 +0200 |
parents | a34078905d01 |
children |
comparison
equal
deleted
inserted
replaced
489:822774a94750 | 490:f8c979770af3 |
---|---|
1 // adapted from dstress.run.a.associative_array_19_A to catch regressions early | 1 // adapted from dstress.run.a.associative_array_19_<n> to catch regressions early |
2 | 2 |
3 module mini.aa7; | 3 module mini.aa7; |
4 | 4 |
5 extern (C) int printf(char*, ...); | 5 extern (C) int printf(char*, ...); |
6 | |
7 extern (C) void gc_collect(); | 6 extern (C) void gc_collect(); |
8 | 7 |
9 union Key{ | |
10 char x; | |
11 } | |
12 | |
13 class Payload { | |
14 this(Key value) { | |
15 value.x += 1; | |
16 _value = value; | |
17 } | |
18 | |
19 Key value() { | |
20 return _value; | |
21 } | |
22 | |
23 Key _value; | |
24 } | |
25 | 8 |
26 int main(){ | 9 int main(){ |
27 Payload[Key] aa; | 10 char*[char] aa; |
28 | 11 |
29 Key[] allKeys; | 12 char key = 'a'; |
30 static Key a = { 'a' }; | 13 aa[key] = &key; |
31 static Key b = { 'b' }; | |
32 static Key c = { 'c' }; | |
33 allKeys ~= a; | |
34 allKeys ~= b; | |
35 allKeys ~= c; | |
36 | |
37 foreach(Key key; allKeys) { | |
38 aa[key] = new Payload(key); | |
39 } | |
40 | |
41 int i = 0; | |
42 foreach(Key key; allKeys) { | |
43 printf("1st #%d\n", i++); | |
44 assert(key in aa); | |
45 } | |
46 | |
47 gc_collect(); | 14 gc_collect(); |
48 | 15 assert(aa[key] == &key); |
49 i = 0; | 16 assert(key in aa); |
50 foreach(Key key; allKeys) { | |
51 printf("2nd #%d\n", i++); | |
52 assert(key in aa); | |
53 } | |
54 | 17 |
55 return 0; | 18 return 0; |
56 } | 19 } |
57 | 20 |