Skip to content

Commit 38fce78

Browse files
committed
Merge branch 'PHP-8.4'
* PHP-8.4: [skip ci] Update NEWS Fix bug and add test for dba_open same file twice (#17979)
2 parents 9d60dc1 + bb4174e commit 38fce78

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

ext/dba/dba.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ ZEND_BEGIN_MODULE_GLOBALS(dba)
5757
const char *default_handler;
5858
const dba_handler *default_hptr;
5959
HashTable connections;
60+
unsigned int connection_counter;
6061
ZEND_END_MODULE_GLOBALS(dba)
6162

6263
ZEND_DECLARE_MODULE_GLOBALS(dba)
@@ -569,7 +570,7 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, bool persistent)
569570
}
570571

571572
zend_string *resource_key = zend_strpprintf(0,
572-
"dba_%d_%s_%s_%s", persistent, ZSTR_VAL(path), ZSTR_VAL(mode), handler_str ? ZSTR_VAL(handler_str) : ""
573+
"dba_%d_%u_%s_%s_%s", persistent, persistent ? 0 : DBA_G(connection_counter)++, ZSTR_VAL(path), ZSTR_VAL(mode), handler_str ? ZSTR_VAL(handler_str) : ""
573574
);
574575

575576
if (persistent) {

ext/dba/tests/dba_duplicateopen.phpt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
--TEST--
2+
DBA open same read only file multiple times
3+
--EXTENSIONS--
4+
dba
5+
--SKIPIF--
6+
<?php
7+
require_once __DIR__ . '/setup/setup_dba_tests.inc';
8+
check_skip('cdb_make');
9+
?>
10+
--CONFLICTS--
11+
test.cdb
12+
--FILE--
13+
<?php
14+
echo "database handler: cdb\n";
15+
$handler = 'cdb';
16+
$db_filename = __DIR__.'/test.cdb';
17+
if (($db_file=dba_open($db_filename, "r", $handler))!==FALSE) {
18+
echo dba_fetch(1, $db_file);
19+
if (($db_file2=dba_open($db_filename, "r", $handler))!==FALSE) {
20+
echo dba_fetch(1, $db_file2);
21+
echo dba_fetch(2, $db_file2);
22+
dba_close($db_file2);
23+
} else {
24+
echo "Error opening database 2nd time\n";
25+
}
26+
echo dba_fetch(2, $db_file);
27+
dba_close($db_file);
28+
} else {
29+
echo "Error opening database\n";
30+
}
31+
?>
32+
--EXPECT--
33+
database handler: cdb
34+
1122

0 commit comments

Comments
 (0)