On 2/6/07, Tony Sidaway <[EMAIL PROTECTED]> wrote:
This is the crux of it.

$ cat testevict.scm
(use lolevel)

(define (myalloc size)
  (printf "Requested ~S byte\n" size)
  (let ((obj (allocate size)))
    (printf "~S\n" obj)
    obj))

(define getmem (foreign-lambda* void ((c-string ptr)) "printf (\"ptr =
%p\\n\", ptr);"))

(define s "A string")
(define e (object-evict s myalloc))
(getmem e)

$

Notice that I'm using the optional second parameter to object-evict so
that I can print out the allocated pointer address.

When compiled and run I'd expect this program to show that the pointer
received by getmem is very close to the pointer returned by allocate
(just the same plus the size of the header used to describe the object
to Scheme, basically).

Instead I get completely different values.

$ csc testevict.scm
$ ./testevict
Requested 12 byte
#<pointer 0x806b488>
ptr = 0xbfec0864
$

My expectations are obviously wrong.

What's happening there?


Since Scheme strings do not have a zero-terminator, the call to getmem
will receive a copy of the string, with a 0-terminator appended. To pass
the String object directly, use the foreign type specifier `scheme-object'
(and access the data-portion of the block via C_c_string(x), for example).


cheers,
felix


_______________________________________________
Chicken-users mailing list
Chicken-users@nongnu.org
http://lists.nongnu.org/mailman/listinfo/chicken-users

Reply via email to