The thing is that Gauche aims at a hybrid of Scheme and general list-processing library in C; C API can be called from other C functions unrelated to Scheme.
The bottom error handler can examine the Scheme VM state and get info from the top frame in the stack.  But it isn't necessarily the Scheme procedure related to the C API, for the Scheme procedure may be tail called, in that case we don't have a frame for it at the time the C API is called.

There's a couple of choices---change all the C API to take some Scheme context info (we can reference the current Scheme VM info, but that's not enough because of the tail-call problem), or wrap low-level calls in srfi-170 to prevent tail-calling bottom-level API.


On Sat, Aug 15, 2020 at 10:55 PM Göran Weinholt <xxxxxx@weinholt.se> wrote:
Shiro Kawai <xxxxxx@gmail.com> writes:

[...]
> I can certainly wrap Gauche's low-level syscall API with guard and
> translate <system-error> to srfi-170 error, in every srfi-170 API. The
> overhead isn't small and I'd rather avoid it if I can.

Loko Scheme's implementation of SRFI 198 uses the R6RS condition system.
This way there is no need to use guard, because any syscall error
anywhere in Loko already raises an R6RS condition and SRFI 198 just
needs to recognize it. Maybe you can use a similar strategy in Gauche,
can you teach SRFI 198 to understand <system-error>?

In Loko, the foreign-error:* procedures understand R6RS conditions and
check their argument to see which kind of condition they've been given.
make-foreign-error translates its argument into conditions. This also
has the benefit of letting any R6RS code handle the &who, &message and
&irritants part of the SRFI 198 error.

It works because SRFI 198 defines a constructor and accessors that hide
the concrete type of conditions. I haven't been keeping up with the
discussion lately, but I hope that this aspect hasn't changed.

Loko is up to date with SRFI 198 draft #3 and SRFI 170 draft #10. Here
is the code:
https://gitlab.com/weinholt/loko/-/tree/master/srfi
(The srfi/ directory is MIT-licensed.)

--
Göran Weinholt   | https://weinholt.se/
Debian Developer | 73 de SA6CJK