chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Chicken-users] Re: problem with callbacks


From: Daniel B. Faken
Subject: [Chicken-users] Re: problem with callbacks
Date: Thu, 22 Jan 2004 12:21:41 -0500 (EST)

Hello all,

  Some more interesting behaviour:
  Consider this program:
;-------------------------------
(declare (uses extras))

(set! bar (make-hash-table))

(let ((foo (make-hash-table)))

#>!
void scm_callback(int);
__callback void test_fn(int val)
{
  fprintf(stderr, "test_fn(%d): before callback\n", val); fflush(stderr);
  scm_callback(val);
  fprintf(stderr, "test_fn(%d): after callback\n", val); fflush(stderr);
}
<#

  (define scm_callback (foreign-callback-wrapper void "scm_callback" (int)
                              (lambda(x)  (print "callback-val is " x)
                                     (print "in callback: foo is " foo)
;                                    (print "in callback: foo is " bar)
                                     )))

(print "foo is " foo)
; (scm_callback 3)
(test_fn 50)
)
------------------

I observe this behaviour with Chicken 1.30 (under redhat 7.3):
compiling with 'csc tst.scm' and running './tst':

---- (1) program as shown above
gloriot2:~/cr/spu/viewpoint/htcam%./tst
foo is #<hash-table>
test_fn(50): before callback
callback-val is 50
Error: unprintable non-immediate object encountered

tst.scm: 3    make-hash-table
tst.scm: 5    make-hash-table
tst.scm: 23   print
tst.scm: 25   test_fn
##sys#gc
tst.scm: 18   print
tst.scm: 19   print
in callback: foo is gloriot2:~/cr/spu/viewpoint/htcam%

--- (2) program with (print .. foo) commented out and (print .. bar) 
--- uncommented (this is proper behaviour):
gloriot2:~/cr/spu/viewpoint/htcam%./tst
foo is #<hash-table>
test_fn(50): before callback
callback-val is 50
in callback: foo is #<hash-table>
test_fn(50): after callback

--- (2) compiling program with '(scm_callback 3)' uncommented:
gloriot2:~/cr/spu/viewpoint/htcam%csc tst.scm
tst.c: In function `scm_callback':
tst.c:68: `f_65' undeclared (first use in this function)
tst.c:68: (Each undeclared identifier is reported only once
tst.c:68: for each function it appears in.)
*** Shell command terminated with exit status 1: gcc tst.c -o tst.o -g -c 
-DC_NO_PIC_NO_DLL -I /home/dfaken/lib/chicken/include

-----------------
  Thus it appears something strange is going on with how 
foreign-callback-wrapper is handling "externally" (out of local scope) 
defined variables.

  Thoughts?

Daniel






reply via email to

[Prev in Thread] Current Thread [Next in Thread]