Tk Source Code

Check-in [0ff4b2be]
Login

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

Overview
Comment:Ongoing work (not finished yet) making Tk fully 64-bit size_t aware (see TIP #494) without compatibility macros
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | tip-494
Files: files | file ages | folders
SHA3-256:0ff4b2be49bcfe37c326a41a421f7e40ccf7e52df4039bdceb8a882c22f19576
User & Date: jan.nijtmans 2018-07-09 18:12:01
Context
2018-07-10
19:22
Make Tk sufficiently 64-bit aware in order to withstand TIP #494 possible problems Closed-Leaf check-in: 785b85f4 user: jan.nijtmans tags: tip-494
2018-07-09
18:12
Ongoing work (not finished yet) making Tk fully 64-bit size_t aware (see TIP #494) without compatibility macros check-in: 0ff4b2be user: jan.nijtmans tags: tip-494
18:10
Make Tk compile with TIP #494 (being tested now) using compatibility macros. Without TIP #494 there is no effect check-in: cc2ef92f user: jan.nijtmans tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to generic/tkBind.c.

    17     17   #ifdef _WIN32
    18     18   #include "tkWinInt.h"
    19     19   #elif defined(MAC_OSX_TK)
    20     20   #include "tkMacOSXInt.h"
    21     21   #else
    22     22   #include "tkUnixInt.h"
    23     23   #endif
           24  +#undef Tcl_ScanElement
           25  +#undef Tcl_ConvertElement
    24     26   
    25     27   /*
    26     28    * File structure:
    27     29    *
    28     30    * Structure definitions and static variables.
    29     31    *
    30     32    * Init/Free this package.
................................................................................
  1918   1920       KeySym keySym,		/* KeySym: only relevant for KeyPress and
  1919   1921   				 * KeyRelease events). */
  1920   1922       unsigned int scriptCount,	/* The number of script-based binding patterns
  1921   1923   				 * matched so far for this event. */
  1922   1924       Tcl_DString *dsPtr)		/* Dynamic string in which to append new
  1923   1925   				 * command. */
  1924   1926   {
  1925         -    int spaceNeeded, cvtFlags;	/* Used to substitute string as proper Tcl
         1927  +    size_t spaceNeeded;
         1928  +    int cvtFlags;	/* Used to substitute string as proper Tcl
  1926   1929   				 * list element. */
  1927   1930       int number, flags, length;
  1928   1931   #define NUM_SIZE 40
  1929   1932       const char *string;
  1930   1933       Tcl_DString buf;
  1931   1934       char numStorage[NUM_SIZE+1];
  1932   1935   

Changes to generic/tkCanvPs.c.

   487    487   	/*
   488    488   	 * Insert the prolog
   489    489   	 */
   490    490   
   491    491   	Tcl_AppendObjToObj(psObj, preambleObj);
   492    492   
   493    493   	if (psInfo.chan != NULL) {
   494         -	    if (Tcl_WriteObj(psInfo.chan, psObj) == -1) {
          494  +	    if ((size_t)Tcl_WriteObj(psInfo.chan, psObj) == (size_t)-1) {
   495    495   	    channelWriteFailed:
   496    496   		Tcl_SetObjResult(interp, Tcl_ObjPrintf(
   497    497   			"problem writing postscript data to channel: %s",
   498    498   			Tcl_PosixError(interp)));
   499    499   		result = TCL_ERROR;
   500    500   		goto cleanup;
   501    501   	    }
................................................................................
   541    541   		psInfo.x2, Tk_PostscriptY((double)psInfo.y,
   542    542   			(Tk_PostscriptInfo)psInfoPtr),
   543    543   		psInfo.x2, Tk_PostscriptY((double)psInfo.y2,
   544    544   			(Tk_PostscriptInfo)psInfoPtr),
   545    545   		psInfo.x, Tk_PostscriptY((double)psInfo.y2,
   546    546   			(Tk_PostscriptInfo)psInfoPtr));
   547    547   	if (psInfo.chan != NULL) {
   548         -	    if (Tcl_WriteObj(psInfo.chan, psObj) == -1) {
          548  +	    if ((size_t)Tcl_WriteObj(psInfo.chan, psObj) == (size_t)-1) {
   549    549   		goto channelWriteFailed;
   550    550   	    }
   551    551   	    Tcl_DecrRefCount(psObj);
   552    552   	    psObj = Tcl_NewObj();
   553    553   	}
   554    554       }
   555    555   
................................................................................
   583    583   	}
   584    584   
   585    585   	Tcl_AppendToObj(psObj, "gsave\n", -1);
   586    586   	Tcl_AppendObjToObj(psObj, Tcl_GetObjResult(interp));
   587    587   	Tcl_AppendToObj(psObj, "grestore\n", -1);
   588    588   
   589    589   	if (psInfo.chan != NULL) {
   590         -	    if (Tcl_WriteObj(psInfo.chan, psObj) == -1) {
          590  +	    if ((size_t)Tcl_WriteObj(psInfo.chan, psObj) == (size_t)-1) {
   591    591   		goto channelWriteFailed;
   592    592   	    }
   593    593   	    Tcl_DecrRefCount(psObj);
   594    594   	    psObj = Tcl_NewObj();
   595    595   	}
   596    596       }
   597    597   
................................................................................
   604    604   	Tcl_AppendToObj(psObj,
   605    605   		"restore showpage\n\n"
   606    606   		"%%Trailer\n"
   607    607   		"end\n"
   608    608   		"%%EOF\n", -1);
   609    609   
   610    610   	if (psInfo.chan != NULL) {
   611         -	    if (Tcl_WriteObj(psInfo.chan, psObj) == -1) {
          611  +	    if ((size_t)Tcl_WriteObj(psInfo.chan, psObj) == (size_t)-1) {
   612    612   		goto channelWriteFailed;
   613    613   	    }
   614    614   	}
   615    615       }
   616    616   
   617    617       if (psInfo.chan == NULL) {
   618    618   	Tcl_SetObjResult(interp, psObj);

Changes to generic/tkFont.c.

   559    559   
   560    560   	/*
   561    561   	 * The 'charPtr' arg must be a single Unicode.
   562    562   	 */
   563    563   
   564    564   	if (charPtr != NULL) {
   565    565   	    const char *string = Tcl_GetString(charPtr);
   566         -	    int len = TkUtfToUniChar(string, &uniChar);
          566  +	    size_t len = TkUtfToUniChar(string, &uniChar);
   567    567   
   568         -	    if (len != charPtr->length) {
          568  +	    if (len != (size_t)charPtr->length) {
   569    569   		resultPtr = Tcl_NewStringObj(
   570    570   			"expected a single character but got \"", -1);
   571    571   		Tcl_AppendLimitedToObj(resultPtr, string,
   572    572   			-1, 40, "...");
   573    573   		Tcl_AppendToObj(resultPtr, "\"", -1);
   574    574   		Tcl_SetObjResult(interp, resultPtr);
   575    575   		Tcl_SetErrorCode(interp, "TK", "VALUE", "FONT_SAMPLE", NULL);

Changes to generic/tkImgGIF.c.

    51     51    * state keeps track of which byte we are about to read, or EOF.
    52     52    */
    53     53   
    54     54   typedef struct mFile {
    55     55       unsigned char *data;	/* mmencoded source string */
    56     56       int c;			/* bits left over from previous character */
    57     57       int state;			/* decoder state (0-4 or GIF_DONE) */
    58         -    int length;			/* Total amount of bytes in data */
           58  +    size_t length;			/* Total amount of bytes in data */
    59     59   } MFile;
    60     60   
    61     61   /*
    62     62    * Non-ASCII encoding support:
    63     63    * Most data in a GIF image is binary and is treated as such. However, a few
    64     64    * key bits are stashed in ASCII. If we try to compare those pieces to the
    65     65    * char they represent, it will fail on any non-ASCII (eg, EBCDIC) system. To
................................................................................
   183    183   			    unsigned char cmap[MAXCOLORMAPSIZE][4], int srcX,
   184    184   			    int srcY, int interlace, int transparent);
   185    185   
   186    186   /*
   187    187    * these are for the BASE64 image reader code only
   188    188    */
   189    189   
   190         -static int		Fread(GIFImageConfig *gifConfPtr, unsigned char *dst,
          190  +static size_t		Fread(GIFImageConfig *gifConfPtr, unsigned char *dst,
   191    191   			    size_t size, size_t count, Tcl_Channel chan);
   192         -static int		Mread(unsigned char *dst, size_t size, size_t count,
          192  +static size_t		Mread(unsigned char *dst, size_t size, size_t count,
   193    193   			    MFile *handle);
   194    194   static int		Mgetc(MFile *handle);
   195    195   static int		char64(int c);
   196    196   static void		mInit(unsigned char *string, MFile *handle,
   197    197   			    int length);
   198    198   
   199    199   /*
................................................................................
   913    913       int number,
   914    914       unsigned char buffer[MAXCOLORMAPSIZE][4])
   915    915   {
   916    916       int i;
   917    917       unsigned char rgb[3];
   918    918   
   919    919       for (i = 0; i < number; ++i) {
   920         -	if (Fread(gifConfPtr, rgb, sizeof(rgb), 1, chan) <= 0) {
          920  +	if (((size_t)Fread(gifConfPtr, rgb, sizeof(rgb), 1, chan) + 1) < 2) {
   921    921   	    return 0;
   922    922   	}
   923    923   
   924    924   	if (buffer) {
   925    925   	    buffer[i][CM_RED] = rgb[0];
   926    926   	    buffer[i][CM_GREEN] = rgb[1];
   927    927   	    buffer[i][CM_BLUE] = rgb[2];
................................................................................
   979    979   GetDataBlock(
   980    980       GIFImageConfig *gifConfPtr,
   981    981       Tcl_Channel chan,
   982    982       unsigned char *buf)
   983    983   {
   984    984       unsigned char count;
   985    985   
   986         -    if (Fread(gifConfPtr, &count, 1, 1, chan) <= 0) {
          986  +    if (((size_t)Fread(gifConfPtr, &count, 1, 1, chan) + 1) < 2) {
   987    987   	return -1;
   988    988       }
   989    989   
   990         -    if ((count != 0) && (Fread(gifConfPtr, buf, count, 1, chan) <= 0)) {
          990  +    if ((count != 0) && (((size_t)Fread(gifConfPtr, buf, count, 1, chan) + 1) < 2)) {
   991    991   	return -1;
   992    992       }
   993    993   
   994    994       return count;
   995    995   }
   996    996   
   997    997   /*
................................................................................
  1045   1045       int codeSize, clearCode, inCode, endCode, oldCode, maxCode;
  1046   1046       int code, firstCode, v;
  1047   1047   
  1048   1048       /*
  1049   1049        * Initialize the decoder
  1050   1050        */
  1051   1051   
  1052         -    if (Fread(gifConfPtr, &initialCodeSize, 1, 1, chan) <= 0) {
         1052  +    if (((size_t)Fread(gifConfPtr, &initialCodeSize, 1, 1, chan) + 1) < 2) {
  1053   1053   	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
  1054   1054   		"error reading GIF image: %s", Tcl_PosixError(interp)));
  1055   1055   	return TCL_ERROR;
  1056   1056       }
  1057   1057   
  1058   1058       if (initialCodeSize > MAX_LWZ_BITS) {
  1059   1059   	Tcl_SetObjResult(interp, Tcl_NewStringObj("malformed image", -1));
................................................................................
  1399   1399    *
  1400   1400    * Side effects:
  1401   1401    *	The base64 handle will change state.
  1402   1402    *
  1403   1403    *----------------------------------------------------------------------
  1404   1404    */
  1405   1405   
  1406         -static int
         1406  +static size_t
  1407   1407   Mread(
  1408   1408       unsigned char *dst,		/* where to put the result */
  1409   1409       size_t chunkSize,		/* size of each transfer */
  1410   1410       size_t numChunks,		/* number of chunks */
  1411   1411       MFile *handle)		/* mmdecode "file" handle */
  1412   1412   {
  1413         -    register int i, c;
  1414         -    int count = chunkSize * numChunks;
         1413  +    int c;
         1414  +    size_t i, count = chunkSize * numChunks;
  1415   1415   
  1416   1416       for (i=0; i<count && (c=Mgetc(handle)) != GIF_DONE; i++) {
  1417   1417   	*dst++ = c;
  1418   1418       }
  1419   1419       return i;
  1420   1420   }
  1421   1421   
................................................................................
  1548   1548    *	a base64 encoded string.
  1549   1549    *
  1550   1550    * Results: - same as POSIX fread() or Tcl Tcl_Read()
  1551   1551    *
  1552   1552    *----------------------------------------------------------------------
  1553   1553    */
  1554   1554   
  1555         -static int
         1555  +static size_t
  1556   1556   Fread(
  1557   1557       GIFImageConfig *gifConfPtr,
  1558   1558       unsigned char *dst,		/* where to put the result */
  1559   1559       size_t hunk, size_t count,	/* how many */
  1560   1560       Tcl_Channel chan)
  1561   1561   {
  1562   1562       if (gifConfPtr->fromData == INLINE_DATA_BASE64) {
  1563   1563   	return Mread(dst, hunk, count, (MFile *) chan);
  1564   1564       }
  1565   1565   
  1566   1566       if (gifConfPtr->fromData == INLINE_DATA_BINARY) {
  1567   1567   	MFile *handle = (MFile *) chan;
  1568   1568   
  1569         -	if (handle->length <= 0 || (size_t) handle->length < hunk*count) {
  1570         -	    return -1;
         1569  +	if ((handle->length + 1 < 2) || (handle->length < hunk*count)) {
         1570  +	    return (size_t)-1;
  1571   1571   	}
  1572         -	memcpy(dst, handle->data, (size_t) (hunk * count));
         1572  +	memcpy(dst, handle->data, hunk * count);
  1573   1573   	handle->data += hunk * count;
  1574   1574   	handle->length -= hunk * count;
  1575         -	return (int)(hunk * count);
         1575  +	return hunk * count;
  1576   1576       }
  1577   1577   
  1578   1578       /*
  1579   1579        * Otherwise we've got a real file to read.
  1580   1580        */
  1581   1581   
  1582         -    return Tcl_Read(chan, (char *) dst, (int) (hunk * count));
         1582  +    return Tcl_Read(chan, (char *) dst, hunk * count);
  1583   1583   }
  1584   1584   
  1585   1585   /*
  1586   1586    * ChanWriteGIF - writes a image in GIF format.
  1587   1587    *-------------------------------------------------------------------------
  1588   1588    * Author:		Lolo
  1589   1589    *			Engeneering Projects Area

Changes to generic/tkImgPNG.c.

   620    620       if (pngPtr->base64Data) {
   621    621   	return ReadBase64(interp, pngPtr, destPtr, destSz, crcPtr);
   622    622       } else if (pngPtr->strDataBuf) {
   623    623   	return ReadByteArray(interp, pngPtr, destPtr, destSz, crcPtr);
   624    624       }
   625    625   
   626    626       while (destSz) {
   627         -	int blockSz = PNG_MIN(destSz, PNG_BLOCK_SZ);
          627  +	size_t blockSz = PNG_MIN(destSz, PNG_BLOCK_SZ);
   628    628   
   629         -	blockSz = Tcl_Read(pngPtr->channel, (char *)destPtr, blockSz);
   630         -	if (blockSz < 0) {
          629  +	blockSz = (size_t)Tcl_Read(pngPtr->channel, (char *)destPtr, blockSz);
          630  +	if (blockSz == (size_t)-1) {
   631    631   	    /* TODO: failure info... */
   632    632   	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
   633    633   		    "channel read failed: %s", Tcl_PosixError(interp)));
   634    634   	    return TCL_ERROR;
   635    635   	}
   636    636   
   637    637   	/*
................................................................................
  2881   2881   	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
  2882   2882   		    "memory allocation failed", -1));
  2883   2883   	    Tcl_SetErrorCode(interp, "TK", "MALLOC", NULL);
  2884   2884   	    return TCL_ERROR;
  2885   2885   	}
  2886   2886   
  2887   2887   	memcpy(destPtr+objSz, srcPtr, srcSz);
  2888         -    } else if (Tcl_Write(pngPtr->channel, (const char *) srcPtr, srcSz) < 0) {
         2888  +    } else if ((size_t)Tcl_Write(pngPtr->channel, (const char *) srcPtr, srcSz) == (size_t)-1) {
  2889   2889   	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
  2890   2890   		"write to channel failed: %s", Tcl_PosixError(interp)));
  2891   2891   	return TCL_ERROR;
  2892   2892       }
  2893   2893   
  2894   2894       return TCL_OK;
  2895   2895   }

Changes to generic/tkMain.c.

    34     34   #include <stdio.h>
    35     35   #include <string.h>
    36     36   #ifdef NO_STDLIB_H
    37     37   #   include "../compat/stdlib.h"
    38     38   #else
    39     39   #   include <stdlib.h>
    40     40   #endif
           41  +#undef Tcl_Gets
           42  +#undef Tcl_WriteObj
           43  +#undef Tcl_WriteChars
    41     44   
    42     45   extern int TkCygwinMainEx(int, char **, Tcl_AppInitProc *, Tcl_Interp *);
    43     46   
    44     47   /*
    45     48    * The default prompt used when the user has not overridden it.
    46     49    */
    47     50   
................................................................................
   416    419       /* ARGSUSED */
   417    420   static void
   418    421   StdinProc(
   419    422       ClientData clientData,	/* The state of interactive cmd line */
   420    423       int mask)			/* Not used. */
   421    424   {
   422    425       char *cmd;
   423         -    int code, count;
          426  +    int code;
          427  +    size_t count;
   424    428       InteractiveState *isPtr = clientData;
   425    429       Tcl_Channel chan = isPtr->input;
   426    430       Tcl_Interp *interp = isPtr->interp;
   427    431   
   428    432       count = Tcl_Gets(chan, &isPtr->line);
   429    433   
   430         -    if (count < 0 && !isPtr->gotPartial) {
          434  +    if (count == (size_t)-1 && !isPtr->gotPartial) {
   431    435   	if (isPtr->tty) {
   432    436   	    Tcl_Exit(0);
   433    437   	} else {
   434    438   	    Tcl_DeleteChannelHandler(chan, StdinProc, isPtr);
   435    439   	}
   436    440   	return;
   437    441       }

Changes to generic/tkOption.c.

     9      9    * Copyright (c) 1994-1997 Sun Microsystems, Inc.
    10     10    *
    11     11    * See the file "license.terms" for information on usage and redistribution of
    12     12    * this file, and for a DISCLAIMER OF ALL WARRANTIES.
    13     13    */
    14     14   
    15     15   #include "tkInt.h"
           16  +#undef Tcl_ReadChars
    16     17   
    17     18   /*
    18     19    * The option database is stored as one tree for each main window. Each name
    19     20    * or class field in an option is associated with a node or leaf of the tree.
    20     21    * For example, the options "x.y.z" and "x.y*a" each correspond to three nodes
    21     22    * in the tree; they share the nodes "x" and "x.y", but have different leaf
    22     23    * nodes. One of the following structures exists for each node or leaf in the
................................................................................
  1077   1078       int priority)		/* Priority level to use for options in this
  1078   1079   				 * file, such as TK_USER_DEFAULT_PRIO or
  1079   1080   				 * TK_INTERACTIVE_PRIO. Must be between 0 and
  1080   1081   				 * TK_MAX_PRIO. */
  1081   1082   {
  1082   1083       const char *realName;
  1083   1084       Tcl_Obj *buffer;
  1084         -    int result, bufferSize;
         1085  +    int result;
         1086  +    size_t bufferSize;
  1085   1087       Tcl_Channel chan;
  1086   1088       Tcl_DString newName;
  1087   1089   
  1088   1090       /*
  1089   1091        * Prevent file system access in a safe interpreter.
  1090   1092        */
  1091   1093   
................................................................................
  1108   1110   	return TCL_ERROR;
  1109   1111       }
  1110   1112   
  1111   1113       buffer = Tcl_NewObj();
  1112   1114       Tcl_IncrRefCount(buffer);
  1113   1115       Tcl_SetChannelOption(NULL, chan, "-encoding", "utf-8");
  1114   1116       bufferSize = Tcl_ReadChars(chan, buffer, -1, 0);
  1115         -    if (bufferSize < 0) {
         1117  +    if (bufferSize == (size_t)-1) {
  1116   1118   	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
  1117   1119   		"error reading file \"%s\": %s",
  1118   1120   		fileName, Tcl_PosixError(interp)));
  1119   1121   	Tcl_Close(NULL, chan);
  1120   1122   	return TCL_ERROR;
  1121   1123       }
  1122   1124       Tcl_Close(NULL, chan);