1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-09 17:38:00 +00:00
putty-source/terminal
Simon Tatham 4f756d2a4d Rework Unicode conversion APIs to use a BinarySink.
The previous mb_to_wc and wc_to_mb had horrible and also buggy APIs.
This commit introduces a fresh pair of functions to replace them,
which generate output by writing to a BinarySink. So it's now up to
the caller to decide whether it wants the output written to a
fixed-size buffer with overflow checking (via buffer_sink), or
dynamically allocated, or even written directly to some other output
channel.

Nothing uses the new functions yet. I plan to migrate things over in
upcoming commits.

What was wrong with the old APIs: they had that awkward undocumented
Windows-specific 'flags' parameter that I described in the previous
commit and took out of the dup_X_to_Y wrappers. But much worse, the
semantics for buffer overflow were not just undocumented but actually
inconsistent. dup_wc_to_mb() in utils assumed that the underlying
wc_to_mb would fill the buffer nearly full and return the size of data
it wrote. In fact, this was untrue in the case where wc_to_mb called
WideCharToMultiByte: that returns straight-up failure, setting the
Windows error code to ERROR_INSUFFICIENT_BUFFER. It _does_ partially
fill the output buffer, but doesn't tell you how much it wrote!

What's wrong with the new API: it's a bit awkward to write a sequence
of wchar_t in native byte order to a byte-oriented BinarySink, so
people using put_mb_to_wc directly have to do some annoying pointer
casting. But I think that's less horrible than the previous APIs.

Another change: in the new API for wc_to_mb, defchr can be "", but not
NULL.
2024-09-26 11:30:07 +01:00
..
bidi_gettype.c Make bidi type enums into list macros. 2021-10-10 14:55:15 +01:00
bidi_test.c bidi_test: minor memory fixes. 2022-01-29 18:25:34 +00:00
bidi.c Update to Unicode 15. 2022-11-11 08:44:07 +00:00
bidi.h Test rig for the new bidi algorithm. 2021-10-10 15:00:30 +01:00
lineedit.c New centralised version of local line editing. 2023-03-04 13:55:50 +00:00
terminal.c Rework Unicode conversion APIs to use a BinarySink. 2024-09-26 11:30:07 +01:00
terminal.h Some int -> size_t cleanup in terminal.c API. 2024-09-24 09:42:53 +01:00