Posted to tcl by APN at Thu Aug 08 06:25:12 GMT 2013view raw

  1. Tcl_Obj *ObjFromULONGLONG(ULONGLONG ull)
  2. {
  3. /*
  4. * Unsigned 64-bit ints with the high bit set will not fit in Tcl_WideInt.
  5. * We need to convert to a bignum from a hex string.
  6. */
  7.  
  8. if (ull & 0x8000000000000000) {
  9. Tcl_Obj *objP;
  10. mp_int mpi;
  11. #if defined(TWAPI_REPLACE_CRT) || defined(TWAPI_MINIMIZE_CRT)
  12. Tcl_Obj *mpobj;
  13. objP = ObjFromWideInt((Tcl_WideInt) ull);
  14. mpobj = Tcl_Format(NULL, "0x%lx", 1, &objP);
  15. Tcl_DecrRefCount(objP);
  16. objP = mpobj;
  17. #else
  18. char buf[40];
  19. _snprintf(buf, sizeof(buf), "%I64u", ull);
  20. objP = ObjFromString(buf);
  21. #endif
  22. /* Force to bignum because COM interface sometimes needs to check type*/
  23. if (Tcl_GetBignumFromObj(NULL, objP, &mpi) == TCL_ERROR)
  24. return objP;
  25. #if defined(TWAPI_REPLACE_CRT) || defined(TWAPI_MINIMIZE_CRT)
  26. Tcl_InvalidateStringRep(objP); /* So we get a decimal string rep */
  27. #endif
  28. TclBN_mp_clear(&mpi);
  29. return objP;
  30. } else {
  31. return ObjFromWideInt((Tcl_WideInt) ull);
  32. }
  33. }
  34.