summary refs log tree commit diff stats
path: root/tests/system/talloc.nim
blob: 18396041d05e4ec8b36bbeecae36f8de7a3b9647 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
var x: ptr int

x = cast[ptr int](alloc(7))
assert x != nil
x = cast[ptr int](x.realloc(2))
assert x != nil
x.dealloc()

x = createU(int, 3)
assert x != nil
x.dealloc()

x = create(int, 4)
assert cast[ptr array[4, int]](x)[0] == 0
assert cast[ptr array[4, int]](x)[1] == 0
assert cast[ptr array[4, int]](x)[2] == 0
assert cast[ptr array[4, int]](x)[3] == 0

x = x.resize(4)
assert x != nil
x.dealloc()

x = cast[ptr int](allocShared(100))
assert x != nil
deallocShared(x)

x = createSharedU(int, 3)
assert x != nil
x.deallocShared()

x = createShared(int, 3)
assert x != nil
assert cast[ptr array[3, int]](x)[0] == 0
assert cast[ptr array[3, int]](x)[1] == 0
assert cast[ptr array[3, int]](x)[2] == 0

assert x != nil
x = cast[ptr int](x.resizeShared(2))
assert x != nil
x.deallocShared()

x = create(int, 10)
assert x != nil
x = x.resize(12)
assert x != nil
x.dealloc()

x = createShared(int, 1)
assert x != nil
x = x.resizeShared(1)
assert x != nil
x.deallocShared()

x = cast[ptr int](alloc0(125 shl 23))
dealloc(x)
x = cast[ptr int](alloc0(126 shl 23))
dealloc(x)