[pure-lang-svn] SF.net SVN: pure-lang:[476] pure/trunk
Status: Beta
Brought to you by:
agraef
|
From: <ag...@us...> - 2008-08-12 19:20:27
|
Revision: 476
http://pure-lang.svn.sourceforge.net/pure-lang/?rev=476&view=rev
Author: agraef
Date: 2008-08-12 19:20:37 +0000 (Tue, 12 Aug 2008)
Log Message:
-----------
Add 'trap' operation to configure signal handlers.
Modified Paths:
--------------
pure/trunk/ChangeLog
pure/trunk/lib/system.pure
pure/trunk/runtime.cc
pure/trunk/runtime.h
Modified: pure/trunk/ChangeLog
===================================================================
--- pure/trunk/ChangeLog 2008-08-12 19:17:34 UTC (rev 475)
+++ pure/trunk/ChangeLog 2008-08-12 19:20:37 UTC (rev 476)
@@ -1,5 +1,8 @@
2008-08-12 Albert Graef <Dr....@t-...>
+ * runtime.cc/h, lib/system.pure: Add 'trap' operation to configure
+ signal handlers.
+
* runtime.cc (pure_sys_vars): Add signal constants.
* pure.cc (main): Set up handlers for standard POSIX termination
Modified: pure/trunk/lib/system.pure
===================================================================
--- pure/trunk/lib/system.pure 2008-08-12 19:17:34 UTC (rev 475)
+++ pure/trunk/lib/system.pure 2008-08-12 19:20:37 UTC (rev 476)
@@ -47,6 +47,18 @@
errno = pure_errno;
set_errno val::int = pure_set_errno val;
+/* Signal handling. The action parameter of 'trap' can be one of the
+ predefined integer values SIG_TRAP, SIG_IGN and SIG_DFL. SIG_TRAP causes
+ the given signal to be handled by mapping it to a Pure exception of the
+ form 'signal SIG'. SIG_IGN ignores the signal, SIG_DFL reverts to the
+ system's default handling. See 'list -g SIG*' for a list of known signal
+ values on your system. NOTE: Most standard termination signals (SIGINT,
+ SIGTERM, etc.) are already set up at the start of the interpreter to report
+ corresponding Pure exceptions; if this is not desired, you can use 'trap'
+ to either ignore these or revert to the default handlers instead. */
+
+extern void pure_trap(int action, int sig) = trap;
+
/* Time functions. 'time' reports the current time in seconds since the
"epoch" a.k.a. 00:00:00 UTC, Jan 1 1970. The result is always a bigint (in
fact, the time value is already 64 bit on many OSes nowadays). */
Modified: pure/trunk/runtime.cc
===================================================================
--- pure/trunk/runtime.cc 2008-08-12 19:17:34 UTC (rev 475)
+++ pure/trunk/runtime.cc 2008-08-12 19:20:37 UTC (rev 476)
@@ -1297,7 +1297,23 @@
pure_throw(signal_exception(SIGFPE));
}
+static void sig_handler(int sig)
+{
+ interpreter::brkflag = sig;
+}
+
extern "C"
+void pure_trap(int32_t action, int32_t sig)
+{
+ if (action > 0)
+ signal(sig, sig_handler);
+ else if (action < 0)
+ signal(sig, SIG_IGN);
+ else
+ signal(sig, SIG_DFL);
+}
+
+extern "C"
pure_expr *pure_catch(pure_expr *h, pure_expr *x)
{
char test;
@@ -2938,6 +2954,10 @@
cdf(interp, "REG_ESPACE", pure_int(REG_ESPACE));
// regexec error codes
cdf(interp, "REG_NOMATCH", pure_int(REG_NOMATCH));
+ // signal actions
+ cdf(interp, "SIG_TRAP", pure_int(1));
+ cdf(interp, "SIG_IGN", pure_int(-1));
+ cdf(interp, "SIG_DFL", pure_int(0));
// signals
#ifdef SIGHUP
cdf(interp, "SIGHUP", pure_int(SIGHUP));
Modified: pure/trunk/runtime.h
===================================================================
--- pure/trunk/runtime.h 2008-08-12 19:17:34 UTC (rev 475)
+++ pure/trunk/runtime.h 2008-08-12 19:20:37 UTC (rev 476)
@@ -345,6 +345,11 @@
void pure_sigfpe(void);
+/* Configure signal handlers. The second argument is the signal number, the
+ first the action to take (-1 = ignore, 1 = handle, 0 = default). */
+
+void pure_trap(int32_t action, int32_t sig);
+
/* Execute a parameterless fbox x and return its result. If an exception
occurs while x is executed, apply h to the value of the exception
instead. */
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|