__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);
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);
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++;
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++;
}
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;
}
}
-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;
}
} 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;
/* 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 */
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);
}
}