summaryrefslogtreecommitdiffstats
path: root/generic/tclBinary.c
diff options
context:
space:
mode:
authorkjnash <k.j.nash@usa.net>2022-08-31 15:24:20 (GMT)
committerkjnash <k.j.nash@usa.net>2022-08-31 15:24:20 (GMT)
commit7443a97bd1d5060c2bc3ea57dbd1899ea2efb9b8 (patch)
treea7402019faf3e75458552fe9dde90324f981fe7b /generic/tclBinary.c
parent19f8c3bb6b2aa8d571a7534b588ddacfb49952d3 (diff)
parent52b58d0c7d1575d7c784ccb344862e0de8a9686b (diff)
downloadtcl-7443a97bd1d5060c2bc3ea57dbd1899ea2efb9b8.zip
tcl-7443a97bd1d5060c2bc3ea57dbd1899ea2efb9b8.tar.gz
tcl-7443a97bd1d5060c2bc3ea57dbd1899ea2efb9b8.tar.bz2
Merge old 8.7 6c69a72c58
Diffstat (limited to 'generic/tclBinary.c')
-rw-r--r--generic/tclBinary.c36
1 files changed, 33 insertions, 3 deletions
diff --git a/generic/tclBinary.c b/generic/tclBinary.c
index 8a3541b..396beec 100644
--- a/generic/tclBinary.c
+++ b/generic/tclBinary.c
@@ -4,8 +4,8 @@
* This file contains the implementation of the "binary" Tcl built-in
* command and the Tcl binary data object.
*
- * Copyright (c) 1997 by Sun Microsystems, Inc.
- * Copyright (c) 1998-1999 by Scriptics Corporation.
+ * Copyright © 1997 Sun Microsystems, Inc.
+ * Copyright © 1998-1999 Scriptics Corporation.
*
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
@@ -496,7 +496,7 @@ TclGetBytesFromObj(
/*
*----------------------------------------------------------------------
*
- * Tcl_GetByteArrayFromObj --
+ * Tcl_GetByteArrayFromObj/TclGetByteArrayFromObj --
*
* Attempt to get the array of bytes from the Tcl object. If the object
* is not already a ByteArray object, an attempt will be made to convert
@@ -511,6 +511,7 @@ TclGetBytesFromObj(
*----------------------------------------------------------------------
*/
+#undef Tcl_GetByteArrayFromObj
unsigned char *
Tcl_GetByteArrayFromObj(
Tcl_Obj *objPtr, /* The ByteArray object. */
@@ -533,6 +534,35 @@ Tcl_GetByteArrayFromObj(
if (lengthPtr != NULL) {
*lengthPtr = baPtr->used;
}
+ return (unsigned char *) baPtr->bytes;
+}
+
+unsigned char *
+TclGetByteArrayFromObj(
+ Tcl_Obj *objPtr, /* The ByteArray object. */
+ size_t *lengthPtr) /* If non-NULL, filled with length of the
+ * array of bytes in the ByteArray object. */
+{
+ ByteArray *baPtr;
+ const Tcl_ObjIntRep *irPtr;
+ unsigned char *result = TclGetBytesFromObj(NULL, objPtr, (int *)NULL);
+
+ if (result) {
+ return result;
+ }
+
+ irPtr = TclFetchIntRep(objPtr, &tclByteArrayType);
+ assert(irPtr != NULL);
+
+ baPtr = GET_BYTEARRAY(irPtr);
+
+ if (lengthPtr != NULL) {
+#if TCL_MAJOR_VERSION > 8
+ *lengthPtr = baPtr->used;
+#else
+ *lengthPtr = ((size_t)(unsigned)(baPtr->used + 1)) - 1;
+#endif
+ }
return baPtr->bytes;
}