From 455b61dce391118995a7762609a6f42035cf43a4 Mon Sep 17 00:00:00 2001 From: dgp Date: Thu, 22 Feb 2018 18:57:20 +0000 Subject: [89dfecb6b7] Make thread IDs in testing commands consistent. --- generic/tclTest.c | 6 +++--- generic/tclThreadTest.c | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/generic/tclTest.c b/generic/tclTest.c index 8a59b83..45cca5a 100644 --- a/generic/tclTest.c +++ b/generic/tclTest.c @@ -5234,7 +5234,7 @@ TestmainthreadCmd( const char **argv) /* Argument strings. */ { if (argc == 1) { - Tcl_Obj *idObj = Tcl_NewLongObj((long)(size_t)Tcl_GetCurrentThread()); + Tcl_Obj *idObj = Tcl_NewWideIntObj((Tcl_WideInt)(size_t)Tcl_GetCurrentThread()); Tcl_SetObjResult(interp, idObj); return TCL_OK; @@ -5631,8 +5631,8 @@ TestChannelCmd( return TCL_ERROR; } - TclFormatInt(buf, (size_t) Tcl_GetChannelThread(chan)); - Tcl_AppendResult(interp, buf, NULL); + Tcl_SetObjResult(interp, Tcl_NewWideIntObj( + (Tcl_WideInt) (size_t) Tcl_GetChannelThread(chan))); return TCL_OK; } diff --git a/generic/tclThreadTest.c b/generic/tclThreadTest.c index fcf3880..6fc0e52 100644 --- a/generic/tclThreadTest.c +++ b/generic/tclThreadTest.c @@ -248,7 +248,7 @@ ThreadObjCmd( switch ((enum options)option) { case THREAD_CANCEL: { - long id; + Tcl_WideInt id; const char *result; int flags, arg; @@ -264,7 +264,7 @@ ThreadObjCmd( arg++; } } - if (Tcl_GetLongFromObj(interp, objv[arg], &id) != TCL_OK) { + if (Tcl_GetWideIntFromObj(interp, objv[arg], &id) != TCL_OK) { return TCL_ERROR; } arg++; -- cgit v0.12 From 812174d5782d57e4dbe97e9a1e378a2a2a4eac1f Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Thu, 22 Feb 2018 20:03:56 +0000 Subject: Correctly distinguish between internalrep.longValue (in case of boolean) and internalre.wideValue (in case of int). Add comment warning for that --- generic/tclGet.c | 2 +- generic/tclObj.c | 12 ++++++++---- 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; -- cgit v0.12