;;;; A string returned from C is copied into the context allocator at the ;;;; boundary, so it stays what it was after C reuses its buffer. ;;;; ;;;; cret/count answers the same static buffer every call: the first answer ;;;; still reads "count 1" after the second call has overwritten that buffer. ;;;; cret/after-slash answers a pointer into its own argument, which is the ;;;; wrapper's temporary copy — short enough for the stack buffer and, in the ;;;; second call, long enough to be on the heap. cret/nothing answers NULL, ;;;; which is the empty string. The last case copies into a named arena, and ;;;; the arena's free-all is what releases it. (import cret "pkgs/cret") (defn main [] i32 (let [a (cret/count 1) b (cret/count 2)] (println a) (println b)) (println (cret/after-slash "assets/brush.png")) (let [path (vec-new u8)] (append (addr path) (bytes-view "dir/")) (dotimes [i 300] (push path \x)) (let [tail (cret/after-slash (str (slice path))) long-name (str (slice path 4))] (println (length tail)) (println (= tail long-name)))) (println (length (cret/nothing))) (let [ar (arena-new 4096) before (alloc-live-blocks ar) s (with-allocator ar (cret/count 3))] (println s) (println (- (alloc-live-blocks ar) before)) (arena-destroy ar)) 0)