aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/bucket.c17
-rw-r--r--src/debug.c137
-rw-r--r--src/falloc.c18
-rw-r--r--src/findkey.c12
-rw-r--r--src/gdbmdefs.h14
-rw-r--r--src/gdbmopen.c8
-rw-r--r--src/gdbmstore.c10
-rw-r--r--src/lex.l2
-rw-r--r--src/update.c12
-rw-r--r--tests/gtload.c68
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
@@ -112,8 +112,7 @@ _gdbm_get_bucket (GDBM_FILE dbf, int dir_index)
112 /* It is not in the cache, read it from the disk. */ 112 /* It is not in the cache, read it from the disk. */
113 113
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)
118 { 117 {
119 GDBM_SET_ERRNO (dbf, GDBM_FILE_SEEK_ERROR, TRUE); 118 GDBM_SET_ERRNO (dbf, GDBM_FILE_SEEK_ERROR, TRUE);
@@ -131,9 +130,8 @@ _gdbm_get_bucket (GDBM_FILE dbf, int dir_index)
131 _gdbm_cache_entry_invalidate (dbf, lru); 130 _gdbm_cache_entry_invalidate (dbf, lru);
132 131
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)
138 { 136 {
139 GDBM_DEBUG (GDBM_DEBUG_ERR, 137 GDBM_DEBUG (GDBM_DEBUG_ERR,
@@ -302,8 +300,7 @@ _gdbm_split_bucket (GDBM_FILE dbf, int next_insert)
302 dir_adr = _gdbm_alloc (dbf, dir_size); 300 dir_adr = _gdbm_alloc (dbf, dir_size);
303 if (dir_adr == 0) 301 if (dir_adr == 0)
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)
308 { 305 {
309 GDBM_SET_ERRNO (dbf, GDBM_MALLOC_ERROR, TRUE); 306 GDBM_SET_ERRNO (dbf, GDBM_MALLOC_ERROR, TRUE);
@@ -435,16 +432,14 @@ _gdbm_write_bucket (GDBM_FILE dbf, cache_elem *ca_entry)
435 int rc; 432 int rc;
436 off_t file_pos; /* The return value for lseek. */ 433 off_t file_pos; /* The return value for lseek. */
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)
441 { 437 {
442 GDBM_SET_ERRNO (dbf, GDBM_FILE_SEEK_ERROR, TRUE); 438 GDBM_SET_ERRNO (dbf, GDBM_FILE_SEEK_ERROR, TRUE);
443 _gdbm_fatal (dbf, _("lseek error")); 439 _gdbm_fatal (dbf, _("lseek error"));
444 return -1; 440 return -1;
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)
449 { 444 {
450 GDBM_DEBUG (GDBM_DEBUG_STORE|GDBM_DEBUG_ERR, 445 GDBM_DEBUG (GDBM_DEBUG_STORE|GDBM_DEBUG_ERR,
diff --git a/src/debug.c b/src/debug.c
index 00f568c..08957ed 100644
--- a/src/debug.c
+++ b/src/debug.c
@@ -136,140 +136,3 @@ gdbm_debug_datum (datum dat, char const *pfx)
136 } 136 }
137} 137}
138 138
139
140struct 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
150static struct hook_list *hook_head, *hook_tail;
151static struct hook_list *hook_recent;
152
153static struct hook_list *
154hook_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
203static struct hook_list *
204hook_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
211static void
212hook_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
236static int
237default_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
243void
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
253void
254_gdbm_debug_hook_remove (char const *id)
255{
256 hook_remove (id);
257}
258
259int
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
268int
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
@@ -182,8 +182,7 @@ pop_avail_block (GDBM_FILE dbf)
182 + sizeof (avail_block)); 182 + sizeof (avail_block));
183 183
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)
188 { 187 {
189 GDBM_SET_ERRNO (dbf, GDBM_MALLOC_ERROR, TRUE); 188 GDBM_SET_ERRNO (dbf, GDBM_MALLOC_ERROR, TRUE);
@@ -192,8 +191,7 @@ pop_avail_block (GDBM_FILE dbf)
192 } 191 }
193 192
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)
198 { 196 {
199 GDBM_SET_ERRNO (dbf, GDBM_FILE_SEEK_ERROR, TRUE); 197 GDBM_SET_ERRNO (dbf, GDBM_FILE_SEEK_ERROR, TRUE);
@@ -202,8 +200,7 @@ pop_avail_block (GDBM_FILE dbf)
202 return -1; 200 return -1;
203 } 201 }
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)
208 { 205 {