10 SV * filter_fetch_key ;
11 SV * filter_store_key ;
12 SV * filter_fetch_value ;
13 SV * filter_store_value ;
17 typedef GDBM_File_type * GDBM_File ;
18 typedef datum datum_key ;
19 typedef datum datum_value ;
21 #define ckFilter(arg,type,name) \
24 /* printf("filtering %s\n", name) ;*/ \
26 croak("recursion detected in %s", name) ; \
27 db->filtering = TRUE ; \
28 save_defsv = newSVsv(DEFSV) ; \
29 sv_setsv(DEFSV, arg) ; \
31 (void) perl_call_sv(db->type, G_DISCARD|G_NOARGS); \
32 sv_setsv(arg, DEFSV) ; \
33 sv_setsv(DEFSV, save_defsv) ; \
34 SvREFCNT_dec(save_defsv) ; \
35 db->filtering = FALSE ; \
36 /*printf("end of filtering %s\n", name) ;*/ \
41 #define GDBM_BLOCKSIZE 0 /* gdbm defaults to stat blocksize */
43 typedef void (*FATALFUNC)();
49 croak("GDBM_File::%s not implemented on this architecture", s);
54 /* GDBM allocates the datum with system malloc() and expects the user
55 * to free() it. So we either have to free() it immediately, or have
56 * perl free() it when it deallocates the SV, depending on whether
57 * perl uses malloc()/free() or not. */
59 output_datum(pTHX_ SV *arg, char *str, int size)
61 #if (!defined(MYMALLOC) || (defined(MYMALLOC) && defined(PERL_POLLUTE_MALLOC))) && !defined(LEAKTEST)
62 sv_usepvn(arg, str, size);
64 sv_setpvn(arg, str, size);
69 /* Versions of gdbm prior to 1.7x might not have the gdbm_sync,
70 gdbm_exists, and gdbm_setopt functions. Apparently Slackware
71 (Linux) 2.1 contains gdbm-1.5 (which dates back to 1991).
74 #define gdbm_exists(db,key) not_here("gdbm_exists")
75 #define gdbm_sync(db) (void) not_here("gdbm_sync")
76 #define gdbm_setopt(db,optflag,optval,optlen) not_here("gdbm_setopt")
79 #define PERL_constant_NOTFOUND 1
80 #define PERL_constant_NOTDEF 2
81 #define PERL_constant_ISIV 3
82 #define PERL_constant_ISNO 4
83 #define PERL_constant_ISNV 5
84 #define PERL_constant_ISPV 6
85 #define PERL_constant_ISPVN 7
86 #define PERL_constant_ISUNDEF 8
87 #define PERL_constant_ISUV 9
88 #define PERL_constant_ISYES 10
91 constant (const char *name, STRLEN len, IV *iv_return) {
92 /* Initially switch on the length of the name. */
93 /* When generated this function returned values for the list of names given
94 in this section of perl code. Rather than manually editing these functions
95 to add or remove constants, which would result in this comment and section
96 of code becoming inaccurate, we recommend that you edit this section of
97 code, and use it to regenerate a new set of constant functions which you
98 then use to replace the originals.
100 Regenerate these constant functions by feeding this entire source file to
104 use ExtUtils::Constant qw (constant_types C_constant XS_constant);
106 my $types = {map {($_, 1)} qw(IV)};
107 my @names = (qw(GDBM_CACHESIZE GDBM_FAST GDBM_FASTMODE GDBM_INSERT GDBM_NEWDB
108 GDBM_NOLOCK GDBM_READER GDBM_REPLACE GDBM_WRCREAT GDBM_WRITER));
110 print constant_types(); # macro defs
111 foreach (C_constant ("GDBM_File", 'constant', 'IV', $types, undef, 8, @names) ) {
112 print $_, "\n"; # C constant subs
114 print "#### XS Section:\n";
115 print XS_constant ("GDBM_File", $types);
121 if (memEQ(name, "GDBM_FAST", 9)) {
123 *iv_return = GDBM_FAST;
124 return PERL_constant_ISIV;
126 return PERL_constant_NOTDEF;
131 if (memEQ(name, "GDBM_NEWDB", 10)) {
133 *iv_return = GDBM_NEWDB;
134 return PERL_constant_ISIV;
136 return PERL_constant_NOTDEF;
141 /* Names all of length 11. */
142 /* GDBM_INSERT GDBM_NOLOCK GDBM_READER GDBM_WRITER */
143 /* Offset 6 gives the best switch position. */
146 if (memEQ(name, "GDBM_READER", 11)) {
149 *iv_return = GDBM_READER;
150 return PERL_constant_ISIV;
152 return PERL_constant_NOTDEF;
157 if (memEQ(name, "GDBM_INSERT", 11)) {
160 *iv_return = GDBM_INSERT;
161 return PERL_constant_ISIV;
163 return PERL_constant_NOTDEF;
168 if (memEQ(name, "GDBM_NOLOCK", 11)) {
171 *iv_return = GDBM_NOLOCK;
172 return PERL_constant_ISIV;
174 return PERL_constant_NOTDEF;
179 if (memEQ(name, "GDBM_WRITER", 11)) {
182 *iv_return = GDBM_WRITER;
183 return PERL_constant_ISIV;
185 return PERL_constant_NOTDEF;
192 /* Names all of length 12. */
193 /* GDBM_REPLACE GDBM_WRCREAT */
194 /* Offset 10 gives the best switch position. */
197 if (memEQ(name, "GDBM_WRCREAT", 12)) {
200 *iv_return = GDBM_WRCREAT;
201 return PERL_constant_ISIV;
203 return PERL_constant_NOTDEF;
208 if (memEQ(name, "GDBM_REPLACE", 12)) {
211 *iv_return = GDBM_REPLACE;
212 return PERL_constant_ISIV;
214 return PERL_constant_NOTDEF;
221 if (memEQ(name, "GDBM_FASTMODE", 13)) {
223 *iv_return = GDBM_FASTMODE;
224 return PERL_constant_ISIV;
226 return PERL_constant_NOTDEF;
231 if (memEQ(name, "GDBM_CACHESIZE", 14)) {
232 #ifdef GDBM_CACHESIZE
233 *iv_return = GDBM_CACHESIZE;
234 return PERL_constant_ISIV;
236 return PERL_constant_NOTDEF;
241 return PERL_constant_NOTFOUND;
244 MODULE = GDBM_File PACKAGE = GDBM_File PREFIX = gdbm_
253 /* NV nv; Uncomment this if you need to return NVs */
254 /* const char *pv; Uncomment this if you need to return PVs */
257 const char * s = SvPV(sv, len);
259 /* Change this to constant(s, len, &iv, &nv);
260 if you need to return both NVs and IVs */
261 type = constant(s, len, &iv);
262 /* Return 1 or 2 items. First is error message, or undef if no error.
263 Second, if present, is found value */
265 case PERL_constant_NOTFOUND:
266 sv = sv_2mortal(newSVpvf("%s is not a valid GDBM_File macro", s));
269 case PERL_constant_NOTDEF:
270 sv = sv_2mortal(newSVpvf(
271 "Your vendor has not defined GDBM_File macro %s, used", s));
274 case PERL_constant_ISIV:
280 sv = sv_2mortal(newSVpvf(
281 "Unexpected return type %d while processing GDBM_File macro %s, used",
288 gdbm_TIEHASH(dbtype, name, read_write, mode, fatal_func = (FATALFUNC)croak)
299 if ((dbp = gdbm_open(name, GDBM_BLOCKSIZE, read_write, mode, fatal_func))) {
300 RETVAL = (GDBM_File)safemalloc(sizeof(GDBM_File_type)) ;
301 Zero(RETVAL, 1, GDBM_File_type) ;
310 #define gdbm_close(db) gdbm_close(db->dbp)
323 #define gdbm_FETCH(db,key) gdbm_fetch(db->dbp,key)
329 #define gdbm_STORE(db,key,value,flags) gdbm_store(db->dbp,key,value,flags)
331 gdbm_STORE(db, key, value, flags = GDBM_REPLACE)
338 if (RETVAL < 0 && errno == EPERM)
339 croak("No write permission to gdbm file");
340 croak("gdbm store returned %d, errno %d, key \"%.*s\"",
341 RETVAL,errno,key.dsize,key.dptr);
344 #define gdbm_DELETE(db,key) gdbm_delete(db->dbp,key)
350 #define gdbm_FIRSTKEY(db) gdbm_firstkey(db->dbp)
355 #define gdbm_NEXTKEY(db,key) gdbm_nextkey(db->dbp,key)
357 gdbm_NEXTKEY(db, key)
361 #define gdbm_reorganize(db) gdbm_reorganize(db->dbp)
367 #define gdbm_sync(db) gdbm_sync(db->dbp)
372 #define gdbm_EXISTS(db,key) gdbm_exists(db->dbp,key)
378 #define gdbm_setopt(db,optflag, optval, optlen) gdbm_setopt(db->dbp,optflag, optval, optlen)
380 gdbm_setopt (db, optflag, optval, optlen)
387 #define setFilter(type) \
390 RETVAL = sv_mortalcopy(db->type) ; \
392 if (db->type && (code == &PL_sv_undef)) { \
393 SvREFCNT_dec(db->type) ; \
398 sv_setsv(db->type, code) ; \
400 db->type = newSVsv(code) ; \
407 filter_fetch_key(db, code)
410 SV * RETVAL = &PL_sv_undef ;
412 setFilter(filter_fetch_key) ;
415 filter_store_key(db, code)
418 SV * RETVAL = &PL_sv_undef ;
420 setFilter(filter_store_key) ;
423 filter_fetch_value(db, code)
426 SV * RETVAL = &PL_sv_undef ;
428 setFilter(filter_fetch_value) ;
431 filter_store_value(db, code)
434 SV * RETVAL = &PL_sv_undef ;
436 setFilter(filter_store_value) ;