Posted to tcl by apn at Sun Feb 05 02:12:09 GMT 2012view raw

  1. Tcl_Obj *ObjFromULONGLONG(ULONGLONG ull)
  2. {
  3. Tcl_Obj *objP;
  4.  
  5. objP = Tcl_NewWideIntObj((Tcl_WideInt) ull);
  6.  
  7. /*
  8. * Unsigned 64-bit ints with the high bit set will not fit in Tcl_WideInt.
  9. * We need to convert to a bignum from a hex string.
  10. */
  11.  
  12. if (ull & 0x8000000000000000) {
  13. mp_int mpi;
  14. Tcl_Obj *mpobj;
  15. Tcl_IncrRefCount(objP); // Not really needed, just in case that was cause of crash
  16. mpobj = Tcl_Format(NULL, "0x%lx", 1, &objP);
  17. Tcl_DecrRefCount(objP);
  18. objP = mpobj;
  19. Tcl_GetBignumFromObj(NULL, objP, &mpi); /* Force to bignum */
  20. Tcl_InvalidateStringRep(objP); /* So we get a decimal string rep */
  21. TclBN_mp_clear(&mpi); <- crashes. Is this call required ?
  22. }
  23.  
  24. return objP;
  25. }
  26.