On Mon, Oct 14, 2002 at 10:38:40AM -0500, Peter Keller wrote:
On Mon, Oct 14, 2002 at 08:57:05AM +0200, Felix Winkelmann wrote:
In this case I would create a number of foreign-lambda*s
that access the slots:
So, I actually thought of this, but rejected it because I didn't
understand how gc would affect it. I thought that I could end up with a
way that I'd have a valid z_stream object with a member field pointing
to gc'ed data.
So, I tried this out:
(declare
(foreign_declare #<< EOF
#include <zlib.h>)
EOF
))
(define-foreign-type z_stream (pointer "z_stream"))
(define make-z_stream
(let ( (alloc (foreign-lambda* z_stream ()
"return (malloc(sizeof(z_stream)));"))
(dealloc (foreign-lambda void "free" c-pointer)))
(lambda ()
(let ((m (alloc)))
(set-finalizer! m dealloc)
m))))
(define z_stream-next_in
(foreign-lambda* c-pointer ((z_stream p))
"return(p->next_in);") )
(define z_stream-next_in-set!
(foreign-lambda* void ((z_stream p) (u8vector x))
"p->next_in = x;") )
(let ((foo (make-z_stream)))
(z_stream-next_in-set! foo (u8vector 1 2 3 4 5))
(print (z_stream-next_in foo)))
And this was the output:
#<pointer -1073745280.>
I seem to have lost the knowledge that next_in was a u8vector.