aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2018-05-30 12:32:31 +0300
committerSergey Poznyakoff <gray@gnu.org>2018-05-30 12:32:31 +0300
commita14a6881538229cd938282bd56c7f0d12a089be6 (patch)
tree89cfa47078460e7505c1a80ce71488eef29dfc63 /src
parent07caec236e3af48973874f2c0e19bafec4d13f78 (diff)
downloadgdbm-a14a6881538229cd938282bd56c7f0d12a089be6.tar.gz
gdbm-a14a6881538229cd938282bd56c7f0d12a089be6.tar.bz2
Drop debugging hooks
The hooks were introduced as a temporary tool in de7834e9. They did their job and are not necessary any more.
Diffstat (limited to 'src')
-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
9 files changed, 26 insertions, 204 deletions
diff --git a/src/bucket.c b/src/bucket.c
index c75db42..2289594 100644
--- a/src/bucket.c
+++ b/src/bucket.c
@@ -109,14 +109,13 @@ _gdbm_get_bucket (GDBM_FILE dbf, int dir_index)
109 } 109 }
110 } 110 }
111 111
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);
120 _gdbm_fatal (dbf, _("lseek error")); 119 _gdbm_fatal (dbf, _("lseek error"));
121 return -1; 120 return -1;
122 } 121 }
@@ -128,15 +127,14 @@ _gdbm_get_bucket (GDBM_FILE dbf, int dir_index)
128 if (_gdbm_write_bucket (dbf, &dbf->bucket_cache[lru])) 127 if (_gdbm_write_bucket (dbf, &dbf->bucket_cache[lru]))
129 return -1; 128 return -1;
130 } 129 }
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,
140 "%s: error reading bucket: %s", 138 "%s: error reading bucket: %s",
141 dbf->name, gdbm_db_strerror (dbf)); 139 dbf->name, gdbm_db_strerror (dbf));
142 dbf->need_recovery = TRUE; 140 dbf->need_recovery = TRUE;
@@ -299,14 +297,13 @@ _gdbm_split_bucket (GDBM_FILE dbf, int next_insert)
299 return -1; 297 return -1;
300 } 298 }
301 dir_size = dbf->header->dir_size * 2; 299 dir_size = dbf->header->dir_size * 2;
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);
310 _gdbm_fatal (dbf, _("malloc error")); 307 _gdbm_fatal (dbf, _("malloc error"));
311 return -1; 308 return -1;
312 } 309 }
@@ -432,22 +429,20 @@ _gdbm_split_bucket (GDBM_FILE dbf, int next_insert)
432int 429int
433_gdbm_write_bucket (GDBM_FILE dbf, cache_elem *ca_entry) 430_gdbm_write_bucket (GDBM_FILE dbf, cache_elem *ca_entry)
434{ 431{
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,
451 "%s: error writing bucket: %s", 446 "%s: error writing bucket: %s",
452 dbf->name, gdbm_db_strerror (dbf)); 447 dbf->name, gdbm_db_strerror (dbf));
453 _gdbm_fatal (dbf, gdbm_strerror (rc)); 448 _gdbm_fatal (dbf, gdbm_strerror (rc));
diff --git a/src/debug.c b/src/debug.c
index 00f568c..08957ed 100644
--- a/src/debug.c
+++ b/src/debug.c
@@ -133,143 +133,6 @@ gdbm_debug_datum (datum dat, char const *pfx)
133 size -= rd; 133 size -= rd;
134 buf += rd; 134 buf += rd;
135 off += rd; 135 off += rd;
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);