aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2018-07-03 19:48:32 +0300
committerSergey Poznyakoff <gray@gnu.org>2018-07-03 22:58:32 +0300
commitf90e8d187d3ca23299c4dad447a4eba0560f84ad (patch)
treeaedc64b78d357efd4478eb41df80d38ea6ad1c35
parent7a1740a11031ad380e0d3c488310c389e9ea07f6 (diff)
downloadGDBM_File-f90e8d187d3ca23299c4dad447a4eba0560f84ad.tar.gz
GDBM_File-f90e8d187d3ca23299c4dad447a4eba0560f84ad.tar.bz2
Implement GDBM_versionHEADmaster
-rw-r--r--GDBM_File.pm92
-rw-r--r--GDBM_File.xs91
2 files changed, 172 insertions, 11 deletions
diff --git a/GDBM_File.pm b/GDBM_File.pm
index b04dd9f..ab25906 100644
--- a/GDBM_File.pm
+++ b/GDBM_File.pm
@@ -6,9 +6,47 @@ GDBM_File - Perl5 access to the gdbm library.
=head1 SYNOPSIS
- use GDBM_File ;
- tie %hash, 'GDBM_File', $filename, &GDBM_WRCREAT, 0640;
+ use GDBM_File;
+ [$db =] tie %hash, 'GDBM_File', $filename, &GDBM_WRCREAT, 0640;
# Use the %hash array.
+
+ $e = $db->errno;
+ $e = $db->syserrno;
+ $str = $db->strerror;
+ $bool = $db->needs_recovery;
+
+ $db->clear_error;
+
+ $db->reorganize;
+ $db->sync;
+
+ $n = $db->count;
+
+ $n = $db->flags;
+
+ $str = $db->dbname;
+
+ $db->cache_size;
+ $db->cache_size($newsize);
+
+ $n = $db->block_size;
+
+ $bool = $db->sync_mode;
+ $db->sync_mode($bool);
+
+ $bool = $db->centfree;
+ $db->centfree($bool);
+
+ $bool = $db->coalesce;
+ $db->coalesce($bool);
+
+ $bool = $db->mmap;
+
+ $size = $db->mmapsize;
+ $db->mmapsize($newsize);
+
+ $db->recover(%args);
+
untie %hash ;
=head1 DESCRIPTION
@@ -24,6 +62,50 @@ Unlike Perl's built-in hashes, it is not safe to C<delete> the current
item from a GDBM_File tied hash while iterating over it with C<each>.
This is a limitation of the gdbm library.
+=head1 STATIC METHODS
+
+=head2 GDBM_version
+
+ $str = GDBM_File->GDBM_version;
+ @ar = GDBM_File->GDBM_version;
+
+Returns the version number of the underlying B<libgdbm> library. In scalar
+context, returns the library version formatted as string:
+
+ MINOR.MAJOR[.PATCH][ (GUESS)]
+
+where I<MINOR>, I<MAJOR>, and I<PATCH> are version numbers, and I<GUESS> is
+a guess level (see below).
+
+In list context, returns a list:
+
+ ( MINOR, MAJOR, PATCH [, GUESS] )
+
+The I<GUESS> component is present only if B<libgdbm> version is 1.8.3 or
+earlier. This is because earlier releases of B<libgdbm> did not include
+information about their version and the B<GDBM_File> module has to implement
+certain guesswork in order to determine it. I<GUESS> is a textual description
+in string context, and a positive number indicating how rough the guess is
+in list context. Possible values are:
+
+=over 4
+
+=item 1 - exact guess
+
+The major and minor version numbers are guaranteed to be correct. The actual
+patchlevel is most probably guessed right, but can be 1-2 less than indicated.
+
+=item 2 - approximate
+
+The major and minor number are guaranteed to be correct. The patchlevel is
+set to the upper bound.
+
+=item 3 - rough guess
+
+The version is guaranteed to be not newer than B<I<MAJOR>.I<MINOR>>.
+
+=back
+
=head1 METHODS
=head2 close
@@ -231,11 +313,11 @@ C<ftp.gnu.org>, but you are strongly urged to use one of the many
mirrors. You can obtain a list of mirror sites from
L<http://www.gnu.org/order/ftp.html>.
-=head1 BUGS
-
=head1 SEE ALSO
-L<perl(1)>, L<DB_File(3)>, L<perldbmfilter>.
+L<perl(1)>, L<DB_File(3)>, L<perldbmfilter>,
+L<gdbm(3)>,
+L<https://www.gnu.org.ua/software/gdbm/manual.html>.
=cut
diff --git a/GDBM_File.xs b/GDBM_File.xs
index 669cb8d..ef7bde5 100644
--- a/GDBM_File.xs
+++ b/GDBM_File.xs
@@ -51,9 +51,52 @@ char const *opt_names[] = {
"GDBM_File::mmapsize"
};
-#ifndef GDBM_VERSION_MAJOR
-# define GDBM_VERSION_MAJOR 0
-# define GDBM_VERSION_MINOR 0
+#ifdef GDBM_VERSION_MAJOR
+# define GDBM_VERSION_GUESS 0
+#else
+/* Try educated guess
+ * The value of GDBM_VERSION_GUESS indicates how rough the guess is:
+ * 1 - Precise; based on the CVS logs and existing archives
+ * 2 - Moderate. The major and minor number are correct. The patchlevel
+ * is set to the upper bound.
+ * 3 - Rough; The version is guaranteed to be not newer than major.minor.
+ */
+# if defined(GDBM_SYNCMODE)
+/* CHANGES from 1.7.3 to 1.8
+ * 1. Added GDBM_CENTFREE functionality and option.
+ */
+# define GDBM_VERSION_MAJOR 1
+# define GDBM_VERSION_MINOR 8
+# define GDBM_VERSION_PATCH 3
+# define GDBM_VERSION_GUESS 1
+# elif defined(GDBM_FASTMODE)
+/* CHANGES from 1.7.2 to 1.7.3
+ * 1. Fixed a couple of last minute problems. (Namely, no autoconf.h in
+ * version.c, and no GDBM_FASTMODE in gdbm.h!)
+ */
+# define GDBM_VERSION_MAJOR 1
+# define GDBM_VERSION_MINOR 7
+# define GDBM_VERSION_PATCH 3
+# define GDBM_VERSION_GUESS 1
+# elif defined(GDBM_FAST)
+/* From CVS logs:
+ * Mon May 17 12:32:02 1993 Phil Nelson (phil at cs.wwu.edu)
+ *
+ * * gdbm.proto: Added GDBM_FAST to the read_write flags.
+ */
+# define GDBM_VERSION_MAJOR 1
+# define GDBM_VERSION_MINOR 7
+# define GDBM_VERSION_PATCH 2
+# define GDBM_VERSION_GUESS 2
+# else
+# define GDBM_VERSION_MAJOR 1
+# define GDBM_VERSION_MINOR 6
+# define GDBM_VERSION_GUESS 3
+# endif
+#endif
+
+#ifndef GDBM_VERSION_PATCH
+# define GDBM_VERSION_PATCH 0
#endif
/* The use of fatal_func argument to gdbm_open is deprecated since 1.13 */
@@ -175,6 +218,41 @@ MODULE = GDBM_File PACKAGE = GDBM_File PREFIX = gdbm_
INCLUDE: const-xs.inc
+void
+gdbm_GDBM_version(package)
+ char *package;
+ PPCODE:
+ I32 gimme = GIMME_V;
+ if (gimme == G_VOID) {
+ /* nothing */;
+ } else if (gimme == G_SCALAR) {
+ static char const *guess[] = {
+ "",
+ " (exact guess)",
+ " (approximate)",
+ " (rough guess)"
+ };
+ if (GDBM_VERSION_PATCH > 0) {
+ XPUSHs(sv_2mortal(newSVpvf("%d.%d.%d%s",
+ GDBM_VERSION_MAJOR,
+ GDBM_VERSION_MINOR,
+ GDBM_VERSION_PATCH,
+ guess[GDBM_VERSION_GUESS])));
+ } else {
+ XPUSHs(sv_2mortal(newSVpvf("%d.%d%s",
+ GDBM_VERSION_MAJOR,
+ GDBM_VERSION_MINOR,
+ guess[GDBM_VERSION_GUESS])));
+ }
+ } else {
+ XPUSHs(sv_2mortal(newSVuv(GDBM_VERSION_MAJOR)));
+ XPUSHs(sv_2mortal(newSVuv(GDBM_VERSION_MINOR)));
+ XPUSHs(sv_2mortal(newSVuv(GDBM_VERSION_PATCH)));
+ if (GDBM_VERSION_GUESS > 0) {
+ XPUSHs(sv_2mortal(newSVuv(GDBM_VERSION_GUESS)));
+ }
+ }
+
GDBM_File
gdbm_TIEHASH(dbtype, name, read_write, mode)
char * dbtype
@@ -747,10 +825,11 @@ filter_fetch_key(db, code)
GDBM_File db
SV * code
SV * RETVAL = &PL_sv_undef ;
- ALIAS:
+ ALIAS:
GDBM_File::filter_fetch_key = fetch_key
GDBM_File::filter_store_key = store_key
GDBM_File::filter_fetch_value = fetch_value
GDBM_File::filter_store_value = store_value
- CODE:
- DBM_setFilter(db->filter[ix], code);
+ CODE:
+ DBM_setFilter(db->filter[ix], code);
+

Return to:

Send suggestions and report system problems to the System administrator.