Skip to content

Commit 24b881c

Browse files
committed
Avoid casts for &this->super access in Panel classes
1 parent 3b7aa07 commit 24b881c

12 files changed

+48
-47
lines changed

AffinityPanel.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -136,20 +136,19 @@ typedef struct AffinityPanel_ {
136136

137137
static void AffinityPanel_delete(Object* cast) {
138138
AffinityPanel* this = (AffinityPanel*) cast;
139-
Panel* super = (Panel*) this;
140-
Panel_done(super);
141139
Vector_delete(this->cpuids);
142140
#ifdef HAVE_LIBHWLOC
143141
hwloc_bitmap_free(this->workCpuset);
144142
MaskItem_delete((Object*) this->topoRoot);
145143
#endif
144+
Panel_done(&this->super);
146145
free(this);
147146
}
148147

149148
#ifdef HAVE_LIBHWLOC
150149

151150
static void AffinityPanel_updateItem(AffinityPanel* this, MaskItem* item) {
152-
Panel* super = (Panel*) this;
151+
Panel* super = &this->super;
153152

154153
item->value = hwloc_bitmap_isincluded(item->cpuset, this->workCpuset) ? 2 :
155154
hwloc_bitmap_intersects(item->cpuset, this->workCpuset) ? 1 : 0;
@@ -170,7 +169,7 @@ static void AffinityPanel_updateTopo(AffinityPanel* this, MaskItem* item) {
170169
#endif
171170

172171
static void AffinityPanel_update(AffinityPanel* this, bool keepSelected) {
173-
Panel* super = (Panel*) this;
172+
Panel* super = &this->super;
174173

175174
FunctionBar_setLabel(super->currentBar, KEY_F(3), this->topoView ? "Collapse/Expand" : "");
176175

@@ -370,7 +369,8 @@ static const int AffinityPanelEvents[] = {13, 27, KEY_F(1), KEY_F(2), KEY_F(3)};
370369

371370
Panel* AffinityPanel_new(Machine* host, const Affinity* affinity, int* width) {
372371
AffinityPanel* this = AllocThis(AffinityPanel);
373-
Panel* super = (Panel*) this;
372+
Panel* super = &this->super;
373+
374374
Panel_init(super, 1, 1, 1, 1, Class(MaskItem), false, FunctionBar_new(AffinityPanelFunctions, AffinityPanelKeys, AffinityPanelEvents));
375375

376376
this->host = host;

AvailableColumnsPanel.c

+4-5
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,8 @@ in the source distribution for its full text.
3030
static const char* const AvailableColumnsFunctions[] = {" ", " ", " ", " ", "Add ", " ", " ", " ", " ", "Done ", NULL};
3131

3232
static void AvailableColumnsPanel_delete(Object* object) {
33-
Panel* super = (Panel*) object;
3433
AvailableColumnsPanel* this = (AvailableColumnsPanel*) object;
35-
Panel_done(super);
34+
Panel_done(&this->super);
3635
free(this);
3736
}
3837

@@ -118,8 +117,7 @@ static void AvailableColumnsPanel_addDynamicScreens(AvailableColumnsPanel* this,
118117
}
119118

120119
void AvailableColumnsPanel_fill(AvailableColumnsPanel* this, const char* dynamicScreen, Hashtable* dynamicColumns) {
121-
Panel* super = (Panel*) this;
122-
Panel_prune(super);
120+
Panel_prune(&this->super);
123121
if (dynamicScreen) {
124122
AvailableColumnsPanel_addDynamicScreens(this, dynamicScreen);
125123
} else {
@@ -130,7 +128,8 @@ void AvailableColumnsPanel_fill(AvailableColumnsPanel* this, const char* dynamic
130128

131129
AvailableColumnsPanel* AvailableColumnsPanel_new(Panel* columns, Hashtable* dynamicColumns) {
132130
AvailableColumnsPanel* this = AllocThis(AvailableColumnsPanel);
133-
Panel* super = (Panel*) this;
131+
Panel* super = &this->super;
132+
134133
FunctionBar* fuBar = FunctionBar_new(AvailableColumnsFunctions, NULL, NULL);
135134
Panel_init(super, 1, 1, 1, 1, Class(ListItem), true, fuBar);
136135
Panel_setHeader(super, "Available Columns");

AvailableMetersPanel.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,9 @@ in the source distribution for its full text.
3030

3131

3232
static void AvailableMetersPanel_delete(Object* object) {
33-
Panel* super = (Panel*) object;
3433
AvailableMetersPanel* this = (AvailableMetersPanel*) object;
35-
Panel_done(super);
3634
free(this->meterPanels);
35+
Panel_done(&this->super);
3736
free(this);
3837
}
3938

@@ -145,7 +144,8 @@ static void AvailableMetersPanel_addPlatformMeter(Panel* super, const MeterClass
145144

146145
AvailableMetersPanel* AvailableMetersPanel_new(Machine* host, Header* header, size_t columns, MetersPanel** meterPanels, ScreenManager* scr) {
147146
AvailableMetersPanel* this = AllocThis(AvailableMetersPanel);
148-
Panel* super = (Panel*) this;
147+
Panel* super = &this->super;
148+
149149
FunctionBar* fuBar = FunctionBar_newEnterEsc("Add ", "Done ");
150150
Panel_init(super, 1, 1, 1, 1, Class(ListItem), true, fuBar);
151151

CategoriesPanel.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,8 @@ in the source distribution for its full text.
3535
static const char* const CategoriesFunctions[] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", "Done ", NULL};
3636

3737
static void CategoriesPanel_delete(Object* object) {
38-
Panel* super = (Panel*) object;
3938
CategoriesPanel* this = (CategoriesPanel*) object;
40-
Panel_done(super);
39+
Panel_done(&this->super);
4140
free(this);
4241
}
4342

@@ -172,7 +171,8 @@ const PanelClass CategoriesPanel_class = {
172171

173172
CategoriesPanel* CategoriesPanel_new(ScreenManager* scr, Header* header, Machine* host) {
174173
CategoriesPanel* this = AllocThis(CategoriesPanel);
175-
Panel* super = (Panel*) this;
174+
Panel* super = &this->super;
175+
176176
FunctionBar* fuBar = FunctionBar_new(CategoriesFunctions, NULL, NULL);
177177
Panel_init(super, 1, 1, 1, 1, Class(ListItem), true, fuBar);
178178

ColorsPanel.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,8 @@ static const char* const ColorSchemeNames[] = {
4141
};
4242

4343
static void ColorsPanel_delete(Object* object) {
44-
Panel* super = (Panel*) object;
4544
ColorsPanel* this = (ColorsPanel*) object;
46-
Panel_done(super);
45+
Panel_done(&this->super);
4746
free(this);
4847
}
4948

@@ -91,7 +90,8 @@ const PanelClass ColorsPanel_class = {
9190

9291
ColorsPanel* ColorsPanel_new(Settings* settings) {
9392
ColorsPanel* this = AllocThis(ColorsPanel);
94-
Panel* super = (Panel*) this;
93+
Panel* super = &this->super;
94+
9595
FunctionBar* fuBar = FunctionBar_new(ColorsFunctions, NULL, NULL);
9696
Panel_init(super, 1, 1, 1, 1, Class(CheckItem), true, fuBar);
9797

ColumnsPanel.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,8 @@ in the source distribution for its full text.
2828
static const char* const ColumnsFunctions[] = {" ", " ", " ", " ", " ", " ", "MoveUp", "MoveDn", "Remove", "Done ", NULL};
2929

3030
static void ColumnsPanel_delete(Object* object) {
31-
Panel* super = (Panel*) object;
3231
ColumnsPanel* this = (ColumnsPanel*) object;
33-
Panel_done(super);
32+
Panel_done(&this->super);
3433
free(this);
3534
}
3635

@@ -126,7 +125,7 @@ static void ColumnsPanel_add(Panel* super, unsigned int key, Hashtable* columns)
126125
}
127126

128127
void ColumnsPanel_fill(ColumnsPanel* this, ScreenSettings* ss, Hashtable* columns) {
129-
Panel* super = (Panel*) this;
128+
Panel* super = &this->super;
130129
Panel_prune(super);
131130
for (const RowField* fields = ss->fields; *fields; fields++)
132131
ColumnsPanel_add(super, *fields, columns);
@@ -135,7 +134,8 @@ void ColumnsPanel_fill(ColumnsPanel* this, ScreenSettings* ss, Hashtable* column
135134

136135
ColumnsPanel* ColumnsPanel_new(ScreenSettings* ss, Hashtable* columns, bool* changed) {
137136
ColumnsPanel* this = AllocThis(ColumnsPanel);
138-
Panel* super = (Panel*) this;
137+
Panel* super = &this->super;
138+
139139
FunctionBar* fuBar = FunctionBar_new(ColumnsFunctions, NULL, NULL);
140140
Panel_init(super, 1, 1, 1, 1, Class(ListItem), true, fuBar);
141141

DisplayOptionsPanel.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,9 @@ static const char* const DisplayOptionsDecIncKeys[] = {"- ", "+ ", " ", "F10",
2929
static const int DisplayOptionsDecIncEvents[] = {'-', '+', ERR, KEY_F(10)};
3030

3131
static void DisplayOptionsPanel_delete(Object* object) {
32-
Panel* super = (Panel*) object;
3332
DisplayOptionsPanel* this = (DisplayOptionsPanel*) object;
3433
FunctionBar_delete(this->decIncBar);
35-
Panel_done(super);
34+
Panel_done(&this->super);
3635
free(this);
3736
}
3837

@@ -127,7 +126,8 @@ const PanelClass DisplayOptionsPanel_class = {
127126

128127
DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager* scr) {
129128
DisplayOptionsPanel* this = AllocThis(DisplayOptionsPanel);
130-
Panel* super = (Panel*) this;
129+
Panel* super = &this->super;
130+
131131
FunctionBar* fuBar = FunctionBar_new(DisplayOptionsFunctions, NULL, NULL);
132132
Panel_init(super, 1, 1, 1, 1, Class(OptionItem), true, fuBar);
133133

@@ -192,5 +192,6 @@ DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager*
192192
#ifdef HAVE_LIBHWLOC
193193
Panel_add(super, (Object*) CheckItem_newByRef("Show topology when selecting affinity by default", &(settings->topologyAffinity)));
194194
#endif
195+
195196
return this;
196197
}

HeaderOptionsPanel.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,8 @@ in the source distribution for its full text.
2525
static const char* const HeaderOptionsFunctions[] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", "Done ", NULL};
2626

2727
static void HeaderOptionsPanel_delete(Object* object) {
28-
Panel* super = (Panel*) object;
2928
HeaderOptionsPanel* this = (HeaderOptionsPanel*) object;
30-
Panel_done(super);
29+
Panel_done(&this->super);
3130
free(this);
3231
}
3332

@@ -74,7 +73,8 @@ const PanelClass HeaderOptionsPanel_class = {
7473

7574
HeaderOptionsPanel* HeaderOptionsPanel_new(Settings* settings, ScreenManager* scr) {
7675
HeaderOptionsPanel* this = AllocThis(HeaderOptionsPanel);
77-
Panel* super = (Panel*) this;
76+
Panel* super = &this->super;
77+
7878
FunctionBar* fuBar = FunctionBar_new(HeaderOptionsFunctions, NULL, NULL);
7979
Panel_init(super, 1, 1, 1, 1, Class(CheckItem), true, fuBar);
8080

MainPanel.c

+3-4
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ void MainPanel_updateLabels(MainPanel* this, bool list, bool filter) {
3636
}
3737

3838
static void MainPanel_idSearch(MainPanel* this, int ch) {
39-
Panel* super = (Panel*) this;
39+
Panel* super = &this->super;
4040
pid_t id = ch - 48 + this->idSearch;
4141
for (int i = 0; i < Panel_size(super); i++) {
4242
const Row* row = (const Row*) Panel_get(super, i);
@@ -159,7 +159,7 @@ int MainPanel_selectedRow(MainPanel* this) {
159159
}
160160

161161
bool MainPanel_foreachRow(MainPanel* this, MainPanel_foreachRowFn fn, Arg arg, bool* wasAnyTagged) {
162-
Panel* super = (Panel*) this;
162+
Panel* super = &this->super;
163163
bool ok = true;
164164
bool anyTagged = false;
165165
for (int i = 0; i < Panel_size(super); i++) {
@@ -236,12 +236,11 @@ void MainPanel_setFunctionBar(MainPanel* this, bool readonly) {
236236
}
237237

238238
void MainPanel_delete(Object* object) {
239-
Panel* super = (Panel*) object;
240239
MainPanel* this = (MainPanel*) object;
241240
MainPanel_setFunctionBar(this, false);
242241
FunctionBar_delete(this->readonlyBar);
243-
Panel_done(super);
244242
IncSet_delete(this->inc);
245243
free(this->keys);
244+
Panel_done(&this->super);
246245
free(this);
247246
}

MetersPanel.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,13 @@ void MetersPanel_cleanup(void) {
4343
}
4444

4545
static void MetersPanel_delete(Object* object) {
46-
Panel* super = (Panel*) object;
4746
MetersPanel* this = (MetersPanel*) object;
48-
Panel_done(super);
47+
Panel_done(&this->super);
4948
free(this);
5049
}
5150

5251
void MetersPanel_setMoving(MetersPanel* this, bool moving) {
53-
Panel* super = (Panel*) this;
52+
Panel* super = &this->super;
5453
this->moving = moving;
5554
ListItem* selected = (ListItem*)Panel_getSelected(super);
5655
if (selected) {
@@ -66,7 +65,7 @@ void MetersPanel_setMoving(MetersPanel* this, bool moving) {
6665
}
6766

6867
static inline bool moveToNeighbor(MetersPanel* this, MetersPanel* neighbor, int selected) {
69-
Panel* super = (Panel*) this;
68+
Panel* super = &this->super;
7069
if (this->moving) {
7170
if (neighbor) {
7271
if (selected < Vector_size(this->meters)) {
@@ -185,7 +184,8 @@ const PanelClass MetersPanel_class = {
185184

186185
MetersPanel* MetersPanel_new(Settings* settings, const char* header, Vector* meters, ScreenManager* scr) {
187186
MetersPanel* this = AllocThis(MetersPanel);
188-
Panel* super = (Panel*) this;
187+
Panel* super = &this->super;
188+
189189
FunctionBar* fuBar = FunctionBar_new(MetersFunctions, MetersKeys, MetersEvents);
190190
if (!Meters_movingBar) {
191191
Meters_movingBar = FunctionBar_new(MetersMovingFunctions, MetersMovingKeys, MetersMovingEvents);

ScreenTabsPanel.c

+7-7
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ ObjectClass ScreenTabListItem_class = {
3535

3636
static void ScreenNamesPanel_fill(ScreenNamesPanel* this, DynamicScreen* ds) {
3737
const Settings* settings = this->settings;
38-
Panel* super = (Panel*) this;
38+
Panel* super = &this->super;
3939
Panel_prune(super);
4040

4141
for (unsigned int i = 0; i < settings->nScreens; i++) {
@@ -59,10 +59,8 @@ static void ScreenNamesPanel_fill(ScreenNamesPanel* this, DynamicScreen* ds) {
5959
}
6060

6161
static void ScreenTabsPanel_delete(Object* object) {
62-
Panel* super = (Panel*) object;
6362
ScreenTabsPanel* this = (ScreenTabsPanel*) object;
64-
65-
Panel_done(super);
63+
Panel_done(&this->super);
6664
free(this);
6765
}
6866

@@ -138,7 +136,8 @@ static const char* const ScreenTabsFunctions[] = {" ", " ", " ",
138136

139137
ScreenTabsPanel* ScreenTabsPanel_new(Settings* settings) {
140138
ScreenTabsPanel* this = AllocThis(ScreenTabsPanel);
141-
Panel* super = (Panel*) this;
139+
Panel* super = &this->super;
140+
142141
FunctionBar* fuBar = FunctionBar_new(ScreenTabsFunctions, NULL, NULL);
143142
Panel_init(super, 1, 1, 1, 1, Class(ListItem), true, fuBar);
144143

@@ -174,8 +173,8 @@ ScreenNameListItem* ScreenNameListItem_new(const char* value, ScreenSettings* ss
174173
static const char* const ScreenNamesFunctions[] = {" ", " ", " ", " ", "New ", " ", " ", " ", " ", "Done ", NULL};
175174

176175
static void ScreenNamesPanel_delete(Object* object) {
177-
Panel* super = (Panel*) object;
178176
ScreenNamesPanel* this = (ScreenNamesPanel*) object;
177+
Panel* super = &this->super;
179178

180179
/* do not delete screen settings still in use */
181180
int n = Panel_size(super);
@@ -350,7 +349,8 @@ PanelClass ScreenNamesPanel_class = {
350349

351350
ScreenNamesPanel* ScreenNamesPanel_new(Settings* settings) {
352351
ScreenNamesPanel* this = AllocThis(ScreenNamesPanel);
353-
Panel* super = (Panel*) this;
352+
Panel* super = &this->super;
353+
354354
FunctionBar* fuBar = FunctionBar_new(ScreenNamesFunctions, NULL, NULL);
355355
Panel_init(super, 1, 1, 1, 1, Class(ListItem), true, fuBar);
356356

ScreensPanel.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -290,11 +290,13 @@ PanelClass ScreensPanel_class = {
290290

291291
ScreensPanel* ScreensPanel_new(Settings* settings) {
292292
ScreensPanel* this = AllocThis(ScreensPanel);
293-
Panel* super = (Panel*) this;
294-
Hashtable* columns = settings->dynamicColumns;
293+
Panel* super = &this->super;
294+
295295
FunctionBar* fuBar = FunctionBar_new(settings->dynamicScreens ? DynamicFunctions : ScreensFunctions, NULL, NULL);
296296
Panel_init(super, 1, 1, 1, 1, Class(ListItem), true, fuBar);
297297

298+
Hashtable* columns = settings->dynamicColumns;
299+
298300
this->settings = settings;
299301
this->columns = ColumnsPanel_new(settings->screens[0], columns, &(settings->changed));
300302
this->availableColumns = AvailableColumnsPanel_new((Panel*) this->columns, columns);

0 commit comments

Comments
 (0)