diff options
Diffstat (limited to 'generic/tclEncoding.c')
| -rw-r--r-- | generic/tclEncoding.c | 102 | 
1 files changed, 52 insertions, 50 deletions
| diff --git a/generic/tclEncoding.c b/generic/tclEncoding.c index a34f193..d246cb2 100644 --- a/generic/tclEncoding.c +++ b/generic/tclEncoding.c @@ -7,8 +7,6 @@   *   * See the file "license.terms" for information on usage and redistribution of   * this file, and for a DISCLAIMER OF ALL WARRANTIES. - * - * RCS: @(#) $Id: tclEncoding.c,v 1.69 2010/02/05 11:47:22 dkf Exp $   */  #include "tclInt.h" @@ -184,6 +182,7 @@ TCL_DECLARE_MUTEX(encodingMutex)  static Tcl_Encoding defaultEncoding;  static Tcl_Encoding systemEncoding; +Tcl_Encoding tclIdentityEncoding;  /*   * The following variable is used in the sparse matrix code for a @@ -272,7 +271,7 @@ static int		Iso88591ToUtfProc(ClientData clientData,  			    int *dstCharsPtr);  /* - * A Tcl_ObjType for holding a cached Tcl_Encoding in the otherValuePtr field + * A Tcl_ObjType for holding a cached Tcl_Encoding in the twoPtrValue.ptr1 field   * of the intrep. This should help the lifetime of encodings be more useful.   * See concerns raised in [Bug 1077262].   */ @@ -295,7 +294,7 @@ static const Tcl_ObjType encodingType = {   *	Standard Tcl return code.   *   * Side effects: - * 	Caches the Tcl_Encoding value as the internal rep of (*objPtr). + *	Caches the Tcl_Encoding value as the internal rep of (*objPtr).   *   *----------------------------------------------------------------------   */ @@ -315,7 +314,7 @@ Tcl_GetEncodingFromObj(  	    return TCL_ERROR;  	}  	TclFreeIntRep(objPtr); -	objPtr->internalRep.otherValuePtr = encoding; +	objPtr->internalRep.twoPtrValue.ptr1 = encoding;  	objPtr->typePtr = &encodingType;      }      *encodingPtr = Tcl_GetEncoding(NULL, name); @@ -336,7 +335,7 @@ static void  FreeEncodingIntRep(      Tcl_Obj *objPtr)  { -    Tcl_FreeEncoding(objPtr->internalRep.otherValuePtr); +    Tcl_FreeEncoding(objPtr->internalRep.twoPtrValue.ptr1);      objPtr->typePtr = NULL;  } @@ -355,7 +354,7 @@ DupEncodingIntRep(      Tcl_Obj *srcPtr,      Tcl_Obj *dupPtr)  { -    dupPtr->internalRep.otherValuePtr = Tcl_GetEncoding(NULL, srcPtr->bytes); +    dupPtr->internalRep.twoPtrValue.ptr1 = Tcl_GetEncoding(NULL, srcPtr->bytes);  }  /* @@ -454,8 +453,8 @@ TclSetLibraryPath(   *   * FillEncodingFileMap --   * - * 	Called to bring the encoding file map in sync with the current value - * 	of the encoding search path. + *	Called to bring the encoding file map in sync with the current value + *	of the encoding search path.   *   *	Scan the directories on the encoding search path, find the *.enc   *	files, and store the found pathnames in a map associated with the @@ -569,7 +568,7 @@ TclInitEncodingSubsystem(void)      type.freeProc	= NULL;      type.nullSize	= 1;      type.clientData	= NULL; -    Tcl_CreateEncoding(&type); +    tclIdentityEncoding = Tcl_CreateEncoding(&type);      type.encodingName	= "utf-8";      type.toUtfProc	= UtfExtToUtfIntProc; @@ -594,14 +593,14 @@ TclInitEncodingSubsystem(void)       * code to duplicate the structure of a table encoding here.       */ -    dataPtr = (TableEncodingData *) ckalloc(sizeof(TableEncodingData)); +    dataPtr = ckalloc(sizeof(TableEncodingData));      memset(dataPtr, 0, sizeof(TableEncodingData));      dataPtr->fallback = '?';      size = 256*(sizeof(unsigned short *) + sizeof(unsigned short)); -    dataPtr->toUnicode = (unsigned short **) ckalloc(size); +    dataPtr->toUnicode = ckalloc(size);      memset(dataPtr->toUnicode, 0, size); -    dataPtr->fromUnicode = (unsigned short **) ckalloc(size); +    dataPtr->fromUnicode = ckalloc(size);      memset(dataPtr->fromUnicode, 0, size);      dataPtr->toUnicode[0] = (unsigned short *) (dataPtr->toUnicode + 256); @@ -653,6 +652,7 @@ TclFinalizeEncodingSubsystem(void)      Tcl_MutexLock(&encodingMutex);      encodingsInitialized = 0;      FreeEncoding(systemEncoding); +    FreeEncoding(tclIdentityEncoding);      hPtr = Tcl_FirstHashEntry(&encodingTable, &search);      while (hPtr != NULL) { @@ -676,15 +676,15 @@ TclFinalizeEncodingSubsystem(void)   *   * Tcl_GetDefaultEncodingDir --   * - * 	Legacy public interface to retrieve first directory in the encoding - * 	searchPath. + *	Legacy public interface to retrieve first directory in the encoding + *	searchPath.   *   * Results:   *	The directory pathname, as a string, or NULL for an empty encoding   *	search path.   *   * Side effects: - * 	None. + *	None.   *   *-------------------------------------------------------------------------   */ @@ -709,14 +709,14 @@ Tcl_GetDefaultEncodingDir(void)   *   * Tcl_SetDefaultEncodingDir --   * - * 	Legacy public interface to set the first directory in the encoding - * 	search path. + *	Legacy public interface to set the first directory in the encoding + *	search path.   *   * Results: - * 	None. + *	None.   *   * Side effects: - * 	Modifies the encoding search path. + *	Modifies the encoding search path.   *   *-------------------------------------------------------------------------   */ @@ -776,7 +776,7 @@ Tcl_GetEncoding(      hPtr = Tcl_FindHashEntry(&encodingTable, name);      if (hPtr != NULL) { -	encodingPtr = (Encoding *) Tcl_GetHashValue(hPtr); +	encodingPtr = Tcl_GetHashValue(hPtr);  	encodingPtr->refCount++;  	Tcl_MutexUnlock(&encodingMutex);  	return (Tcl_Encoding) encodingPtr; @@ -851,8 +851,8 @@ FreeEncoding(  	if (encodingPtr->hPtr != NULL) {  	    Tcl_DeleteHashEntry(encodingPtr->hPtr);  	} -	ckfree((char *) encodingPtr->name); -	ckfree((char *) encodingPtr); +	ckfree(encodingPtr->name); +	ckfree(encodingPtr);      }  } @@ -925,7 +925,7 @@ Tcl_GetEncodingNames(  	Encoding *encodingPtr = Tcl_GetHashValue(hPtr);  	Tcl_CreateHashEntry(&table, -		(char *) Tcl_NewStringObj(encodingPtr->name, -1), &dummy); +		Tcl_NewStringObj(encodingPtr->name, -1), &dummy);      }      Tcl_MutexUnlock(&encodingMutex); @@ -938,7 +938,7 @@ Tcl_GetEncodingNames(      Tcl_DictObjFirst(NULL, map, &mapSearch, &name, NULL, &done);      for (; !done; Tcl_DictObjNext(&mapSearch, &name, NULL, &done)) { -	Tcl_CreateHashEntry(&table, (char *) name, &dummy); +	Tcl_CreateHashEntry(&table, name, &dummy);      }      /* @@ -981,13 +981,13 @@ Tcl_GetEncodingNames(  int  Tcl_SetSystemEncoding(      Tcl_Interp *interp,		/* Interp for error reporting, if not NULL. */ -    const char *name)		/* The name of the desired encoding, or NULL +    const char *name)		/* The name of the desired encoding, or NULL/""  				 * to reset to default encoding. */  {      Tcl_Encoding encoding;      Encoding *encodingPtr; -    if (name == NULL) { +    if (!name || !*name) {  	Tcl_MutexLock(&encodingMutex);  	encoding = defaultEncoding;  	encodingPtr = (Encoding *) encoding; @@ -1056,9 +1056,9 @@ Tcl_CreateEncoding(  	encodingPtr->hPtr = NULL;      } -    name = ckalloc((unsigned) strlen(typePtr->encodingName) + 1); +    name = ckalloc(strlen(typePtr->encodingName) + 1); -    encodingPtr = (Encoding *) ckalloc(sizeof(Encoding)); +    encodingPtr = ckalloc(sizeof(Encoding));      encodingPtr->name		= strcpy(name, typePtr->encodingName);      encodingPtr->toUtfProc	= typePtr->toUtfProc;      encodingPtr->fromUtfProc	= typePtr->fromUtfProc; @@ -1427,7 +1427,7 @@ Tcl_UtfToExternal(   *   *---------------------------------------------------------------------------   */ - +#undef Tcl_FindExecutable  void  Tcl_FindExecutable(      const char *argv0)		/* The value of the application's argv[0] @@ -1446,9 +1446,9 @@ Tcl_FindExecutable(   *	Open the file believed to hold data for the encoding, "name".   *   * Results: - * 	Returns the readable Tcl_Channel from opening the file, or NULL if the - * 	file could not be successfully opened. If NULL was returned, an error - * 	message is left in interp's result object, unless interp was NULL. + *	Returns the readable Tcl_Channel from opening the file, or NULL if the + *	file could not be successfully opened. If NULL was returned, an error + *	message is left in interp's result object, unless interp was NULL.   *   * Side effects:   *	Channel may be opened. Information about the filesystem may be cached @@ -1544,7 +1544,8 @@ OpenEncodingFileChannel(      }      if ((NULL == chan) && (interp != NULL)) { -	Tcl_AppendResult(interp, "unknown encoding \"", name, "\"", NULL); +	Tcl_SetObjResult(interp, Tcl_ObjPrintf( +		"unknown encoding \"%s\"", name));  	Tcl_SetErrorCode(interp, "TCL", "LOOKUP", "ENCODING", name, NULL);      }      Tcl_DecrRefCount(fileNameObj); @@ -1618,7 +1619,8 @@ LoadEncodingFile(  	break;      }      if ((encoding == NULL) && (interp != NULL)) { -	Tcl_AppendResult(interp, "invalid encoding file \"", name, "\"", NULL); +	Tcl_SetObjResult(interp, Tcl_ObjPrintf( +		"invalid encoding file \"%s\"", name));  	Tcl_SetErrorCode(interp, "TCL", "LOOKUP", "ENCODING", name, NULL);      }      Tcl_Close(NULL, chan); @@ -1709,7 +1711,7 @@ LoadTableEncoding(  #undef PAGESIZE  #define PAGESIZE    (256 * sizeof(unsigned short)) -    dataPtr = (TableEncodingData *) ckalloc(sizeof(TableEncodingData)); +    dataPtr = ckalloc(sizeof(TableEncodingData));      memset(dataPtr, 0, sizeof(TableEncodingData));      dataPtr->fallback = fallback; @@ -1721,7 +1723,7 @@ LoadTableEncoding(       */      size = 256 * sizeof(unsigned short *) + numPages * PAGESIZE; -    dataPtr->toUnicode = (unsigned short **) ckalloc(size); +    dataPtr->toUnicode = ckalloc(size);      memset(dataPtr->toUnicode, 0, size);      pageMemPtr = (unsigned short *) (dataPtr->toUnicode + 256); @@ -1779,7 +1781,7 @@ LoadTableEncoding(  	}      }      size = 256 * sizeof(unsigned short *) + numPages * PAGESIZE; -    dataPtr->fromUnicode = (unsigned short **) ckalloc(size); +    dataPtr->fromUnicode = ckalloc(size);      memset(dataPtr->fromUnicode, 0, size);      pageMemPtr = (unsigned short *) (dataPtr->fromUnicode + 256); @@ -1874,9 +1876,9 @@ LoadTableEncoding(       * Read lines from the encoding until EOF.       */ -    for (Tcl_DStringSetLength(&lineString, 0); +    for (TclDStringClear(&lineString);  	    (len = Tcl_Gets(chan, &lineString)) >= 0; -	    Tcl_DStringSetLength(&lineString, 0)) { +	    TclDStringClear(&lineString)) {  	const unsigned char *p;  	int to, from; @@ -2011,17 +2013,17 @@ LoadEscapeEncoding(  		Tcl_DStringAppend(&escapeData, (char *) &est, sizeof(est));  	    }  	} -	ckfree((char *) argv); +	ckfree(argv);  	Tcl_DStringFree(&lineString);      }      size = sizeof(EscapeEncodingData) - sizeof(EscapeSubTable)  	    + Tcl_DStringLength(&escapeData); -    dataPtr = (EscapeEncodingData *) ckalloc(size); +    dataPtr = ckalloc(size);      dataPtr->initLen = strlen(init); -    strcpy(dataPtr->init, init); +    memcpy(dataPtr->init, init, (unsigned) dataPtr->initLen + 1);      dataPtr->finalLen = strlen(final); -    strcpy(dataPtr->final, final); +    memcpy(dataPtr->final, final, (unsigned) dataPtr->finalLen + 1);      dataPtr->numSubTables =  	    Tcl_DStringLength(&escapeData) / sizeof(EscapeSubTable);      memcpy(dataPtr->subTables, Tcl_DStringValue(&escapeData), @@ -2957,9 +2959,9 @@ TableFreeProc(       * Make sure we aren't freeing twice on shutdown. [Bug 219314]       */ -    ckfree((char *) dataPtr->toUnicode); -    ckfree((char *) dataPtr->fromUnicode); -    ckfree((char *) dataPtr); +    ckfree(dataPtr->toUnicode); +    ckfree(dataPtr->fromUnicode); +    ckfree(dataPtr);  }  /* @@ -3288,7 +3290,7 @@ EscapeFromUtfProc(  	    for (state = 0; state < dataPtr->numSubTables; state++) {  		encodingPtr = GetTableEncoding(dataPtr, state);  		tableDataPtr = encodingPtr->clientData; -	    	word = tableDataPtr->fromUnicode[(ch >> 8)][ch & 0xff]; +		word = tableDataPtr->fromUnicode[(ch >> 8)][ch & 0xff];  		if (word != 0) {  		    break;  		} @@ -3434,7 +3436,7 @@ EscapeFreeProc(  	    subTablePtr++;  	}      } -    ckfree((char *) dataPtr); +    ckfree(dataPtr);  }  /* @@ -3572,7 +3574,7 @@ InitializeEncodingSearchPath(      bytes = Tcl_GetStringFromObj(searchPathObj, &numBytes);      *lengthPtr = numBytes; -    *valuePtr = ckalloc((unsigned) numBytes + 1); +    *valuePtr = ckalloc(numBytes + 1);      memcpy(*valuePtr, bytes, (size_t) numBytes + 1);      Tcl_DecrRefCount(searchPathObj);  } | 
