]> granicus.if.org Git - php/commitdiff
MFH: as discussed
authorMarcus Boerger <helly@php.net>
Fri, 20 Dec 2002 20:25:19 +0000 (20:25 +0000)
committerMarcus Boerger <helly@php.net>
Fri, 20 Dec 2002 20:25:19 +0000 (20:25 +0000)
ext/dba/dba.c
ext/dba/dba_cdb.c
ext/dba/dba_db2.c
ext/dba/dba_db3.c
ext/dba/dba_dbm.c
ext/dba/dba_flatfile.c
ext/dba/dba_gdbm.c
ext/dba/php_dba.h
ext/dba/tests/dba_cdb.phpt
ext/dba/tests/dba_handler.inc

index 43710d32ce1e27f2e9b221c3a2c2071e8d32088f..28638b66dacfc03cf6ff9c0780f092731eafa026 100644 (file)
@@ -211,7 +211,7 @@ static int le_pdb;
 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);
@@ -219,8 +219,8 @@ static void dba_close(dba_info *info TSRMLS_DC)
                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);
 }
 /* }}} */
 
@@ -228,7 +228,7 @@ static void dba_close(dba_info *info TSRMLS_DC)
  */
 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);
 }
@@ -510,7 +510,7 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, int persistent)
        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:
@@ -536,12 +536,12 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, int persistent)
                        if (!strcmp(file_mode, "r")) {
                                /* when in read only mode try to use existing .lck file first */
                                /* do not log errors for .lck file while in read ony mode on .lck file */
-                       lock_file_mode = "rb";
+                               lock_file_mode = "rb";
                                info->lock.fp = php_stream_open_wrapper(info->lock.name, lock_file_mode, STREAM_MUST_SEEK|IGNORE_PATH|ENFORCE_SAFE_MODE, NULL);
-               }
+                       }
                        if (!info->lock.fp) {
                                /* when not in read mode or failed to open .lck file read only. now try again in create(write) mode and log errors */
-                       lock_file_mode = "a+b";
+                               lock_file_mode = "a+b";
                        }
                }
                if (!info->lock.fp) {
index e04545e65f0b9560b785362f3a5ac9301fa8c097..b704465ab9d24da1aacef03d8c6b14996bd2ba7a 100644 (file)
@@ -98,7 +98,7 @@ DBA_OPEN_FUNC(cdb)
                        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 @@ DBA_CLOSE_FUNC(cdb)
        cdb_free(&cdb->c);
        close(cdb->file);
 #endif
-       efree(cdb);
+       pefree(cdb, info->flags&DBA_PERSISTENT);
 }
 
 #if DBA_CDB_BUILTIN
index 580e6f62e205d09f20b9134c7ccb24b271de6d28..e1afa98ff425f92750850bf3ad9e1fe4c42135b0 100644 (file)
@@ -76,7 +76,7 @@ DBA_OPEN_FUNC(db2)
                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 @@ DBA_CLOSE_FUNC(db2)
        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 9dfe8ad822e8fdf031af04ff81d070fc4261f3dc..65ff51e7a4efae6fa001152db848891694c2258e 100644 (file)
@@ -80,8 +80,8 @@ DBA_OPEN_FUNC(db3)
                        dbp->open(dbp, info->path, NULL, type, gmode, filemode) == 0) {
 #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 @@ DBA_CLOSE_FUNC(db3)
        
        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 4eca420786373a618aad2533fa3c72c7002fd740..cb7664987bc5f736d3a2f4be446b832e244c929c 100644 (file)
@@ -78,14 +78,14 @@ DBA_OPEN_FUNC(dbm)
                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 a22866c4560082f63221196230443fa070c8b0bc..53a577ab5724fb28ca70be6335df36501b81e53f 100644 (file)
@@ -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 @@ DBA_CLOSE_FUNC(flatfile)
 
        if (dba->nextkey.dptr)
                efree(dba->nextkey.dptr);
-       efree(dba);
+       pefree(dba, info->flags&DBA_PERSISTENT);
 }
 
 DBA_FETCH_FUNC(flatfile)
index 18288ace27a9b9243a6513c1bb7bf472fac0644a..93c53d4b9404ec7e14c145a8a1234d9038257c32 100644 (file)
@@ -59,7 +59,7 @@ DBA_OPEN_FUNC(gdbm)
        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 @@ DBA_CLOSE_FUNC(gdbm)
        
        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 2290c638e836f5821c998ea56b9de33b9a1fea5f..2e8877b6b5b643de11d0ab66c6ec4e2fa77fe893 100644 (file)
@@ -63,6 +63,7 @@ typedef struct dba_info {
 #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 2390acbce59b0142966dc8cbaeb378594fe0b7c2..9a881706ee2400f589156a008a447fa53f9f1cd3 100644 (file)
@@ -4,7 +4,7 @@ DBA CDB handler test
 <?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 @@ DBA CDB handler test
 ?>
 --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 dafc9910258b650d8116e64e79f225b91132b00c..66a356bb18e1d162eb5ea93a7a2ba5d64f1a2426 100644 (file)
@@ -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) {
                }
                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) {
+       }       
 ?>
\ No newline at end of file