helly           Fri Dec 20 12:47:58 2002 EDT

  Modified files:              
    /php4/ext/dba       dba.c dba_cdb.c dba_db2.c dba_db3.c dba_db4.c 
                        dba_dbm.c dba_flatfile.c dba_gdbm.c php_dba.h 
    /php4/ext/dba/tests dba_cdb.phpt dba_handler.inc 
  Log:
  -Fix memory handling of persistent dba connections.
  -Update tests.
  # cdb and flatfile still FAIL for dba_popen since the known streams problem
  
  
Index: php4/ext/dba/dba.c
diff -u php4/ext/dba/dba.c:1.72 php4/ext/dba/dba.c:1.73
--- php4/ext/dba/dba.c:1.72     Fri Dec 20 11:45:34 2002
+++ php4/ext/dba/dba.c  Fri Dec 20 12:47:57 2002
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: dba.c,v 1.72 2002/12/20 16:45:34 andrei Exp $ */
+/* $Id: dba.c,v 1.73 2002/12/20 17:47:57 helly Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -215,7 +215,7 @@
 static void dba_close(dba_info *info TSRMLS_DC)
 {
        if (info->hnd) info->hnd->close(info TSRMLS_CC);
-       if (info->path) efree(info->path);
+       if (info->path) pefree(info->path, info->flags&DBA_PERSISTENT);
        if (info->fp && info->fp!=info->lock.fp) php_stream_close(info->fp);
        if (info->lock.fd) {
                php_flock(info->lock.fd, LOCK_UN);
@@ -223,8 +223,8 @@
                info->lock.fd = 0;
        }
        if (info->lock.fp) php_stream_close(info->lock.fp);
-       if (info->lock.name) efree(info->lock.name);
-       efree(info);
+       if (info->lock.name) pefree(info->lock.name, info->flags&DBA_PERSISTENT);
+       pefree(info, info->flags&DBA_PERSISTENT);
 }
 /* }}} */
 
@@ -232,8 +232,8 @@
  */
 static void dba_close_rsrc(zend_rsrc_list_entry *rsrc TSRMLS_DC)
 {
-       dba_info *info = (dba_info *)rsrc->ptr;
-
+       dba_info *info = (dba_info *)rsrc->ptr; 
+       
        dba_close(info TSRMLS_CC);
 }
 /* }}} */
@@ -514,7 +514,7 @@
        info->mode = modenr;
        info->argc = ac - 3;
        info->argv = args + 3;
