Skip to content

Commit

Permalink
Tcl_Alloc -> ckalloc. Remove unnecessary type-casts.
Browse files Browse the repository at this point in the history
  • Loading branch information
jan.nijtmans committed Feb 14, 2024
1 parent 535f5f5 commit d315baa
Show file tree
Hide file tree
Showing 12 changed files with 53 additions and 53 deletions.
2 changes: 1 addition & 1 deletion generic/tkCmds.c
Expand Up @@ -383,7 +383,7 @@ Tk_BindtagsObjCmd(
} else {
for (i = 0; i < winPtr->numTags; i++) {
Tcl_ListObjAppendElement(NULL, listPtr,
Tcl_NewStringObj(winPtr->tagPtr[i], TCL_INDEX_NONE));
Tcl_NewStringObj((const char *)winPtr->tagPtr[i], TCL_INDEX_NONE));
}
}
Tcl_SetObjResult(interp, listPtr);
Expand Down
2 changes: 1 addition & 1 deletion generic/tkEntry.c
Expand Up @@ -1051,7 +1051,7 @@ DestroyEntry(
* Tk_FreeOptions handle all the standard option-related stuff.
*/

ckfree((char *)entryPtr->string);
ckfree(entryPtr->string);
if (entryPtr->textVarName != NULL) {
Tcl_UntraceVar2(entryPtr->interp, entryPtr->textVarName,
NULL, TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS,
Expand Down
2 changes: 1 addition & 1 deletion generic/tkImage.c
Expand Up @@ -951,7 +951,7 @@ Tk_DeleteImage(
if (hPtr == NULL) {
return;
}
DeleteImage(Tcl_GetHashValue(hPtr));
DeleteImage((char *)Tcl_GetHashValue(hPtr));
}

/*
Expand Down
4 changes: 2 additions & 2 deletions generic/tkOldConfig.c
Expand Up @@ -958,9 +958,9 @@ Tk_ConfigureValue(
Tcl_SetObjResult(interp, Tcl_NewStringObj(result, TCL_INDEX_NONE));
if (freeProc != NULL) {
if (freeProc == TCL_DYNAMIC) {
ckfree((char *) result);
ckfree((char *)result);
} else {
freeProc((char *) result);
freeProc((char *)result);
}
}
return TCL_OK;
Expand Down
2 changes: 1 addition & 1 deletion generic/tkText.c
Expand Up @@ -5603,7 +5603,7 @@ TkTextRunAfterSyncCmd(
*/

if (textPtr->refCount-- <= 1) {
ckfree((char *) textPtr);
ckfree(textPtr);
}
return;
}
Expand Down
2 changes: 1 addition & 1 deletion unix/tkUnixWm.c
Expand Up @@ -2490,7 +2490,7 @@ WmIconphotoCmd(
for (i = 3 + isDefault; i < objc; i++) {
photo = Tk_FindPhoto(interp, Tcl_GetString(objv[i]));
if (photo == NULL) {
ckfree((char *) iconPropertyData);
ckfree(iconPropertyData);
Tcl_SetObjResult(interp, Tcl_ObjPrintf(
"failed to create an iconphoto with image \"%s\"",
Tcl_GetString(objv[i])));
Expand Down
4 changes: 2 additions & 2 deletions win/tkWinButton.c
Expand Up @@ -113,7 +113,7 @@ static Window CreateProc(Tk_Window tkwin, Window parent,
void *instanceData);
static void InitBoxes(Tk_Window tkwin);
static void ColorToStr(COLORREF color, char *colorStr);
static void ImageChanged(ClientData clientData,
static void ImageChanged(void *clientData,
int x, int y, int width, int height,
int imageWidth, int imageHeight);
static void TkpDrawIndicator(TkButton *butPtr, Drawable d,
Expand Down Expand Up @@ -333,7 +333,7 @@ ColorToStr(

static void
ImageChanged(
ClientData clientData,
void *clientData,
int x, int y, int width, int height,
int imageWidth, int imageHeight)
{
Expand Down
4 changes: 2 additions & 2 deletions win/tkWinDialog.c
Expand Up @@ -2166,9 +2166,9 @@ static void FreeFilterVista(DWORD count, TCLCOMDLG_FILTERSPEC *dlgFilterPtr)
DWORD dw;
for (dw = 0; dw < count; ++dw) {
if (dlgFilterPtr[dw].pszName != NULL)
ckfree((char *)dlgFilterPtr[dw].pszName);
ckfree(dlgFilterPtr[dw].pszName);
if (dlgFilterPtr[dw].pszSpec != NULL)
ckfree((char *)dlgFilterPtr[dw].pszSpec);
ckfree(dlgFilterPtr[dw].pszSpec);
}
ckfree(dlgFilterPtr);
}
Expand Down
58 changes: 29 additions & 29 deletions win/tkWinGDI.c
Expand Up @@ -85,22 +85,22 @@ static void GetDisplaySize(LONG *width, LONG *height);
static int GdiWordToWeight(const char *str);
static int GdiParseFontWords(Tcl_Interp *interp, LOGFONTW *lf,
const char *str[], int numargs);
static int PrintSelectPrinter(ClientData clientData,
static int PrintSelectPrinter(void *clientData,
Tcl_Interp *interp, int objc,
Tcl_Obj *const objv[]);
static int PrintOpenPrinter(ClientData clientData,
static int PrintOpenPrinter(void *clientData,
Tcl_Interp *interp, int objc,
Tcl_Obj *const objv[]);
static int PrintClosePrinter(ClientData clientData,
static int PrintClosePrinter(void *clientData,
Tcl_Interp *interp, int objc,
Tcl_Obj *const objv[]);
static int PrintOpenDoc(ClientData clientData, Tcl_Interp *interp,
static int PrintOpenDoc(void *clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *const objv[]);
static int PrintCloseDoc(ClientData clientData, Tcl_Interp *interp,
static int PrintCloseDoc(void *clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *const objv[]);
static int PrintOpenPage(ClientData clientData, Tcl_Interp *interp,
static int PrintOpenPage(void *clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *const objv[]);
static int PrintClosePage(ClientData clientData,
static int PrintClosePage(void *clientData,
Tcl_Interp *interp, int objc,
Tcl_Obj *const objv[]);

Expand Down Expand Up @@ -481,7 +481,7 @@ static int GdiPhoto(
* recoverable.
*/

pbuf = (char *) Tcl_AttemptAlloc(sll * ny * sizeof(char));
pbuf = (char *)attemptckalloc(sll * ny * sizeof(char));
if (pbuf == 0) { /* Memory allocation failure. */
Tcl_AppendResult(interp,
"::tk::print::_gdi photo failed--out of memory", NULL);
Expand Down Expand Up @@ -546,7 +546,7 @@ static int GdiPhoto(
SetBrushOrgEx(dst, pt.x, pt.y, &pt);
}

Tcl_Free(pbuf);
ckfree(pbuf);

if (retval == TCL_OK) {
Tcl_SetObjResult(interp, Tcl_ObjPrintf(
Expand Down Expand Up @@ -582,7 +582,7 @@ static int Bezierize(
int nbpoints = 0;
POINT* bpoints;

inPointList = (double *) Tcl_AttemptAlloc(2 * sizeof(double) * npoly);
inPointList = (double *)attemptckalloc(2 * sizeof(double) * npoly);
if (inPointList == 0) {
/* TODO: unreachable */
return nbpoints; /* 0. */
Expand All @@ -594,29 +594,29 @@ static int Bezierize(
}

nbpoints = 1 + npoly * nStep; /* this is the upper limit. */
outPointList = (double *) Tcl_AttemptAlloc(2 * sizeof(double) * nbpoints);
outPointList = (double *)attemptckalloc(2 * sizeof(double) * nbpoints);
if (outPointList == 0) {
/* TODO: unreachable */
Tcl_Free((void *) inPointList);
ckfree((void *) inPointList);
return 0;
}

nbpoints = TkMakeBezierCurve(NULL, inPointList, npoly, nStep,
NULL, outPointList);

Tcl_Free((void *) inPointList);
bpoints = (POINT *) Tcl_AttemptAlloc(sizeof(POINT)*nbpoints);
ckfree((void *) inPointList);
bpoints = (POINT *)attemptckalloc(sizeof(POINT)*nbpoints);
if (bpoints == 0) {
/* TODO: unreachable */
Tcl_Free((void *) outPointList);
ckfree((void *) outPointList);
return 0;
}

for (n=0; n<nbpoints; n++) {
bpoints[n].x = (long) outPointList[2*n];
bpoints[n].y = (long) outPointList[2*n + 1];
}
Tcl_Free((void *) outPointList);
ckfree((void *) outPointList);
*bpointptr = *bpoints;
return nbpoints;
}
Expand Down Expand Up @@ -681,7 +681,7 @@ static int GdiLine(

hDC = printDC;

polypoints = (POINT *) Tcl_AttemptAlloc((argc - 1) * sizeof(POINT));
polypoints = (POINT *)attemptckalloc((argc - 1) * sizeof(POINT));
if (polypoints == 0) {
Tcl_AppendResult(interp, "Out of memory in GdiLine", NULL);
return TCL_ERROR;
Expand Down Expand Up @@ -712,7 +712,7 @@ static int GdiLine(
objv += 2;
} else {
/* Only one number... Assume a usage error. */
Tcl_Free((void *)polypoints);
ckfree((void *)polypoints);
Tcl_AppendResult(interp, usage_message, NULL);
return TCL_ERROR;
}
Expand Down Expand Up @@ -826,7 +826,7 @@ static int GdiLine(
Polyline(hDC, polypoints, npoly); /* Out of memory? Just draw a regular line. */
}
if (bpoints != 0) {
Tcl_Free((void *)bpoints);
ckfree((void *)bpoints);
}
} else {
Polyline(hDC, polypoints, npoly);
Expand Down Expand Up @@ -918,7 +918,7 @@ static int GdiLine(
GdiFreeBrush(interp, hDC, hBrush);
}

Tcl_Free((void *)polypoints);
ckfree((void *)polypoints);
return TCL_OK;
}

Expand Down Expand Up @@ -1091,7 +1091,7 @@ static int GdiPolygon(

hDC = printDC;

polypoints = (POINT *) Tcl_AttemptAlloc((argc - 1) * sizeof(POINT));
polypoints = (POINT *)attemptckalloc((argc - 1) * sizeof(POINT));
if (polypoints == 0) {
/* TODO: unreachable */
Tcl_AppendResult(interp, "Out of memory in GdiLine", NULL);
Expand Down Expand Up @@ -1122,7 +1122,7 @@ static int GdiPolygon(
objv += 2;
} else {
/* Only one number... Assume a usage error. */
Tcl_Free((void *) polypoints);
ckfree((void *) polypoints);
Tcl_AppendResult(interp, usage_message, NULL);
return TCL_ERROR;
}
Expand Down Expand Up @@ -1198,7 +1198,7 @@ static int GdiPolygon(
Polygon(hDC, polypoints, npoly);
}
if (bpoints != 0) {
Tcl_Free((void *)bpoints);
ckfree((void *)bpoints);
}
} else {
Polygon(hDC, polypoints, npoly);
Expand All @@ -1213,7 +1213,7 @@ static int GdiPolygon(
SelectObject(hDC, oldobj);
}

Tcl_Free((void *)polypoints);
ckfree((void *)polypoints);
return TCL_OK;
}

Expand Down Expand Up @@ -2642,7 +2642,7 @@ static int GdiMakeLogFont(
GdiParseFontWords(interp, lf, list+2, count-2);
}

Tcl_Free((char *)list);
ckfree(list);
return 1;
}

Expand Down Expand Up @@ -2706,7 +2706,7 @@ static int GdiMakePen(
if (dashstyle != 0 && dashstyledata != 0) {
const char *cp;
size_t i;
char *dup = (char *) Tcl_Alloc(strlen(dashstyledata) + 1);
char *dup = (char *) ckalloc(strlen(dashstyledata) + 1);
strcpy(dup, dashstyledata);
/* DEBUG. */
Tcl_SetObjResult(interp, Tcl_ObjPrintf(
Expand Down Expand Up @@ -2749,7 +2749,7 @@ static int GdiMakePen(
dashstyle = 0;
}
if (dup) {
Tcl_Free(dup);
ckfree(dup);
}
}

Expand Down Expand Up @@ -3654,8 +3654,8 @@ static int PrintSelectPrinter(
* script level.
*/
if (localPrinterName != NULL) {
char* varlink1 = (char*)Tcl_Alloc(100 * sizeof(char));
char** varlink2 = (char**)Tcl_Alloc(sizeof(char*));
char* varlink1 = (char*)ckalloc(100 * sizeof(char));
char** varlink2 = (char**)ckalloc(sizeof(char*));
*varlink2 = varlink1;
WideCharToMultiByte(CP_UTF8, 0, localPrinterName, -1, varlink1, 0, NULL, NULL);

Expand Down
2 changes: 1 addition & 1 deletion win/tkWinSendCom.c
Expand Up @@ -144,7 +144,7 @@ static void
TkWinSendCom_Destroy(
LPDISPATCH pdisp)
{
CoTaskMemFree((void *) pdisp);
CoTaskMemFree(pdisp);
}

/*
Expand Down
16 changes: 8 additions & 8 deletions win/tkWinSysTray.c
Expand Up @@ -191,7 +191,7 @@ DrawANDMask(
lpIcon->lpAND, lpbi, DIB_RGB_COLORS);

/* clean up */
ckfree((char *) lpbi);
ckfree(lpbi);

return TRUE;
}
Expand Down Expand Up @@ -851,7 +851,7 @@ CreateTaskbarHandlerWindow(void) {

static void
WinIcoDestroy(
ClientData clientData,
void *clientData,
XEvent *eventPtr)
{
IcoInterpInfo *icoInterpPtr = (IcoInterpInfo*) clientData;
Expand All @@ -878,7 +878,7 @@ WinIcoDestroy(
nextPtr = icoPtr->nextPtr;
FreeIcoPtr(icoInterpPtr, icoPtr);
}
ckfree((char *) icoInterpPtr);
ckfree(icoInterpPtr);
}

/*
Expand All @@ -899,7 +899,7 @@ WinIcoDestroy(

static int
WinSystrayCmd(
ClientData clientData,
void *clientData,
Tcl_Interp *interp,
int objc,
Tcl_Obj *const objv[])
Expand Down Expand Up @@ -1060,7 +1060,7 @@ WinSystrayCmd(

static int
WinSysNotifyCmd(
ClientData clientData,
void *clientData,
Tcl_Interp *interp,
int objc,
Tcl_Obj *const objv[])
Expand Down Expand Up @@ -1159,12 +1159,12 @@ WinIcoInit(
icoInterpPtr->nextPtr = firstIcoInterpPtr;
firstIcoInterpPtr = icoInterpPtr;
Tcl_CreateObjCommand(interp, "::tk::systray::_systray", WinSystrayCmd,
(ClientData) icoInterpPtr, NULL);
icoInterpPtr, NULL);
Tcl_CreateObjCommand(interp, "::tk::sysnotify::_sysnotify", WinSysNotifyCmd,
(ClientData) icoInterpPtr, NULL);
icoInterpPtr, NULL);

Tk_CreateEventHandler(mainWindow, StructureNotifyMask,
WinIcoDestroy, (ClientData) icoInterpPtr);
WinIcoDestroy, icoInterpPtr);

return TCL_OK;
}
Expand Down
8 changes: 4 additions & 4 deletions win/ttkWinXPTheme.c
Expand Up @@ -426,10 +426,10 @@ static void DestroyElementData(void *clientData)
{
ElementData *elementData = (ElementData *)clientData;
if (elementData->info->flags & HEAP_ELEMENT) {
ckfree((char *)elementData->info->statemap);
ckfree((char *)elementData->info->className);
ckfree((char *)elementData->info->elementName);
ckfree((char *)elementData->info);
ckfree(elementData->info->statemap);
ckfree(elementData->info->className);
ckfree(elementData->info->elementName);
ckfree(elementData->info);
}
ckfree(clientData);
}
Expand Down

0 comments on commit d315baa

Please sign in to comment.