Tk Source Code

Check-in [785b85f4]
Login

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

Overview
Comment:Make Tk sufficiently 64-bit aware in order to withstand TIP #494 possible problems
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | tip-494
Files: files | file ages | folders
SHA3-256:785b85f49d9d2091cc6200271cb0ffeba2e9c4db5c016239122c105f94442eab
User & Date: jan.nijtmans 2018-07-10 19:22:52
Context
2018-07-11
19:55
Promote some internal variables from int to size_t. This makes Tk compile with TIP #494-enabled Tcl, without the need for -DTCL_USE_INT_RETURN check-in: bda7be3d user: jan.nijtmans tags: trunk
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
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
    26     24   
    27     25   /*
    28     26    * File structure:
    29     27    *
    30     28    * Structure definitions and static variables.
    31     29    *
    32     30    * Init/Free this package.

Changes to generic/tkImgBmap.c.

  1075   1075    */
  1076   1076   
  1077   1077   static int
  1078   1078   GetByte(
  1079   1079       Tcl_Channel chan)	/* The channel we read from. */
  1080   1080   {
  1081   1081       char buffer;
  1082         -    int size;
         1082  +    size_t size;
  1083   1083   
  1084   1084       size = Tcl_Read(chan, &buffer, 1);
  1085         -    if (size <= 0) {
         1085  +    if ((size + 1) < 2) {
  1086   1086   	return EOF;
  1087   1087       } else {
  1088   1088   	return buffer;
  1089   1089       }
  1090   1090   }
  1091   1091   
  1092   1092   /*

Changes to generic/tkImgGIF.c.

   107    107   } GIFImageConfig;
   108    108   
   109    109   /*
   110    110    * Type of a function used to do the writing to a file or buffer when
   111    111    * serializing in the GIF format.
   112    112    */
   113    113   
   114         -typedef int (WriteBytesFunc) (ClientData clientData, const char *bytes,
   115         -			    int byteCount);
          114  +typedef size_t (WriteBytesFunc) (ClientData clientData, const char *bytes,
          115  +			    size_t byteCount);
   116    116   
   117    117   /*
   118    118    * The format record for the GIF file format:
   119    119    */
   120    120   
   121    121   static int		FileMatchGIF(Tcl_Channel chan, const char *fileName,
   122    122   			    Tcl_Obj *format, int *widthPtr, int *heightPtr,
................................................................................
   190    190   static size_t		Fread(GIFImageConfig *gifConfPtr, unsigned char *dst,
   191    191   			    size_t size, size_t count, Tcl_Channel chan);
   192    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         -			    int length);
          197  +			    size_t length);
   198    198   
   199    199   /*
   200    200    * Types, defines and variables needed to write and compress a GIF.
   201    201    */
   202    202   
   203    203   #define LSB(a)		((unsigned char) (((short)(a)) & 0x00FF))
   204    204   #define MSB(a)		((unsigned char) (((short)(a)) >> 8))
................................................................................
  1373   1373    *----------------------------------------------------------------------
  1374   1374    */
  1375   1375   
  1376   1376   static void
  1377   1377   mInit(
  1378   1378       unsigned char *string,	/* string containing initial mmencoded data */
  1379   1379       MFile *handle,		/* mmdecode "file" handle */
  1380         -    int length)			/* Number of bytes in string */
         1380  +    size_t length)			/* Number of bytes in string */
  1381   1381   {
  1382   1382       handle->data = string;
  1383   1383       handle->state = 0;
  1384   1384       handle->c = 0;
  1385   1385       handle->length = length;
  1386   1386   }
  1387   1387   