-       info->flags = (hptr->flags & ~DBA_LOCK_ALL) | (lock_flag & DBA_LOCK_ALL);
+       info->flags = (hptr->flags & ~DBA_LOCK_ALL) | (lock_flag & DBA_LOCK_ALL) | 
+(persistent ? DBA_PERSISTENT : 0);
        info->lock.mode = lock_mode;
 
        /* if any open call is a locking call:
Index: php4/ext/dba/dba_cdb.c
diff -u php4/ext/dba/dba_cdb.c:1.23 php4/ext/dba/dba_cdb.c:1.24
--- php4/ext/dba/dba_cdb.c:1.23 Wed Nov 13 07:12:44 2002
+++ php4/ext/dba/dba_cdb.c      Fri Dec 20 12:47:58 2002
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: dba_cdb.c,v 1.23 2002/11/13 12:12:44 edink Exp $ */
+/* $Id: dba_cdb.c,v 1.24 2002/12/20 17:47:58 helly Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -98,7 +98,7 @@
                        return FAILURE;
        }
 
-       cdb = emalloc(sizeof(dba_cdb));
+       cdb = pemalloc(sizeof(dba_cdb), info->flags&DBA_PERSISTENT);
        memset(cdb, 0, sizeof(dba_cdb));
 
 #if DBA_CDB_BUILTIN
@@ -132,7 +132,7 @@
        cdb_free(&cdb->c);
        close(cdb->file);
 #endif
-       efree(cdb);
+       pefree(cdb, info->flags&DBA_PERSISTENT);
 }
 
 #if DBA_CDB_BUILTIN
Index: php4/ext/dba/dba_db2.c
diff -u php4/ext/dba/dba_db2.c:1.30 php4/ext/dba/dba_db2.c:1.31
--- php4/ext/dba/dba_db2.c:1.30 Wed Nov  6 12:59:03 2002
+++ php4/ext/dba/dba_db2.c      Fri Dec 20 12:47:58 2002
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: dba_db2.c,v 1.30 2002/11/06 17:59:03 sas Exp $ */
+/* $Id: dba_db2.c,v 1.31 2002/12/20 17:47:58 helly Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -76,7 +76,7 @@
                return FAILURE;
        }
 
-       info->dbf = emalloc(sizeof(dba_db2_data));
+       info->dbf = pemalloc(sizeof(dba_db2_data), info->flags&DBA_PERSISTENT);
        memset(info->dbf, 0, sizeof(dba_db2_data));
        ((dba_db2_data *) info->dbf)->dbp = dbp;
        return SUCCESS;
@@ -89,7 +89,7 @@
        if (dba->cursor) 
                dba->cursor->c_close(dba->cursor);
        dba->dbp->close(dba->dbp, 0);
-       efree(dba);
+       pefree(dba, info->flags&DBA_PERSISTENT);
 }
 
 DBA_FETCH_FUNC(db2)
Index: php4/ext/dba/dba_db3.c
diff -u php4/ext/dba/dba_db3.c:1.22 php4/ext/dba/dba_db3.c:1.23
--- php4/ext/dba/dba_db3.c:1.22 Sat Nov 23 16:11:12 2002
+++ php4/ext/dba/dba_db3.c      Fri Dec 20 12:47:58 2002
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: dba_db3.c,v 1.22 2002/11/23 21:11:12 helly Exp $ */
+/* $Id: dba_db3.c,v 1.23 2002/12/20 17:47:58 helly Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -81,7 +81,7 @@
 #endif
                dba_db3_data *data;
 
-               data = emalloc(sizeof(*data));
+               data = pemalloc(sizeof(*data), info->flags&DBA_PERSISTENT);
                data->dbp = dbp;
                data->cursor = NULL;
                info->dbf = data;
@@ -100,7 +100,7 @@
        
        if (dba->cursor) dba->cursor->c_close(dba->cursor);
        dba->dbp->close(dba->dbp, 0);
-       efree(dba);
+       pefree(dba, info->flags&DBA_PERSISTENT);
 }
 
 DBA_FETCH_FUNC(db3)
Index: php4/ext/dba/dba_db4.c
diff -u php4/ext/dba/dba_db4.c:1.1 php4/ext/dba/dba_db4.c:1.2
--- php4/ext/dba/dba_db4.c:1.1  Tue Nov 26 07:05:59 2002
+++ php4/ext/dba/dba_db4.c      Fri Dec 20 12:47:58 2002
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: dba_db4.c,v 1.1 2002/11/26 12:05:59 helly Exp $ */
+/* $Id: dba_db4.c,v 1.2 2002/12/20 17:47:58 helly Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -81,7 +81,7 @@
 #endif
                dba_db4_data *data;
 
-               data = emalloc(sizeof(*data));
+               data = pemalloc(sizeof(*data), info->flags&DBA_PERSISTENT);
                data->dbp = dbp;
                data->cursor = NULL;
                info->dbf = data;
@@ -100,7 +100,7 @@
        
        if (dba->cursor) dba->cursor->c_close(dba->cursor);
        dba->dbp->close(dba->dbp, 0);
-       efree(dba);
+       pefree(dba, info->flags&DBA_PERSISTENT);
 }
 
 DBA_FETCH_FUNC(db4)
Index: php4/ext/dba/dba_dbm.c
diff -u php4/ext/dba/dba_dbm.c:1.22 php4/ext/dba/dba_dbm.c:1.23
--- php4/ext/dba/dba_dbm.c:1.22 Wed Nov  6 12:59:03 2002
+++ php4/ext/dba/dba_dbm.c      Fri Dec 20 12:47:58 2002
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: dba_dbm.c,v 1.22 2002/11/06 17:59:03 sas Exp $ */
+/* $Id: dba_dbm.c,v 1.23 2002/12/20 17:47:58 helly Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -78,14 +78,14 @@
                return FAILURE;
        }
 
-       info->dbf = emalloc(sizeof(dba_dbm_data));
+       info->dbf = pemalloc(sizeof(dba_dbm_data), info->flags&DBA_PERSISTENT);
        memset(info->dbf, 0, sizeof(dba_dbm_data));
        return SUCCESS;
 }
 
 DBA_CLOSE_FUNC(dbm)
 {
-       efree(info->dbf);
+       pefree(info->dbf, info->flags&DBA_PERSISTENT);
        dbmclose();
 }
 
Index: php4/ext/dba/dba_flatfile.c
diff -u php4/ext/dba/dba_flatfile.c:1.8 php4/ext/dba/dba_flatfile.c:1.9
--- php4/ext/dba/dba_flatfile.c:1.8     Wed Nov 13 07:12:44 2002
+++ php4/ext/dba/dba_flatfile.c Fri Dec 20 12:47:58 2002
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: dba_flatfile.c,v 1.8 2002/11/13 12:12:44 edink Exp $ */
+/* $Id: dba_flatfile.c,v 1.9 2002/12/20 17:47:58 helly Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -41,7 +41,7 @@
 
 DBA_OPEN_FUNC(flatfile)
 {
-       info->dbf = emalloc(sizeof(flatfile));
+       info->dbf = pemalloc(sizeof(flatfile), info->flags&DBA_PERSISTENT);
        memset(info->dbf, 0, sizeof(flatfile));
 
        ((flatfile*)info->dbf)->fp = info->fp;
@@ -55,7 +55,7 @@
 
        if (dba->nextkey.dptr)
                efree(dba->nextkey.dptr);
-       efree(dba);
+       pefree(dba, info->flags&DBA_PERSISTENT);
 }
 
 DBA_FETCH_FUNC(flatfile)
Index: php4/ext/dba/dba_gdbm.c
diff -u php4/ext/dba/dba_gdbm.c:1.16 php4/ext/dba/dba_gdbm.c:1.17
--- php4/ext/dba/dba_gdbm.c:1.16        Thu Nov  7 08:00:37 2002
+++ php4/ext/dba/dba_gdbm.c     Fri Dec 20 12:47:58 2002
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: dba_gdbm.c,v 1.16 2002/11/07 13:00:37 helly Exp $ */
+/* $Id: dba_gdbm.c,v 1.17 2002/12/20 17:47:58 helly Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -59,7 +59,7 @@
        dbf = gdbm_open(info->path, 0, gmode, filemode, NULL);
        
        if(dbf) {
-               info->dbf = emalloc(sizeof(dba_gdbm_data));
+               info->dbf = pemalloc(sizeof(dba_gdbm_data), 
+info->flags&DBA_PERSISTENT);
                memset(info->dbf, 0, sizeof(dba_gdbm_data));
                ((dba_gdbm_data *) info->dbf)->dbf = dbf;
                return SUCCESS;
@@ -74,7 +74,7 @@
        
        if(dba->nextkey.dptr) free(dba->nextkey.dptr);
        gdbm_close(dba->dbf);
-       efree(dba);
+       pefree(dba, info->flags&DBA_PERSISTENT);
 }
 
 DBA_FETCH_FUNC(gdbm)
Index: php4/ext/dba/php_dba.h
diff -u php4/ext/dba/php_dba.h:1.20 php4/ext/dba/php_dba.h:1.21
--- php4/ext/dba/php_dba.h:1.20 Thu Nov 14 09:32:39 2002
+++ php4/ext/dba/php_dba.h      Fri Dec 20 12:47:58 2002
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: php_dba.h,v 1.20 2002/11/14 14:32:39 helly Exp $ */
+/* $Id: php_dba.h,v 1.21 2002/12/20 17:47:58 helly Exp $ */
 
 #ifndef PHP_DBA_H
 #define PHP_DBA_H
