summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhobbs <hobbs>2005-01-28 01:49:49 (GMT)
committerhobbs <hobbs>2005-01-28 01:49:49 (GMT)
commiteba80ac0e1a2b6854d25b4b3522a5aeeb26a4725 (patch)
tree3e59a6f93962157001e95118daf541f3d6ca8b3e
parent98dadc4e726ce2e9342141de853d74f6d614cc7b (diff)
downloadtcl-eba80ac0e1a2b6854d25b4b3522a5aeeb26a4725.zip
tcl-eba80ac0e1a2b6854d25b4b3522a5aeeb26a4725.tar.gz
tcl-eba80ac0e1a2b6854d25b4b3522a5aeeb26a4725.tar.bz2
* generic/tclBasic.c (Tcl_ExprBoolean, Tcl_ExprDouble)
(Tcl_ExprLong): Fix to recognize Tcl_WideInt type. [Bug 1109484]
-rw-r--r--ChangeLog5
-rw-r--r--generic/tclBasic.c50
2 files changed, 51 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index d12a253..05619b4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2005-01-27 Jeff Hobbs <jeffh@ActiveState.com>
+
+ * generic/tclBasic.c (Tcl_ExprBoolean, Tcl_ExprDouble)
+ (Tcl_ExprLong): Fix to recognize Tcl_WideInt type. [Bug 1109484]
+
2005-01-26 Andreas Kupries <andreask@activestate.com>
TIP#218 IMPLEMENTATION
diff --git a/generic/tclBasic.c b/generic/tclBasic.c
index 0e59e99..1d2c77f 100644
--- a/generic/tclBasic.c
+++ b/generic/tclBasic.c
@@ -13,7 +13,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclBasic.c,v 1.139 2005/01/21 17:42:11 andreas_kupries Exp $
+ * RCS: @(#) $Id: tclBasic.c,v 1.140 2005/01/28 01:49:50 hobbs Exp $
*/
#include "tclInt.h"
@@ -3882,11 +3882,29 @@ Tcl_ExprLong(interp, string, ptr)
/*
* Store an integer based on the expression result.
*/
-
+
if (resultPtr->typePtr == &tclIntType) {
*ptr = resultPtr->internalRep.longValue;
} else if (resultPtr->typePtr == &tclDoubleType) {
*ptr = (long) resultPtr->internalRep.doubleValue;
+ } else if (resultPtr->typePtr == &tclWideIntType) {
+#ifndef TCL_WIDE_INT_IS_LONG
+ /*
+ * See Tcl_GetIntFromObj for conversion comments.
+ */
+ Tcl_WideInt w = resultPtr->internalRep.wideValue;
+ if ((w >= -(Tcl_WideInt)(ULONG_MAX))
+ && (w <= (Tcl_WideInt)(ULONG_MAX))) {
+ *ptr = Tcl_WideAsLong(w);
+ } else {
+ Tcl_SetResult(interp,
+ "integer value too large to represent as non-long integer",
+ TCL_STATIC);
+ result = TCL_ERROR;
+ }
+#else
+ *ptr = resultPtr->internalRep.longValue;
+#endif
} else {
Tcl_SetResult(interp,
"expression didn't have numeric value", TCL_STATIC);
@@ -3932,11 +3950,29 @@ Tcl_ExprDouble(interp, string, ptr)
/*
* Store a double based on the expression result.
*/
-
+
if (resultPtr->typePtr == &tclIntType) {
*ptr = (double) resultPtr->internalRep.longValue;
} else if (resultPtr->typePtr == &tclDoubleType) {
*ptr = resultPtr->internalRep.doubleValue;
+ } else if (resultPtr->typePtr == &tclWideIntType) {
+#ifndef TCL_WIDE_INT_IS_LONG
+ /*
+ * See Tcl_GetIntFromObj for conversion comments.
+ */
+ Tcl_WideInt w = resultPtr->internalRep.wideValue;
+ if ((w >= -(Tcl_WideInt)(ULONG_MAX))
+ && (w <= (Tcl_WideInt)(ULONG_MAX))) {
+ *ptr = (double) Tcl_WideAsLong(w);
+ } else {
+ Tcl_SetResult(interp,
+ "integer value too large to represent as non-long integer",
+ TCL_STATIC);
+ result = TCL_ERROR;
+ }
+#else
+ *ptr = (double) resultPtr->internalRep.longValue;
+#endif
} else {
Tcl_SetResult(interp,
"expression didn't have numeric value", TCL_STATIC);
@@ -3982,11 +4018,17 @@ Tcl_ExprBoolean(interp, string, ptr)
/*
* Store a boolean based on the expression result.
*/
-
+
if (resultPtr->typePtr == &tclIntType) {
*ptr = (resultPtr->internalRep.longValue != 0);
} else if (resultPtr->typePtr == &tclDoubleType) {
*ptr = (resultPtr->internalRep.doubleValue != 0.0);
+ } else if (resultPtr->typePtr == &tclWideIntType) {
+#ifndef TCL_WIDE_INT_IS_LONG
+ *ptr = (resultPtr->internalRep.wideValue != 0);
+#else
+ *ptr = (resultPtr->internalRep.longValue != 0);
+#endif
} else {
result = Tcl_GetBooleanFromObj(interp, resultPtr, ptr);
}