................................................................................
  1654   1654       if (result == TCL_OK) {
  1655   1655   	Tcl_SetObjResult(interp, objPtr);
  1656   1656       }
  1657   1657       Tcl_DecrRefCount(objPtr);
  1658   1658       return result;
  1659   1659   }
  1660   1660   
  1661         -static int
         1661  +static size_t
  1662   1662   WriteToChannel(
  1663   1663       ClientData clientData,
  1664   1664       const char *bytes,
  1665         -    int byteCount)
         1665  +    size_t byteCount)
  1666   1666   {
  1667   1667       Tcl_Channel handle = clientData;
  1668   1668   
  1669   1669       return Tcl_Write(handle, bytes, byteCount);
  1670   1670   }
  1671   1671   
  1672         -static int
         1672  +static size_t
  1673   1673   WriteToByteArray(
  1674   1674       ClientData clientData,
  1675   1675       const char *bytes,
  1676         -    int byteCount)
         1676  +    size_t byteCount)
  1677   1677   {
  1678   1678       Tcl_Obj *objPtr = clientData;
  1679   1679       Tcl_Obj *tmpObj = Tcl_NewByteArrayObj((unsigned char *) bytes, byteCount);
  1680   1680   
  1681   1681       Tcl_IncrRefCount(tmpObj);
  1682   1682       Tcl_AppendObjToObj(objPtr, tmpObj);
  1683   1683       Tcl_DecrRefCount(tmpObj);

Changes to generic/tkImgPPM.c.

   137    137   				 * image to be written to. */
   138    138       int width, int height,	/* Dimensions of block of photo image to be
   139    139   				 * written to. */
   140    140       int srcX, int srcY)		/* Coordinates of top-left pixel to be used in
   141    141   				 * image being read. */
   142    142   {
   143    143       int fileWidth, fileHeight, maxIntensity;
   144         -    int nLines, nBytes, h, type, count, bytesPerChannel = 1;
          144  +    int nLines, h, type, bytesPerChannel = 1;
          145  +    size_t nBytes, count;
   145    146       unsigned char *pixelPtr;
   146    147       Tk_PhotoImageBlock block;
   147    148   
   148    149       type = ReadPPMFileHeader(chan, &fileWidth, &fileHeight, &maxIntensity);
   149    150       if (type == 0) {
   150    151   	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
   151    152   		"couldn't read raw PPM header from file \"%s\"", fileName));
