Skip to content

Commit 7fa87be

Browse files
authored
Merge pull request #11 from php/master
sync
2 parents 2032ee3 + 90c16db commit 7fa87be

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+821
-240
lines changed

TSRM/TSRM.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -729,13 +729,13 @@ TSRM_API size_t tsrm_get_ls_cache_tcb_offset(void)
729729
#if defined(__APPLE__) && defined(__x86_64__)
730730
// TODO: Implement support for fast JIT ZTS code ???
731731
return 0;
732-
#elif defined(__x86_64__) && defined(__GNUC__) && !defined(__FreeBSD__)
732+
#elif defined(__x86_64__) && defined(__GNUC__) && !defined(__FreeBSD__) && !defined(__OpenBSD__)
733733
size_t ret;
734734

735735
asm ("movq _tsrm_ls_cache@gottpoff(%%rip),%0"
736736
: "=r" (ret));
737737
return ret;
738-
#elif defined(__i386__) && defined(__GNUC__) && !defined(__FreeBSD__)
738+
#elif defined(__i386__) && defined(__GNUC__) && !defined(__FreeBSD__) && !defined(__OpenBSD__)
739739
size_t ret;
740740

741741
asm ("leal _tsrm_ls_cache@ntpoff,%0"

Zend/Optimizer/pass1.c

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
* - constant expression evaluation
2626
* - optimize constant conditional JMPs
2727
* - pre-evaluate constant function calls
28-
* - eliminate FETCH $GLOBALS followed by FETCH_DIM/UNSET_DIM/ISSET_ISEMPTY_DIM
2928
*/
3029

3130
#include "php.h"
@@ -531,52 +530,6 @@ void zend_optimizer_pass1(zend_op_array *op_array, zend_optimizer_ctx *ctx)
531530
zend_optimizer_collect_constant(ctx, &ZEND_OP1_LITERAL(opline), &ZEND_OP2_LITERAL(opline));
532531
}
533532
break;
534-
#if 0
535-
/* see ext/opcache/tests/bug78961.phpt */
536-
// case ZEND_FETCH_R:
537-
case ZEND_FETCH_W:
538-
// case ZEND_FETCH_RW:
539-
case ZEND_FETCH_IS:
540-
// case ZEND_FETCH_FUNC_ARG:
541-
case ZEND_FETCH_UNSET:
542-
/* convert FETCH $GLOBALS (global), FETCH_DIM $x into FETCH $x (global) */
543-
if ((opline->extended_value & ZEND_FETCH_GLOBAL) != 0 &&
544-
opline->op1_type == IS_CONST &&
545-
Z_TYPE(ZEND_OP1_LITERAL(opline)) == IS_STRING &&
546-
zend_string_equals_literal(Z_STR(ZEND_OP1_LITERAL(opline)), "GLOBALS") &&
547-
((opline + 1)->opcode == opline->opcode + 1 ||
548-
((opline + 1)->opcode == ZEND_UNSET_DIM &&
549-
opline->opcode == ZEND_FETCH_UNSET) ||
550-
((opline + 1)->opcode == ZEND_ISSET_ISEMPTY_DIM_OBJ &&
551-
opline->opcode == ZEND_FETCH_IS)) &&
552-
(opline + 1)->op1_type == opline->result_type &&
553-
(opline + 1)->op1.var == opline->result.var &&
554-
((opline + 1)->op2_type != IS_CONST ||
555-
Z_TYPE(ZEND_OP2_LITERAL(opline + 1)) < IS_ARRAY)) {
556-
557-
if ((opline + 1)->opcode == ZEND_UNSET_DIM) {
558-
(opline + 1)->opcode = ZEND_UNSET_VAR;
559-
(opline + 1)->extended_value = ZEND_FETCH_GLOBAL;
560-
} else if ((opline + 1)->opcode == ZEND_ISSET_ISEMPTY_DIM_OBJ) {
561-
(opline + 1)->opcode = ZEND_ISSET_ISEMPTY_VAR;
562-
(opline + 1)->extended_value |= ZEND_FETCH_GLOBAL;
563-
} else {
564-
(opline + 1)->opcode = opline->opcode;
565-
(opline + 1)->extended_value = ZEND_FETCH_GLOBAL;
566-
}
567-
(opline + 1)->op1_type = (opline + 1)->op2_type;
568-
(opline + 1)->op1 = (opline + 1)->op2;
569-
if ((opline + 1)->op1_type == IS_CONST &&
570-
Z_TYPE(ZEND_OP1_LITERAL(opline + 1)) != IS_STRING) {
571-
572-
convert_to_string(&ZEND_OP1_LITERAL(opline + 1));
573-
zend_string_hash_val(Z_STR(ZEND_OP1_LITERAL(opline + 1)));
574-
}
575-
SET_UNUSED((opline + 1)->op2);
576-
MAKE_NOP(opline);
577-
}
578-
break;
579-
#endif
580533

