G
Guest
Dave said:You are right. But, the only ANSI C (1989) library functions that AMPC
does
not support are longjmp(), setjmp(),
setjmp is a macro, not a function. It seems to me that it shouldn't be
too hard to invoke some compiler magic to compile setjmp/longjmp as a
fairly thin wrapper around try/throw.
signal(), and raise().
Why not those? They should be some of the easiest to implement,
especially since there's no requirement that an implementation be able
to actually generate signals asynchronously.
Here's a first pass at it to get you started.
(Not compiled or tested. The usual disclaimers apply, and then some.) [...]
--------signal_implementation.c
#include <signal.h>
#include <stdlib.h>
void __sig_dfl(int sig)
{
if(sig==SIGTERM || sig==SIGINT)
{
/*termination request or interrupt are typically
not fatal errors
*/
exit(EXIT_SUCCESS);
<Semi-OT>
If a process exits from SIGTERM or SIGINT, normally it is not
considered to have exited successfully. If you have access to a
Unix-style system (Linux is good enough), try something like 'cat &&
echo success', and then send cat a SIGINT signal, for a simple example.
Or run a tool exiting from SIGTERM as part of any build system; most
will halt afterwards.
</Semi-OT>
[...]
Question for the language lawyers: Is this a correct C program?
--------
#include <signal.h>
int main(void)
{
SIG_DFL(SIGTERM);
return 0;
}
I suspect it isn't, either. I don't see anything preventing SIG_DFL
from being a null pointer, or a converted pointer to an incompatible
function, or a valid pointer to a non-function.