Previous: objects misc, Up: objects [Index]
While writing C language code interfacing with Scheme, if we call a C language function which calls back a Scheme function we have to save and restore the current system continuation:
ikpcb_t * pcb = the_pcb; ik_enter_c_function(pcb); { /* place here C code that calls Scheme code */ } ik_leave_c_function(pcb);
else, upon returning from the Scheme code, the execution flow will go to the wrong continuation and undefined behaviour ensues.
Save the current Scheme continuation followed by the current system
continuation. A call to this function must be matched by a call to
ik_leave_c_function()
.
Restore the previously saved Scheme continuation. A call to this
function must be matched by a call to ik_enter_c_function()
.
Notice that when Scheme calls C then C calls Scheme: garbage collections
can happen in the nested Scheme code, so the C code cannot rely on the
Scheme values to keep their location. Also, nested C code invocations
can happen, so the C code calling out to Scheme cannot use the
pcb->root
fields to preserve Scheme values.