Print "interned" instead of fake refcount in debug_zval_dump()

debug_zval_dump() currently prints refcount 1 for interned strings
and arrays, which does not really reflect the truth. These values
are not refcounted, so the refcount is misleading. Instead print
an "interned" tag.

Closes GH-6598.
This commit is contained in:
Nikita Popov 2021-01-12 10:26:17 +01:00
parent 869221cfb6
commit e2c8ab7c33
15 changed files with 122 additions and 109 deletions

View File

@ -7,16 +7,16 @@ Bug #26639 (mb_convert_variables() clutters variables beyond the references)
$a = "‚ ‚¢‚¤‚¦‚¨";
$b = $a;
mb_convert_variables("EUC-JP", "Shift_JIS", $b);
debug_zval_dump($a);
debug_zval_dump($b);
var_dump($a);
var_dump($b);
unset($a);
unset($b);
$a = "‚ ‚¢‚¤‚¦‚¨";
$b = &$a;
mb_convert_variables("EUC-JP", "Shift_JIS", $b);
debug_zval_dump($a);
debug_zval_dump($b);
var_dump($a);
var_dump($b);
unset($a);
unset($b);
@ -24,8 +24,8 @@ $a = "
$b = array($a);
$c = $b;
mb_convert_variables("EUC-JP", "Shift_JIS", $c);
debug_zval_dump($b);
debug_zval_dump($c);
var_dump($b);
var_dump($c);
unset($a);
unset($b);
unset($c);
@ -34,8 +34,8 @@ $a = "
$b = array(&$a);
$c = $b;
mb_convert_variables("EUC-JP", "Shift_JIS", $c);
debug_zval_dump($b);
debug_zval_dump($c);
var_dump($b);
var_dump($c);
unset($a);
unset($b);
unset($c);
@ -44,8 +44,8 @@ $a = "
$b = array($a);
$c = &$b;
mb_convert_variables("EUC-JP", "Shift_JIS", $c);
debug_zval_dump($b);
debug_zval_dump($c);
var_dump($b);
var_dump($c);
unset($a);
unset($b);
unset($c);
@ -54,8 +54,8 @@ $a = "
$b = array(&$a);
$c = &$b;
mb_convert_variables("EUC-JP", "Shift_JIS", $c);
debug_zval_dump($b);
debug_zval_dump($c);
var_dump($b);
var_dump($c);
unset($a);
unset($b);
unset($c);
@ -64,60 +64,60 @@ $a = array(array("
$b = $a;
$c = $b;
mb_convert_variables("EUC-JP", "Shift_JIS", $c);
debug_zval_dump($b);
debug_zval_dump($c);
var_dump($b);
var_dump($c);
unset($a);
unset($b);
unset($c);
?>
--EXPECTF--
string(10) "あいうえお" refcount(%d)
string(10) "、「、、、ヲ、ィ、ェ" refcount(%d)
string(10) "、「、、、ヲ、ィ、ェ" refcount(%d)
string(10) "、「、、、ヲ、ィ、ェ" refcount(%d)
array(1) refcount(%d){
--EXPECT--
string(10) "あいうえお"
string(10) "、「、、、ヲ、ィ、ェ"
string(10) "、「、、、ヲ、ィ、ェ"
string(10) "、「、、、ヲ、ィ、ェ"
array(1) {
[0]=>
string(10) "あいうえお" refcount(%d)
string(10) "あいうえお"
}
array(1) refcount(%d){
array(1) {
[0]=>
string(10) "、「、、、ヲ、ィ、ェ" refcount(%d)
string(10) "、「、、、ヲ、ィ、ェ"
}
array(1) refcount(%d){
array(1) {
[0]=>
&string(10) "あいうえお" refcount(%d)
&string(10) "あいうえお"
}
array(1) refcount(%d){
array(1) {
[0]=>
string(10) "、「、、、ヲ、ィ、ェ" refcount(%d)
string(10) "、「、、、ヲ、ィ、ェ"
}
array(1) refcount(%d){
array(1) {
[0]=>
string(10) "、「、、、ヲ、ィ、ェ" refcount(%d)
string(10) "、「、、、ヲ、ィ、ェ"
}
array(1) refcount(%d){
array(1) {
[0]=>
string(10) "、「、、、ヲ、ィ、ェ" refcount(%d)
string(10) "、「、、、ヲ、ィ、ェ"
}
array(1) refcount(%d){
array(1) {
[0]=>
string(10) "、「、、、ヲ、ィ、ェ" refcount(%d)
string(10) "、「、、、ヲ、ィ、ェ"
}
array(1) refcount(%d){
array(1) {
[0]=>
string(10) "、「、、、ヲ、ィ、ェ" refcount(%d)
string(10) "、「、、、ヲ、ィ、ェ"
}
array(1) refcount(%d){
array(1) {
[0]=>
array(1) refcount(%d){
array(1) {
[0]=>
string(10) "あいうえお" refcount(%d)
string(10) "あいうえお"
}
}
array(1) refcount(%d){
array(1) {
[0]=>
array(1) refcount(%d){
array(1) {
[0]=>
string(10) "、「、、、ヲ、ィ、ェ" refcount(%d)
string(10) "、「、、、ヲ、ィ、ェ"
}
}

View File

@ -5,6 +5,8 @@ References to result sets
require_once('skipif.inc');
require_once('skipifconnectfailure.inc');
?>
--INI--
opcache.enable=0
--FILE--
<?php
require_once('connect.inc');
@ -136,9 +138,9 @@ array(1) refcount(2){
[0]=>
array(2) refcount(1){
["id"]=>
string(1) "1" refcount(%d)
string(1) "1" interned
["label"]=>
string(1) "a" refcount(%d)
string(1) "a" interned
}
}
done!

View File

@ -59,14 +59,14 @@ array(1) refcount(%d){
["row_copy"]=>
array(2) refcount(1){
["id"]=>
string(1) "1" refcount(%d)
string(1) "1" interned
["label"]=>
string(1) "a" refcount(%d)
string(1) "a" interned
}
["id_ref"]=>
string(1) "1" refcount(%d)
string(1) "1" interned
["id_copy"]=>
string(1) "1" refcount(%d)
string(1) "1" interned
}
}
array(2) refcount(%d){
@ -77,35 +77,35 @@ array(2) refcount(%d){
["row_copy"]=>
array(2) refcount(%d){
["id"]=>
string(1) "1" refcount(%d)
string(1) "1" interned
["label"]=>
string(1) "a" refcount(%d)
string(1) "a" interned
}
["id_ref"]=>
string(1) "1" refcount(%d)
string(1) "1" interned
["id_copy"]=>
string(1) "1" refcount(%d)
string(1) "1" interned
}
[1]=>
array(5) refcount(%d){
["row_ref"]=>
&array(2) refcount(%d){
["id"]=>
&string(1) "2" refcount(%d)
&string(1) "2" interned
["label"]=>
string(1) "b" refcount(%d)
string(1) "b" interned
}
["row_copy"]=>
array(2) refcount(%d){
["id"]=>
string(1) "2" refcount(%d)
string(1) "2" interned
["label"]=>
string(1) "b" refcount(%d)
string(1) "b" interned
}
["id_ref"]=>
&string(1) "2" refcount(%d)
&string(1) "2" interned
["id_copy"]=>
string(1) "2" refcount(%d)
string(1) "2" interned
["id_copy_mod"]=>
int(2)
}

View File

@ -7,35 +7,35 @@ error_reporting(E_ALL);
$a = unpack('C2', "\0224V");
$b = array(1 => 18, 2 => 52);
debug_zval_dump($a, $b);
var_dump($a, $b);
$k = array_keys($a);
$l = array_keys($b);
debug_zval_dump($k, $l);
var_dump($k, $l);
$i=$k[0];
var_dump($a[$i]);
$i=$l[0];
var_dump($b[$i]);
?>
--EXPECTF--
array(2) refcount(%d){
--EXPECT--
array(2) {
[1]=>
int(18)
[2]=>
int(52)
}
array(2) refcount(%d){
array(2) {
[1]=>
int(18)
[2]=>
int(52)
}
array(2) refcount(%d){
array(2) {
[0]=>
int(1)
[1]=>
int(2)
}
array(2) refcount(%d){
array(2) {
[0]=>
int(1)
[1]=>

View File

@ -21,7 +21,7 @@ function foo($ref, $alt) {
$b = NULL;
}
debug_zval_dump($a, $b, $GLOBALS['a'], $GLOBALS['b']);
var_dump($a, $b, $GLOBALS['a'], $GLOBALS['b']);
echo "--\n";
if ($alt) {
$a = &$GLOBALS['a'];
@ -29,25 +29,25 @@ function foo($ref, $alt) {
} else {
extract($GLOBALS, EXTR_REFS);
}
debug_zval_dump($a, $b, $GLOBALS['a'], $GLOBALS['b']);
var_dump($a, $b, $GLOBALS['a'], $GLOBALS['b']);
echo "--\n";
$a = &$GLOBALS['a'];
$b = &$GLOBALS['b'];
debug_zval_dump($a, $b, $GLOBALS['a'], $GLOBALS['b']);
var_dump($a, $b, $GLOBALS['a'], $GLOBALS['b']);
echo "--\n";
$GLOBALS['b'] = 3;
debug_zval_dump($a, $b, $GLOBALS['a'], $GLOBALS['b']);
var_dump($a, $b, $GLOBALS['a'], $GLOBALS['b']);
echo "--\n";
$a = 4;
debug_zval_dump($a, $b, $GLOBALS['a'], $GLOBALS['b']);
var_dump($a, $b, $GLOBALS['a'], $GLOBALS['b']);
echo "--\n";
$c = $b;
debug_zval_dump($b, $GLOBALS['b'], $c);
var_dump($b, $GLOBALS['b'], $c);
echo "--\n";
$b = 'x';
debug_zval_dump($a, $b, $GLOBALS['a'], $GLOBALS['b'], $c);
var_dump($a, $b, $GLOBALS['a'], $GLOBALS['b'], $c);
echo "--\n";
debug_zval_dump($org_a, $org_b);
var_dump($org_a, $org_b);
echo "----";
if ($ref) echo 'r';
if ($alt) echo 'a';
@ -64,9 +64,9 @@ foo(true, true);
foo(false, false);
foo(true, false);
debug_zval_dump($_a, $_b);
var_dump($_a, $_b);
?>
--EXPECTF--
--EXPECT--
NULL
NULL
int(1)
@ -97,9 +97,9 @@ int(3)
int(3)
--
int(4)
string(1) "x" refcount(%d)
string(1) "x"
int(4)
string(1) "x" refcount(%d)
string(1) "x"
int(3)
--
int(1)
@ -135,9 +135,9 @@ int(3)
int(3)
--
int(4)
string(1) "x" refcount(%d)
string(1) "x"
int(4)
string(1) "x" refcount(%d)
string(1) "x"
int(3)
--
int(1)
@ -173,9 +173,9 @@ int(3)
int(3)
--
int(4)
string(1) "x" refcount(%d)
string(1) "x"
int(4)
string(1) "x" refcount(%d)
string(1) "x"
int(3)
--
int(1)
@ -211,13 +211,13 @@ int(3)
int(3)
--
int(4)
string(1) "x" refcount(%d)
string(1) "x"
int(4)
string(1) "x" refcount(%d)
string(1) "x"
int(3)
--
int(1)
int(2)
----r
string(2) "ok" refcount(%d)
string(2) "ok" refcount(%d)
string(2) "ok"
string(2) "ok"

View File

@ -12,5 +12,5 @@ debug_zval_dump($a);
--EXPECTF--
array(1) refcount(%d){
["test"]=>
string(3) "xxx" refcount(%d)
string(3) "xxx" interned
}

View File

@ -3,7 +3,7 @@ Test extract() for overwrite of GLOBALS
--FILE--
<?php
$str = "John";
debug_zval_dump($GLOBALS["str"]);
var_dump($GLOBALS["str"]);
/* Extracting Global Variables */
$splat = array("foo" => "bar");
@ -11,13 +11,13 @@ var_dump(extract(array("GLOBALS" => $splat, EXTR_OVERWRITE)));
unset ($splat);
debug_zval_dump($GLOBALS["str"]);
var_dump($GLOBALS["str"]);
echo "\nDone";
?>
--EXPECTF--
string(4) "John" refcount(%d)
--EXPECT--
string(4) "John"
int(1)
string(4) "John" refcount(%d)
string(4) "John"
Done

View File

@ -6,21 +6,21 @@ Test extract() function (variation 1)
$val = 4;
$str = "John";
debug_zval_dump($val);
debug_zval_dump($str);
var_dump($val);
var_dump($str);
/* Extracting Global Variables */
var_dump(extract($GLOBALS, EXTR_REFS));
debug_zval_dump($val);
debug_zval_dump($str);
var_dump($val);
var_dump($str);
echo "\nDone";
?>
--EXPECTF--
int(4)
string(4) "John" refcount(%d)
string(4) "John"
int(%d)
int(4)
string(4) "John" refcount(%d)
string(4) "John"
Done

View File

@ -23,20 +23,20 @@ function & test2($arg1, $arg2)
function test($func)
{
debug_zval_dump($func('Direct', 'Call'));
debug_zval_dump(call_user_func_array($func, array('User', 'Func')));
var_dump($func('Direct', 'Call'));
var_dump(call_user_func_array($func, array('User', 'Func')));
}
test('test1');
test('test2');
?>
--EXPECTF--
--EXPECT--
Direct Call
string(5) "test1" refcount(%d)
string(5) "test1"
User Func
string(5) "test1" refcount(%d)
string(5) "test1"
Direct Call
string(5) "test2" refcount(%d)
string(5) "test2"
User Func
string(5) "test2" refcount(%d)
string(5) "test2"

View File

@ -2,6 +2,8 @@
Test debug_zval_dump() function : working on objects
--SKIPIF--
<?php if (PHP_ZTS) { print "skip only for no-zts build"; }
--INI--
opcache.enable=0
--FILE--
<?php
function zval_dump( $values ) {

View File

@ -188,11 +188,11 @@ NULL
-- Iteration 4 --
NULL
-- Iteration 5 --
string(7) "TRUE123" refcount(%d)
string(7) "TRUE123" interned
-- Iteration 6 --
string(9) "123string" refcount(%d)
string(9) "123string" interned
-- Iteration 7 --
string(9) "string123" refcount(%d)
string(9) "string123" interned
-- Iteration 8 --
string(10) "NULLstring" refcount(%d)
string(10) "NULLstring" interned
Done

View File

@ -299,7 +299,11 @@ again:
case IS_STRING:
php_printf("%sstring(%zd) \"", COMMON, Z_STRLEN_P(struc));
PHPWRITE(Z_STRVAL_P(struc), Z_STRLEN_P(struc));
php_printf("\" refcount(%u)\n", Z_REFCOUNTED_P(struc) ? Z_REFCOUNT_P(struc) : 1);
if (Z_REFCOUNTED_P(struc)) {
php_printf("\" refcount(%u)\n", Z_REFCOUNT_P(struc));
} else {
PUTS("\" interned\n");
}
break;
case IS_ARRAY:
myht = Z_ARRVAL_P(struc);
@ -312,7 +316,12 @@ again:
GC_PROTECT_RECURSION(myht);
}
count = zend_hash_num_elements(myht);
php_printf("%sarray(%d) refcount(%u){\n", COMMON, count, Z_REFCOUNTED_P(struc) ? Z_REFCOUNT_P(struc) - 1 : 1);
if (Z_REFCOUNTED_P(struc)) {
/* -1 because of ADDREF above. */
php_printf("%sarray(%d) refcount(%u){\n", COMMON, count, Z_REFCOUNT_P(struc) - 1);
} else {
php_printf("%sarray(%d) interned {\n", COMMON, count);
}
ZEND_HASH_FOREACH_KEY_VAL(myht, index, key, val) {
zval_array_element_dump(val, index, key, level);
} ZEND_HASH_FOREACH_END();