This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
regcomp.c: Use an equivalent 'if' condition
[perl5.git] / cpan / DB_File / DB_File.xs
index 6790d5d..6e6e154 100644 (file)
@@ -2,13 +2,11 @@
 
  DB_File.xs -- Perl 5 interface to Berkeley DB 
 
- written by Paul Marquess <pmqs@cpan.org>
- last modified 4th February 2007
- version 1.818
+ Written by Paul Marquess <pmqs@cpan.org>
 
  All comments/suggestions/problems are welcome
 
-     Copyright (c) 1995-2012 Paul Marquess. All rights reserved.
+     Copyright (c) 1995-2018 Paul Marquess. All rights reserved.
      This program is free software; you can redistribute it and/or
      modify it under the same terms as Perl itself.
 
 #  include "ppport.h"
 #endif
 
+int DB_File___unused() { return 0; }
+
 /* Mention DB_VERSION_MAJOR_CFG, DB_VERSION_MINOR_CFG, and
    DB_VERSION_PATCH_CFG here so that Configure pulls them all in. */
 
 #ifdef COMPAT185
 #    include <db_185.h>
 #else
+
+/* Uncomment one of the lines below */
+/* See the section "At least one secondary cursor must be specified to DB->join"
+   in the README file for the circumstances where you need to uncomment one
+   of the two lines below.
+*/
+
+/* #define time_t __time64_t */
+/* #define time_t __time32_t */
+
 #    include <db.h>
 #endif
 
+#ifndef PERL_UNUSED_ARG
+#  define PERL_UNUSED_ARG(x) ((void)x)
+#endif
+
 /* Wall starts with 5.7.x */
 
 #if PERL_REVISION > 5 || (PERL_REVISION == 5 && PERL_VERSION >= 7)
 #  ifndef DB_VERSION_MAJOR
 
 #    undef  dNOOP
-#    define dNOOP extern int Perl___notused
+#    ifdef __cplusplus
+#        define dNOOP (void)0
+#    else
+#        define dNOOP extern int DB_File___notused()
+#    endif
 
     /* Ditto for dXSARGS. */
 #    undef  dXSARGS
 #    define AT_LEAST_DB_4_3
 #endif
 
+#if DB_VERSION_MAJOR >= 6 
+#    define AT_LEAST_DB_6_0
+#endif
+
 #ifdef AT_LEAST_DB_3_3
 #   define WANT_ERROR
 #endif
@@ -248,7 +270,7 @@ typedef db_recno_t  recno_t;
 #if DB_VERSION_MAJOR == 2 && DB_VERSION_MINOR < 5
 #  define R_SETCURSOR  0x800000
 #else
-#  define R_SETCURSOR  (-100)
+#  define R_SETCURSOR  (DB_OPFLAGS_MASK)
 #endif
 
 #define R_RECNOSYNC     0
@@ -292,7 +314,7 @@ typedef db_recno_t  recno_t;
 #if DB_VERSION_MAJOR == 2 && DB_VERSION_MINOR < 5
 #    define flagSet(flags, bitmask)    ((flags) & (bitmask))
 #else
-#    define flagSet(flags, bitmask)    (((flags) & DB_OPFLAGS_MASK) == (bitmask))
+#    define flagSet(flags, bitmask)    (((flags) & DB_OPFLAGS_MASK) == (u_int)(bitmask))
 #endif
 
 #else /* db version 1.x */
@@ -514,7 +536,6 @@ u_int               flags ;
     if (flagSet(flags, R_CURSOR)) {
        return ((db->cursor)->c_put)(db->cursor, &key, &value, DB_CURRENT);
     }
