summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Zend/zend_hash.h21
-rw-r--r--ext/opcache/zend_accelerator_util_funcs.c47
2 files changed, 55 insertions, 13 deletions
diff --git a/Zend/zend_hash.h b/Zend/zend_hash.h
index e11d57b1ca..220bccbb76 100644
--- a/Zend/zend_hash.h
+++ b/Zend/zend_hash.h
@@ -1099,14 +1099,14 @@ static zend_always_inline void *zend_hash_get_current_data_ptr_ex(HashTable *ht,
__fill_ht->nInternalPointer = 0; \
} while (0)
-static zend_always_inline zval *_zend_hash_append(HashTable *ht, zend_string *key, zval *zv)
+static zend_always_inline zval *_zend_hash_append_ex(HashTable *ht, zend_string *key, zval *zv, int interned)
{
uint32_t idx = ht->nNumUsed++;
uint32_t nIndex;
Bucket *p = ht->arData + idx;
ZVAL_COPY_VALUE(&p->val, zv);
- if (!ZSTR_IS_INTERNED(key)) {
+ if (!interned && !ZSTR_IS_INTERNED(key)) {
HT_FLAGS(ht) &= ~HASH_FLAG_STATIC_KEYS;
zend_string_addref(key);
zend_string_hash_val(key);
@@ -1116,19 +1116,23 @@ static zend_always_inline zval *_zend_hash_append(HashTable *ht, zend_string *ke
nIndex = (uint32_t)p->h | ht->nTableMask;
Z_NEXT(p->val) = HT_HASH(ht, nIndex);
HT_HASH(ht, nIndex) = HT_IDX_TO_HASH(idx);
- ht->nNumUsed = idx + 1;
ht->nNumOfElements++;
return &p->val;
}
-static zend_always_inline zval *_zend_hash_append_ptr(HashTable *ht, zend_string *key, void *ptr)
+static zend_always_inline zval *_zend_hash_append(HashTable *ht, zend_string *key, zval *zv)
+{
+ return _zend_hash_append_ex(ht, key, zv, 0);
+}
+
+static zend_always_inline zval *_zend_hash_append_ptr_ex(HashTable *ht, zend_string *key, void *ptr, int interned)
{
uint32_t idx = ht->nNumUsed++;
uint32_t nIndex;
Bucket *p = ht->arData + idx;
ZVAL_PTR(&p->val, ptr);
- if (!ZSTR_IS_INTERNED(key)) {
+ if (!interned && !ZSTR_IS_INTERNED(key)) {
HT_FLAGS(ht) &= ~HASH_FLAG_STATIC_KEYS;
zend_string_addref(key);
zend_string_hash_val(key);
@@ -1138,11 +1142,15 @@ static zend_always_inline zval *_zend_hash_append_ptr(HashTable *ht, zend_string
nIndex = (uint32_t)p->h | ht->nTableMask;
Z_NEXT(p->val) = HT_HASH(ht, nIndex);
HT_HASH(ht, nIndex) = HT_IDX_TO_HASH(idx);
- ht->nNumUsed = idx + 1;
ht->nNumOfElements++;
return &p->val;
}
+static zend_always_inline zval *_zend_hash_append_ptr(HashTable *ht, zend_string *key, void *ptr)
+{
+ return _zend_hash_append_ptr_ex(ht, key, ptr, 0);
+}
+
static zend_always_inline void _zend_hash_append_ind(HashTable *ht, zend_string *key, zval *ptr)
{
uint32_t idx = ht->nNumUsed++;
@@ -1160,7 +1168,6 @@ static zend_always_inline void _zend_hash_append_ind(HashTable *ht, zend_string
nIndex = (uint32_t)p->h | ht->nTableMask;
Z_NEXT(p->val) = HT_HASH(ht, nIndex);
HT_HASH(ht, nIndex) = HT_IDX_TO_HASH(idx);
- ht->nNumUsed = idx + 1;
ht->nNumOfElements++;
}
diff --git a/ext/opcache/zend_accelerator_util_funcs.c b/ext/opcache/zend_accelerator_util_funcs.c
index fe98d77d3b..a6d9b543a6 100644
--- a/ext/opcache/zend_accelerator_util_funcs.c
+++ b/ext/opcache/zend_accelerator_util_funcs.c
@@ -533,7 +533,7 @@ static void zend_accel_function_hash_copy_from_shm(HashTable *target, HashTable
goto failure;
}
} else {
- _zend_hash_append_ptr(target, p->key, ARENA_REALLOC(Z_PTR(p->val)));
+ _zend_hash_append_ptr_ex(target, p->key, ARENA_REALLOC(Z_PTR(p->val)), 1);
}
}
target->nInternalPointer = 0;
@@ -556,7 +556,7 @@ failure:
}
}
-static void zend_accel_class_hash_copy(HashTable *target, HashTable *source, unique_copy_ctor_func_t pCopyConstructor)
+static void zend_accel_class_hash_copy(HashTable *target, HashTable *source)
{
Bucket *p, *end;
zval *t;
@@ -587,9 +587,44 @@ static void zend_accel_class_hash_copy(HashTable *target, HashTable *source, uni
}
} else {
t = _zend_hash_append_ptr(target, p->key, Z_PTR(p->val));
- if (pCopyConstructor) {
- pCopyConstructor(&Z_PTR_P(t));
+ }
+ }
+ target->nInternalPointer = 0;
+ return;
+}
+
+static void zend_accel_class_hash_copy_from_shm(HashTable *target, HashTable *source)
+{
+ Bucket *p, *end;
+ zval *t;
+
+ zend_hash_extend(target, target->nNumUsed + source->nNumUsed, 0);
+ p = source->arData;
+ end = p + source->nNumUsed;
+ for (; p != end; p++) {
+ ZEND_ASSERT(Z_TYPE(p->val) != IS_UNDEF);
+ ZEND_ASSERT(p->key);
+ t = zend_hash_find_ex(target, p->key, 1);
+ if (UNEXPECTED(t != NULL)) {
+ if (EXPECTED(ZSTR_LEN(p->key) > 0) && EXPECTED(ZSTR_VAL(p->key)[0] == 0)) {
+ /* Mangled key - ignore and wait for runtime */
+ continue;
+ } else if (UNEXPECTED(!ZCG(accel_directives).ignore_dups)) {
+ zend_class_entry *ce1 = Z_PTR(p->val);
+ if (!(ce1->ce_flags & ZEND_ACC_ANON_CLASS)) {
+ CG(in_compilation) = 1;
+ zend_set_compiled_filename(ce1->info.user.filename);
+ CG(zend_lineno) = ce1->info.user.line_start;
+ zend_error(E_ERROR,
+ "Cannot declare %s %s, because the name is already in use",
+ zend_get_object_type(ce1), ZSTR_VAL(ce1->name));
+ return;
+ }
+ continue;
}
+ } else {
+ t = _zend_hash_append_ptr_ex(target, p->key, Z_PTR(p->val), 1);
+ zend_class_copy_ctor((zend_class_entry**)&Z_PTR_P(t));
}
}
target->nInternalPointer = 0;
@@ -771,7 +806,7 @@ zend_op_array* zend_accel_load_script(zend_persistent_script *persistent_script,
/* Copy all the necessary stuff from shared memory to regular memory, and protect the shared script */
if (zend_hash_num_elements(&persistent_script->script.class_table) > 0) {
- zend_accel_class_hash_copy(CG(class_table), &persistent_script->script.class_table, (unique_copy_ctor_func_t) zend_class_copy_ctor);
+ zend_accel_class_hash_copy_from_shm(CG(class_table), &persistent_script->script.class_table);
}
/* we must first to copy all classes and then prepare functions, since functions may try to bind
classes - which depend on pre-bind class entries existent in the class table */
@@ -799,7 +834,7 @@ zend_op_array* zend_accel_load_script(zend_persistent_script *persistent_script,
zend_accel_function_hash_copy(CG(function_table), &persistent_script->script.function_table);
}
if (zend_hash_num_elements(&persistent_script->script.class_table) > 0) {
- zend_accel_class_hash_copy(CG(class_table), &persistent_script->script.class_table, NULL);
+ zend_accel_class_hash_copy(CG(class_table), &persistent_script->script.class_table);
}
}