[ I've Cc'ed Ben on this. Ben, please note the continuable signal
related question at the end. ]
Kai.Grossjohann(a)CS.Uni-Dortmund.DE (Kai writes:
Tramp invokes `read' in a buffer containing an sexp which in
turn
might contain, as one item, a largish number. How do I make it so
that the resulting Lisp structure contains -1 instead of that
largish number?
Let me see if I understand this correctly. So, for instance, you have
a piece of buffer that looks like this:
(foo bar 1927120979049047309282389079128346218936)
Is it correct to say that you want to call (read (current-buffer)) and
have it return (foo bar -1)?
Your suggestion to trap the overflow and re-try seems to work, but
requires modifying the buffer. If this is not allowed, you must
create a temporary buffer, which is slower. You could optimize by
trying to read from the buffer in-place, and if that fails, copy the
expression in a temporary buffer and continue from there, replacing
the overflowing constants with -1. This is not hard to do, but it's
tedious.
One interesting feature that XEmacs supports are continuable errors.
This means that you should be able to use a condition-case-like a
handler that returns from a new value, in your case -1. You can test
this from the debugger: set debug-on-error to t, evaluate
(read (current-buffer)) before the above sexp, and press `r -1 RET'
in the debugger. The returned value will be the desired (foo bar -1).
However, this feature currently only works from the debugger. The way
to code it would be like this:
(defun read-trapping-overflow ()
(call-with-condition-handler
(lambda (error-info)
;; Correct code would check whether the error really is integer
;; overflow and rethrow by returning `signal' if not.
;; Otherwise, replace overflowing value with -1.
-1)
(lambda ()
(read (current-buffer)))))
But for this to work, you need to enable that functionality with this
patch:
--- src/eval.c.orig Mon Jul 29 00:27:19 2002
+++ src/eval.c Mon Jul 29 00:41:48 2002
@@ -1928,12 +1928,12 @@
NNUNGCPRO;
}
NUNGCPRO;
-#if 0
- if (!EQ (tem, Qsignal))
- return return_from_signal (tem);
-#endif
+
/* If handler didn't throw, try another handler */
Vcondition_handlers = all_handlers;
+
+ if (!EQ (tem, Qsignal))
+ return return_from_signal (tem);
}
/* It's a condition-case handler */
I have no idea why someone went to all the trouble to implement the
continuable errors, and then disabled their use! If the feature is
disabled because it's unstable, then why is it available from the
debugger?
Ben, can you comment on this? Does this patch clash with your
modified `signal' workspace?
Unless there is a good reason to disable this, I'd like this patch to
be applied.