diff options
Diffstat (limited to 'generic')
-rw-r--r-- | generic/tclBinary.c | 72 | ||||
-rw-r--r-- | generic/tclInt.h | 4 |
2 files changed, 20 insertions, 56 deletions
diff --git a/generic/tclBinary.c b/generic/tclBinary.c index f069090..5b26b2f 100644 --- a/generic/tclBinary.c +++ b/generic/tclBinary.c @@ -57,12 +57,9 @@ static void DupByteArrayInternalRep(Tcl_Obj *srcPtr, Tcl_Obj *copyPtr); -static void DupProperByteArrayInternalRep(Tcl_Obj *srcPtr, - Tcl_Obj *copyPtr); static int FormatNumber(Tcl_Interp *interp, int type, Tcl_Obj *src, unsigned char **cursorPtr); static void FreeByteArrayInternalRep(Tcl_Obj *objPtr); -static void FreeProperByteArrayInternalRep(Tcl_Obj *objPtr); static int GetFormatSpec(const char **formatPtr, char *cmdPtr, int *countPtr, int *flagsPtr); static Tcl_Obj * ScanNumber(unsigned char *buffer, int type, @@ -248,10 +245,10 @@ static const EnsembleImplMap decodeMap[] = { * over which bytearray values can be useful in the meanwhile. */ -static const Tcl_ObjType properByteArrayType = { +const Tcl_ObjType tclPureByteArrayType = { "bytearray", - FreeProperByteArrayInternalRep, - DupProperByteArrayInternalRep, + FreeByteArrayInternalRep, + DupByteArrayInternalRep, UpdateStringOfByteArray, NULL }; @@ -287,13 +284,6 @@ typedef struct ByteArray { #define SET_BYTEARRAY(irPtr, baPtr) \ (irPtr)->twoPtrValue.ptr1 = (void *) (baPtr) -int -TclIsPureByteArray( - Tcl_Obj * objPtr) -{ - return objPtr->typePtr == &properByteArrayType; -} - /* *---------------------------------------------------------------------- * @@ -425,7 +415,7 @@ Tcl_SetByteArrayObj( } SET_BYTEARRAY(&ir, byteArrayPtr); - Tcl_StoreIntRep(objPtr, &properByteArrayType, &ir); + Tcl_StoreIntRep(objPtr, &tclPureByteArrayType, &ir); } /* @@ -453,13 +443,13 @@ Tcl_GetByteArrayFromObj( * array of bytes in the ByteArray object. */ { ByteArray *baPtr; - const Tcl_ObjIntRep *irPtr = TclFetchIntRep(objPtr, &properByteArrayType); + const Tcl_ObjIntRep *irPtr = TclFetchIntRep(objPtr, &tclPureByteArrayType); if (irPtr == NULL) { irPtr = TclFetchIntRep(objPtr, &tclByteArrayType); if (irPtr == NULL) { SetByteArrayFromAny(NULL, objPtr); - irPtr = TclFetchIntRep(objPtr, &properByteArrayType); + irPtr = TclFetchIntRep(objPtr, &tclPureByteArrayType); if (irPtr == NULL) { irPtr = TclFetchIntRep(objPtr, &tclByteArrayType); } @@ -511,12 +501,12 @@ Tcl_SetByteArrayLength( Tcl_Panic("%s called with shared object", "Tcl_SetByteArrayLength"); } - irPtr = TclFetchIntRep(objPtr, &properByteArrayType); + irPtr = TclFetchIntRep(objPtr, &tclPureByteArrayType); if (irPtr == NULL) { irPtr = TclFetchIntRep(objPtr, &tclByteArrayType); if (irPtr == NULL) { SetByteArrayFromAny(NULL, objPtr); - irPtr = TclFetchIntRep(objPtr, &properByteArrayType); + irPtr = TclFetchIntRep(objPtr, &tclPureByteArrayType); if (irPtr == NULL) { irPtr = TclFetchIntRep(objPtr, &tclByteArrayType); } @@ -562,7 +552,7 @@ SetByteArrayFromAny( ByteArray *byteArrayPtr; Tcl_ObjIntRep ir; - if (objPtr->typePtr == &properByteArrayType) { + if (objPtr->typePtr == &tclPureByteArrayType) { return TCL_OK; } if (objPtr->typePtr == &tclByteArrayType) { @@ -586,7 +576,7 @@ SetByteArrayFromAny( SET_BYTEARRAY(&ir, byteArrayPtr); Tcl_StoreIntRep(objPtr, - improper ? &tclByteArrayType : &properByteArrayType, &ir); + improper ? &tclByteArrayType : &tclPureByteArrayType, &ir); return TCL_OK; } @@ -611,14 +601,7 @@ static void FreeByteArrayInternalRep( Tcl_Obj *objPtr) /* Object with internal rep to free. */ { - ckfree(GET_BYTEARRAY(TclFetchIntRep(objPtr, &tclByteArrayType))); -} - -static void -FreeProperByteArrayInternalRep( - Tcl_Obj *objPtr) /* Object with internal rep to free. */ -{ - ckfree(GET_BYTEARRAY(TclFetchIntRep(objPtr, &properByteArrayType))); + ckfree(GET_BYTEARRAY(&(objPtr->internalRep))); } /* @@ -647,37 +630,16 @@ DupByteArrayInternalRep( ByteArray *srcArrayPtr, *copyArrayPtr; Tcl_ObjIntRep ir; - srcArrayPtr = GET_BYTEARRAY(TclFetchIntRep(srcPtr, &tclByteArrayType)); - length = srcArrayPtr->used; - - copyArrayPtr = ckalloc(BYTEARRAY_SIZE(length)); - copyArrayPtr->used = length; - copyArrayPtr->allocated = length; - memcpy(copyArrayPtr->bytes, srcArrayPtr->bytes, (size_t) length); - - SET_BYTEARRAY(&ir, copyArrayPtr); - Tcl_StoreIntRep(copyPtr, &tclByteArrayType, &ir); -} - -static void -DupProperByteArrayInternalRep( - Tcl_Obj *srcPtr, /* Object with internal rep to copy. */ - Tcl_Obj *copyPtr) /* Object with internal rep to set. */ -{ - unsigned int length; - ByteArray *srcArrayPtr, *copyArrayPtr; - Tcl_ObjIntRep ir; - - srcArrayPtr = GET_BYTEARRAY(TclFetchIntRep(srcPtr, &properByteArrayType)); + srcArrayPtr = GET_BYTEARRAY(&(srcPtr->internalRep)); length = srcArrayPtr->used; copyArrayPtr = ckalloc(BYTEARRAY_SIZE(length)); copyArrayPtr->used = length; copyArrayPtr->allocated = length; - memcpy(copyArrayPtr->bytes, srcArrayPtr->bytes, (size_t) length); + memcpy(copyArrayPtr->bytes, srcArrayPtr->bytes, length); SET_BYTEARRAY(&ir, copyArrayPtr); - Tcl_StoreIntRep(copyPtr, &properByteArrayType, &ir); + Tcl_StoreIntRep(copyPtr, srcPtr->typePtr, &ir); } /* @@ -702,7 +664,7 @@ UpdateStringOfByteArray( Tcl_Obj *objPtr) /* ByteArray object whose string rep to * update. */ { - const Tcl_ObjIntRep *irPtr = TclFetchIntRep(objPtr, &properByteArrayType); + const Tcl_ObjIntRep *irPtr = TclFetchIntRep(objPtr, &tclPureByteArrayType); ByteArray *byteArrayPtr = GET_BYTEARRAY(irPtr); unsigned char *src = byteArrayPtr->bytes; unsigned int i, length = byteArrayPtr->used; @@ -777,12 +739,12 @@ TclAppendBytesToByteArray( length = (unsigned int)len; - irPtr = TclFetchIntRep(objPtr, &properByteArrayType); + irPtr = TclFetchIntRep(objPtr, &tclPureByteArrayType); if (irPtr == NULL) { irPtr = TclFetchIntRep(objPtr, &tclByteArrayType); if (irPtr == NULL) { SetByteArrayFromAny(NULL, objPtr); - irPtr = TclFetchIntRep(objPtr, &properByteArrayType); + irPtr = TclFetchIntRep(objPtr, &tclPureByteArrayType); if (irPtr == NULL) { irPtr = TclFetchIntRep(objPtr, &tclByteArrayType); } diff --git a/generic/tclInt.h b/generic/tclInt.h index b220a31..c3989fd 100644 --- a/generic/tclInt.h +++ b/generic/tclInt.h @@ -2749,6 +2749,7 @@ MODULE_SCOPE ClientData tclTimeClientData; MODULE_SCOPE const Tcl_ObjType tclBignumType; MODULE_SCOPE const Tcl_ObjType tclBooleanType; MODULE_SCOPE const Tcl_ObjType tclByteArrayType; +MODULE_SCOPE const Tcl_ObjType tclPureByteArrayType; MODULE_SCOPE const Tcl_ObjType tclByteCodeType; MODULE_SCOPE const Tcl_ObjType tclDoubleType; MODULE_SCOPE const Tcl_ObjType tclIntType; @@ -4621,7 +4622,8 @@ MODULE_SCOPE void TclDbInitNewObj(Tcl_Obj *objPtr, const char *file, *---------------------------------------------------------------- */ -MODULE_SCOPE int TclIsPureByteArray(Tcl_Obj *objPtr); +#define TclIsPureByteArray(objPtr) \ + ((objPtr)->typePtr==&tclPureByteArrayType) #define TclIsPureDict(objPtr) \ (((objPtr)->bytes==NULL) && ((objPtr)->typePtr==&tclDictType)) #define TclFetchIntRep(objPtr, type) \ |