foreign-lambda expand struct-by-value pasted by klm` on Fri Mar 2 23:18:13 2012
; I want a function to be able to return a struct-by-val like this: (foreign-lambda (struct "line") "foo" ) ; My wrapper does this: ; Allocate struct on stack and continue with continuation, returning address (foreign-lambda* (c-pointer (struct "line")) () "struct line _tmp=foo();C_return(&_tmp);") ; When I run this once, twice, 10 times, it works all right. ; When I run it 100 times, the values become corrupted, as if something ; gets eaten by chicken's GC. ; What am I doing wrong?
still no luck added by klm` on Sat Mar 3 00:03:26 2012
; So I realized I needed to do foreign-primitive and use C_alloc (according to sjamaan and the docs). ; But my struct is still not stored in a safe place: ; my c-code looks like this: ;struct line foo2 () { ; struct line l; ; l.origin.tag = 11; ; l.origin.x = 12; ; l.origin.y = 13; ; ; l.direction.tag = 14; ; l.direction.x = 15; ; l.direction.y = 16; ; return l; ;} (define make-line (foreign-primitive (c-pointer (struct "line")) () "struct line *_tmp=(struct line*)C_alloc(sizeof(struct line)); *_tmp=foo2(); return(_tmp);")) ; I tried C_return with same results. ; C_malloc seems to work, however!