summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2018-02-22 20:03:56 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2018-02-22 20:03:56 (GMT)
commit812174d5782d57e4dbe97e9a1e378a2a2a4eac1f (patch)
tree5a752cf215bcc6b40fb9849e4195af458fdbe724
parent471d3566056a68fe1741cd6cd906d11fdacc80db (diff)
downloadtcl-812174d5782d57e4dbe97e9a1e378a2a2a4eac1f.zip
tcl-812174d5782d57e4dbe97e9a1e378a2a2a4eac1f.tar.gz
tcl-812174d5782d57e4dbe97e9a1e378a2a2a4eac1f.tar.bz2
Correctly distinguish between internalrep.longValue (in case of boolean) and internalre.wideValue (in case of int). Add comment warning for that
-rw-r--r--generic/tclGet.c2
-rw-r--r--generic/tclObj.c12
2 files changed, 9 insertions, 5 deletions
diff --git a/generic/tclGet.c b/generic/tclGet.c
index 2d611fa..12e0e79 100644
--- a/generic/tclGet.c
+++ b/generic/tclGet.c
@@ -142,7 +142,7 @@ Tcl_GetBoolean(
Tcl_Panic("invalid sharing of Tcl_Obj on C stack");
}
if (code == TCL_OK) {
- *boolPtr = (int)obj.internalRep.wideValue;
+ TclGetBooleanFromObj(NULL, &obj, boolPtr);
}
return code;
}
diff --git a/generic/tclObj.c b/generic/tclObj.c
index 8d4c492..6d365a2 100644
--- a/generic/tclObj.c
+++ b/generic/tclObj.c
@@ -1899,7 +1899,7 @@ Tcl_GetBooleanFromObj(
return TCL_OK;
}
if (objPtr->typePtr == &tclBooleanType) {
- *boolPtr = (int) objPtr->internalRep.longValue;
+ *boolPtr = objPtr->internalRep.longValue != 0;
return TCL_OK;
}
if (objPtr->typePtr == &tclDoubleType) {
@@ -1943,7 +1943,12 @@ Tcl_GetBooleanFromObj(
*
* Side effects:
* If no error occurs, an integer 1 or 0 is stored as "objPtr"s internal
- * representation and the type of "objPtr" is set to boolean.
+ * representation and the type of "objPtr" is set to boolean or int/wideInt.
+ *
+ * Warning: If the returned type is "wideInt" (32-bit platforms) and your
+ * platform is bigendian, you cannot use internalRep.longValue to distinguish
+ * between false and true. On Windows and most other platforms this still will
+ * work fine, but basically it is non-portable.
*
*----------------------------------------------------------------------
*/
@@ -1961,8 +1966,7 @@ TclSetBooleanFromAny(
if (objPtr->bytes == NULL) {
if (objPtr->typePtr == &tclIntType) {
- switch (objPtr->internalRep.wideValue) {
- case 0L: case 1L:
+ if ((Tcl_WideUInt)objPtr->internalRep.wideValue < 2) {
return TCL_OK;
}
goto badBoolean;