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

Tcl_Obj *ObjFromULONGLONG(ULONGLONG ull)
{
    Tcl_Obj *objP;

    objP = Tcl_NewWideIntObj((Tcl_WideInt) ull);

    /*
     * Unsigned 64-bit ints with the high bit set will not fit in Tcl_WideInt.
     * We need to convert to a bignum from a hex string.
     */

    if (ull & 0x8000000000000000) {
        mp_int mpi;
        Tcl_Obj *mpobj;
        Tcl_IncrRefCount(objP); // Not really needed, just in case that was cause of crash
        mpobj = Tcl_Format(NULL, "0x%lx", 1, &objP);
        Tcl_DecrRefCount(objP);
        objP = mpobj;
        Tcl_GetBignumFromObj(NULL, objP, &mpi); /* Force to bignum */
        Tcl_InvalidateStringRep(objP);          /* So we get a decimal string rep */
        TclBN_mp_clear(&mpi); <- crashes. Is this call required ?
    }

    return objP;
}