summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordkf <donal.k.fellows@manchester.ac.uk>2011-01-01 10:49:09 (GMT)
committerdkf <donal.k.fellows@manchester.ac.uk>2011-01-01 10:49:09 (GMT)
commitda1eee73c7323e2f858ee6556938bdfb31e6bc0e (patch)
tree244c419663f8544c29dfa4e7c7b5ddc49644d6a0
parent841cf21cd27b778487c1996e20f5dffff6052acd (diff)
downloadtcl-da1eee73c7323e2f858ee6556938bdfb31e6bc0e.zip
tcl-da1eee73c7323e2f858ee6556938bdfb31e6bc0e.tar.gz
tcl-da1eee73c7323e2f858ee6556938bdfb31e6bc0e.tar.bz2
* generic/tclCmdIL.c (SortElement): Use unions properly in the
definition of this structure so that there is no need to use nasty int/pointer type punning. Made it clearer what the purposes of the various parts of the structure are.
-rw-r--r--ChangeLog19
-rw-r--r--generic/tclCmdIL.c53
2 files changed, 41 insertions, 31 deletions
diff --git a/ChangeLog b/ChangeLog
index cf15d77..70f1301 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,14 +1,21 @@
+2010-12-31 Donal K. Fellows <dkf@users.sf.net>
+
+ * generic/tclCmdIL.c (SortElement): Use unions properly in the
+ definition of this structure so that there is no need to use nasty
+ int/pointer type punning. Made it clearer what the purposes of the
+ various parts of the structure are.
+
2010-12-31 Jan Nijtmans <nijtmans@users.sf.net>
- * unix/dltest/*.c: Fix [Bug 3148192]: [load] broken. Assure that
- those files are never compiled with -DSTATIC_BUILD
+ * unix/dltest/*.c: [Bug 3148192]: Fix broken [load] tests by ensuring
+ that the affected files are never compiled with -DSTATIC_BUILD.
2010-12-30 Miguel Sofer <msofer@users.sf.net>
- * generic/tclExecute.c (GrowEvaluationStack): off-by-one error in
- sizing the new allocation - was ok in comment but wrong in the
- code. Triggered by [Bug 3142026] which happened to require
- exactly one more than what was in existence.
+ * generic/tclExecute.c (GrowEvaluationStack): Off-by-one error in
+ sizing the new allocation - was ok in comment but wrong in the code.
+ Triggered by [Bug 3142026] which happened to require exactly one more
+ than what was in existence.
2010-12-26 Donal K. Fellows <dkf@users.sf.net>
diff --git a/generic/tclCmdIL.c b/generic/tclCmdIL.c
index 5cef561..ffb8b98 100644
--- a/generic/tclCmdIL.c
+++ b/generic/tclCmdIL.c
@@ -16,7 +16,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclCmdIL.c,v 1.187 2010/12/27 00:01:07 dkf Exp $
+ * RCS: @(#) $Id: tclCmdIL.c,v 1.188 2011/01/01 10:49:09 dkf Exp $
*/
#include "tclInt.h"
@@ -29,13 +29,16 @@
*/
typedef struct SortElement {
- union {
+ union { /* The value that we sorting by. */
const char *strValuePtr;
long intValue;
double doubleValue;
Tcl_Obj *objValuePtr;
- } index;
- Tcl_Obj *objPtr; /* Object being sorted, or its index. */
+ } collationKey;
+ union { /* Object being sorted, or its index. */
+ Tcl_Obj *objPtr;
+ int index;
+ } payload;
struct SortElement *nextPtr;/* Next element in the list, or NULL for end
* of list. */
} SortElement;
@@ -3922,7 +3925,7 @@ Tcl_LsortObjCmd(
*/
if (sortMode == SORTMODE_ASCII) {
- elementArray[i].index.strValuePtr = TclGetString(indexPtr);
+ elementArray[i].collationKey.strValuePtr = TclGetString(indexPtr);
} else if (sortMode == SORTMODE_INTEGER) {
long a;
@@ -3930,7 +3933,7 @@ Tcl_LsortObjCmd(
sortInfo.resultCode = TCL_ERROR;
goto done1;
}
- elementArray[i].index.intValue = a;
+ elementArray[i].collationKey.intValue = a;
} else if (sortInfo.sortMode == SORTMODE_REAL) {
double a;
@@ -3939,9 +3942,9 @@ Tcl_LsortObjCmd(
sortInfo.resultCode = TCL_ERROR;
goto done1;
}
- elementArray[i].index.doubleValue = a;
+ elementArray[i].collationKey.doubleValue = a;
} else {
- elementArray[i].index.objValuePtr = indexPtr;
+ elementArray[i].collationKey.objValuePtr = indexPtr;
}
/*
@@ -3950,9 +3953,9 @@ Tcl_LsortObjCmd(
*/
if (indices || group) {
- elementArray[i].objPtr = INT2PTR(idx);
+ elementArray[i].payload.index = idx;
} else {
- elementArray[i].objPtr = listObjPtrs[idx];
+ elementArray[i].payload.objPtr = listObjPtrs[idx];
}
/*
@@ -3994,7 +3997,7 @@ Tcl_LsortObjCmd(
newArray = &listRepPtr->elements;
if (group) {
for (i=0; elementPtr!=NULL ; elementPtr=elementPtr->nextPtr) {
- idx = PTR2INT(elementPtr->objPtr);
+ idx = elementPtr->payload.index;
for (j = 0; j < groupSize; j++) {
if (indices) {
objPtr = Tcl_NewIntObj(idx + j - groupOffset);
@@ -4009,13 +4012,13 @@ Tcl_LsortObjCmd(
}
} else if (indices) {
for (i=0; elementPtr != NULL ; elementPtr = elementPtr->nextPtr) {
- objPtr = Tcl_NewIntObj(PTR2INT(elementPtr->objPtr));
+ objPtr = Tcl_NewIntObj(elementPtr->payload.index);
newArray[i++] = objPtr;
Tcl_IncrRefCount(objPtr);
}
} else {
for (i=0; elementPtr != NULL ; elementPtr = elementPtr->nextPtr) {
- objPtr = elementPtr->objPtr;
+ objPtr = elementPtr->payload.objPtr;
newArray[i++] = objPtr;
Tcl_IncrRefCount(objPtr);
}
@@ -4170,25 +4173,25 @@ SortCompare(
int order = 0;
if (infoPtr->sortMode == SORTMODE_ASCII) {
- order = strcmp(elemPtr1->index.strValuePtr,
- elemPtr2->index.strValuePtr);
+ order = strcmp(elemPtr1->collationKey.strValuePtr,
+ elemPtr2->collationKey.strValuePtr);
} else if (infoPtr->sortMode == SORTMODE_ASCII_NC) {
- order = strcasecmp(elemPtr1->index.strValuePtr,
- elemPtr2->index.strValuePtr);
+ order = strcasecmp(elemPtr1->collationKey.strValuePtr,
+ elemPtr2->collationKey.strValuePtr);
} else if (infoPtr->sortMode == SORTMODE_DICTIONARY) {
- order = DictionaryCompare(elemPtr1->index.strValuePtr,
- elemPtr2->index.strValuePtr);
+ order = DictionaryCompare(elemPtr1->collationKey.strValuePtr,
+ elemPtr2->collationKey.strValuePtr);
} else if (infoPtr->sortMode == SORTMODE_INTEGER) {
long a, b;
- a = elemPtr1->index.intValue;
- b = elemPtr2->index.intValue;
+ a = elemPtr1->collationKey.intValue;
+ b = elemPtr2->collationKey.intValue;
order = ((a >= b) - (a <= b));
} else if (infoPtr->sortMode == SORTMODE_REAL) {
double a, b;
- a = elemPtr1->index.doubleValue;
- b = elemPtr2->index.doubleValue;
+ a = elemPtr1->collationKey.doubleValue;
+ b = elemPtr2->collationKey.doubleValue;
order = ((a >= b) - (a <= b));
} else {
Tcl_Obj **objv, *paramObjv[2];
@@ -4205,8 +4208,8 @@ SortCompare(
}
- objPtr1 = elemPtr1->index.objValuePtr;
- objPtr2 = elemPtr2->index.objValuePtr;
+ objPtr1 = elemPtr1->collationKey.objValuePtr;
+ objPtr2 = elemPtr2->collationKey.objValuePtr;
paramObjv[0] = objPtr1;
paramObjv[1] = objPtr2;