aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2018-07-03 15:01:55 +0300
committerSergey Poznyakoff <gray@gnu.org>2018-07-03 15:01:55 +0300
commit3a1d5f8bdc29803fb7a6713515f2c0c332e379fc (patch)
treef95c9240257bec56094b938541c80aa7b61c62f3
downloadGDBM_File-3a1d5f8bdc29803fb7a6713515f2c0c332e379fc.tar.gz
GDBM_File-3a1d5f8bdc29803fb7a6713515f2c0c332e379fc.tar.bz2
Perl 5.28.0
-rw-r--r--GDBM_File.pm80
-rw-r--r--GDBM_File.xs203
-rw-r--r--Makefile.PL20
-rw-r--r--hints/sco.pl2
-rw-r--r--t/fatal.t49
-rw-r--r--t/gdbm.t6
-rw-r--r--typemap56
7 files changed, 416 insertions, 0 deletions
diff --git a/GDBM_File.pm b/GDBM_File.pm
new file mode 100644
index 0000000..a33b8b5
--- /dev/null
+++ b/GDBM_File.pm
@@ -0,0 +1,80 @@
1# GDBM_File.pm -- Perl 5 interface to GNU gdbm library.
2
3=head1 NAME
4
5GDBM_File - Perl5 access to the gdbm library.
6
7=head1 SYNOPSIS
8
9 use GDBM_File ;
10 tie %hash, 'GDBM_File', $filename, &GDBM_WRCREAT, 0640;
11 # Use the %hash array.
12 untie %hash ;
13
14=head1 DESCRIPTION
15
16B<GDBM_File> is a module which allows Perl programs to make use of the
17facilities provided by the GNU gdbm library. If you intend to use this
18module you should really have a copy of the gdbm manualpage at hand.
19
20Most of the libgdbm.a functions are available through the GDBM_File
21interface.
22
23Unlike Perl's built-in hashes, it is not safe to C<delete> the current
24item from a GDBM_File tied hash while iterating over it with C<each>.
25This is a limitation of the gdbm library.
26
27=head1 AVAILABILITY
28
29gdbm is available from any GNU archive. The master site is
30C<ftp.gnu.org>, but you are strongly urged to use one of the many
31mirrors. You can obtain a list of mirror sites from
32L<http://www.gnu.org/order/ftp.html>.
33
34=head1 BUGS
35
36The available functions and the gdbm/perl interface need to be documented.
37
38The GDBM error number and error message interface needs to be added.
39
40=head1 SEE ALSO
41
42L<perl(1)>, L<DB_File(3)>, L<perldbmfilter>.
43
44=cut
45
46package GDBM_File;
47
48use strict;
49use warnings;
50our($VERSION, @ISA, @EXPORT);
51
52require Carp;
53require Tie::Hash;
54require Exporter;
55require XSLoader;
56@ISA = qw(Tie::Hash Exporter);
57@EXPORT = qw(
58 GDBM_CACHESIZE
59 GDBM_CENTFREE
60 GDBM_COALESCEBLKS
61 GDBM_FAST
62 GDBM_FASTMODE
63 GDBM_INSERT
64 GDBM_NEWDB
65 GDBM_NOLOCK
66 GDBM_OPENMASK
67 GDBM_READER
68 GDBM_REPLACE
69 GDBM_SYNC
70 GDBM_SYNCMODE
71 GDBM_WRCREAT
72 GDBM_WRITER
73);
74
75# This module isn't dual life, so no need for dev version numbers.
76$VERSION = '1.17';
77
78XSLoader::load();
79
801;
diff --git a/GDBM_File.xs b/GDBM_File.xs
new file mode 100644
index 0000000..7f91049
--- /dev/null
+++ b/GDBM_File.xs
@@ -0,0 +1,203 @@
1#define PERL_NO_GET_CONTEXT
2
3#include "EXTERN.h"
4#include "perl.h"
5#include "XSUB.h"
6
7#include <gdbm.h>
8#include <fcntl.h>
9
10#define fetch_key 0
11#define store_key 1
12#define fetch_value 2
13#define store_value 3
14
15typedef struct {
16 GDBM_FILE dbp ;
17 SV * filter[4];
18 int filtering ;
19 } GDBM_File_type;
20
21typedef GDBM_File_type * GDBM_File ;
22typedef datum datum_key ;
23typedef datum datum_value ;
24typedef datum datum_key_copy;
25
26#if defined(GDBM_VERSION_MAJOR) && defined(GDBM_VERSION_MINOR) \
27 && GDBM_VERSION_MAJOR > 1 || \
28 (GDBM_VERSION_MAJOR == 1 && GDBM_VERSION_MINOR >= 9)
29typedef void (*FATALFUNC)(const char *);
30#else
31typedef void (*FATALFUNC)();
32#endif
33
34#ifndef GDBM_FAST
35static int
36not_here(char *s)
37{
38 croak("GDBM_File::%s not implemented on this architecture", s);
39 return -1;
40}
41#endif
42
43/* GDBM allocates the datum with system malloc() and expects the user
44 * to free() it. So we either have to free() it immediately, or have
45 * perl free() it when it deallocates the SV, depending on whether
46 * perl uses malloc()/free() or not. */
47static void
48output_datum(pTHX_ SV *arg, char *str, int size)
49{
50 sv_setpvn(arg, str, size);
51# undef free
52 free(str);
53}
54
55/* Versions of gdbm prior to 1.7x might not have the gdbm_sync,
56 gdbm_exists, and gdbm_setopt functions. Apparently Slackware
57 (Linux) 2.1 contains gdbm-1.5 (which dates back to 1991).
58*/
59#ifndef GDBM_FAST
60#define gdbm_exists(db,key) not_here("gdbm_exists")
61#define gdbm_sync(db) (void) not_here("gdbm_sync")
62#define gdbm_setopt(db,optflag,optval,optlen) not_here("gdbm_setopt")
63#endif
64
65static void
66croak_string(const char *message) {
67 Perl_croak_nocontext("%s", message);
68}
69
70#include "const-c.inc"
71
72MODULE = GDBM_File PACKAGE = GDBM_File PREFIX = gdbm_
73
74INCLUDE: const-xs.inc
75
76GDBM_File
77gdbm_TIEHASH(dbtype, name, read_write, mode)
78 char * dbtype
79 char * name
80 int read_write
81 int mode
82 PREINIT:
83 GDBM_FILE dbp;
84 CODE:
85 dbp = gdbm_open(name, 0, read_write, mode, (FATALFUNC)croak_string);
86 if (!dbp && gdbm_errno == GDBM_BLOCK_SIZE_ERROR) {
87 /*
88 * By specifying a block size of 0 above, we asked gdbm to
89 * default to the filesystem's block size. That's usually the
90 * right size to choose. But some versions of gdbm require
91 * a power-of-two block size, and some unusual filesystems
92 * or devices have a non-power-of-two size that cause this
93 * defaulting to fail. In that case, force an acceptable
94 * block size.
95 */
96 dbp = gdbm_open(name, 4096, read_write, mode,
97 (FATALFUNC)croak_string);
98 }
99 if (dbp) {
100 RETVAL = (GDBM_File)safecalloc(1, sizeof(GDBM_File_type));
101 RETVAL->dbp = dbp;
102 } else {
103 RETVAL = NULL;
104 }
105 OUTPUT:
106 RETVAL
107
108
109#define gdbm_close(db) gdbm_close(db->dbp)
110void
111gdbm_close(db)
112 GDBM_File db
113 CLEANUP:
114
115void
116gdbm_DESTROY(db)
117 GDBM_File db
118 PREINIT:
119 int i = store_value;
120 CODE:
121 gdbm_close(db);
122 do {
123 if (db->filter[i])
124 SvREFCNT_dec(db->filter[i]);
125 } while (i-- > 0);
126 safefree(db);
127
128#define gdbm_FETCH(db,key) gdbm_fetch(db->dbp,key)
129datum_value
130gdbm_FETCH(db, key)
131 GDBM_File db
132 datum_key_copy key
133
134#define gdbm_STORE(db,key,value,flags) gdbm_store(db->dbp,key,value,flags)
135int
136gdbm_STORE(db, key, value, flags = GDBM_REPLACE)
137 GDBM_File db
138 datum_key key
139 datum_value value
140 int flags
141 CLEANUP:
142 if (RETVAL) {
143 if (RETVAL < 0 && errno == EPERM)
144 croak("No write permission to gdbm file");
145 croak("gdbm store returned %d, errno %d, key \"%.*s\"",
146 RETVAL,errno,key.dsize,key.dptr);
147 }
148
149#define gdbm_DELETE(db,key) gdbm_delete(db->dbp,key)
150int
151gdbm_DELETE(db, key)