581534
case ZEND_JMPZ_EX:
582535
case ZEND_JMPNZ_EX:

Zend/Optimizer/zend_func_infos.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ static const func_info_t func_infos[] = {
9595
F1("filter_input_array", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_ANY|MAY_BE_ARRAY_OF_REF|MAY_BE_FALSE|MAY_BE_NULL),
9696
F1("filter_var_array", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_ANY|MAY_BE_ARRAY_OF_REF|MAY_BE_FALSE|MAY_BE_NULL),
9797
F1("filter_list", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_STRING),
98+
F1("ftp_raw", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_STRING|MAY_BE_NULL),
99+
F1("ftp_nlist", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_STRING|MAY_BE_FALSE),
100+
F1("ftp_rawlist", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_STRING|MAY_BE_FALSE),
101+
F1("ftp_mlsd", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_ARRAY|MAY_BE_FALSE),
98102
F1("gd_info", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_STRING|MAY_BE_ARRAY_OF_FALSE|MAY_BE_ARRAY_OF_TRUE),
99103
F1("imagecreatetruecolor", MAY_BE_OBJECT|MAY_BE_FALSE),
100104
#if defined(PHP_WIN32)
@@ -163,6 +167,10 @@ static const func_info_t func_infos[] = {
163167
#if defined(HAVE_BIND_TEXTDOMAIN_CODESET)
164168
F1("bind_textdomain_codeset", MAY_BE_STRING|MAY_BE_FALSE),
165169
#endif
170+
F1("gmp_div_qr", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_OBJECT),
171+
F1("gmp_sqrtrem", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_OBJECT),
172+
F1("gmp_rootrem", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_OBJECT),
173+
F1("gmp_gcdext", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_OBJECT),
166174
F1("hash", MAY_BE_STRING|MAY_BE_FALSE),
167175
F1("hash_file", MAY_BE_STRING|MAY_BE_FALSE),
168176
F1("hash_hmac", MAY_BE_STRING|MAY_BE_FALSE),
@@ -189,6 +197,13 @@ static const func_info_t func_infos[] = {
189197
F1("iconv_mime_decode_headers", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_STRING|MAY_BE_ARRAY_OF_ARRAY|MAY_BE_FALSE),
190198
F1("iconv", MAY_BE_STRING|MAY_BE_FALSE),
191199
F1("iconv_get_encoding", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_STRING|MAY_BE_STRING|MAY_BE_FALSE),
200+
F1("intlcal_get_available_locales", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_STRING),
201+
F1("datefmt_localtime", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_LONG|MAY_BE_FALSE),
202+
F1("locale_get_keywords", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_STRING|MAY_BE_FALSE|MAY_BE_NULL),
203+
F1("msgfmt_parse", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_LONG|MAY_BE_ARRAY_OF_DOUBLE|MAY_BE_ARRAY_OF_STRING|MAY_BE_FALSE),
204+
F1("msgfmt_parse_message", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_LONG|MAY_BE_ARRAY_OF_DOUBLE|MAY_BE_ARRAY_OF_STRING|MAY_BE_FALSE),
205+
F1("resourcebundle_locales", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_STRING|MAY_BE_FALSE),
206+
F1("transliterator_list_ids", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_STRING|MAY_BE_FALSE),
192207
F1("json_encode", MAY_BE_STRING|MAY_BE_FALSE),
193208
F1("json_last_error_msg", MAY_BE_STRING),
194209
F1("ldap_get_entries", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_LONG|MAY_BE_ARRAY_OF_ARRAY|MAY_BE_FALSE),

Zend/tests/bug81626.phpt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
Bug #81626: Error on use static:: in __сallStatic() wrapped to Closure::fromCallable()
3+
--FILE--
4+
<?php
5+
class TestClass {
6+
public static bool $wasCalled = false;
7+
public static function __callStatic(string $name, array $args): string
8+
{
9+
static::$wasCalled = true;
10+
return 'ok';
11+
}
12+
}
13+
$closure = Closure::fromCallable([TestClass::class, 'foo']);
14+
var_dump($closure());
15+
?>
16+
--EXPECT--
17+
string(2) "ok"

Zend/tests/bug81631.phpt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
Bug #81631: ::class with dynamic class name may yield wrong line number
3+
--FILE--
4+
<?php
5+
$a = 0;
6+
var_dump($b::class);
7+
?>
8+
--EXPECTF--
9+
Warning: Undefined variable $b in %s on line 3
10+
11+
Fatal error: Uncaught TypeError: Cannot use "::class" on value of type null in %s:3
12+
Stack trace:
13+
#0 {main}
14+
thrown in %s on line 3
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
--TEST--
2+
Class constant inheritance with mutable data
3+
--SKIPIF--
4+
<?php
5+
if (getenv('SKIP_PRELOAD')) die('skip preload produces additional warnings');
6+
?>
7+
--FILE--
8+
<?php
9+
10+
// This would previously leak under opcache.
11+
class A {
12+
const X = 'X' . self::Y;
13+
const Y = 'Y';
14+
}
15+
interface I {
16+
const X2 = 'X2' . self::Y2;
17+
const Y2 = 'Y2';
18+
}
19+
eval('class B extends A implements I {}');
20+
var_dump(new B);
21+
var_dump(B::X, B::X2);
22+
23+
// This should only produce one warning, not two.
24+
class X {
25+
const C = 1 % 1.5;
26+
}
27+
class Y extends X {
28+
}
29+
var_dump(X::C, Y::C);
30+
?>
31+
--EXPECTF--
32+
object(B)#1 (0) {
33+
}
34+
string(2) "XY"
35+
string(4) "X2Y2"
36+
37+
Deprecated: Implicit conversion from float 1.5 to int loses precision in %s on line %d
38+
int(0)
39+
int(0)

Zend/tests/weakrefs/weakrefs_006.phpt

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
--TEST--
2+
WeakReference overwriting existing value
3+
--FILE--
4+
<?php
5+
6+
class HasDtor {
7+
public function __destruct() {
8+
echo "In destruct\n";
9+
global $w, $all;
10+
for ($i = 0; $i < 10; $i++) {
11+
$v = new stdClass();
12+
$all[] = $v;
13+
$w[$v] = $i;
14+
}
15+
}
16+
}
17+
$all = [];
18+
$w = new WeakMap();
19+
$o = new stdClass();
20+
21+
$w[$o] = new HasDtor();
22+
$w[$o] = 123;
23+
var_dump($w);
24+
?>
25+
--EXPECT--
26+
In destruct
27+
object(WeakMap)#1 (11) {
28+
[0]=>
29+
array(2) {
30+
["key"]=>
31+
object(stdClass)#2 (0) {
32+
}
33+
["value"]=>
34+
int(123)
35+
}
36+
[1]=>
37+
array(2) {
38+
["key"]=>
39+
object(stdClass)#4 (0) {
40+
}
41+
["value"]=>
42+
int(0)
43+
}
44+
[2]=>
45+
array(2) {
46+
["key"]=>
47+
object(stdClass)#5 (0) {
48+
}
49+
["value"]=>
50+
int(1)
51+
}
52+
[3]=>
53+
array(2) {
54+
["key"]=>
55+
object(stdClass)#6 (0) {
56+
}
57+
["value"]=>
58+
int(2)
59+
}
60+
[4]=>
61+
array(2) {
62+
["key"]=>
63+
object(stdClass)#7 (0) {
64+
}
65+
["value"]=>
66+
int(3)
67+
}
68+
[5]=>
69+
array(2) {
70+
["key"]=>
71+
object(stdClass)#8 (0) {
72+
}
73+
["value"]=>
74+
int(4)
75+
}
76+
[6]=>
77+
array(2) {
78+
["key"]=>
79+
object(stdClass)#9 (0) {
80+
}
81+
["value"]=>
82+
int(5)
83+
}
84+
[7]=>
85+
array(2) {
86+
["key"]=>
87+
object(stdClass)#10 (0) {
88+
}
89+
["value"]=>
90+
int(6)
91+
}
92+
[8]=>
93+
array(2) {
94+
["key"]=>
95+
object(stdClass)#11 (0) {
96+
}
97+
["value"]=>
98+
int(7)
99+
}
100+
[9]=>
101+
array(2) {
102+
["key"]=>
103+
object(stdClass)#12 (0) {
104+
}
105+
["value"]=>
106+
int(8)
107+
}
108+
[10]=>
109+
array(2) {
110+
["key"]=>
111+
object(stdClass)#13 (0) {
112+
}
113+
["value"]=>
114+
int(9)
115+
}
116+
}

