Hi,
I don't know if array_combine()
was intentionally made binary-key unsafe,
but it seems wrong and inconsistent since binary keys work everywhere else I
can think of -- including array_flip()
and the new array_fill_keys()
. And
updating it is a bit of an optimization by eliminating strlen()
calls. :-)
I also changed the error message to be more grammatically-correct and fixed
some typos in the description.
http://www.realplain.com/php/array_combine_binkey.diff
http://www.realplain.com/php/array_combine_binkey_5_2.diff
Thanks,
Matt
Hi,
There are 46 uses of add_assoc_zval() in the CVS. Many are with fixed
length strings for the key. Should the others all be using
add_assoc_zval_ex() ?
Hi,
I don't know if
array_combine()
was intentionally made binary-key unsafe,
but it seems wrong and inconsistent since binary keys work everywhere else I
can think of -- includingarray_flip()
and the newarray_fill_keys()
. And
updating it is a bit of an optimization by eliminatingstrlen()
calls. :-)I also changed the error message to be more grammatically-correct and fixed
some typos in the description.http://www.realplain.com/php/array_combine_binkey.diff
http://www.realplain.com/php/array_combine_binkey_5_2.diffThanks,
Matt--
--
Richard Quadling
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
"Standing on the shoulders of some very clever giants!"
Hi Richard,
I think I've seen those instances that you're referring to. By fixed length
string I assume you mean hard-coded "string_key". Yeah, I would think those
should use add_assoc_*_ex() since the length is known (sizeof("string_key")
etc.) to save unnecessary strlen()
calls.
Unless compilers optimize the strlen("string_key") + 1 to a constant from
the add_assoc_*() macro. But I wouldn't think that's the case...? :-/
Matt
----- Original Message -----
From: "Richard Quadling"
Sent: Friday, July 21, 2006
Hi,
There are 46 uses of add_assoc_zval() in the CVS. Many are with fixed
length strings for the key. Should the others all be using
add_assoc_zval_ex() ?Hi,
I don't know if
array_combine()
was intentionally made binary-key
unsafe,
but it seems wrong and inconsistent since binary keys work everywhere
else I
can think of -- includingarray_flip()
and the newarray_fill_keys()
.
And
updating it is a bit of an optimization by eliminatingstrlen()
calls.
:-)I also changed the error message to be more grammatically-correct and
fixed
some typos in the description.http://www.realplain.com/php/array_combine_binkey.diff
http://www.realplain.com/php/array_combine_binkey_5_2.diffThanks,
Matt
Yeah, that's probably a good idea. You can submit a patch if you
want. :)
-Andrei
Hi Richard,
I think I've seen those instances that you're referring to. By
fixed length
string I assume you mean hard-coded "string_key". Yeah, I would
think those
should use add_assoc_*_ex() since the length is known (sizeof
("string_key")
etc.) to save unnecessarystrlen()
calls.Unless compilers optimize the strlen("string_key") + 1 to a
constant from
the add_assoc_*() macro. But I wouldn't think that's the case...? :-/Matt
Hi Andrei,
I see you applied my patch. However, the 5.2 code still isn't binary-key
safe (you only changed the second occurrence of add_assoc_zval to the _ex
version). Or was that intentional and you only want to change the behavior
in 6?
And you know 5.2's description is still wrong -- with "keys" at the end
instead of "values"? :-) When you changed that part in HEAD last week, you
also added a "the" -- "... as the corresponding values" -- which was in
my patch, if you want both branches exactly the same. :-P
Matt
P.S. The other patch you're talking about below... I think Richard Quadling
said he'll do it.
----- Original Message -----
From: "Andrei Zmievski"
Sent: Friday, July 21, 2006
Yeah, that's probably a good idea. You can submit a patch if you
want. :)-Andrei
Hi Richard,
I think I've seen those instances that you're referring to. By
fixed length
string I assume you mean hard-coded "string_key". Yeah, I would
think those
should use add_assoc_*_ex() since the length is known (sizeof
("string_key")
etc.) to save unnecessarystrlen()
calls.Unless compilers optimize the strlen("string_key") + 1 to a
constant from
the add_assoc_*() macro. But I wouldn't think that's the case...? :-/Matt
Matt W wrote:
Hi Andrei,
I see you applied my patch.
Testing with a php5.2-200607222030 snaps having
/* $Id: array.c,v 1.308.2.21.2.7 2006/07/22 16:58:39 andrei Exp $ */
Looks by me as the ext/standard/tests/array/array_combine.phpt fails
Is it by me ?
$ diff -W 60 -y --suppress-common-lines
ext/standard/tests/array/array_combine.exp
ext/standard/tests/array/array_combine.out
[green] => green | [gree] => green
[red] => red | [re] => red
[yellow] => yellow | [yello] => yellow
[green] => 1 | [gree] => 1
[red] => 2 | [re] => 2
[yellow] => 3 | [yello] => 3
[green] => 0 | [gree] => 0
[red] => 1 | [re] => 1
[yellow] => 2 | [yello] => 2
[green] => 1 | [gree] => 1
[red] => | [re] =>
[yellow] => | [yello] =>
[1] => green | [] => green
[2] => red | [] => red
[3] => yellow | [] => yellow
[1] => 1 | [] => 1
[2] => 2 | [] => 2
[3] => 3 | [] => 3
[1] => 0 | [] => 0
[2] => 1 | [] => 1
[3] => 2 | [] => 2
[1] => 1 | [] => 1
[2] => | [] =>
[3] => | [] =>
PHP : /home/bertrand/php/php5.2-200607222030/sapi/cli/php
PHP_SAPI
: cli
PHP_VERSION
: 5.2.0-dev
ZEND_VERSION: 2.2.0
PHP_OS
: Linux - Linux ancilla.toggg.net 2.6.12-1.1381_FC3 #1 Fri
Oct 21 03 :46:55 EDT 2005 i686
Configure Command => './configure'
Sorry for the noise , case I did something wrong , but what ?
(or case it is repaired in the mean time)
toggg
Hi,
----- Original Message -----
From: "bertrand Gugger"
Sent: Monday, July 24, 2006
Matt W wrote:
Hi Andrei,
I see you applied my patch.
Testing with a php5.2-200607222030 snaps having
/* $Id: array.c,v 1.308.2.21.2.7 2006/07/22 16:58:39 andrei Exp $ */Looks by me as the ext/standard/tests/array/array_combine.phpt fails
Is it by me ?$ diff -W 60 -y --suppress-common-lines
ext/standard/tests/array/array_combine.exp
ext/standard/tests/array/array_combine.out
[green] => green | [gree] => green
[red] => red | [re] => red
[yellow] => yellow | [yello] => yellow
[green] => 1 | [gree] => 1
[red] => 2 | [re] => 2
[yellow] => 3 | [yello] => 3
[green] => 0 | [gree] => 0
[red] => 1 | [re] => 1
[yellow] => 2 | [yello] => 2
[green] => 1 | [gree] => 1
[red] => | [re] =>
[yellow] => | [yello] =>
[1] => green | [] => green
[2] => red | [] => red
[3] => yellow | [] => yellow
[1] => 1 | [] => 1
[2] => 2 | [] => 2
[3] => 3 | [] => 3
[1] => 0 | [] => 0
[2] => 1 | [] => 1
[3] => 2 | [] => 2
[1] => 1 | [] => 1
[2] => | [] =>
[3] => | [] =>PHP : /home/bertrand/php/php5.2-200607222030/sapi/cli/php
PHP_SAPI
: cli
PHP_VERSION
: 5.2.0-dev
ZEND_VERSION: 2.2.0
PHP_OS
: Linux - Linux ancilla.toggg.net 2.6.12-1.1381_FC3 #1 Fri
Oct 21 03 :46:55 EDT 2005 i686Configure Command => './configure'
Sorry for the noise , case I did something wrong , but what ?
(or case it is repaired in the mean time)
Nope, it's broken. :-) I was confused as to why Andrei only fully applied
my patch for HEAD, and seemed to manually "take part of" the 5.2 patch (I
thought the binary key change was unwanted in 5.2, but he did update it
then). Now it needs a 4th update... shrug :-)
Andrei, in the first add_assoc_zval_ex(), after Z_STRLEN_PP(entry_keys), you
forgot the +1.
--
toggg
It wasn't your fault, good catch. ;-)
Matt
Fixed now.
-Andrei
Hi,
----- Original Message -----
From: "bertrand Gugger"
Sent: Monday, July 24, 2006Matt W wrote:
Hi Andrei,
I see you applied my patch.
Testing with a php5.2-200607222030 snaps having
/* $Id: array.c,v 1.308.2.21.2.7 2006/07/22 16:58:39 andrei Exp $ */Looks by me as the ext/standard/tests/array/array_combine.phpt fails
Is it by me ?$ diff -W 60 -y --suppress-common-lines
ext/standard/tests/array/array_combine.exp
ext/standard/tests/array/array_combine.out
[green] => green | [gree] => green
[red] => red | [re] => red
[yellow] => yellow | [yello] => yellow
[green] => 1 | [gree] => 1
[red] => 2 | [re] => 2
[yellow] => 3 | [yello] => 3
[green] => 0 | [gree] => 0
[red] => 1 | [re] => 1
[yellow] => 2 | [yello] => 2
[green] => 1 | [gree] => 1
[red] => | [re] =>
[yellow] => | [yello] =>
[1] => green | [] => green
[2] => red | [] => red
[3] => yellow | [] => yellow
[1] => 1 | [] => 1
[2] => 2 | [] => 2
[3] => 3 | [] => 3
[1] => 0 | [] => 0
[2] => 1 | [] => 1
[3] => 2 | [] => 2
[1] => 1 | [] => 1
[2] => | [] =>
[3] => | [] =>PHP : /home/bertrand/php/php5.2-200607222030/sapi/cli/php
PHP_SAPI
: cli
PHP_VERSION
: 5.2.0-dev
ZEND_VERSION: 2.2.0
PHP_OS
: Linux - Linux ancilla.toggg.net 2.6.12-1.1381_FC3 #1
Fri
Oct 21 03 :46:55 EDT 2005 i686Configure Command => './configure'
Sorry for the noise , case I did something wrong , but what ?
(or case it is repaired in the mean time)Nope, it's broken. :-) I was confused as to why Andrei only fully
applied
my patch for HEAD, and seemed to manually "take part of" the 5.2
patch (I
thought the binary key change was unwanted in 5.2, but he did
update it
then). Now it needs a 4th update... shrug :-)Andrei, in the first add_assoc_zval_ex(), after Z_STRLEN_PP
(entry_keys), you
forgot the +1.--
togggIt wasn't your fault, good catch. ;-)
Matt
Is the patch to use the _ex functions needed?
Fixed now.
-Andrei
Hi,
----- Original Message -----
From: "bertrand Gugger"
Sent: Monday, July 24, 2006Matt W wrote:
Hi Andrei,
I see you applied my patch.
Testing with a php5.2-200607222030 snaps having
/* $Id: array.c,v 1.308.2.21.2.7 2006/07/22 16:58:39 andrei Exp $ */Looks by me as the ext/standard/tests/array/array_combine.phpt fails
Is it by me ?$ diff -W 60 -y --suppress-common-lines
ext/standard/tests/array/array_combine.exp
ext/standard/tests/array/array_combine.out
[green] => green | [gree] => green
[red] => red | [re] => red
[yellow] => yellow | [yello] => yellow
[green] => 1 | [gree] => 1
[red] => 2 | [re] => 2
[yellow] => 3 | [yello] => 3
[green] => 0 | [gree] => 0
[red] => 1 | [re] => 1
[yellow] => 2 | [yello] => 2
[green] => 1 | [gree] => 1
[red] => | [re] =>
[yellow] => | [yello] =>
[1] => green | [] => green
[2] => red | [] => red
[3] => yellow | [] => yellow
[1] => 1 | [] => 1
[2] => 2 | [] => 2
[3] => 3 | [] => 3
[1] => 0 | [] => 0
[2] => 1 | [] => 1
[3] => 2 | [] => 2
[1] => 1 | [] => 1
[2] => | [] =>
[3] => | [] =>PHP : /home/bertrand/php/php5.2-200607222030/sapi/cli/php
PHP_SAPI
: cli
PHP_VERSION
: 5.2.0-dev
ZEND_VERSION: 2.2.0
PHP_OS
: Linux - Linux ancilla.toggg.net 2.6.12-1.1381_FC3 #1
Fri
Oct 21 03 :46:55 EDT 2005 i686Configure Command => './configure'
Sorry for the noise , case I did something wrong , but what ?
(or case it is repaired in the mean time)Nope, it's broken. :-) I was confused as to why Andrei only fully
applied
my patch for HEAD, and seemed to manually "take part of" the 5.2
patch (I
thought the binary key change was unwanted in 5.2, but he did
update it
then). Now it needs a 4th update... shrug :-)Andrei, in the first add_assoc_zval_ex(), after Z_STRLEN_PP
(entry_keys), you
forgot the +1.--
togggIt wasn't your fault, good catch. ;-)
Matt
--
--
--
Richard Quadling
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
"Standing on the shoulders of some very clever giants!"
Most compiler (I know gcc and Visual C do) will optimize strlen
("static_string").
Hi Richard,
I think I've seen those instances that you're referring to. By
fixed length
string I assume you mean hard-coded "string_key". Yeah, I would
think those
should use add_assoc_*_ex() since the length is known (sizeof
("string_key")
etc.) to save unnecessarystrlen()
calls.Unless compilers optimize the strlen("string_key") + 1 to a
constant from
the add_assoc_*() macro. But I wouldn't think that's the case...? :-/Matt
----- Original Message -----
From: "Richard Quadling"
Sent: Friday, July 21, 2006Hi,
There are 46 uses of add_assoc_zval() in the CVS. Many are with
fixed
length strings for the key. Should the others all be using
add_assoc_zval_ex() ?Hi,
I don't know if
array_combine()
was intentionally made binary-key
unsafe,
but it seems wrong and inconsistent since binary keys work
everywhere
else I
can think of -- includingarray_flip()
and the new array_fill_keys
().
And
updating it is a bit of an optimization by eliminatingstrlen()
calls.
:-)I also changed the error message to be more grammatically-correct
and
fixed
some typos in the description.http://www.realplain.com/php/array_combine_binkey.diff
http://www.realplain.com/php/array_combine_binkey_5_2.diffThanks,
Matt--
Ilia Alshanetsky
Either way, is it worth committing the patch ?
1 - For the non-optimizing compilers.
2 - Consistency across all source - static string use sizeof()
rather
than strlen()
+1
If so, I'll need to amend the patch to NOT use +1, though judging by
the comments made by bertrand Gugger, maybe something needs to be
revisited.
Most compiler (I know gcc and Visual C do) will optimize
strlen("static_string").Hi Richard,
I think I've seen those instances that you're referring to. By fixed length
string I assume you mean hard-coded "string_key". Yeah, I would think those
should use add_assoc_*_ex() since the length is known (sizeof("string_key")
etc.) to save unnecessarystrlen()
calls.Unless compilers optimize the strlen("string_key") + 1 to a constant from
the add_assoc_*() macro. But I wouldn't think that's the case...? :-/Matt
--
Richard Quadling
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
"Standing on the shoulders of some very clever giants!"