Skip to content

Commit 3e9bb03

Browse files
committed
Removed IS_TYPE_IMMUTABLE (it's the same as COPYABLE & !REFCOUED)
1 parent 4240769 commit 3e9bb03

10 files changed

+34
-71
lines changed

NEWS

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ PHP NEWS
66
. Fix integer overflows (Joshua Rogers)
77

88
- Core:
9+
. Removed IS_TYPE_IMMUTABLE (it's the same as COPYABLE & !REFCOUED). (Dmitry)
910
. Removed the sql.safe_mode directive. (Kalle)
1011
. Removed support for Netware. (Kalle)
1112
. Fixed bug #54535 (WSA cleanup executes before MSHUTDOWN). (Kalle)

Zend/zend_ast.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ ZEND_API int zend_ast_evaluate(zval *result, zend_ast *ast, zend_class_entry *sc
266266
zval *zv = zend_ast_get_zval(ast);
267267

268268
if (Z_OPT_CONSTANT_P(zv)) {
269-
if (!(Z_TYPE_FLAGS_P(zv) & IS_TYPE_IMMUTABLE)) {
269+
if (Z_TYPE_FLAGS_P(zv) & IS_TYPE_REFCOUNTED) {
270270
if (UNEXPECTED(zval_update_constant_ex(zv, scope) != SUCCESS)) {
271271
ret = FAILURE;
272272
break;

Zend/zend_builtin_functions.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -836,7 +836,7 @@ static int validate_constant_array(HashTable *ht) /* {{{ */
836836
ZVAL_DEREF(val);
837837
if (Z_REFCOUNTED_P(val)) {
838838
if (Z_TYPE_P(val) == IS_ARRAY) {
839-
if (!Z_IMMUTABLE_P(val)) {
839+
if (Z_REFCOUNTED_P(val)) {
840840
if (Z_ARRVAL_P(val)->u.v.nApplyCount > 0) {
841841
zend_error(E_WARNING, "Constants cannot be recursive arrays");
842842
ret = 0;
@@ -874,7 +874,7 @@ static void copy_constant_array(zval *dst, zval *src) /* {{{ */
874874
new_val = zend_hash_index_add_new(Z_ARRVAL_P(dst), idx, val);
875875
}
876876
if (Z_TYPE_P(val) == IS_ARRAY) {
877-
if (!Z_IMMUTABLE_P(val)) {
877+
if (Z_REFCOUNTED_P(val)) {
878878
copy_constant_array(new_val, val);
879879
}
880880
} else if (Z_REFCOUNTED_P(val)) {
@@ -932,7 +932,7 @@ ZEND_FUNCTION(define)
932932
val = &val_free;
933933
break;
934934
case IS_ARRAY:
935-
if (!Z_IMMUTABLE_P(val)) {
935+
if (Z_REFCOUNTED_P(val)) {
936936
if (!validate_constant_array(Z_ARRVAL_P(val))) {
937937
RETURN_FALSE;
938938
} else {

Zend/zend_execute_API.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ ZEND_API int zval_update_constant_ex(zval *p, zend_class_entry *scope) /* {{{ */
573573
zend_throw_error(NULL, "Cannot declare self-referencing constant '%s'", Z_STRVAL_P(p));
574574
return FAILURE;
575575
}
576-
inline_change = (Z_TYPE_FLAGS_P(p) & IS_TYPE_IMMUTABLE) == 0;
576+
inline_change = (Z_TYPE_FLAGS_P(p) & IS_TYPE_REFCOUNTED) != 0;
577577
SEPARATE_ZVAL_NOREF(p);
578578
MARK_CONSTANT_VISITED(p);
579579
if (Z_CONST_FLAGS_P(p) & IS_CONSTANT_CLASS) {
@@ -638,7 +638,7 @@ ZEND_API int zval_update_constant_ex(zval *p, zend_class_entry *scope) /* {{{ */
638638
} else if (Z_TYPE_P(p) == IS_CONSTANT_AST) {
639639
zval tmp;
640640

641-
inline_change = (Z_TYPE_FLAGS_P(p) & IS_TYPE_IMMUTABLE) == 0;
641+
inline_change = (Z_TYPE_FLAGS_P(p) & IS_TYPE_REFCOUNTED) != 0;
642642
if (UNEXPECTED(zend_ast_evaluate(&tmp, Z_ASTVAL_P(p), scope) != SUCCESS)) {
643643
return FAILURE;
644644
}

Zend/zend_object_handlers.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ ZEND_API HashTable *zend_std_get_debug_info(zval *object, int *is_temp) /* {{{ *
163163

164164
zend_call_method_with_0_params(object, ce, &ce->__debugInfo, ZEND_DEBUGINFO_FUNC_NAME, &retval);
165165
if (Z_TYPE(retval) == IS_ARRAY) {
166-
if (Z_IMMUTABLE(retval)) {
166+
if (!Z_REFCOUNTED(retval)) {
167167
*is_temp = 1;
168168
return zend_array_dup(Z_ARRVAL(retval));
169169
} else if (Z_REFCOUNT(retval) <= 1) {

Zend/zend_types.h

+12-23
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,6 @@ static zend_always_inline zend_uchar zval_get_type(const zval* pz) {
386386

387387
#define Z_GC_INFO(zval) GC_INFO(Z_COUNTED(zval))
388388
#define Z_GC_INFO_P(zval_p) Z_GC_INFO(*(zval_p))
389-
390389
#define Z_GC_TYPE_INFO(zval) GC_TYPE_INFO(Z_COUNTED(zval))
391390
#define Z_GC_TYPE_INFO_P(zval_p) Z_GC_TYPE_INFO(*(zval_p))
392391

@@ -402,7 +401,6 @@ static zend_always_inline zend_uchar zval_get_type(const zval* pz) {
402401

403402
/* zval.u1.v.type_flags */
404403
#define IS_TYPE_CONSTANT (1<<0)
405-
#define IS_TYPE_IMMUTABLE (1<<1)
406404
#define IS_TYPE_REFCOUNTED (1<<2)
407405
#define IS_TYPE_COPYABLE (1<<4)
408406

@@ -437,7 +435,7 @@ static zend_always_inline zend_uchar zval_get_type(const zval* pz) {
437435
#define IS_STR_CONSTANT_UNQUALIFIED (1<<4) /* the same as IS_CONSTANT_UNQUALIFIED */
438436

439437
/* array flags */
440-
#define IS_ARRAY_IMMUTABLE (1<<1) /* the same as IS_TYPE_IMMUTABLE */
438+
#define IS_ARRAY_IMMUTABLE (1<<1)
441439

442440
/* object flags (zval.value->gc.u.flags) */
443441
#define IS_OBJ_APPLY_COUNT 0x07
@@ -475,9 +473,6 @@ static zend_always_inline zend_uchar zval_get_type(const zval* pz) {
475473
#define Z_COPYABLE(zval) ((Z_TYPE_FLAGS(zval) & IS_TYPE_COPYABLE) != 0)
476474
#define Z_COPYABLE_P(zval_p) Z_COPYABLE(*(zval_p))
477475

478-
#define Z_IMMUTABLE(zval) ((Z_TYPE_FLAGS(zval) & IS_TYPE_IMMUTABLE) != 0)
479-
#define Z_IMMUTABLE_P(zval_p) Z_IMMUTABLE(*(zval_p))
480-
481476
/* the following Z_OPT_* macros make better code when Z_TYPE_INFO accessed before */
482477
#define Z_OPT_TYPE(zval) (Z_TYPE_INFO(zval) & Z_TYPE_MASK)
483478
#define Z_OPT_TYPE_P(zval_p) Z_OPT_TYPE(*(zval_p))
@@ -491,9 +486,6 @@ static zend_always_inline zend_uchar zval_get_type(const zval* pz) {
491486
#define Z_OPT_COPYABLE(zval) ((Z_TYPE_INFO(zval) & (IS_TYPE_COPYABLE << Z_TYPE_FLAGS_SHIFT)) != 0)
492487
#define Z_OPT_COPYABLE_P(zval_p) Z_OPT_COPYABLE(*(zval_p))
493488

494-
#define Z_OPT_IMMUTABLE(zval) ((Z_TYPE_INFO(zval) & (IS_TYPE_IMMUTABLE << Z_TYPE_FLAGS_SHIFT)) != 0)
495-
#define Z_OPT_IMMUTABLE_P(zval_p) Z_OPT_IMMUTABLE(*(zval_p))
496-
497489
#define Z_OPT_ISREF(zval) (Z_OPT_TYPE(zval) == IS_REFERENCE)
498490
#define Z_OPT_ISREF_P(zval_p) Z_OPT_ISREF(*(zval_p))
499491

@@ -818,7 +810,7 @@ static zend_always_inline zend_uchar zval_get_type(const zval* pz) {
818810
#define Z_TRY_DELREF(z) Z_TRY_DELREF_P(&(z))
819811

820812
static zend_always_inline uint32_t zval_refcount_p(zval* pz) {
821-
ZEND_ASSERT(Z_REFCOUNTED_P(pz) || Z_IMMUTABLE_P(pz));
813+
ZEND_ASSERT(Z_REFCOUNTED_P(pz) || Z_COPYABLE_P(pz));
822814
return GC_REFCOUNT(Z_COUNTED_P(pz));
823815
}
824816

@@ -883,8 +875,8 @@ static zend_always_inline uint32_t zval_delref_p(zval* pz) {
883875
zend_refcounted *_gc = Z_COUNTED_P(_z2); \
884876
uint32_t _t = Z_TYPE_INFO_P(_z2); \
885877
ZVAL_COPY_VALUE_EX(_z1, _z2, _gc, _t); \
886-
if ((_t & ((IS_TYPE_REFCOUNTED|IS_TYPE_IMMUTABLE) << Z_TYPE_FLAGS_SHIFT)) != 0) { \
887-
if ((_t & ((IS_TYPE_COPYABLE|IS_TYPE_IMMUTABLE) << Z_TYPE_FLAGS_SHIFT)) != 0) { \
878+
if ((_t & ((IS_TYPE_REFCOUNTED|IS_TYPE_COPYABLE) << Z_TYPE_FLAGS_SHIFT)) != 0) { \
879+
if ((_t & (IS_TYPE_COPYABLE << Z_TYPE_FLAGS_SHIFT)) != 0) { \
888880
_zval_copy_ctor_func(_z1 ZEND_FILE_LINE_CC); \
889881
} else { \
890882
GC_REFCOUNT(_gc)++; \
@@ -950,7 +942,7 @@ static zend_always_inline uint32_t zval_delref_p(zval* pz) {
950942
zval *_zv = (zv); \
951943
zend_array *_arr = Z_ARR_P(_zv); \
952944
if (UNEXPECTED(GC_REFCOUNT(_arr) > 1)) { \
953-
if (!Z_IMMUTABLE_P(_zv)) { \
945+
if (Z_REFCOUNTED_P(_zv)) { \
954946
GC_REFCOUNT(_arr)--; \
955947
} \
956948
ZVAL_ARR(_zv, zend_array_dup(_arr)); \
@@ -960,10 +952,9 @@ static zend_always_inline uint32_t zval_delref_p(zval* pz) {
960952
#define SEPARATE_ZVAL_NOREF(zv) do { \
961953
zval *_zv = (zv); \
962954
ZEND_ASSERT(Z_TYPE_P(_zv) != IS_REFERENCE); \
963-
if (Z_COPYABLE_P(_zv) || \
964-
Z_IMMUTABLE_P(_zv)) { \
955+
if (Z_COPYABLE_P(_zv)) { \
965956
if (Z_REFCOUNT_P(_zv) > 1) { \
966-
if (!Z_IMMUTABLE_P(_zv)) { \
957+
if (Z_REFCOUNTED_P(_zv)) { \
967958
Z_DELREF_P(_zv); \
968959
} \
969960
zval_copy_ctor_func(_zv); \
@@ -974,11 +965,10 @@ static zend_always_inline uint32_t zval_delref_p(zval* pz) {
974965
#define SEPARATE_ZVAL(zv) do { \
975966
zval *_zv = (zv); \
976967
if (Z_REFCOUNTED_P(_zv) || \
977-
Z_IMMUTABLE_P(_zv)) { \
968+
Z_COPYABLE_P(_zv)) { \
978969
if (Z_REFCOUNT_P(_zv) > 1) { \
979-
if (Z_COPYABLE_P(_zv) || \
980-
Z_IMMUTABLE_P(_zv)) { \
981-
if (!Z_IMMUTABLE_P(_zv)) { \
970+
if (Z_COPYABLE_P(_zv)) { \
971+
if (Z_REFCOUNTED_P(_zv)) { \
982972
Z_DELREF_P(_zv); \
983973
} \
984974
zval_copy_ctor_func(_zv); \
@@ -992,10 +982,9 @@ static zend_always_inline uint32_t zval_delref_p(zval* pz) {
992982

993983
#define SEPARATE_ZVAL_IF_NOT_REF(zv) do { \
994984
zval *_zv = (zv); \
995-
if (Z_COPYABLE_P(_zv) || \
996-
Z_IMMUTABLE_P(_zv)) { \
985+
if (Z_COPYABLE_P(_zv)) { \
997986
if (Z_REFCOUNT_P(_zv) > 1) { \
998-
if (!Z_IMMUTABLE_P(_zv)) { \
987+
if (Z_REFCOUNTED_P(_zv)) { \
999988
Z_DELREF_P(_zv); \
1000989
} \
1001990
zval_copy_ctor_func(_zv); \

Zend/zend_variables.h

+3-27
Original file line numberDiff line numberDiff line change
@@ -55,29 +55,7 @@ static zend_always_inline void i_zval_ptr_dtor(zval *zval_ptr ZEND_FILE_LINE_DC)
5555

5656
static zend_always_inline void _zval_copy_ctor(zval *zvalue ZEND_FILE_LINE_DC)
5757
{
58-
if (Z_REFCOUNTED_P(zvalue) || Z_IMMUTABLE_P(zvalue)) {
59-
if (Z_COPYABLE_P(zvalue) || Z_IMMUTABLE_P(zvalue)) {
60-
_zval_copy_ctor_func(zvalue ZEND_FILE_LINE_RELAY_CC);
61-
} else {
62-
Z_ADDREF_P(zvalue);
63-
}
64-
}
65-
}
66-
67-
static zend_always_inline void _zval_opt_copy_ctor(zval *zvalue ZEND_FILE_LINE_DC)
68-
{
69-
if (Z_OPT_REFCOUNTED_P(zvalue) || Z_OPT_IMMUTABLE_P(zvalue)) {
70-
if (Z_OPT_COPYABLE_P(zvalue) || Z_OPT_IMMUTABLE_P(zvalue)) {
71-
_zval_copy_ctor_func(zvalue ZEND_FILE_LINE_RELAY_CC);
72-
} else {
73-
Z_ADDREF_P(zvalue);
74-
}
75-
}
76-
}
77-
78-
static zend_always_inline void _zval_copy_ctor_no_imm(zval *zvalue ZEND_FILE_LINE_DC)
79-
{
80-
if (Z_REFCOUNTED_P(zvalue)) {
58+
if (Z_REFCOUNTED_P(zvalue) || Z_COPYABLE_P(zvalue)) {
8159
if (Z_COPYABLE_P(zvalue)) {
8260
_zval_copy_ctor_func(zvalue ZEND_FILE_LINE_RELAY_CC);
8361
} else {
@@ -86,9 +64,9 @@ static zend_always_inline void _zval_copy_ctor_no_imm(zval *zvalue ZEND_FILE_LIN
8664
}
8765
}
8866

89-
static zend_always_inline void _zval_opt_copy_ctor_no_imm(zval *zvalue ZEND_FILE_LINE_DC)
67+
static zend_always_inline void _zval_opt_copy_ctor(zval *zvalue ZEND_FILE_LINE_DC)
9068
{
91-
if (Z_OPT_REFCOUNTED_P(zvalue)) {
69+
if (Z_OPT_REFCOUNTED_P(zvalue) || Z_OPT_COPYABLE_P(zvalue)) {
9270
if (Z_OPT_COPYABLE_P(zvalue)) {
9371
_zval_copy_ctor_func(zvalue ZEND_FILE_LINE_RELAY_CC);
9472
} else {
@@ -105,8 +83,6 @@ ZEND_API void _zval_internal_ptr_dtor(zval *zvalue ZEND_FILE_LINE_DC);
10583
ZEND_API void _zval_dtor_wrapper(zval *zvalue);
10684
#define zval_copy_ctor(zvalue) _zval_copy_ctor((zvalue) ZEND_FILE_LINE_CC)
10785
#define zval_opt_copy_ctor(zvalue) _zval_opt_copy_ctor((zvalue) ZEND_FILE_LINE_CC)
108-
#define zval_copy_ctor_no_imm(zvalue) _zval_copy_ctor_no_imm((zvalue) ZEND_FILE_LINE_CC)
109-
#define zval_opt_copy_ctor_no_imm(zvalue) _zval_opt_copy_ctor_no_imm((zvalue) ZEND_FILE_LINE_CC)
11086
#define zval_dtor(zvalue) zval_ptr_dtor_nogc(zvalue)
11187
#define zval_ptr_dtor(zval_ptr) _zval_ptr_dtor((zval_ptr) ZEND_FILE_LINE_CC)
11288
#define zval_ptr_dtor_nogc(zval_ptr) _zval_ptr_dtor_nogc((zval_ptr) ZEND_FILE_LINE_CC)

ext/mbstring/mbstring.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -3939,7 +3939,7 @@ PHP_FUNCTION(mb_convert_variables)
39393939
target_hash = HASH_OF(var);
39403940
if (target_hash != NULL) {
39413941
while ((hash_entry = zend_hash_get_current_data(target_hash)) != NULL) {
3942-
if (!Z_IMMUTABLE_P(var)) {
3942+
if (Z_REFCOUNTED_P(var)) {
39433943
if (++target_hash->u.v.nApplyCount > 1) {
39443944
--target_hash->u.v.nApplyCount;
39453945
recursion_error = 1;
@@ -3988,7 +3988,7 @@ PHP_FUNCTION(mb_convert_variables)
39883988
}
39893989
if (recursion_error) {
39903990
while(stack_level-- && (var = &stack[stack_level])) {
3991-
if (!Z_IMMUTABLE_P(var)) {
3991+
if (Z_REFCOUNTED_P(var)) {
39923992
if (HASH_OF(var)->u.v.nApplyCount > 1) {
39933993
HASH_OF(var)->u.v.nApplyCount--;
39943994
}
@@ -4055,7 +4055,7 @@ PHP_FUNCTION(mb_convert_variables)
40554055
hash_entry = hash_entry_ptr;
40564056
ZVAL_DEREF(hash_entry);
40574057
if (Z_TYPE_P(hash_entry) == IS_ARRAY || Z_TYPE_P(hash_entry) == IS_OBJECT) {
4058-
if (!Z_IMMUTABLE_P(hash_entry)) {
4058+
if (Z_REFCOUNTED_P(hash_entry)) {
40594059
if (++(HASH_OF(hash_entry)->u.v.nApplyCount) > 1) {
40604060
--(HASH_OF(hash_entry)->u.v.nApplyCount);
40614061
recursion_error = 1;
@@ -4108,7 +4108,7 @@ PHP_FUNCTION(mb_convert_variables)
41084108

41094109
if (recursion_error) {
41104110
while(stack_level-- && (var = &stack[stack_level])) {
4111-
if (!Z_IMMUTABLE_P(var)) {
4111+
if (Z_REFCOUNTED_P(var)) {
41124112
if (HASH_OF(var)->u.v.nApplyCount > 1) {
41134113
HASH_OF(var)->u.v.nApplyCount--;
41144114
}

ext/opcache/zend_persist.c

+6-9
Original file line numberDiff line numberDiff line change
@@ -276,26 +276,23 @@ static void zend_persist_zval(zval *z)
276276
flags = Z_GC_FLAGS_P(z) & ~ (IS_STR_PERSISTENT | IS_STR_INTERNED | IS_STR_PERMANENT);
277277
zend_accel_store_interned_string(Z_STR_P(z));
278278
Z_GC_FLAGS_P(z) |= flags;
279-
Z_TYPE_FLAGS_P(z) &= ~(IS_TYPE_REFCOUNTED | IS_TYPE_COPYABLE);
280-
if (Z_TYPE_P(z) == IS_CONSTANT) {
281-
Z_TYPE_FLAGS_P(z) |= IS_TYPE_IMMUTABLE;
282-
}
279+
Z_TYPE_FLAGS_P(z) &= ~IS_TYPE_REFCOUNTED;
283280
break;
284281
case IS_ARRAY:
285282
new_ptr = zend_shared_alloc_get_xlat_entry(Z_ARR_P(z));
286283
if (new_ptr) {
287284
Z_ARR_P(z) = new_ptr;
288-
Z_TYPE_FLAGS_P(z) = IS_TYPE_IMMUTABLE;
285+
Z_TYPE_FLAGS_P(z) = IS_TYPE_COPYABLE;
289286
} else {
290-
if (Z_IMMUTABLE_P(z)) {
287+
if (!Z_REFCOUNTED_P(z)) {
291288
Z_ARR_P(z) = zend_accel_memdup(Z_ARR_P(z), sizeof(zend_array));
292289
zend_hash_persist_immutable(Z_ARRVAL_P(z));
293290
} else {
294291
GC_REMOVE_FROM_BUFFER(Z_ARR_P(z));
295292
zend_accel_store(Z_ARR_P(z), sizeof(zend_array));
296293
zend_hash_persist(Z_ARRVAL_P(z), zend_persist_zval);
297294
/* make immutable array */
298-
Z_TYPE_FLAGS_P(z) = IS_TYPE_IMMUTABLE;
295+
Z_TYPE_FLAGS_P(z) = IS_TYPE_COPYABLE;
299296
GC_REFCOUNT(Z_COUNTED_P(z)) = 2;
300297
GC_FLAGS(Z_COUNTED_P(z)) |= IS_ARRAY_IMMUTABLE;
301298
Z_ARRVAL_P(z)->u.flags |= HASH_FLAG_STATIC_KEYS;
@@ -316,11 +313,11 @@ static void zend_persist_zval(zval *z)
316313
new_ptr = zend_shared_alloc_get_xlat_entry(Z_AST_P(z));
317314
if (new_ptr) {
318315
Z_AST_P(z) = new_ptr;
319-
Z_TYPE_FLAGS_P(z) = IS_TYPE_CONSTANT | IS_TYPE_IMMUTABLE;
316+
Z_TYPE_FLAGS_P(z) = IS_TYPE_CONSTANT | IS_TYPE_COPYABLE;
320317
} else {
321318
zend_accel_store(Z_AST_P(z), sizeof(zend_ast_ref));
322319
Z_ASTVAL_P(z) = zend_persist_ast(Z_ASTVAL_P(z));
323-
Z_TYPE_FLAGS_P(z) = IS_TYPE_CONSTANT | IS_TYPE_IMMUTABLE;
320+
Z_TYPE_FLAGS_P(z) = IS_TYPE_CONSTANT | IS_TYPE_COPYABLE;
324321
GC_REFCOUNT(Z_COUNTED_P(z)) = 2;
325322
}
326323
break;

ext/wddx/wddx.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ static void php_wddx_add_var(wddx_packet *packet, zval *name_var)
693693
return;
694694
}
695695

696-
if (Z_IMMUTABLE_P(name_var)) {
696+
if (!Z_REFCOUNTED_P(name_var)) {
697697
ZEND_HASH_FOREACH_VAL(target_hash, val) {
698698
php_wddx_add_var(packet, val);
699699
} ZEND_HASH_FOREACH_END();

0 commit comments

Comments
 (0)