Incrementing the buffer head by 1 (as in the previous commit) is in
general not a good strategy for 2- and 4-byte external formats.
Propagate the unit size of the external format to
stream-decoding-error-and-handle and to the resync-funtion, so that
restarts can advance by an appropriate amount.
In the process, notice various bits of breakage in octet routines for
2- and 4-byte external formats, where the routines assumed that the
subsequence contained an integer number of units, and read off the end
of the provided memory area. Add checks for this case, and unify the
error signalling behaviour with that in fd-streams.
Add another clump of tests for these things.
Don't wrap a handler around every stream or octet function. Instead,
thread the replacement from the external format through the various
functions all the way to the coding error site, and inline handling a
coding error if a replacement is provided.
In the process, also somewhat unify the behaviour of restarts around
stream and octet encoding- and decoding-errors: provide a USE-VALUE
restart whose argument should be a character, a string, an octet or an
octet sequence, which will be used as a replacement (with encoding or
decoding if necessary) to the operation that caused the error.
Note a couple of TODOs in the process.
Make the external-format size function check the encodability of the
character before returning a size for it; this usually involves
calling a function that we already have. In a few cases this may lead
to a duplicate call to CHAR-CODE, which is cheap but elidable if
necessary, though this function is only called in FILE-STRING-LENGTH
in any case.
(That's not quite true: it's also called in :UNREAD in fd-stream.lisp,
which is shadowed for FD-STREAMs with buffers, but exposed by
generating an FD-STREAM without a buffer by using :direction :io or
bivalent streams.)