summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2017-12-06 13:28:12 (GMT)
committerdgp <dgp@users.sourceforge.net>2017-12-06 13:28:12 (GMT)
commit21877b851cd37a74cf2bff60aeea082cdfa0bafd (patch)
tree00277636db9bd4331dee668c294e31a78bcb06d5
parentd7ed3259130eb94a7050d2d66b99c997378c969d (diff)
downloadtcl-21877b851cd37a74cf2bff60aeea082cdfa0bafd.zip
tcl-21877b851cd37a74cf2bff60aeea082cdfa0bafd.tar.gz
tcl-21877b851cd37a74cf2bff60aeea082cdfa0bafd.tar.bz2
Adapt the bytearray accommodation of Tcl_CharLength() for 8.7+.
-rw-r--r--generic/tclStringObj.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/generic/tclStringObj.c b/generic/tclStringObj.c
index 85cac83..385ce4f 100644
--- a/generic/tclStringObj.c
+++ b/generic/tclStringObj.c
@@ -421,13 +421,14 @@ Tcl_GetCharLength(
* Optimize the case where we're really dealing with a bytearray object;
* we don't need to convert to a string to perform the get-length operation.
*
- * NOTE that we do not need the bytearray to be "pure". A ByteArray value
- * with a string rep cannot be trusted to represent the same value as the
- * string rep, but it *can* be trusted to have the same character length
- * as the string rep, which is all this routine cares about.
+ * Starting in Tcl 8.7, we check for a "pure" bytearray, because the
+ * machinery behind that test is using a proper bytearray ObjType. We
+ * could also compute length of an improper bytearray without shimmering
+ * but there's no value in that. We *want* to shimmer an improper bytearray
+ * because improper bytearrays have worthless internal reps.
*/
- if (objPtr->typePtr == &tclByteArrayType) {
+ if (TclIsPureByteArray(objPtr)) {
int length;
(void) Tcl_GetByteArrayFromObj(objPtr, &length);