diff options
author | hobbs <hobbs> | 2005-01-28 01:50:25 (GMT) |
---|---|---|
committer | hobbs <hobbs> | 2005-01-28 01:50:25 (GMT) |
commit | 46fc28eab3f694dfc885d8087face2b939d48059 (patch) | |
tree | 275de9007403d770f195fd88861b79247f3e7245 | |
parent | 2123231f4d20076fce7107118855c3b04308298b (diff) | |
download | tcl-46fc28eab3f694dfc885d8087face2b939d48059.zip tcl-46fc28eab3f694dfc885d8087face2b939d48059.tar.gz tcl-46fc28eab3f694dfc885d8087face2b939d48059.tar.bz2 |
* generic/tclBasic.c (Tcl_ExprBoolean, Tcl_ExprDouble)
(Tcl_ExprLong): Fix to recognize Tcl_WideInt type. [Bug 1109484]
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | generic/tclBasic.c | 50 |
2 files changed, 51 insertions, 4 deletions
@@ -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-27 Andreas Kupries <andreask@activestate.com> TIP#218 IMPLEMENTATION diff --git a/generic/tclBasic.c b/generic/tclBasic.c index 8b199ce..9d6255c 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.75.2.10 2004/09/29 19:36:36 msofer Exp $ + * RCS: @(#) $Id: tclBasic.c,v 1.75.2.11 2005/01/28 01:50:26 hobbs Exp $ */ #include "tclInt.h" @@ -4139,11 +4139,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); @@ -4190,11 +4208,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); @@ -4241,11 +4277,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); } |