From: Matt Birkholz Date: Wed, 30 May 2018 14:43:32 +0000 (-0700) Subject: gdbm: Accommodate gdbm 1.14. X-Git-Tag: mit-scheme-pucked-gdbm-0.3.4~1 X-Git-Url: https://birchwood-abbey.net/git?a=commitdiff_plain;h=5f20a8efaf8093933ffb539cc1a575a9517b73d5;p=mit-scheme.git gdbm: Accommodate gdbm 1.14. Add const declarations. Rename struct member gdbm_errno, which conflicts with a new pre-processor macro. Presume external locking is already in place where necessary. Add GDBM_NOLOCK to the gdbm_open flags in versions >= 1.13. Gdbm 1.14 on Ubuntu 18.04 fails to lock a DB file it just created (during `make check`). --- diff --git a/src/gdbm/gdbm-adapter.c b/src/gdbm/gdbm-adapter.c index b6f0ac544..403eacbe2 100644 --- a/src/gdbm/gdbm-adapter.c +++ b/src/gdbm/gdbm-adapter.c @@ -67,7 +67,7 @@ alloc_gdbm_content (gdbm_args * args, int size) return (bytes); } -extern char * +extern const char * get_gdbm_version (void) { return (gdbm_version); @@ -81,26 +81,38 @@ fatal_error (const char * msg) error_external_return (); } +#ifdef GDBM_VERSION_MAJOR +# if GDBM_VERSION_MAJOR > 1 +# define GDBM_NEED_NOLOCK 1 +# elif GDBM_VERSION_MAJOR == 1 && GDBM_VERSION_MINOR >= 13 +# define GDBM_NEED_NOLOCK 1 +# endif +#endif + extern gdbm_args * do_gdbm_open (char * name, int block_size, int read_write, int mode) { gdbm_args *args = (gdbm_args *) malloc (sizeof (gdbm_args)); if (!args) return (args); +#ifdef GDBM_NEED_NOLOCK + read_write |= GDBM_NOLOCK; +#endif + args->key.dsize = 0; args->key.dptr = NULL; args->key_allocation = 0; args->content.dsize = 0; args->content.dptr = NULL; args->content_allocation = 0; - args->gdbm_errno = 0; - args->sys_errno = 0; + args->errno_gdbm = 0; + args->errno_sys = 0; args->dbf = gdbm_open (name, block_size, read_write, mode, &fatal_error); if (args->dbf == NULL) { - args->gdbm_errno = gdbm_errno; - args->sys_errno = errno; + args->errno_gdbm = gdbm_errno; + args->errno_sys = errno; } return (args); } @@ -122,8 +134,8 @@ do_gdbm_store (gdbm_args * args, int flag) int ret = gdbm_store (args->dbf, args->key, args->content, flag); if (ret == -1) { - args->gdbm_errno = gdbm_errno; - args->sys_errno = errno; + args->errno_gdbm = gdbm_errno; + args->errno_sys = errno; } return (ret); } @@ -180,8 +192,8 @@ do_gdbm_reorganize (gdbm_args * args) int ret = gdbm_reorganize (args->dbf); if (ret) { - args->gdbm_errno = gdbm_errno; - args->sys_errno = errno; + args->errno_gdbm = gdbm_errno; + args->errno_sys = errno; } return (ret); } @@ -198,8 +210,8 @@ do_gdbm_setopt (gdbm_args * args, int option, int value) int ret = gdbm_setopt (args->dbf, option, &value, sizeof (int)); if (ret) { - args->gdbm_errno = gdbm_errno; - args->sys_errno = errno; + args->errno_gdbm = gdbm_errno; + args->errno_sys = errno; } return (ret); } diff --git a/src/gdbm/gdbm-shim.h b/src/gdbm/gdbm-shim.h index c8bac6b3c..4fb76967b 100644 --- a/src/gdbm/gdbm-shim.h +++ b/src/gdbm/gdbm-shim.h @@ -33,8 +33,8 @@ USA. typedef struct gdbm_args { GDBM_FILE dbf; - gdbm_error gdbm_errno; - int sys_errno; + gdbm_error errno_gdbm; + int errno_sys; datum key, content; int key_allocation, content_allocation; } gdbm_args; @@ -54,4 +54,4 @@ extern int do_gdbm_nextkey (gdbm_args * args); extern int do_gdbm_reorganize (gdbm_args * args); extern void do_gdbm_sync (gdbm_args * args); extern int do_gdbm_setopt (gdbm_args * args, int option, int value); -extern char * get_gdbm_version (void); +extern const char * get_gdbm_version (void); diff --git a/src/gdbm/gdbm.cdecl b/src/gdbm/gdbm.cdecl index e8af45622..221fbe84a 100644 --- a/src/gdbm/gdbm.cdecl +++ b/src/gdbm/gdbm.cdecl @@ -56,8 +56,8 @@ USA. (typedef gdbm_args (struct (dbf GDBM_FILE) - (gdbm_errno int) - (sys_errno int) + (errno_gdbm int) + (errno_sys int) (key datum) (content datum))) @@ -77,10 +77,10 @@ USA. (extern int do_gdbm_nextkey (args (* gdbm_args))) (extern int do_gdbm_reorganize (args (* gdbm_args))) (extern void do_gdbm_sync (args (* gdbm_args))) -(extern (* char) gdbm_strerror (errnum int)) -(extern (* char) strerror (errnum int)) +(extern (* (const char)) gdbm_strerror (errnum int)) +(extern (* (const char)) strerror (errnum int)) (extern int do_gdbm_setopt (args (* gdbm_args)) (option int) (value int)) -(extern (* char) get_gdbm_version) +(extern (* (const char)) get_gdbm_version) (enum (GDBM_NO_ERROR) (GDBM_MALLOC_ERROR) diff --git a/src/gdbm/gdbm.scm b/src/gdbm/gdbm.scm index 9ce6bd948..91f9e239a 100644 --- a/src/gdbm/gdbm.scm +++ b/src/gdbm/gdbm.scm @@ -294,8 +294,8 @@ USA. (define (gdbm-error gdbf msg) (let ((args (gdbf-args gdbf))) (error (string-append msg " failed:") - (gdbm-strerror (C-> args "gdbm_args gdbm_errno")) - (strerror (C-> args "gdbm_args sys_errno"))))) + (gdbm-strerror (C-> args "gdbm_args errno_gdbm")) + (strerror (C-> args "gdbm_args errno_sys"))))) (define (gdbf-args-put-key! args key) (let ((bytes (->bytes key)))