From 06f59b99282221ee57c7522fee82e757d50258a1 Mon Sep 17 00:00:00 2001 From: "Carlos R. Mafra" Date: Thu, 6 Nov 2008 01:37:44 +0100 Subject: [PATCH] wmaker: Fix compiler warnings about pointer <--> integer conversion There may be issues with running applications in 64-bit mode when they were written with tacit assumptions about 32-bit platforms. For example, * Assuming that a pointer can be cast back and forth to an integer The reason is that the size of the integer and pointer may be different. See the description of "[PATCH] Warn when casting a pointer (constant) to an integer of different size." in the gcc mailing list http://gcc.gnu.org/ml/gcc-patches/2005-12/msg01881.html where it was also suggested the use of casts to uintptr_t. This is what this patch does. As a result the following warnings are fixed, leaving us with an almost warning-free compilation in 64-bit platforms: defaults.c:1446: warning: cast to pointer from integer of different size defaults.c:1457: warning: cast to pointer from integer of different size defaults.c:1471: warning: cast to pointer from integer of different size defaults.c:1486: warning: cast to pointer from integer of different size icon.c:67: warning: cast from pointer to integer of different size menu.c:112: warning: cast from pointer to integer of different size switchmenu.c:452: warning: cast from pointer to integer of different size window.c:140: warning: cast from pointer to integer of different size window.c:2217: warning: cast to pointer from integer of different size workspace.c:135: warning: cast to pointer from integer of different size workspace.c:214: warning: cast to pointer from integer of different size workspace.c:634: warning: cast to pointer from integer of different size workspace.c:1330: warning: cast to pointer from integer of different size workspace.c:1514: warning: cast to pointer from integer of different size wfilepanel.c:135: warning: cast from pointer to integer of different size wfilepanel.c:171: warning: cast from pointer to integer of different size wfontpanel.c:499: warning: cast to pointer from integer of different size wfontpanel.c:500: warning: cast to pointer from integer of different size wfontpanel.c:505: warning: cast to pointer from integer of different size wfontpanel.c:506: warning: cast to pointer from integer of different size wfontpanel.c:776: warning: cast from pointer to integer of different size wfontpanel.c:777: warning: cast from pointer to integer of different size wfontpanel.c:877: warning: cast from pointer to integer of different size wfontpanel.c:878: warning: cast from pointer to integer of different size wpanel.c:363: warning: cast from pointer to integer of different size fontl.c:42: warning: cast from pointer to integer of different size fontl.c:42: warning: cast from pointer to integer of different size fontl.c:42: warning: cast from pointer to integer of different size fontl.c:90: warning: cast to pointer from integer of different size puzzle.c:138: warning: cast from pointer to integer of different size puzzle.c:225: warning: cast to pointer from integer of different size wtableview.c:1031: warning: cast to pointer from integer of different size wtableview.c:1067: warning: cast to pointer from integer of different size wtableview.c:1069: warning: cast to pointer from integer of different size wtableview.c:1074: warning: cast to pointer from integer of different size wtabledelegates.c:234: warning: cast from pointer to integer of different size wtabledelegates.c:250: warning: cast from pointer to integer of different size wtabledelegates.c:265: warning: cast from pointer to integer of different size wtabledelegates.c:287: warning: cast to pointer from integer of different size wtabledelegates.c:351: warning: cast from pointer to integer of different size wtabledelegates.c:372: warning: cast from pointer to integer of different size wtabledelegates.c:393: warning: cast from pointer to integer of different size wtabledelegates.c:410: warning: cast to pointer from integer of different size test.c:44: warning: cast from pointer to integer of different size test.c:47: warning: cast to pointer from integer of different size test.c:55: warning: cast from pointer to integer of different size test.c:58: warning: cast from pointer to integer of different size --- WINGs/Examples/fontl.c | 6 ++++-- WINGs/Examples/puzzle.c | 6 +++--- WINGs/Extras/test.c | 9 +++++---- WINGs/Extras/wtabledelegates.c | 18 +++++++++--------- WINGs/Extras/wtableview.c | 9 +++++---- WINGs/wfilepanel.c | 5 +++-- WINGs/wfontpanel.c | 17 +++++++++-------- WINGs/wpanel.c | 3 ++- WPrefs.app/editmenu.c | 3 ++- src/defaults.c | 9 +++++---- src/icon.c | 3 ++- src/menu.c | 3 ++- src/switchmenu.c | 3 ++- src/window.c | 5 +++-- src/workspace.c | 11 ++++++----- 15 files changed, 62 insertions(+), 48 deletions(-) diff --git a/WINGs/Examples/fontl.c b/WINGs/Examples/fontl.c index 7c365b45..ad9957aa 100644 --- a/WINGs/Examples/fontl.c +++ b/WINGs/Examples/fontl.c @@ -24,6 +24,7 @@ #include #include +#include #include #include @@ -39,7 +40,8 @@ void show(WMWidget *self, void *data) void *d; WMLabel *l = (WMLabel*)data; d = WMGetHangedData(self); - sprintf(buf, "%i - 0x%x - 0%o", (int)d, (int)d, (int)d); + sprintf(buf, "%i - 0x%x - 0%o", (int)(uintptr_t)d, (int)(uintptr_t)d, + (int)(uintptr_t)d); WMSetLabelText(l, buf); } @@ -87,7 +89,7 @@ main(int argc, char **argv) sprintf(buf, "%c", c); WMSetButtonText(lab, buf); WMSetButtonAction(lab, show, pos); - WMHangData(lab, (void*)c); + WMHangData(lab, (void*)(uintptr_t)c); if (c>0) { WMGroupButtons(l0, lab); } else { diff --git a/WINGs/Examples/puzzle.c b/WINGs/Examples/puzzle.c index 5d54d6d7..21e69104 100644 --- a/WINGs/Examples/puzzle.c +++ b/WINGs/Examples/puzzle.c @@ -4,7 +4,7 @@ #include #include #include - +#include #define MAX_SIZE 10*10 @@ -135,7 +135,7 @@ void buttonClick(WMWidget *w, void *ptr) { char buffer[300]; - if (SlideButton((int)ptr)) { + if (SlideButton((int)(uintptr_t)ptr)) { MoveCount++; if (CheckWin()) { @@ -222,7 +222,7 @@ int main(int argc, char **argv) Button[i] = WMCreateButton(win, WBTMomentaryLight); WMSetWidgetBackgroundColor(Button[i], color); WMReleaseColor(color); - WMSetButtonAction(Button[i], buttonClick, (void*)i); + WMSetButtonAction(Button[i], buttonClick, (void*)(uintptr_t)i); WMResizeWidget(Button[i], WinSize/Size, WinSize/Size); WMMoveWidget(Button[i], x*(WinSize/Size), y*(WinSize/Size)); sprintf(buf, "%i", i+1); diff --git a/WINGs/Extras/test.c b/WINGs/Extras/test.c index e1c0ef2f..e37b11e7 100644 --- a/WINGs/Extras/test.c +++ b/WINGs/Extras/test.c @@ -2,6 +2,7 @@ #include #include +#include #include "wtableview.h" #include "wtabledelegates.h" @@ -41,10 +42,10 @@ valueForCell(WMTableViewDelegate *self, WMTableColumn *column, int row) col2[i] = 0; } } - if ((int)WMGetTableColumnId(column) == 1) + if ((int)(uintptr_t)WMGetTableColumnId(column) == 1) return col1[row]; else - return (void*)col2[row]; + return (void*)(uintptr_t)col2[row]; } @@ -52,10 +53,10 @@ void setValueForCell(WMTableViewDelegate *self, WMTableColumn *column, int row, void *data) { - if ((int)WMGetTableColumnId(column) == 1) + if ((int)(uintptr_t)WMGetTableColumnId(column) == 1) col1[row] = data; else - col2[row] = (int)data; + col2[row] = (int)(uintptr_t)data; } diff --git a/WINGs/Extras/wtabledelegates.c b/WINGs/Extras/wtabledelegates.c index 9c46e7dc..c7c3d742 100644 --- a/WINGs/Extras/wtabledelegates.c +++ b/WINGs/Extras/wtabledelegates.c @@ -1,5 +1,5 @@ - +#include #include #include "wtableview.h" @@ -231,7 +231,7 @@ ESCellPainter(WMTableColumnDelegate *self, WMTableColumn *column, { EnumSelectorData *strdata = (EnumSelectorData*)self->data; WMTableView *table = WMGetTableColumnTableView(column); - int i = (int)WMTableViewDataForCell(table, column, row); + int i = (int)(uintptr_t)WMTableViewDataForCell(table, column, row); stringDraw(WMWidgetScreen(table), d, strdata->gc, strdata->selGC, strdata->textColor, strdata->font, @@ -247,7 +247,7 @@ selectedESCellPainter(WMTableColumnDelegate *self, WMTableColumn *column, { EnumSelectorData *strdata = (EnumSelectorData*)self->data; WMTableView *table = WMGetTableColumnTableView(column); - int i = (int)WMTableViewDataForCell(table, column, row); + int i = (int)(uintptr_t)WMTableViewDataForCell(table, column, row); stringDraw(WMWidgetScreen(table), d, strdata->gc, strdata->selGC, strdata->textColor, strdata->font, @@ -262,7 +262,7 @@ beginESCellEdit(WMTableColumnDelegate *self, WMTableColumn *column, int row) { EnumSelectorData *strdata = (EnumSelectorData*)self->data; WMRect rect = WMTableViewRectForCell(strdata->table, column, row); - int data = (int)WMTableViewDataForCell(strdata->table, column, row); + int data = (int)(uintptr_t)WMTableViewDataForCell(strdata->table, column, row); wassertr(data < strdata->count); @@ -284,7 +284,7 @@ endESCellEdit(WMTableColumnDelegate *self, WMTableColumn *column, int row) WMUnmapWidget(strdata->widget); option = WMGetPopUpButtonSelectedItem(strdata->widget); - WMSetTableViewDataForCell(strdata->table, column, row, (void*)option); + WMSetTableViewDataForCell(strdata->table, column, row, (void*)(uintptr_t)option); } @@ -348,7 +348,7 @@ BSCellPainter(WMTableColumnDelegate *self, WMTableColumn *column, { BooleanSwitchData *strdata = (BooleanSwitchData*)self->data; WMTableView *table = WMGetTableColumnTableView(column); - int i = (int)WMTableViewDataForCell(table, column, row); + int i = (int)(uintptr_t)WMTableViewDataForCell(table, column, row); WMScreen *scr = WMWidgetScreen(table); if (i) { @@ -369,7 +369,7 @@ selectedBSCellPainter(WMTableColumnDelegate *self, WMTableColumn *column, { BooleanSwitchData *strdata = (BooleanSwitchData*)self->data; WMTableView *table = WMGetTableColumnTableView(column); - int i = (int)WMTableViewDataForCell(table, column, row); + int i = (int)(uintptr_t)WMTableViewDataForCell(table, column, row); WMScreen *scr = WMWidgetScreen(table); if (i) { @@ -390,7 +390,7 @@ beginBSCellEdit(WMTableColumnDelegate *self, WMTableColumn *column, int row) { BooleanSwitchData *strdata = (BooleanSwitchData*)self->data; WMRect rect = WMTableViewRectForCell(strdata->table, column, row); - int data = (int)WMTableViewDataForCell(strdata->table, column, row); + int data = (int)(uintptr_t)WMTableViewDataForCell(strdata->table, column, row); WMSetButtonSelected(strdata->widget, data); WMMoveWidget(strdata->widget, rect.pos.x+1, rect.pos.y+1); @@ -407,7 +407,7 @@ endBSCellEdit(WMTableColumnDelegate *self, WMTableColumn *column, int row) int value; value = WMGetButtonSelected(strdata->widget); - WMSetTableViewDataForCell(strdata->table, column, row, (void*)value); + WMSetTableViewDataForCell(strdata->table, column, row, (void*)(uintptr_t)value); WMUnmapWidget(strdata->widget); } diff --git a/WINGs/Extras/wtableview.c b/WINGs/Extras/wtableview.c index 94a2c3bb..dd193a9b 100644 --- a/WINGs/Extras/wtableview.c +++ b/WINGs/Extras/wtableview.c @@ -2,6 +2,7 @@ #include #include +#include #include "wtableview.h" @@ -1028,7 +1029,7 @@ drawRow(WMTableView *table, int row, WMRect clipRect) if (!column->delegate || !column->delegate->drawCell) continue; - if (WMFindInArray(table->selectedRows, NULL, (void*)row) != WANotFound) + if (WMFindInArray(table->selectedRows, NULL, (void*)(uintptr_t)row) != WANotFound) (*column->delegate->drawSelectedCell)(column->delegate, column, row, d); else (*column->delegate->drawCell)(column->delegate, column, row, d); @@ -1064,14 +1065,14 @@ setRowSelected(WMTableView *table, unsigned row, Bool flag) { int repaint = 0; - if (WMFindInArray(table->selectedRows, NULL, (void*)row) != WANotFound) { + if (WMFindInArray(table->selectedRows, NULL, (void*)(uintptr_t)row) != WANotFound) { if (!flag) { - WMRemoveFromArray(table->selectedRows, (void*)row); + WMRemoveFromArray(table->selectedRows, (void*)(uintptr_t)row); repaint = 1; } } else { if (flag) { - WMAddToArray(table->selectedRows, (void*)row); + WMAddToArray(table->selectedRows, (void*)(uintptr_t)row); repaint = 1; } } diff --git a/WINGs/wfilepanel.c b/WINGs/wfilepanel.c index b2ddea4e..e5565eb2 100644 --- a/WINGs/wfilepanel.c +++ b/WINGs/wfilepanel.c @@ -8,6 +8,7 @@ #include #include #include +#include #ifndef PATH_MAX #define PATH_MAX 1024 @@ -132,7 +133,7 @@ textChangedObserver(void *observerData, WMNotification *notification) return; text = WMGetTextFieldText(panel->fileField); - textEvent = (int)WMGetNotificationClientData(notification); + textEvent = (int)(uintptr_t)WMGetNotificationClientData(notification); if (panel->flags.autoCompletion && textEvent!=WMDeleteTextEvent) i = closestListItem(list, text, False); @@ -168,7 +169,7 @@ textEditedObserver(void *observerData, WMNotification *notification) { W_FilePanel *panel = (W_FilePanel*)observerData; - if ((int)WMGetNotificationClientData(notification)==WMReturnTextMovement) { + if ((int)(uintptr_t)WMGetNotificationClientData(notification)==WMReturnTextMovement) { WMPerformButtonClick(panel->okButton); } } diff --git a/WINGs/wfontpanel.c b/WINGs/wfontpanel.c index c9909055..537e54dd 100644 --- a/WINGs/wfontpanel.c +++ b/WINGs/wfontpanel.c @@ -8,6 +8,7 @@ #include #include +#include #include #include @@ -496,14 +497,14 @@ addSizeToTypeface(Typeface *face, int size) for (j = 0; j < sizeof(scalableFontSizes)/sizeof(int); j++) { size = scalableFontSizes[j]; - if (!WMCountInArray(face->sizes, (void*)size)) { - WMAddToArray(face->sizes, (void*)size); + if (!WMCountInArray(face->sizes, (void*)(uintptr_t)size)) { + WMAddToArray(face->sizes, (void*)(uintptr_t)size); } } WMSortArray(face->sizes, compare_int); } else { - if (!WMCountInArray(face->sizes, (void*)size)) { - WMAddToArray(face->sizes, (void*)size); + if (!WMCountInArray(face->sizes, (void*)(uintptr_t)size)) { + WMAddToArray(face->sizes, (void*)(uintptr_t)size); WMSortArray(face->sizes, compare_int); } } @@ -773,8 +774,8 @@ typefaceClick(WMWidget *w, void *data) WMClearList(panel->sizLs); WM_ITERATE_ARRAY(face->sizes, size, i) { - if ((int)size != 0) { - sprintf(buffer, "%i", (int)size); + if ((int)(uintptr_t)size != 0) { + sprintf(buffer, "%i", (int)(uintptr_t)size); WMAddListItem(panel->sizLs, buffer); } @@ -874,8 +875,8 @@ setFontPanelFontName(FontPanel *panel, char *family, char *style, double size) WM_ITERATE_ARRAY(face->sizes, vsize, i) { char buffer[32]; - if ((int)vsize != 0) { - sprintf(buffer, "%i", (int)vsize); + if ((int)(uintptr_t)vsize != 0) { + sprintf(buffer, "%i", (int)(uintptr_t)vsize); WMAddListItem(panel->sizLs, buffer); } diff --git a/WINGs/wpanel.c b/WINGs/wpanel.c index d6f21bfe..1f280677 100644 --- a/WINGs/wpanel.c +++ b/WINGs/wpanel.c @@ -3,6 +3,7 @@ #include "WINGsP.h" #include +#include @@ -360,7 +361,7 @@ endedEditingObserver(void *observerData, WMNotification *notification) { WMInputPanel *panel = (WMInputPanel*)observerData; - switch ((int)WMGetNotificationClientData(notification)) { + switch ((int)(uintptr_t)WMGetNotificationClientData(notification)) { case WMReturnTextMovement: if (panel->defBtn) WMPerformButtonClick(panel->defBtn); diff --git a/WPrefs.app/editmenu.c b/WPrefs.app/editmenu.c index e6013905..508f48e6 100644 --- a/WPrefs.app/editmenu.c +++ b/WPrefs.app/editmenu.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -969,7 +970,7 @@ textEndedEditing(struct WMTextFieldDelegate *self, WMNotification *notif) if (!menu->flags.isEditing) return; - reason = (int)WMGetNotificationClientData(notif); + reason = (int)(uintptr_t)WMGetNotificationClientData(notif); switch (reason) { case WMEscapeTextMovement: diff --git a/src/defaults.c b/src/defaults.c index c07ad37b..7bc18e07 100644 --- a/src/defaults.c +++ b/src/defaults.c @@ -24,6 +24,7 @@ #include "wconfig.h" #include +#include #include #include #include @@ -1443,7 +1444,7 @@ wReadDefaults(WScreen *scr, WMPropList *new_dict) foo |= WColorSettings; if (foo) WMPostNotificationName(WNMenuTitleAppearanceSettingsChanged, NULL, - (void*)foo); + (void*)(uintptr_t)foo); foo = 0; if (needs_refresh & REFRESH_MENU_TEXTURE) @@ -1454,7 +1455,7 @@ wReadDefaults(WScreen *scr, WMPropList *new_dict) foo |= WColorSettings; if (foo) WMPostNotificationName(WNMenuAppearanceSettingsChanged, NULL, - (void*)foo); + (void*)(uintptr_t)foo); foo = 0; if (needs_refresh & REFRESH_WINDOW_FONT) { @@ -1468,7 +1469,7 @@ wReadDefaults(WScreen *scr, WMPropList *new_dict) } if (foo) WMPostNotificationName(WNWindowAppearanceSettingsChanged, NULL, - (void*)foo); + (void*)(uintptr_t)foo); if (!(needs_refresh & REFRESH_ICON_TILE)) { foo = 0; @@ -1483,7 +1484,7 @@ wReadDefaults(WScreen *scr, WMPropList *new_dict) } if (foo) WMPostNotificationName(WNIconAppearanceSettingsChanged, NULL, - (void*)foo); + (void*)(uintptr_t)foo); } if (needs_refresh & REFRESH_ICON_TILE) WMPostNotificationName(WNIconTileSettingsChanged, NULL, NULL); diff --git a/src/icon.c b/src/icon.c index 19a918c8..3ff44ac5 100644 --- a/src/icon.c +++ b/src/icon.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -64,7 +65,7 @@ static void appearanceObserver(void *self, WMNotification *notif) { WIcon *icon = (WIcon*)self; - int flags = (int)WMGetNotificationClientData(notif); + int flags = (int)(uintptr_t)WMGetNotificationClientData(notif); if (flags & WTextureSettings) { icon->force_paint = 1; diff --git a/src/menu.c b/src/menu.c index 04b05a1c..c6c1837d 100644 --- a/src/menu.c +++ b/src/menu.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #if 0 @@ -109,7 +110,7 @@ static void appearanceObserver(void *self, WMNotification *notif) { WMenu *menu = (WMenu*)self; - int flags = (int)WMGetNotificationClientData(notif); + int flags = (int)(uintptr_t)WMGetNotificationClientData(notif); if (!menu->flags.realized) return; diff --git a/src/switchmenu.c b/src/switchmenu.c index 544652b3..0db6e71a 100644 --- a/src/switchmenu.c +++ b/src/switchmenu.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -449,7 +450,7 @@ wsobserver(void *self, WMNotification *notif) void *data = WMGetNotificationClientData(notif); if (strcmp(name, WMNWorkspaceNameChanged) == 0) { - UpdateSwitchMenuWorkspace(scr, (int)data); + UpdateSwitchMenuWorkspace(scr, (int)(uintptr_t)data); } else if (strcmp(name, WMNWorkspaceChanged) == 0) { } diff --git a/src/window.c b/src/window.c index 0b6a39a3..6cefe6c4 100644 --- a/src/window.c +++ b/src/window.c @@ -33,6 +33,7 @@ #include #include #include +#include /* For getting mouse wheel mappings from WINGs */ #include @@ -137,7 +138,7 @@ static void appearanceObserver(void *self, WMNotification *notif) { WWindow *wwin = (WWindow*)self; - int flags = (int)WMGetNotificationClientData(notif); + int flags = (int)(uintptr_t)WMGetNotificationClientData(notif); if (!wwin->frame || (!wwin->frame->titlebar && !wwin->frame->resizebar)) return; @@ -2214,7 +2215,7 @@ wWindowChangeWorkspace(WWindow *wwin, int workspace) wwin->frame->workspace = workspace; - WMPostNotificationName(WMNChangedWorkspace, wwin, (void*)oldWorkspace); + WMPostNotificationName(WMNChangedWorkspace, wwin, (void*)(uintptr_t)oldWorkspace); } if (unmap) { diff --git a/src/workspace.c b/src/workspace.c index fd27b83f..3c72710f 100644 --- a/src/workspace.c +++ b/src/workspace.c @@ -29,6 +29,7 @@ #include #include +#include #include #include #include @@ -132,7 +133,7 @@ wWorkspaceNew(WScreen *scr) #endif WMPostNotificationName(WMNWorkspaceCreated, scr, - (void*)(scr->workspace_count-1)); + (void*)(uintptr_t)(scr->workspace_count-1)); XFlush(dpy); return scr->workspace_count-1; @@ -211,7 +212,7 @@ wWorkspaceDelete(WScreen *scr, int workspace) #endif WMPostNotificationName(WMNWorkspaceDestroyed, scr, - (void*)(scr->workspace_count-1)); + (void*)(uintptr_t)(scr->workspace_count-1)); if (scr->current_workspace >= scr->workspace_count) wWorkspaceChange(scr, scr->workspace_count-1); @@ -631,7 +632,7 @@ wWorkspaceForceChange(WScreen *scr, int workspace) showWorkspaceName(scr, workspace); - WMPostNotificationName(WMNWorkspaceChanged, scr, (void*)workspace); + WMPostNotificationName(WMNWorkspaceChanged, scr, (void*)(uintptr_t)workspace); /* XSync(dpy, False); */ } @@ -1327,7 +1328,7 @@ wWorkspaceRename(WScreen *scr, int workspace, char *name) if (scr->clip_icon) wClipIconPaint(scr->clip_icon); - WMPostNotificationName(WMNWorkspaceNameChanged, scr, (void*)workspace); + WMPostNotificationName(WMNWorkspaceNameChanged, scr, (void*)(uintptr_t)workspace); } @@ -1511,7 +1512,7 @@ wWorkspaceRestoreState(WScreen *scr) } } - WMPostNotificationName(WMNWorkspaceNameChanged, scr, (void*)i); + WMPostNotificationName(WMNWorkspaceNameChanged, scr, (void*)(uintptr_t)i); } } -- 2.11.4.GIT