diff options
| author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2023-07-19 11:18:30 (GMT) |
|---|---|---|
| committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2023-07-19 11:18:30 (GMT) |
| commit | 2542a8f81ee6278e9e3fa9937483bd2183fc3548 (patch) | |
| tree | 6f2beefbb8bba8c4ab7ff73cacf6df4bc3d67926 | |
| parent | c444c608df624587909b00a2dd705639d77ee3c5 (diff) | |
| download | tcl-2542a8f81ee6278e9e3fa9937483bd2183fc3548.zip tcl-2542a8f81ee6278e9e3fa9937483bd2183fc3548.tar.gz tcl-2542a8f81ee6278e9e3fa9937483bd2183fc3548.tar.bz2 | |
Somewhat better error-reporting
| -rw-r--r-- | generic/tclEncoding.c | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/generic/tclEncoding.c b/generic/tclEncoding.c index 720c2a1..8c10ab9 100644 --- a/generic/tclEncoding.c +++ b/generic/tclEncoding.c @@ -202,12 +202,12 @@ static struct TclEncodingProfiles { #define PROFILE_TCL8(flags_) \ (ENCODING_PROFILE_GET(flags_) == TCL_ENCODING_PROFILE_TCL8) +#define PROFILE_REPLACE(flags_) \ + (ENCODING_PROFILE_GET(flags_) == TCL_ENCODING_PROFILE_REPLACE) + #define PROFILE_STRICT(flags_) \ (!PROFILE_TCL8(flags_) && !PROFILE_REPLACE(flags_)) -#define PROFILE_REPLACE(flags_) \ - (ENCODING_PROFILE_GET(flags_) == TCL_ENCODING_PROFILE_REPLACE) - #define UNICODE_REPLACE_CHAR ((Tcl_UniChar)0xFFFD) #define SURROGATE(c_) (((c_) & ~0x7FF) == 0xD800) #define HIGH_SURROGATE(c_) (((c_) & ~0x3FF) == 0xD800) @@ -1227,6 +1227,7 @@ Tcl_ExternalToUtfDStringEx( "Parameter error: TCL_ENCODING_{START,STOP} bits set in flags.", TCL_INDEX_NONE)); Tcl_SetErrorCode(interp, "TCL", "ENCODING", "ILLEGALFLAGS", NULL); + errno = EINVAL; return TCL_ERROR; } @@ -1302,6 +1303,9 @@ Tcl_ExternalToUtfDStringEx( interp, "TCL", "ENCODING", "ILLEGALSEQUENCE", buf, NULL); } } + if (result != TCL_OK) { + errno = (result == TCL_CONVERT_NOSPACE) ? ENOMEM : EILSEQ; + } return result; } @@ -1492,7 +1496,7 @@ Tcl_UtfToExternalDString( * The parameter flags controls the behavior, if any of the bytes in * the source buffer are invalid or cannot be represented in the * target encoding. It should be composed by OR-ing the following: - * - *At most one* of TCL_ENCODING_PROFILE{DEFAULT,TCL8,STRICT} + * - *At most one* of TCL_ENCODING_PROFILE_* * * Results: * The return value is one of @@ -1553,6 +1557,7 @@ Tcl_UtfToExternalDStringEx( "Parameter error: TCL_ENCODING_{START,STOP} bits set in flags.", TCL_INDEX_NONE)); Tcl_SetErrorCode(interp, "TCL", "ENCODING", "ILLEGALFLAGS", NULL); + errno = EINVAL; return TCL_ERROR; } @@ -1632,6 +1637,9 @@ Tcl_UtfToExternalDStringEx( buf, NULL); } } + if (result != TCL_OK) { + errno = (result == TCL_CONVERT_NOSPACE) ? ENOMEM : EILSEQ; + } return result; } @@ -3599,7 +3607,7 @@ TableFromUtfProc( word = 0; } else #endif - word = fromUnicode[(ch >> 8)][ch & 0xFF]; + word = fromUnicode[(ch >> 8)][ch & 0xFF]; if ((word == 0) && (ch != 0)) { if (PROFILE_STRICT(flags)) { |
