Tcl Source Code

Check-in [3e22a9b9f9]
Login
Bounty program for improvements to Tcl and certain Tcl packages.
Tcl 2019 Conference, Houston/TX, US, Nov 4-8
Send your abstracts to [email protected]
or submit via the online form by Sep 9.

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Merge 8.7
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | tip-515
Files: files | file ages | folders
SHA3-256: 3e22a9b9f99a300108c42b4fe1d6cbb380f3d2ae50e59ac402f7f125b22080a6
User & Date: jan.nijtmans 2018-09-22 13:24:33
Context
2018-09-26
23:43
Implementatin of TIP #515: Level Value Reform check-in: 1486105322 user: jan.nijtmans tags: core-8-branch-timeline-fix
2018-09-22
13:37
merge tip-515 branch check-in: 686effa0af user: jan.nijtmans tags: tip-514
13:24
Merge 8.7 Closed-Leaf check-in: 3e22a9b9f9 user: jan.nijtmans tags: tip-515
13:18
Change ULLONG_MAX -> UWIDE_MAX, LLONG_MAX -> WIDE_MAX and LLONG_MIN -> WIDE_MIN everywhere, because ... check-in: 59d28e540e user: jan.nijtmans tags: core-8-branch
12:45
merge 8.7 check-in: 7160931bed user: jan.nijtmans tags: tip-515
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to generic/tclBasic.c.

  7512   7512   			Tcl_SetObjResult(interp, Tcl_NewLongObj(0));
  7513   7513   			return TCL_OK;
  7514   7514   		    }
  7515   7515   		    string++;
  7516   7516   		}
  7517   7517   	    }
  7518   7518   	    goto unChanged;
  7519         -	} else if (l == LLONG_MIN) {
         7519  +	} else if (l == WIDE_MIN) {
  7520   7520   	    TclInitBignumFromWideInt(&big, l);
  7521   7521   	    goto tooLarge;
  7522   7522   	}
  7523   7523   	Tcl_SetObjResult(interp, Tcl_NewWideIntObj(-l));
  7524   7524   	return TCL_OK;
  7525   7525       }
  7526   7526   