Zend/zend_API.c

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1325,12 +1325,19 @@ ZEND_API HashTable *zend_separate_class_constants_table(zend_class_entry *class_
13251325
zend_hash_extend(constants_table, zend_hash_num_elements(&class_type->constants_table), 0);
13261326

13271327
ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(&class_type->constants_table, key, c) {
1328-
if (Z_TYPE(c->value) == IS_CONSTANT_AST) {
1329-
new_c = zend_arena_alloc(&CG(arena), sizeof(zend_class_constant));
1330-
memcpy(new_c, c, sizeof(zend_class_constant));
1331-
c = new_c;
1328+
if (c->ce == class_type) {
1329+
if (Z_TYPE(c->value) == IS_CONSTANT_AST) {
1330+
new_c = zend_arena_alloc(&CG(arena), sizeof(zend_class_constant));
1331+
memcpy(new_c, c, sizeof(zend_class_constant));
1332+
c = new_c;
1333+
}
1334+
Z_TRY_ADDREF(c->value);
1335+
} else {
1336+
if (Z_TYPE(c->value) == IS_CONSTANT_AST) {
1337+
c = zend_hash_find_ptr(CE_CONSTANTS_TABLE(c->ce), key);
1338+
ZEND_ASSERT(c);
1339+
}
13321340
}
1333-
Z_TRY_ADDREF(c->value);
13341341
_zend_hash_append_ptr(constants_table, key, c);
13351342
} ZEND_HASH_FOREACH_END();
13361343

@@ -1412,8 +1419,18 @@ ZEND_API zend_result zend_update_class_constants(zend_class_entry *class_type) /
14121419
} else {
14131420
constants_table = &class_type->constants_table;
14141421
}
1415-
ZEND_HASH_MAP_FOREACH_PTR(constants_table, c) {
1422+
1423+
zend_string *name;
1424+
ZEND_HASH_MAP_FOREACH_STR_KEY_VAL(constants_table, name, val) {
1425+
c = Z_PTR_P(val);
14161426
if (Z_TYPE(c->value) == IS_CONSTANT_AST) {
1427+
if (c->ce != class_type) {
1428+
Z_PTR_P(val) = c = zend_hash_find_ptr(CE_CONSTANTS_TABLE(c->ce), name);
1429+
if (Z_TYPE(c->value) != IS_CONSTANT_AST) {
1430+
continue;
1431+
}
1432+
}
1433+
14171434
val = &c->value;
14181435
if (UNEXPECTED(zval_update_constant_ex(val, c->ce) != SUCCESS)) {
14191436
return FAILURE;

Zend/zend_ast.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ static zend_result zend_ast_add_unpacked_element(zval *result, zval *expr) {
482482

483483
zend_class_entry *zend_ast_fetch_class(zend_ast *ast, zend_class_entry *scope)
484484
{
485-
return zend_fetch_class(zend_ast_get_str(ast), ast->attr | ZEND_FETCH_CLASS_EXCEPTION);
485+
return zend_fetch_class_with_scope(zend_ast_get_str(ast), ast->attr | ZEND_FETCH_CLASS_EXCEPTION, scope);
486486
}
487487

488488
ZEND_API zend_result ZEND_FASTCALL zend_ast_evaluate(zval *result, zend_ast *ast, zend_class_entry *scope)

Zend/zend_execute.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ ZEND_API void zend_set_timeout(zend_long seconds, bool reset_signals);
349349
ZEND_API void zend_unset_timeout(void);
350350
ZEND_API ZEND_NORETURN void ZEND_FASTCALL zend_timeout(void);
351351
ZEND_API zend_class_entry *zend_fetch_class(zend_string *class_name, int fetch_type);
352+
ZEND_API zend_class_entry *zend_fetch_class_with_scope(zend_string *class_name, int fetch_type, zend_class_entry *scope);
352353
ZEND_API zend_class_entry *zend_fetch_class_by_name(zend_string *class_name, zend_string *lcname, int fetch_type);
353354

354355
ZEND_API zend_function * ZEND_FASTCALL zend_fetch_function(zend_string *name);

0 commit comments

Comments
 (0)