[gambit-list] Passing lambdas as callbacks to C functions
Phil Dawes
pdawes at users.sf.net
Sat Feb 3 02:57:09 EST 2007
Actually, here's a testcase that's more representative of what I'm
trying to do:
--------------------
(c-define (call-lambda l) (scheme-object) void "call_lambda" ""
(l))
(define looper
(c-lambda (scheme-object) void
#<<c-lambda-end
while(1){
call_lambda(___ARG1);
}
c-lambda-end
))
(define (main)
(let ((e 1))
(looper
(lambda () (set! e 2)))))
--------------------
It seems that modifying state outside the lambda causes it to crash
(after looping a few times). This time I get:
*** ERROR IN looper -- Operator is not a PROCEDURE
('#<meroon #2>)
..which strikes me as a corrupted memory sort of error since I'm not
doing anything with meroon.
Any pointers would be much appreciated.
Many thanks,
Phil
Phil Dawes wrote:
> Hi Marc, Hi Gambit List,
>
> I ran into problems using lambda expressions as callbacks when wrapping
> libcsv and I've boiled it down to this testcase. Can anybody tell me why
> this crashes?:
>
> -------
> (c-define (call-lambda l) (scheme-object) void "call_lambda" ""
> (l))
>
> (define looper
> (c-lambda (scheme-object) void
> #<<c-lambda-end
> while(1){
> call_lambda(___ARG1);
> }
> c-lambda-end
> ))
>
>
> (define (main)
> (looper (lambda () (write "foo"))))
> --------
>
> looper is a c function which takes a scheme lambda and repeated invokes
> it using the 'call_lambda' bridging function.
>
> When I gsc compile it and run '(main)' after a bunch of looping and
> printing it crashes with:
> ERROR IN looper -- Operator is not a PROCEDURE
> ('#<return #2>)
>
> Any ideas? (or am I being stupid?!)
>
> Many thanks,
>
> Phil
>
>
More information about the Gambit-list
mailing list