summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Stogov <dmitry@zend.com>2018-01-19 17:47:26 +0300
committerDmitry Stogov <dmitry@zend.com>2018-01-19 17:47:26 +0300
commit742d5a01ed5bd39a18929c04a5f5c5596a4b005b (patch)
treec55c4fa3011823683ba58698d6bff121cdc5c864
parent465a8cfbadf267c65725e4c8a31c67b98f2f3697 (diff)
downloadphp-git-742d5a01ed5bd39a18929c04a5f5c5596a4b005b.tar.gz
Get rid of IS_TYPE_COPYABLE.
-rw-r--r--UPGRADING.INTERNALS6
-rw-r--r--Zend/zend.c4
-rw-r--r--Zend/zend_hash.h2
-rw-r--r--Zend/zend_types.h45
-rw-r--r--Zend/zend_variables.h20
-rw-r--r--ext/opcache/zend_persist.c4
6 files changed, 41 insertions, 40 deletions
diff --git a/UPGRADING.INTERNALS b/UPGRADING.INTERNALS
index 19eeacc57e..69e073a4d3 100644
--- a/UPGRADING.INTERNALS
+++ b/UPGRADING.INTERNALS
@@ -103,10 +103,12 @@ PHP 7.3 INTERNALS UPGRADE NOTES
m. zend_cpu_supports() determines if a feature is supported by current cpu.
- n. IS_STRING zvals don't set IS_TYPE_COPYALE anymore. This prevents string
+ n. IS_TYPE_COPYABLE flag is removed. IS_STRING zvals didn't need to be
duplication by zval_copy_ctor(), ZVAL_DUP() and SEPARATE_ZVAL*() macros.
Interned strings didn't set IS_TYPE_COPYALE, so they aren't affected at
- all.
+ all. Now instead of checking for IS_TYPE_COPYABLE, engine checks for
+ IS_ARRAY type (it may be IS_TYPE_REFCOUNTED or not). All the related
+ macros: Z_COPYABLE..., Z_IMMUTABLE... are kept for compatibility.
========================
2. Build system changes
diff --git a/Zend/zend.c b/Zend/zend.c
index f42a987542..a915de1b3e 100644
--- a/Zend/zend.c
+++ b/Zend/zend.c
@@ -732,9 +732,9 @@ static zend_bool php_auto_globals_create_globals(zend_string *name) /* {{{ */
{
zval globals;
- /* IS_TYPE_COPYABLE, but with ref-counter 1 and not IS_TYPE_REFCOUNTED */
+ /* IS_ARRAY, but with ref-counter 1 and not IS_TYPE_REFCOUNTED */
ZVAL_ARR(&globals, &EG(symbol_table));
- Z_TYPE_FLAGS_P(&globals) = IS_TYPE_COPYABLE;
+ Z_TYPE_FLAGS_P(&globals) = 0;
ZVAL_NEW_REF(&globals, &globals);
zend_hash_update(&EG(symbol_table), name, &globals);
return 0;
diff --git a/Zend/zend_hash.h b/Zend/zend_hash.h
index 312b7d30e8..3c9e22cb85 100644
--- a/Zend/zend_hash.h
+++ b/Zend/zend_hash.h
@@ -61,7 +61,7 @@ extern ZEND_API const HashTable zend_empty_array;
#define ZVAL_EMPTY_ARRAY(z) do { \
zval *__z = (z); \
Z_ARR_P(__z) = (zend_array*)&zend_empty_array; \
- Z_TYPE_INFO_P(__z) = IS_ARRAY | (IS_TYPE_COPYABLE << Z_TYPE_FLAGS_SHIFT); \
+ Z_TYPE_INFO_P(__z) = IS_ARRAY; \
} while (0)
diff --git a/Zend/zend_types.h b/Zend/zend_types.h
index 24f20913c2..ef1b83a11c 100644
--- a/Zend/zend_types.h
+++ b/Zend/zend_types.h
@@ -470,19 +470,18 @@ static zend_always_inline zend_uchar zval_get_type(const zval* pz) {
#define GC_OBJECT (IS_OBJECT | (GC_COLLECTABLE << GC_FLAGS_SHIFT))
/* zval.u1.v.type_flags */
-#define IS_TYPE_COPYABLE (1<<1)
#define IS_TYPE_REFCOUNTED (1<<2) /* equal to ZEND_CALL_FREE_EXTRA_ARGS */
/* extended types */
#define IS_INTERNED_STRING_EX IS_STRING
-#define IS_STRING_EX (IS_STRING | ((IS_TYPE_REFCOUNTED ) << Z_TYPE_FLAGS_SHIFT))
-#define IS_ARRAY_EX (IS_ARRAY | ((IS_TYPE_REFCOUNTED | IS_TYPE_COPYABLE) << Z_TYPE_FLAGS_SHIFT))
-#define IS_OBJECT_EX (IS_OBJECT | ((IS_TYPE_REFCOUNTED ) << Z_TYPE_FLAGS_SHIFT))
-#define IS_RESOURCE_EX (IS_RESOURCE | ((IS_TYPE_REFCOUNTED ) << Z_TYPE_FLAGS_SHIFT))
-#define IS_REFERENCE_EX (IS_REFERENCE | ((IS_TYPE_REFCOUNTED ) << Z_TYPE_FLAGS_SHIFT))
+#define IS_STRING_EX (IS_STRING | (IS_TYPE_REFCOUNTED << Z_TYPE_FLAGS_SHIFT))
+#define IS_ARRAY_EX (IS_ARRAY | (IS_TYPE_REFCOUNTED << Z_TYPE_FLAGS_SHIFT))
+#define IS_OBJECT_EX (IS_OBJECT | (IS_TYPE_REFCOUNTED << Z_TYPE_FLAGS_SHIFT))
+#define IS_RESOURCE_EX (IS_RESOURCE | (IS_TYPE_REFCOUNTED << Z_TYPE_FLAGS_SHIFT))
+#define IS_REFERENCE_EX (IS_REFERENCE | (IS_TYPE_REFCOUNTED << Z_TYPE_FLAGS_SHIFT))
-#define IS_CONSTANT_AST_EX (IS_CONSTANT_AST | ((IS_TYPE_REFCOUNTED ) << Z_TYPE_FLAGS_SHIFT))
+#define IS_CONSTANT_AST_EX (IS_CONSTANT_AST | (IS_TYPE_REFCOUNTED << Z_TYPE_FLAGS_SHIFT))
/* string flags (zval.value->gc.u.flags) */
#define IS_STR_INTERNED GC_IMMUTABLE /* interned string */
@@ -525,11 +524,12 @@ static zend_always_inline zend_uchar zval_get_type(const zval* pz) {
#define Z_REFCOUNTED(zval) ((Z_TYPE_FLAGS(zval) & IS_TYPE_REFCOUNTED) != 0)
#define Z_REFCOUNTED_P(zval_p) Z_REFCOUNTED(*(zval_p))
-#define Z_COPYABLE(zval) ((Z_TYPE_FLAGS(zval) & IS_TYPE_COPYABLE) != 0)
+/* deprecated: (COPYABLE is the same as IS_ARRAY) */
+#define Z_COPYABLE(zval) ((Z_TYPE(zval) == IS_ARRAY)
#define Z_COPYABLE_P(zval_p) Z_COPYABLE(*(zval_p))
-/* deprecated: (IMMUTABLE is the same as COPYABLE && !REFCOUED) */
-#define Z_IMMUTABLE(zval) ((Z_TYPE_FLAGS(zval) & (IS_TYPE_REFCOUNTED|IS_TYPE_COPYABLE)) == IS_TYPE_COPYABLE)
+/* deprecated: (IMMUTABLE is the same as IS_ARRAY && !REFCOUED) */
+#define Z_IMMUTABLE(zval) ((Z_TYPE_INFO(zval) == IS_ARRAY)
#define Z_IMMUTABLE_P(zval_p) Z_IMMUTABLE(*(zval_p))
#define Z_OPT_IMMUTABLE(zval) Z_IMMUTABLE(zval_p)
#define Z_OPT_IMMUTABLE_P(zval_p) Z_IMMUTABLE(*(zval_p))
@@ -544,7 +544,8 @@ static zend_always_inline zend_uchar zval_get_type(const zval* pz) {
#define Z_OPT_REFCOUNTED(zval) ((Z_TYPE_INFO(zval) & (IS_TYPE_REFCOUNTED << Z_TYPE_FLAGS_SHIFT)) != 0)
#define Z_OPT_REFCOUNTED_P(zval_p) Z_OPT_REFCOUNTED(*(zval_p))
-#define Z_OPT_COPYABLE(zval) ((Z_TYPE_INFO(zval) & (IS_TYPE_COPYABLE << Z_TYPE_FLAGS_SHIFT)) != 0)
+/* deprecated: (COPYABLE is the same as IS_ARRAY) */
+#define Z_OPT_COPYABLE(zval) ((Z_OPT_TYPE(zval) == IS_ARRAY)
#define Z_OPT_COPYABLE_P(zval_p) Z_OPT_COPYABLE(*(zval_p))
#define Z_OPT_ISREF(zval) (Z_OPT_TYPE(zval) == IS_REFERENCE)
@@ -935,7 +936,9 @@ static zend_always_inline uint32_t zend_gc_delref_ex(zend_refcounted_h *p, uint3
}
static zend_always_inline uint32_t zval_refcount_p(const zval* pz) {
- ZEND_ASSERT(Z_REFCOUNTED_P(pz) || Z_COPYABLE_P(pz));
+#if ZEND_DEBUG
+ ZEND_ASSERT(Z_REFCOUNTED_P(pz) || Z_TYPE_P(pz) == IS_ARRAY);
+#endif
return GC_REFCOUNT(Z_COUNTED_P(pz));
}
@@ -999,13 +1002,13 @@ static zend_always_inline uint32_t zval_delref_p(zval* pz) {
const zval *_z2 = (v); \
zend_refcounted *_gc = Z_COUNTED_P(_z2); \
uint32_t _t = Z_TYPE_INFO_P(_z2); \
- ZVAL_COPY_VALUE_EX(_z1, _z2, _gc, _t); \
- if ((_t & ((IS_TYPE_REFCOUNTED|IS_TYPE_COPYABLE) << Z_TYPE_FLAGS_SHIFT)) != 0) { \
- if ((_t & (IS_TYPE_COPYABLE << Z_TYPE_FLAGS_SHIFT)) != 0) { \
- zval_copy_ctor_func(_z1); \
- } else { \
+ if ((_t & Z_TYPE_MASK) == IS_ARRAY) { \
+ ZVAL_ARR(_z1, zend_array_dup((zend_array*)_gc));\
+ } else { \
+ if ((_t & (IS_TYPE_REFCOUNTED << Z_TYPE_FLAGS_SHIFT)) != 0) { \
GC_ADDREF(_gc); \
} \
+ ZVAL_COPY_VALUE_EX(_z1, _z2, _gc, _t); \
} \
} while (0)
@@ -1099,12 +1102,12 @@ static zend_always_inline uint32_t zval_delref_p(zval* pz) {
#define SEPARATE_ZVAL_IF_NOT_REF(zv) do { \
zval *__zv = (zv); \
- if (Z_COPYABLE_P(__zv)) { \
+ if (Z_TYPE_P(__zv) == IS_ARRAY) { \
if (Z_REFCOUNT_P(__zv) > 1) { \
if (Z_REFCOUNTED_P(__zv)) { \
Z_DELREF_P(__zv); \
} \
- zval_copy_ctor_func(__zv); \
+ ZVAL_ARR(__zv, zend_array_dup(Z_ARR_P(__zv)));\
} \
} \
} while (0)
@@ -1122,8 +1125,8 @@ static zend_always_inline uint32_t zval_delref_p(zval* pz) {
ZVAL_COPY_VALUE(_zv, &_r->val); \
if (GC_DELREF(_r) == 0) { \
efree_size(_r, sizeof(zend_reference)); \
- } else if (Z_OPT_COPYABLE_P(_zv)) { \
- zval_copy_ctor_func(_zv); \
+ } else if (Z_OPT_TYPE_P(_zv) == IS_ARRAY) { \
+ ZVAL_ARR(_zv, zend_array_dup(Z_ARR_P(_zv)));\
break; \
} else if (Z_OPT_REFCOUNTED_P(_zv)) { \
Z_ADDREF_P(_zv); \
diff --git a/Zend/zend_variables.h b/Zend/zend_variables.h
index 1f356bd000..9be2dc8d48 100644
--- a/Zend/zend_variables.h
+++ b/Zend/zend_variables.h
@@ -55,23 +55,19 @@ static zend_always_inline void i_zval_ptr_dtor(zval *zval_ptr ZEND_FILE_LINE_DC)
static zend_always_inline void _zval_copy_ctor(zval *zvalue ZEND_FILE_LINE_DC)
{
- if (Z_REFCOUNTED_P(zvalue) || Z_COPYABLE_P(zvalue)) {
- if (Z_COPYABLE_P(zvalue)) {
- _zval_copy_ctor_func(zvalue ZEND_FILE_LINE_RELAY_CC);
- } else {
- Z_ADDREF_P(zvalue);
- }
+ if (Z_TYPE_P(zvalue) == IS_ARRAY) {
+ ZVAL_ARR(zvalue, zend_array_dup(Z_ARR_P(zvalue)));
+ } else if (Z_REFCOUNTED_P(zvalue)) {
+ Z_ADDREF_P(zvalue);
}
}
static zend_always_inline void _zval_opt_copy_ctor(zval *zvalue ZEND_FILE_LINE_DC)
{
- if (Z_OPT_REFCOUNTED_P(zvalue) || Z_OPT_COPYABLE_P(zvalue)) {
- if (Z_OPT_COPYABLE_P(zvalue)) {
- _zval_copy_ctor_func(zvalue ZEND_FILE_LINE_RELAY_CC);
- } else {
- Z_ADDREF_P(zvalue);
- }
+ if (Z_OPT_TYPE_P(zvalue) == IS_ARRAY) {
+ ZVAL_ARR(zvalue, zend_array_dup(Z_ARR_P(zvalue)));
+ } else if (Z_OPT_REFCOUNTED_P(zvalue)) {
+ Z_ADDREF_P(zvalue);
}
}
diff --git a/ext/opcache/zend_persist.c b/ext/opcache/zend_persist.c
index 136255dbef..010cc9b533 100644
--- a/ext/opcache/zend_persist.c
+++ b/ext/opcache/zend_persist.c
@@ -289,7 +289,7 @@ static void zend_persist_zval(zval *z)
new_ptr = zend_shared_alloc_get_xlat_entry(Z_ARR_P(z));
if (new_ptr) {
Z_ARR_P(z) = new_ptr;
- Z_TYPE_FLAGS_P(z) = IS_TYPE_COPYABLE;
+ Z_TYPE_FLAGS_P(z) = 0;
} else {
if (!Z_REFCOUNTED_P(z)) {
Z_ARR_P(z) = zend_accel_memdup(Z_ARR_P(z), sizeof(zend_array));
@@ -299,7 +299,7 @@ static void zend_persist_zval(zval *z)
zend_accel_store(Z_ARR_P(z), sizeof(zend_array));
zend_hash_persist(Z_ARRVAL_P(z), zend_persist_zval);
/* make immutable array */
- Z_TYPE_FLAGS_P(z) = IS_TYPE_COPYABLE;
+ Z_TYPE_FLAGS_P(z) = 0;
GC_SET_REFCOUNT(Z_COUNTED_P(z), 2);
GC_FLAGS(Z_COUNTED_P(z)) |= IS_ARRAY_IMMUTABLE;
Z_ARRVAL_P(z)->u.flags |= HASH_FLAG_STATIC_KEYS;