diff options
Diffstat (limited to 'ext')
31 files changed, 184 insertions, 268 deletions
diff --git a/ext/dom/attr.c b/ext/dom/attr.c index 63be8762d1..b0489ef122 100644 --- a/ext/dom/attr.c +++ b/ext/dom/attr.c @@ -171,7 +171,7 @@ int dom_attr_value_write(dom_object *obj, zval *newval TSRMLS_DC) node_list_unlink(attrp->children TSRMLS_CC); } - str = zval_get_string(newval TSRMLS_CC); + str = zval_get_string(newval); xmlNodeSetContentLen((xmlNodePtr) attrp, str->val, str->len + 1); diff --git a/ext/dom/characterdata.c b/ext/dom/characterdata.c index b1b5d76d26..2ef6352f20 100644 --- a/ext/dom/characterdata.c +++ b/ext/dom/characterdata.c @@ -106,7 +106,7 @@ int dom_characterdata_data_write(dom_object *obj, zval *newval TSRMLS_DC) return FAILURE; } - str = zval_get_string(newval TSRMLS_CC); + str = zval_get_string(newval); xmlNodeSetContentLen(nodep, str->val, str->len + 1); diff --git a/ext/dom/document.c b/ext/dom/document.c index 35d8348a2d..b1c1dc2737 100644 --- a/ext/dom/document.c +++ b/ext/dom/document.c @@ -338,7 +338,7 @@ int dom_document_encoding_write(dom_object *obj, zval *newval TSRMLS_DC) return FAILURE; } - str = zval_get_string(newval TSRMLS_CC); + str = zval_get_string(newval); handler = xmlFindCharEncodingHandler(Z_STRVAL_P(newval)); @@ -436,7 +436,7 @@ int dom_document_version_write(dom_object *obj, zval *newval TSRMLS_DC) xmlFree((xmlChar *) docp->version ); } - str = zval_get_string(newval TSRMLS_CC); + str = zval_get_string(newval); docp->version = xmlStrdup((const xmlChar *) str->val); @@ -664,7 +664,7 @@ int dom_document_document_uri_write(dom_object *obj, zval *newval TSRMLS_DC) xmlFree((xmlChar *) docp->URL); } - str = zval_get_string(newval TSRMLS_CC); + str = zval_get_string(newval); docp->URL = xmlStrdup((const xmlChar *) str->val); diff --git a/ext/dom/node.c b/ext/dom/node.c index 57669b5069..25c8daee6f 100644 --- a/ext/dom/node.c +++ b/ext/dom/node.c @@ -343,7 +343,7 @@ int dom_node_node_value_write(dom_object *obj, zval *newval TSRMLS_DC) case XML_CDATA_SECTION_NODE: case XML_PI_NODE: { - zend_string *str = zval_get_string(newval TSRMLS_CC); + zend_string *str = zval_get_string(newval); xmlNodeSetContentLen(nodep, str->val, str->len + 1); STR_RELEASE(str); break; @@ -720,7 +720,7 @@ int dom_node_prefix_write(dom_object *obj, zval *newval TSRMLS_DC) nsnode = xmlDocGetRootElement(nodep->doc); } } - str = zval_get_string(newval TSRMLS_CC); + str = zval_get_string(newval); prefix = str->val; if (nsnode && nodep->ns != NULL && !xmlStrEqual(nodep->ns->prefix, (xmlChar *)prefix)) { strURI = (char *) nodep->ns->href; diff --git a/ext/dom/php_dom.c b/ext/dom/php_dom.c index 99d99e236f..9f971ee0ac 100644 --- a/ext/dom/php_dom.c +++ b/ext/dom/php_dom.c @@ -313,7 +313,7 @@ static void dom_register_prop_handler(HashTable *prop_handler, char *name, dom_r static zval *dom_get_property_ptr_ptr(zval *object, zval *member, int type, zend_uint cache_slot TSRMLS_DC) /* {{{ */ { dom_object *obj = Z_DOMOBJ_P(object); - zend_string *member_str = zval_get_string(member TSRMLS_CC); + zend_string *member_str = zval_get_string(member); zval *retval = NULL; if (!obj->prop_handler || !zend_hash_exists(obj->prop_handler, member_str)) { @@ -330,7 +330,7 @@ static zval *dom_get_property_ptr_ptr(zval *object, zval *member, int type, zend zval *dom_read_property(zval *object, zval *member, int type, zend_uint cache_slot, zval *rv TSRMLS_DC) { dom_object *obj = Z_DOMOBJ_P(object); - zend_string *member_str = zval_get_string(member TSRMLS_CC); + zend_string *member_str = zval_get_string(member); zval *retval; dom_prop_handler *hnd = NULL; @@ -361,7 +361,7 @@ zval *dom_read_property(zval *object, zval *member, int type, zend_uint cache_sl void dom_write_property(zval *object, zval *member, zval *value, zend_uint cache_slot TSRMLS_DC) { dom_object *obj = Z_DOMOBJ_P(object); - zend_string *member_str = zval_get_string(member TSRMLS_CC); + zend_string *member_str = zval_get_string(member); dom_prop_handler *hnd = NULL; if (obj->prop_handler != NULL) { @@ -382,7 +382,7 @@ void dom_write_property(zval *object, zval *member, zval *value, zend_uint cache static int dom_property_exists(zval *object, zval *member, int check_empty, zend_uint cache_slot TSRMLS_DC) { dom_object *obj = Z_DOMOBJ_P(object); - zend_string *member_str = zval_get_string(member TSRMLS_CC); + zend_string *member_str = zval_get_string(member); dom_prop_handler *hnd = NULL; int retval = 0; diff --git a/ext/dom/processinginstruction.c b/ext/dom/processinginstruction.c index aef9e92b64..36b159cc6e 100644 --- a/ext/dom/processinginstruction.c +++ b/ext/dom/processinginstruction.c @@ -145,7 +145,7 @@ int dom_processinginstruction_data_write(dom_object *obj, zval *newval TSRMLS_DC return FAILURE; } - str = zval_get_string(newval TSRMLS_CC); + str = zval_get_string(newval); xmlNodeSetContentLen(nodep, str->val, str->len + 1); diff --git a/ext/dom/xpath.c b/ext/dom/xpath.c index 08bb8603a5..3290a3a5e7 100644 --- a/ext/dom/xpath.c +++ b/ext/dom/xpath.c @@ -522,7 +522,7 @@ PHP_FUNCTION(dom_xpath_register_php_functions) intern = Z_XPATHOBJ_P(id); zend_hash_internal_pointer_reset(Z_ARRVAL_P(array_value)); while ((entry = zend_hash_get_current_data(Z_ARRVAL_P(array_value)))) { - zend_string *str = zval_get_string(entry TSRMLS_CC); + zend_string *str = zval_get_string(entry); ZVAL_LONG(&new_string,1); zend_hash_update(intern->registered_phpfunctions, str, &new_string); zend_hash_move_forward(Z_ARRVAL_P(array_value)); diff --git a/ext/opcache/Optimizer/block_pass.c b/ext/opcache/Optimizer/block_pass.c index 2260af80bc..51ab3cd97b 100644 --- a/ext/opcache/Optimizer/block_pass.c +++ b/ext/opcache/Optimizer/block_pass.c @@ -1038,9 +1038,6 @@ static void zend_optimize_block(zend_code_block *block, zend_op_array *op_array, er = EG(error_reporting); EG(error_reporting) = 0; if (binary_op(&result, &ZEND_OP1_LITERAL(opline), &ZEND_OP2_LITERAL(opline) TSRMLS_CC) == SUCCESS) { -//??? PZ_SET_REFCOUNT_P(&result, 1); -//??? PZ_UNSET_ISREF_P(&result); - literal_dtor(&ZEND_OP1_LITERAL(opline)); literal_dtor(&ZEND_OP2_LITERAL(opline)); opline->opcode = ZEND_QM_ASSIGN; @@ -1068,8 +1065,6 @@ static void zend_optimize_block(zend_code_block *block, zend_op_array *op_array, convert_to_boolean(&result); ZVAL_NULL(&ZEND_OP1_LITERAL(opline)); } -//??? PZ_SET_REFCOUNT_P(&result, 1); -//??? PZ_UNSET_ISREF_P(&result); opline->opcode = ZEND_QM_ASSIGN; update_op1_const(op_array, opline, &result TSRMLS_CC); } else if ((opline->opcode == ZEND_RETURN || opline->opcode == ZEND_EXIT) && @@ -1654,11 +1649,6 @@ next_target: char *same_t=NULL; zend_code_block *target_block; int var_num = op_array->last_var + op_array->T; -//??? if (op_array->T >= (zend_uint)op_array->last_var) { -//??? var_num = op_array->T; -//??? } else { -//??? var_num = op_array->last_var; -//??? } if (var_num <= 0) { return; diff --git a/ext/opcache/Optimizer/compact_literals.c b/ext/opcache/Optimizer/compact_literals.c index 6c3bf41ec3..59628243f6 100644 --- a/ext/opcache/Optimizer/compact_literals.c +++ b/ext/opcache/Optimizer/compact_literals.c @@ -396,13 +396,6 @@ static void optimizer_compact_literals(zend_op_array *op_array TSRMLS_DC) op_array->literals[j] = op_array->literals[i]; info[j] = info[i]; } -//??? if (!Z_STR(op_array->literals[j].hash_value) { -//??? if (IS_INTERNED(Z_STRVAL(op_array->literals[j].constant))) { -//??? op_array->literals[j].hash_value = INTERNED_HASH(Z_STRVAL(op_array->literals[j].constant)); -//??? } else { -//??? op_array->literals[j].hash_value = zend_hash_func(Z_STRVAL(op_array->literals[j].constant), Z_STRLEN(op_array->literals[j].constant)+1); -//??? } -//??? } if (LITERAL_NUM_SLOTS(info[i].flags)) { Z_CACHE_SLOT(op_array->literals[j]) = cache_slots; cache_slots += LITERAL_NUM_SLOTS(info[i].flags); @@ -412,13 +405,6 @@ static void optimizer_compact_literals(zend_op_array *op_array TSRMLS_DC) while (n > 1) { i++; if (i != j) op_array->literals[j] = op_array->literals[i]; -//??? if (!op_array->literals[j].hash_value) { -//??? if (IS_INTERNED(Z_STRVAL(op_array->literals[j].constant))) { -//??? op_array->literals[j].hash_value = INTERNED_HASH(Z_STRVAL(op_array->literals[j].constant)); -//??? } else { -//??? op_array->literals[j].hash_value = zend_hash_func(Z_STRVAL(op_array->literals[j].constant), Z_STRLEN(op_array->literals[j].constant)+1); -//??? } -//??? } j++; n--; } diff --git a/ext/opcache/Optimizer/pass1_5.c b/ext/opcache/Optimizer/pass1_5.c index 207b8d0e61..4e1410a76e 100644 --- a/ext/opcache/Optimizer/pass1_5.c +++ b/ext/opcache/Optimizer/pass1_5.c @@ -60,9 +60,6 @@ if (ZEND_OPTIMIZER_PASS_1 & OPTIMIZATION_LEVEL) { break; } EG(error_reporting) = er; -//??? PZ_SET_REFCOUNT_P(&result, 1); -//??? PZ_UNSET_ISREF_P(&result); - literal_dtor(&ZEND_OP1_LITERAL(opline)); literal_dtor(&ZEND_OP2_LITERAL(opline)); MAKE_NOP(opline); @@ -134,9 +131,6 @@ if (ZEND_OPTIMIZER_PASS_1 & OPTIMIZATION_LEVEL) { break; } EG(error_reporting) = er; -//??? PZ_SET_REFCOUNT_P(&result, 1); -//??? PZ_UNSET_ISREF_P(&result); - literal_dtor(&ZEND_OP1_LITERAL(opline)); MAKE_NOP(opline); diff --git a/ext/opcache/Optimizer/zend_optimizer.c b/ext/opcache/Optimizer/zend_optimizer.c index 0498bcba07..39f7b01eea 100644 --- a/ext/opcache/Optimizer/zend_optimizer.c +++ b/ext/opcache/Optimizer/zend_optimizer.c @@ -170,24 +170,20 @@ static void update_op1_const(zend_op_array *op_array, case ZEND_FETCH_CONSTANT: opline->op1.constant = zend_optimizer_add_literal(op_array, val TSRMLS_CC); STR_HASH_VAL(Z_STR(ZEND_OP1_LITERAL(opline))); -//??? Z_HASH_P(&ZEND_OP1_LITERAL(opline)) = zend_hash_func(Z_STRVAL(ZEND_OP1_LITERAL(opline)), Z_STRLEN(ZEND_OP1_LITERAL(opline)) + 1); Z_CACHE_SLOT(op_array->literals[opline->op1.constant]) = op_array->last_cache_slot++; zend_str_tolower(Z_STRVAL_P(val), Z_STRLEN_P(val)); zend_optimizer_add_literal(op_array, val TSRMLS_CC); STR_HASH_VAL(Z_STR(op_array->literals[opline->op1.constant+1])); -//??? op_array->literals[opline->op1.constant+1].hash_value = zend_hash_func(Z_STRVAL(op_array->literals[opline->op1.constant+1].constant), Z_STRLEN(op_array->literals[opline->op1.constant+1].constant) + 1); break; case ZEND_DO_FCALL: zend_str_tolower(Z_STRVAL_P(val), Z_STRLEN_P(val)); opline->op1.constant = zend_optimizer_add_literal(op_array, val TSRMLS_CC); STR_HASH_VAL(Z_STR(ZEND_OP1_LITERAL(opline))); -//??? Z_HASH_P(&ZEND_OP1_LITERAL(opline)) = zend_hash_func(Z_STRVAL(ZEND_OP1_LITERAL(opline)), Z_STRLEN(ZEND_OP1_LITERAL(opline)) + 1); Z_CACHE_SLOT(op_array->literals[opline->op1.constant]) = op_array->last_cache_slot++; break; default: opline->op1.constant = zend_optimizer_add_literal(op_array, val TSRMLS_CC); STR_HASH_VAL(Z_STR(ZEND_OP1_LITERAL(opline))); -//??? Z_HASH_P(&ZEND_OP1_LITERAL(opline)) = zend_hash_func(Z_STRVAL(ZEND_OP1_LITERAL(opline)), Z_STRLEN(ZEND_OP1_LITERAL(opline)) + 1); break; } } else { @@ -208,7 +204,6 @@ static void update_op2_const(zend_op_array *op_array, opline->op2.constant = zend_optimizer_add_literal(op_array, val TSRMLS_CC); if (Z_TYPE_P(val) == IS_STRING) { STR_HASH_VAL(Z_STR(ZEND_OP2_LITERAL(opline))); -//??? Z_HASH_P(&ZEND_OP2_LITERAL(opline)) = zend_hash_func(Z_STRVAL(ZEND_OP2_LITERAL(opline)), Z_STRLEN(ZEND_OP2_LITERAL(opline)) + 1); switch (opline->opcode) { case ZEND_FETCH_R: case ZEND_FETCH_W: @@ -227,14 +222,12 @@ static void update_op2_const(zend_op_array *op_array, zend_str_tolower(Z_STRVAL_P(val), Z_STRLEN_P(val)); zend_optimizer_add_literal(op_array, val TSRMLS_CC); STR_HASH_VAL(Z_STR(op_array->literals[opline->op2.constant+1])); -//??? op_array->literals[opline->op2.constant+1].hash_value = zend_hash_func(Z_STRVAL(op_array->literals[opline->op2.constant+1].constant), Z_STRLEN(op_array->literals[opline->op2.constant+1].constant) + 1); break; case ZEND_INIT_METHOD_CALL: case ZEND_INIT_STATIC_METHOD_CALL: zend_str_tolower(Z_STRVAL_P(val), Z_STRLEN_P(val)); zend_optimizer_add_literal(op_array, val TSRMLS_CC); STR_HASH_VAL(Z_STR(op_array->literals[opline->op2.constant+1])); -//??? op_array->literals[opline->op2.constant+1].hash_value = zend_hash_func(Z_STRVAL(op_array->literals[opline->op2.constant+1].constant), Z_STRLEN(op_array->literals[opline->op2.constant+1].constant) + 1); /* break missing intentionally */ /*case ZEND_FETCH_CONSTANT:*/ case ZEND_ASSIGN_OBJ: diff --git a/ext/opcache/ZendAccelerator.c b/ext/opcache/ZendAccelerator.c index 01dfd5c2a9..84c397d7ab 100644 --- a/ext/opcache/ZendAccelerator.c +++ b/ext/opcache/ZendAccelerator.c @@ -1247,6 +1247,8 @@ static const struct jit_auto_global_info #endif }; +static zend_string *jit_auto_globals_str[4]; + static int zend_accel_get_auto_globals(TSRMLS_D) { int i, ag_size = (sizeof(jit_auto_globals_info) / sizeof(jit_auto_globals_info[0])); @@ -1254,7 +1256,7 @@ static int zend_accel_get_auto_globals(TSRMLS_D) int mask = 0; for (i = 0; i < ag_size ; i++) { - if (zend_hash_str_exists(&EG(symbol_table).ht, jit_auto_globals_info[i].name, jit_auto_globals_info[i].len)) { + if (zend_hash_exists(&EG(symbol_table).ht, jit_auto_globals_str[i])) { mask |= n; } n += n; @@ -1265,7 +1267,7 @@ static int zend_accel_get_auto_globals(TSRMLS_D) #if ZEND_EXTENSION_API_NO > PHP_5_3_X_API_NO static int zend_accel_get_auto_globals_no_jit(TSRMLS_D) { - if (zend_hash_str_exists(&EG(symbol_table).ht, jit_auto_globals_info[3].name, jit_auto_globals_info[3].len)) { + if (zend_hash_exists(&EG(symbol_table).ht, jit_auto_globals_str[3])) { return 8; } return 0; @@ -1276,19 +1278,26 @@ static void zend_accel_set_auto_globals(int mask TSRMLS_DC) { int i, ag_size = (sizeof(jit_auto_globals_info) / sizeof(jit_auto_globals_info[0])); int n = 1; - zend_string *str; for (i = 0; i < ag_size ; i++) { if (mask & n) { -//??? - str = STR_INIT(jit_auto_globals_info[i].name, jit_auto_globals_info[i].len, 0); - zend_is_auto_global(str TSRMLS_CC); - STR_RELEASE(str); + zend_is_auto_global(jit_auto_globals_str[i] TSRMLS_CC); } n += n; } } +static void zend_accel_init_auto_globals(TSRMLS_D) +{ + int i, ag_size = (sizeof(jit_auto_globals_info) / sizeof(jit_auto_globals_info[0])); + + for (i = 0; i < ag_size ; i++) { + jit_auto_globals_str[i] = STR_INIT(jit_auto_globals_info[i].name, jit_auto_globals_info[i].len, 1); + STR_HASH_VAL(jit_auto_globals_str[i]); + jit_auto_globals_str[i] = accel_new_interned_string(jit_auto_globals_str[i] TSRMLS_CC); + } +} + static zend_persistent_script *compile_and_cache_file(zend_file_handle *file_handle, int type, char *key, unsigned int key_length, zend_op_array **op_array_p, int *from_shared_memory TSRMLS_DC) { zend_persistent_script *new_persistent_script; @@ -2342,7 +2351,7 @@ static void zend_accel_fast_shutdown(TSRMLS_D) } zend_end_try(); EG(symbol_table).ht.pDestructor = old_destructor; } - zend_hash_init(&EG(symbol_table).ht, 0, NULL, NULL, 0); + zend_hash_init(&EG(symbol_table).ht, 8, NULL, NULL, 0); old_destructor = EG(function_table)->pDestructor; EG(function_table)->pDestructor = NULL; zend_hash_reverse_apply(EG(function_table), (apply_func_t) accel_clean_non_persistent_function TSRMLS_CC); @@ -2624,6 +2633,9 @@ static int accel_startup(zend_extension *extension) /* from this point further, shared memory is supposed to be OK */ + /* Init auto-global strings */ + zend_accel_init_auto_globals(TSRMLS_C); + /* Override compiler */ accelerator_orig_compile_file = zend_compile_file; zend_compile_file = persistent_compile_file; diff --git a/ext/opcache/zend_accelerator_util_funcs.c b/ext/opcache/zend_accelerator_util_funcs.c index 51051dd6ce..c93bec7994 100644 --- a/ext/opcache/zend_accelerator_util_funcs.c +++ b/ext/opcache/zend_accelerator_util_funcs.c @@ -77,12 +77,12 @@ zend_persistent_script* create_persistent_script(void) zend_persistent_script *persistent_script = (zend_persistent_script *) emalloc(sizeof(zend_persistent_script)); memset(persistent_script, 0, sizeof(zend_persistent_script)); - zend_hash_init(&persistent_script->function_table, 100, NULL, (dtor_func_t) zend_accel_destroy_zend_function, 0); + zend_hash_init(&persistent_script->function_table, 128, NULL, (dtor_func_t) zend_accel_destroy_zend_function, 0); /* class_table is usually destroyed by free_persistent_script() that * overrides destructor. ZEND_CLASS_DTOR may be used by standard * PHP compiler */ - zend_hash_init(&persistent_script->class_table, 10, NULL, ZEND_CLASS_DTOR, 0); + zend_hash_init(&persistent_script->class_table, 16, NULL, ZEND_CLASS_DTOR, 0); return persistent_script; } @@ -95,7 +95,7 @@ static int compact_hash_table(HashTable *ht) Bucket *d; Bucket *p; - if (!ht->nNumOfElements || (ht->flags & HASH_FLAG_PACKED)) { + if (!ht->nNumOfElements || (ht->u.flags & HASH_FLAG_PACKED)) { /* Empty tables don't allocate space for Buckets */ return 1; } @@ -115,7 +115,7 @@ static int compact_hash_table(HashTable *ht) return 1; } - d = (Bucket *)pemalloc(nSize * (sizeof(Bucket) + sizeof(zend_uint)), ht->flags & HASH_FLAG_PERSISTENT); + d = (Bucket *)pemalloc(nSize * (sizeof(Bucket) + sizeof(zend_uint)), ht->u.flags & HASH_FLAG_PERSISTENT); if (!d) { return 0; } @@ -128,7 +128,7 @@ static int compact_hash_table(HashTable *ht) } ht->nNumUsed = j; - pefree(ht->arData, ht->flags & HASH_FLAG_PERSISTENT); + pefree(ht->arData, ht->u.flags & HASH_FLAG_PERSISTENT); ht->arData = d; ht->arHash = (zend_uint *)(d + nSize); @@ -360,11 +360,10 @@ static void zend_hash_clone_zval(HashTable *ht, HashTable *source, int bind) ht->nNumOfElements = source->nNumOfElements; ht->nNextFreeElement = source->nNextFreeElement; ht->pDestructor = ZVAL_PTR_DTOR; - ht->flags = HASH_FLAG_APPLY_PROTECTION; + ht->u.flags = HASH_FLAG_APPLY_PROTECTION; ht->arData = NULL; ht->arHash = NULL; ht->nInternalPointer = source->nNumOfElements ? 0 : INVALID_IDX; - ht->nApplyCount = 0; #if ZEND_EXTENSION_API_NO > PHP_5_3_X_API_NO if (!ht->nTableMask) { @@ -373,8 +372,8 @@ static void zend_hash_clone_zval(HashTable *ht, HashTable *source, int bind) } #endif - if (source->flags & HASH_FLAG_PACKED) { - ht->flags |= HASH_FLAG_PACKED; + if (source->u.flags & HASH_FLAG_PACKED) { + ht->u.flags |= HASH_FLAG_PACKED; ht->arData = (Bucket *) emalloc(ht->nTableSize * sizeof(Bucket)); ht->arHash = (zend_uint*)&uninitialized_bucket; } else { @@ -389,7 +388,7 @@ static void zend_hash_clone_zval(HashTable *ht, HashTable *source, int bind) nIndex = p->h & ht->nTableMask; /* Insert into hash collision list */ - if (source->flags & HASH_FLAG_PACKED) { + if (source->u.flags & HASH_FLAG_PACKED) { Bucket *r = ht->arData + ht->nNumUsed; q = ht->arData + p->h; while (r != q) { @@ -432,9 +431,8 @@ static void zend_hash_clone_methods(HashTable *ht, HashTable *source, zend_class ht->nNumOfElements = source->nNumOfElements; ht->nNextFreeElement = source->nNextFreeElement; ht->pDestructor = ZEND_FUNCTION_DTOR; - ht->flags = HASH_FLAG_APPLY_PROTECTION; + ht->u.flags = HASH_FLAG_APPLY_PROTECTION; ht->nInternalPointer = source->nNumOfElements ? 0 : INVALID_IDX; - ht->nApplyCount = 0; #if ZEND_EXTENSION_API_NO > PHP_5_3_X_API_NO if (!ht->nTableMask) { @@ -443,8 +441,8 @@ static void zend_hash_clone_methods(HashTable *ht, HashTable *source, zend_class } #endif - if (source->flags & HASH_FLAG_PACKED) { - ht->flags |= HASH_FLAG_PACKED; + if (source->u.flags & HASH_FLAG_PACKED) { + ht->u.flags |= HASH_FLAG_PACKED; ht->arData = (Bucket *) emalloc(ht->nTableSize * sizeof(Bucket)); ht->arHash = (zend_uint*)&uninitialized_bucket; } else { @@ -460,7 +458,7 @@ static void zend_hash_clone_methods(HashTable *ht, HashTable *source, zend_class nIndex = p->h & ht->nTableMask; /* Insert into hash collision list */ - if (source->flags & HASH_FLAG_PACKED) { + if (source->u.flags & HASH_FLAG_PACKED) { Bucket *r = ht->arData + ht->nNumUsed; q = ht->arData + p->h; while (r != q) { @@ -530,9 +528,8 @@ static void zend_hash_clone_prop_info(HashTable *ht, HashTable *source, zend_cla ht->nNumOfElements = source->nNumOfElements; ht->nNextFreeElement = source->nNextFreeElement; ht->pDestructor = zend_destroy_property_info; - ht->flags = HASH_FLAG_APPLY_PROTECTION; + ht->u.flags = HASH_FLAG_APPLY_PROTECTION; ht->nInternalPointer = source->nNumOfElements ? 0 : INVALID_IDX; - ht->nApplyCount = 0; #if ZEND_EXTENSION_API_NO > PHP_5_3_X_API_NO if (!ht->nTableMask) { @@ -541,9 +538,9 @@ static void zend_hash_clone_prop_info(HashTable *ht, HashTable *source, zend_cla } #endif - if (source->flags & HASH_FLAG_PACKED) { + if (source->u.flags & HASH_FLAG_PACKED) { ht->arData = (Bucket *) emalloc(ht->nTableSize * sizeof(Bucket)); - ht->flags |= HASH_FLAG_PACKED; + ht->u.flags |= HASH_FLAG_PACKED; ht->arHash = (zend_uint*)&uninitialized_bucket; } else { ht->arData = (Bucket *) emalloc(ht->nTableSize * (sizeof(Bucket) + sizeof(zend_uint))); @@ -558,7 +555,7 @@ static void zend_hash_clone_prop_info(HashTable *ht, HashTable *source, zend_cla nIndex = p->h & ht->nTableMask; /* Insert into hash collision list */ - if (source->flags & HASH_FLAG_PACKED) { + if (source->u.flags & HASH_FLAG_PACKED) { Bucket *r = ht->arData + ht->nNumUsed; q = ht->arData + p->h; while (r != q) { diff --git a/ext/opcache/zend_persist.c b/ext/opcache/zend_persist.c index ca8835c2ed..ca2ad5150c 100644 --- a/ext/opcache/zend_persist.c +++ b/ext/opcache/zend_persist.c @@ -79,7 +79,7 @@ static void zend_hash_persist(HashTable *ht, zend_persist_func_t pPersistElement ht->arHash = (zend_uint*)&uninitialized_bucket; return; } - if (ht->flags & HASH_FLAG_PACKED) { + if (ht->u.flags & HASH_FLAG_PACKED) { zend_accel_store(ht->arData, sizeof(Bucket) * ht->nTableSize); ht->arHash = (zend_uint*)&uninitialized_bucket; } else { diff --git a/ext/opcache/zend_persist_calc.c b/ext/opcache/zend_persist_calc.c index 20e6b083c4..6298fb1aa2 100644 --- a/ext/opcache/zend_persist_calc.c +++ b/ext/opcache/zend_persist_calc.c @@ -62,7 +62,7 @@ static uint zend_hash_persist_calc(HashTable *ht, uint (*pPersistElement)(zval * if (!ht->nTableMask) { RETURN_SIZE(); } - if (ht->flags & HASH_FLAG_PACKED) { + if (ht->u.flags & HASH_FLAG_PACKED) { ADD_DUP_SIZE(ht->arData, sizeof(Bucket) * ht->nTableSize); } else { ADD_DUP_SIZE(ht->arData, (sizeof(Bucket) + sizeof(zend_uint)) * ht->nTableSize); diff --git a/ext/opcache/zend_shared_alloc.c b/ext/opcache/zend_shared_alloc.c index 4a31d3de6a..0faabee8b2 100644 --- a/ext/opcache/zend_shared_alloc.c +++ b/ext/opcache/zend_shared_alloc.c @@ -402,7 +402,7 @@ void zend_shared_alloc_lock(TSRMLS_D) * won't be taken from space which is freed by efree in memdup. * Otherwise it leads to false matches in memdup check. */ - zend_hash_init(&xlat_table, 100, NULL, NULL, 1); + zend_hash_init(&xlat_table, 128, NULL, NULL, 1); } void zend_shared_alloc_unlock(TSRMLS_D) diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index d2a6790d6b..4940457333 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -655,23 +655,13 @@ static void _class_string(string *str, zend_class_entry *ce, zval *obj, char *in /* {{{ _const_string */ static void _const_string(string *str, char *name, zval *value, char *indent TSRMLS_DC) { - char *type; - zval value_copy; - int use_copy; - - type = zend_zval_type_name(value); - - zend_make_printable_zval(value, &value_copy, &use_copy); - if (use_copy) { - value = &value_copy; - } + char *type = zend_zval_type_name(value); + zend_string *value_str = zval_get_string(value); string_printf(str, "%s Constant [ %s %s ] { %s }\n", - indent, type, name, Z_STRVAL_P(value)); + indent, type, name, value_str->val); - if (use_copy) { - zval_dtor(value); - } + STR_RELEASE(value_str); } /* }}} */ @@ -728,8 +718,7 @@ static void _parameter_string(string *str, zend_function *fptr, struct _zend_arg if (fptr->type == ZEND_USER_FUNCTION && offset >= required) { zend_op *precv = _get_recv_op((zend_op_array*)fptr, offset); if (precv && precv->opcode == ZEND_RECV_INIT && precv->op2_type != IS_UNUSED) { - zval zv, zv_copy; - int use_copy; + zval zv; string_write(str, " = ", sizeof(" = ")-1); ZVAL_DUP(&zv, precv->op2.zv); zval_update_constant_ex(&zv, (void*)1, fptr->common.scope TSRMLS_CC); @@ -751,11 +740,9 @@ static void _parameter_string(string *str, zend_function *fptr, struct _zend_arg } else if (Z_TYPE(zv) == IS_ARRAY) { string_write(str, "Array", sizeof("Array")-1); } else { - zend_make_printable_zval(&zv, &zv_copy, &use_copy); - string_write(str, Z_STRVAL(zv_copy), Z_STRLEN(zv_copy)); - if (use_copy) { - zval_dtor(&zv_copy); - } + zend_string *zv_str = zval_get_string(&zv); + string_write(str, zv_str->val, zv_str->len); + STR_RELEASE(zv_str); } zval_ptr_dtor(&zv); } @@ -1529,7 +1516,7 @@ ZEND_METHOD(reflection, export) ZVAL_COPY_VALUE(return_value, &retval); } else { /* No need for _r variant, return of __toString should always be a string */ - zend_print_zval(&retval, 0); + zend_print_zval(&retval, 0 TSRMLS_CC); zend_printf("\n"); zval_ptr_dtor(&retval); } @@ -4974,11 +4961,6 @@ ZEND_METHOD(reflection_property, getValue) zend_unmangle_property_name(ref->prop.name->val, ref->prop.name->len, &class_name, &prop_name); member_p = zend_read_property(ref->ce, object, prop_name, strlen(prop_name), 1 TSRMLS_CC); ZVAL_DUP(return_value, member_p); -//??? - if (member_p != &EG(uninitialized_zval)) { - zval_add_ref(member_p); - zval_ptr_dtor(member_p); - } } } /* }}} */ diff --git a/ext/spl/spl_array.c b/ext/spl/spl_array.c index 208f9de7a6..eafc280f0e 100644 --- a/ext/spl/spl_array.c +++ b/ext/spl/spl_array.c @@ -129,7 +129,7 @@ SPL_API int spl_hash_verify_pos_ex(spl_array_object * intern, HashTable * ht TSR /* IS_CONSISTENT(ht);*/ /* HASH_PROTECT_RECURSION(ht);*/ - if (ht->flags & HASH_FLAG_PACKED) { + if (ht->u.flags & HASH_FLAG_PACKED) { if (intern->pos_h == intern->pos && Z_TYPE(ht->arData[intern->pos_h].val) != IS_UNDEF) { return SUCCESS; } @@ -309,7 +309,7 @@ static zval *spl_array_get_dimension_ptr(int check_inherited, zval *object, zval return &EG(uninitialized_zval); } - if ((type == BP_VAR_W || type == BP_VAR_RW) && (ht->nApplyCount > 0)) { + if ((type == BP_VAR_W || type == BP_VAR_RW) && (ht->u.v.nApplyCount > 0)) { zend_error(E_WARNING, "Modification of ArrayObject during sorting is prohibited"); return &EG(error_zval);; } @@ -464,7 +464,7 @@ static void spl_array_write_dimension_ex(int check_inherited, zval *object, zval if (!offset) { ht = spl_array_get_hash_table(intern, 0 TSRMLS_CC); - if (ht->nApplyCount > 0) { + if (ht->u.v.nApplyCount > 0) { zend_error(E_WARNING, "Modification of ArrayObject during sorting is prohibited"); return; } @@ -481,7 +481,7 @@ static void spl_array_write_dimension_ex(int check_inherited, zval *object, zval switch (Z_TYPE_P(offset)) { case IS_STRING: ht = spl_array_get_hash_table(intern, 0 TSRMLS_CC); - if (ht->nApplyCount > 0) { + if (ht->u.v.nApplyCount > 0) { zend_error(E_WARNING, "Modification of ArrayObject during sorting is prohibited"); return; } @@ -492,7 +492,7 @@ static void spl_array_write_dimension_ex(int check_inherited, zval *object, zval case IS_BOOL: case IS_LONG: ht = spl_array_get_hash_table(intern, 0 TSRMLS_CC); - if (ht->nApplyCount > 0) { + if (ht->u.v.nApplyCount > 0) { zend_error(E_WARNING, "Modification of ArrayObject during sorting is prohibited"); return; } @@ -505,7 +505,7 @@ static void spl_array_write_dimension_ex(int check_inherited, zval *object, zval return; case IS_NULL: ht = spl_array_get_hash_table(intern, 0 TSRMLS_CC); - if (ht->nApplyCount > 0) { + if (ht->u.v.nApplyCount > 0) { zend_error(E_WARNING, "Modification of ArrayObject during sorting is prohibited"); return; } @@ -538,7 +538,7 @@ static void spl_array_unset_dimension_ex(int check_inherited, zval *object, zval switch(Z_TYPE_P(offset)) { case IS_STRING: ht = spl_array_get_hash_table(intern, 0 TSRMLS_CC); - if (ht->nApplyCount > 0) { + if (ht->u.v.nApplyCount > 0) { zend_error(E_WARNING, "Modification of ArrayObject during sorting is prohibited"); return; } @@ -583,7 +583,7 @@ static void spl_array_unset_dimension_ex(int check_inherited, zval *object, zval index = Z_LVAL_P(offset); } ht = spl_array_get_hash_table(intern, 0 TSRMLS_CC); - if (ht->nApplyCount > 0) { + if (ht->u.v.nApplyCount > 0) { zend_error(E_WARNING, "Modification of ArrayObject during sorting is prohibited"); return; } @@ -827,7 +827,7 @@ static HashTable* spl_array_get_debug_info(zval *obj, int *is_temp TSRMLS_DC) /* ZEND_INIT_SYMTABLE_EX(intern->debug_info, zend_hash_num_elements(intern->std.properties) + 1, 0); } - if (intern->debug_info->nApplyCount == 0) { + if (intern->debug_info->u.v.nApplyCount == 0) { zend_hash_clean(intern->debug_info); zend_hash_copy(intern->debug_info, intern->std.properties, (copy_ctor_func_t) zval_add_ref); @@ -1446,27 +1446,27 @@ static void spl_array_method(INTERNAL_FUNCTION_PARAMETERS, char *fname, int fnam *Z_ARRVAL(tmp) = *aht; if (!use_arg) { - aht->nApplyCount++; + aht->u.v.nApplyCount++; zend_call_method(NULL, NULL, NULL, fname, fname_len, &retval, 1, &tmp, NULL TSRMLS_CC); - aht->nApplyCount--; + aht->u.v.nApplyCount--; } else if (use_arg == SPL_ARRAY_METHOD_MAY_USER_ARG) { if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "|z", &arg) == FAILURE) { zval_ptr_dtor(&tmp); zend_throw_exception(spl_ce_BadMethodCallException, "Function expects one argument at most", 0 TSRMLS_CC); return; } - aht->nApplyCount++; + aht->u.v.nApplyCount++; zend_call_method(NULL, NULL, NULL, fname, fname_len, &retval, arg? 2 : 1, &tmp, arg TSRMLS_CC); - aht->nApplyCount--; + aht->u.v.nApplyCount--; } else { if (ZEND_NUM_ARGS() != 1 || zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "z", &arg) == FAILURE) { zval_ptr_dtor(&tmp); zend_throw_exception(spl_ce_BadMethodCallException, "Function expects exactly one argument", 0 TSRMLS_CC); return; } - aht->nApplyCount++; + aht->u.v.nApplyCount++; zend_call_method(NULL, NULL, NULL, fname, fname_len, &retval, 2, &tmp, arg TSRMLS_CC); - aht->nApplyCount--; + aht->u.v.nApplyCount--; } /* A tricky way to pass "aht" by reference, copy back and cleanup */ if (Z_ISREF(tmp) && Z_TYPE_P(Z_REFVAL(tmp))) { diff --git a/ext/spl/spl_dllist.c b/ext/spl/spl_dllist.c index 6bc21ee814..dc10dde6e9 100644 --- a/ext/spl/spl_dllist.c +++ b/ext/spl/spl_dllist.c @@ -514,7 +514,7 @@ static HashTable* spl_dllist_object_get_debug_info(zval *obj, int *is_temp TSRML zend_hash_init(intern->debug_info, 1, NULL, ZVAL_PTR_DTOR, 0); } - if (intern->debug_info->nApplyCount == 0) { + if (intern->debug_info->u.v.nApplyCount == 0) { if (!intern->std.properties) { rebuild_object_properties(&intern->std); diff --git a/ext/spl/spl_heap.c b/ext/spl/spl_heap.c index 55550d6f40..f8ce102967 100644 --- a/ext/spl/spl_heap.c +++ b/ext/spl/spl_heap.c @@ -524,7 +524,7 @@ static HashTable* spl_heap_object_get_debug_info_helper(zend_class_entry *ce, zv ZEND_INIT_SYMTABLE_EX(intern->debug_info, zend_hash_num_elements(intern->std.properties) + 1, 0); } - if (intern->debug_info->nApplyCount == 0) { + if (intern->debug_info->u.v.nApplyCount == 0) { zend_hash_copy(intern->debug_info, intern->std.properties, (copy_ctor_func_t) zval_add_ref); diff --git a/ext/spl/spl_observer.c b/ext/spl/spl_observer.c index 0b2eee69eb..5abedecb7f 100644 --- a/ext/spl/spl_observer.c +++ b/ext/spl/spl_observer.c @@ -328,7 +328,7 @@ static HashTable* spl_object_storage_debug_info(zval *obj, int *is_temp TSRMLS_D ZEND_INIT_SYMTABLE_EX(intern->debug_info, zend_hash_num_elements(props) + 1, 0); } - if (intern->debug_info->nApplyCount == 0) { + if (intern->debug_info->u.v.nApplyCount == 0) { zend_hash_copy(intern->debug_info, props, (copy_ctor_func_t)zval_add_ref); array_init(&storage); diff --git a/ext/standard/array.c b/ext/standard/array.c index 03c77fea80..6dada188cf 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -274,7 +274,7 @@ static int php_count_recursive(zval *array, long mode TSRMLS_DC) /* {{{ */ zval *element; if (Z_TYPE_P(array) == IS_ARRAY) { - if (Z_ARRVAL_P(array)->nApplyCount > 1) { + if (Z_ARRVAL_P(array)->u.v.nApplyCount > 1) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "recursion detected"); return 0; } @@ -282,10 +282,10 @@ static int php_count_recursive(zval *array, long mode TSRMLS_DC) /* {{{ */ cnt = zend_hash_num_elements(Z_ARRVAL_P(array)); if (mode == COUNT_RECURSIVE) { ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(array), element) { - Z_ARRVAL_P(array)->nApplyCount++; + Z_ARRVAL_P(array)->u.v.nApplyCount++; ZVAL_DEREF(element); cnt += php_count_recursive(element, COUNT_RECURSIVE TSRMLS_CC); - Z_ARRVAL_P(array)->nApplyCount--; + Z_ARRVAL_P(array)->u.v.nApplyCount--; } ZEND_HASH_FOREACH_END(); } } @@ -1089,7 +1089,7 @@ static int php_array_walk(HashTable *target_hash, zval *userdata, int recursive SEPARATE_ZVAL(zv); thash = Z_ARRVAL_P(zv); } - if (thash->nApplyCount > 1) { + if (thash->u.v.nApplyCount > 1) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "recursion detected"); if (userdata) { zval_ptr_dtor(&args[2]); @@ -1101,9 +1101,9 @@ static int php_array_walk(HashTable *target_hash, zval *userdata, int recursive orig_array_walk_fci = BG(array_walk_fci); orig_array_walk_fci_cache = BG(array_walk_fci_cache); - thash->nApplyCount++; + thash->u.v.nApplyCount++; php_array_walk(thash, userdata, recursive TSRMLS_CC); - thash->nApplyCount--; + thash->u.v.nApplyCount--; /* restore the fcall info and cache */ BG(array_walk_fci) = orig_array_walk_fci; @@ -1216,31 +1216,43 @@ static void php_search_array(INTERNAL_FUNCTION_PARAMETERS, int behavior) /* {{{ ulong num_idx; zend_string *str_idx; zend_bool strict = 0; /* strict comparison or not */ - int (*is_equal_func)(zval *, zval *, zval * TSRMLS_DC) = is_equal_function; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "za|b", &value, &array, &strict) == FAILURE) { return; } if (strict) { - is_equal_func = is_identical_function; - } - - ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(array), num_idx, str_idx, entry) { - is_equal_func(&res, value, entry TSRMLS_CC); - if (Z_LVAL(res)) { - if (behavior == 0) { - RETURN_TRUE; - } else { - if (str_idx) { - RETVAL_STR(STR_COPY(str_idx)); + ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(array), num_idx, str_idx, entry) { + is_identical_function(&res, value, entry TSRMLS_CC); + if (Z_LVAL(res)) { + if (behavior == 0) { + RETURN_TRUE; } else { - RETVAL_LONG(num_idx); + if (str_idx) { + RETVAL_STR(STR_COPY(str_idx)); + } else { + RETVAL_LONG(num_idx); + } + return; } - return; } - } - } ZEND_HASH_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); + } else { + ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(array), num_idx, str_idx, entry) { + if (fast_equal_function(&res, value, entry TSRMLS_CC)) { + if (behavior == 0) { + RETURN_TRUE; + } else { + if (str_idx) { + RETVAL_STR(STR_COPY(str_idx)); + } else { + RETVAL_LONG(num_idx); + } + return; + } + } + } ZEND_HASH_FOREACH_END(); + } RETURN_FALSE; } @@ -1475,17 +1487,17 @@ static void php_compact_var(HashTable *eg_active_symbol_table, zval *return_valu zend_hash_update(Z_ARRVAL_P(return_value), Z_STR_P(entry), &data); } } else if (Z_TYPE_P(entry) == IS_ARRAY) { - if ((Z_ARRVAL_P(entry)->nApplyCount > 1)) { + if ((Z_ARRVAL_P(entry)->u.v.nApplyCount > 1)) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "recursion detected"); return; } - Z_ARRVAL_P(entry)->nApplyCount++; + Z_ARRVAL_P(entry)->u.v.nApplyCount++; ZEND_HASH_FOREACH_VAL_IND(Z_ARRVAL_P(entry), value_ptr) { php_compact_var(eg_active_symbol_table, return_value, value_ptr TSRMLS_CC); } ZEND_HASH_FOREACH_END(); - Z_ARRVAL_P(entry)->nApplyCount--; + Z_ARRVAL_P(entry)->u.v.nApplyCount--; } } /* }}} */ @@ -1797,7 +1809,7 @@ static void php_array_data_shuffle(zval *array TSRMLS_DC) /* {{{ */ p->key = NULL; } hash->nNextFreeElement = n_elems; - if (!(hash->flags & HASH_FLAG_PACKED)) { + if (!(hash->u.flags & HASH_FLAG_PACKED)) { zend_hash_to_packed(hash); } HANDLE_UNBLOCK_INTERRUPTIONS(); @@ -2037,7 +2049,7 @@ static void _phpi_pop(INTERNAL_FUNCTION_PARAMETERS, int off_the_end) } Z_ARRVAL_P(stack)->nNextFreeElement = k; if (should_rehash) { - if (Z_ARRVAL_P(stack)->flags & HASH_FLAG_PACKED) { + if (Z_ARRVAL_P(stack)->u.flags & HASH_FLAG_PACKED) { zend_hash_packed_to_hash(Z_ARRVAL_P(stack)); } else { zend_hash_rehash(Z_ARRVAL_P(stack)); @@ -2272,7 +2284,7 @@ PHPAPI int php_array_merge(HashTable *dest, HashTable *src, int recursive TSRMLS ZVAL_DEREF(src_zval); ZVAL_DEREF(dest_zval); thash = Z_TYPE_P(dest_zval) == IS_ARRAY ? Z_ARRVAL_P(dest_zval) : NULL; - if ((thash && thash->nApplyCount > 1) || (src_entry == dest_entry && Z_ISREF_P(dest_entry) && (Z_REFCOUNT_P(dest_entry) % 2))) { + if ((thash && thash->u.v.nApplyCount > 1) || (src_entry == dest_entry && Z_ISREF_P(dest_entry) && (Z_REFCOUNT_P(dest_entry) % 2))) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "recursion detected"); return 0; } @@ -2303,16 +2315,16 @@ PHPAPI int php_array_merge(HashTable *dest, HashTable *src, int recursive TSRMLS } if (Z_TYPE_P(src_zval) == IS_ARRAY) { if (thash) { - thash->nApplyCount++; + thash->u.v.nApplyCount++; } if (!php_array_merge(Z_ARRVAL_P(dest_zval), Z_ARRVAL_P(src_zval), recursive TSRMLS_CC)) { if (thash) { - thash->nApplyCount--; + thash->u.v.nApplyCount--; } return 0; } if (thash) { - thash->nApplyCount--; + thash->u.v.nApplyCount--; } } else { if (Z_REFCOUNTED_P(src_entry)) { @@ -2377,24 +2389,24 @@ PHPAPI int php_array_replace_recursive(HashTable *dest, HashTable *src TSRMLS_DC dest_zval = dest_entry; ZVAL_DEREF(dest_zval); - if (Z_ARRVAL_P(dest_zval)->nApplyCount > 1 || - Z_ARRVAL_P(src_zval)->nApplyCount > 1 || + if (Z_ARRVAL_P(dest_zval)->u.v.nApplyCount > 1 || + Z_ARRVAL_P(src_zval)->u.v.nApplyCount > 1 || (Z_ISREF_P(src_entry) && Z_ISREF_P(dest_entry) && Z_REF_P(src_entry) == Z_REF_P(dest_entry) && (Z_REFCOUNT_P(dest_entry) % 2))) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "recursion detected"); return 0; } SEPARATE_ZVAL(dest_zval); - Z_ARRVAL_P(dest_zval)->nApplyCount++; - Z_ARRVAL_P(src_zval)->nApplyCount++; + Z_ARRVAL_P(dest_zval)->u.v.nApplyCount++; + Z_ARRVAL_P(src_zval)->u.v.nApplyCount++; if (!php_array_replace_recursive(Z_ARRVAL_P(dest_zval), Z_ARRVAL_P(src_zval) TSRMLS_CC)) { - Z_ARRVAL_P(dest_zval)->nApplyCount--; - Z_ARRVAL_P(src_zval)->nApplyCount--; + Z_ARRVAL_P(dest_zval)->u.v.nApplyCount--; + Z_ARRVAL_P(src_zval)->u.v.nApplyCount--; return 0; } - Z_ARRVAL_P(dest_zval)->nApplyCount--; - Z_ARRVAL_P(src_zval)->nApplyCount--; + Z_ARRVAL_P(dest_zval)->u.v.nApplyCount--; + Z_ARRVAL_P(src_zval)->u.v.nApplyCount--; } ZEND_HASH_FOREACH_END(); return 1; @@ -2883,7 +2895,7 @@ PHP_FUNCTION(array_unique) } /* create and sort array with pointers to the target_hash buckets */ - arTmp = (struct bucketindex *) pemalloc((Z_ARRVAL_P(array)->nNumOfElements + 1) * sizeof(struct bucketindex), Z_ARRVAL_P(array)->flags & HASH_FLAG_PERSISTENT); + arTmp = (struct bucketindex *) pemalloc((Z_ARRVAL_P(array)->nNumOfElements + 1) * sizeof(struct bucketindex), Z_ARRVAL_P(array)->u.flags & HASH_FLAG_PERSISTENT); if (!arTmp) { zval_dtor(return_value); RETURN_FALSE; @@ -2922,7 +2934,7 @@ PHP_FUNCTION(array_unique) } } } - pefree(arTmp, Z_ARRVAL_P(array)->flags & HASH_FLAG_PERSISTENT); + pefree(arTmp, Z_ARRVAL_P(array)->u.flags & HASH_FLAG_PERSISTENT); } /* }}} */ @@ -3215,7 +3227,7 @@ static void php_array_intersect(INTERNAL_FUNCTION_PARAMETERS, int behavior, int goto out; } hash = Z_ARRVAL(args[i]); - list = (Bucket *) pemalloc((hash->nNumOfElements + 1) * sizeof(Bucket), hash->flags & HASH_FLAG_PERSISTENT); + list = (Bucket *) pemalloc((hash->nNumOfElements + 1) * sizeof(Bucket), hash->u.flags & HASH_FLAG_PERSISTENT); if (!list) { PHP_ARRAY_CMP_FUNC_RESTORE(); @@ -3352,7 +3364,7 @@ static void php_array_intersect(INTERNAL_FUNCTION_PARAMETERS, int behavior, int out: for (i = 0; i < arr_argc; i++) { hash = Z_ARRVAL(args[i]); - pefree(lists[i], hash->flags & HASH_FLAG_PERSISTENT); + pefree(lists[i], hash->u.flags & HASH_FLAG_PERSISTENT); } PHP_ARRAY_CMP_FUNC_RESTORE(); @@ -3635,7 +3647,7 @@ static void php_array_diff(INTERNAL_FUNCTION_PARAMETERS, int behavior, int data_ goto out; } hash = Z_ARRVAL(args[i]); - list = (Bucket *) pemalloc((hash->nNumOfElements + 1) * sizeof(Bucket), hash->flags & HASH_FLAG_PERSISTENT); + list = (Bucket *) pemalloc((hash->nNumOfElements + 1) * sizeof(Bucket), hash->u.flags & HASH_FLAG_PERSISTENT); if (!list) { PHP_ARRAY_CMP_FUNC_RESTORE(); @@ -3768,7 +3780,7 @@ static void php_array_diff(INTERNAL_FUNCTION_PARAMETERS, int behavior, int data_ out: for (i = 0; i < arr_argc; i++) { hash = Z_ARRVAL(args[i]); - pefree(lists[i], hash->flags & HASH_FLAG_PERSISTENT); + pefree(lists[i], hash->u.flags & HASH_FLAG_PERSISTENT); } PHP_ARRAY_CMP_FUNC_RESTORE(); @@ -4033,7 +4045,7 @@ PHP_FUNCTION(array_multisort) } hash->nNextFreeElement = array_size; - if (!(hash->flags & HASH_FLAG_PACKED)) { + if (!(hash->u.flags & HASH_FLAG_PACKED)) { zend_hash_to_packed(hash); } } diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index bf9a5a94db..7647781e2b 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -3760,9 +3760,7 @@ PHP_RINIT_FUNCTION(basic) /* {{{ */ BG(page_inode) = -1; BG(page_mtime) = -1; #ifdef HAVE_PUTENV - if (zend_hash_init(&BG(putenv_ht), 1, NULL, php_putenv_destructor, 0) == FAILURE) { - return FAILURE; - } + zend_hash_init(&BG(putenv_ht), 1, NULL, php_putenv_destructor, 0); #endif BG(user_shutdown_function_names) = NULL; diff --git a/ext/standard/browscap.c b/ext/standard/browscap.c index ef49ee4d10..186c30cc90 100644 --- a/ext/standard/browscap.c +++ b/ext/standard/browscap.c @@ -139,7 +139,7 @@ static void convert_browscap_pattern(zval *pattern, int persistent) /* {{{ */ static void php_browscap_parser_cb(zval *arg1, zval *arg2, zval *arg3, int callback_type, void *arg TSRMLS_DC) /* {{{ */ { browser_data *bdata = arg; - int persistent = bdata->htab->flags & HASH_FLAG_PERSISTENT; + int persistent = bdata->htab->u.flags & HASH_FLAG_PERSISTENT; if (!arg1) { return; @@ -232,14 +232,10 @@ static int browscap_read_file(char *filename, browser_data *browdata, int persis return FAILURE; } - if (zend_hash_init_ex(browdata->htab, 0, NULL, + zend_hash_init_ex(browdata->htab, 0, NULL, (dtor_func_t) (persistent?browscap_entry_dtor_persistent :browscap_entry_dtor_request), - persistent, 0) == FAILURE) { - pefree(browdata->htab, persistent); - browdata->htab = NULL; - return FAILURE; - } + persistent, 0); fh.handle.fp = VCWD_FOPEN(filename, "r"); fh.opened_path = NULL; diff --git a/ext/standard/formatted_print.c b/ext/standard/formatted_print.c index 622fbfbb3f..2942daaad3 100644 --- a/ext/standard/formatted_print.c +++ b/ext/standard/formatted_print.c @@ -559,24 +559,14 @@ php_formatted_print(int param_count, int use_array, int format_offset TSRMLS_DC) switch (format[inpos]) { case 's': { - zval *var, var_copy; - int use_copy; - - zend_make_printable_zval(&tmp, &var_copy, &use_copy); - if (use_copy) { - var = &var_copy; - } else { - var = &tmp; - } + zend_string *str = zval_get_string(&tmp); php_sprintf_appendstring(&result, &outpos, - Z_STRVAL_P(var), + str->val, width, precision, padding, alignment, - Z_STRLEN_P(var), + str->len, 0, expprec, 0); - if (use_copy) { - zval_dtor(&var_copy); - } + STR_RELEASE(str); break; } diff --git a/ext/standard/http.c b/ext/standard/http.c index b839a4cb97..14d73779a4 100644 --- a/ext/standard/http.c +++ b/ext/standard/http.c @@ -41,7 +41,7 @@ PHPAPI int php_url_encode_hash_ex(HashTable *ht, smart_str *formstr, return FAILURE; } - if (ht->nApplyCount > 0) { + if (ht->u.v.nApplyCount > 0) { /* Prevent recursion */ return SUCCESS; } @@ -134,9 +134,9 @@ PHPAPI int php_url_encode_hash_ex(HashTable *ht, smart_str *formstr, *(p++) = 'B'; *p = '\0'; } - ht->nApplyCount++; + ht->u.v.nApplyCount++; php_url_encode_hash_ex(HASH_OF(zdata), formstr, NULL, 0, newprefix, newprefix_len, "%5D", 3, (Z_TYPE_P(zdata) == IS_OBJECT ? zdata : NULL), arg_sep, enc_type TSRMLS_CC); - ht->nApplyCount--; + ht->u.v.nApplyCount--; efree(newprefix); } else if (Z_TYPE_P(zdata) == IS_NULL || Z_TYPE_P(zdata) == IS_RESOURCE) { /* Skip these types */ diff --git a/ext/standard/php_var.h b/ext/standard/php_var.h index 4ecdd09dd7..2dc13f4012 100644 --- a/ext/standard/php_var.h +++ b/ext/standard/php_var.h @@ -59,7 +59,7 @@ do { \ /* fprintf(stderr, "SERIALIZE_INIT == lock: %u, level: %u\n", BG(serialize_lock), BG(serialize).level); */ \ if (BG(serialize_lock) || !BG(serialize).level) { \ ALLOC_HASHTABLE(var_hash_ptr); \ - zend_hash_init((var_hash_ptr), 10, NULL, NULL, 0); \ + zend_hash_init((var_hash_ptr), 16, NULL, NULL, 0); \ if (!BG(serialize_lock)) { \ BG(serialize).var_hash = (void *)(var_hash_ptr); \ BG(serialize).level = 1; \ diff --git a/ext/standard/string.c b/ext/standard/string.c index a1ea1cbf45..a960cd1a5c 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -2273,7 +2273,7 @@ PHP_FUNCTION(substr_replace) int argc = ZEND_NUM_ARGS(); zend_string *result; - HashPosition pos_str, pos_from, pos_repl, pos_len; + HashPosition pos_from, pos_repl, pos_len; zval *tmp_str = NULL, *tmp_from = NULL, *tmp_repl = NULL, *tmp_len= NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zzz|z", &str, &repl, &from, &len) == FAILURE) { @@ -2399,8 +2399,7 @@ PHP_FUNCTION(substr_replace) zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(repl), &pos_repl); } - zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(str), &pos_str); - while ((tmp_str = zend_hash_get_current_data_ex(Z_ARRVAL_P(str), &pos_str)) != NULL) { + ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(str), num_index, str_index, tmp_str) { zval *orig_str; zval dummy; @@ -2542,8 +2541,11 @@ PHP_FUNCTION(substr_replace) result->val[result->len] = '\0'; - if (zend_hash_get_current_key_ex(Z_ARRVAL_P(str), &str_index, &num_index, 0, &pos_str) == HASH_KEY_IS_STRING) { - add_assoc_str_ex(return_value, str_index->val, str_index->len, result); + if (str_index) { + zval tmp; + + ZVAL_STR(&tmp, result); + zend_symtable_update(Z_ARRVAL_P(return_value), str_index, &tmp); } else { add_index_str(return_value, num_index, result); } @@ -2553,8 +2555,7 @@ PHP_FUNCTION(substr_replace) } else { //??? Z_SET_ISREF_TO_P(orig_str, was_ref); } - zend_hash_move_forward_ex(Z_ARRVAL_P(str), &pos_str); - } /*while*/ + } ZEND_HASH_FOREACH_END(); } /* if */ } /* }}} */ @@ -3932,30 +3933,22 @@ static void php_str_replace_common(INTERNAL_FUNCTION_PARAMETERS, int case_sensit /* if subject is an array */ if (Z_TYPE_P(subject) == IS_ARRAY) { array_init(return_value); - zend_hash_internal_pointer_reset(Z_ARRVAL_P(subject)); /* For each subject entry, convert it to string, then perform replacement and add the result to the return_value array. */ - while ((subject_entry = zend_hash_get_current_data(Z_ARRVAL_P(subject))) != NULL) { + ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(subject), num_key, string_key, subject_entry) { if (Z_TYPE_P(subject_entry) != IS_ARRAY && Z_TYPE_P(subject_entry) != IS_OBJECT) { php_str_replace_in_subject(search, replace, subject_entry, &result, case_sensitivity, (argc > 3) ? &count : NULL TSRMLS_CC); } else { ZVAL_COPY(&result, subject_entry); } /* Add to return array */ - switch (zend_hash_get_current_key(Z_ARRVAL_P(subject), &string_key, - &num_key, 0)) { - case HASH_KEY_IS_STRING: - zend_hash_update(Z_ARRVAL_P(return_value), string_key, &result); - break; - - case HASH_KEY_IS_LONG: - add_index_zval(return_value, num_key, &result); - break; + if (string_key) { + zend_hash_update(Z_ARRVAL_P(return_value), string_key, &result); + } else { + add_index_zval(return_value, num_key, &result); } - - zend_hash_move_forward(Z_ARRVAL_P(subject)); - } + } ZEND_HASH_FOREACH_END(); } else { /* if subject is not an array */ php_str_replace_in_subject(search, replace, subject, return_value, case_sensitivity, (argc > 3) ? &count : NULL TSRMLS_CC); } @@ -4963,31 +4956,13 @@ static void php_strnatcmp(INTERNAL_FUNCTION_PARAMETERS, int fold_case) PHPAPI int string_natural_compare_function_ex(zval *result, zval *op1, zval *op2, zend_bool case_insensitive TSRMLS_DC) /* {{{ */ { - zval op1_copy, op2_copy; - int use_copy1 = 0, use_copy2 = 0; + zend_string *str1 = zval_get_string(op1); + zend_string *str2 = zval_get_string(op2); - if (Z_TYPE_P(op1) != IS_STRING) { - zend_make_printable_zval(op1, &op1_copy, &use_copy1); - } - if (Z_TYPE_P(op2) != IS_STRING) { - zend_make_printable_zval(op2, &op2_copy, &use_copy2); - } - - if (use_copy1) { - op1 = &op1_copy; - } - if (use_copy2) { - op2 = &op2_copy; - } - - ZVAL_LONG(result, strnatcmp_ex(Z_STRVAL_P(op1), Z_STRLEN_P(op1), Z_STRVAL_P(op2), Z_STRLEN_P(op2), case_insensitive)); + ZVAL_LONG(result, strnatcmp_ex(str1->val, str1->len, str2->val, str2->len, case_insensitive)); - if (use_copy1) { - zval_dtor(op1); - } - if (use_copy2) { - zval_dtor(op2); - } + STR_RELEASE(str1); + STR_RELEASE(str2); return SUCCESS; } /* }}} */ diff --git a/ext/standard/type.c b/ext/standard/type.c index c4fdbc87e3..1e3572c22f 100644 --- a/ext/standard/type.c +++ b/ext/standard/type.c @@ -195,21 +195,12 @@ PHP_FUNCTION(boolval) Get the string value of a variable */ PHP_FUNCTION(strval) { - zval *num, *tmp; - zval expr_copy; - int use_copy; - + zval *num; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &num) == FAILURE) { return; } - zend_make_printable_zval(num, &expr_copy, &use_copy); - if (use_copy) { - tmp = &expr_copy; - RETVAL_ZVAL(tmp, 0, 0); - } else { - RETVAL_ZVAL(num, 1, 0); - } + RETVAL_STR(zval_get_string(num)); } /* }}} */ diff --git a/ext/standard/user_filters.c b/ext/standard/user_filters.c index 762b65387a..b0811d8c4f 100644 --- a/ext/standard/user_filters.c +++ b/ext/standard/user_filters.c @@ -578,7 +578,7 @@ PHP_FUNCTION(stream_filter_register) if (!BG(user_filter_map)) { BG(user_filter_map) = (HashTable*) emalloc(sizeof(HashTable)); - zend_hash_init(BG(user_filter_map), 5, NULL, (dtor_func_t) filter_item_dtor, 0); + zend_hash_init(BG(user_filter_map), 8, NULL, (dtor_func_t) filter_item_dtor, 0); } fdat = ecalloc(1, sizeof(struct php_user_filter_data)); diff --git a/ext/standard/var.c b/ext/standard/var.c index a4e556abdc..3dbd71abd5 100644 --- a/ext/standard/var.c +++ b/ext/standard/var.c @@ -148,9 +148,9 @@ again: break; case IS_ARRAY: myht = Z_ARRVAL_P(struc); - if (++myht->nApplyCount > 1) { + if (++myht->u.v.nApplyCount > 1) { PUTS("*RECURSION*\n"); - --myht->nApplyCount; + --myht->u.v.nApplyCount; return; } php_printf("%sarray(%d) {\n", COMMON, zend_hash_num_elements(myht)); @@ -159,9 +159,9 @@ again: goto head_done; case IS_OBJECT: myht = Z_OBJDEBUG_P(struc, is_temp); - if (myht && ++myht->nApplyCount > 1) { + if (myht && ++myht->u.v.nApplyCount > 1) { PUTS("*RECURSION*\n"); - --myht->nApplyCount; + --myht->u.v.nApplyCount; return; } @@ -176,7 +176,7 @@ again: head_done: if (myht) { zend_hash_apply_with_arguments(myht TSRMLS_CC, (apply_func_args_t) php_element_dump_func, 1, level); - --myht->nApplyCount; + --myht->u.v.nApplyCount; if (is_temp) { zend_hash_destroy(myht); efree(myht); @@ -323,7 +323,7 @@ again: break; case IS_ARRAY: myht = Z_ARRVAL_P(struc); - if (myht->nApplyCount > 1) { + if (myht->u.v.nApplyCount > 1) { PUTS("*RECURSION*\n"); return; } @@ -332,7 +332,7 @@ again: goto head_done; case IS_OBJECT: myht = Z_OBJDEBUG_P(struc, is_temp); - if (myht && myht->nApplyCount > 1) { + if (myht && myht->u.v.nApplyCount > 1) { PUTS("*RECURSION*\n"); return; } @@ -522,7 +522,7 @@ again: break; case IS_ARRAY: myht = Z_ARRVAL_P(struc); - if (myht->nApplyCount > 0){ + if (myht->u.v.nApplyCount > 0){ smart_str_appendl(buf, "NULL", 4); zend_error(E_WARNING, "var_export does not handle circular references"); return; @@ -543,7 +543,7 @@ again: case IS_OBJECT: myht = Z_OBJPROP_P(struc); - if(myht && myht->nApplyCount > 0){ + if(myht && myht->u.v.nApplyCount > 0){ smart_str_appendl(buf, "NULL", 4); zend_error(E_WARNING, "var_export does not handle circular references"); return; @@ -961,16 +961,16 @@ again: /* we should still add element even if it's not OK, * since we already wrote the length of the array before */ if ((Z_TYPE_P(data) == IS_ARRAY && Z_TYPE_P(struc) == IS_ARRAY && Z_ARR_P(data) == Z_ARR_P(struc)) - || (Z_TYPE_P(data) == IS_ARRAY && Z_ARRVAL_P(data)->nApplyCount > 1) + || (Z_TYPE_P(data) == IS_ARRAY && Z_ARRVAL_P(data)->u.v.nApplyCount > 1) ) { smart_str_appendl(buf, "N;", 2); } else { if (Z_TYPE_P(data) == IS_ARRAY) { - Z_ARRVAL_P(data)->nApplyCount++; + Z_ARRVAL_P(data)->u.v.nApplyCount++; } php_var_serialize_intern(buf, data, var_hash TSRMLS_CC); if (Z_TYPE_P(data) == IS_ARRAY) { - Z_ARRVAL_P(data)->nApplyCount--; + Z_ARRVAL_P(data)->u.v.nApplyCount--; } } } ZEND_HASH_FOREACH_END(); |