................................................................................
   281    282   FileWritePPM(
   282    283       Tcl_Interp *interp,
   283    284       const char *fileName,
   284    285       Tcl_Obj *format,
   285    286       Tk_PhotoImageBlock *blockPtr)
   286    287   {
   287    288       Tcl_Channel chan;
   288         -    int w, h, greenOffset, blueOffset, nBytes;
          289  +    int w, h, greenOffset, blueOffset;
          290  +    size_t nBytes;
   289    291       unsigned char *pixelPtr, *pixLinePtr;
   290    292       char header[16 + TCL_INTEGER_SPACE * 2];
   291    293   
   292    294       chan = Tcl_OpenFileChannel(interp, fileName, "w", 0666);
   293    295       if (chan == NULL) {
   294    296   	return TCL_ERROR;
   295    297       }
................................................................................
   311    313       pixLinePtr = blockPtr->pixelPtr + blockPtr->offset[0];
   312    314       greenOffset = blockPtr->offset[1] - blockPtr->offset[0];
   313    315       blueOffset = blockPtr->offset[2] - blockPtr->offset[0];
   314    316   
   315    317       if ((greenOffset == 1) && (blueOffset == 2) && (blockPtr->pixelSize == 3)
   316    318   	    && (blockPtr->pitch == (blockPtr->width * 3))) {
   317    319   	nBytes = blockPtr->height * blockPtr->pitch;
   318         -	if (Tcl_Write(chan, (char *) pixLinePtr, nBytes) != nBytes) {
          320  +	if ((size_t)Tcl_Write(chan, (char *) pixLinePtr, nBytes) != nBytes) {
   319    321   	    goto writeerror;
   320    322   	}
   321    323       } else {
   322    324   	for (h = blockPtr->height; h > 0; h--) {
   323    325   	    pixelPtr = pixLinePtr;
   324    326   	    for (w = blockPtr->width; w > 0; w--) {
   325         -		if (    Tcl_Write(chan,(char *)&pixelPtr[0], 1) == -1 ||
   326         -			Tcl_Write(chan,(char *)&pixelPtr[greenOffset],1)==-1 ||
   327         -			Tcl_Write(chan,(char *)&pixelPtr[blueOffset],1) ==-1) {
          327  +		if ((size_t)Tcl_Write(chan,(char *)&pixelPtr[0], 1) == (size_t)-1 ||
          328  +			(size_t)Tcl_Write(chan,(char *)&pixelPtr[greenOffset],1)==(size_t)-1 ||
          329  +			(size_t)Tcl_Write(chan,(char *)&pixelPtr[blueOffset],1) ==(size_t)-1) {
   328    330   		    goto writeerror;
   329    331   		}
   330    332   		pixelPtr += blockPtr->pixelSize;
   331    333   	    }
   332    334   	    pixLinePtr += blockPtr->pitch;
   333    335   	}
   334    336       }

Changes to generic/tkInt.h.

   820    820   
   821    821   /*
   822    822    * Real definition of some events. Note that these events come from outside
   823    823    * but have internally generated pieces added to them.
   824    824    */
   825    825   
   826    826   typedef struct {
   827         -    XKeyEvent keyEvent;		/* The real event from X11. */
   828         -    char *charValuePtr;		/* A pointer to a string that holds the key's
          827  +    XKeyEvent keyEvent;	/* The real event from X11. */
          828  +    char *charValuePtr;	/* A pointer to a string that holds the key's
   829    829   				 * %A substitution text (before backslash
   830    830   				 * adding), or NULL if that has not been
   831    831   				 * computed yet. If non-NULL, this string was
   832    832   				 * allocated with ckalloc(). */
   833         -    int charValueLen;		/* Length of string in charValuePtr when that
          833  +    size_t charValueLen;	/* Length of string in charValuePtr when that
   834    834   				 * is non-NULL. */
   835    835       KeySym keysym;		/* Key symbol computed after input methods
   836    836   				 * have been invoked */
   837    837   } TkKeyEvent;
   838    838   
   839    839   /*
   840    840    * Flags passed to TkpMakeMenuWindow's 'transient' argument.

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
    44     41   
    45     42   extern int TkCygwinMainEx(int, char **, Tcl_AppInitProc *, Tcl_Interp *);
    46     43   
    47     44   /*
    48     45    * The default prompt used when the user has not overridden it.
    49     46    */
    50     47   

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
    17     16   
    18     17   /*
    19     18    * The option database is stored as one tree for each main window. Each name
    20     19    * or class field in an option is associated with a node or leaf of the tree.
    21     20    * For example, the options "x.y.z" and "x.y*a" each correspond to three nodes
    22     21    * in the tree; they share the nodes "x" and "x.y", but have different leaf
    23     22    * nodes. One of the following structures exists for each node or leaf in the

Changes to generic/tkUtil.c.

   729    729       int *intPtr)		/* Filled in with number of pages or lines to
   730    730   				 * scroll, if any. */
   731    731   {
   732    732       const char *arg = Tcl_GetString(objv[2]);
   733    733       size_t length = objv[2]->length;
   734    734   
   735    735   #define ArgPfxEq(str) \
   736         -	((arg[0] == str[0]) && !strncmp(arg, str, (unsigned)length))
          736  +	((arg[0] == str[0]) && !strncmp(arg, str, length))
   737    737   
   738    738       if (ArgPfxEq("moveto")) {
   739    739   	if (objc != 4) {
   740    740   	    Tcl_WrongNumArgs(interp, 2, objv, "moveto fraction");
   741    741   	    return TK_SCROLL_ERROR;
   742    742   	}
   743    743   	if (Tcl_GetDoubleFromObj(interp, objv[3], dblPtr) != TCL_OK) {

Changes to generic/ttk/ttkState.c.

   126    126   
   127    127   static void StateSpecUpdateString(Tcl_Obj *objPtr)
   128    128   {
   129    129       unsigned int onbits = (objPtr->internalRep.longValue & 0xFFFF0000) >> 16;
   130    130       unsigned int offbits = objPtr->internalRep.longValue & 0x0000FFFF;
   131    131       unsigned int mask = onbits | offbits;
   132    132       Tcl_DString result;
   133         -    int i, len;
          133  +    int i;
          134  +    size_t len;
   134    135   
   135    136       Tcl_DStringInit(&result);
   136    137   
   137    138       for (i=0; stateNames[i] != NULL; ++i) {
   138    139   	if (mask & (1<<i)) {
   139    140   	    if (offbits & (1<<i))
   140    141   		Tcl_DStringAppend(&result, "!", 1);
................................................................................
   142    143   	    Tcl_DStringAppend(&result, " ", 1);
   143    144   	}
   144    145       }
   145    146   
   146    147       len = Tcl_DStringLength(&result);
   147    148       if (len) {
   148    149   	/* 'len' includes extra trailing ' ' */
   149         -	objPtr->bytes = Tcl_Alloc((unsigned)len);
          150  +	objPtr->bytes = Tcl_Alloc(len);
   150    151   	objPtr->length = len-1;
   151         -	strncpy(objPtr->bytes, Tcl_DStringValue(&result), (size_t)len-1);
          152  +	strncpy(objPtr->bytes, Tcl_DStringValue(&result), len-1);
   152    153   	objPtr->bytes[len-1] = '\0';
   153    154       } else {
   154    155   	/* empty string */
   155    156   	objPtr->length = 0;
   156    157   	objPtr->bytes = Tcl_Alloc(1);
   157    158   	*objPtr->bytes = '\0';
   158    159       }

Changes to unix/Makefile.in.

   133    133   CFLAGS_OPTIMIZE		= @CFLAGS_OPTIMIZE@
   134    134   
   135    135   # To change the compiler switches, for example to change from optimization to
   136    136   # debugging symbols, change the following line:
   137    137   #CFLAGS			= $(CFLAGS_DEBUG)
   138    138   #CFLAGS			= $(CFLAGS_OPTIMIZE)
   139    139   #CFLAGS			= $(CFLAGS_DEBUG) $(CFLAGS_OPTIMIZE)
   140         -CFLAGS			= @CFLAGS_DEFAULT@ @CFLAGS@ -DTCL_USE_INT_RETURN
          140  +CFLAGS			= @CFLAGS_DEFAULT@ @CFLAGS@ 
   141    141   
   142    142   # Flags to pass to the linker
   143    143   LDFLAGS_DEBUG		= @LDFLAGS_DEBUG@
   144    144   LDFLAGS_OPTIMIZE	= @LDFLAGS_OPTIMIZE@
   145    145   LDFLAGS			= @LDFLAGS_DEFAULT@ @LDFLAGS@
   146    146   
   147    147   # A "-I" switch that can be used when compiling to make all of the

Changes to unix/tkUnixKey.c.

   106    106   
   107    107   const char *
   108    108   TkpGetString(
   109    109       TkWindow *winPtr,		/* Window where event occurred */
   110    110       XEvent *eventPtr,		/* X keyboard event. */
   111    111       Tcl_DString *dsPtr)		/* Initialized, empty string to hold result. */
   112    112   {
   113         -    int len, mincode, maxcode;
          113  +    size_t len;
          114  +    int mincode, maxcode;
   114    115       Tcl_DString buf;
   115    116       TkKeyEvent *kePtr = (TkKeyEvent *) eventPtr;
   116    117   
   117    118       /*
   118    119        * If we have the value cached already, use it now. [Bug 1373712]
   119    120        */
   120    121   
   121    122       if (kePtr->charValuePtr != NULL) {
   122    123   	Tcl_DStringSetLength(dsPtr, kePtr->charValueLen);
   123    124   	memcpy(Tcl_DStringValue(dsPtr), kePtr->charValuePtr,
   124         -		(unsigned) kePtr->charValueLen+1);
          125  +		kePtr->charValueLen+1);
   125    126   	return Tcl_DStringValue(dsPtr);
   126    127       }
   127    128   
   128    129       /*
   129    130        * Only do this for KeyPress events, otherwise
   130    131        * further Xlib function behavior might be undefined.
   131    132        */
................................................................................
   242    243        * function, we will be able to produce it without asking X. This stops us
   243    244        * from having to reenter the XIM engine. [Bug 1373712]
   244    245        */
   245    246   
   246    247   done:
   247    248       kePtr->charValuePtr = ckalloc(len + 1);
   248    249       kePtr->charValueLen = len;
   249         -    memcpy(kePtr->charValuePtr, Tcl_DStringValue(dsPtr), (unsigned) len + 1);
          250  +    memcpy(kePtr->charValuePtr, Tcl_DStringValue(dsPtr), len + 1);
   250    251       return Tcl_DStringValue(dsPtr);
   251    252   }
   252    253   
   253    254   /*
   254    255    * When mapping from a keysym to a keycode, need information about the
   255    256    * modifier state to be used so that when they call TkKeycodeToKeysym taking
   256    257    * into account the xkey.state, they will get back the original keysym.

Changes to win/Makefile.in.

   166    166   LDFLAGS_OPTIMIZE = @LDFLAGS_OPTIMIZE@
   167    167   
   168    168   # To change the compiler switches, for example to change from optimization to
   169    169   # debugging symbols, change the following line:
   170    170   #CFLAGS		= $(CFLAGS_DEBUG)
   171    171   #CFLAGS		= $(CFLAGS_OPTIMIZE)
   172    172   #CFLAGS		= $(CFLAGS_DEBUG) $(CFLAGS_OPTIMIZE)
   173         -CFLAGS		= @CFLAGS@ @CFLAGS_DEFAULT@ -DUNICODE -D_UNICODE -D_ATL_XP_TARGETING -DTCL_USE_INT_RETURN
          173  +CFLAGS		= @CFLAGS@ @CFLAGS_DEFAULT@ -DUNICODE -D_UNICODE -D_ATL_XP_TARGETING
   174    174   
   175    175   # Special compiler flags to use when building man2tcl on Windows.
   176    176   MAN2TCLFLAGS	= @MAN2TCLFLAGS@
   177    177   
   178    178   AR		= @AR@
   179    179   RANLIB		= @RANLIB@
   180    180   CC		= @CC@