Hello, 1. Debuggers like gdb can run a program that crashes, without themselves
itself crashing. Could our FFI calls be wrapped in similar mechanism?
I don't think so. A debugger does not run in the same process as the program being debugged. Also, you don't have any guarantee that you have not corrupted something important as the VM. If we have the debugger in the same process as the program being debugged, then the debugger could be corrupted by the error in the external C library. Trying to do something like that could be very dangerous.
2. Languages have exception handling, so that errors like divide by zero can be caught. Could our FFI calls be wrapped in similar mechanism? cheers -ben
The short answer is that it cannot be done automatically, without losing a lot in portability Exception handling implementations depends in the language, operating system and CPU architectude. The way that exceptions are implemented is a wild territory. For C++, you do not have a standard ABI. You cannot interface directly with C++ without losing portability. For wrapping C++, you first have to write a C wrapper for the C++ library, and then you have to do a wrapper in Pharo to the C library. In this C wrapper, you could something like catching all the exceptions and store them in some data structure that can be retrieved later. Then in the Pharo image you have to check for a pending exception in this data structure, and then transform wrapped exception into something more appropriate. Greetings, Ronie 2014-09-25 21:50 GMT-03:00 Ben Coman <btc@openinworld.com>:
I had a brief moment wondering about the general problem we have when calling out through FFI that we expose ourselves to bugs in the external library that crash the Image. I wonder...
1. Debuggers like gdb can run a program that crashes, without themselves itself crashing. Could our FFI calls be wrapped in similar mechanism?
2. Languages have exception handling, so that errors like divide by zero can be caught. Could our FFI calls be wrapped in similar mechanism? cheers -ben