feeley/gambit — pull request #61 by euccastro (2013-12-25 19:12:26+00:00)
Title: Make the garbage collector track the field at __FOREIGN_SIZE, if any.

I won't repeat what the point of this is. :)

I have checked that this minimal patch is enough to enable me to do the rest out of the Gambit source tree. A self-contained usage example follows below. It's more complicated than the other ones but that's no problem at all for me as long as I can isolate users of my libraries from that complexity.

(c-declare #<x;"))

(define p-y
(c-lambda (point)
int
"___result = ((point*)___arg1)->y;"))

(define p-x-set!
(c-lambda (point int) void
"((point*)___arg1)->x = ___arg2;"))

(define p-y-set!
(c-lambda (point int) void
"((point*)___arg1)->y = ___arg2;"))

(p-x-set! p 3)
(p-y-set! p 5)
(println "p.x: " (p-x p) "; p.y: " (p-y p))
(define o (list 1 2))
(make-will o (lambda (x) (println "o checking out!")))
(println "initial data is:")
(write (foreign-dependencies p))
(newline)
(register-foreign-dependency! p o)
(println "data is now:")
(write (foreign-dependencies p))
(newline)
(println "losing global reference to o")
(set! o #f)
(##gc)
(##gc)
(##gc)
(println "killing p")
(set! p #f)
(##gc)
(println "done!")