Skip to content

Commit 629ee93

Browse files
committed
Remove IS_STATIC_VAR_UNINITIALIZED
This flag was never necessary. We know a static variable is uninitialized (i.e. the initializer has never been called) iff the zval in the static variable array does not contain a reference. Prompted by a related issue in ext-uopz reported by Christoph.
1 parent 31f2564 commit 629ee93

6 files changed

+26
-8
lines changed

UPGRADING.INTERNALS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ PHP 8.4 INTERNALS UPGRADE NOTES
9999
zend_std_get_properties(). Use zend_std_get_properties_ex() or
100100
zend_std_get_properties() instead.
101101

102+
* Removed IS_STATIC_VAR_UNINITIALIZED constant. Check for IS_NULL in the
103+
static_variables array instead.
104+
102105
========================
103106
2. Build system changes
104107
========================
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
Static variable with throwing initializer
3+
--FILE--
4+
<?php
5+
6+
function foo($throw) {
7+
static $a = $throw ? (throw new Exception('Throwing from foo()')) : 42;
8+
return $a;
9+
}
10+
11+
try {
12+
var_dump(foo(true));
13+
} catch (Exception $e) {
14+
echo $e->getMessage(), "\n";
15+
}
16+
var_dump(foo(false));
17+
18+
?>
19+
--EXPECT--
20+
Throwing from foo()
21+
int(42)

Zend/zend_compile.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5483,7 +5483,6 @@ static void zend_compile_static_var(zend_ast *ast) /* {{{ */
54835483
zend_op *opline;
54845484

54855485
zval *placeholder_ptr = zend_hash_update(CG(active_op_array)->static_variables, var_name, &EG(uninitialized_zval));
5486-
Z_TYPE_EXTRA_P(placeholder_ptr) |= IS_STATIC_VAR_UNINITIALIZED;
54875486
uint32_t placeholder_offset = (uint32_t)((char*)placeholder_ptr - (char*)CG(active_op_array)->static_variables->arData);
54885487

54895488
uint32_t static_def_jmp_opnum = get_next_op_number();

Zend/zend_types.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -791,11 +791,6 @@ static zend_always_inline uint32_t zval_gc_info(uint32_t gc_type_info) {
791791
/* zval.u1.v.type_flags */
792792
#define IS_TYPE_REFCOUNTED (1<<0)
793793
#define IS_TYPE_COLLECTABLE (1<<1)
794-
/* Used for static variables to check if they have been initialized. We can't use IS_UNDEF because
795-
* we can't store IS_UNDEF zvals in the static_variables HashTable. This needs to live in type_info
796-
* so that the ZEND_ASSIGN overrides it but is moved to extra to avoid breaking the Z_REFCOUNTED()
797-
* optimization that only checks for Z_TYPE_FLAGS() without `& (IS_TYPE_COLLECTABLE|IS_TYPE_REFCOUNTED)`. */
798-
#define IS_STATIC_VAR_UNINITIALIZED (1<<0)
799794

800795
#if 1
801796
/* This optimized version assumes that we have a single "type_flag" */

Zend/zend_vm_def.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9110,7 +9110,7 @@ ZEND_VM_HANDLER(203, ZEND_BIND_INIT_STATIC_OR_JMP, CV, JMP_ADDR)
91109110
ZEND_ASSERT(GC_REFCOUNT(ht) == 1);
91119111

91129112
value = (zval*)((char*)ht->arData + opline->extended_value);
9113-
if (Z_TYPE_EXTRA_P(value) & IS_STATIC_VAR_UNINITIALIZED) {
9113+
if (Z_TYPE_P(value) == IS_NULL) {
91149114
ZEND_VM_NEXT_OPCODE();
91159115
} else {
91169116
SAVE_OPLINE();

Zend/zend_vm_execute.h

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)