… | |
… | |
48 | } |
48 | } |
49 | |
49 | |
50 | ol = first_friendly_object; |
50 | ol = first_friendly_object; |
51 | first_friendly_object = get_objectlink (); |
51 | first_friendly_object = get_objectlink (); |
52 | first_friendly_object->ob = op; |
52 | first_friendly_object->ob = op; |
53 | first_friendly_object->id = op->count; |
|
|
54 | first_friendly_object->next = ol; |
53 | first_friendly_object->next = ol; |
55 | } |
54 | } |
56 | |
55 | |
57 | /* |
56 | /* |
58 | * Removes the specified object from the linked list of friendly objects. |
57 | * Removes the specified object from the linked list of friendly objects. |
… | |
… | |
75 | */ |
74 | */ |
76 | if (first_friendly_object->ob == op) |
75 | if (first_friendly_object->ob == op) |
77 | { |
76 | { |
78 | obj = first_friendly_object; |
77 | obj = first_friendly_object; |
79 | first_friendly_object = obj->next; |
78 | first_friendly_object = obj->next; |
80 | free (obj); |
79 | delete obj; |
81 | } |
80 | } |
82 | else |
81 | else |
83 | { |
82 | { |
84 | objectlink *prev = first_friendly_object; |
83 | objectlink *prev = first_friendly_object; |
85 | |
84 | |
… | |
… | |
87 | { |
86 | { |
88 | if (obj->ob == op) |
87 | if (obj->ob == op) |
89 | break; |
88 | break; |
90 | prev = obj; |
89 | prev = obj; |
91 | } |
90 | } |
|
|
91 | |
92 | if (obj) |
92 | if (obj) |
93 | { |
93 | { |
94 | /* This should not happen. But if it does, presumably the |
|
|
95 | * call to remove it is still valid. |
|
|
96 | */ |
|
|
97 | if (obj->id != op->count) |
|
|
98 | { |
|
|
99 | LOG (llevError, "remove_friendly_object, tags do no match, %s, %d != %d\n", |
|
|
100 | op->name ? (const char *) op->name : "none", op->count, obj->id); |
|
|
101 | } |
|
|
102 | prev->next = obj->next; |
94 | prev->next = obj->next; |
103 | free (obj); |
95 | delete obj; |
104 | } |
96 | } |
105 | } |
97 | } |
106 | } |
98 | } |
107 | |
99 | |
108 | /* |
100 | /* |
… | |
… | |
126 | clean_friendly_list (void) |
118 | clean_friendly_list (void) |
127 | { |
119 | { |
128 | objectlink *obj, *prev = NULL, *next; |
120 | objectlink *obj, *prev = NULL, *next; |
129 | int count = 0; |
121 | int count = 0; |
130 | |
122 | |
131 | for (obj = first_friendly_object; obj != NULL; obj = next) |
123 | for (obj = first_friendly_object; obj; obj = next) |
132 | { |
124 | { |
133 | next = obj->next; |
125 | next = obj->next; |
134 | if (QUERY_FLAG (obj->ob, FLAG_FREED) || !QUERY_FLAG (obj->ob, FLAG_FRIENDLY) || (obj->id != obj->ob->count)) |
126 | if (QUERY_FLAG (obj->ob, FLAG_FREED) || !QUERY_FLAG (obj->ob, FLAG_FRIENDLY)) |
135 | { |
127 | { |
136 | if (prev) |
128 | if (prev) |
137 | { |
|
|
138 | prev->next = obj->next; |
129 | prev->next = obj->next; |
139 | } |
|
|
140 | else |
130 | else |
141 | { |
|
|
142 | first_friendly_object = obj->next; |
131 | first_friendly_object = obj->next; |
143 | } |
132 | |
144 | count++; |
133 | count++; |
145 | free (obj); |
134 | delete obj; |
146 | } |
135 | } |
147 | /* If we removed the object, then prev is still valid. */ |
|
|
148 | else |
136 | else |
|
|
137 | /* If we removed the object, then prev is still valid. */ |
149 | prev = obj; |
138 | prev = obj; |
150 | } |
139 | } |
|
|
140 | |
151 | if (count) |
141 | if (count) |
152 | LOG (llevDebug, "clean_friendly_list: Removed %d bogus links\n", count); |
142 | LOG (llevDebug, "clean_friendly_list: Removed %d bogus links\n", count); |
153 | } |
143 | } |
154 | |
144 | |
155 | /* Checks if the given object is already in the friendly list or not |
145 | /* Checks if the given object is already in the friendly list or not |