]> birchwood-abbey.net Git - mit-scheme.git/commitdiff
gdbm: Document the undocumented.
authorMatt Birkholz <matt@birchwood-abbey.net>
Sat, 1 Oct 2022 20:16:33 +0000 (14:16 -0600)
committerMatt Birkholz <matt@birchwood-abbey.net>
Sat, 1 Oct 2022 20:16:33 +0000 (14:16 -0600)
Export the documented gdbm_sync, gdbm_syncmode and gdbm_nolock flags.
Mention the ability to use symbols for flag arguments, rather than
constants like these.

src/gdbm/README
src/gdbm/gdbm.pkg
src/gdbm/gdbm.scm
src/gdbm/gdbm.texi

index 53a6e92272fe4c0780593210ef9bebed9be437db..c12da83416e1cc92d716ff926c776548f3275fc3 100644 (file)
@@ -27,26 +27,6 @@ creating a short optiondb file.
        ~/.mit-scheme-x86-64:/usr/local/lib/mit-scheme-x86-64
     make install
 
-To use:
-
-    (load-option 'gdbm)
-    (import-gdbm)
-
-Import-gdbm will modify the REPL's current environment by adding
-bindings linked to the plugin's exports.  They are not exported to the
-global environment because they would conflict with the deprecated
-exports from (runtime gdbm).
-
-To import into a CREF package set, add this to your .pkg file:
-
-    (global-definitions gdbm/)
-
-    (define-package (your package name)
-      (parent (your package parent))
-      (import (gdbm)
-              gdbm-open
-              ...))
-
 Please see the manual for API details.  An Info version should have
 been installed along with the plugin.  If you have a texlive or
 similar TeX environment installed, then HTML and PDF versions of the
index f4b174e9f0e899073f0117c7ed53e5aef8d2f808..72c32f6418b4a4d775be7e33a1b16d19e2d6316e 100644 (file)
@@ -55,8 +55,11 @@ USA.
          ;;gdbm_fastmode obsolete
          gdbm_insert
          gdbm_newdb
+         gdbm_nolock
          gdbm_reader
          gdbm_replace
+         gdbm_sync
+         gdbm_syncmode
          gdbm_wrcreat
          gdbm_writer))
 
index 3ae6971a10d2c2adb7d2fa1a5743d7d6209067eb..9d88424f3d2df44b992e6516056e4886a46e2c2e 100644 (file)
@@ -50,7 +50,6 @@ USA.
                gdbm-version
                gdbm_cachesize
                gdbm_fast
-               ;;gdbm_fastmode obsolete
                gdbm_insert
                gdbm_newdb
                gdbm_reader
@@ -84,13 +83,13 @@ USA.
       (bytevector-length bytes)
       (string-length bytes)))
 
-;; Parameters to gdbm_open for readers, writers, and writers who can
-;; create the database.
-(define gdbm_reader  (C-enum "GDBM_READER"))   ;A reader.
-(define gdbm_writer  (C-enum "GDBM_WRITER"))   ;A writer.
-(define gdbm_wrcreat (C-enum "GDBM_WRCREAT"))  ;A writer.  Create the db if needed.
-(define gdbm_newdb   (C-enum "GDBM_NEWDB"))    ;A writer.  Always create a new db.
-(define gdbm_fast    (C-enum "GDBM_FAST"))     ;Write fast! => No fsyncs.
+(define gdbm_reader  (C-enum "GDBM_READER"))
+(define gdbm_writer  (C-enum "GDBM_WRITER"))
+(define gdbm_wrcreat (C-enum "GDBM_WRCREAT"))
+(define gdbm_newdb   (C-enum "GDBM_NEWDB"))
+(define gdbm_fast    (C-enum "GDBM_FAST"))
+(define gdbm_sync    (C-enum "GDBM_SYNC"))
+(define gdbm_nolock  (C-enum "GDBM_NOLOCK"))
 
 (define (gdbm-open filename block-size flags mode)
   (guarantee integer? block-size 'gdbm-open)
@@ -119,6 +118,8 @@ USA.
       ((wrcreat) (C-enum "GDBM_WRCREAT"))
       ((newdb) (C-enum "GDBM_NEWDB"))
       ((fast) (C-enum "GDBM_FAST"))
+      ((sync) (C-enum "GDBM_SYNC"))
+      ((nolock) (C-enum "GDBM_NOLOCK"))
       (else (error:wrong-type-argument flags "gdbm-open flags" 'gdbm-open))))
   (cond ((integer? flags) flags)
        ((symbol? flags) (flag->number flags))
@@ -139,10 +140,8 @@ USA.
             (remove-open-gdbf-cleanup gdbf))))
      unspecific)))
 
