mirror of
https://github.com/php/php-src.git
synced 2025-08-15 13:38:49 +02:00
-Fix memory handling of persistent dba connections.
-Update tests. # cdb and flatfile still FAIL for dba_popen since the known streams problem
This commit is contained in:
parent
710e49a30b
commit
efd314e767
11 changed files with 65 additions and 51 deletions
|
@ -215,7 +215,7 @@ static int le_pdb;
|
||||||
static void dba_close(dba_info *info TSRMLS_DC)
|
static void dba_close(dba_info *info TSRMLS_DC)
|
||||||
{
|
{
|
||||||
if (info->hnd) info->hnd->close(info TSRMLS_CC);
|
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->fp && info->fp!=info->lock.fp) php_stream_close(info->fp);
|
||||||
if (info->lock.fd) {
|
if (info->lock.fd) {
|
||||||
php_flock(info->lock.fd, LOCK_UN);
|
php_flock(info->lock.fd, LOCK_UN);
|
||||||
|
@ -223,8 +223,8 @@ static void dba_close(dba_info *info TSRMLS_DC)
|
||||||
info->lock.fd = 0;
|
info->lock.fd = 0;
|
||||||
}
|
}
|
||||||
if (info->lock.fp) php_stream_close(info->lock.fp);
|
if (info->lock.fp) php_stream_close(info->lock.fp);
|
||||||
if (info->lock.name) efree(info->lock.name);
|
if (info->lock.name) pefree(info->lock.name, info->flags&DBA_PERSISTENT);
|
||||||
efree(info);
|
pefree(info, info->flags&DBA_PERSISTENT);
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
|
@ -232,8 +232,8 @@ static void dba_close(dba_info *info TSRMLS_DC)
|
||||||
*/
|
*/
|
||||||
static void dba_close_rsrc(zend_rsrc_list_entry *rsrc 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);
|
dba_close(info TSRMLS_CC);
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
@ -514,7 +514,7 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, int persistent)
|
||||||
info->mode = modenr;
|
info->mode = modenr;
|
||||||
info->argc = ac - 3;
|
info->argc = ac - 3;
|
||||||
info->argv = args + 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;
|
info->lock.mode = lock_mode;
|
||||||
|
|
||||||
/* if any open call is a locking call:
|
/* if any open call is a locking call:
|
||||||
|
|
|
@ -98,7 +98,7 @@ DBA_OPEN_FUNC(cdb)
|
||||||
return FAILURE;
|
return FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
cdb = emalloc(sizeof(dba_cdb));
|
cdb = pemalloc(sizeof(dba_cdb), info->flags&DBA_PERSISTENT);
|
||||||
memset(cdb, 0, sizeof(dba_cdb));
|
memset(cdb, 0, sizeof(dba_cdb));
|
||||||
|
|
||||||
#if DBA_CDB_BUILTIN
|
#if DBA_CDB_BUILTIN
|
||||||
|
@ -132,7 +132,7 @@ DBA_CLOSE_FUNC(cdb)
|
||||||
cdb_free(&cdb->c);
|
cdb_free(&cdb->c);
|
||||||
close(cdb->file);
|
close(cdb->file);
|
||||||
#endif
|
#endif
|
||||||
efree(cdb);
|
pefree(cdb, info->flags&DBA_PERSISTENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if DBA_CDB_BUILTIN
|
#if DBA_CDB_BUILTIN
|
||||||
|
|
|
@ -76,7 +76,7 @@ DBA_OPEN_FUNC(db2)
|
||||||
return FAILURE;
|
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));
|
memset(info->dbf, 0, sizeof(dba_db2_data));
|
||||||
((dba_db2_data *) info->dbf)->dbp = dbp;
|
((dba_db2_data *) info->dbf)->dbp = dbp;
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
|
@ -89,7 +89,7 @@ DBA_CLOSE_FUNC(db2)
|
||||||
if (dba->cursor)
|
if (dba->cursor)
|
||||||
dba->cursor->c_close(dba->cursor);
|
dba->cursor->c_close(dba->cursor);
|
||||||
dba->dbp->close(dba->dbp, 0);
|
dba->dbp->close(dba->dbp, 0);
|
||||||
efree(dba);
|
pefree(dba, info->flags&DBA_PERSISTENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
DBA_FETCH_FUNC(db2)
|
DBA_FETCH_FUNC(db2)
|
||||||
|
|
|
@ -81,7 +81,7 @@ DBA_OPEN_FUNC(db3)
|
||||||
#endif
|
#endif
|
||||||
dba_db3_data *data;
|
dba_db3_data *data;
|
||||||
|
|
||||||
data = emalloc(sizeof(*data));
|
data = pemalloc(sizeof(*data), info->flags&DBA_PERSISTENT);
|
||||||
data->dbp = dbp;
|
data->dbp = dbp;
|
||||||
data->cursor = NULL;
|
data->cursor = NULL;
|
||||||
info->dbf = data;
|
info->dbf = data;
|
||||||
|
@ -100,7 +100,7 @@ DBA_CLOSE_FUNC(db3)
|
||||||
|
|
||||||
if (dba->cursor) dba->cursor->c_close(dba->cursor);
|
if (dba->cursor) dba->cursor->c_close(dba->cursor);
|
||||||
dba->dbp->close(dba->dbp, 0);
|
dba->dbp->close(dba->dbp, 0);
|
||||||
efree(dba);
|
pefree(dba, info->flags&DBA_PERSISTENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
DBA_FETCH_FUNC(db3)
|
DBA_FETCH_FUNC(db3)
|
||||||
|
|
|
@ -81,7 +81,7 @@ DBA_OPEN_FUNC(db4)
|
||||||
#endif
|
#endif
|
||||||
dba_db4_data *data;
|
dba_db4_data *data;
|
||||||
|
|
||||||
data = emalloc(sizeof(*data));
|
data = pemalloc(sizeof(*data), info->flags&DBA_PERSISTENT);
|
||||||
data->dbp = dbp;
|
data->dbp = dbp;
|
||||||
data->cursor = NULL;
|
data->cursor = NULL;
|
||||||
info->dbf = data;
|
info->dbf = data;
|
||||||
|
@ -100,7 +100,7 @@ DBA_CLOSE_FUNC(db4)
|
||||||
|
|
||||||
if (dba->cursor) dba->cursor->c_close(dba->cursor);
|
if (dba->cursor) dba->cursor->c_close(dba->cursor);
|
||||||
dba->dbp->close(dba->dbp, 0);
|
dba->dbp->close(dba->dbp, 0);
|
||||||
efree(dba);
|
pefree(dba, info->flags&DBA_PERSISTENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
DBA_FETCH_FUNC(db4)
|
DBA_FETCH_FUNC(db4)
|
||||||
|
|
|
@ -78,14 +78,14 @@ DBA_OPEN_FUNC(dbm)
|
||||||
return FAILURE;
|
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));
|
memset(info->dbf, 0, sizeof(dba_dbm_data));
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
DBA_CLOSE_FUNC(dbm)
|
DBA_CLOSE_FUNC(dbm)
|
||||||
{
|
{
|
||||||
efree(info->dbf);
|
pefree(info->dbf, info->flags&DBA_PERSISTENT);
|
||||||
dbmclose();
|
dbmclose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,7 @@
|
||||||
|
|
||||||
DBA_OPEN_FUNC(flatfile)
|
DBA_OPEN_FUNC(flatfile)
|
||||||
{
|
{
|
||||||
info->dbf = emalloc(sizeof(flatfile));
|
info->dbf = pemalloc(sizeof(flatfile), info->flags&DBA_PERSISTENT);
|
||||||
memset(info->dbf, 0, sizeof(flatfile));
|
memset(info->dbf, 0, sizeof(flatfile));
|
||||||
|
|
||||||
((flatfile*)info->dbf)->fp = info->fp;
|
((flatfile*)info->dbf)->fp = info->fp;
|
||||||
|
@ -55,7 +55,7 @@ DBA_CLOSE_FUNC(flatfile)
|
||||||
|
|
||||||
if (dba->nextkey.dptr)
|
if (dba->nextkey.dptr)
|
||||||
efree(dba->nextkey.dptr);
|
efree(dba->nextkey.dptr);
|
||||||
efree(dba);
|
pefree(dba, info->flags&DBA_PERSISTENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
DBA_FETCH_FUNC(flatfile)
|
DBA_FETCH_FUNC(flatfile)
|
||||||
|
|
|
@ -59,7 +59,7 @@ DBA_OPEN_FUNC(gdbm)
|
||||||
dbf = gdbm_open(info->path, 0, gmode, filemode, NULL);
|
dbf = gdbm_open(info->path, 0, gmode, filemode, NULL);
|
||||||
|
|
||||||
if(dbf) {
|
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));
|
memset(info->dbf, 0, sizeof(dba_gdbm_data));
|
||||||
((dba_gdbm_data *) info->dbf)->dbf = dbf;
|
((dba_gdbm_data *) info->dbf)->dbf = dbf;
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
|
@ -74,7 +74,7 @@ DBA_CLOSE_FUNC(gdbm)
|
||||||
|
|
||||||
if(dba->nextkey.dptr) free(dba->nextkey.dptr);
|
if(dba->nextkey.dptr) free(dba->nextkey.dptr);
|
||||||
gdbm_close(dba->dbf);
|
gdbm_close(dba->dbf);
|
||||||
efree(dba);
|
pefree(dba, info->flags&DBA_PERSISTENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
DBA_FETCH_FUNC(gdbm)
|
DBA_FETCH_FUNC(gdbm)
|
||||||
|
|
|
@ -63,6 +63,7 @@ typedef struct dba_info {
|
||||||
#define DBA_LOCK_WCT (DBA_LOCK_WRITER|DBA_LOCK_CREAT|DBA_LOCK_TRUNC)
|
#define DBA_LOCK_WCT (DBA_LOCK_WRITER|DBA_LOCK_CREAT|DBA_LOCK_TRUNC)
|
||||||
|
|
||||||
#define DBA_STREAM_OPEN (0x0010)
|
#define DBA_STREAM_OPEN (0x0010)
|
||||||
|
#define DBA_PERSISTENT (0x0020)
|
||||||
|
|
||||||
extern zend_module_entry dba_module_entry;
|
extern zend_module_entry dba_module_entry;
|
||||||
#define dba_module_ptr &dba_module_entry
|
#define dba_module_ptr &dba_module_entry
|
||||||
|
|
|
@ -4,7 +4,7 @@ DBA CDB handler test
|
||||||
<?php
|
<?php
|
||||||
require_once('skipif.inc');
|
require_once('skipif.inc');
|
||||||
if (!in_array('cdb', dba_handlers())) die('skip CDB handler not available');
|
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--
|
--FILE--
|
||||||
<?php
|
<?php
|
||||||
|
@ -14,17 +14,17 @@ DBA CDB handler test
|
||||||
?>
|
?>
|
||||||
--EXPECT--
|
--EXPECT--
|
||||||
database handler: cdb
|
database handler: cdb
|
||||||
3NYNYY
|
5YYYYY
|
||||||
Content String 2
|
Content String 2
|
||||||
Content 2 replaced
|
array(5) {
|
||||||
Read during write: not allowed
|
["key1"]=>
|
||||||
Content 2 replaced 2nd time
|
string(16) "Content String 1"
|
||||||
The 6th value
|
|
||||||
array(3) {
|
|
||||||
["key number 6"]=>
|
|
||||||
string(13) "The 6th value"
|
|
||||||
["key2"]=>
|
["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"]=>
|
["key5"]=>
|
||||||
string(23) "The last content string"
|
string(23) "The last content string"
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,8 +6,15 @@
|
||||||
dba_insert("key3", "Third Content String", $db_file);
|
dba_insert("key3", "Third Content String", $db_file);
|
||||||
dba_insert("key4", "Another Content String", $db_file);
|
dba_insert("key4", "Another Content String", $db_file);
|
||||||
dba_insert("key5", "The last content string", $db_file);
|
dba_insert("key5", "The last content string", $db_file);
|
||||||
dba_delete("key3", $db_file);
|
if ($handler != 'cdb') {
|
||||||
dba_delete("key1", $db_file);
|
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);
|
$a = dba_firstkey($db_file);
|
||||||
$i=0;
|
$i=0;
|
||||||
while($a) {
|
while($a) {
|
||||||
|
@ -20,28 +27,32 @@
|
||||||
}
|
}
|
||||||
echo "\n";
|
echo "\n";
|
||||||
echo dba_fetch("key2", $db_file)."\n";
|
echo dba_fetch("key2", $db_file)."\n";
|
||||||
dba_replace("key2", "Content 2 replaced", $db_file);
|
if ($handler != 'cdb') {
|
||||||
echo dba_fetch("key2", $db_file)."\n";
|
dba_replace("key2", "Content 2 replaced", $db_file);
|
||||||
|
echo dba_fetch("key2", $db_file)."\n";
|
||||||
|
}
|
||||||
dba_close($db_file);
|
dba_close($db_file);
|
||||||
} else {
|
} else {
|
||||||
echo "Error creating database\n";
|
echo "Error creating database\n";
|
||||||
}
|
}
|
||||||
$db_writer = dba_open($db_filename, 'w'.$lock_flag, $handler);
|
if ($handler != 'cdb') {
|
||||||
if (($dba_reader = @dba_open($db_filename, 'r'.$lock_flag.($lock_flag ? 't' : ''), $handler))===false) {
|
$db_writer = dba_open($db_filename, 'w'.$lock_flag, $handler);
|
||||||
echo "Read during write: not allowed\n";
|
if (($dba_reader = @dba_open($db_filename, 'r'.$lock_flag.($lock_flag ? 't' : ''), $handler))===false) {
|
||||||
} else {
|
echo "Read during write: not allowed\n";
|
||||||
echo "Read during write: allowed\n";
|
} else {
|
||||||
}
|
echo "Read during write: allowed\n";
|
||||||
if ($db_writer!==FALSE) {
|
}
|
||||||
dba_insert("key number 6", "The 6th value", $db_writer);
|
if ($db_writer!==FALSE) {
|
||||||
@dba_insert("key number 6", "The 6th value inserted again would be an error", $db_writer);
|
dba_insert("key number 6", "The 6th value", $db_writer);
|
||||||
dba_replace("key2", "Content 2 replaced 2nd time", $db_writer);
|
@dba_insert("key number 6", "The 6th value inserted again would be an error", $db_writer);
|
||||||
dba_delete("key4", $db_writer);
|
dba_replace("key2", "Content 2 replaced 2nd time", $db_writer);
|
||||||
echo dba_fetch("key2", $db_writer)."\n";
|
dba_delete("key4", $db_writer);
|
||||||
echo dba_fetch("key number 6", $db_writer)."\n";
|
echo dba_fetch("key2", $db_writer)."\n";
|
||||||
dba_close($db_writer); // when the writer is open at least db3 would fail because of buffered io.
|
echo dba_fetch("key number 6", $db_writer)."\n";
|
||||||
} else {
|
dba_close($db_writer); // when the writer is open at least db3 would fail because of buffered io.
|
||||||
die("Error reopening database\n");
|
} else {
|
||||||
|
die("Error reopening database\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (($db_file = dba_open($db_filename, 'r'.$lock_flag, $handler))!==FALSE) {
|
if (($db_file = dba_open($db_filename, 'r'.$lock_flag, $handler))!==FALSE) {
|
||||||
$key = dba_firstkey($db_file);
|
$key = dba_firstkey($db_file);
|
||||||
|
@ -59,4 +70,6 @@
|
||||||
if ($dba_reader) {
|
if ($dba_reader) {
|
||||||
dba_close($dba_reader);
|
dba_close($dba_reader);
|
||||||
}
|
}
|
||||||
|
if (($db_file = dba_popen($db_filename, 'r'.($handler!='gdbm'?'-':''), $handler))!==FALSE) {
|
||||||
|
}
|
||||||
?>
|
?>
|
Loading…
Add table
Add a link
Reference in a new issue