summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Stogov <dmitry@zend.com>2014-02-17 11:50:32 +0400
committerDmitry Stogov <dmitry@zend.com>2014-02-17 11:50:32 +0400
commit0e425121b3cb9ab7cbffee83ee62d833de42e9dd (patch)
tree3121a683c647ef28f5209c79f85463a8b6fd265e
parentab2a73a6629850bfd131996a54ca649cfd455f01 (diff)
downloadphp-git-0e425121b3cb9ab7cbffee83ee62d833de42e9dd.tar.gz
Use better data structures (incomplete)
-rw-r--r--Zend/zend_API.c29
-rw-r--r--Zend/zend_API.h14
-rw-r--r--Zend/zend_compile.c36
-rw-r--r--Zend/zend_constants.c8
-rw-r--r--Zend/zend_execute.h49
-rw-r--r--Zend/zend_ini_parser.y38
6 files changed, 101 insertions, 73 deletions
diff --git a/Zend/zend_API.c b/Zend/zend_API.c
index 26db975bc5..bd5867f3a5 100644
--- a/Zend/zend_API.c
+++ b/Zend/zend_API.c
@@ -1763,6 +1763,15 @@ ZEND_API int zend_startup_module_ex(zend_module_entry *module TSRMLS_DC) /* {{{
}
/* }}} */
+static int zend_startup_module_zval(zval *zv TSRMLS_DC) /* {{{ */
+{
+ zend_module_entry *module = Z_PTR_P(zv);
+
+ return zend_startup_module_ex(module TSRMLS_CC);
+}
+/* }}} */
+
+
static void zend_sort_modules(void *base, size_t count, size_t siz, compare_func_t compare TSRMLS_DC) /* {{{ */
{
Bucket *b1 = base;
@@ -1805,7 +1814,7 @@ ZEND_API void zend_collect_module_handlers(TSRMLS_D) /* {{{ */
int startup_count = 0;
int shutdown_count = 0;
int post_deactivate_count = 0;
- zend_class_entry **pce;
+ zend_class_entry *ce;
int class_count = 0;
/* Collect extensions with request startup/shutdown handlers */
@@ -1850,10 +1859,10 @@ ZEND_API void zend_collect_module_handlers(TSRMLS_D) /* {{{ */
/* Collect internal classes with static members */
for (zend_hash_internal_pointer_reset_ex(CG(class_table), &pos);
- (pce = zend_hash_get_current_data_ptr_ex(CG(class_table), &pos)) != NULL;
+ (ce = zend_hash_get_current_data_ptr_ex(CG(class_table), &pos)) != NULL;
zend_hash_move_forward_ex(CG(class_table), &pos)) {
- if ((*pce)->type == ZEND_INTERNAL_CLASS &&
- (*pce)->default_static_members_count > 0) {
+ if (ce->type == ZEND_INTERNAL_CLASS &&
+ ce->default_static_members_count > 0) {
class_count++;
}
}
@@ -1865,11 +1874,11 @@ ZEND_API void zend_collect_module_handlers(TSRMLS_D) /* {{{ */
if (class_count) {
for (zend_hash_internal_pointer_reset_ex(CG(class_table), &pos);
- (pce = zend_hash_get_current_data_ptr_ex(CG(class_table), &pos)) != NULL;
+ (ce = zend_hash_get_current_data_ptr_ex(CG(class_table), &pos)) != NULL;
zend_hash_move_forward_ex(CG(class_table), &pos)) {
- if ((*pce)->type == ZEND_INTERNAL_CLASS &&
- (*pce)->default_static_members_count > 0) {
- class_cleanup_handlers[--class_count] = *pce;
+ if (ce->type == ZEND_INTERNAL_CLASS &&
+ ce->default_static_members_count > 0) {
+ class_cleanup_handlers[--class_count] = ce;
}
}
}
@@ -1879,7 +1888,7 @@ ZEND_API void zend_collect_module_handlers(TSRMLS_D) /* {{{ */
ZEND_API int zend_startup_modules(TSRMLS_D) /* {{{ */
{
zend_hash_sort(&module_registry, zend_sort_modules, NULL, 0 TSRMLS_CC);
- zend_hash_apply(&module_registry, (apply_func_t)zend_startup_module_ex TSRMLS_CC);
+ zend_hash_apply(&module_registry, zend_startup_module_zval TSRMLS_CC);
return SUCCESS;
}
/* }}} */
@@ -2050,7 +2059,7 @@ ZEND_API int zend_register_functions(zend_class_entry *scope, const zend_functio
if (scope) {
class_name_len = scope->name->len;
- if ((lc_class_name = zend_memrchr(scope->name, '\\', class_name_len))) {
+ if ((lc_class_name = zend_memrchr(scope->name->val, '\\', class_name_len))) {
++lc_class_name;
class_name_len -= (lc_class_name - scope->name->val);
lc_class_name = zend_str_tolower_dup(lc_class_name, class_name_len);
diff --git a/Zend/zend_API.h b/Zend/zend_API.h
index 61d2276f13..2ff7e69437 100644
--- a/Zend/zend_API.h
+++ b/Zend/zend_API.h
@@ -545,10 +545,10 @@ END_EXTERN_C()
#define CHECK_NULL_PATH(p, l) (strlen(p) != l)
#define ZVAL_STRINGL(z, s, l) do { \
- zval *__z = (z); \
+ zval *_z = (z); \
int __l = l; \
- ZVAL_STR(__z, STR_ALLOC(__l, 0)); \
- memcpy(Z_STRVAL_P(__z), (s), __l + 1); \
+ ZVAL_STR(_z, STR_ALLOC(__l, 0)); \
+ memcpy(Z_STRVAL_P(_z), (s), __l + 1); \
} while (0)
#define ZVAL_STRING(z, s) do { \
@@ -562,10 +562,10 @@ END_EXTERN_C()
} while (0)
#define ZVAL_PSTRINGL(z, s, l) do { \
- zval *__z = (z); \
+ zval *_z = (z); \
int __l = l; \
- ZVAL_STR(__z, STR_ALLOC(__l, 1)); \
- memcpy(Z_STRVAL_P(__z), (s), __l + 1); \
+ ZVAL_STR(_z, STR_ALLOC(__l, 1)); \
+ memcpy(Z_STRVAL_P(_z), (s), __l + 1); \
} while (0)
#define ZVAL_PSTRING(z, s) do { \
@@ -575,7 +575,7 @@ END_EXTERN_C()
} while (0)
#define ZVAL_EMPTY_PSTRING(z) do { \
- ZVAL_PSTRINGL(z, "", 0); \
+ ZVAL_PSTRINGL(z, "", 0); \
} while (0)
#define ZVAL_ZVAL(z, zv, copy, dtor) do { \
diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c
index cffa756114..75c5a827d5 100644
--- a/Zend/zend_compile.c
+++ b/Zend/zend_compile.c
@@ -106,14 +106,28 @@ static void zend_duplicate_property_info(zend_property_info *property_info) /* {
}
/* }}} */
+static void zend_duplicate_property_info_zval(zval *zv) /* {{{ */
+{
+ zend_duplicate_property_info((zend_property_info*)Z_PTR_P(zv));
+}
+/* }}} */
+
static void zend_duplicate_property_info_internal(zend_property_info *property_info) /* {{{ */
{
STR_ADDREF(property_info->name);
}
/* }}} */
-static void zend_destroy_property_info(zend_property_info *property_info) /* {{{ */
+static void zend_duplicate_property_info_internal_zval(zval *zv) /* {{{ */
+{
+ zend_duplicate_property_info_internal((zend_property_info*)Z_PTR_P(zv));
+}
+/* }}} */
+
+static void zend_destroy_property_info(zval *zv) /* {{{ */
{
+ zend_property_info *property_info = Z_PTR_P(zv);
+
STR_RELEASE(property_info->name);
if (property_info->doc_comment) {
STR_RELEASE(property_info->doc_comment);
@@ -121,8 +135,10 @@ static void zend_destroy_property_info(zend_property_info *property_info) /* {{{
}
/* }}} */
-static void zend_destroy_property_info_internal(zend_property_info *property_info) /* {{{ */
+static void zend_destroy_property_info_internal(zval *zv) /* {{{ */
{
+ zend_property_info *property_info = Z_PTR_P(zv);
+
STR_RELEASE(property_info->name);
}
/* }}} */
@@ -3540,8 +3556,9 @@ static void do_inheritance_check_on_method(zend_function *child, zend_function *
}
/* }}} */
-static zend_bool do_inherit_method_check(HashTable *child_function_table, zend_function *parent, const zend_hash_key *hash_key, zend_class_entry *child_ce) /* {{{ */
+static zend_bool do_inherit_method_check(HashTable *child_function_table, zval *zv, const zend_hash_key *hash_key, zend_class_entry *child_ce) /* {{{ */
{
+ zend_function *parent = Z_PTR_P(zv);
zend_uint parent_flags = parent->common.fn_flags;
zend_function *child;
TSRMLS_FETCH();
@@ -3559,8 +3576,9 @@ static zend_bool do_inherit_method_check(HashTable *child_function_table, zend_f
}
/* }}} */
-static zend_bool do_inherit_property_access_check(HashTable *target_ht, zend_property_info *parent_info, const zend_hash_key *hash_key, zend_class_entry *ce) /* {{{ */
+static zend_bool do_inherit_property_access_check(HashTable *target_ht, zval *zv, const zend_hash_key *hash_key, zend_class_entry *ce) /* {{{ */
{
+ zend_property_info *parent_info = Z_PTR_P(zv);
zend_property_info *child_info;
zend_class_entry *parent_ce = ce->parent;
@@ -3700,15 +3718,15 @@ ZEND_API void zend_do_inheritance(zend_class_entry *ce, zend_class_entry *parent
if (parent_ce->default_properties_count) {
int i = ce->default_properties_count + parent_ce->default_properties_count;
- ce->default_properties_table = perealloc(ce->default_properties_table, sizeof(void*) * i, ce->type == ZEND_INTERNAL_CLASS);
+ ce->default_properties_table = perealloc(ce->default_properties_table, sizeof(zval) * i, ce->type == ZEND_INTERNAL_CLASS);
if (ce->default_properties_count) {
while (i-- > parent_ce->default_properties_count) {
ce->default_properties_table[i] = ce->default_properties_table[i - parent_ce->default_properties_count];
}
}
for (i = 0; i < parent_ce->default_properties_count; i++) {
- ce->default_properties_table[i] = parent_ce->default_properties_table[i];
- if (Z_TYPE(ce->default_properties_table[i]) != IS_UNDEF) {
+ ZVAL_COPY_VALUE(&ce->default_properties_table[i], &parent_ce->default_properties_table[i]);
+ if (IS_REFCOUNTED(Z_TYPE(ce->default_properties_table[i]))) {
#ifdef ZTS
if (parent_ce->type != ce->type) {
zval *p;
@@ -3781,7 +3799,7 @@ ZEND_API void zend_do_inheritance(zend_class_entry *ce, zend_class_entry *parent
}
}
- zend_hash_merge_ex(&ce->properties_info, &parent_ce->properties_info, (copy_ctor_func_t) (ce->type & ZEND_INTERNAL_CLASS ? zend_duplicate_property_info_internal : zend_duplicate_property_info), (merge_checker_func_t) do_inherit_property_access_check, ce);
+ zend_hash_merge_ex(&ce->properties_info, &parent_ce->properties_info, (ce->type & ZEND_INTERNAL_CLASS ? zend_duplicate_property_info_internal_zval : zend_duplicate_property_info_zval), (merge_checker_func_t) do_inherit_property_access_check, ce);
zend_hash_merge(&ce->constants_table, &parent_ce->constants_table, zval_property_ctor(parent_ce, ce), 0);
zend_hash_merge_ex(&ce->function_table, &parent_ce->function_table, (copy_ctor_func_t) do_inherit_method, (merge_checker_func_t) do_inherit_method_check, ce);
@@ -6837,7 +6855,7 @@ ZEND_API void zend_initialize_class_data(zend_class_entry *ce, zend_bool nullify
ce->default_properties_table = NULL;
ce->default_static_members_table = NULL;
- zend_hash_init_ex(&ce->properties_info, 0, NULL, (dtor_func_t) (persistent_hashes ? zend_destroy_property_info_internal : zend_destroy_property_info), persistent_hashes, 0);
+ zend_hash_init_ex(&ce->properties_info, 0, NULL, (persistent_hashes ? zend_destroy_property_info_internal : zend_destroy_property_info), persistent_hashes, 0);
zend_hash_init_ex(&ce->constants_table, 0, NULL, zval_ptr_dtor_func, persistent_hashes, 0);
zend_hash_init_ex(&ce->function_table, 0, NULL, ZEND_FUNCTION_DTOR, persistent_hashes, 0);
diff --git a/Zend/zend_constants.c b/Zend/zend_constants.c
index a68f3f09a9..f6cbac3968 100644
--- a/Zend/zend_constants.c
+++ b/Zend/zend_constants.c
@@ -274,13 +274,12 @@ static zend_constant *zend_get_special_constant(const char *name, uint name_len
ZEND_API int zend_get_constant(const char *name, uint name_len, zval *result TSRMLS_DC)
{
zend_constant *c;
- int retval = 1;
if ((c = zend_hash_str_find_ptr(EG(zend_constants), name, name_len)) == NULL) {
char *lcname = zend_str_tolower_dup(name, name_len);
if ((c = zend_hash_str_find_ptr(EG(zend_constants), lcname, name_len)) != NULL) {
if (c->flags & CONST_CS) {
- retval=0;
+ c = NULL;
}
} else {
c = zend_get_special_constant(name, name_len TSRMLS_CC);
@@ -288,11 +287,12 @@ ZEND_API int zend_get_constant(const char *name, uint name_len, zval *result TSR
efree(lcname);
}
- if (retval) {
+ if (c) {
ZVAL_DUP(result, &c->value);
+ return 1;
}
- return retval;
+ return 0;
}
ZEND_API int zend_get_constant_ex(const char *name, uint name_len, zval *result, zend_class_entry *scope, ulong flags TSRMLS_DC)
diff --git a/Zend/zend_execute.h b/Zend/zend_execute.h
index 1d4853d5ee..8ad16de2d8 100644
--- a/Zend/zend_execute.h
+++ b/Zend/zend_execute.h
@@ -72,36 +72,37 @@ ZEND_API int zend_verify_arg_error(int error_type, const zend_function *zf, zend
static zend_always_inline void i_zval_ptr_dtor(zval *zval_ptr ZEND_FILE_LINE_DC TSRMLS_DC)
{
- if (!Z_DELREF_P(zval_ptr)) {
- ZEND_ASSERT(zval_ptr != &EG(uninitialized_zval));
- GC_REMOVE_ZVAL_FROM_BUFFER(zval_ptr);
- zval_dtor(zval_ptr);
- efree_rel(zval_ptr);
- } else {
- if (Z_REFCOUNT_P(zval_ptr) == 1 && Z_TYPE_P(zval_ptr) == IS_REFERENCE) {
- /* convert reference to regular value */
- zend_reference *ref = Z_REF_P(zval_ptr);
- *zval_ptr = ref->val;
- efree_rel(ref);
+ if (IS_REFCOUNTED(Z_TYPE_P(zval_ptr))) {
+ if (!Z_DELREF_P(zval_ptr)) {
+ ZEND_ASSERT(zval_ptr != &EG(uninitialized_zval));
+ GC_REMOVE_ZVAL_FROM_BUFFER(zval_ptr);
+ zval_dtor(zval_ptr);
+ } else {
+ if (Z_REFCOUNT_P(zval_ptr) == 1 && Z_TYPE_P(zval_ptr) == IS_REFERENCE) {
+ /* convert reference to regular value */
+ zend_reference *ref = Z_REF_P(zval_ptr);
+ ZVAL_COPY_VALUE(zval_ptr, &ref->val);
+ efree_rel(ref);
+ }
+ GC_ZVAL_CHECK_POSSIBLE_ROOT(zval_ptr);
}
-
- GC_ZVAL_CHECK_POSSIBLE_ROOT(zval_ptr);
}
}
static zend_always_inline void i_zval_ptr_dtor_nogc(zval *zval_ptr ZEND_FILE_LINE_DC TSRMLS_DC)
{
- if (!Z_DELREF_P(zval_ptr)) {
- ZEND_ASSERT(zval_ptr != &EG(uninitialized_zval));
- GC_REMOVE_ZVAL_FROM_BUFFER(zval_ptr);
- zval_dtor(zval_ptr);
- efree_rel(zval_ptr);
- } else {
- if (Z_REFCOUNT_P(zval_ptr) == 1 && Z_TYPE_P(zval_ptr) == IS_REFERENCE) {
- /* convert reference to regular value */
- zend_reference *ref = Z_REF_P(zval_ptr);
- *zval_ptr = ref->val;
- efree_rel(ref);
+ if (IS_REFCOUNTED(Z_TYPE_P(zval_ptr))) {
+ if (!Z_DELREF_P(zval_ptr)) {
+ ZEND_ASSERT(zval_ptr != &EG(uninitialized_zval));
+ GC_REMOVE_ZVAL_FROM_BUFFER(zval_ptr);
+ zval_dtor(zval_ptr);
+ } else {
+ if (Z_REFCOUNT_P(zval_ptr) == 1 && Z_TYPE_P(zval_ptr) == IS_REFERENCE) {
+ /* convert reference to regular value */
+ zend_reference *ref = Z_REF_P(zval_ptr);
+ ZVAL_COPY_VALUE(zval_ptr, &ref->val);
+ efree_rel(ref);
+ }
}
}
}
diff --git a/Zend/zend_ini_parser.y b/Zend/zend_ini_parser.y
index 73a0b257b6..37943bc222 100644
--- a/Zend/zend_ini_parser.y
+++ b/Zend/zend_ini_parser.y
@@ -53,10 +53,10 @@ static void zend_ini_do_op(char type, zval *result, zval *op1, zval *op2)
char str_result[MAX_LENGTH_OF_LONG];
i_op1 = atoi(Z_STRVAL_P(op1));
- free(Z_STRVAL_P(op1));
+ STR_FREE(Z_STR_P(op1));
if (op2) {
i_op2 = atoi(Z_STRVAL_P(op2));
- free(Z_STRVAL_P(op2));
+ STR_FREE(Z_STR_P(op2));
} else {
i_op2 = 0;
}
@@ -121,7 +121,7 @@ static void zend_ini_get_constant(zval *result, zval *name TSRMLS_DC)
convert_to_string(&z_constant);
ZVAL_PSTRINGL(result, Z_STRVAL(z_constant), Z_STRLEN(z_constant));
zval_dtor(&z_constant);
- free(Z_STRVAL_P(name));
+ STR_FREE(Z_STR_P(name));
} else {
*result = *name;
}
@@ -273,26 +273,26 @@ statement:
printf("SECTION: [%s]\n", Z_STRVAL($2));
#endif
ZEND_INI_PARSER_CB(&$2, NULL, NULL, ZEND_INI_PARSER_SECTION, ZEND_INI_PARSER_ARG TSRMLS_CC);
- free(Z_STRVAL($2));
+ STR_FREE(Z_STR($2));
}
| TC_LABEL '=' string_or_value {
#if DEBUG_CFG_PARSER
printf("NORMAL: '%s' = '%s'\n", Z_STRVAL($1), Z_STRVAL($3));
#endif
ZEND_INI_PARSER_CB(&$1, &$3, NULL, ZEND_INI_PARSER_ENTRY, ZEND_INI_PARSER_ARG TSRMLS_CC);
- free(Z_STRVAL($1));
- free(Z_STRVAL($3));
+ STR_FREE(Z_STR($1));
+ STR_FREE(Z_STR($3));
}
| TC_OFFSET option_offset ']' '=' string_or_value {
#if DEBUG_CFG_PARSER
printf("OFFSET: '%s'[%s] = '%s'\n", Z_STRVAL($1), Z_STRVAL($2), Z_STRVAL($5));
#endif
ZEND_INI_PARSER_CB(&$1, &$5, &$2, ZEND_INI_PARSER_POP_ENTRY, ZEND_INI_PARSER_ARG TSRMLS_CC);
- free(Z_STRVAL($1));
- free(Z_STRVAL($2));
- free(Z_STRVAL($5));
+ STR_FREE(Z_STR($1));
+ STR_FREE(Z_STR($2));
+ STR_FREE(Z_STR($5));
}
- | TC_LABEL { ZEND_INI_PARSER_CB(&$1, NULL, NULL, ZEND_INI_PARSER_ENTRY, ZEND_INI_PARSER_ARG TSRMLS_CC); free(Z_STRVAL($1)); }
+ | TC_LABEL { ZEND_INI_PARSER_CB(&$1, NULL, NULL, ZEND_INI_PARSER_ENTRY, ZEND_INI_PARSER_ARG TSRMLS_CC); STR_FREE(Z_STR($1)); }
| END_OF_LINE
;
@@ -314,8 +314,8 @@ option_offset:
;
encapsed_list:
- encapsed_list cfg_var_ref { zend_ini_add_string(&$$, &$1, &$2); free(Z_STRVAL($2)); }
- | encapsed_list TC_QUOTED_STRING { zend_ini_add_string(&$$, &$1, &$2); free(Z_STRVAL($2)); }
+ encapsed_list cfg_var_ref { zend_ini_add_string(&$$, &$1, &$2); STR_FREE(Z_STR($2)); }
+ | encapsed_list TC_QUOTED_STRING { zend_ini_add_string(&$$, &$1, &$2); STR_FREE(Z_STR($2)); }
| /* empty */ { zend_ini_init_string(&$$); }
;
@@ -323,18 +323,18 @@ var_string_list_section:
cfg_var_ref { $$ = $1; }
| constant_literal { $$ = $1; }
| '"' encapsed_list '"' { $$ = $2; }
- | var_string_list_section cfg_var_ref { zend_ini_add_string(&$$, &$1, &$2); free(Z_STRVAL($2)); }
- | var_string_list_section constant_literal { zend_ini_add_string(&$$, &$1, &$2); free(Z_STRVAL($2)); }
- | var_string_list_section '"' encapsed_list '"' { zend_ini_add_string(&$$, &$1, &$3); free(Z_STRVAL($3)); }
+ | var_string_list_section cfg_var_ref { zend_ini_add_string(&$$, &$1, &$2); STR_FREE(Z_STR($2)); }
+ | var_string_list_section constant_literal { zend_ini_add_string(&$$, &$1, &$2); STR_FREE(Z_STR($2)); }
+ | var_string_list_section '"' encapsed_list '"' { zend_ini_add_string(&$$, &$1, &$3); STR_FREE(Z_STR($3)); }
;
var_string_list:
cfg_var_ref { $$ = $1; }
| constant_string { $$ = $1; }
| '"' encapsed_list '"' { $$ = $2; }
- | var_string_list cfg_var_ref { zend_ini_add_string(&$$, &$1, &$2); free(Z_STRVAL($2)); }
- | var_string_list constant_string { zend_ini_add_string(&$$, &$1, &$2); free(Z_STRVAL($2)); }
- | var_string_list '"' encapsed_list '"' { zend_ini_add_string(&$$, &$1, &$3); free(Z_STRVAL($3)); }
+ | var_string_list cfg_var_ref { zend_ini_add_string(&$$, &$1, &$2); STR_FREE(Z_STR($2)); }
+ | var_string_list constant_string { zend_ini_add_string(&$$, &$1, &$2); STR_FREE(Z_STR($2)); }
+ | var_string_list '"' encapsed_list '"' { zend_ini_add_string(&$$, &$1, &$3); STR_FREE(Z_STR($3)); }
;
expr:
@@ -348,7 +348,7 @@ expr:
;
cfg_var_ref:
- TC_DOLLAR_CURLY TC_VARNAME '}' { zend_ini_get_var(&$$, &$2 TSRMLS_CC); free(Z_STRVAL($2)); }
+ TC_DOLLAR_CURLY TC_VARNAME '}' { zend_ini_get_var(&$$, &$2 TSRMLS_CC); STR_FREE(Z_STR($2)); }
;
constant_literal: