Re: Interlanguage condition signalling and handling
"Hoehle, Joerg-Cyril" <[email protected]> Mon, 28 Oct 2002 14:31:21 +0100
| Newsgroups | gmane.lisp.uffi.general |
|---|---|
| Message-ID | <[email protected]> |
Liam M. Healy writes: >I have need of being able to signal a condition in a C library It's unclear to me what conditions there could be in C. Do you mean C++ signals or exceptions (or whatever they're called)? It's unclear to me what your exact situation is. However (being proactive): Here's for the FFI HowTo: ------------- Don't throw exceptions across language barriers (foreign language interfaces) - you'll almost certainly cause unreliable behaviour! UNWIND-PROTECT and its C++ counterparts won't fully work. ------------- If you need this functionality, use a framework that supports passing exceptions across language barriers. CORBA is the only thing that comes to mind (I never used it). Perhaps Java RMI also has hints on how to do that. > they suggested a solution that required wrapping every function. Use macros for repetitive work! I repeat: foreign C++ code must *not* throw an exception through into your Lisp system (I'm not saying they are forbidden). Likewise, a foreign callback written in Lisp must not THROW into your main Lisp loop. It must return to the foreign world via the callback. The dumb IGNORE-ERRORS is useful for this w.r.t. exception catching. The reason is that the run-time support libraries of each language know nothing about the other language. So they will not unwind the other language's stack frames properly. You must stick to "functional" (C-like) behaviour across different implementations and not jump. The same restriction remains for all sorts of library callbacks, even within a single language. I've seen broken GUI code which would jump out of the GUI event loop. You should treat all other .so or .dll files as possibly written in a foreign language. Regards, Jorg Hohle.