summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2009-02-17 21:40:48 (GMT)
committerdgp <dgp@users.sourceforge.net>2009-02-17 21:40:48 (GMT)
commit72ccff69bc0257f9100758149d569b6299654067 (patch)
tree8e603cd497ab3874a9afa85dedd7ab1c8ce90b68
parent2a06ac14dadfef67de933e930cfec32263642fef (diff)
downloadtcl-72ccff69bc0257f9100758149d569b6299654067.zip
tcl-72ccff69bc0257f9100758149d569b6299654067.tar.gz
tcl-72ccff69bc0257f9100758149d569b6299654067.tar.bz2
* generic/tclStringObj.c: Pare back the length of the unicode
array in a non-extended String struct to one Tcl_UniChar, meant to hold the terminating NUL character. Non-empty unicode strings are then stored by extending the String struct by stringPtr->maxChars additional slots in that array with sizeof(Tcl_UniChar) bytes per slot. This revision makes the allocation macros much simpler.
-rw-r--r--ChangeLog7
-rw-r--r--generic/tclStringObj.c22
2 files changed, 17 insertions, 12 deletions
diff --git a/ChangeLog b/ChangeLog
index fb11b08..7509a02 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -6,6 +6,13 @@
2009-02-17 Don Porter <dgp@users.sourceforge.net>
+ * generic/tclStringObj.c: Pare back the length of the unicode
+ array in a non-extended String struct to one Tcl_UniChar, meant to
+ hold the terminating NUL character. Non-empty unicode strings are
+ then stored by extending the String struct by stringPtr->maxChars
+ additional slots in that array with sizeof(Tcl_UniChar) bytes per slot.
+ This revision makes the allocation macros much simpler.
+
* generic/tclStringObj.c: Factor out common GrowUnicodeBuffer()
and solve overflow and growth algorithm fallbacks in it.
diff --git a/generic/tclStringObj.c b/generic/tclStringObj.c
index d79a565..a4968d6 100644
--- a/generic/tclStringObj.c
+++ b/generic/tclStringObj.c
@@ -33,7 +33,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclStringObj.c,v 1.112 2009/02/17 21:05:41 dgp Exp $ */
+ * RCS: @(#) $Id: tclStringObj.c,v 1.113 2009/02/17 21:40:48 dgp Exp $ */
#include "tclInt.h"
#include "tommath.h"
@@ -109,7 +109,7 @@ typedef struct String {
* space allocated for the unicode array. */
int hasUnicode; /* Boolean determining whether the string has
* a Unicode representation. */
- Tcl_UniChar unicode[2]; /* The array of Unicode chars. The actual size
+ Tcl_UniChar unicode[1]; /* The array of Unicode chars. The actual size
* of this field depends on the 'maxChars'
* field above. */
} String;
@@ -117,25 +117,23 @@ typedef struct String {
#define STRING_UALLOC(numChars) \
((numChars) * sizeof(Tcl_UniChar))
#define STRING_SIZE(numBytes) \
- (sizeof(String) - sizeof(Tcl_UniChar) + (numBytes))
+ (sizeof(String) + (numBytes))
#define STRING_NOMEM(numBytes) \
(Tcl_Panic("unable to alloc %u bytes", STRING_SIZE(numBytes)), \
(char *) NULL)
#define stringAlloc(numBytes) \
- (String *) (((numBytes) > INT_MAX - STRING_SIZE(0)) \
+ (String *) (((numBytes) > INT_MAX - sizeof(String)) \
? STRING_NOMEM(numBytes) \
- : ckalloc((unsigned) STRING_SIZE( \
- (numBytes) ? (numBytes) : sizeof(Tcl_UniChar)) ))
+ : ckalloc((unsigned) STRING_SIZE(numBytes) ))
#define stringRealloc(ptr, numBytes) \
- (String *) (((numBytes) > INT_MAX - STRING_SIZE(0)) \
+ (String *) (((numBytes) > INT_MAX - sizeof(String)) \
? STRING_NOMEM(numBytes) \
- : ckrealloc((char *) ptr, (unsigned) STRING_SIZE( \
- (numBytes) ? (numBytes) : sizeof(Tcl_UniChar)) ))
+ : ckrealloc((char *) ptr, (unsigned) STRING_SIZE(numBytes) ))
#define stringAttemptRealloc(ptr, numBytes) \
- (String *) (((numBytes) > INT_MAX - STRING_SIZE(0)) \
+ (String *) (((numBytes) > INT_MAX - sizeof(String)) \
? NULL \
- : attemptckrealloc((char *) ptr, (unsigned) STRING_SIZE( \
- (numBytes) ? (numBytes) : sizeof(Tcl_UniChar)) ))
+ : attemptckrealloc((char *) ptr, \
+ (unsigned) STRING_SIZE(numBytes) ))
#define GET_STRING(objPtr) \
((String *) (objPtr)->internalRep.otherValuePtr)
#define SET_STRING(objPtr, stringPtr) \