diff options
author | dkf <donal.k.fellows@manchester.ac.uk> | 2011-03-12 15:06:47 (GMT) |
---|---|---|
committer | dkf <donal.k.fellows@manchester.ac.uk> | 2011-03-12 15:06:47 (GMT) |
commit | 2ff0db90f57b60e46b714f2b5cdb1d2c5eacce98 (patch) | |
tree | ed891ab3e00ea5888426f25d675aff2d89a00b1d /unix | |
parent | 0d3106376c20bbe48cba344885fcad371b72b50f (diff) | |
download | tcl-2ff0db90f57b60e46b714f2b5cdb1d2c5eacce98.zip tcl-2ff0db90f57b60e46b714f2b5cdb1d2c5eacce98.tar.gz tcl-2ff0db90f57b60e46b714f2b5cdb1d2c5eacce98.tar.bz2 |
Adjust ckalloc/ckfree macros to greatly reduce number of explicit casts in
rest of Tcl source code. No ABI change. API change *should* be harmless.
Diffstat (limited to 'unix')
-rw-r--r-- | unix/tclLoadDl.c | 6 | ||||
-rw-r--r-- | unix/tclLoadDyld.c | 22 | ||||
-rw-r--r-- | unix/tclLoadNext.c | 4 | ||||
-rw-r--r-- | unix/tclLoadOSF.c | 4 | ||||
-rw-r--r-- | unix/tclLoadShl.c | 4 | ||||
-rw-r--r-- | unix/tclUnixChan.c | 26 | ||||
-rw-r--r-- | unix/tclUnixFile.c | 4 | ||||
-rw-r--r-- | unix/tclUnixInit.c | 4 | ||||
-rw-r--r-- | unix/tclUnixNotfy.c | 6 | ||||
-rw-r--r-- | unix/tclUnixPipe.c | 8 | ||||
-rw-r--r-- | unix/tclUnixSock.c | 28 | ||||
-rw-r--r-- | unix/tclUnixThrd.c | 11 | ||||
-rw-r--r-- | unix/tclXtNotify.c | 6 |
13 files changed, 64 insertions, 69 deletions
diff --git a/unix/tclLoadDl.c b/unix/tclLoadDl.c index 5341141..aeb06ef 100644 --- a/unix/tclLoadDl.c +++ b/unix/tclLoadDl.c @@ -110,7 +110,7 @@ TclpDlopen( Tcl_GetString(pathPtr), "\": ", errorStr, NULL); return TCL_ERROR; } - newHandle = (Tcl_LoadHandle) ckalloc(sizeof(*newHandle)); + newHandle = ckalloc(sizeof(*newHandle)); newHandle->clientData = handle; newHandle->findSymbolProcPtr = &FindSymbol; newHandle->unloadFileProcPtr = &UnloadFile; @@ -202,10 +202,10 @@ UnloadFile( * TclpDlopen(). The loadHandle is a token * that represents the loaded file. */ { - void *handle = (void *) loadHandle->clientData; + void *handle = loadHandle->clientData; dlclose(handle); - ckfree((char *) loadHandle); + ckfree(loadHandle); } /* diff --git a/unix/tclLoadDyld.c b/unix/tclLoadDyld.c index e2c3bab..4fa1954 100644 --- a/unix/tclLoadDyld.c +++ b/unix/tclLoadDyld.c @@ -280,8 +280,7 @@ TclpDlopen( | NSLINKMODULE_OPTION_RETURN_ON_ERROR); NSDestroyObjectFileImage(dyldObjFileImage); if (module) { - modulePtr = (Tcl_DyldModuleHandle *) - ckalloc(sizeof(Tcl_DyldModuleHandle)); + modulePtr = ckalloc(sizeof(Tcl_DyldModuleHandle)); modulePtr->module = module; modulePtr->nextPtr = NULL; TclLoadDbgMsg("NSLinkModule() successful"); @@ -307,8 +306,7 @@ TclpDlopen( || dyldLibHeader || modulePtr #endif ) { - dyldLoadHandle = (Tcl_DyldLoadHandle *) - ckalloc(sizeof(Tcl_DyldLoadHandle)); + dyldLoadHandle = ckalloc(sizeof(Tcl_DyldLoadHandle)); #if TCL_DYLD_USE_DLFCN dyldLoadHandle->dlHandle = dlHandle; #endif @@ -316,7 +314,7 @@ TclpDlopen( dyldLoadHandle->dyldLibHeader = dyldLibHeader; dyldLoadHandle->modulePtr = modulePtr; #endif - newHandle = (Tcl_LoadHandle) ckalloc(sizeof(*newHandle)); + newHandle = ckalloc(sizeof(*newHandle)); newHandle->clientData = dyldLoadHandle; newHandle->findSymbolProcPtr = &FindSymbol; newHandle->unloadFileProcPtr = &UnloadFile; @@ -413,8 +411,7 @@ FindSymbol( modulePtr = modulePtr->nextPtr; } if (modulePtr == NULL) { - modulePtr = (Tcl_DyldModuleHandle *) - ckalloc(sizeof(Tcl_DyldModuleHandle)); + modulePtr = ckalloc(sizeof(Tcl_DyldModuleHandle)); modulePtr->module = module; modulePtr->nextPtr = dyldLoadHandle->modulePtr; dyldLoadHandle->modulePtr = modulePtr; @@ -519,8 +516,8 @@ UnloadFile( } #endif /* TCL_DYLD_USE_NSMODULE */ } - ckfree((char *) dyldLoadHandle); - ckfree((char *) loadHandle); + ckfree(dyldLoadHandle); + ckfree(loadHandle); } /* @@ -765,17 +762,16 @@ TclpLoadMemory( * Stash the module reference within the load handle we create and return. */ - modulePtr = (Tcl_DyldModuleHandle *) ckalloc(sizeof(Tcl_DyldModuleHandle)); + modulePtr = ckalloc(sizeof(Tcl_DyldModuleHandle)); modulePtr->module = module; modulePtr->nextPtr = NULL; - dyldLoadHandle = (Tcl_DyldLoadHandle *) - ckalloc(sizeof(Tcl_DyldLoadHandle)); + dyldLoadHandle = ckalloc(sizeof(Tcl_DyldLoadHandle)); #if TCL_DYLD_USE_DLFCN dyldLoadHandle->dlHandle = NULL; #endif dyldLoadHandle->dyldLibHeader = NULL; dyldLoadHandle->modulePtr = modulePtr; - newHandle = (Tcl_LoadHandle) ckalloc(sizeof(*newHandle)); + newHandle = ckalloc(sizeof(*newHandle)); newHandle->clientData = dyldLoadHandle; newHandle->findSymbolProcPtr = &FindSymbol; newHandle->unloadFileProcPtr = &UnloadFile; diff --git a/unix/tclLoadNext.c b/unix/tclLoadNext.c index b6225f0..c74a29a 100644 --- a/unix/tclLoadNext.c +++ b/unix/tclLoadNext.c @@ -101,7 +101,7 @@ TclpDlopen( } NXCloseMemory(errorStream, NX_FREEBUFFER); - newHandle = (Tcl_LoadHandle) ckalloc(sizeof(*newHandle)); + newHandle = ckalloc(sizeof(*newHandle)); newHandle->clientData = INT2PTR(1); newHandle->findSymbolProcPtr = &FindSymbol; newHandle->unloadFileProcPtr = &UnloadFile; @@ -175,7 +175,7 @@ UnloadFile( * TclpDlopen(). The loadHandle is a token * that represents the loaded file. */ { - ckfree((char*) loadHandle); + ckfree(loadHandle); } /* diff --git a/unix/tclLoadOSF.c b/unix/tclLoadOSF.c index 9ed49f2..fbd4d5f 100644 --- a/unix/tclLoadOSF.c +++ b/unix/tclLoadOSF.c @@ -124,7 +124,7 @@ TclpDlopen( } else { pkg++; } - newHandle = (Tcl_LoadHandle*) ckalloc(sizeof(*newHandle)); + newHandle = ckalloc(sizeof(*newHandle)); newHandle->clientData = pkg; newHandle->findSymbolProcPtr = &FindSymbol; newHandle->unloadFileProcPtr = &UnloadFile; @@ -188,7 +188,7 @@ UnloadFile( * TclpDlopen(). The loadHandle is a token * that represents the loaded file. */ { - ckfree((char*) loadHandle); + ckfree(loadHandle); } /* diff --git a/unix/tclLoadShl.c b/unix/tclLoadShl.c index a7b41d7..9656983 100644 --- a/unix/tclLoadShl.c +++ b/unix/tclLoadShl.c @@ -104,7 +104,7 @@ TclpDlopen( Tcl_PosixError(interp), (char *) NULL); return TCL_ERROR; } - newHandle = (Tcl_LoadHandle) ckalloc(sizeof(*newHandle)); + newHandle = ckalloc(sizeof(*newHandle)); newHandle->clientData = handle; newHandle->findSymbolProcPtr = &FindSymbol; newHandle->unloadFileProcPtr = *unloadProcPtr = &UnloadFile; @@ -190,7 +190,7 @@ UnloadFile( handle = (shl_t) (loadHandle -> clientData); shl_unload(handle); - ckfree((char*) loadHandle); + ckfree(loadHandle); } /* diff --git a/unix/tclUnixChan.c b/unix/tclUnixChan.c index 302e171..6ee9b89 100644 --- a/unix/tclUnixChan.c +++ b/unix/tclUnixChan.c @@ -396,7 +396,7 @@ FileCloseProc( errorCode = errno; } } - ckfree((char *) fsPtr); + ckfree(fsPtr); return errorCode; } @@ -720,7 +720,7 @@ TtySetOptionProc( Tcl_AppendResult(interp, "bad value for -xchar: " "should be a list of two elements", NULL); } - ckfree((char *) argv); + ckfree(argv); return TCL_ERROR; } @@ -733,7 +733,7 @@ TtySetOptionProc( Tcl_UtfToExternalDString(NULL, argv[1], -1, &ds); iostate.c_cc[VSTOP] = *(const cc_t *) Tcl_DStringValue(&ds); Tcl_DStringFree(&ds); - ckfree((char *) argv); + ckfree(argv); SETIOSTATE(fsPtr->fd, &iostate); return TCL_OK; @@ -771,14 +771,14 @@ TtySetOptionProc( Tcl_AppendResult(interp, "bad value for -ttycontrol: " "should be a list of signal,value pairs", NULL); } - ckfree((char *) argv); + ckfree(argv); return TCL_ERROR; } GETCONTROL(fsPtr->fd, &control); for (i = 0; i < argc-1; i += 2) { if (Tcl_GetBoolean(interp, argv[i+1], &flag) == TCL_ERROR) { - ckfree((char *) argv); + ckfree(argv); return TCL_ERROR; } if (strncasecmp(argv[i], "DTR", strlen(argv[i])) == 0) { @@ -790,7 +790,7 @@ TtySetOptionProc( } #else /* !TIOCM_DTR */ UNSUPPORTED_OPTION("-ttycontrol DTR"); - ckfree((char *) argv); + ckfree(argv); return TCL_ERROR; #endif /* TIOCM_DTR */ } else if (strncasecmp(argv[i], "RTS", strlen(argv[i])) == 0) { @@ -802,7 +802,7 @@ TtySetOptionProc( } #else /* !TIOCM_RTS*/ UNSUPPORTED_OPTION("-ttycontrol RTS"); - ckfree((char *) argv); + ckfree(argv); return TCL_ERROR; #endif /* TIOCM_RTS*/ } else if (strncasecmp(argv[i], "BREAK", strlen(argv[i])) == 0) { @@ -810,7 +810,7 @@ TtySetOptionProc( SETBREAK(fsPtr->fd, flag); #else /* !SETBREAK */ UNSUPPORTED_OPTION("-ttycontrol BREAK"); - ckfree((char *) argv); + ckfree(argv); return TCL_ERROR; #endif /* SETBREAK */ } else { @@ -819,13 +819,13 @@ TtySetOptionProc( "\" for -ttycontrol: must be " "DTR, RTS or BREAK", NULL); } - ckfree((char *) argv); + ckfree(argv); return TCL_ERROR; } } /* -ttycontrol options loop */ SETCONTROL(fsPtr->fd, &control); - ckfree((char *) argv); + ckfree(argv); return TCL_OK; } @@ -1458,7 +1458,7 @@ TtyInit( * initialized. */ int initialize) { - TtyState *ttyPtr = (TtyState *) ckalloc((unsigned) sizeof(TtyState)); + TtyState *ttyPtr = ckalloc(sizeof(TtyState)); int stateUpdated = 0; GETIOSTATE(fd, &ttyPtr->savedState); @@ -1609,7 +1609,7 @@ TclpOpenFileChannel( { translation = NULL; channelTypePtr = &fileChannelType; - fsPtr = (FileState *) ckalloc((unsigned) sizeof(FileState)); + fsPtr = ckalloc(sizeof(FileState)); } fsPtr->validMask = channelPermissions | TCL_EXCEPTION; @@ -1685,7 +1685,7 @@ Tcl_MakeFileChannel( return TclpMakeTcpClientChannelMode(INT2PTR(fd), mode); } else { channelTypePtr = &fileChannelType; - fsPtr = (FileState *) ckalloc((unsigned) sizeof(FileState)); + fsPtr = ckalloc(sizeof(FileState)); sprintf(channelName, "file%d", fd); } diff --git a/unix/tclUnixFile.c b/unix/tclUnixFile.c index b6a8b97..2be68c4 100644 --- a/unix/tclUnixFile.c +++ b/unix/tclUnixFile.c @@ -705,7 +705,7 @@ TclpGetNativeCwd( #endif if ((clientData == NULL) || strcmp(buffer, (const char*)clientData)) { - char *newCd = ckalloc((unsigned) strlen(buffer) + 1); + char *newCd = ckalloc(strlen(buffer) + 1); strcpy(newCd, buffer); return newCd; @@ -1109,7 +1109,7 @@ TclNativeCreateNativeRep( Tcl_UtfToExternalDString(NULL, str, len, &ds); len = Tcl_DStringLength(&ds) + sizeof(char); Tcl_DecrRefCount(validPathPtr); - nativePathPtr = ckalloc((unsigned) len); + nativePathPtr = ckalloc(len); memcpy(nativePathPtr, Tcl_DStringValue(&ds), (size_t) len); Tcl_DStringFree(&ds); diff --git a/unix/tclUnixInit.c b/unix/tclUnixInit.c index 7bbdc5c..8f872d5 100644 --- a/unix/tclUnixInit.c +++ b/unix/tclUnixInit.c @@ -473,7 +473,7 @@ TclpInitLibraryPath( Tcl_ListObjAppendElement(NULL, pathPtr, objPtr); Tcl_DStringFree(&ds); } - ckfree((char *) pathv); + ckfree(pathv); } /* @@ -506,7 +506,7 @@ TclpInitLibraryPath( *encodingPtr = Tcl_GetEncoding(NULL, NULL); str = Tcl_GetStringFromObj(pathPtr, lengthPtr); - *valuePtr = ckalloc((unsigned int) (*lengthPtr)+1); + *valuePtr = ckalloc((*lengthPtr) + 1); memcpy(*valuePtr, str, (size_t)(*lengthPtr)+1); Tcl_DecrRefCount(pathPtr); } diff --git a/unix/tclUnixNotfy.c b/unix/tclUnixNotfy.c index 34e1fbb..ebbbb78 100644 --- a/unix/tclUnixNotfy.c +++ b/unix/tclUnixNotfy.c @@ -460,7 +460,7 @@ Tcl_CreateFileHandler( } } if (filePtr == NULL) { - filePtr = (FileHandler *) ckalloc(sizeof(FileHandler)); + filePtr = ckalloc(sizeof(FileHandler)); filePtr->fd = fd; filePtr->readyMask = 0; filePtr->nextPtr = tsdPtr->firstFileHandlerPtr; @@ -579,7 +579,7 @@ Tcl_DeleteFileHandler( } else { prevPtr->nextPtr = filePtr->nextPtr; } - ckfree((char *) filePtr); + ckfree(filePtr); } } @@ -870,7 +870,7 @@ Tcl_WaitForEvent( */ if (filePtr->readyMask == 0) { - FileHandlerEvent *fileEvPtr = (FileHandlerEvent *) + FileHandlerEvent *fileEvPtr = ckalloc(sizeof(FileHandlerEvent)); fileEvPtr->header.proc = FileHandlerEventProc; diff --git a/unix/tclUnixPipe.c b/unix/tclUnixPipe.c index 30a6da8..d01624c 100644 --- a/unix/tclUnixPipe.c +++ b/unix/tclUnixPipe.c @@ -761,7 +761,7 @@ TclpCreateCommandChannel( { char channelName[16 + TCL_INTEGER_SPACE]; int channelId; - PipeState *statePtr = (PipeState *) ckalloc((unsigned) sizeof(PipeState)); + PipeState *statePtr = ckalloc(sizeof(PipeState)); int mode; statePtr->inFile = readFile; @@ -893,7 +893,7 @@ TclGetAndDetachPids( Tcl_DetachPids(1, &(pipePtr->pidPtr[i])); } if (pipePtr->numPids > 0) { - ckfree((char *) pipePtr->pidPtr); + ckfree(pipePtr->pidPtr); pipePtr->numPids = 0; } } @@ -1024,9 +1024,9 @@ PipeClose2Proc( } if (pipePtr->numPids != 0) { - ckfree((char *) pipePtr->pidPtr); + ckfree(pipePtr->pidPtr); } - ckfree((char *) pipePtr); + ckfree(pipePtr); if (errorCode == 0) { return result; } diff --git a/unix/tclUnixSock.c b/unix/tclUnixSock.c index b55d1cb..35728e1 100644 --- a/unix/tclUnixSock.c +++ b/unix/tclUnixSock.c @@ -182,7 +182,7 @@ InitializeHostName( char *dot = strchr(u.nodename, '.'); if (dot != NULL) { - char *node = ckalloc((unsigned) (dot - u.nodename + 1)); + char *node = ckalloc(dot - u.nodename + 1); memcpy(node, u.nodename, (size_t) (dot - u.nodename)); node[dot - u.nodename] = '\0'; @@ -228,7 +228,7 @@ InitializeHostName( *encodingPtr = Tcl_GetEncoding(NULL, NULL); *lengthPtr = strlen(native); - *valuePtr = ckalloc((unsigned) (*lengthPtr) + 1); + *valuePtr = ckalloc((*lengthPtr) + 1); memcpy(*valuePtr, native, (size_t)(*lengthPtr)+1); } @@ -528,9 +528,9 @@ TcpCloseProc( if (close(fds->fd) < 0) { errorCode = errno; } - ckfree((char *) fds); + ckfree(fds); } - ckfree((char *) statePtr); + ckfree(statePtr); return errorCode; } @@ -995,9 +995,9 @@ error: * Allocate a new TcpState for this socket. */ - statePtr = (TcpState *) ckalloc((unsigned) sizeof(TcpState)); + statePtr = ckalloc(sizeof(TcpState)); statePtr->flags = async ? TCP_ASYNC_CONNECT : 0; - statePtr->fds = (TcpFdList *) ckalloc((unsigned) sizeof(TcpFdList)); + statePtr->fds = ckalloc(sizeof(TcpFdList)); memset(statePtr->fds, (int) 0, sizeof(TcpFdList)); statePtr->fds->fd = sock; @@ -1108,8 +1108,8 @@ TclpMakeTcpClientChannelMode( TcpState *statePtr; char channelName[16 + TCL_INTEGER_SPACE]; - statePtr = (TcpState *) ckalloc((unsigned) sizeof(TcpState)); - statePtr->fds = (TcpFdList *) ckalloc((unsigned) sizeof(TcpFdList)); + statePtr = ckalloc(sizeof(TcpState)); + statePtr->fds = ckalloc(sizeof(TcpFdList)); memset(statePtr->fds, (int) 0, sizeof(TcpFdList)); statePtr->fds->fd = PTR2INT(sock); statePtr->flags = 0; @@ -1239,14 +1239,14 @@ Tcl_OpenTcpServer( close(sock); continue; } - newfds = (TcpFdList *) ckalloc((unsigned) sizeof(TcpFdList)); + newfds = ckalloc(sizeof(TcpFdList)); memset(newfds, (int) 0, sizeof(TcpFdList)); if (statePtr == NULL) { /* * Allocate a new TcpState for this socket. */ - statePtr = (TcpState *) ckalloc((unsigned) sizeof(TcpState)); + statePtr = ckalloc(sizeof(TcpState)); statePtr->fds = newfds; statePtr->acceptProc = acceptProc; statePtr->acceptProcData = acceptProcData; @@ -1310,7 +1310,7 @@ TcpAccept( ClientData data, /* Callback token. */ int mask) /* Not used. */ { - TcpFdList *fds; /* Client data of server socket. */ + TcpFdList *fds = data; /* Client data of server socket. */ int newsock; /* The new client socket */ TcpState *newSockState; /* State for new socket. */ address addr; /* The remote address */ @@ -1318,8 +1318,6 @@ TcpAccept( char channelName[16 + TCL_INTEGER_SPACE]; char host[NI_MAXHOST], port[NI_MAXSERV]; - fds = (TcpFdList *) data; - len = sizeof(addr); newsock = accept(fds->fd, &(addr.sa), &len); if (newsock < 0) { @@ -1333,10 +1331,10 @@ TcpAccept( (void) fcntl(newsock, F_SETFD, FD_CLOEXEC); - newSockState = (TcpState *) ckalloc((unsigned) sizeof(TcpState)); + newSockState = ckalloc(sizeof(TcpState)); newSockState->flags = 0; - newSockState->fds = (TcpFdList *) ckalloc(sizeof(TcpFdList)); + newSockState->fds = ckalloc(sizeof(TcpFdList)); memset(newSockState->fds, (int) 0, sizeof(TcpFdList)); newSockState->fds->fd = newsock; newSockState->acceptProc = NULL; diff --git a/unix/tclUnixThrd.c b/unix/tclUnixThrd.c index 7a4300e..0469d7a 100644 --- a/unix/tclUnixThrd.c +++ b/unix/tclUnixThrd.c @@ -430,7 +430,7 @@ Tcl_MutexLock( * Double inside master lock check to avoid a race condition. */ - pmutexPtr = (pthread_mutex_t *) ckalloc(sizeof(pthread_mutex_t)); + pmutexPtr = ckalloc(sizeof(pthread_mutex_t)); pthread_mutex_init(pmutexPtr, NULL); *mutexPtr = (Tcl_Mutex)pmutexPtr; TclRememberMutex(mutexPtr); @@ -494,7 +494,7 @@ TclpFinalizeMutex( if (pmutexPtr != NULL) { pthread_mutex_destroy(pmutexPtr); - ckfree((char *) pmutexPtr); + ckfree(pmutexPtr); *mutexPtr = NULL; } } @@ -540,9 +540,9 @@ Tcl_ConditionWait( */ if (*condPtr == NULL) { - pcondPtr = (pthread_cond_t *) ckalloc(sizeof(pthread_cond_t)); + pcondPtr = ckalloc(sizeof(pthread_cond_t)); pthread_cond_init(pcondPtr, NULL); - *condPtr = (Tcl_Condition)pcondPtr; + *condPtr = (Tcl_Condition) pcondPtr; TclRememberCondition(condPtr); } MASTER_UNLOCK; @@ -624,9 +624,10 @@ TclpFinalizeCondition( Tcl_Condition *condPtr) { pthread_cond_t *pcondPtr = *(pthread_cond_t **)condPtr; + if (pcondPtr != NULL) { pthread_cond_destroy(pcondPtr); - ckfree((char *) pcondPtr); + ckfree(pcondPtr); *condPtr = NULL; } } diff --git a/unix/tclXtNotify.c b/unix/tclXtNotify.c index 71215f4..50eb4a2 100644 --- a/unix/tclXtNotify.c +++ b/unix/tclXtNotify.c @@ -358,7 +358,7 @@ CreateFileHandler( } } if (filePtr == NULL) { - filePtr = (FileHandler *) ckalloc(sizeof(FileHandler)); + filePtr = ckalloc(sizeof(FileHandler)); filePtr->fd = fd; filePtr->read = 0; filePtr->write = 0; @@ -469,7 +469,7 @@ DeleteFileHandler( if (filePtr->mask & TCL_EXCEPTION) { XtRemoveInput(filePtr->except); } - ckfree((char *) filePtr); + ckfree(filePtr); } /* @@ -524,7 +524,7 @@ FileProc( */ filePtr->readyMask |= mask; - fileEvPtr = (FileHandlerEvent *) ckalloc(sizeof(FileHandlerEvent)); + fileEvPtr = ckalloc(sizeof(FileHandlerEvent)); fileEvPtr->header.proc = FileHandlerEventProc; fileEvPtr->fd = filePtr->fd; Tcl_QueueEvent((Tcl_Event *) fileEvPtr, TCL_QUEUE_TAIL); |