................................................................................
  7637   7637       }
  7638   7638       if (TclGetNumberFromObj(interp, objv[1], &ptr, &type) != TCL_OK) {
  7639   7639   	return TCL_ERROR;
  7640   7640       }
  7641   7641   
  7642   7642       if (type == TCL_NUMBER_DOUBLE) {
  7643   7643   	d = *((const double *) ptr);
  7644         -	if ((d >= (double)LLONG_MAX) || (d <= (double)LLONG_MIN)) {
         7644  +	if ((d >= (double)WIDE_MAX) || (d <= (double)WIDE_MIN)) {
  7645   7645   	    mp_int big;
  7646   7646   
  7647   7647   	    if (Tcl_InitBignumFromDouble(interp, d, &big) != TCL_OK) {
  7648   7648   		/* Infinity */
  7649   7649   		return TCL_ERROR;
  7650   7650   	    }
  7651   7651   	    Tcl_SetObjResult(interp, Tcl_NewBignumObj(&big));

Changes to generic/tclExecute.c.

  5631   5631   	int type1, type2;
  5632   5632   	Tcl_WideInt w1, w2, wResult;
  5633   5633   
  5634   5634       case INST_NUM_TYPE:
  5635   5635   	if (GetNumberFromObj(NULL, OBJ_AT_TOS, &ptr1, &type1) != TCL_OK) {
  5636   5636   	    type1 = 0;
  5637   5637   	} else if (type1 == TCL_NUMBER_WIDE) {
  5638         -	    /* value is between LLONG_MIN and LLONG_MAX */
         5638  +	    /* value is between WIDE_MIN and WIDE_MAX */
  5639   5639   	    /* [string is integer] is -UINT_MAX to UINT_MAX range */
  5640         -	    /* [string is wideinteger] is -ULLONG_MAX to ULLONG_MAX range */
         5640  +	    /* [string is wideinteger] is -UWIDE_MAX to UWIDE_MAX range */
  5641   5641   	    int i;
  5642   5642   
  5643   5643   	    if (Tcl_GetIntFromObj(NULL, OBJ_AT_TOS, &i) == TCL_OK) {
  5644   5644   		type1 = TCL_NUMBER_LONG;
  5645   5645   	    }
  5646   5646   	} else if (type1 == TCL_NUMBER_BIG) {
  5647         -	    /* value is an integer outside the LLONG_MIN to LLONG_MAX range */
  5648         -	    /* [string is wideinteger] is -ULLONG_MAX to ULLONG_MAX range */
         5647  +	    /* value is an integer outside the WIDE_MIN to WIDE_MAX range */
         5648  +	    /* [string is wideinteger] is -UWIDE_MAX to UWIDE_MAX range */
  5649   5649   	    Tcl_WideInt w;
  5650   5650   
  5651   5651   	    if (Tcl_GetWideIntFromObj(NULL, OBJ_AT_TOS, &w) == TCL_OK) {
  5652   5652   		type1 = TCL_NUMBER_WIDE;
  5653   5653   	    }
  5654   5654   	}
  5655   5655   	TclNewIntObj(objResultPtr, type1);
................................................................................
  6057   6057   		NEXT_INST_F(1, 1, 0);
  6058   6058   
  6059   6059   	    case INST_DIV:
  6060   6060   		if (w2 == 0) {
  6061   6061   		    TRACE(("%s %s => DIVIDE BY ZERO\n",
  6062   6062   			    O2S(valuePtr), O2S(value2Ptr)));
  6063   6063   		    goto divideByZero;
  6064         -		} else if ((w1 == LLONG_MIN) && (w2 == -1)) {
         6064  +		} else if ((w1 == WIDE_MIN) && (w2 == -1)) {
  6065   6065   		    /*
  6066         -		     * Can't represent (-LLONG_MIN) as a Tcl_WideInt.
         6066  +		     * Can't represent (-WIDE_MIN) as a Tcl_WideInt.
  6067   6067   		     */
  6068   6068   
  6069   6069   		    goto overflow;
  6070   6070   		}
  6071   6071   		wResult = w1 / w2;
  6072   6072   
  6073   6073   		/*
................................................................................
  6192   6192   	switch (type1) {
  6193   6193   	case TCL_NUMBER_NAN:
  6194   6194   	    /* -NaN => NaN */
  6195   6195   	    TRACE_APPEND(("%s\n", O2S(valuePtr)));
  6196   6196   	    NEXT_INST_F(1, 0, 0);
  6197   6197   	case TCL_NUMBER_WIDE:
  6198   6198   	    w1 = *((const Tcl_WideInt *) ptr1);
  6199         -	    if (w1 != LLONG_MIN) {
         6199  +	    if (w1 != WIDE_MIN) {
  6200   6200   		if (Tcl_IsShared(valuePtr)) {
  6201   6201   		    TclNewIntObj(objResultPtr, -w1);
  6202   6202   		    TRACE_APPEND(("%s\n", O2S(objResultPtr)));
  6203   6203   		    NEXT_INST_F(1, 1, 1);
  6204   6204   		}
  6205   6205   		TclSetIntObj(valuePtr, -w1);
  6206   6206   		TRACE_APPEND(("%s\n", O2S(valuePtr)));
................................................................................
  8666   8666   
  8667   8667   	    case INST_DIV:
  8668   8668   		if (w2 == 0) {
  8669   8669   		    return DIVIDED_BY_ZERO;
  8670   8670   		}
  8671   8671   
  8672   8672   		/*
  8673         -		 * Need a bignum to represent (LLONG_MIN / -1)
         8673  +		 * Need a bignum to represent (WIDE_MIN / -1)
  8674   8674   		 */
  8675   8675   
  8676         -		if ((w1 == LLONG_MIN) && (w2 == -1)) {
         8676  +		if ((w1 == WIDE_MIN) && (w2 == -1)) {
  8677   8677   		    goto overflowBasic;
  8678   8678   		}
  8679   8679   		wResult = w1 / w2;
  8680   8680   
  8681   8681   		/*
  8682   8682   		 * Force Tcl's integer division rules.
  8683   8683   		 * TODO: examine for logic simplification
................................................................................
  8772   8772   	BIG_RESULT(&big);
  8773   8773       case INST_UMINUS:
  8774   8774   	switch (type) {
  8775   8775   	case TCL_NUMBER_DOUBLE:
  8776   8776   	    DOUBLE_RESULT(-(*((const double *) ptr)));
  8777   8777   	case TCL_NUMBER_WIDE:
  8778   8778   	    w = *((const Tcl_WideInt *) ptr);
  8779         -	    if (w != LLONG_MIN) {
         8779  +	    if (w != WIDE_MIN) {
  8780   8780   		WIDE_RESULT(-w);
  8781   8781   	    }
  8782   8782   	    TclInitBignumFromWideInt(&big, w);
  8783   8783   	    break;
  8784   8784   	default:
  8785   8785   	    Tcl_TakeBignumFromObj(NULL, valuePtr, &big);
  8786   8786   	}
................................................................................
  8858   8858   	     *	  expr 20000000000000003 < 20000000000000004.0
  8859   8859   	     * right. Converting the first argument to double will yield two
  8860   8860   	     * double values that are equivalent within double precision.
  8861   8861   	     * Converting the double to an integer gets done exactly, then
  8862   8862   	     * integer comparison can tell the difference.
  8863   8863   	     */
  8864   8864   
  8865         -	    if (d2 < (double)LLONG_MIN) {
         8865  +	    if (d2 < (double)WIDE_MIN) {
  8866   8866   		return MP_GT;
  8867   8867   	    }
  8868         -	    if (d2 > (double)LLONG_MAX) {
         8868  +	    if (d2 > (double)WIDE_MAX) {
  8869   8869   		return MP_LT;
  8870   8870   	    }
  8871   8871   	    w2 = (Tcl_WideInt) d2;
  8872   8872   	    goto wideCompare;
  8873   8873   	case TCL_NUMBER_BIG:
  8874   8874   	    Tcl_TakeBignumFromObj(NULL, value2Ptr, &big2);
  8875   8875   	    if (mp_isneg(&big2)) {
................................................................................
  8891   8891   	case TCL_NUMBER_WIDE:
  8892   8892   	    w2 = *((const Tcl_WideInt *)ptr2);
  8893   8893   	    d2 = (double) w2;
  8894   8894   	    if (DBL_MANT_DIG > CHAR_BIT*sizeof(Tcl_WideInt)
  8895   8895   		    || w2 == (Tcl_WideInt) d2 || modf(d1, &tmp) != 0.0) {
  8896   8896   		goto doubleCompare;
  8897   8897   	    }
  8898         -	    if (d1 < (double)LLONG_MIN) {
         8898  +	    if (d1 < (double)WIDE_MIN) {
  8899   8899   		return MP_LT;
  8900   8900   	    }
  8901         -	    if (d1 > (double)LLONG_MAX) {
         8901  +	    if (d1 > (double)WIDE_MAX) {
  8902   8902   		return MP_GT;
  8903   8903   	    }
  8904   8904   	    w1 = (Tcl_WideInt) d1;
  8905   8905   	    goto wideCompare;
  8906   8906   	case TCL_NUMBER_BIG:
  8907   8907   	    if (TclIsInfinite(d1)) {
  8908   8908   		return (d1 > 0.0) ? MP_GT : MP_LT;
  8909   8909   	    }
  8910   8910   	    Tcl_TakeBignumFromObj(NULL, value2Ptr, &big2);
  8911         -	    if ((d1 < (double)LLONG_MAX) && (d1 > (double)LLONG_MIN)) {
         8911  +	    if ((d1 < (double)WIDE_MAX) && (d1 > (double)WIDE_MIN)) {
  8912   8912   		if (mp_isneg(&big2)) {
  8913   8913   		    compare = MP_GT;
  8914   8914   		} else {
  8915   8915   		    compare = MP_LT;
  8916   8916   		}
  8917   8917   		mp_clear(&big2);
  8918   8918   		return compare;
................................................................................
  8937   8937   	case TCL_NUMBER_DOUBLE:
  8938   8938   	    d2 = *((const double *)ptr2);
  8939   8939   	    if (TclIsInfinite(d2)) {
  8940   8940   		compare = (d2 > 0.0) ? MP_LT : MP_GT;
  8941   8941   		mp_clear(&big1);
  8942   8942   		return compare;
  8943   8943   	    }
  8944         -	    if ((d2 < (double)LLONG_MAX) && (d2 > (double)LLONG_MIN)) {
         8944  +	    if ((d2 < (double)WIDE_MAX) && (d2 > (double)WIDE_MIN)) {
  8945   8945   		compare = mp_cmp_d(&big1, 0);
  8946   8946   		mp_clear(&big1);
  8947   8947   		return compare;
  8948   8948   	    }
  8949   8949   	    if (DBL_MANT_DIG > CHAR_BIT*sizeof(long)
  8950   8950   		    && modf(d2, &tmp) != 0.0) {
  8951   8951   		d1 = TclBignumToDouble(&big1);

Changes to generic/tclPort.h.

    20     20   #if defined(_WIN32)
    21     21   #   include "tclWinPort.h"
    22     22   #else
    23     23   #   include "tclUnixPort.h"
    24     24   #endif
    25     25   #include "tcl.h"
    26     26   
    27         -#define WIDE_MAX ((Tcl_WideInt)((~(Tcl_WideUInt)0) >> 1))
           27  +#define UWIDE_MAX ((Tcl_WideUInt)-1)
           28  +#define WIDE_MAX ((Tcl_WideInt)(UWIDE_MAX >> 1))
    28     29   #define WIDE_MIN ((Tcl_WideInt)((Tcl_WideUInt)WIDE_MAX+1))
    29     30   
    30     31   #endif /* _TCLPORT */

Changes to generic/tclScan.c.

   922    922   	    string = end;
   923    923   	    if (flags & SCAN_SUPPRESS) {
   924    924   		Tcl_DecrRefCount(objPtr);
   925    925   		break;
   926    926   	    }
   927    927   	    if (flags & SCAN_LONGER) {
   928    928   		if (Tcl_GetWideIntFromObj(NULL, objPtr, &wideValue) != TCL_OK) {
   929         -		    wideValue = LLONG_MAX;
          929  +		    wideValue = WIDE_MAX;
   930    930   		    if (TclGetString(objPtr)[0] == '-') {
   931         -			wideValue = LLONG_MIN;
          931  +			wideValue = WIDE_MIN;
   932    932   		    }
   933    933   		}
   934    934   		if ((flags & SCAN_UNSIGNED) && (wideValue < 0)) {
   935    935   		    sprintf(buf, "%" TCL_LL_MODIFIER "u",
   936    936   			    (Tcl_WideUInt)wideValue);
   937    937   		    Tcl_SetStringObj(objPtr, buf, -1);
   938    938   		} else {