From 03a3a2d78e1c26683170d32685d3f4d3b9ed902d Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Thu, 1 Oct 2015 11:04:19 +0000 Subject: Eliminate a few gcc compiler warnings, when using -Wwrite-strings (tested with the brand-new gcc 5.2.0) --- generic/tclCmdAH.c | 8 ++++---- generic/tclCmdMZ.c | 6 ++++-- generic/tclExecute.c | 30 +++++++++++++++--------------- generic/tclLiteral.c | 11 ++++++----- generic/tclObj.c | 42 +++++++++++++++++++++--------------------- generic/tclTest.c | 6 +++--- unix/tclUnixChan.c | 10 +++++----- unix/tclUnixNotfy.c | 2 +- unix/tclUnixTest.c | 2 +- 9 files changed, 60 insertions(+), 57 deletions(-) diff --git a/generic/tclCmdAH.c b/generic/tclCmdAH.c index 7f0df83..5484002 100644 --- a/generic/tclCmdAH.c +++ b/generic/tclCmdAH.c @@ -25,7 +25,7 @@ static int EncodingDirsObjCmd(ClientData dummy, Tcl_Obj *const objv[]); static int GetStatBuf(Tcl_Interp *interp, Tcl_Obj *pathPtr, Tcl_FSStatProc *statProc, Tcl_StatBuf *statPtr); -static char * GetTypeFromMode(int mode); +static const char * GetTypeFromMode(int mode); static int StoreStatData(Tcl_Interp *interp, Tcl_Obj *varName, Tcl_StatBuf *statPtr); @@ -1289,7 +1289,7 @@ Tcl_FileObjCmd( return TCL_ERROR; } if (objc == 2) { - char *separator = NULL; /* lint */ + const char *separator = NULL; /* lint */ switch (tclPlatform) { case TCL_PLATFORM_UNIX: @@ -1554,7 +1554,7 @@ StoreStatData( *---------------------------------------------------------------------- */ -static char * +static const char * GetTypeFromMode( int mode) { @@ -1757,7 +1757,7 @@ Tcl_ForeachObjCmd( maxj = 0; for (i=0 ; imarkerPtr = tmpMarkerPtr; - memStart = tmpMarkerPtr + offset; + memStart = tmpMarkerPtr + offset; esPtr->tosPtr = memStart - 1; *esPtr->markerPtr = (Tcl_Obj *) markerPtr; return memStart; @@ -982,7 +982,7 @@ GrowEvaluationStack( esPtr->markerPtr = &esPtr->stackWords[0]; memStart = MEMSTART(esPtr->markerPtr); esPtr->tosPtr = memStart - 1; - + if (move) { memcpy(memStart, MEMSTART(markerPtr), moveWords*sizeof(Tcl_Obj *)); esPtr->tosPtr += moveWords; @@ -1486,19 +1486,19 @@ TclCompEvalObj( * Note: Type BC => ctx.data.eval.path is not used. * ctx.data.tebc.codePtr used instead */ - + TclGetSrcInfoForPc(ctxPtr); if (ctxPtr->type == TCL_LOCATION_SOURCE) { /* * The reference made by 'TclGetSrcInfoForPc' is * dead. */ - + Tcl_DecrRefCount(ctxPtr->data.eval.path); ctxPtr->data.eval.path = NULL; } } - + if (word < ctxPtr->nline) { /* * Note: We do not care if the line[word] is -1. This @@ -1510,15 +1510,15 @@ TclCompEvalObj( * test info-32.0 using literal of info-24.8 * (dict with ... vs set body ...). */ - + redo = ((eclPtr->type == TCL_LOCATION_SOURCE) && (eclPtr->start != ctxPtr->line[word])) || ((eclPtr->type == TCL_LOCATION_BC) && (ctxPtr->type == TCL_LOCATION_SOURCE)); } - + TclStackFree(interp, ctxPtr); - + if (redo) { goto recompileObj; } @@ -1778,7 +1778,7 @@ TclExecuteByteCode( int traceInstructions = (tclTraceExec == 3); char cmdNameBuf[21]; #endif - char *curInstName = NULL; + const char *curInstName = NULL; /* * The execution uses a unified stack: first the catch stack, immediately @@ -5802,9 +5802,9 @@ TclExecuteByteCode( /* * We refuse to accept exponent arguments that exceed * one mp_digit which means the max exponent value is - * 2**28-1 = 0x0fffffff = 268435455, which fits into + * 2**28-1 = 0x0fffffff = 268435455, which fits into * a signed 32 bit int which is within the range of the - * long int type. This means any numeric Tcl_Obj value + * long int type. This means any numeric Tcl_Obj value * not using TCL_NUMBER_LONG type must hold a value larger * than we accept. */ diff --git a/generic/tclLiteral.c b/generic/tclLiteral.c index 6a617b0..fb7c28a 100644 --- a/generic/tclLiteral.c +++ b/generic/tclLiteral.c @@ -153,7 +153,7 @@ TclDeleteLiteralTable( * Find, or if necessary create, an object in the interpreter's literal * table that has a string representation matching the argument * string. If nsPtr!=NULL then only literals stored for the namespace are - * considered. + * considered. * * Results: * The literal object. If it was created in this call *newPtr is set to @@ -161,7 +161,7 @@ TclDeleteLiteralTable( * * Side effects: * Increments the ref count of the global LiteralEntry since the caller - * now holds a reference. + * now holds a reference. * If LITERAL_ON_HEAP is set in flags, this function is given ownership * of the string: if an object is created then its string representation * is set directly from string, otherwise the string is freed. Typically, @@ -186,7 +186,7 @@ TclCreateLiteral( LiteralEntry *globalPtr; int globalHash; Tcl_Obj *objPtr; - + /* * Is it in the interpreter's global literal table? */ @@ -709,7 +709,7 @@ ExpandLocalLiteralArray( if (currArrayPtr != newArrayPtr) { for (i=0 ; inumBuckets; oldBuckets = tablePtr->buckets; diff --git a/generic/tclObj.c b/generic/tclObj.c index d278b1f..230842a 100644 --- a/generic/tclObj.c +++ b/generic/tclObj.c @@ -569,7 +569,7 @@ TclContinuationsEnter(Tcl_Obj* objPtr, Tcl_HashEntry* hPtr = Tcl_CreateHashEntry (tsdPtr->lineCLPtr, (char*) objPtr, &newEntry); - ContLineLoc* clLocPtr = + ContLineLoc* clLocPtr = (ContLineLoc*) ckalloc (sizeof(ContLineLoc) + num*sizeof(int)); if (!newEntry) { @@ -675,7 +675,7 @@ TclContinuationsEnterDerived(Tcl_Obj* objPtr, int start, int* clNext) num = wordCLLast - clNext; if (num) { int i; - ContLineLoc* clLocPtr = + ContLineLoc* clLocPtr = TclContinuationsEnter(objPtr, num, clNext); /* @@ -1371,10 +1371,10 @@ TclFreeObj( */ objPtr->refCount = -1; - /* Invalidate the string rep first so we can use the bytes value + /* Invalidate the string rep first so we can use the bytes value * for our pointer chain, and signal an obj deletion (as opposed - * to shimmering) with 'length == -1' */ - + * to shimmering) with 'length == -1' */ + TclInvalidateStringRep(objPtr); objPtr->length = -1; @@ -1436,13 +1436,13 @@ void TclFreeObj( register Tcl_Obj *objPtr) /* The object to be freed. */ { - /* Invalidate the string rep first so we can use the bytes value + /* Invalidate the string rep first so we can use the bytes value * for our pointer chain, and signal an obj deletion (as opposed - * to shimmering) with 'length == -1' */ + * to shimmering) with 'length == -1' */ TclInvalidateStringRep(objPtr); objPtr->length = -1; - + if (!objPtr->typePtr || !objPtr->typePtr->freeIntRepProc) { /* * objPtr can be freed safely, as it will not attempt to free any @@ -2799,7 +2799,7 @@ Tcl_GetLongFromObj( tooLarge: #endif if (interp != NULL) { - char *s = "integer value too large to represent"; + const char *s = "integer value too large to represent"; Tcl_Obj *msg = Tcl_NewStringObj(s, -1); Tcl_SetObjResult(interp, msg); @@ -3098,7 +3098,7 @@ Tcl_GetWideIntFromObj( } } if (interp != NULL) { - char *s = "integer value too large to represent"; + const char *s = "integer value too large to represent"; Tcl_Obj* msg = Tcl_NewStringObj(s, -1); Tcl_SetObjResult(interp, msg); @@ -4084,7 +4084,7 @@ Tcl_GetCommandFromObj( * is not deleted. * * If any check fails, then force another conversion to the command type, - * to discard the old rep and create a new one. + * to discard the old rep and create a new one. */ resPtr = (ResolvedCmdName *) objPtr->internalRep.twoPtrValue.ptr1; @@ -4094,15 +4094,15 @@ Tcl_GetCommandFromObj( || (cmdPtr->flags & CMD_IS_DELETED) || (interp != cmdPtr->nsPtr->interp) || (cmdPtr->nsPtr->flags & NS_DYING) - || ((resPtr->refNsPtr != NULL) && + || ((resPtr->refNsPtr != NULL) && (((refNsPtr = (Namespace *) TclGetCurrentNamespace(interp)) != resPtr->refNsPtr) || (resPtr->refNsId != refNsPtr->nsId) || (resPtr->refNsCmdEpoch != refNsPtr->cmdRefEpoch))) ) { - + result = tclCmdNameType.setFromAnyProc(interp, objPtr); - + resPtr = (ResolvedCmdName *) objPtr->internalRep.twoPtrValue.ptr1; if ((result == TCL_OK) && resPtr) { cmdPtr = resPtr->cmdPtr; @@ -4110,7 +4110,7 @@ Tcl_GetCommandFromObj( cmdPtr = NULL; } } - + return (Tcl_Command) cmdPtr; } @@ -4162,7 +4162,7 @@ TclSetCmdNameObj( if ((*name++ == ':') && (*name == ':')) { /* * The name is fully qualified: set the referring namespace to - * NULL. + * NULL. */ resPtr->refNsPtr = NULL; @@ -4172,7 +4172,7 @@ TclSetCmdNameObj( */ currNsPtr = iPtr->varFramePtr->nsPtr; - + resPtr->refNsPtr = currNsPtr; resPtr->refNsId = currNsPtr->nsId; resPtr->refNsCmdEpoch = currNsPtr->cmdRefEpoch; @@ -4332,7 +4332,7 @@ SetCmdNameFromAny( /* * Reuse the old ResolvedCmdName struct instead of freeing it */ - + Command *oldCmdPtr = resPtr->cmdPtr; if (--oldCmdPtr->refCount == 0) { TclCleanupCommandMacro(oldCmdPtr); @@ -4349,8 +4349,8 @@ SetCmdNameFromAny( resPtr->cmdEpoch = cmdPtr->cmdEpoch; if ((*name++ == ':') && (*name == ':')) { /* - * The name is fully qualified: set the referring namespace to - * NULL. + * The name is fully qualified: set the referring namespace to + * NULL. */ resPtr->refNsPtr = NULL; @@ -4360,7 +4360,7 @@ SetCmdNameFromAny( */ currNsPtr = iPtr->varFramePtr->nsPtr; - + resPtr->refNsPtr = currNsPtr; resPtr->refNsId = currNsPtr->nsId; resPtr->refNsCmdEpoch = currNsPtr->cmdRefEpoch; diff --git a/generic/tclTest.c b/generic/tclTest.c index 5b51baa..1d92ff5 100644 --- a/generic/tclTest.c +++ b/generic/tclTest.c @@ -909,7 +909,7 @@ TestasyncCmd( static int AsyncHandlerProc( - ClientData clientData, /* If of TestAsyncHandler structure. + ClientData clientData, /* If of TestAsyncHandler structure. * in global list. */ Tcl_Interp *interp, /* Interpreter in which command was * executed, or NULL. */ @@ -3606,7 +3606,7 @@ PrintParse( Tcl_Parse *parsePtr) /* Parse structure to print out. */ { Tcl_Obj *objPtr; - char *typeString; + const char *typeString; Tcl_Token *tokenPtr; int i; @@ -6518,7 +6518,7 @@ TestGetIndexFromObjStructObjCmd( int objc, /* Number of arguments. */ Tcl_Obj *const objv[]) /* Argument objects. */ { - char *ary[] = { + const char *ary[] = { "a", "b", "c", "d", "e", "f", NULL, NULL }; int idx,target; diff --git a/unix/tclUnixChan.c b/unix/tclUnixChan.c index a0d9811..8448b77 100644 --- a/unix/tclUnixChan.c +++ b/unix/tclUnixChan.c @@ -2181,7 +2181,7 @@ TcpGetOptionProc( * We don't want to resolve INADDR_ANY; it can sometimes cause * problems (and never has a name). */ - + hostEntPtr = NULL; } else { hostEntPtr = TclpGetHostByAddr( /* INTL: Native. */ @@ -2292,7 +2292,7 @@ TcpWatchProc( * to the guarantees Tcl makes that its channels become * writable and fire writable events on an error conditon. * This has caused a leak of file descriptors in a state of - * background flushing. See Tcl ticket 1758a0b603. + * background flushing. See Tcl ticket 1758a0b603. * * As a workaround, when our caller indicates an interest in * writable notifications, we must tell the notifier built @@ -2303,7 +2303,7 @@ TcpWatchProc( * channel states and report the chan events as best it can. * We save a copy of the mask passed in to assist with that. */ - + statePtr->interest = mask; Tcl_CreateFileHandler(statePtr->fd, mask|TCL_READABLE, (Tcl_FileProc *) WrapNotify, (ClientData) statePtr); @@ -2927,7 +2927,7 @@ TclpGetDefaultStdChannel( Tcl_Channel channel = NULL; int fd = 0; /* Initializations needed to prevent */ int mode = 0; /* compiler warning (used before set). */ - char *bufMode = NULL; + const char *bufMode = NULL; /* * Some #def's to make the code a little clearer! @@ -3216,7 +3216,7 @@ TclUnixWaitForFile( if (FD_ISSET(fd, &writableMask)) { SET_BITS(result, TCL_WRITABLE); } - if (FD_ISSET(fd, &exceptionalMask)) { + if (FD_ISSET(fd, &exceptionalMask)) { SET_BITS(result, TCL_EXCEPTION); } result &= mask; diff --git a/unix/tclUnixNotfy.c b/unix/tclUnixNotfy.c index 5c7f8b5..2df704b 100644 --- a/unix/tclUnixNotfy.c +++ b/unix/tclUnixNotfy.c @@ -238,7 +238,7 @@ typedef struct { void *hCursor; void *hbrBackground; void *lpszMenuName; - void *lpszClassName; + const void *lpszClassName; } WNDCLASS; extern void __stdcall CloseHandle(void *); diff --git a/unix/tclUnixTest.c b/unix/tclUnixTest.c index 0747c2d..722ded9 100644 --- a/unix/tclUnixTest.c +++ b/unix/tclUnixTest.c @@ -53,7 +53,7 @@ static Pipe testPipes[MAX_PIPES]; * The stuff below is used by the testalarm and testgotsig ommands. */ -static char *gotsig = "0"; +static const char *gotsig = "0"; /* * Forward declarations of functions defined later in this file: -- cgit v0.12