[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] Add errno property to condition objects
From: |
Lassi Kortela |
Subject: |
Re: [PATCH] Add errno property to condition objects |
Date: |
Sun, 7 Jan 2024 14:06:30 +0200 |
User-agent: |
Mozilla Thunderbird |
This is a very good idea.
Would a code review be appropriate? Here is a quick one.
In the Scheme code, strerror seems to be both a procedure and a variable.
Procedure: (strerror rn)
Variable: (##sys#string-append "cannot read from port - " strerror)
The latter is defined as:
(define-foreign-variable strerror c-string "strerror(errno)")
This is not a variable in the conventional sense; more like a symbol macro.
strerror is widely known as a C function. I suggest keeping it as a
procedure in Scheme, and renaming the symbol macro to something less
ambiguous.
Most of the calls to ##sys#signal-hook/errno contain a redundant
string-append (and some identical error messages which could perhaps be
refactored):
(##sys#string-append "cannot read from port - " strerror)
(##sys#string-append "cannot read from port - " strerror)
(##sys#string-append "cannot read from port - " strerror)
(##sys#string-append "cannot read from port - " strerror)
(##sys#string-append "cannot read from port - " strerror)
(##sys#string-append "cannot read from port - " strerror)
(##sys#string-append "cannot read from port - " strerror)
(##sys#string-append "cannot read from port - " strerror)
(##sys#string-append "cannot delete file - " strerror) filename)
(##sys#string-append "cannot delete file - " strerror) filename)
(##sys#string-append "cannot rename file - " strerror) oldfile newfile)
(##sys#string-append "cannot open file - " strerror)
(##sys#string-append "cannot open file - " strerror)
A typical call to ##sys#signal-hook/errno is like this:
(##sys#signal-hook/errno
#:file-error err 'read-char
(##sys#string-append "cannot read from port - " strerror)
p)
It seems that strerror doesn't have to be supplied by the caller.
##sys#signal-hook/errno could append it itself. For example:
(when errno (set! msg (##sys#string-append msg " - " strerror)))
Messages returned by the C call strerror(err) depend only on two things:
- The err argument.
- The POSIX locale active at the time of the call.
This means that it's fine to compute strerror() at the last minute when
the error message is requested. It doesn't have to be computed at the
time the error is encountered. I'm not sure whether Chicken's condition
system supports a custom lambda to generate the error message. If it
does, errno conditions would be a natural application (no pun intended).