@@ -63,6 +63,7 @@
 #define DBA_LOCK_WCT     (DBA_LOCK_WRITER|DBA_LOCK_CREAT|DBA_LOCK_TRUNC)
 
 #define DBA_STREAM_OPEN  (0x0010)
+#define DBA_PERSISTENT   (0x0020)
 
 extern zend_module_entry dba_module_entry;
 #define dba_module_ptr &dba_module_entry
Index: php4/ext/dba/tests/dba_cdb.phpt
diff -u php4/ext/dba/tests/dba_cdb.phpt:1.5 php4/ext/dba/tests/dba_cdb.phpt:1.6
--- php4/ext/dba/tests/dba_cdb.phpt:1.5 Thu Nov 14 09:32:39 2002
+++ php4/ext/dba/tests/dba_cdb.phpt     Fri Dec 20 12:47:58 2002
@@ -4,7 +4,7 @@
 <?php 
        require_once('skipif.inc');
        if (!in_array('cdb', dba_handlers())) die('skip CDB handler not available');
-       die('skip CDB does not support replace or delete');
+       die('info CDB does not support replace or delete');
 ?>
 --FILE--
 <?php
@@ -14,17 +14,17 @@
 ?>
 --EXPECT--
 database handler: cdb
-3NYNYY
+5YYYYY
 Content String 2
