[gambit-list] output ports created with ##open-predefined not being garbage collected
santana at mailbox.org
santana at mailbox.org
Sat Apr 4 22:49:21 EDT 2020
Was fiddling with gambit's c-ffi and noticed that wills I attached to ports made with ##open-predefined weren't executing so I wrote some test code, if there's something wrong with my code please let me know.
# cat fdes.scm
(c-declare #<<c-declare-end
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
c-declare-end
)
(define-macro (c-macro var)
`(define ,var
((c-lambda () int ,(string-append "___return(" (symbol->string var) ");")))))
;; posix open flags
(c-macro O_RDONLY)
(c-macro O_WRONLY)
(c-macro O_RDWR)
(c-macro O_CREAT)
;; filename flags mode -> fdes | -1
(define posix-open (c-lambda (nonnull-char-string int int) int "open"))
;; fdes -> 0 | -1
(define posix-close (c-lambda (int) int "close"))
(define in 1)
(define out 2)
(define inout 3)
;;;
;;; The will only executes if direction is in
(define (test-posix-open filename direction)
(let* ((fd (case direction
((1) (posix-open filename (bitwise-ior O_RDONLY O_CREAT) #o755))
((2) (posix-open filename (bitwise-ior O_WRONLY O_CREAT) #o755))
((3) (posix-open filename (bitwise-ior O_RDWR O_CREAT) #o755))))
(port (##open-predefined direction filename fd)))
(println "fd: " fd " port: " port)
(make-will port (lambda (p) (println "[WILL] closing port " p) (posix-close fd))))
(##gc))
;;; when run with direction other than in this eats up all my ram
(define (test-loop filename direction)
(let ((fd (case direction
((1) (posix-open filename (bitwise-ior O_RDONLY O_CREAT) #o755))
((2) (posix-open filename (bitwise-ior O_WRONLY O_CREAT) #o755))
((3) (posix-open filename (bitwise-ior O_RDWR O_CREAT) #o755)))))
(let loop ()
(##open-predefined direction filename fd)
(loop))))
More information about the Gambit-list
mailing list