diff options
Diffstat (limited to 'generic/tclBinary.c')
-rw-r--r-- | generic/tclBinary.c | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/generic/tclBinary.c b/generic/tclBinary.c index 328faaf..ccdab6e 100644 --- a/generic/tclBinary.c +++ b/generic/tclBinary.c @@ -126,8 +126,8 @@ typedef struct ByteArray { #define GET_BYTEARRAY(objPtr) \ ((ByteArray *) (objPtr)->internalRep.twoPtrValue.ptr1) #define SET_BYTEARRAY(objPtr, baPtr) do { \ - (objPtr)->internalRep.twoPtrValue.ptr2 = NULL; \ (objPtr)->internalRep.twoPtrValue.ptr1 = (VOID *) (baPtr); \ + (objPtr)->internalRep.twoPtrValue.ptr2 = NULL; \ } while(0) @@ -268,11 +268,17 @@ Tcl_SetByteArrayObj( * >= 0. */ { ByteArray *byteArrayPtr; + void *stringIntRep = NULL; if (Tcl_IsShared(objPtr)) { Tcl_Panic("%s called with shared object", "Tcl_SetByteArrayObj"); } - TclFreeIntRep(objPtr); + /* If previous objType was string, keep the internal representation */ + if (objPtr->typePtr == &tclStringType) { + stringIntRep = objPtr->internalRep.twoPtrValue.ptr1; + } else { + TclFreeIntRep(objPtr); + } Tcl_InvalidateStringRep(objPtr); if (length < 0) { @@ -287,6 +293,7 @@ Tcl_SetByteArrayObj( } objPtr->typePtr = &tclByteArrayType; SET_BYTEARRAY(objPtr, byteArrayPtr); + objPtr->internalRep.twoPtrValue.ptr2 = stringIntRep; } /* @@ -418,10 +425,10 @@ SetByteArrayFromAny( /* If previous objType was string, keep the internal representation */ if(objPtr->typePtr == &tclStringType) { - stringIntRep = objPtr->internalRep.twoPtrValue.ptr2; - objPtr->internalRep.twoPtrValue.ptr2 = NULL; + stringIntRep = objPtr->internalRep.twoPtrValue.ptr1; + } else { + TclFreeIntRep(objPtr); } - TclFreeIntRep(objPtr); objPtr->typePtr = &tclByteArrayType; SET_BYTEARRAY(objPtr, byteArrayPtr); objPtr->internalRep.twoPtrValue.ptr2 = stringIntRep; |