-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrc.cicili
More file actions
63 lines (51 loc) · 1.77 KB
/
Copy pathrc.cicili
File metadata and controls
63 lines (51 loc) · 1.77 KB
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
58
59
60
61
62
63
;;; test Cicili std rc
(source "rc.c"
(make :std #t
:compile #t :link ("-lrc.o" "-o" "rc_test"))
(decl-array int)
(impl-array int)
(decl-rc array_int)
(impl-rc array_int)
(main
(letin ((rc01 (new rc array (cast (const int []) '{ 1 2 3 4 5 })))
) ; decls
(let_rc (arr_ptr rc01)
(printf "1. rc01 arr len: %zu\n" (len_array (cof arr_ptr))))
(printf "2. rc01 arr len: %zu\n"
(letn_rc (arr_ptr rc01 -1)
(len_array (cof arr_ptr))))
;; could not take because of counter is 2
(letin ((cl01 (clone_rc rc01)))
(take_rc (arr cl01)
(printf "3. rc01 arr len: %zu\n" (len_array arr))))
(taken_rc (arr rc01
(printf "4. default value is strict\n"))
(printf "4. rc01 arr len: %zu\n" (len_array arr)))
(format #t "Done\n")
) ; letin
)) ; rc.c
;; sbcl --script cicili.lisp --syslog ./test/std/rc.cicili
;; ./test/std/rc_test
;; NEW ARR: array_int 0x7ff585f06080 5 of 5
;; NEW RC: 0x7ff585f05f60
;; 1. rc01 arr len: 5
;; 2. rc01 arr len: 5
;; CLONE RC: 0x7ff585f05f60, count 2
;; FREE RC: 0x7ff585f05f60
;; FREE RC COUNT: 2
;; FREE RC: 0x0
;; 4. default value is strict
;; 4. rc01 arr len: 5
;; FREE ARR: 0x7ff585f06080
;; FREE RC: 0x0
;; Done
;; FREE RC: 0x0
;; There is no "3." line and that is the test: cl01 is a live clone, so the
;; count is 2 and take_rc declines -- a shared payload belongs to the other
;; owner too. The FREE RC COUNT: 2 above it is that clone going away.
;;
;; No FREE CELL / NEW RC CTX lines any more either. An rc is no longer a cell
;; over a context struct, it is a cell's ptr with a count beside it, so there is
;; one allocation to trace instead of three.
;;
;; leaks --atExit -- ./rc_test => 0 leaks for 0 total leaked bytes