summaryrefslogtreecommitdiff
path: root/Zend
diff options
context:
space:
mode:
authorOndřej Surý <ondrej@sury.org>2012-05-31 10:55:48 +0200
committerOndřej Surý <ondrej@sury.org>2012-05-31 10:55:48 +0200
commit90ceaa9e92fadfef4c21ec0f76063c4387beb561 (patch)
tree42c54fe576b4513fa12eb949ce67bda472411abc /Zend
parent01c525f668ecff08bea21c4ff22745b8f77e8c3a (diff)
downloadphp-90ceaa9e92fadfef4c21ec0f76063c4387beb561.tar.gz
Imported Upstream version 5.4.4~rc2upstream/5.4.4_rc2
Diffstat (limited to 'Zend')
-rw-r--r--Zend/tests/bug62097.phpt17
-rw-r--r--Zend/tests/traits/bug61998.phpt68
-rw-r--r--Zend/zend_compile.c19
-rw-r--r--Zend/zend_multibyte.c2
-rw-r--r--Zend/zend_opcode.c6
-rw-r--r--Zend/zend_operators.c6
6 files changed, 108 insertions, 10 deletions
diff --git a/Zend/tests/bug62097.phpt b/Zend/tests/bug62097.phpt
new file mode 100644
index 000000000..07e93bfa8
--- /dev/null
+++ b/Zend/tests/bug62097.phpt
@@ -0,0 +1,17 @@
+--TEST--
+Bug #62097: fix for bug #54547 is wrong for 32-bit machines
+--SKIPIF--
+<?php
+if (PHP_INT_MAX !== 2147483647)
+ die('skip for system with 32-bit wide longs only');
+--FILE--
+<?php
+var_dump("02147483647" == "2147483647",
+ "02147483648" == "2147483648",
+ "09007199254740991" == "9007199254740991",
+ "09007199254740992" == "9007199254740992");
+--EXPECT--
+bool(true)
+bool(true)
+bool(true)
+bool(false)
diff --git a/Zend/tests/traits/bug61998.phpt b/Zend/tests/traits/bug61998.phpt
new file mode 100644
index 000000000..612caa066
--- /dev/null
+++ b/Zend/tests/traits/bug61998.phpt
@@ -0,0 +1,68 @@
+--TEST--
+Bug #61998 (Using traits with method aliases appears to result in crash during execution)
+--FILE--
+<?php
+class Foo {
+ use T1 {
+ func as newFunc;
+ }
+
+ public function func() {
+ echo "From Foo\n";
+ }
+}
+
+trait T1 {
+ public function func() {
+ echo "From T1\n";
+ }
+}
+
+class Bar {
+ public function func() {
+ echo "From Bar\n";
+ }
+ public function func2() {
+ echo "From Bar\n";
+ }
+ public function func3() {
+ echo "From Bar\n";
+ }
+ use T1 {
+ func as newFunc;
+ func as func2;
+ }
+ use T2 {
+ func2 as newFunc2;
+ func2 as newFunc3;
+ func2 as func3;
+ }
+}
+
+trait T2 {
+ public function func2() {
+ echo "From T2\n";
+ }
+}
+
+$f = new Foo();
+
+$f->newFunc(); //from T1
+$f->func(); //from Foo
+
+$b = new Bar();
+$b->newFunc(); //from T1
+$b->func(); //from Bar
+$b->func2(); //from Bar
+$b->newFunc2(); //from T2
+$b->newFunc3(); //from T2
+$b->func3(); //from Bar
+--EXPECTF--
+From T1
+From Foo
+From T1
+From Bar
+From Bar
+From T2
+From T2
+From Bar
diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c
index 602b60041..28f98249d 100644
--- a/Zend/zend_compile.c
+++ b/Zend/zend_compile.c
@@ -3619,6 +3619,7 @@ ZEND_API void zend_do_implement_trait(zend_class_entry *ce, zend_class_entry *tr
}
}
ce->traits[ce->num_traits++] = trait;
+ trait->refcount++;
}
}
/* }}} */
@@ -3870,8 +3871,8 @@ static int zend_traits_copy_functions(zend_function *fn TSRMLS_DC, int num_args,
fn_copy = *fn;
function_add_ref(&fn_copy);
/* this function_name is never destroyed, because its refcount
- greater than 1, classes are always destoyed in reverse order
- and trait is declared early than this class */
+ greater than 1 and classes are always destoyed before the
+ traits they use */
fn_copy.common.function_name = aliases[i]->alias;
/* if it is 0, no modifieres has been changed */
@@ -4076,14 +4077,14 @@ static void zend_do_traits_method_binding(zend_class_entry *ce TSRMLS_DC) /* {{{
size_t i;
/* prepare copies of trait function tables for combination */
- function_tables = malloc(sizeof(HashTable*) * ce->num_traits);
- resulting_table = (HashTable *) malloc(sizeof(HashTable));
+ function_tables = emalloc(sizeof(HashTable*) * ce->num_traits);
+ resulting_table = (HashTable *)emalloc(sizeof(HashTable));
/* TODO: revisit this start size, may be its not optimal */
- zend_hash_init_ex(resulting_table, 10, NULL, NULL, 1, 0);
+ zend_hash_init_ex(resulting_table, 10, NULL, NULL, 0, 0);
for (i = 0; i < ce->num_traits; i++) {
- function_tables[i] = (HashTable *) malloc(sizeof(HashTable));
+ function_tables[i] = (HashTable *)emalloc(sizeof(HashTable));
zend_hash_init_ex(function_tables[i], ce->traits[i]->function_table.nNumOfElements, NULL, NULL, 1, 0);
if (ce->trait_precedences) {
@@ -4116,14 +4117,14 @@ static void zend_do_traits_method_binding(zend_class_entry *ce TSRMLS_DC) /* {{{
for (i = 0; i < ce->num_traits; i++) {
/* zend_hash_destroy(function_tables[i]); */
zend_hash_graceful_destroy(function_tables[i]);
- free(function_tables[i]);
+ efree(function_tables[i]);
}
- free(function_tables);
+ efree(function_tables);
/* free temporary resulting table */
/* zend_hash_destroy(resulting_table); */
zend_hash_graceful_destroy(resulting_table);
- free(resulting_table);
+ efree(resulting_table);
}
/* }}} */
diff --git a/Zend/zend_multibyte.c b/Zend/zend_multibyte.c
index 9149fdcf0..379f50b01 100644
--- a/Zend/zend_multibyte.c
+++ b/Zend/zend_multibyte.c
@@ -168,7 +168,7 @@ ZEND_API const zend_encoding *zend_multibyte_get_script_encoding(TSRMLS_D)
ZEND_API int zend_multibyte_set_script_encoding(const zend_encoding **encoding_list, size_t encoding_list_size TSRMLS_DC)
{
if (CG(script_encoding_list)) {
- efree(CG(script_encoding_list));
+ free(CG(script_encoding_list));
}
CG(script_encoding_list) = encoding_list;
CG(script_encoding_list_size) = encoding_list_size;
diff --git a/Zend/zend_opcode.c b/Zend/zend_opcode.c
index 65fa85185..19fd71e76 100644
--- a/Zend/zend_opcode.c
+++ b/Zend/zend_opcode.c
@@ -215,6 +215,12 @@ ZEND_API int zend_cleanup_class_data(zend_class_entry **pce TSRMLS_DC)
void _destroy_zend_class_traits_info(zend_class_entry *ce)
{
if (ce->num_traits > 0 && ce->traits) {
+ size_t i;
+ for (i = 0; i < ce->num_traits; i++) {
+ if (ce->traits[i]) {
+ destroy_zend_class(&ce->traits[i]);
+ }
+ }
efree(ce->traits);
}
diff --git a/Zend/zend_operators.c b/Zend/zend_operators.c
index 8d4baa6ac..dd3ee2d8c 100644
--- a/Zend/zend_operators.c
+++ b/Zend/zend_operators.c
@@ -2041,7 +2041,13 @@ ZEND_API void zendi_smart_strcmp(zval *result, zval *s1, zval *s2) /* {{{ */
if ((ret1=is_numeric_string_ex(Z_STRVAL_P(s1), Z_STRLEN_P(s1), &lval1, &dval1, 0, &oflow1)) &&
(ret2=is_numeric_string_ex(Z_STRVAL_P(s2), Z_STRLEN_P(s2), &lval2, &dval2, 0, &oflow2))) {
+#if ULONG_MAX == 0xFFFFFFFF
+ if (oflow1 != 0 && oflow1 == oflow2 && dval1 - dval2 == 0. &&
+ ((oflow1 == 1 && dval1 > 9007199254740991. /*0x1FFFFFFFFFFFFF*/)
+ || (oflow1 == -1 && dval1 < -9007199254740991.))) {
+#else
if (oflow1 != 0 && oflow1 == oflow2 && dval1 - dval2 == 0.) {
+#endif
/* both values are integers overflown to the same side, and the
* double comparison may have resulted in crucial accuracy lost */
goto string_cmp;