1 |
Around 2002, I started working on a project that involved a few simple |
2 |
database tables, and I wanted it |
3 |
simple, so I used python and the gdbm module. Since then, all has been |
4 |
well. Now I find that not only |
5 |
do the gdbm modules of python and perl reject my files, but so does a C |
6 |
program that uses the distributed |
7 |
libgdbm. |
8 |
|
9 |
Okay, so you think I broke my files somehow. I was afraid that was true, so |
10 |
I used the gdbm source |
11 |
I had in distfiles, configured it with default setup but did not install |
12 |
it. Instead I compiled it with my |
13 |
C test program, and set out to find the problem in the data, more or less |
14 |
expecting |
15 |
to spend a long time in the debugger. But lo and behold, it worked just |
16 |
fine. Now I'm suspecting that |
17 |
the ebuild does something (Large File support?) to the GDBM that it didn't |
18 |
used to do. |
19 |
|
20 |
I did not know when I started how much configuration information I was going |
21 |
to need, and so there's |
22 |
a configuation database. As it happens, I never put more than one record in |
23 |
it, so it's perfect for |
24 |
simple testing. The database is called dbhex.control, and the single record |
25 |
key is "control". I've |
26 |
attached it. |
27 |
|
28 |
I used this Makefile, with no targets or rules, just to get the flags I |
29 |
want: I have my testfile 'testgdbm.c' in |
30 |
the same directory with the makefile, and a gdbm-1.8.3 directory. |
31 |
|
32 |
I make testgdbm, run "testgdbm dbhex.control" and get exactly what I |
33 |
should. If I link against the |
34 |
Gentoo gdbm distribution, I get error 22 "invalid argument". Not knowing |
35 |
much about ebuilds, I'm not sure |
36 |
how to tell what has changed. |
37 |
|
38 |
Can anybody help me with: |
39 |
1) why it fails now with Gentoo tools. |
40 |
2) the best way to get it working again, preferably with both python and |
41 |
C. I expect there's either |
42 |
a compatibility flag, or I may need to do a file conversion. Overall, |
43 |
my databases run to about |
44 |
3 gigabytes, so it's doable either way. |
45 |
|
46 |
Thanks in advance for any help. |
47 |
|
48 |
# Makefile for tests |
49 |
CC=gcc |
50 |
CFLAGS=-Wall -g -m32 -ansi |
51 |
LDFLAGS=-m32 gdbm-1.8.3/global.o gdbm-1.8.3/gdbmopen.o |
52 |
gdbm-1.8.3/gdbmerrno.o gdbm-1.8.3/gdbmclose.o gdbm-1.8.3/update.o |
53 |
gdbm-1.8.3/falloc.o gdbm-1.8.3/bucket.o gdbm-1.8.3/gdbmfetch.o |
54 |
gdbm-1.8.3/findkey.o gdbm-1.8.3/version.o gdbm-1.8.3/gdbmseq.o |
55 |
gdbm-1.8.3/hash.o |
56 |
|
57 |
My test file: |
58 |
|
59 |
/** |
60 |
* @file |
61 |
* |
62 |
* Program to test minimal functionality of the gdbm library on a known gdbm |
63 |
file. |
64 |
* |
65 |
* Last Modified: Mon Aug 9 12:01:32 PDT 2010</pre> |
66 |
* @author Kevin O'Gorman |
67 |
*/ |
68 |
|
69 |
#include <unistd.h> |
70 |
#include <stdlib.h> |
71 |
#include <stdio.h> |
72 |
#include <gdbm.h> |
73 |
#include <string.h> |
74 |
#include <errno.h> |
75 |
|
76 |
void |
77 |
fatal(void) { |
78 |
fprintf(stderr, "Fatal function called\n"); |
79 |
fprintf(stderr, "Errno is %d\n", errno); |
80 |
exit(EXIT_FAILURE); |
81 |
} |
82 |
|
83 |
/** The main thing. |
84 |
* @param argc the number of tokens on the input line. |
85 |
* @param argv an array of tokens. |
86 |
* @return 0 on success, 1-255 on failure |
87 |
*/ |
88 |
int |
89 |
main(int argc, char *argv[]) |
90 |
{ |
91 |
datum key; |
92 |
datum value; |
93 |
datum nextkey; |
94 |
char longbucket[4096]; |
95 |
|
96 |
printf("Running with GDBM: %s\n", gdbm_version); |
97 |
if (argc !=2) { |
98 |
fprintf(stderr, "Usage:\n %s filename\n", argv[0]); |
99 |
exit(EXIT_FAILURE); |
100 |
} |
101 |
|
102 |
errno = 0; |
103 |
GDBM_FILE control = gdbm_open(argv[1], 1024, GDBM_READER, 0666, fatal); |
104 |
if (control == NULL) { |
105 |
perror("gdbm"); |
106 |
fprintf(stderr, "Open returned NULL\n"); |
107 |
fprintf(stderr, "Errno is %d\n", errno); |
108 |
exit(EXIT_FAILURE); |
109 |
} |
110 |
printf("is open\n"); |
111 |
|
112 |
key = gdbm_firstkey(control); |
113 |
while (key.dptr) { |
114 |
memcpy(longbucket, key.dptr, key.dsize); |
115 |
longbucket[key.dsize] = '\0'; |
116 |
printf("Key: %s", longbucket); |
117 |
value = gdbm_fetch(control, key); |
118 |
memcpy(longbucket, value.dptr, value.dsize); |
119 |
longbucket[value.dsize] = '\0'; |
120 |
printf(", val: \"%s\"\n", longbucket); |
121 |
free(value.dptr); |
122 |
nextkey = gdbm_nextkey(control, key); |
123 |
free(key.dptr); |
124 |
key = nextkey; |
125 |
} |
126 |
|
127 |
gdbm_close(control); |
128 |
printf("That's all, folks...\n"); |
129 |
|
130 |
return EXIT_SUCCESS; |
131 |
} |
132 |
|
133 |
/* vim: set et ai sts=2 sw=2: */ |
134 |
|
135 |
|
136 |
-- |
137 |
Kevin O'Gorman, PhD |