summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Göttsche <cgzones@googlemail.com>2020-10-06 12:28:11 +0200
committercgzones <cgzones@googlemail.com>2020-10-10 11:25:19 +0200
commit79ad39c718bfb2973d610c2d039a5024354e602f (patch)
treeefac0bfaf60cc44a5a2b2a8c8db251cbacf5ebab
parente5fdb80c7d13d836ec244390976741dd99bc6535 (diff)
Mark Object pointer to _display function const
-rw-r--r--AffinityPanel.c4
-rw-r--r--CPUMeter.c4
-rw-r--r--CheckItem.c6
-rw-r--r--CheckItem.h2
-rw-r--r--DiskIOMeter.c2
-rw-r--r--ListItem.c4
-rw-r--r--LoadAverageMeter.c8
-rw-r--r--MemoryMeter.c4
-rw-r--r--Meter.c5
-rw-r--r--Object.h8
-rw-r--r--Process.c12
-rw-r--r--Process.h6
-rw-r--r--SwapMeter.c4
-rw-r--r--TasksMeter.c6
-rw-r--r--linux/PressureStallMeter.c4
-rw-r--r--zfs/ZfsArcMeter.c4
-rw-r--r--zfs/ZfsCompressedArcMeter.c6
17 files changed, 44 insertions, 45 deletions
diff --git a/AffinityPanel.c b/AffinityPanel.c
index 127623c6..0cddd079 100644
--- a/AffinityPanel.c
+++ b/AffinityPanel.c
@@ -44,8 +44,8 @@ static void MaskItem_delete(Object* cast) {
free(this);
}
-static void MaskItem_display(Object* cast, RichString* out) {
- MaskItem* this = (MaskItem*)cast;
+static void MaskItem_display(const Object* cast, RichString* out) {
+ const MaskItem* this = (const MaskItem*)cast;
assert (this != NULL);
RichString_append(out, CRT_colors[CHECK_BOX], "[");
if (this->value == 2)
diff --git a/CPUMeter.c b/CPUMeter.c
index 7ce6caf8..c1ccb12c 100644
--- a/CPUMeter.c
+++ b/CPUMeter.c
@@ -66,9 +66,9 @@ static void CPUMeter_updateValues(Meter* this, char* buffer, int size) {
}
}
-static void CPUMeter_display(Object* cast, RichString* out) {
+static void CPUMeter_display(const Object* cast, RichString* out) {
char buffer[50];
- Meter* this = (Meter*)cast;
+ const Meter* this = (const Meter*)cast;
RichString_prune(out);
if (this->param > this->pl->cpuCount) {
RichString_append(out, CRT_colors[METER_TEXT], "absent");
diff --git a/CheckItem.c b/CheckItem.c
index 09e42ee6..d1f11963 100644
--- a/CheckItem.c
+++ b/CheckItem.c
@@ -21,8 +21,8 @@ static void CheckItem_delete(Object* cast) {
free(this);
}
-static void CheckItem_display(Object* cast, RichString* out) {
- CheckItem* this = (CheckItem*)cast;
+static void CheckItem_display(const Object* cast, RichString* out) {
+ const CheckItem* this = (const CheckItem*)cast;
assert (this != NULL);
RichString_write(out, CRT_colors[CHECK_BOX], "[");
if (CheckItem_get(this))
@@ -61,7 +61,7 @@ void CheckItem_set(CheckItem* this, bool value) {
this->value = value;
}
-bool CheckItem_get(CheckItem* this) {
+bool CheckItem_get(const CheckItem* this) {
if (this->ref)
return *(this->ref);
else
diff --git a/CheckItem.h b/CheckItem.h
index 168efdcc..b4300db4 100644
--- a/CheckItem.h
+++ b/CheckItem.h
@@ -24,6 +24,6 @@ CheckItem* CheckItem_newByVal(char* text, bool value);
void CheckItem_set(CheckItem* this, bool value);
-bool CheckItem_get(CheckItem* this);
+bool CheckItem_get(const CheckItem* this);
#endif
diff --git a/DiskIOMeter.c b/DiskIOMeter.c
index 781d9bb6..6baca32c 100644
--- a/DiskIOMeter.c
+++ b/DiskIOMeter.c
@@ -59,7 +59,7 @@ static void DiskIOMeter_updateValues(Meter* this, char* buffer, int len) {
snprintf(buffer, len, "%sB %sB %.1f%%", bufferRead, bufferWrite, cached_utilisation_diff);
}
-static void DIskIOMeter_display(ATTR_UNUSED Object* cast, RichString* out) {
+static void DIskIOMeter_display(ATTR_UNUSED const Object* cast, RichString* out) {
char buffer[16];
int color = cached_utilisation_diff > 40.0 ? DISKIO_UTIL_HIGH : METER_VALUE;
diff --git a/ListItem.c b/ListItem.c
index e1dcd52d..d9d36f89 100644
--- a/ListItem.c
+++ b/ListItem.c
@@ -22,8 +22,8 @@ static void ListItem_delete(Object* cast) {
free(this);
}
-static void ListItem_display(Object* cast, RichString* out) {
- ListItem* const this = (ListItem*)cast;
+static void ListItem_display(const Object* cast, RichString* out) {
+ const ListItem* const this = (const ListItem*)cast;
assert (this != NULL);
/*
int len = strlen(this->value)+1;
diff --git a/LoadAverageMeter.c b/LoadAverageMeter.c
index d2fa582a..208b7e95 100644
--- a/LoadAverageMeter.c
+++ b/LoadAverageMeter.c
@@ -26,8 +26,8 @@ static void LoadAverageMeter_updateValues(Meter* this, char* buffer, int size) {
xSnprintf(buffer, size, "%.2f/%.2f/%.2f", this->values[0], this->values[1], this->values[2]);
}
-static void LoadAverageMeter_display(Object* cast, RichString* out) {
- Meter* this = (Meter*)cast;
+static void LoadAverageMeter_display(const Object* cast, RichString* out) {
+ const Meter* this = (const Meter*)cast;
char buffer[20];
xSnprintf(buffer, sizeof(buffer), "%.2f ", this->values[0]);
RichString_write(out, CRT_colors[LOAD_AVERAGE_ONE], buffer);
@@ -46,8 +46,8 @@ static void LoadMeter_updateValues(Meter* this, char* buffer, int size) {
xSnprintf(buffer, size, "%.2f", this->values[0]);
}
-static void LoadMeter_display(Object* cast, RichString* out) {
- Meter* this = (Meter*)cast;
+static void LoadMeter_display(const Object* cast, RichString* out) {
+ const Meter* this = (const Meter*)cast;
char buffer[20];
xSnprintf(buffer, sizeof(buffer), "%.2f ", this->values[0]);
RichString_write(out, CRT_colors[LOAD], buffer);
diff --git a/MemoryMeter.c b/MemoryMeter.c
index fa0e09ab..311f1791 100644
--- a/MemoryMeter.c
+++ b/MemoryMeter.c
@@ -36,9 +36,9 @@ static void MemoryMeter_updateValues(Meter* this, char* buffer, int size) {
}
}
-static void MemoryMeter_display(Object* cast, RichString* out) {
+static void MemoryMeter_display(const Object* cast, RichString* out) {
char buffer[50];
- Meter* this = (Meter*)cast;
+ const Meter* this = (const Meter*)cast;
RichString_write(out, CRT_colors[METER_TEXT], ":");
Meter_humanUnit(buffer, this->total, 50);
RichString_append(out, CRT_colors[METER_VALUE], buffer);
diff --git a/Meter.c b/Meter.c
index 15be309f..c8cd19eb 100644
--- a/Meter.c
+++ b/Meter.c
@@ -92,7 +92,7 @@ void Meter_setCaption(Meter* this, const char* caption) {
this->caption = xStrdup(caption);
}
-static inline void Meter_displayBuffer(Meter* this, char* buffer, RichString* out) {
+static inline void Meter_displayBuffer(const Meter* this, const char* buffer, RichString* out) {
if (Object_displayFn(this)) {
Object_display(this, out);
} else {
@@ -428,8 +428,7 @@ static void BlankMeter_updateValues(Meter* this, char* buffer, int size) {
}
}
-static void BlankMeter_display(Object* cast, RichString* out) {
- (void) cast;
+static void BlankMeter_display(ATTR_UNUSED const Object* cast, RichString* out) {
RichString_prune(out);
}
diff --git a/Object.h b/Object.h
index 0d0e0036..36ab2544 100644
--- a/Object.h
+++ b/Object.h
@@ -14,16 +14,16 @@ in the source distribution for its full text.
typedef struct Object_ Object;
-typedef void(*Object_Display)(Object*, RichString*);
+typedef void(*Object_Display)(const Object*, RichString*);
typedef long(*Object_Compare)(const void*, const void*);
typedef void(*Object_Delete)(Object*);
-#define Object_getClass(obj_) ((Object*)(obj_))->klass
-#define Object_setClass(obj_, class_) Object_getClass(obj_) = (const ObjectClass*) class_
+#define Object_getClass(obj_) ((const Object*)(obj_))->klass
+#define Object_setClass(obj_, class_) (((Object*)(obj_))->klass = (const ObjectClass*) class_)
#define Object_delete(obj_) Object_getClass(obj_)->delete((Object*)(obj_))
#define Object_displayFn(obj_) Object_getClass(obj_)->display
-#define Object_display(obj_, str_) Object_getClass(obj_)->display((Object*)(obj_), str_)
+#define Object_display(obj_, str_) Object_getClass(obj_)->display((const Object*)(obj_), str_)
#define Object_compare(obj_, other_) Object_getClass(obj_)->compare((const void*)(obj_), other_)
#define Class(class_) ((const ObjectClass*)(&(class_ ## _class)))
diff --git a/Process.c b/Process.c
index ea703e4b..2d5ffb4f 100644
--- a/Process.c
+++ b/Process.c
@@ -181,9 +181,9 @@ void Process_printTime(RichString* str, unsigned long long totalHundredths) {
}
}
-static inline void Process_writeCommand(Process* this, int attr, int baseattr, RichString* str) {
+static inline void Process_writeCommand(const Process* this, int attr, int baseattr, RichString* str) {
int start = RichString_size(str), finish = 0;
- char* comm = this->comm;
+ const char* comm = this->comm;
if (this->settings->highlightBaseName || !this->settings->showProgramPath) {
int i, basename = 0;
@@ -240,7 +240,7 @@ void Process_outputRate(RichString* str, char* buffer, int n, double rate, int c
}
}
-void Process_writeField(Process* this, RichString* str, ProcessField field) {
+void Process_writeField(const Process* this, RichString* str, ProcessField field) {
char buffer[256]; buffer[255] = '\0';
int attr = CRT_colors[DEFAULT_COLOR];
int baseattr = CRT_colors[PROCESS_BASENAME];
@@ -366,9 +366,9 @@ void Process_writeField(Process* this, RichString* str, ProcessField field) {
RichString_append(str, attr, buffer);
}
-void Process_display(Object* cast, RichString* out) {
- Process* this = (Process*) cast;
- ProcessField* fields = this->settings->fields;
+void Process_display(const Object* cast, RichString* out) {
+ const Process* this = (const Process*) cast;
+ const ProcessField* fields = this->settings->fields;
RichString_prune(out);
for (int i = 0; fields[i]; i++)
As_Process(this)->writeField(this, out, fields[i]);
diff --git a/Process.h b/Process.h
index 664aecc7..7e1bda68 100644
--- a/Process.h
+++ b/Process.h
@@ -113,7 +113,7 @@ typedef struct ProcessFieldData_ {
} ProcessFieldData;
// Implemented in platform-specific code:
-void Process_writeField(Process* this, RichString* str, ProcessField field);
+void Process_writeField(const Process* this, RichString* str, ProcessField field);
long Process_compare(const void* v1, const void* v2);
void Process_delete(Object* cast);
bool Process_isThread(const Process* this);
@@ -122,7 +122,7 @@ extern ProcessPidColumn Process_pidColumns[];
extern char Process_pidFormat[20];
typedef Process*(*Process_New)(struct Settings_*);
-typedef void (*Process_WriteField)(Process*, RichString*, ProcessField);
+typedef void (*Process_WriteField)(const Process*, RichString*, ProcessField);
typedef struct ProcessClass_ {
const ObjectClass super;
@@ -158,7 +158,7 @@ void Process_printTime(RichString* str, unsigned long long totalHundredths);
void Process_outputRate(RichString* str, char* buffer, int n, double rate, int coloring);
-void Process_display(Object* cast, RichString* out);
+void Process_display(const Object* cast, RichString* out);
void Process_done(Process* this);
diff --git a/SwapMeter.c b/SwapMeter.c
index e754bbe6..fc4e6b28 100644
--- a/SwapMeter.c
+++ b/SwapMeter.c
@@ -34,9 +34,9 @@ static void SwapMeter_updateValues(Meter* this, char* buffer, int size) {
}
}
-static void SwapMeter_display(Object* cast, RichString* out) {
+static void SwapMeter_display(const Object* cast, RichString* out) {
char buffer[50];
- Meter* this = (Meter*)cast;
+ const Meter* this = (const Meter*)cast;
RichString_write(out, CRT_colors[METER_TEXT], ":");
Meter_humanUnit(buffer, this->total, 50);
RichString_append(out, CRT_colors[METER_VALUE], buffer);
diff --git a/TasksMeter.c b/TasksMeter.c
index bf289e99..fb3767c5 100644
--- a/TasksMeter.c
+++ b/TasksMeter.c
@@ -33,9 +33,9 @@ static void TasksMeter_updateValues(Meter* this, char* buffer, int len) {
xSnprintf(buffer, len, "%d/%d", (int) this->values[3], (int) this->total);
}
-static void TasksMeter_display(Object* cast, RichString* out) {
- Meter* this = (Meter*)cast;
- Settings* settings = this->pl->settings;
+static void TasksMeter_display(const Object* cast, RichString* out) {
+ const Meter* this = (const Meter*)cast;
+ const Settings* settings = this->pl->settings;
char buffer[20];
int processes = (int) this->values[2];
diff --git a/linux/PressureStallMeter.c b/linux/PressureStallMeter.c
index 577692e3..a54b4375 100644
--- a/linux/PressureStallMeter.c
+++ b/linux/PressureStallMeter.c
@@ -41,8 +41,8 @@ static void PressureStallMeter_updateValues(Meter* this, char* buffer, int len)
xSnprintf(buffer, len, "xxxx %.2lf%% %.2lf%% %.2lf%%", this->values[0], this->values[1], this->values[2]);
}
-static void PressureStallMeter_display(Object* cast, RichString* out) {
- Meter* this = (Meter*)cast;
+static void PressureStallMeter_display(const Object* cast, RichString* out) {
+ const Meter* this = (const Meter*)cast;
char buffer[20];
xSnprintf(buffer, sizeof(buffer), "%.2lf%% ", this->values[0]);
RichString_write(out, CRT_colors[PRESSURE_STALL_TEN], buffer);
diff --git a/zfs/ZfsArcMeter.c b/zfs/ZfsArcMeter.c
index d52605c6..6301a9c4 100644
--- a/zfs/ZfsArcMeter.c
+++ b/zfs/ZfsArcMeter.c
@@ -55,9 +55,9 @@ static void ZfsArcMeter_updateValues(Meter* this, char* buffer, int size) {
}
}
-static void ZfsArcMeter_display(Object* cast, RichString* out) {
+static void ZfsArcMeter_display(const Object* cast, RichString* out) {
char buffer[50];
- Meter* this = (Meter*)cast;
+ const Meter* this = (const Meter*)cast;
if (this->values[5] > 0) {
Meter_humanUnit(buffer, this->total, 50);
diff --git a/zfs/ZfsCompressedArcMeter.c b/zfs/ZfsCompressedArcMeter.c
index 360877ad..ccf57203 100644
--- a/zfs/ZfsCompressedArcMeter.c
+++ b/zfs/ZfsCompressedArcMeter.c
@@ -38,7 +38,7 @@ void ZfsCompressedArcMeter_readStats(Meter* this, ZfsArcStats* stats) {
}
}
-static void ZfsCompressedArcMeter_printRatioString(Meter* this, char* buffer, int size) {
+static void ZfsCompressedArcMeter_printRatioString(const Meter* this, char* buffer, int size) {
xSnprintf(buffer, size, "%.2f:1", this->total/this->values[0]);
}
@@ -48,9 +48,9 @@ static void ZfsCompressedArcMeter_updateValues(Meter* this, char* buffer, int si
ZfsCompressedArcMeter_printRatioString(this, buffer, size);
}
-static void ZfsCompressedArcMeter_display(Object* cast, RichString* out) {
+static void ZfsCompressedArcMeter_display(const Object* cast, RichString* out) {
char buffer[50];
- Meter* this = (Meter*)cast;
+ const Meter* this = (const Meter*)cast;
if (this->values[0] > 0) {
Meter_humanUnit(buffer, this->total, 50);

© 2014-2024 Faster IT GmbH | imprint | privacy policy