diff options
-rw-r--r-- | src/bucket.c | 17 | ||||
-rw-r--r-- | src/debug.c | 137 | ||||
-rw-r--r-- | src/falloc.c | 18 | ||||
-rw-r--r-- | src/findkey.c | 12 | ||||
-rw-r--r-- | src/gdbmdefs.h | 14 | ||||
-rw-r--r-- | src/gdbmopen.c | 8 | ||||
-rw-r--r-- | src/gdbmstore.c | 10 | ||||
-rw-r--r-- | src/lex.l | 2 | ||||
-rw-r--r-- | src/update.c | 12 | ||||
-rw-r--r-- | tests/gtload.c | 68 |
10 files changed, 26 insertions, 272 deletions
diff --git a/src/bucket.c b/src/bucket.c index c75db42..2289594 100644 --- a/src/bucket.c +++ b/src/bucket.c | |||
@@ -114,4 +114,3 @@ _gdbm_get_bucket (GDBM_FILE dbf, int dir_index) | |||
114 | /* Position the file pointer */ | 114 | /* Position the file pointer */ |
115 | file_pos = GDBM_DEBUG_OVERRIDE ("_gdbm_get_bucket:seek-failure", | 115 | file_pos = __lseek (dbf, bucket_adr, SEEK_SET); |
116 | __lseek (dbf, bucket_adr, SEEK_SET)); | ||
117 | if (file_pos != bucket_adr) | 116 | if (file_pos != bucket_adr) |
@@ -133,5 +132,4 @@ _gdbm_get_bucket (GDBM_FILE dbf, int dir_index) | |||
133 | /* Read the bucket. */ | 132 | /* Read the bucket. */ |
134 | rc = GDBM_DEBUG_OVERRIDE ("_gdbm_get_bucket:read-failure", | 133 | rc = _gdbm_full_read (dbf, dbf->bucket_cache[lru].ca_bucket, |
135 | _gdbm_full_read (dbf, dbf->bucket_cache[lru].ca_bucket, | 134 | dbf->header->bucket_size); |
136 | dbf->header->bucket_size)); | ||
137 | if (rc) | 135 | if (rc) |
@@ -304,4 +302,3 @@ _gdbm_split_bucket (GDBM_FILE dbf, int next_insert) | |||
304 | return -1; | 302 | return -1; |
305 | new_dir = GDBM_DEBUG_ALLOC ("_gdbm_split_bucket:malloc-failure", | 303 | new_dir = malloc (dir_size); |
306 | malloc (dir_size)); | ||
307 | if (new_dir == NULL) | 304 | if (new_dir == NULL) |
@@ -437,4 +434,3 @@ _gdbm_write_bucket (GDBM_FILE dbf, cache_elem *ca_entry) | |||
437 | 434 | ||
438 | file_pos = GDBM_DEBUG_OVERRIDE ("_gdbm_write_bucket:seek-failure", | 435 | file_pos = __lseek (dbf, ca_entry->ca_adr, SEEK_SET); |
439 | __lseek (dbf, ca_entry->ca_adr, SEEK_SET)); | ||
440 | if (file_pos != ca_entry->ca_adr) | 436 | if (file_pos != ca_entry->ca_adr) |
@@ -445,4 +441,3 @@ _gdbm_write_bucket (GDBM_FILE dbf, cache_elem *ca_entry) | |||
445 | } | 441 | } |
446 | rc = GDBM_DEBUG_OVERRIDE ("_gdbm_write_bucket:write-failure", | 442 | rc = _gdbm_full_write (dbf, ca_entry->ca_bucket, dbf->header->bucket_size); |
447 | _gdbm_full_write (dbf, ca_entry->ca_bucket, dbf->header->bucket_size)); | ||
448 | if (rc) | 443 | if (rc) |
diff --git a/src/debug.c b/src/debug.c index 00f568c..08957ed 100644 --- a/src/debug.c +++ b/src/debug.c | |||
@@ -138,138 +138 @@ gdbm_debug_datum (datum dat, char const *pfx) | |||
138 | 138 | ||
139 | |||
140 | struct hook_list | ||
141 | { | ||
142 | struct hook_list *next; | ||
143 | struct hook_list *prev; | ||
144 | char *id; | ||
145 | gdbm_debug_hook hook; | ||
146 | void *data; | ||
147 | int retval; | ||
148 | }; | ||
149 | |||
150 | static struct hook_list *hook_head, *hook_tail; | ||
151 | static struct hook_list *hook_recent; | ||
152 | |||
153 | static struct hook_list * | ||
154 | hook_lookup_or_install (char const *id, int install) | ||
155 | { | ||
156 | struct hook_list *p; | ||
157 | |||
158 | for (p = hook_head; p; p = p->next) | ||
159 | { | ||
160 | int res = strcmp (p->id, id); | ||
161 | if (res == 0) | ||
162 | return p; | ||
163 | if (res > 0) | ||
164 | break; | ||
165 | } | ||
166 | |||
167 | if (install) | ||
168 | { | ||
169 | struct hook_list *elt = malloc (sizeof *elt); | ||
170 | if (!elt) | ||
171 | return NULL; | ||
172 | elt->id = strdup (id); | ||
173 | if (!elt->id) | ||
174 | { | ||
175 | SAVE_ERRNO (free (elt)); | ||
176 | return NULL; | ||
177 | } | ||
178 | elt->hook = NULL; | ||
179 | elt->next = p; | ||
180 | if (p) | ||
181 | { | ||
182 | if (p->prev) | ||
183 | p->prev->next = elt; | ||
184 | else | ||
185 | hook_head = elt; | ||
186 | elt->prev = p->prev; | ||
187 | } | ||
188 | else | ||
189 | { | ||
190 | elt->prev = hook_tail; | ||
191 | if (hook_tail) | ||
192 | hook_tail->next = elt; | ||
193 | else | ||
194 | hook_head = elt; | ||
195 | hook_tail = elt; | ||
196 | } | ||
197 | return elt; | ||
198 | } | ||
199 | |||
200 | return NULL; | ||
201 | } | ||
202 | |||
203 | static struct hook_list * | ||
204 | hook_lookup (char const *id) | ||
205 | { | ||
206 | if (!(hook_recent && strcmp (hook_recent->id, id) == 0)) | ||
207 | hook_recent = hook_lookup_or_install (id, FALSE); | ||
208 | return hook_recent; | ||
209 | } | ||
210 | |||
211 | static void | ||
212 | hook_remove (char const *id) | ||
213 | { | ||
214 | struct hook_list *p; | ||
215 | |||
216 | p = hook_lookup (id); | ||
217 | if (!p) | ||
218 | return; | ||
219 | |||
220 | hook_recent = NULL; | ||
221 | |||
222 | if (p->prev) | ||
223 | p->prev->next = p->next; | ||
224 | else | ||
225 | hook_head = p->next; | ||
226 | |||
227 | if (p->next) | ||
228 | p->next->prev = p->prev; | ||
229 | else | ||
230 | hook_tail = p->prev; | ||
231 | |||
232 | free (p->id); | ||
233 | free (p); | ||
234 | } | ||
235 | |||
236 | static int | ||
237 | default_hook (char const *file, int line, char const *id, void *data) | ||
238 | { | ||
239 | fprintf (stderr, "%s:%d: hit debug hook %s\n", file, line, id); | ||
240 | return 1; | ||
241 | } | ||
242 | |||
243 | void | ||
244 | _gdbm_debug_hook_install (char const *id, gdbm_debug_hook hook, void *data) | ||
245 | { | ||
246 | struct hook_list *p; | ||
247 | |||
248 | p = hook_lookup_or_install (id, TRUE); | ||
249 | p->hook = hook ? hook : default_hook; | ||
250 | p->data = data; | ||
251 | } | ||
252 | |||
253 | void | ||
254 | _gdbm_debug_hook_remove (char const *id) | ||
255 | { | ||
256 | hook_remove (id); | ||
257 | } | ||
258 | |||
259 | int | ||
260 | _gdbm_debug_hook_check (char const *file, int line, char const *id) | ||
261 | { | ||
262 | struct hook_list *p = hook_lookup (id); | ||
263 | if (p) | ||
264 | return p->retval = p->hook (file, line, id, p->data); | ||
265 | return 0; | ||
266 | } | ||
267 | |||
268 | int | ||
269 | _gdbm_debug_hook_val (char const *id) | ||
270 | { | ||
271 | struct hook_list *p = hook_lookup (id); | ||
272 | if (p) | ||
273 | return p->retval; | ||
274 | return 0; | ||
275 | } | ||
diff --git a/src/falloc.c b/src/falloc.c index c3bd145..13ee0ed 100644 --- a/src/falloc.c +++ b/src/falloc.c | |||
@@ -184,4 +184,3 @@ pop_avail_block (GDBM_FILE dbf) | |||
184 | /* Allocate space for the block. */ | 184 | /* Allocate space for the block. */ |
185 | new_blk = GDBM_DEBUG_ALLOC ("pop_avail_block:malloc-failure", | 185 | new_blk = malloc (new_el.av_size); |
186 | malloc (new_el.av_size)); | ||
187 | if (new_blk == NULL) | 186 | if (new_blk == NULL) |
@@ -194,4 +193,3 @@ pop_avail_block (GDBM_FILE dbf) | |||
194 | /* Read the block. */ | 193 | /* Read the block. */ |
195 | file_pos = GDBM_DEBUG_OVERRIDE ("pop_avail_block:lseek-failure", | 194 | file_pos = __lseek (dbf, new_el.av_adr, SEEK_SET); |
196 | __lseek (dbf, new_el.av_adr, SEEK_SET)); | ||
197 | if (file_pos != new_el.av_adr) | 195 | if (file_pos != new_el.av_adr) |
@@ -204,4 +202,3 @@ pop_avail_block (GDBM_FILE dbf) | |||
204 | 202 | ||
205 | rc = GDBM_DEBUG_OVERRIDE ("pop_avail_block:read-failure", | 203 | rc = _gdbm_full_read (dbf, new_blk, new_el.av_size); |
206 | _gdbm_full_read (dbf, new_blk, new_el.av_size)); | ||
207 | if (rc) | 204 | if (rc) |
@@ -297,4 +294,3 @@ push_avail_block (GDBM_FILE dbf) | |||
297 | /* Split the header block. */ | 294 | /* Split the header block. */ |
298 | temp = GDBM_DEBUG_ALLOC ("push_avail_block:malloc-failure", | 295 | temp = malloc (av_size); |
299 | malloc (av_size)); | ||
300 | if (temp == NULL) | 296 | if (temp == NULL) |
@@ -327,4 +323,3 @@ push_avail_block (GDBM_FILE dbf) | |||
327 | /* Update the disk. */ | 323 | /* Update the disk. */ |
328 | file_pos = GDBM_DEBUG_OVERRIDE ("push_avail_block:lseek-failure", | 324 | file_pos = __lseek (dbf, av_adr, SEEK_SET); |
329 | __lseek (dbf, av_adr, SEEK_SET)); | ||
330 | if (file_pos != av_adr) | 325 | if (file_pos != av_adr) |
@@ -336,4 +331,3 @@ push_avail_block (GDBM_FILE dbf) | |||
336 | 331 | ||
337 | rc = GDBM_DEBUG_OVERRIDE ("push_avail_block:write-failure", | 332 | rc = _gdbm_full_write (dbf, temp, av_size); |
338 | _gdbm_full_write (dbf, temp, av_size)); | ||
339 | if (rc) | 333 | if (rc) |
diff --git a/src/findkey.c b/src/findkey.c index bd9fd83..9bb4553 100644 --- a/src/findkey.c +++ b/src/findkey.c | |||
@@ -73,5 +73,3 @@ _gdbm_read_entry (GDBM_FILE dbf, int elem_loc) | |||
73 | 73 | ||
74 | if (GDBM_DEBUG_HOOK ("_gdbm_read_entry:malloc-failure")) | 74 | if (key_size + data_size == 0) |
75 | data_ca->dptr = NULL; | ||
76 | else if (key_size + data_size == 0) | ||
77 | data_ca->dptr = (char *) malloc (1); | 75 | data_ca->dptr = (char *) malloc (1); |
@@ -87,5 +85,4 @@ _gdbm_read_entry (GDBM_FILE dbf, int elem_loc) | |||
87 | /* Read into the cache. */ | 85 | /* Read into the cache. */ |
88 | file_pos = GDBM_DEBUG_OVERRIDE ("_gdbm_read_entry:lseek-failure", | 86 | file_pos = __lseek (dbf, dbf->bucket->h_table[elem_loc].data_pointer, |
89 | __lseek (dbf, dbf->bucket->h_table[elem_loc].data_pointer, | 87 | SEEK_SET); |
90 | SEEK_SET)); | ||
91 | if (file_pos != dbf->bucket->h_table[elem_loc].data_pointer) | 88 | if (file_pos != dbf->bucket->h_table[elem_loc].data_pointer) |
@@ -97,4 +94,3 @@ _gdbm_read_entry (GDBM_FILE dbf, int elem_loc) | |||
97 | 94 | ||
98 | rc = GDBM_DEBUG_OVERRIDE ("_gdbm_read_entry:read-failure", | 95 | rc = _gdbm_full_read (dbf, data_ca->dptr, key_size+data_size); |
99 | _gdbm_full_read (dbf, data_ca->dptr, key_size+data_size)); | ||
100 | if (rc) | 96 | if (rc) |
diff --git a/src/gdbmdefs.h b/src/gdbmdefs.h index d940c5d..4ae646f 100644 --- a/src/gdbmdefs.h +++ b/src/gdbmdefs.h | |||
@@ -327,13 +327,2 @@ struct gdbm_file_info | |||
327 | while (0) | 327 | while (0) |
328 | |||
329 | typedef int (*gdbm_debug_hook) (char const *, int, char const *, void *); | ||