summaryrefslogtreecommitdiffstats
path: root/generic
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2007-03-21 18:02:49 (GMT)
committerdgp <dgp@users.sourceforge.net>2007-03-21 18:02:49 (GMT)
commit1daf7b251b3f3c433644a0298c902c1c3032aa4d (patch)
tree15313c19062f14adf25226dab2cc03675bf43831 /generic
parent02f9ee42d9908ad9e6c31c5c43aec3c3c65b3390 (diff)
downloadtcl-1daf7b251b3f3c433644a0298c902c1c3032aa4d.zip
tcl-1daf7b251b3f3c433644a0298c902c1c3032aa4d.tar.gz
tcl-1daf7b251b3f3c433644a0298c902c1c3032aa4d.tar.bz2
* generic/tclExecute.c: More ckalloc -> ckrealloc conversions.
* generic/tclLiteral.c: * generic/tclNamesp.c: * generic/tclParse.c: * generic/tclPreserve.c: * generic/tclStringObj.c: * generic/tclUtil.c:
Diffstat (limited to 'generic')
-rw-r--r--generic/tclNamesp.c33
-rw-r--r--generic/tclParse.c19
-rw-r--r--generic/tclPreserve.c22
-rw-r--r--generic/tclStringObj.c18
-rw-r--r--generic/tclUtil.c14
5 files changed, 40 insertions, 66 deletions
diff --git a/generic/tclNamesp.c b/generic/tclNamesp.c
index 34a449d..605a7d8 100644
--- a/generic/tclNamesp.c
+++ b/generic/tclNamesp.c
@@ -22,7 +22,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclNamesp.c,v 1.126 2007/03/12 19:10:49 dgp Exp $
+ * RCS: @(#) $Id: tclNamesp.c,v 1.127 2007/03/21 18:02:51 dgp Exp $
*/
#include "tclInt.h"
@@ -1307,21 +1307,12 @@ Tcl_Export(
*/
neededElems = nsPtr->numExportPatterns + 1;
- if (nsPtr->exportArrayPtr == NULL) {
- nsPtr->exportArrayPtr = (char **)
- ckalloc((unsigned) (INIT_EXPORT_PATTERNS * sizeof(char *)));
- nsPtr->numExportPatterns = 0;
- nsPtr->maxExportPatterns = INIT_EXPORT_PATTERNS;
- } else if (neededElems > nsPtr->maxExportPatterns) {
- int numNewElems = 2 * nsPtr->maxExportPatterns;
- size_t currBytes = nsPtr->numExportPatterns * sizeof(char *);
- size_t newBytes = numNewElems * sizeof(char *);
- char **newPtr = (char **) ckalloc((unsigned) newBytes);
-
- memcpy(newPtr, nsPtr->exportArrayPtr, currBytes);
- ckfree((char *) nsPtr->exportArrayPtr);
- nsPtr->exportArrayPtr = (char **) newPtr;
- nsPtr->maxExportPatterns = numNewElems;
+ if (neededElems > nsPtr->maxExportPatterns) {
+ nsPtr->maxExportPatterns = nsPtr->maxExportPatterns ?
+ 2 * nsPtr->maxExportPatterns : INIT_EXPORT_PATTERNS;
+ nsPtr->exportArrayPtr = (char **) ckrealloc(
+ (char *)nsPtr->exportArrayPtr,
+ sizeof(char *) * nsPtr->maxExportPatterns);
}
/*
@@ -2763,13 +2754,15 @@ TclResetShadowedCmdRefs(
size_t currBytes = trailSize * sizeof(Namespace *);
int newSize = 2 * trailSize;
size_t newBytes = newSize * sizeof(Namespace *);
- Namespace **newPtr = (Namespace **) ckalloc((unsigned) newBytes);
- memcpy(newPtr, trailPtr, currBytes);
if (trailPtr != trailStorage) {
- ckfree((char *) trailPtr);
+ trailPtr = (Namespace **) ckrealloc((char *) trailPtr,
+ newBytes);
+ } else {
+ Namespace **newPtr = (Namespace **) ckalloc(newBytes);
+ memcpy(newPtr, trailPtr, currBytes);
+ trailPtr = newPtr;
}
- trailPtr = newPtr;
trailSize = newSize;
}
trailPtr[trailFront] = nsPtr;
diff --git a/generic/tclParse.c b/generic/tclParse.c
index 07b88c6..51e0306 100644
--- a/generic/tclParse.c
+++ b/generic/tclParse.c
@@ -12,7 +12,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclParse.c,v 1.49 2006/11/28 22:20:29 andreas_kupries Exp $
+ * RCS: @(#) $Id: tclParse.c,v 1.50 2007/03/21 18:02:51 dgp Exp $
*/
#include "tclInt.h"
@@ -1181,17 +1181,18 @@ TclExpandTokenArray(
Tcl_Parse *parsePtr) /* Parse structure whose token space has
* overflowed. */
{
- int newCount;
- Tcl_Token *newPtr;
+ int newCount = parsePtr->tokensAvailable*2;
- newCount = parsePtr->tokensAvailable*2;
- newPtr = (Tcl_Token *) ckalloc((unsigned) (newCount * sizeof(Tcl_Token)));
- memcpy((VOID *) newPtr, (VOID *) parsePtr->tokenPtr,
- (size_t) (parsePtr->tokensAvailable * sizeof(Tcl_Token)));
if (parsePtr->tokenPtr != parsePtr->staticTokens) {
- ckfree((char *) parsePtr->tokenPtr);
+ parsePtr->tokenPtr = (Tcl_Token *) ckrealloc ((char *)
+ (parsePtr->tokenPtr), newCount * sizeof(Tcl_Token));
+ } else {
+ Tcl_Token *newPtr = (Tcl_Token *) ckalloc(
+ newCount * sizeof(Tcl_Token));
+ memcpy(newPtr, parsePtr->tokenPtr,
+ (size_t) (parsePtr->tokensAvailable * sizeof(Tcl_Token)));
+ parsePtr->tokenPtr = newPtr;
}
- parsePtr->tokenPtr = newPtr;
parsePtr->tokensAvailable = newCount;
}
diff --git a/generic/tclPreserve.c b/generic/tclPreserve.c
index a721bb7..3c991ea 100644
--- a/generic/tclPreserve.c
+++ b/generic/tclPreserve.c
@@ -11,7 +11,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclPreserve.c,v 1.9 2006/08/10 12:15:31 dkf Exp $
+ * RCS: @(#) $Id: tclPreserve.c,v 1.10 2007/03/21 18:02:51 dgp Exp $
*/
#include "tclInt.h"
@@ -38,7 +38,7 @@ typedef struct {
* These variables are protected by "preserveMutex".
*/
-static Reference *refArray; /* First in array of references. */
+static Reference *refArray = NULL; /* First in array of references. */
static int spaceAvl = 0; /* Total number of structures available at
* *firstRefPtr. */
static int inUse = 0; /* Count of structures currently in use in
@@ -145,21 +145,9 @@ Tcl_Preserve(
*/
if (inUse == spaceAvl) {
- if (spaceAvl == 0) {
- refArray = (Reference *) ckalloc((unsigned)
- (INITIAL_SIZE*sizeof(Reference)));
- spaceAvl = INITIAL_SIZE;
- } else {
- Reference *new;
-
- new = (Reference *) ckalloc((unsigned)
- (2*spaceAvl*sizeof(Reference)));
- memcpy((void *) new, (void *) refArray,
- spaceAvl*sizeof(Reference));
- ckfree((char *) refArray);
- refArray = new;
- spaceAvl *= 2;
- }
+ spaceAvl = spaceAvl ? 2*spaceAvl : INITIAL_SIZE;
+ refArray = (Reference *) ckrealloc((char *) refArray,
+ spaceAvl * sizeof(Reference));
}
/*
diff --git a/generic/tclStringObj.c b/generic/tclStringObj.c
index ea76330..f3aa3ab 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.63 2006/11/15 20:08:45 dgp Exp $ */
+ * RCS: @(#) $Id: tclStringObj.c,v 1.64 2007/03/21 18:02:51 dgp Exp $ */
#include "tclInt.h"
#include "tommath.h"
@@ -761,25 +761,24 @@ Tcl_SetObjLength(
if (length > (int) stringPtr->allocated &&
(objPtr->bytes != NULL || stringPtr->hasUnicode == 0)) {
- char *new;
/*
* Not enough space in current string. Reallocate the string space and
* free the old string.
*/
- if (objPtr->bytes != tclEmptyStringRep && objPtr->bytes != NULL) {
- new = (char *) ckrealloc((char *)objPtr->bytes,
+ if (objPtr->bytes != tclEmptyStringRep) {
+ objPtr->bytes = ckrealloc((char *)objPtr->bytes,
(unsigned)(length+1));
} else {
- new = (char *) ckalloc((unsigned) (length+1));
+ char *new = ckalloc((unsigned) (length+1));
if (objPtr->bytes != NULL && objPtr->length != 0) {
memcpy((void *) new, (void *) objPtr->bytes,
(size_t) objPtr->length);
Tcl_InvalidateStringRep(objPtr);
}
+ objPtr->bytes = new;
}
- objPtr->bytes = new;
stringPtr->allocated = length;
/*
@@ -884,14 +883,13 @@ Tcl_AttemptSetObjLength(
* free the old string.
*/
- if (objPtr->bytes != tclEmptyStringRep && objPtr->bytes != NULL) {
- new = (char *) attemptckrealloc((char *)objPtr->bytes,
- (unsigned)(length+1));
+ if (objPtr->bytes != tclEmptyStringRep) {
+ new = attemptckrealloc(objPtr->bytes, (unsigned)(length+1));
if (new == NULL) {
return 0;
}
} else {
- new = (char *) attemptckalloc((unsigned) (length+1));
+ new = attemptckalloc((unsigned) (length+1));
if (new == NULL) {
return 0;
}
diff --git a/generic/tclUtil.c b/generic/tclUtil.c
index d63be29..adced82 100644
--- a/generic/tclUtil.c
+++ b/generic/tclUtil.c
@@ -11,7 +11,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclUtil.c,v 1.80 2007/01/18 23:17:07 dkf Exp $
+ * RCS: @(#) $Id: tclUtil.c,v 1.81 2007/03/21 18:02:51 dgp Exp $
*/
#include "tclInt.h"
@@ -1598,9 +1598,7 @@ Tcl_DStringAppend(
if (newSize >= dsPtr->spaceAvl) {
dsPtr->spaceAvl = newSize * 2;
if (dsPtr->string == dsPtr->staticSpace) {
- char *newString;
-
- newString = (char *) ckalloc((unsigned) dsPtr->spaceAvl);
+ char *newString = ckalloc((unsigned) dsPtr->spaceAvl);
memcpy((void *) newString, (void *) dsPtr->string,
(size_t) dsPtr->length);
dsPtr->string = newString;
@@ -1665,9 +1663,7 @@ Tcl_DStringAppendElement(
if (newSize >= dsPtr->spaceAvl) {
dsPtr->spaceAvl = newSize * 2;
if (dsPtr->string == dsPtr->staticSpace) {
- char *newString;
-
- newString = (char *) ckalloc((unsigned) dsPtr->spaceAvl);
+ char *newString = ckalloc((unsigned) dsPtr->spaceAvl);
memcpy((void *) newString, (void *) dsPtr->string,
(size_t) dsPtr->length);
dsPtr->string = newString;
@@ -1749,9 +1745,7 @@ Tcl_DStringSetLength(
dsPtr->spaceAvl = length + 1;
}
if (dsPtr->string == dsPtr->staticSpace) {
- char *newString;
-
- newString = (char *) ckalloc((unsigned) dsPtr->spaceAvl);
+ char *newString = ckalloc((unsigned) dsPtr->spaceAvl);
memcpy((void *) newString, (void *) dsPtr->string,
(size_t) dsPtr->length);
dsPtr->string = newString;