-Content 2 replaced
-Read during write: not allowed
-Content 2 replaced 2nd time
-The 6th value
-array(3) {
-  ["key number 6"]=>
-  string(13) "The 6th value"
+array(5) {
+  ["key1"]=>
+  string(16) "Content String 1"
   ["key2"]=>
-  string(27) "Content 2 replaced 2nd time"
+  string(16) "Content String 2"
+  ["key3"]=>
+  string(20) "Third Content String"
+  ["key4"]=>
+  string(22) "Another Content String"
   ["key5"]=>
   string(23) "The last content string"
-}
\ No newline at end of file
+}
Index: php4/ext/dba/tests/dba_handler.inc
diff -u php4/ext/dba/tests/dba_handler.inc:1.8 php4/ext/dba/tests/dba_handler.inc:1.9
--- php4/ext/dba/tests/dba_handler.inc:1.8      Thu Nov 14 09:32:39 2002
+++ php4/ext/dba/tests/dba_handler.inc  Fri Dec 20 12:47:58 2002
@@ -6,8 +6,15 @@
                dba_insert("key3", "Third Content String", $db_file);
                dba_insert("key4", "Another Content String", $db_file);
                dba_insert("key5", "The last content string", $db_file);
-               dba_delete("key3", $db_file);
-               dba_delete("key1", $db_file);
+               if ($handler != 'cdb') {
+                       dba_delete("key3", $db_file);
+                       dba_delete("key1", $db_file);
+               } else {
+                       dba_close($db_file);
+                       if (($db_file = dba_open($db_filename, 'r'.$lock_flag, 
+$handler))===FALSE) {
+                               echo "Error reopening database\n";
+                       }
+               }
                $a = dba_firstkey($db_file);
                $i=0;
                while($a) {
@@ -20,28 +27,32 @@
                }
                echo "\n";
                echo dba_fetch("key2", $db_file)."\n";
-               dba_replace("key2", "Content 2 replaced", $db_file);
-               echo dba_fetch("key2", $db_file)."\n";
+               if ($handler != 'cdb') {
+                       dba_replace("key2", "Content 2 replaced", $db_file);
+                       echo dba_fetch("key2", $db_file)."\n";
+               }
                dba_close($db_file);
        } else {
                echo "Error creating database\n";
        }
-       $db_writer = dba_open($db_filename, 'w'.$lock_flag, $handler);
-       if (($dba_reader = @dba_open($db_filename, 'r'.$lock_flag.($lock_flag ? 't' : 
''), $handler))===false) {
-               echo "Read during write: not allowed\n";
-       } else {
-               echo "Read during write: allowed\n";
-       }
-       if ($db_writer!==FALSE) {
-               dba_insert("key number 6", "The 6th value", $db_writer);
-               @dba_insert("key number 6", "The 6th value inserted again would be an 
error", $db_writer);
-               dba_replace("key2", "Content 2 replaced 2nd time", $db_writer);
-               dba_delete("key4", $db_writer);
-               echo dba_fetch("key2", $db_writer)."\n";
-               echo dba_fetch("key number 6", $db_writer)."\n";
-               dba_close($db_writer); // when the writer is open at least db3 would 
fail because of buffered io.
-       } else {
-               die("Error reopening database\n");
+       if ($handler != 'cdb') {
+               $db_writer = dba_open($db_filename, 'w'.$lock_flag, $handler);
+               if (($dba_reader = @dba_open($db_filename, 'r'.$lock_flag.($lock_flag 
+? 't' : ''), $handler))===false) {
+                       echo "Read during write: not allowed\n";
+               } else {
+                       echo "Read during write: allowed\n";
+               }
+               if ($db_writer!==FALSE) {
+                       dba_insert("key number 6", "The 6th value", $db_writer);
+                       @dba_insert("key number 6", "The 6th value inserted again 
+would be an error", $db_writer);
+                       dba_replace("key2", "Content 2 replaced 2nd time", $db_writer);
+                       dba_delete("key4", $db_writer);
+                       echo dba_fetch("key2", $db_writer)."\n";
+                       echo dba_fetch("key number 6", $db_writer)."\n";
+                       dba_close($db_writer); // when the writer is open at least db3 
+would fail because of buffered io.
+               } else {
+                       die("Error reopening database\n");
+               }
        }
        if (($db_file = dba_open($db_filename, 'r'.$lock_flag, $handler))!==FALSE) {
                $key = dba_firstkey($db_file);
@@ -59,4 +70,6 @@
        if ($dba_reader) {
                dba_close($dba_reader);
        }
+       if (($db_file = dba_popen($db_filename, 'r'.($handler!='gdbm'?'-':''), 
+$handler))!==FALSE) {
+       }       
 ?>

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to