What's up here? I have a Scheme string that I want to send to a C library. The library will remember its location and so I want it to be in static memory, so I use object_evict and send the result of object-evict to the library as a c-string argument to a foreign-lambda. The library now knows the address of the data in the evicted string.
At some point I call another library function as a foreign-safe-lambda. During the course of executing that function it executes a callback whose address I've sent it as a c-pointer argument to another foreign-lambda. The callback seems to execute okay. It makes a new u8vector and copies some data into it, then has a let loop to convert u8s to char (integer->char) and display, character-by-character However the evicted string seems to be trashed. It now contains garbage. I wondered if I could duplicate this so I wrote a simple dummy copy of the library functions. The dummy version of the first C function stores the c-string in a static pointer to char. The dummy version of the second C function executes the callback and then writes out the value of the string. The string in the dummy copy is corrupted just as it was in the real library. Further tests show that the corruption appears after the callback is invoked. Making all foreign-lambdas into foreign-safe-lambdas doesn't make any difference. However the evicted variable seems to be quite okay on the Scheme side. This is what is really puzzling. It seems that the evicted object has moved around after being evicted, and Scheme keeps track of it. But of course C doesn't know this and gets corrupted data. That doesn't make sense. If we can say one thing about the output of object-evict, surely it's that it won't move around? _______________________________________________ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users