summaryrefslogtreecommitdiffstats
path: root/generic
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2021-05-26 14:04:00 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2021-05-26 14:04:00 (GMT)
commit588e5a48cb262a4fa3d60698be3f1d94434dfcf1 (patch)
tree21cb8573b4117b94c7a339111087f5f033da852d /generic
parent543961cfe677aed974b369bd0dee75a7bbdfaacc (diff)
downloadtcl-588e5a48cb262a4fa3d60698be3f1d94434dfcf1.zip
tcl-588e5a48cb262a4fa3d60698be3f1d94434dfcf1.tar.gz
tcl-588e5a48cb262a4fa3d60698be3f1d94434dfcf1.tar.bz2
Handle the situation when there is "-nothrow" or "-stoponerror" but without providing encoding
Diffstat (limited to 'generic')
-rw-r--r--generic/tclCmdAH.c77
1 files changed, 45 insertions, 32 deletions
diff --git a/generic/tclCmdAH.c b/generic/tclCmdAH.c
index 0f9aa27..6549648 100644
--- a/generic/tclCmdAH.c
+++ b/generic/tclCmdAH.c
@@ -561,21 +561,26 @@ EncodingConvertfromObjCmd(
encoding = Tcl_GetEncoding(interp, NULL);
data = objv[1];
} else if ((unsigned)(objc - 2) < 3) {
- if (Tcl_GetEncodingFromObj(interp, objv[objc - 2], &encoding) != TCL_OK) {
- return TCL_ERROR;
- }
data = objv[objc - 1];
- if (objc > 3) {
- bytesPtr = Tcl_GetString(objv[1]);
- if (bytesPtr[0] == '-' && bytesPtr[1] == 'n'
- && !strncmp(bytesPtr, "-nothrow", strlen(bytesPtr))) {
- flags = TCL_ENCODING_NO_THROW;
- } else if (bytesPtr[0] == '-' && bytesPtr[1] == 's'
- && !strncmp(bytesPtr, "-stoponerror", strlen(bytesPtr))) {
- flags = TCL_ENCODING_STOPONERROR;
- } else {
- goto encConvFromError;
+ bytesPtr = Tcl_GetString(objv[1]);
+ if (bytesPtr[0] == '-' && bytesPtr[1] == 'n'
+ && !strncmp(bytesPtr, "-nothrow", strlen(bytesPtr))) {
+ flags = TCL_ENCODING_NO_THROW;
+ } else if (bytesPtr[0] == '-' && bytesPtr[1] == 's'
+ && !strncmp(bytesPtr, "-stoponerror", strlen(bytesPtr))) {
+ flags = TCL_ENCODING_STOPONERROR;
+ } else if (objc < 4) {
+ if (Tcl_GetEncodingFromObj(interp, objv[objc - 2], &encoding) != TCL_OK) {
+ return TCL_ERROR;
}
+ goto encConvFromOK;
+ } else {
+ goto encConvFromError;
+ }
+ if (objc < 4) {
+ encoding = Tcl_GetEncoding(interp, NULL);
+ } else if (Tcl_GetEncodingFromObj(interp, objv[objc - 2], &encoding) != TCL_OK) {
+ return TCL_ERROR;
}
} else {
encConvFromError:
@@ -583,16 +588,18 @@ EncodingConvertfromObjCmd(
return TCL_ERROR;
}
+encConvFromOK:
/*
* Convert the string into a byte array in 'ds'
*/
- if (flags & TCL_ENCODING_STOPONERROR) {
- bytesPtr = (char *) TclGetBytesFromObj(interp, data, &length);
- if (bytesPtr == NULL) {
- return TCL_ERROR;
- }
- } else {
+#if !defined(TCL_NO_DEPRECATED) && (TCL_MAJOR_VERSION < 9)
+ if (!(flags & TCL_ENCODING_STOPONERROR)) {
bytesPtr = (char *) Tcl_GetByteArrayFromObj(data, &length);
+ } else
+#endif
+ bytesPtr = (char *) TclGetBytesFromObj(interp, data, &length);
+ if (bytesPtr == NULL) {
+ return TCL_ERROR;
}
result = Tcl_ExternalToUtfDStringEx(encoding, bytesPtr, length,
flags, &ds);
@@ -660,21 +667,26 @@ EncodingConverttoObjCmd(
encoding = Tcl_GetEncoding(interp, NULL);
data = objv[1];
} else if ((unsigned)(objc - 2) < 3) {
- if (Tcl_GetEncodingFromObj(interp, objv[objc - 2], &encoding) != TCL_OK) {
- return TCL_ERROR;
- }
data = objv[objc - 1];
- if (objc > 3) {
- stringPtr = Tcl_GetString(objv[1]);
- if (stringPtr[0] == '-' && stringPtr[1] == 'n'
- && !strncmp(stringPtr, "-nothrow", strlen(stringPtr))) {
- flags = TCL_ENCODING_NO_THROW;
- } else if (stringPtr[0] == '-' && stringPtr[1] == 's'
- && !strncmp(stringPtr, "-stoponerror", strlen(stringPtr))) {
- flags = TCL_ENCODING_STOPONERROR;
- } else {
- goto encConvToError;
+ stringPtr = Tcl_GetString(objv[1]);
+ if (stringPtr[0] == '-' && stringPtr[1] == 'n'
+ && !strncmp(stringPtr, "-nothrow", strlen(stringPtr))) {
+ flags = TCL_ENCODING_NO_THROW;
+ } else if (stringPtr[0] == '-' && stringPtr[1] == 's'
+ && !strncmp(stringPtr, "-stoponerror", strlen(stringPtr))) {
+ flags = TCL_ENCODING_STOPONERROR;
+ } else if (objc < 4) {
+ if (Tcl_GetEncodingFromObj(interp, objv[objc - 2], &encoding) != TCL_OK) {
+ return TCL_ERROR;
}
+ goto encConvToOK;
+ } else {
+ goto encConvToError;
+ }
+ if (objc < 4) {
+ encoding = Tcl_GetEncoding(interp, NULL);
+ } else if (Tcl_GetEncodingFromObj(interp, objv[objc - 2], &encoding) != TCL_OK) {
+ return TCL_ERROR;
}
} else {
encConvToError:
@@ -682,6 +694,7 @@ EncodingConverttoObjCmd(
return TCL_ERROR;
}
+encConvToOK:
/*
* Convert the string to a byte array in 'ds'
*/