diff options
author | dgp <dgp@users.sourceforge.net> | 2017-10-24 23:16:23 (GMT) |
---|---|---|
committer | dgp <dgp@users.sourceforge.net> | 2017-10-24 23:16:23 (GMT) |
commit | 1552384787fef03116569d8281bc0a69a02d6e3f (patch) | |
tree | 2a9e8acdbdfb4744ba33efc99c6338a5cf637c1c /generic/tclEncoding.c | |
parent | 319b71965b6c3a38ef712ac4e6b58fa7dae7e6f4 (diff) | |
download | tcl-1552384787fef03116569d8281bc0a69a02d6e3f.zip tcl-1552384787fef03116569d8281bc0a69a02d6e3f.tar.gz tcl-1552384787fef03116569d8281bc0a69a02d6e3f.tar.bz2 |
Extend Tcl_CreateEncoding() to be able to create an encoding without
registering it when it has no name. Then use this to create "identity"
encoding without naming it "identity". Then no one can look it up by that name.
Diffstat (limited to 'generic/tclEncoding.c')
-rw-r--r-- | generic/tclEncoding.c | 38 |
1 files changed, 21 insertions, 17 deletions
diff --git a/generic/tclEncoding.c b/generic/tclEncoding.c index e328340..f43c0e1 100644 --- a/generic/tclEncoding.c +++ b/generic/tclEncoding.c @@ -563,7 +563,7 @@ TclInitEncodingSubsystem(void) * formed UTF-8 into a properly formed stream. */ - type.encodingName = "identity"; + type.encodingName = NULL; type.toUtfProc = BinaryProc; type.fromUtfProc = BinaryProc; type.freeProc = NULL; @@ -851,7 +851,9 @@ FreeEncoding( if (encodingPtr->hPtr != NULL) { Tcl_DeleteHashEntry(encodingPtr->hPtr); } - ckfree(encodingPtr->name); + if (encodingPtr->name) { + ckfree(encodingPtr->name); + } ckfree(encodingPtr); } } @@ -1040,9 +1042,24 @@ Tcl_CreateEncoding( const Tcl_EncodingType *typePtr) /* The encoding type. */ { + Encoding *encodingPtr = ckalloc(sizeof(Encoding)); + encodingPtr->name = NULL; + encodingPtr->toUtfProc = typePtr->toUtfProc; + encodingPtr->fromUtfProc = typePtr->fromUtfProc; + encodingPtr->freeProc = typePtr->freeProc; + encodingPtr->nullSize = typePtr->nullSize; + encodingPtr->clientData = typePtr->clientData; + if (typePtr->nullSize == 1) { + encodingPtr->lengthProc = (LengthProc *) strlen; + } else { + encodingPtr->lengthProc = (LengthProc *) unilen; + } + encodingPtr->refCount = 1; + encodingPtr->hPtr = NULL; + + if (typePtr->encodingName) { Tcl_HashEntry *hPtr; int isNew; - Encoding *encodingPtr; char *name; Tcl_MutexLock(&encodingMutex); @@ -1058,25 +1075,12 @@ Tcl_CreateEncoding( } name = ckalloc(strlen(typePtr->encodingName) + 1); - - encodingPtr = ckalloc(sizeof(Encoding)); encodingPtr->name = strcpy(name, typePtr->encodingName); - encodingPtr->toUtfProc = typePtr->toUtfProc; - encodingPtr->fromUtfProc = typePtr->fromUtfProc; - encodingPtr->freeProc = typePtr->freeProc; - encodingPtr->nullSize = typePtr->nullSize; - encodingPtr->clientData = typePtr->clientData; - if (typePtr->nullSize == 1) { - encodingPtr->lengthProc = (LengthProc *) strlen; - } else { - encodingPtr->lengthProc = (LengthProc *) unilen; - } - encodingPtr->refCount = 1; encodingPtr->hPtr = hPtr; Tcl_SetHashValue(hPtr, encodingPtr); Tcl_MutexUnlock(&encodingMutex); - + } return (Tcl_Encoding) encodingPtr; } |