summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2006-11-12 21:53:56 +0000
committerHisham Muhammad <hisham@gobolinux.org>2006-11-12 21:53:56 +0000
commit3d62edb67857c448dc028fb8a6fca3db73d5a599 (patch)
tree28130992fbd98f05acb48171070c6d7a2c73fc9a
parent36848494f57ff8cdc95876c95c36052eca40ccdb (diff)
Bugfix: collect orphaned items during tree generation
at the end of the tree. Add debugging sanity checks.
-rw-r--r--ProcessList.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/ProcessList.c b/ProcessList.c
index d9f31429..f05801fd 100644
--- a/ProcessList.c
+++ b/ProcessList.c
@@ -204,6 +204,7 @@ ProcessList* ProcessList_new(UsersTable* usersTable) {
this = malloc(sizeof(ProcessList));
this->processes = Vector_new(PROCESS_CLASS, true, DEFAULT_SIZE, Process_compare);
this->processTable = Hashtable_new(70, false);
+ assert(Hashtable_count(this->processTable) == Vector_count(this->processes));
this->prototype = Process_new(this);
this->usersTable = usersTable;
@@ -303,6 +304,7 @@ void ProcessList_add(ProcessList* this, Process* p) {
Hashtable_put(this->processTable, p->pid, p);
assert(Vector_indexOf(this->processes, p, Process_pidCompare) != -1);
assert(Hashtable_get(this->processTable, p->pid) != NULL);
+ assert(Hashtable_count(this->processTable) == Vector_count(this->processes));
}
void ProcessList_remove(ProcessList* this, Process* p) {
@@ -315,6 +317,7 @@ void ProcessList_remove(ProcessList* this, Process* p) {
assert(index != -1);
Vector_remove(this->processes, index);
assert(Hashtable_get(this->processTable, pid) == NULL); (void)pid;
+ assert(Hashtable_count(this->processTable) == Vector_count(this->processes));
}
Process* ProcessList_get(ProcessList* this, int index) {
@@ -338,10 +341,12 @@ static void ProcessList_buildTree(ProcessList* this, int pid, int level, int ind
int size = Vector_size(children);
for (int i = 0; i < size; i++) {
Process* process = (Process*) (Vector_get(children, i));
+ int s = this->processes2->items;
if (direction == 1)
Vector_add(this->processes2, process);
else
Vector_insert(this->processes2, 0, process);
+ assert(this->processes2->items == s+1); (void)s;
int nextIndent = indent;
if (i < size - 1)
nextIndent = indent | (1 << level);
@@ -362,11 +367,19 @@ void ProcessList_sort(ProcessList* this) {
Vector_sort(this->processes);
this->sortKey = sortKey;
this->direction = direction;
+ int vsize = Vector_size(this->processes);
Process* init = (Process*) (Vector_take(this->processes, 0));
assert(init->pid == 1);
init->indent = 0;
Vector_add(this->processes2, init);
ProcessList_buildTree(this, init->pid, 0, 0, direction);
+ while (Vector_size(this->processes)) {
+ Process* p = (Process*) (Vector_take(this->processes, 0));
+ p->indent = 0;
+ Vector_add(this->processes2, p);
+ }
+ assert(Vector_size(this->processes2) == vsize); (void)vsize;
+ assert(Vector_size(this->processes) == 0);
Vector* t = this->processes;
this->processes = this->processes2;
this->processes2 = t;
@@ -519,6 +532,7 @@ void ProcessList_processEntries(ProcessList* this, char* dirname, int parent, fl
Process* process = NULL;
+ assert(Hashtable_count(this->processTable) == Vector_count(this->processes));
Process* existingProcess = (Process*) Hashtable_get(this->processTable, pid);
if (existingProcess) {
assert(Vector_indexOf(this->processes, existingProcess, Process_pidCompare) != -1);
@@ -612,6 +626,7 @@ void ProcessList_processEntries(ProcessList* this, char* dirname, int parent, fl
}
if (existingProcess)
ProcessList_remove(this, process);
+ assert(Hashtable_count(this->processTable) == Vector_count(this->processes));
}
}
}

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