chicken-users
[Top][All Lists]
Advanced

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

Re: [Chicken-users] Help with foreign code and lists on the stack and he


From: Peter Bex
Subject: Re: [Chicken-users] Help with foreign code and lists on the stack and heap
Date: Tue, 6 May 2014 12:23:09 +0200
User-agent: Mutt/1.4.2.3i

On Tue, May 06, 2014 at 03:39:31AM -0600, Alex Stuart wrote:
> Greetings,
> 

Hi there!

> I want to append the latter list to the former and pass it to a second
> callback function. I'm trying to do this by setting the cdr of the first
> list's last pair (using C_set_block_item). However, the appended list is
> wrong.
> 
> I'm guessing that garbage collection is messing with the list even
> though I dereference my GC root to read the first part of it. Things
> work fine if I just pass that part, but appending the other part doesn't
> work.
> 
> Is the problem that the first list is heap-allocated and the second list
> is stack-allocated? Am I approaching this the wrong way? I would much
> appreciate any advice I can get.

I think the problem is that you're setting the pointer to the first_list
in the gc_root.  I don't know the type of first_list, but CHICKEN_apply
expects an address of a C_word, to which it will write the list's cons
cell.  When using CHICKEN_gc_root_set, you should pass the C_word, not
its address.

> /* RETRIEVE LIST NUMBER 1 */
> CHICKEN_apply( CHICKEN_gc_root_ref( callback1 ), arg_list, first_list );
> void *gc_root = CHICKEN_new_gc_root();
> CHICKEN_gc_root_set( gc_root, first_list );

Assuming first_list is a C_word, that should be:

CHICKEN_apply( CHICKEN_gc_root_ref( callback1 ), arg_list, &first_list );
void *gc_root = CHICKEN_new_gc_root();
CHICKEN_gc_root_set( gc_root, first_list );

Cheers,
Peter
-- 
http://www.more-magic.net



reply via email to

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