diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2022-11-21 23:54:42 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2022-11-21 23:54:42 (GMT) |
commit | ef78b1558f3f0feb6b934f68dba8c84d402511db (patch) | |
tree | cefc2509704bf47aa223bf56d01d2bb3a4a719cf /generic/tclLink.c | |
parent | 948fd24ddb34fc06ec3c6a8bc76133b5f1daafd6 (diff) | |
parent | c1e4942181ef1b8b60b89bfe5983b410080cd477 (diff) | |
download | tcl-ef78b1558f3f0feb6b934f68dba8c84d402511db.zip tcl-ef78b1558f3f0feb6b934f68dba8c84d402511db.tar.gz tcl-ef78b1558f3f0feb6b934f68dba8c84d402511db.tar.bz2 |
Merge 8.7
Diffstat (limited to 'generic/tclLink.c')
-rw-r--r-- | generic/tclLink.c | 54 |
1 files changed, 6 insertions, 48 deletions
diff --git a/generic/tclLink.c b/generic/tclLink.c index 4df2a33..a0212ee 100644 --- a/generic/tclLink.c +++ b/generic/tclLink.c @@ -527,56 +527,14 @@ GetUWide( Tcl_Obj *objPtr, Tcl_WideUInt *uwidePtr) { - Tcl_WideInt *widePtr = (Tcl_WideInt *) uwidePtr; - void *clientData; - int type, intValue; - - if (Tcl_GetNumberFromObj(NULL, objPtr, &clientData, &type) == TCL_OK) { - if (type == TCL_NUMBER_INT) { - *widePtr = *((const Tcl_WideInt *) clientData); - return (*widePtr < 0); - } else if (type == TCL_NUMBER_BIG) { - mp_int *numPtr = (mp_int *)clientData; - Tcl_WideUInt value = 0; - union { - Tcl_WideUInt value; - unsigned char bytes[sizeof(Tcl_WideUInt)]; - } scratch; - size_t numBytes; - unsigned char *bytes = scratch.bytes; - - if (numPtr->sign || (MP_OKAY != mp_to_ubin(numPtr, - bytes, sizeof(Tcl_WideUInt), &numBytes))) { - /* - * If the sign bit is set (a negative value) or if the value - * can't possibly fit in the bits of an unsigned wide, there's - * no point in doing further conversion. - */ - return 1; - } -#ifndef WORDS_BIGENDIAN - while (numBytes-- > 0) { - value = (value << CHAR_BIT) | *bytes++; - } -#else /* WORDS_BIGENDIAN */ - /* - * Big-endian can read the value directly. - */ - value = scratch.value; -#endif /* WORDS_BIGENDIAN */ - *uwidePtr = value; - return 0; - } - } - - /* - * Evil edge case fallback. - */ + if (Tcl_GetWideUIntFromObj(NULL, objPtr, uwidePtr) != TCL_OK) { + int intValue; - if (GetInvalidIntFromObj(objPtr, &intValue) != TCL_OK) { - return 1; + if (GetInvalidIntFromObj(objPtr, &intValue) != TCL_OK) { + return 1; + } + *uwidePtr = intValue; } - *uwidePtr = intValue; return 0; } |