Skip to content

Commit 493c3cb

Browse files
committed
Change ht_key_t typedef to size_t
This allows a larger hash table. The bit width of keys no longer limited to 2^32 in 64-bit builds. Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
1 parent daf0292 commit 493c3cb

20 files changed

Lines changed: 42 additions & 39 deletions

Action.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ static bool changePriority(MainPanel* panel, int delta) {
113113
static void addUserToVector(ht_key_t key, void* userCast, void* panelCast) {
114114
const char* user = userCast;
115115
Panel* panel = panelCast;
116-
Panel_add(panel, (Object*) ListItem_new(user, key));
116+
Panel_add(panel, (Object*) ListItem_new(user, (int)key));
117117
}
118118

119119
bool Action_setUserOnly(const char* userName, uid_t* userId) {

AvailableColumnsPanel.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ static void AvailableColumnsPanel_addDynamicColumn(ht_key_t key, void* value, vo
9191
xSnprintf(description, sizeof(description), "%s - %s", title, text);
9292
else
9393
xSnprintf(description, sizeof(description), "%s", title);
94-
Panel_add(&this->super, (Object*) ListItem_new(description, key));
94+
Panel_add(&this->super, (Object*) ListItem_new(description, (int)key));
9595
}
9696

9797
// Handle DynamicColumns entries in the AvailableColumnsPanel

DynamicColumn.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ void DynamicColumn_done(DynamicColumn* this) {
4646
typedef struct {
4747
const char* name;
4848
const DynamicColumn* data;
49-
unsigned int key;
49+
ht_key_t key;
5050
} DynamicIterator;
5151

5252
static void DynamicColumn_compare(ht_key_t key, void* value, void* data) {
@@ -58,7 +58,7 @@ static void DynamicColumn_compare(ht_key_t key, void* value, void* data) {
5858
}
5959
}
6060

61-
const DynamicColumn* DynamicColumn_search(Hashtable* dynamics, const char* name, unsigned int* key) {
61+
const DynamicColumn* DynamicColumn_search(Hashtable* dynamics, const char* name, ht_key_t* key) {
6262
DynamicIterator iter = { .key = 0, .data = NULL, .name = name };
6363
if (dynamics)
6464
Hashtable_foreach(dynamics, DynamicColumn_compare, &iter);
@@ -67,10 +67,10 @@ const DynamicColumn* DynamicColumn_search(Hashtable* dynamics, const char* name,
6767
return iter.data;
6868
}
6969

70-
const DynamicColumn* DynamicColumn_lookup(Hashtable* dynamics, unsigned int key) {
70+
const DynamicColumn* DynamicColumn_lookup(Hashtable* dynamics, ht_key_t key) {
7171
return (const DynamicColumn*) Hashtable_get(dynamics, key);
7272
}
7373

74-
bool DynamicColumn_writeField(const Process* proc, RichString* str, unsigned int key) {
74+
bool DynamicColumn_writeField(const Process* proc, RichString* str, ht_key_t key) {
7575
return Platform_dynamicColumnWriteField(proc, str, key);
7676
}

DynamicColumn.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ const char* DynamicColumn_name(unsigned int key);
3636

3737
void DynamicColumn_done(DynamicColumn* this);
3838

39-
const DynamicColumn* DynamicColumn_lookup(Hashtable* dynamics, unsigned int key);
39+
const DynamicColumn* DynamicColumn_lookup(Hashtable* dynamics, ht_key_t key);
4040

41-
const DynamicColumn* DynamicColumn_search(Hashtable* dynamics, const char* name, unsigned int* key);
41+
const DynamicColumn* DynamicColumn_search(Hashtable* dynamics, const char* name, ht_key_t* key);
4242

43-
bool DynamicColumn_writeField(const Process* proc, RichString* str, unsigned int key);
43+
bool DynamicColumn_writeField(const Process* proc, RichString* str, ht_key_t key);
4444

4545
#endif

DynamicScreen.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ void DynamicScreen_done(DynamicScreen* this);
3131

3232
void DynamicScreens_addAvailableColumns(Panel* availableColumns, char* screen);
3333

34-
const char* DynamicScreen_lookup(Hashtable* screens, unsigned int key);
34+
const char* DynamicScreen_lookup(Hashtable* screens, ht_key_t key);
3535

36-
bool DynamicScreen_search(Hashtable* screens, const char* name, unsigned int* key);
36+
bool DynamicScreen_search(Hashtable* screens, const char* name, ht_key_t* key);
3737

3838
#endif

Hashtable.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ static void Hashtable_dump(const Hashtable* this) {
4949

5050
size_t items = 0;
5151
for (size_t i = 0; i < this->size; i++) {
52-
fprintf(stderr, " item %5zu: key = %5u probe = %2zu value = %p\n",
52+
fprintf(stderr, " item %5zu: key = %5zu probe = %2zu value = %p\n",
5353
i,
54-
this->buckets[i].key,
54+
(size_t)this->buckets[i].key,
5555
this->buckets[i].probe,
5656
this->buckets[i].value);
5757

Hashtable.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ in the source distribution for its full text.
1111
#include <stddef.h>
1212

1313

14-
typedef unsigned int ht_key_t;
14+
typedef size_t ht_key_t;
1515

1616
typedef void(*Hashtable_PairFunction)(ht_key_t key, void* value, void* userdata);
1717

Header.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ in the source distribution for its full text.
1010
#include "Header.h"
1111

1212
#include <assert.h>
13+
#include <limits.h>
1314
#include <math.h>
1415
#include <stdbool.h>
1516
#include <stdint.h>
@@ -94,8 +95,10 @@ static void Header_addMeterByName(Header* this, const char* name, MeterModeId mo
9495
return; // htoprc parse failure
9596
*end = '\0';
9697
const Settings* settings = this->host->settings;
97-
if (!DynamicMeter_search(settings->dynamicMeters, dynamic, &param))
98+
ht_key_t key;
99+
if (!DynamicMeter_search(settings->dynamicMeters, dynamic, &key) || key > UINT_MAX)
98100
return; // name lookup failure
101+
param = (unsigned int)key;
99102
} else {
100103
param = 0;
101104
}

Process.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,7 @@ void Process_writeField(const Process* this, RichString* str, RowField field) {
782782
xSnprintf(buffer, n, "%-10d ", this->st_uid);
783783
break;
784784
default:
785-
if (DynamicColumn_writeField(this, str, field))
785+
if (DynamicColumn_writeField(this, str, (ht_key_t)field))
786786
return;
787787
assert(0 && "Process_writeField: default key reached"); /* should never be reached */
788788
xSnprintf(buffer, n, "- ");

Settings.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,12 +209,12 @@ static int toFieldIndex(Hashtable* columns, const char* str) {
209209
char* end;
210210
if ((end = strrchr(dynamic, ')')) != NULL) {
211211
bool success;
212-
unsigned int key;
212+
ht_key_t key;
213213
*end = '\0';
214-
success = DynamicColumn_search(columns, dynamic, &key) != NULL;
214+
success = DynamicColumn_search(columns, dynamic, &key) != NULL && key <= INT_MAX;
215215
*end = ')';
216216
if (success)
217-
return key;
217+
return (int)key;
218218
}
219219
}
220220
// Fallback to iterative scan of table of fields by-name.

0 commit comments

Comments
 (0)