-
     if (flagSet(flags, R_SETCURSOR)) {
        if ((db->dbp)->put(db->dbp, NULL, &key, &value, 0) != 0)
                return -1 ;
@@ -536,6 +557,19 @@ tidyUp(DB_File db)
 
 
 static int
+
+#ifdef AT_LEAST_DB_6_0
+#ifdef CAN_PROTOTYPE
+btree_compare(DB * db, const DBT *key1, const DBT *key2, size_t* locp)
+#else
+btree_compare(db, key1, key2, locp)
+DB * db ;
+const DBT * key1 ;
+const DBT * key2 ;
+size_t* locp;
+#endif /* CAN_PROTOTYPE */
+
+#else /* Berkeley DB < 6.0 */
 #ifdef AT_LEAST_DB_3_2
 
 #ifdef CAN_PROTOTYPE
@@ -558,6 +592,7 @@ const DBT * key2 ;
 #endif
 
 #endif
+#endif
 
 {
 #ifdef dTHX
@@ -569,6 +604,12 @@ const DBT * key2 ;
     int retval ;
     int count ;
     
+#ifdef AT_LEAST_DB_3_2
+    PERL_UNUSED_ARG(db);
+#endif
+#ifdef AT_LEAST_DB_6_0
+    PERL_UNUSED_ARG(locp);
+#endif
 
     if (CurrentDB->in_compare) {
         tidyUp(CurrentDB);
@@ -654,6 +695,10 @@ const DBT * key2 ;
     int retval ;
     int count ;
     
+#ifdef AT_LEAST_DB_3_2
+    PERL_UNUSED_ARG(db);
+#endif
+
     if (CurrentDB->in_prefix){
         tidyUp(CurrentDB);
         croak ("DB_File btree_prefix: recursion detected\n") ;
@@ -743,6 +788,10 @@ HASH_CB_SIZE_TYPE size ;
     int retval = 0;
     int count ;
 
+#ifdef AT_LEAST_DB_3_2
+    PERL_UNUSED_ARG(db);
+#endif
+
     if (CurrentDB->in_hash){
         tidyUp(CurrentDB);
         croak ("DB_File hash callback: recursion detected\n") ;
@@ -798,6 +847,9 @@ db_errcall_cb(const char * db_errpfx, char * buffer)
     dTHX;
 #endif    
     SV * sv = perl_get_sv(ERR_BUFF, FALSE) ;
+#ifdef AT_LEAST_DB_4_3
+    PERL_UNUSED_ARG(dbenv);
+#endif
     if (sv) {
         if (db_errpfx)
             sv_setpvf(sv, "%s: %s", db_errpfx, buffer) ;
@@ -1387,10 +1439,10 @@ SV *   sv ;
                    value = (int)SvIV(*svp) ;
 
                if (fixed) {
-                   status = dbp->set_re_pad(dbp, value) ;
+                   (void)dbp->set_re_pad(dbp, value) ;
                }
                else {
-                   status = dbp->set_re_delim(dbp, value) ;
+                   (void)dbp->set_re_delim(dbp, value) ;
                }
 
             }
@@ -1399,12 +1451,12 @@ SV *   sv ;
                svp = hv_fetch(action, "reclen", 6, FALSE);
               if (svp) {
                   u_int32_t len =  my_SvUV32(*svp) ;
-                   status = dbp->set_re_len(dbp, len) ;
+                   (void)dbp->set_re_len(dbp, len) ;
               }    
           }
          
            if (name != NULL) {
-               status = dbp->set_re_source(dbp, name) ;
+               (void)dbp->set_re_source(dbp, name) ;
                name = NULL ;
            }   
 
@@ -1417,7 +1469,7 @@ SV *   sv ;
                name = NULL ;
          
 
-           status = dbp->set_flags(dbp, (u_int32_t)DB_RENUMBER) ;
+           (void)dbp->set_flags(dbp, (u_int32_t)DB_RENUMBER) ;
          
                if (flags){
                    (void)dbp->set_flags(dbp, (u_int32_t)flags) ;
@@ -1471,7 +1523,10 @@ SV *   sv ;
        }
 
         if (status)
+       {
+           db_close(RETVAL); /* close **dbp handle to prevent mem.leak */
            RETVAL->dbp = NULL ;
+       }
 
     }
 
@@ -1497,6 +1552,9 @@ BOOT:
     SV * sv_err = perl_get_sv(ERR_BUFF, GV_ADD|GV_ADDMULTI) ; 
 #endif
     MY_CXT_INIT;
+#ifdef WANT_ERROR
+    PERL_UNUSED_VAR(sv_err); /* huh? we just retrieved it... */
+#endif
     __getBerkeleyDBInfo() ;
  
     DBT_clear(empty) ; 
@@ -1525,6 +1583,7 @@ db_DoTie_(isHASH, dbtype, name=undef, flags=O_CREAT|O_RDWR, mode=0666, type=DB_H
                sv = ST(5) ;
 
            RETVAL = ParseOpenInfo(aTHX_ isHASH, name, flags, mode, sv) ;
+           Trace(("db_DoTie_ %p\n", RETVAL));
            if (RETVAL->dbp == NULL) {
                Safefree(RETVAL);
                RETVAL = NULL ;
@@ -1572,6 +1631,7 @@ db_DELETE(db, key, flags=0)
        PREINIT:
          dMY_CXT;
        INIT:
+         (void)flags;
          CurrentDB = db ;
 
 
@@ -1620,6 +1680,7 @@ db_STORE(db, key, value, flags=0)
        PREINIT:
          dMY_CXT;
        INIT:
+         (void)flags;
          CurrentDB = db ;