-;; Parameters to gdbm_store for simple insertion or replacement in the
-;; case that the key is already in the database.
-(define gdbm_insert  (C-enum "GDBM_INSERT"))   ;Never replace old data.
-(define gdbm_replace (C-enum "GDBM_REPLACE"))  ;Always replace old data.
+(define gdbm_insert  (C-enum "GDBM_INSERT"))
+(define gdbm_replace (C-enum "GDBM_REPLACE"))
 
 (define (gdbm-store gdbf key content flag)
   (guarantee-gdbf gdbf 'gdbm-store)
@@ -215,9 +214,6 @@ USA.
      (gdbf-args-get-key args))))
 
 (define (gdbm-nextkey gdbf key)
-  ;; Returns #f if key is not (or no longer) in the database.  Use
-  ;; gdbm-keys to read a complete list despite deletes.  Gdbm-keys
-  ;; also avoids copying the keys back for gdbm_nextkey.
   (guarantee-gdbf gdbf 'gdbm-nextkey)
   (guarantee-nonnull-string key 'gdbm-nextkey)
   (with-gdbf-locked-open
@@ -251,9 +247,8 @@ USA.
   (guarantee fixnum? errno 'strerror)
   (c-peek-cstring (C-call "strerror" (make-alien '(* char)) errno)))
 
-;; Parameters to gdbm_setopt, specifing the type of operation to perform.
-(define gdbm_cachesize (C-enum "GDBM_CACHESIZE"))      ;Set the cache size.
-(define gdbm_syncmode  (C-enum "GDBM_SYNCMODE"))       ;Toggle fast mode.
+(define gdbm_cachesize (C-enum "GDBM_CACHESIZE"))
+(define gdbm_syncmode  (C-enum "GDBM_SYNCMODE"))
 
 (define (gdbm-setopt gdbf opt val)
   (guarantee-gdbf gdbf 'gdbm-setopt)
@@ -297,7 +292,7 @@ USA.
   ;; helper struct assumes there are no callbacks possible during gdbm
   ;; operations (via which this procedure could be called multiple
   ;; times [requiring a malloc per operation]).  The per-gdbf lock is
-  ;; probably already be poised to deadlock any thread trying it.
+  ;; probably already poised to deadlock any thread trying it.
   (args #f read-only #t)
   (mutex #f read-only #t)
   (filename #f read-only #t))
index 86d7218d06585ff62c46416ea4a463562f1db6fe..b7827350640e632f211fe8c0cb4684d88d4c30f9 100644 (file)
@@ -69,7 +69,6 @@ by the Free Software Foundation.
 
 Functions:
 
-* List::                      The exported bindings.
 * Open::                       Opening the database.
 * Close::                      Closing the database.
 * Store::                      Inserting and replacing records in the database.
@@ -114,59 +113,55 @@ to block any thread attempting to access the database while an
 operation is in progress.  No file locks are used by gdbm or the
 Scheme wrapper to ensure exclusive access by a Scheme writer.
 
-@node List
-@chapter The exported bindings.
-
-The following is a quick list of the procedures provided by the plugin.
+The plugin creates its bindings in the @code{(gdbm)} package.  These
+can be imported into @code{(your package)} by adding a
+@code{global-definitions} declaration to your @file{.pkg} file, as
+shown below.
 
 @example
-         gdbm-open
-         gdbm-close
-         gdbm-store
-         gdbm-fetch
-         gdbm-delete
-         gdbm-firstkey
-         gdbm-nextkey
-         gdbm-reorganize
-         gdbm-sync
-         gdbm-exists?
-         gdbm-setopt
-@end example
+    (global-definitions gdbm/)
 
-Neither @code{gdbm_errno} nor @code{gdbm_strerror} are exposed because
-the plugin automatically tests and calls them to detect errors and
-convert codes into strings.  @code{gdbm_fdesc} is also not exposed,
-treated as an implementation detail the plugin should probably hide,
-used by tricky code that cooperates with multiple file locking
-libraries.
+    (define-package (your package)
+      (parent (your package parent))
+      (import (gdbm)
+              gdbm-open
+              ...))
+@end example
 
-There is one global variable, @code{gdbm-version}, which is
-initialized from the library's @code{gdbm_version} string.
+For interactive use, enter:
 
-And several constants:
 @example
-         gdbm_cachesize
-          gdbm_fast
-          gdbm_insert
-          gdbm_newdb
-          gdbm_reader
-          gdbm_replace
-          gdbm_wrcreat
-          gdbm_writer
-@end example
-
-You can load these bindings into your global environment with the
-following expression.
-@smallexample
     (load-option 'gdbm)
-@end smallexample
+    (import-gdbm)
+@end example
 
-And you can include these bindings in your package description
-(@file{.pkg}) file with the following expression.
-@smallexample
-    (global-definitions gdbm/)
-@end smallexample
+@deffn Procedure import-gdbm
+Define the ``exported'' names in the current REPL environment for
+interactive use.  (The plugin's bindings are not linked to the
+deprecated bindings in the global environment.)
+@end deffn
 
+The plugin implements the same API as that exported from the
+@code{(runtime gdbm)} package, and is in fact the same code in a new
+wrapper.  The plugin is automatically loaded when the deprecated
+@code{gdbm-available?} procedure is called.  Until then the other
+deprecated bindings in @code{(runtime gdbm)} (and @code{()}) are
+unassigned.  After the plugin is loaded, the bindings can be used as
+before.
+
+The GDBM library's @code{gdbm_errno} and @code{gdbm_strerror}
+variables are not exposed in the API.  The plugin automatically tests
+and calls them to detect errors and convert codes into strings.  The
+@code{gdbm_fdesc} function is also not exposed, but treated as an
+implementation detail the plugin should probably hide, perhaps only
+used by tricky code cooperating with multiple file locking libraries.
+
+There is one global variable, @code{gdbm-version}.
+
+@deffn Variable gdbm-version
+The value of this variable is initialized from the library's
+@code{gdbm_version} string.
+@end deffn
 
 @node Open
 @chapter Opening the database.
@@ -191,19 +186,26 @@ if the file has been previously initialized. The minimum size is 512.
 If the value is less than 512, the file system blocksize is used, otherwise the
 value of @var{block-size} is used.
 @item flags
-If @var{flags} is @code{gdbm_reader}, the user wants to just read the
-database and any call to @code{gdbm-store} or @code{gdbm-delete} will fail.
-Many readers can access the database at the same time. If @var{flags} is
-@code{gdbm_writer}, the user wants both read and write access to the database
-and requires exclusive access. If @var{flags} is @code{gdbm_wrcreat}, the
-user wants both read and write access to the database and if the database does
-not exist, create a new one. If @var{flags} is @code{gdbm_newdb}, the
-user want a new database created, regardless of whether one existed, and wants
-read and write access to the new database.  The following may also be logically
-or'd into the database flags: @code{gdbm_sync}, which causes all database operations
-to be synchronized to the disk, and @code{gdbm_nolock}, which prevents the library
-from performing any locking on the database file.  @code{gdbm_fast} is
-now obsolete, since gdbm defaults to no-sync mode.
+If @var{flags} is @code{gdbm_reader} or the symbol @code{reader}, the
+user wants to just read the database and any call to @code{gdbm-store}
+or @code{gdbm-delete} will fail.  Many readers can access the database
+at the same time. If @var{flags} is @code{gdbm_writer} or the symbol
+@code{writer}, the user wants both read and write access to the
+database and requires exclusive access. If @var{flags} is
+@code{gdbm_wrcreat} or the symbol @code{wrcreat}, the user wants both
+read and write access to the database and if the database does not
+exist, create a new one. If @var{flags} is @code{gdbm_newdb} or the
+symbol @code{newdb}, the user want a new database created, regardless
+of whether one existed, and wants read and write access to the new
+database.  The following may also be logically or'd into the database
+flags: @code{gdbm_fast}, which is the default and included just for
+backward compatibility, @code{gdbm_sync}, which causes all database
+operations to be synchronized to the disk, and @code{gdbm_nolock},
+which prevents the library from performing any locking on the database
+file.  The flags can also be a list of symbols containing one of
+@code{reader}, @code{writer}, @code{wrcreat} or @code{newdb} and zero
+or more of @code{fast}, @code{sync} or @code{nolock}.  Again
+@code{fast} is accepted but ignored.
 @item mode
 File mode (see chmod(2) and open(2) if the file is created).
 @end table
@@ -212,6 +214,16 @@ The return value is the object needed by all other procedures to
 access that gdbm file.
 @end deffn
 
+@deffn Variable gdbm_reader
+@deffnx Variable gdbm_writer
+@deffnx Variable gdbm_wrcreat
+@deffnx Variable gdbm_newdb
+@deffnx Variable gdbm_fast
+@deffnx Variable gdbm_sync
+@deffnx Variable gdbm_nolock
+The values of these variables are meaningful as the @var{flags}
+argument to the @code{gdbm-open} procedure above.
+@end deffn
 
 @node Close
 @chapter Closing the database.
@@ -250,9 +262,10 @@ A non-empty string, converted to utf-8 bytes for lookup in the database.
 Another non-empty string, the content to be stored in the database file, also
 converted to utf-8.
 @item flag
-The action to take when @var{key} is already in the database. The value
-of @code{gdbm_replace} indicates that the old content should be replaced
-by @var{content}. The value of @code{gdbm_insert} indicates that
+The action to take when @var{key} is already in the database. The
+value of @code{gdbm_replace}, or the symbol @code{replace}, indicates
+that the old content should be replaced by @var{content}. The value of
+@code{gdbm_insert}, or the symbol @code{insert}, indicates that
 @code{#f} should be returned and no action taken if @var{key} already
 exists.
 @end table
@@ -280,6 +293,11 @@ The size in gdbm is not restricted like dbm or ndbm. Your
 content can be as large as you want.
 @end deffn
 
+@deffn Variable gdbm_replace
+@deffnx Variable gdbm_insert
+The value of these variables are meaningful as the @var{flag} argument
+to the @code{gdbm-store} procedure above.
+@end deffn
 
 @node Fetch
 @chapter Searching for records in the database.
@@ -357,8 +375,13 @@ If there are no keys, returns @code{#f}.
 
 @deffn Procedure gdbm-nextkey dbf key
 Returns the key to visit after @var{key}, converting its utf-8 bytes
-to a string.
-If there are no more keys, returns @code{#f}.
+to a string.  If there are no more keys, returns @code{#f}.
+
+This may not be the best way to iterate over all keys in a database.
+The @code{gdbm-keys} procedure returns a complete list, which is
+unaffected by database deletions made while iterating over it.  The
+@code{gdbm-keys} procedure also avoids making a copy of each key to
+pass back to @code{gdbm_nextkey}.
 @end deffn
 
 These functions were intended to visit the database in read-only algorithms,
@@ -418,7 +441,8 @@ The parameters are:
 The pointer returned by @code{gdbm-open}.
 @item option
 The option to be set, the value of @code{gdbm_cachesize} or
-@code{gdbm_syncmode}.
+@code{gdbm_syncmode} (or the symbol @code{cachesize} or
+@code{syncmode}).
 @item value
 The value to be set, an integer.
 @end table
@@ -433,8 +457,10 @@ turned on or off.  By default it is off.  @var{Value} should @code{1}
 to turn it on, or @code{0} to turn it off.
 @end deffn
 
-The obsolete and experimental options @code{GDBM_FASTMODE},
-@code{GDBM_CENTFREE} and @code{GDBM_COALESCEBLKS} are not supported by
-this plugin.
+@deffn Variable gdbm_cachesize
+@deffnx Variable gdbm_syncmode
+The value of these variables are meaningful as the @var{option} argument
+to the @code{gdbm-setopt} procedure above.
+@end deffn
 
 @bye