thanks Bill, I would not have found that solution on my own. GC question
time! In this case I am recursively walking a Max dictionary structure to
convert to a hash or vice versa. If I gc_protect the hash, am I good for
any dynamically created entries too during this traversal process? Or
should I be turning off the gc entirely until the traversal is done? Am I
correct in understanding that the issue is that the GC might collect items
that were made from C but not in scheme?

thanks again, getting close to a major upgrade in usefulness here!
iain

On Tue, Dec 8, 2020 at 2:45 AM <[email protected]> wrote:

> I would use s7_iterate which underlies map and for-each:
>
>      s7_pointer iter, hash, x;
>      s7_int gc1, gc2;
>
>      hash = s7_make_hash_table(sc, 8);
>      gc1 = s7_gc_protect(sc, hash);
>      s7_hash_table_set(sc, hash, s7_make_symbol(sc, "a"),
> s7_make_integer(sc, 1));
>      s7_hash_table_set(sc, hash, s7_make_symbol(sc, "b"),
> s7_make_integer(sc, 2));
>
>      iter = s7_make_iterator(sc, hash);
>      gc2 = s7_gc_protect(sc, iter);
>
>      x = s7_iterate(sc, iter);  /* (a . 1) */
>      fprintf(stderr, "x: %s\n", s7_object_to_c_string(sc, x));
>      x = s7_iterate(sc, iter);  /* (b . 2) */
>      fprintf(stderr, "x: %s\n", s7_object_to_c_string(sc, x));
>      x = s7_iterate(sc, iter);  /* #<eof> == end */
>      fprintf(stderr, "x: %s\n", s7_object_to_c_string(sc, x));
>
>      s7_gc_unprotect_at(sc, gc1);
>      s7_gc_unprotect_at(sc, gc2);
>
>
_______________________________________________
Cmdist mailing list
[email protected]
https://cm-mail.stanford.edu/mailman/listinfo/cmdist

Reply via email to