GDBM_File must cast fatal_func appropriately for the version of gdbm.h
authorNicholas Clark <nick@ccl4.org>
Mon, 17 Dec 2012 09:31:11 +0000 (10:31 +0100)
committerNicholas Clark <nick@ccl4.org>
Mon, 17 Dec 2012 09:31:11 +0000 (10:31 +0100)
The fifth argument to gdbm_open() is an optional callback function for fatal
errors. The prototype for this function has changed between gdbm 1.8.3 and
1.9.0, from void (*)() to void(*)(const char *). This distinction doesn't
matter to a C compiler, but does to a C++ compiler, which we use to test the
core build. So, cast appropriately, depending on the version macros in
gdbm.h

ext/GDBM_File/GDBM_File.xs

index 6e28f22..33e08e2 100644 (file)
@@ -25,6 +25,14 @@ typedef datum datum_key_copy;
 
 #define GDBM_BLOCKSIZE 0 /* gdbm defaults to stat blocksize */
 
+#if defined(GDBM_VERSION_MAJOR) && defined(GDBM_VERSION_MINOR) \
+    && GDBM_VERSION_MAJOR > 1 || \
+    (GDBM_VERSION_MAJOR == 1 && GDBM_VERSION_MINOR >= 9)
+typedef void (*FATALFUNC)(const char *);
+#else
+typedef void (*FATALFUNC)();
+#endif
+
 #ifndef GDBM_FAST
 static int
 not_here(char *s)
@@ -78,7 +86,8 @@ gdbm_TIEHASH(dbtype, name, read_write, mode)
            GDBM_FILE   dbp ;
 
            RETVAL = NULL ;
-           if ((dbp =  gdbm_open(name, GDBM_BLOCKSIZE, read_write, mode, croak_string))) {
+           if ((dbp =  gdbm_open(name, GDBM_BLOCKSIZE, read_write, mode,
+                                 (FATALFUNC) croak_string))) {
                RETVAL = (GDBM_File)safecalloc(1, sizeof(GDBM_File_type)) ;
                RETVAL->dbp = dbp ;
            }