From 2361745806553db9099542d9237ade00dcee799b Mon Sep 17 00:00:00 2001 From: Bob Weinand Date: Thu, 31 Oct 2013 08:57:12 +0100 Subject: Working commit for constant scalar expressions (with constants). Tests will follow. --- ext/reflection/php_reflection.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'ext/reflection/php_reflection.c') diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index cc148b39c5..abebc216c3 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -2599,9 +2599,14 @@ ZEND_METHOD(reflection_parameter, getDefaultValue) *return_value = *precv->op2.zv; INIT_PZVAL(return_value); - if ((Z_TYPE_P(return_value) & IS_CONSTANT_TYPE_MASK) != IS_CONSTANT - && (Z_TYPE_P(return_value) & IS_CONSTANT_TYPE_MASK) != IS_CONSTANT_ARRAY) { - zval_copy_ctor(return_value); + switch (Z_TYPE_P(return_value) & IS_CONSTANT_TYPE_MASK) { + case IS_CONSTANT: + case IS_CONSTANT_ARRAY: + case IS_CONSTANT_AST: + break; + + default: + zval_copy_ctor(return_value); } zval_update_constant_ex(&return_value, (void*)0, param->fptr->common.scope TSRMLS_CC); } @@ -3414,8 +3419,11 @@ static void add_class_vars(zend_class_entry *ce, int statics, zval *return_value /* this is necessary to make it able to work with default array * properties, returned to user */ - if (Z_TYPE_P(prop_copy) == IS_CONSTANT_ARRAY || (Z_TYPE_P(prop_copy) & IS_CONSTANT_TYPE_MASK) == IS_CONSTANT) { - zval_update_constant(&prop_copy, (void *) 1 TSRMLS_CC); + switch (Z_TYPE_P(prop_copy) & IS_CONSTANT_TYPE_MASK) { + case IS_CONSTANT: + case IS_CONSTANT_ARRAY: + case IS_CONSTANT_AST: + zval_update_constant(&prop_copy, (void *) 1 TSRMLS_CC); } add_assoc_zval(return_value, key, prop_copy); -- cgit v1.2.1 From b45043a1b71c29a0c7b8de9e4929dde08bd61216 Mon Sep 17 00:00:00 2001 From: Bob Weinand Date: Fri, 1 Nov 2013 16:16:58 +0100 Subject: converted several switches to ifs and made more opcache friendly --- ext/reflection/php_reflection.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) (limited to 'ext/reflection/php_reflection.c') diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index abebc216c3..bff5e66472 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -2599,14 +2599,8 @@ ZEND_METHOD(reflection_parameter, getDefaultValue) *return_value = *precv->op2.zv; INIT_PZVAL(return_value); - switch (Z_TYPE_P(return_value) & IS_CONSTANT_TYPE_MASK) { - case IS_CONSTANT: - case IS_CONSTANT_ARRAY: - case IS_CONSTANT_AST: - break; - - default: - zval_copy_ctor(return_value); + if (!IS_CONSTANT_TYPE(Z_TYPE_P(return_value))) { + zval_copy_ctor(return_value); } zval_update_constant_ex(&return_value, (void*)0, param->fptr->common.scope TSRMLS_CC); } @@ -3419,11 +3413,8 @@ static void add_class_vars(zend_class_entry *ce, int statics, zval *return_value /* this is necessary to make it able to work with default array * properties, returned to user */ - switch (Z_TYPE_P(prop_copy) & IS_CONSTANT_TYPE_MASK) { - case IS_CONSTANT: - case IS_CONSTANT_ARRAY: - case IS_CONSTANT_AST: - zval_update_constant(&prop_copy, (void *) 1 TSRMLS_CC); + if (IS_CONSTANT_TYPE(Z_TYPE_P(prop_copy))) { + zval_update_constant(&prop_copy, (void *) 1 TSRMLS_CC); } add_assoc_zval(return_value, key, prop_copy); -- cgit v1.2.1 From 3e963f8eb44863ef3d758eabe791190b0fd7bb9a Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Tue, 10 Dec 2013 16:07:16 +0100 Subject: Fixed Bug #66218 zend_register_functions breaks reflection Functions registered using zend_register_functions instead of zend_module_entry.functions are not seen on reflection. Ex: additional_functions from api_module_entry. Ex: in CLI, dl, cli_set_process_title and cli_get_process_title Note: - also affects functions overrided in extension (should be be reported in extension, where overrided, not in original extension) - also allow extension to call zend_register_functions for various list (instead of having a single bug list) --- ext/reflection/php_reflection.c | 66 ++++++++++++++++------------------------- 1 file changed, 26 insertions(+), 40 deletions(-) (limited to 'ext/reflection/php_reflection.c') diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index c4a7c554f0..803b12b031 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -1105,29 +1105,26 @@ static void _extension_string(string *str, zend_module_entry *module, char *inde string_free(&str_constants); } - if (module->functions && module->functions->fname) { + { + HashPosition iterator; zend_function *fptr; - const zend_function_entry *func = module->functions; - - string_printf(str, "\n - Functions {\n"); - - /* Is there a better way of doing this? */ - while (func->fname) { - int fname_len = strlen(func->fname); - char *lc_name = zend_str_tolower_dup(func->fname, fname_len); - - if (zend_hash_find(EG(function_table), lc_name, fname_len + 1, (void**) &fptr) == FAILURE) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Internal error: Cannot find extension function %s in global function table", func->fname); - func++; - efree(lc_name); - continue; + int first = 1; + + zend_hash_internal_pointer_reset_ex(CG(function_table), &iterator); + while (zend_hash_get_current_data_ex(CG(function_table), (void **) &fptr, &iterator) == SUCCESS) { + if (fptr->common.type==ZEND_INTERNAL_FUNCTION + && fptr->internal_function.module == module) { + if (first) { + string_printf(str, "\n - Functions {\n"); + first = 0; + } + _function_string(str, fptr, NULL, " " TSRMLS_CC); } - - _function_string(str, fptr, NULL, " " TSRMLS_CC); - efree(lc_name); - func++; + zend_hash_move_forward_ex(CG(function_table), &iterator); + } + if (!first) { + string_printf(str, "%s }\n", indent); } - string_printf(str, "%s }\n", indent); } { @@ -5242,6 +5239,9 @@ ZEND_METHOD(reflection_extension, getFunctions) { reflection_object *intern; zend_module_entry *module; + HashPosition iterator; + zval *function; + zend_function *fptr; if (zend_parse_parameters_none() == FAILURE) { return; @@ -5249,29 +5249,15 @@ ZEND_METHOD(reflection_extension, getFunctions) GET_REFLECTION_OBJECT_PTR(module); array_init(return_value); - if (module->functions) { - zval *function; - zend_function *fptr; - const zend_function_entry *func = module->functions; - - /* Is there a better way of doing this? */ - while (func->fname) { - int fname_len = strlen(func->fname); - char *lc_name = zend_str_tolower_dup(func->fname, fname_len); - - if (zend_hash_find(EG(function_table), lc_name, fname_len + 1, (void**) &fptr) == FAILURE) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Internal error: Cannot find extension function %s in global function table", func->fname); - func++; - efree(lc_name); - continue; - } - + zend_hash_internal_pointer_reset_ex(CG(function_table), &iterator); + while (zend_hash_get_current_data_ex(CG(function_table), (void **) &fptr, &iterator) == SUCCESS) { + if (fptr->common.type==ZEND_INTERNAL_FUNCTION + && fptr->internal_function.module == module) { ALLOC_ZVAL(function); reflection_function_factory(fptr, NULL, function TSRMLS_CC); - add_assoc_zval_ex(return_value, func->fname, fname_len+1, function); - func++; - efree(lc_name); + add_assoc_zval(return_value, fptr->common.function_name, function); } + zend_hash_move_forward_ex(CG(function_table), &iterator); } } /* }}} */ -- cgit v1.2.1 From 47c902777297ce895aa915c13efdb00881af3669 Mon Sep 17 00:00:00 2001 From: Xinchen Hui Date: Fri, 3 Jan 2014 11:06:16 +0800 Subject: Bump year --- ext/reflection/php_reflection.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ext/reflection/php_reflection.c') diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index e6cef1dfed..31d836a7ac 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2013 The PHP Group | + | Copyright (c) 1997-2014 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | -- cgit v1.2.1 From c081ce628f0d76d44784d7bb8e06428b06142ac0 Mon Sep 17 00:00:00 2001 From: Xinchen Hui Date: Fri, 3 Jan 2014 11:08:10 +0800 Subject: Bump year --- ext/reflection/php_reflection.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ext/reflection/php_reflection.c') diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 15cfec98c0..a24153dc20 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2013 The PHP Group | + | Copyright (c) 1997-2014 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | -- cgit v1.2.1 From f4cfaf36e23ca47da3e352e1c60909104c059647 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Mon, 10 Feb 2014 10:04:30 +0400 Subject: Use better data structures (incomplete) --- ext/reflection/php_reflection.c | 1144 +++++++++++++++++++-------------------- 1 file changed, 557 insertions(+), 587 deletions(-) (limited to 'ext/reflection/php_reflection.c') diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index a24153dc20..e566711c1a 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -42,10 +42,9 @@ #include "zend_extensions.h" #define reflection_update_property(object, name, value) do { \ - zval *member; \ - MAKE_STD_ZVAL(member); \ - ZVAL_STRINGL(member, name, sizeof(name)-1, 1); \ - zend_std_write_property(object, member, value, NULL TSRMLS_CC); \ + zval member; \ + ZVAL_STRINGL(&member, name, sizeof(name)-1); \ + zend_std_write_property(object, &member, value, NULL TSRMLS_CC); \ Z_DELREF_P(value); \ zval_ptr_dtor(&member); \ } while (0) @@ -95,12 +94,12 @@ ZEND_DECLARE_MODULE_GLOBALS(reflection) return; \ #define RETURN_ON_EXCEPTION \ - if (EG(exception) && Z_OBJCE_P(EG(exception)) == reflection_exception_ptr) { \ + if (EG(exception) && EG(exception)->ce == reflection_exception_ptr) { \ return; \ } #define GET_REFLECTION_OBJECT_PTR(target) \ - intern = (reflection_object *) zend_object_store_get_object(getThis() TSRMLS_CC); \ + intern = (reflection_object *) Z_OBJ_P(getThis()); \ if (intern == NULL || intern->ptr == NULL) { \ RETURN_ON_EXCEPTION \ php_error_docref(NULL TSRMLS_CC, E_ERROR, "Internal error: Failed to retrieve the reflection object"); \ @@ -207,7 +206,7 @@ typedef struct { zend_object zo; void *ptr; reflection_type_t ref_type; - zval *obj; + zval obj; zend_class_entry *ce; unsigned int ignore_visibility:1; } reflection_object; @@ -218,13 +217,13 @@ static zend_object_handlers reflection_object_handlers; static void _default_get_entry(zval *object, char *name, int name_len, zval *return_value TSRMLS_DC) /* {{{ */ { - zval **value; + zval *value; - if (zend_hash_find(Z_OBJPROP_P(object), name, name_len, (void **) &value) == FAILURE) { + if ((value = zend_hash_str_find(Z_OBJPROP_P(object), name, name_len)) == NULL) { RETURN_FALSE; } - MAKE_COPY_ZVAL(value, return_value); + ZVAL_DUP(return_value, value); } /* }}} */ @@ -260,7 +259,7 @@ static zend_function *_copy_function(zend_function *fptr TSRMLS_DC) /* {{{ */ zend_function *copy_fptr; copy_fptr = emalloc(sizeof(zend_function)); memcpy(copy_fptr, fptr, sizeof(zend_function)); - copy_fptr->internal_function.function_name = estrdup(fptr->internal_function.function_name); + copy_fptr->internal_function.function_name = STR_DUP(fptr->internal_function.function_name, 0); return copy_fptr; } else { /* no copy needed */ @@ -281,7 +280,7 @@ static void _free_function(zend_function *fptr TSRMLS_DC) /* {{{ */ } /* }}} */ -static void reflection_free_objects_storage(void *object TSRMLS_DC) /* {{{ */ +static void reflection_free_objects_storage(zend_object *object TSRMLS_DC) /* {{{ */ { reflection_object *intern = (reflection_object *) object; parameter_reference *reference; @@ -310,16 +309,13 @@ static void reflection_free_objects_storage(void *object TSRMLS_DC) /* {{{ */ } } intern->ptr = NULL; - if (intern->obj) { - zval_ptr_dtor(&intern->obj); - } - zend_objects_free_object_storage(object TSRMLS_CC); + zval_ptr_dtor(&intern->obj); +//??? zend_objects_free_object_storage(object TSRMLS_CC); } /* }}} */ -static zend_object_value reflection_objects_new(zend_class_entry *class_type TSRMLS_DC) /* {{{ */ +static zend_object *reflection_objects_new(zend_class_entry *class_type TSRMLS_DC) /* {{{ */ { - zend_object_value retval; reflection_object *intern; intern = ecalloc(1, sizeof(reflection_object)); @@ -327,21 +323,14 @@ static zend_object_value reflection_objects_new(zend_class_entry *class_type TSR zend_object_std_init(&intern->zo, class_type TSRMLS_CC); object_properties_init(&intern->zo, class_type); - retval.handle = zend_objects_store_put(intern, NULL, reflection_free_objects_storage, NULL TSRMLS_CC); - retval.handlers = &reflection_object_handlers; - return retval; + intern->zo.handlers = &reflection_object_handlers; + return (zend_object*)intern; } /* }}} */ static zval * reflection_instantiate(zend_class_entry *pce, zval *object TSRMLS_DC) /* {{{ */ { - if (!object) { - ALLOC_ZVAL(object); - } - Z_TYPE_P(object) = IS_OBJECT; object_init_ex(object, pce); - Z_SET_REFCOUNT_P(object, 1); - Z_SET_ISREF_P(object); return object; } /* }}} */ @@ -433,17 +422,16 @@ static void _class_string(string *str, zend_class_entry *ce, zval *obj, char *in string_printf(str, "%s - Constants [%d] {\n", indent, count); if (count > 0) { HashPosition pos; - zval **value; - char *key; - uint key_len; + zval *value; + zend_string *key; ulong num_index; zend_hash_internal_pointer_reset_ex(&ce->constants_table, &pos); - while (zend_hash_get_current_data_ex(&ce->constants_table, (void **) &value, &pos) == SUCCESS) { - zend_hash_get_current_key_ex(&ce->constants_table, &key, &key_len, &num_index, 0, &pos); + while ((value = zend_hash_get_current_data_ex(&ce->constants_table, &pos)) != NULL) { + zend_hash_get_current_key_ex(&ce->constants_table, &key, &num_index, 0, &pos); - _const_string(str, key, *value, indent TSRMLS_CC); + _const_string(str, key->val, value, indent TSRMLS_CC); zend_hash_move_forward_ex(&ce->constants_table, &pos); } } @@ -460,7 +448,7 @@ static void _class_string(string *str, zend_class_entry *ce, zval *obj, char *in zend_hash_internal_pointer_reset_ex(&ce->properties_info, &pos); - while (zend_hash_get_current_data_ex(&ce->properties_info, (void **) &prop, &pos) == SUCCESS) { + while ((prop = zend_hash_get_current_data_ptr_ex(&ce->properties_info, &pos)) != NULL) { if(prop->flags & ZEND_ACC_SHADOW) { count_shadow_props++; } else if (prop->flags & ZEND_ACC_STATIC) { @@ -478,7 +466,7 @@ static void _class_string(string *str, zend_class_entry *ce, zval *obj, char *in zend_hash_internal_pointer_reset_ex(&ce->properties_info, &pos); - while (zend_hash_get_current_data_ex(&ce->properties_info, (void **) &prop, &pos) == SUCCESS) { + while ((prop = zend_hash_get_current_data_ptr_ex(&ce->properties_info, &pos)) != NULL) { if ((prop->flags & ZEND_ACC_STATIC) && !(prop->flags & ZEND_ACC_SHADOW)) { _property_string(str, prop, NULL, sub_indent.string TSRMLS_CC); } @@ -499,7 +487,7 @@ static void _class_string(string *str, zend_class_entry *ce, zval *obj, char *in zend_hash_internal_pointer_reset_ex(&ce->function_table, &pos); - while (zend_hash_get_current_data_ex(&ce->function_table, (void **) &mptr, &pos) == SUCCESS) { + while ((mptr = zend_hash_get_current_data_ptr_ex(&ce->function_table, &pos)) != NULL) { if (mptr->common.fn_flags & ZEND_ACC_STATIC && ((mptr->common.fn_flags & ZEND_ACC_PRIVATE) == 0 || mptr->common.scope == ce)) { @@ -517,7 +505,7 @@ static void _class_string(string *str, zend_class_entry *ce, zval *obj, char *in zend_hash_internal_pointer_reset_ex(&ce->function_table, &pos); - while (zend_hash_get_current_data_ex(&ce->function_table, (void **) &mptr, &pos) == SUCCESS) { + while ((mptr = zend_hash_get_current_data_ptr_ex(&ce->function_table, &pos)) != NULL) { if (mptr->common.fn_flags & ZEND_ACC_STATIC && ((mptr->common.fn_flags & ZEND_ACC_PRIVATE) == 0 || mptr->common.scope == ce)) { @@ -542,7 +530,7 @@ static void _class_string(string *str, zend_class_entry *ce, zval *obj, char *in zend_hash_internal_pointer_reset_ex(&ce->properties_info, &pos); - while (zend_hash_get_current_data_ex(&ce->properties_info, (void **) &prop, &pos) == SUCCESS) { + while ((prop = zend_hash_get_current_data_ptr_ex(&ce->properties_info, &pos)) != NULL) { if (!(prop->flags & (ZEND_ACC_STATIC|ZEND_ACC_SHADOW))) { _property_string(str, prop, NULL, sub_indent.string TSRMLS_CC); } @@ -564,16 +552,15 @@ static void _class_string(string *str, zend_class_entry *ce, zval *obj, char *in if (properties && zend_hash_num_elements(properties)) { zend_hash_internal_pointer_reset_ex(properties, &pos); - while (zend_hash_get_current_data_ex(properties, (void **) &prop, &pos) == SUCCESS) { - char *prop_name; - uint prop_name_size; + while ((prop = zend_hash_get_current_data_ptr_ex(properties, &pos)) != NULL) { + zend_string *prop_name; ulong index; - if (zend_hash_get_current_key_ex(properties, &prop_name, &prop_name_size, &index, 1, &pos) == HASH_KEY_IS_STRING) { - if (prop_name_size && prop_name[0]) { /* skip all private and protected properties */ - if (!zend_hash_quick_exists(&ce->properties_info, prop_name, prop_name_size, zend_get_hash_value(prop_name, prop_name_size))) { + if (zend_hash_get_current_key_ex(properties, &prop_name, &index, 1, &pos) == HASH_KEY_IS_STRING) { + if (prop_name->len && prop_name->val[0]) { /* skip all private and protected properties */ + if (!zend_hash_exists(&ce->properties_info, prop_name)) { count++; - _property_string(&dyn, NULL, prop_name, sub_indent.string TSRMLS_CC); + _property_string(&dyn, NULL, prop_name->val, sub_indent.string TSRMLS_CC); } } efree(prop_name); @@ -600,20 +587,19 @@ static void _class_string(string *str, zend_class_entry *ce, zval *obj, char *in string_init(&dyn); zend_hash_internal_pointer_reset_ex(&ce->function_table, &pos); - while (zend_hash_get_current_data_ex(&ce->function_table, (void **) &mptr, &pos) == SUCCESS) { + while ((mptr = zend_hash_get_current_data_ptr_ex(&ce->function_table, &pos)) != NULL) { if ((mptr->common.fn_flags & ZEND_ACC_STATIC) == 0 && ((mptr->common.fn_flags & ZEND_ACC_PRIVATE) == 0 || mptr->common.scope == ce)) { - char *key; - uint key_len; + zend_string *key; ulong num_index; - uint len = strlen(mptr->common.function_name); + uint len = mptr->common.function_name->len; /* Do not display old-style inherited constructors */ if ((mptr->common.fn_flags & ZEND_ACC_CTOR) == 0 || mptr->common.scope == ce - || zend_hash_get_current_key_ex(&ce->function_table, &key, &key_len, &num_index, 0, &pos) != HASH_KEY_IS_STRING - || zend_binary_strcasecmp(key, key_len-1, mptr->common.function_name, len) == 0) + || zend_hash_get_current_key_ex(&ce->function_table, &key, &num_index, 0, &pos) != HASH_KEY_IS_STRING + || zend_binary_strcasecmp(key->val, key->len-1, mptr->common.function_name->val, len) == 0) { zend_function *closure; /* see if this is a closure */ @@ -726,33 +712,31 @@ 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; + zval zv, zv_copy; int use_copy; string_write(str, " = ", sizeof(" = ")-1); - ALLOC_ZVAL(zv); - *zv = *precv->op2.zv; - zval_copy_ctor(zv); - INIT_PZVAL(zv); + ZVAL_DUP(&zv, precv->op2.zv); +//??? INIT_PZVAL(zv); zval_update_constant_ex(&zv, (void*)1, fptr->common.scope TSRMLS_CC); - if (Z_TYPE_P(zv) == IS_BOOL) { - if (Z_LVAL_P(zv)) { + if (Z_TYPE(zv) == IS_BOOL) { + if (Z_LVAL(zv)) { string_write(str, "true", sizeof("true")-1); } else { string_write(str, "false", sizeof("false")-1); } - } else if (Z_TYPE_P(zv) == IS_NULL) { + } else if (Z_TYPE(zv) == IS_NULL) { string_write(str, "NULL", sizeof("NULL")-1); - } else if (Z_TYPE_P(zv) == IS_STRING) { + } else if (Z_TYPE(zv) == IS_STRING) { string_write(str, "'", sizeof("'")-1); - string_write(str, Z_STRVAL_P(zv), MIN(Z_STRLEN_P(zv), 15)); - if (Z_STRLEN_P(zv) > 15) { + string_write(str, Z_STRVAL(zv), MIN(Z_STRLEN(zv), 15)); + if (Z_STRLEN(zv) > 15) { string_write(str, "...", sizeof("...")-1); } string_write(str, "'", sizeof("'")-1); - } else if (Z_TYPE_P(zv) == IS_ARRAY) { + } else if (Z_TYPE(zv) == IS_ARRAY) { string_write(str, "Array", sizeof("Array")-1); } else { - zend_make_printable_zval(zv, &zv_copy, &use_copy); + 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); @@ -792,8 +776,7 @@ static void _function_closure_string(string *str, zend_function *fptr, char* ind { zend_uint i, count; ulong num_index; - char *key; - uint key_len; + zend_string *key; HashTable *static_variables; HashPosition pos; @@ -813,8 +796,8 @@ static void _function_closure_string(string *str, zend_function *fptr, char* ind zend_hash_internal_pointer_reset_ex(static_variables, &pos); i = 0; while (i < count) { - zend_hash_get_current_key_ex(static_variables, &key, &key_len, &num_index, 0, &pos); - string_printf(str, "%s Variable #%d [ $%s ]\n", indent, i++, key); + zend_hash_get_current_key_ex(static_variables, &key, &num_index, 0, &pos); + string_printf(str, "%s Variable #%d [ $%s ]\n", indent, i++, key->val); zend_hash_move_forward_ex(static_variables, &pos); } string_printf(str, "%s}\n", indent); @@ -826,7 +809,7 @@ static void _function_string(string *str, zend_function *fptr, zend_class_entry { string param_indent; zend_function *overwrites; - char *lc_name; + zend_string *lc_name; unsigned int lc_name_len; /* TBD: Repair indenting of doc comment (or is this to be done in the parser?) @@ -851,9 +834,10 @@ static void _function_string(string *str, zend_function *fptr, zend_class_entry if (fptr->common.scope != scope) { string_printf(str, ", inherits %s", fptr->common.scope->name); } else if (fptr->common.scope->parent) { - lc_name_len = strlen(fptr->common.function_name); - lc_name = zend_str_tolower_dup(fptr->common.function_name, lc_name_len); - if (zend_hash_find(&fptr->common.scope->parent->function_table, lc_name, lc_name_len + 1, (void**) &overwrites) == SUCCESS) { + lc_name_len = fptr->common.function_name->len; + lc_name = STR_ALLOC(lc_name_len, 0); + zend_str_tolower_copy(lc_name->val, fptr->common.function_name->val, lc_name_len); + if ((overwrites = zend_hash_find_ptr(&fptr->common.scope->parent->function_table, lc_name)) != NULL) { if (fptr->common.scope != overwrites->common.scope) { string_printf(str, ", overwrites %s", overwrites->common.scope->name); } @@ -958,7 +942,7 @@ static void _property_string(string *str, zend_property_info *prop, char *prop_n string_printf(str, "static "); } - zend_unmangle_property_name(prop->name, prop->name_length, &class_name, (const char**)&prop_name); + zend_unmangle_property_name(prop->name->val, prop->name->len, &class_name, (const char**)&prop_name); string_printf(str, "$%s", prop_name); } @@ -1026,7 +1010,7 @@ static int _extension_const_string(zend_constant *constant TSRMLS_DC, int num_ar int *num_classes = va_arg(args, int*); if (constant->module_number == module->module_number) { - _const_string(str, constant->name, &constant->value, indent TSRMLS_CC); + _const_string(str, constant->name->val, &constant->value, indent TSRMLS_CC); (*num_classes)++; } return ZEND_HASH_APPLY_KEEP; @@ -1114,7 +1098,7 @@ static void _extension_string(string *str, zend_module_entry *module, char *inde int first = 1; zend_hash_internal_pointer_reset_ex(CG(function_table), &iterator); - while (zend_hash_get_current_data_ex(CG(function_table), (void **) &fptr, &iterator) == SUCCESS) { + while ((fptr = zend_hash_get_current_data_ptr_ex(CG(function_table), &iterator)) != NULL) { if (fptr->common.type==ZEND_INTERNAL_FUNCTION && fptr->internal_function.module == module) { if (first) { @@ -1191,16 +1175,15 @@ static void _function_check_flag(INTERNAL_FUNCTION_PARAMETERS, int mask) PHPAPI void zend_reflection_class_factory(zend_class_entry *ce, zval *object TSRMLS_DC) { reflection_object *intern; - zval *name; + zval name; - MAKE_STD_ZVAL(name); - ZVAL_STRINGL(name, ce->name, ce->name_length, 1); + ZVAL_STR(&name, STR_COPY(ce->name)); reflection_instantiate(reflection_class_ptr, object TSRMLS_CC); - intern = (reflection_object *) zend_object_store_get_object(object TSRMLS_CC); + intern = (reflection_object *) Z_STR_P(object); intern->ptr = ce; intern->ref_type = REF_TYPE_OTHER; intern->ce = ce; - reflection_update_property(object, "name", name); + reflection_update_property(object, "name", &name); } /* }}} */ @@ -1208,28 +1191,26 @@ PHPAPI void zend_reflection_class_factory(zend_class_entry *ce, zval *object TSR static void reflection_extension_factory(zval *object, const char *name_str TSRMLS_DC) { reflection_object *intern; - zval *name; + zval name; int name_len = strlen(name_str); - char *lcname; + zend_string *lcname; struct _zend_module_entry *module; - ALLOCA_FLAG(use_heap) - lcname = do_alloca(name_len + 1, use_heap); - zend_str_tolower_copy(lcname, name_str, name_len); - if (zend_hash_find(&module_registry, lcname, name_len + 1, (void **)&module) == FAILURE) { - free_alloca(lcname, use_heap); + lcname = STR_ALLOC(name_len, 0); + zend_str_tolower_copy(lcname->val, name_str, name_len); + module = zend_hash_find_ptr(&module_registry, lcname); + STR_FREE(lcname); + if (!module) { return; } - free_alloca(lcname, use_heap); reflection_instantiate(reflection_extension_ptr, object TSRMLS_CC); - intern = (reflection_object *) zend_object_store_get_object(object TSRMLS_CC); - MAKE_STD_ZVAL(name); - ZVAL_STRINGL(name, module->name, name_len, 1); + intern = (reflection_object *) Z_OBJ_P(object); + ZVAL_STRINGL(&name, module->name, name_len); intern->ptr = module; intern->ref_type = REF_TYPE_OTHER; intern->ce = NULL; - reflection_update_property(object, "name", name); + reflection_update_property(object, "name", &name); } /* }}} */ @@ -1238,19 +1219,18 @@ static void reflection_parameter_factory(zend_function *fptr, zval *closure_obje { reflection_object *intern; parameter_reference *reference; - zval *name; + zval name; if (closure_object) { Z_ADDREF_P(closure_object); } - MAKE_STD_ZVAL(name); if (arg_info->name) { - ZVAL_STRINGL(name, arg_info->name, arg_info->name_len, 1); + ZVAL_STRINGL(&name, arg_info->name, arg_info->name_len); } else { - ZVAL_NULL(name); + ZVAL_NULL(&name); } reflection_instantiate(reflection_parameter_ptr, object TSRMLS_CC); - intern = (reflection_object *) zend_object_store_get_object(object TSRMLS_CC); + intern = (reflection_object *) Z_OBJ_P(object); reference = (parameter_reference*) emalloc(sizeof(parameter_reference)); reference->arg_info = arg_info; reference->offset = offset; @@ -1259,8 +1239,8 @@ static void reflection_parameter_factory(zend_function *fptr, zval *closure_obje intern->ptr = reference; intern->ref_type = REF_TYPE_PARAMETER; intern->ce = fptr->common.scope; - intern->obj = closure_object; - reflection_update_property(object, "name", name); + ZVAL_COPY_VALUE(&intern->obj, closure_object); + reflection_update_property(object, "name", &name); } /* }}} */ @@ -1268,21 +1248,20 @@ static void reflection_parameter_factory(zend_function *fptr, zval *closure_obje static void reflection_function_factory(zend_function *function, zval *closure_object, zval *object TSRMLS_DC) { reflection_object *intern; - zval *name; + zval name; if (closure_object) { Z_ADDREF_P(closure_object); } - MAKE_STD_ZVAL(name); - ZVAL_STRING(name, function->common.function_name, 1); + ZVAL_STR(&name, STR_COPY(function->common.function_name)); reflection_instantiate(reflection_function_ptr, object TSRMLS_CC); - intern = (reflection_object *) zend_object_store_get_object(object TSRMLS_CC); + intern = (reflection_object *) Z_OBJ_P(object); intern->ptr = function; intern->ref_type = REF_TYPE_FUNCTION; intern->ce = NULL; - intern->obj = closure_object; - reflection_update_property(object, "name", name); + ZVAL_COPY_VALUE(&intern->obj, closure_object); + reflection_update_property(object, "name", &name); } /* }}} */ @@ -1290,25 +1269,23 @@ static void reflection_function_factory(zend_function *function, zval *closure_o static void reflection_method_factory(zend_class_entry *ce, zend_function *method, zval *closure_object, zval *object TSRMLS_DC) { reflection_object *intern; - zval *name; - zval *classname; + zval name; + zval classname; if (closure_object) { Z_ADDREF_P(closure_object); } - MAKE_STD_ZVAL(name); - MAKE_STD_ZVAL(classname); - ZVAL_STRING(name, (method->common.scope && method->common.scope->trait_aliases)? - zend_resolve_method_name(ce, method) : method->common.function_name, 1); - ZVAL_STRINGL(classname, method->common.scope->name, method->common.scope->name_length, 1); + ZVAL_STR(&name, STR_COPY((method->common.scope && method->common.scope->trait_aliases)? + zend_resolve_method_name(ce, method) : method->common.function_name)); + ZVAL_STR(&classname, STR_COPY(method->common.scope->name)); reflection_instantiate(reflection_method_ptr, object TSRMLS_CC); - intern = (reflection_object *) zend_object_store_get_object(object TSRMLS_CC); + intern = (reflection_object *) Z_OBJ_P(object); intern->ptr = method; intern->ref_type = REF_TYPE_FUNCTION; intern->ce = ce; - intern->obj = closure_object; - reflection_update_property(object, "name", name); - reflection_update_property(object, "class", classname); + ZVAL_COPY_VALUE(&intern->obj, closure_object); + reflection_update_property(object, "name", &name); + reflection_update_property(object, "class", &classname); } /* }}} */ @@ -1316,19 +1293,19 @@ static void reflection_method_factory(zend_class_entry *ce, zend_function *metho static void reflection_property_factory(zend_class_entry *ce, zend_property_info *prop, zval *object TSRMLS_DC) { reflection_object *intern; - zval *name; - zval *classname; + zval name; + zval classname; property_reference *reference; const char *class_name, *prop_name; - zend_unmangle_property_name(prop->name, prop->name_length, &class_name, &prop_name); + zend_unmangle_property_name(prop->name->val, prop->name->len, &class_name, &prop_name); if (!(prop->flags & ZEND_ACC_PRIVATE)) { /* we have to search the class hierarchy for this (implicit) public or protected property */ zend_class_entry *tmp_ce = ce, *store_ce = ce; zend_property_info *tmp_info = NULL; - while (tmp_ce && zend_hash_find(&tmp_ce->properties_info, prop_name, strlen(prop_name) + 1, (void **) &tmp_info) != SUCCESS) { + while (tmp_ce && (tmp_info = zend_hash_str_find_ptr(&tmp_ce->properties_info, prop_name, strlen(prop_name))) == NULL) { ce = tmp_ce; tmp_ce = tmp_ce->parent; } @@ -1340,13 +1317,11 @@ static void reflection_property_factory(zend_class_entry *ce, zend_property_info } } - MAKE_STD_ZVAL(name); - MAKE_STD_ZVAL(classname); - ZVAL_STRING(name, prop_name, 1); - ZVAL_STRINGL(classname, prop->ce->name, prop->ce->name_length, 1); + ZVAL_STRING(&name, prop_name); + ZVAL_STR(&classname, STR_COPY(prop->ce->name)); reflection_instantiate(reflection_property_ptr, object TSRMLS_CC); - intern = (reflection_object *) zend_object_store_get_object(object TSRMLS_CC); + intern = (reflection_object *) Z_OBJ_P(object); reference = (property_reference*) emalloc(sizeof(property_reference)); reference->ce = ce; reference->prop = *prop; @@ -1354,23 +1329,22 @@ static void reflection_property_factory(zend_class_entry *ce, zend_property_info intern->ref_type = REF_TYPE_PROPERTY; intern->ce = ce; intern->ignore_visibility = 0; - reflection_update_property(object, "name", name); - reflection_update_property(object, "class", classname); + reflection_update_property(object, "name", &name); + reflection_update_property(object, "class", &classname); } /* }}} */ /* {{{ _reflection_export */ static void _reflection_export(INTERNAL_FUNCTION_PARAMETERS, zend_class_entry *ce_ptr, int ctor_argc) { - zval *reflector_ptr; + zval reflector; zval output, *output_ptr = &output; zval *argument_ptr, *argument2_ptr; - zval *retval_ptr, **params[2]; + zval retval, params[2]; int result; int return_output = 0; zend_fcall_info fci; zend_fcall_info_cache fcc; - zval fname; if (ctor_argc == 1) { if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|b", &argument_ptr, &return_output) == FAILURE) { @@ -1382,24 +1356,23 @@ static void _reflection_export(INTERNAL_FUNCTION_PARAMETERS, zend_class_entry *c } } - INIT_PZVAL(&output); +//??? INIT_PZVAL(&output); /* Create object */ - MAKE_STD_ZVAL(reflector_ptr); - if (object_and_properties_init(reflector_ptr, ce_ptr, NULL) == FAILURE) { + if (object_and_properties_init(&reflector, ce_ptr, NULL) == FAILURE) { _DO_THROW("Could not create reflector"); } /* Call __construct() */ - params[0] = &argument_ptr; - params[1] = &argument2_ptr; + ZVAL_COPY_VALUE(¶ms[0], argument_ptr); + ZVAL_COPY_VALUE(¶ms[1], argument2_ptr); fci.size = sizeof(fci); fci.function_table = NULL; - fci.function_name = NULL; + ZVAL_UNDEF(&fci.function_name); fci.symbol_table = NULL; - fci.object_ptr = reflector_ptr; - fci.retval_ptr_ptr = &retval_ptr; + fci.object_ptr = &reflector; + fci.retval = &retval; fci.param_count = ctor_argc; fci.params = params; fci.no_separation = 1; @@ -1407,34 +1380,32 @@ static void _reflection_export(INTERNAL_FUNCTION_PARAMETERS, zend_class_entry *c fcc.initialized = 1; fcc.function_handler = ce_ptr->constructor; fcc.calling_scope = ce_ptr; - fcc.called_scope = Z_OBJCE_P(reflector_ptr); - fcc.object_ptr = reflector_ptr; + fcc.called_scope = Z_OBJCE(reflector); + fcc.object_ptr = &reflector; result = zend_call_function(&fci, &fcc TSRMLS_CC); - if (retval_ptr) { - zval_ptr_dtor(&retval_ptr); - } + zval_ptr_dtor(&retval); if (EG(exception)) { - zval_ptr_dtor(&reflector_ptr); + zval_ptr_dtor(&reflector); return; } if (result == FAILURE) { - zval_ptr_dtor(&reflector_ptr); + zval_ptr_dtor(&reflector); _DO_THROW("Could not create reflector"); } /* Call static reflection::export */ ZVAL_BOOL(&output, return_output); - params[0] = &reflector_ptr; - params[1] = &output_ptr; + ZVAL_COPY_VALUE(¶ms[0], &reflector); + ZVAL_COPY_VALUE(¶ms[1], output_ptr); - ZVAL_STRINGL(&fname, "reflection::export", sizeof("reflection::export") - 1, 0); +//??? ZVAL_STRINGL(&fname, "reflection::export", sizeof("reflection::export") - 1, 0); + ZVAL_STRINGL(&fci.function_name, "reflection::export", sizeof("reflection::export") - 1); fci.function_table = &reflection_ptr->function_table; - fci.function_name = &fname; fci.object_ptr = NULL; - fci.retval_ptr_ptr = &retval_ptr; + fci.retval = &retval; fci.param_count = 2; fci.params = params; fci.no_separation = 1; @@ -1442,19 +1413,19 @@ static void _reflection_export(INTERNAL_FUNCTION_PARAMETERS, zend_class_entry *c result = zend_call_function(&fci, NULL TSRMLS_CC); if (result == FAILURE && EG(exception) == NULL) { - zval_ptr_dtor(&reflector_ptr); - zval_ptr_dtor(&retval_ptr); + zval_ptr_dtor(&reflector); + zval_ptr_dtor(&retval); _DO_THROW("Could not execute reflection::export()"); } if (return_output) { - COPY_PZVAL_TO_ZVAL(*return_value, retval_ptr); + COPY_PZVAL_TO_ZVAL(*return_value, &retval); } else { - zval_ptr_dtor(&retval_ptr); + zval_ptr_dtor(&retval); } /* Destruct reflector which is no longer needed */ - zval_ptr_dtor(&reflector_ptr); + zval_ptr_dtor(&reflector); } /* }}} */ @@ -1464,9 +1435,9 @@ static parameter_reference *_reflection_param_get_default_param(INTERNAL_FUNCTIO reflection_object *intern; parameter_reference *param; - intern = (reflection_object *) zend_object_store_get_object(getThis() TSRMLS_CC); + intern = (reflection_object *) Z_OBJ_P(getThis()); if (intern == NULL || intern->ptr == NULL) { - if (EG(exception) && Z_OBJCE_P(EG(exception)) == reflection_exception_ptr) { + if (EG(exception) && EG(exception)->ce == reflection_exception_ptr) { return NULL; } php_error_docref(NULL TSRMLS_CC, E_ERROR, "Internal error: Failed to retrieve the reflection object"); @@ -1513,7 +1484,7 @@ ZEND_METHOD(reflection, __clone) Exports a reflection object. Returns the output if TRUE is specified for return, printing it otherwise. */ ZEND_METHOD(reflection, export) { - zval *object, fname, *retval_ptr; + zval *object, fname, retval; int result; zend_bool return_output = 0; @@ -1522,8 +1493,8 @@ ZEND_METHOD(reflection, export) } /* Invoke the __toString() method */ - ZVAL_STRINGL(&fname, "__tostring", sizeof("__tostring") - 1, 1); - result= call_user_function_ex(NULL, &object, &fname, &retval_ptr, 0, NULL, 0, NULL TSRMLS_CC); + ZVAL_STRINGL(&fname, "__tostring", sizeof("__tostring") - 1); + result= call_user_function_ex(NULL, object, &fname, &retval, 0, NULL, 0, NULL TSRMLS_CC); zval_dtor(&fname); if (result == FAILURE) { @@ -1531,18 +1502,18 @@ ZEND_METHOD(reflection, export) /* Returns from this function */ } - if (!retval_ptr) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::__toString() did not return anything", Z_OBJCE_P(object)->name); + if (Z_TYPE(retval) == IS_UNDEF) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::__toString() did not return anything", Z_OBJCE_P(object)->name->val); RETURN_FALSE; } if (return_output) { - COPY_PZVAL_TO_ZVAL(*return_value, retval_ptr); + COPY_PZVAL_TO_ZVAL(*return_value, &retval); } else { /* No need for _r variant, return of __toString should always be a string */ - zend_print_zval(retval_ptr, 0); + zend_print_zval(&retval, 0); zend_printf("\n"); - zval_ptr_dtor(&retval_ptr); + zval_ptr_dtor(&retval); } } /* }}} */ @@ -1600,7 +1571,7 @@ ZEND_METHOD(reflection_function, export) Constructor. Throws an Exception in case the given function does not exist */ ZEND_METHOD(reflection_function, __construct) { - zval *name; + zval name; zval *object; zval *closure = NULL; char *lcname; @@ -1610,7 +1581,7 @@ ZEND_METHOD(reflection_function, __construct) int name_len; object = getThis(); - intern = (reflection_object *) zend_object_store_get_object(object TSRMLS_CC); + intern = (reflection_object *) Z_OBJ_P(object); if (intern == NULL) { return; } @@ -1630,7 +1601,7 @@ ZEND_METHOD(reflection_function, __construct) name_len--; } - if (zend_hash_find(EG(function_table), nsname, name_len + 1, (void **)&fptr) == FAILURE) { + if ((fptr = zend_hash_str_find_ptr(EG(function_table), nsname, name_len)) == NULL) { efree(lcname); zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Function %s() does not exist", name_str); @@ -1641,12 +1612,11 @@ ZEND_METHOD(reflection_function, __construct) return; } - MAKE_STD_ZVAL(name); - ZVAL_STRING(name, fptr->common.function_name, 1); - reflection_update_property(object, "name", name); + ZVAL_STR(&name, STR_COPY(fptr->common.function_name)); + reflection_update_property(object, "name", &name); intern->ptr = fptr; intern->ref_type = REF_TYPE_FUNCTION; - intern->obj = closure; + ZVAL_COPY_VALUE(&intern->obj, closure); intern->ce = NULL; } /* }}} */ @@ -1665,7 +1635,8 @@ ZEND_METHOD(reflection_function, __toString) GET_REFLECTION_OBJECT_PTR(fptr); string_init(&str); _function_string(&str, fptr, intern->ce, "" TSRMLS_CC); - RETURN_STRINGL(str.string, str.len - 1, 0); +//??? RETURN_STRINGL(str.string, str.len - 1, 0); + RETURN_STRINGL(str.string, str.len - 1); } /* }}} */ @@ -1676,7 +1647,7 @@ ZEND_METHOD(reflection_function, getName) if (zend_parse_parameters_none() == FAILURE) { return; } - _default_get_entry(getThis(), "name", sizeof("name"), return_value TSRMLS_CC); + _default_get_entry(getThis(), "name", sizeof("name")-1, return_value TSRMLS_CC); } /* }}} */ @@ -1707,8 +1678,8 @@ ZEND_METHOD(reflection_function, getClosureThis) return; } GET_REFLECTION_OBJECT_PTR(fptr); - if (intern->obj) { - closure_this = zend_get_closure_this_ptr(intern->obj TSRMLS_CC); + if (Z_TYPE(intern->obj) != IS_UNDEF) { + closure_this = zend_get_closure_this_ptr(&intern->obj TSRMLS_CC); if (closure_this) { RETURN_ZVAL(closure_this, 1, 0); } @@ -1728,8 +1699,8 @@ ZEND_METHOD(reflection_function, getClosureScopeClass) return; } GET_REFLECTION_OBJECT_PTR(fptr); - if (intern->obj) { - closure_func = zend_get_closure_method_def(intern->obj TSRMLS_CC); + if (Z_TYPE(intern->obj) != IS_UNDEF) { + closure_func = zend_get_closure_method_def(&intern->obj TSRMLS_CC); if (closure_func && closure_func->common.scope) { zend_reflection_class_factory(closure_func->common.scope, return_value TSRMLS_CC); } @@ -1809,7 +1780,7 @@ ZEND_METHOD(reflection_function, getFileName) } GET_REFLECTION_OBJECT_PTR(fptr); if (fptr->type == ZEND_USER_FUNCTION) { - RETURN_STRING(fptr->op_array.filename, 1); + RETURN_STR(STR_COPY(fptr->op_array.filename)); } RETURN_FALSE; } @@ -1863,7 +1834,7 @@ ZEND_METHOD(reflection_function, getDocComment) } GET_REFLECTION_OBJECT_PTR(fptr); if (fptr->type == ZEND_USER_FUNCTION && fptr->op_array.doc_comment) { - RETURN_STRINGL(fptr->op_array.doc_comment, fptr->op_array.doc_comment_len, 1); + RETURN_STR(STR_COPY(fptr->op_array.doc_comment)); } RETURN_FALSE; } @@ -1873,7 +1844,6 @@ ZEND_METHOD(reflection_function, getDocComment) Returns an associative array containing this function's static variables and their values */ ZEND_METHOD(reflection_function, getStaticVariables) { - zval *tmp_copy; reflection_object *intern; zend_function *fptr; @@ -1886,7 +1856,7 @@ ZEND_METHOD(reflection_function, getStaticVariables) array_init(return_value); if (fptr->type == ZEND_USER_FUNCTION && fptr->op_array.static_variables != NULL) { zend_hash_apply_with_argument(fptr->op_array.static_variables, (apply_func_arg_t) zval_update_constant_inline_change, fptr->common.scope TSRMLS_CC); - zend_hash_copy(Z_ARRVAL_P(return_value), fptr->op_array.static_variables, (copy_ctor_func_t) zval_add_ref, (void *) &tmp_copy, sizeof(zval *)); + zend_hash_copy(Z_ARRVAL_P(return_value), fptr->op_array.static_variables, zval_add_ref); } } /* }}} */ @@ -1895,8 +1865,9 @@ ZEND_METHOD(reflection_function, getStaticVariables) Invokes the function */ ZEND_METHOD(reflection_function, invoke) { - zval *retval_ptr; - zval ***params = NULL; + zval retval; +//??? + zval *params = NULL; int result, num_args = 0; zend_fcall_info fci; zend_fcall_info_cache fcc; @@ -1912,10 +1883,10 @@ ZEND_METHOD(reflection_function, invoke) fci.size = sizeof(fci); fci.function_table = NULL; - fci.function_name = NULL; + ZVAL_UNDEF(&fci.function_name); fci.symbol_table = NULL; fci.object_ptr = NULL; - fci.retval_ptr_ptr = &retval_ptr; + fci.retval = &retval; fci.param_count = num_args; fci.params = params; fci.no_separation = 1; @@ -1938,15 +1909,16 @@ ZEND_METHOD(reflection_function, invoke) return; } - if (retval_ptr) { - COPY_PZVAL_TO_ZVAL(*return_value, retval_ptr); + if (Z_TYPE(retval) != IS_UNDEF) { + COPY_PZVAL_TO_ZVAL(*return_value, &retval); } } /* }}} */ -static int _zval_array_to_c_array(zval **arg, zval ****params TSRMLS_DC) /* {{{ */ +static int _zval_array_to_c_array(zval *arg, zval **params TSRMLS_DC) /* {{{ */ { - *(*params)++ = arg; + ZVAL_COPY_VALUE((*params), arg); + (*params)++; return ZEND_HASH_APPLY_KEEP; } /* }}} */ @@ -1954,8 +1926,8 @@ static int _zval_array_to_c_array(zval **arg, zval ****params TSRMLS_DC) /* {{{ Invokes the function and pass its arguments as array. */ ZEND_METHOD(reflection_function, invokeArgs) { - zval *retval_ptr; - zval ***params; + zval retval; + zval *params; int result; int argc; zend_fcall_info fci; @@ -1973,16 +1945,16 @@ ZEND_METHOD(reflection_function, invokeArgs) argc = zend_hash_num_elements(Z_ARRVAL_P(param_array)); - params = safe_emalloc(sizeof(zval **), argc, 0); + params = safe_emalloc(sizeof(zval), argc, 0); zend_hash_apply_with_argument(Z_ARRVAL_P(param_array), (apply_func_arg_t)_zval_array_to_c_array, ¶ms TSRMLS_CC); params -= argc; fci.size = sizeof(fci); fci.function_table = NULL; - fci.function_name = NULL; + ZVAL_UNDEF(&fci.function_name); fci.symbol_table = NULL; fci.object_ptr = NULL; - fci.retval_ptr_ptr = &retval_ptr; + fci.retval = &retval; fci.param_count = argc; fci.params = params; fci.no_separation = 1; @@ -2003,8 +1975,8 @@ ZEND_METHOD(reflection_function, invokeArgs) return; } - if (retval_ptr) { - COPY_PZVAL_TO_ZVAL(*return_value, retval_ptr); + if (Z_TYPE(retval) != IS_UNDEF) { + COPY_PZVAL_TO_ZVAL(*return_value, &retval); } } /* }}} */ @@ -2067,11 +2039,10 @@ ZEND_METHOD(reflection_function, getParameters) array_init(return_value); for (i = 0; i < fptr->common.num_args; i++) { - zval *parameter; + zval parameter; - ALLOC_ZVAL(parameter); - reflection_parameter_factory(_copy_function(fptr TSRMLS_CC), intern->obj, arg_info, i, fptr->common.required_num_args, parameter TSRMLS_CC); - add_next_index_zval(return_value, parameter); + reflection_parameter_factory(_copy_function(fptr TSRMLS_CC), &intern->obj, arg_info, i, fptr->common.required_num_args, ¶meter TSRMLS_CC); + add_next_index_zval(return_value, ¶meter); arg_info++; } @@ -2119,7 +2090,7 @@ ZEND_METHOD(reflection_function, getExtensionName) internal = (zend_internal_function *)fptr; if (internal->module) { - RETURN_STRING(internal->module->name, 1); + RETURN_STRING(internal->module->name); } else { RETURN_FALSE; } @@ -2139,9 +2110,9 @@ ZEND_METHOD(reflection_parameter, export) ZEND_METHOD(reflection_parameter, __construct) { parameter_reference *ref; - zval *reference, **parameter; + zval *reference, *parameter; zval *object; - zval *name; + zval name; reflection_object *intern; zend_function *fptr; struct _zend_arg_info *arg_info; @@ -2149,12 +2120,12 @@ ZEND_METHOD(reflection_parameter, __construct) zend_class_entry *ce = NULL; zend_bool is_closure = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zZ", &reference, ¶meter) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", &reference, ¶meter) == FAILURE) { return; } object = getThis(); - intern = (reflection_object *) zend_object_store_get_object(object TSRMLS_CC); + intern = (reflection_object *) Z_OBJ_P(object); if (intern == NULL) { return; } @@ -2167,7 +2138,7 @@ ZEND_METHOD(reflection_parameter, __construct) lcname_len = Z_STRLEN_P(reference); lcname = zend_str_tolower_dup(Z_STRVAL_P(reference), lcname_len); - if (zend_hash_find(EG(function_table), lcname, lcname_len + 1, (void**) &fptr) == FAILURE) { + if ((fptr = zend_hash_str_find_ptr(EG(function_table), lcname, lcname_len)) == NULL) { efree(lcname); zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Function %s() does not exist", Z_STRVAL_P(reference)); @@ -2179,45 +2150,43 @@ ZEND_METHOD(reflection_parameter, __construct) break; case IS_ARRAY: { - zval **classref; - zval **method; - zend_class_entry **pce; + zval *classref; + zval *method; unsigned int lcname_len; char *lcname; - if ((zend_hash_index_find(Z_ARRVAL_P(reference), 0, (void **) &classref) == FAILURE) - || (zend_hash_index_find(Z_ARRVAL_P(reference), 1, (void **) &method) == FAILURE)) + if (((classref =zend_hash_index_find(Z_ARRVAL_P(reference), 0)) == NULL) + || ((method = zend_hash_index_find(Z_ARRVAL_P(reference), 1)) == NULL)) { _DO_THROW("Expected array($object, $method) or array($classname, $method)"); /* returns out of this function */ } - if (Z_TYPE_PP(classref) == IS_OBJECT) { - ce = Z_OBJCE_PP(classref); + if (Z_TYPE_P(classref) == IS_OBJECT) { + ce = Z_OBJCE_P(classref); } else { convert_to_string_ex(classref); - if (zend_lookup_class(Z_STRVAL_PP(classref), Z_STRLEN_PP(classref), &pce TSRMLS_CC) == FAILURE) { + if ((ce = zend_lookup_class(Z_STR_P(classref) TSRMLS_CC)) == NULL) { zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, - "Class %s does not exist", Z_STRVAL_PP(classref)); + "Class %s does not exist", Z_STRVAL_P(classref)); return; } - ce = *pce; } convert_to_string_ex(method); - lcname_len = Z_STRLEN_PP(method); - lcname = zend_str_tolower_dup(Z_STRVAL_PP(method), lcname_len); - if (ce == zend_ce_closure && Z_TYPE_PP(classref) == IS_OBJECT + lcname_len = Z_STRLEN_P(method); + lcname = zend_str_tolower_dup(Z_STRVAL_P(method), lcname_len); + if (ce == zend_ce_closure && Z_TYPE_P(classref) == IS_OBJECT && (lcname_len == sizeof(ZEND_INVOKE_FUNC_NAME)-1) && memcmp(lcname, ZEND_INVOKE_FUNC_NAME, sizeof(ZEND_INVOKE_FUNC_NAME)-1) == 0 - && (fptr = zend_get_closure_invoke_method(*classref TSRMLS_CC)) != NULL) + && (fptr = zend_get_closure_invoke_method(classref TSRMLS_CC)) != NULL) { /* nothing to do. don't set is_closure since is the invoke handler, - not the closure itself */ - } else if (zend_hash_find(&ce->function_table, lcname, lcname_len + 1, (void **) &fptr) == FAILURE) { + } else if ((fptr = zend_hash_str_find_ptr(&ce->function_table, lcname, lcname_len)) == NULL) { efree(lcname); zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, - "Method %s::%s() does not exist", ce->name, Z_STRVAL_PP(method)); + "Method %s::%s() does not exist", ce->name->val, Z_STRVAL_P(method)); return; } efree(lcname); @@ -2231,7 +2200,7 @@ ZEND_METHOD(reflection_parameter, __construct) fptr = (zend_function *)zend_get_closure_method_def(reference TSRMLS_CC); Z_ADDREF_P(reference); is_closure = 1; - } else if (zend_hash_find(&ce->function_table, ZEND_INVOKE_FUNC_NAME, sizeof(ZEND_INVOKE_FUNC_NAME), (void **)&fptr) == FAILURE) { + } else if ((fptr = zend_hash_str_find_ptr(&ce->function_table, ZEND_INVOKE_FUNC_NAME, sizeof(ZEND_INVOKE_FUNC_NAME))) == NULL) { zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Method %s::%s() does not exist", ce->name, ZEND_INVOKE_FUNC_NAME); return; @@ -2246,17 +2215,17 @@ ZEND_METHOD(reflection_parameter, __construct) /* Now, search for the parameter */ arg_info = fptr->common.arg_info; - if (Z_TYPE_PP(parameter) == IS_LONG) { - position= Z_LVAL_PP(parameter); + if (Z_TYPE_P(parameter) == IS_LONG) { + position= Z_LVAL_P(parameter); if (position < 0 || (zend_uint)position >= fptr->common.num_args) { if (fptr->common.fn_flags & ZEND_ACC_CALL_VIA_HANDLER) { if (fptr->type != ZEND_OVERLOADED_FUNCTION) { - efree((char*)fptr->common.function_name); + STR_RELEASE(fptr->common.function_name); } efree(fptr); } if (is_closure) { - zval_ptr_dtor(&reference); + zval_ptr_dtor(reference); } _DO_THROW("The parameter specified by its offset could not be found"); /* returns out of this function */ @@ -2267,7 +2236,7 @@ ZEND_METHOD(reflection_parameter, __construct) position= -1; convert_to_string_ex(parameter); for (i = 0; i < fptr->common.num_args; i++) { - if (arg_info[i].name && strcmp(arg_info[i].name, Z_STRVAL_PP(parameter)) == 0) { + if (arg_info[i].name && strcmp(arg_info[i].name, Z_STRVAL_P(parameter)) == 0) { position= i; break; } @@ -2275,25 +2244,24 @@ ZEND_METHOD(reflection_parameter, __construct) if (position == -1) { if (fptr->common.fn_flags & ZEND_ACC_CALL_VIA_HANDLER) { if (fptr->type != ZEND_OVERLOADED_FUNCTION) { - efree((char*)fptr->common.function_name); + STR_RELEASE(fptr->common.function_name); } efree(fptr); } if (is_closure) { - zval_ptr_dtor(&reference); + zval_ptr_dtor(reference); } _DO_THROW("The parameter specified by its name could not be found"); /* returns out of this function */ } } - MAKE_STD_ZVAL(name); if (arg_info[position].name) { - ZVAL_STRINGL(name, arg_info[position].name, arg_info[position].name_len, 1); + ZVAL_STRINGL(&name, arg_info[position].name, arg_info[position].name_len); } else { - ZVAL_NULL(name); + ZVAL_NULL(&name); } - reflection_update_property(object, "name", name); + reflection_update_property(object, "name", &name); ref = (parameter_reference*) emalloc(sizeof(parameter_reference)); ref->arg_info = &arg_info[position]; @@ -2305,7 +2273,7 @@ ZEND_METHOD(reflection_parameter, __construct) intern->ref_type = REF_TYPE_PARAMETER; intern->ce = ce; if (reference && is_closure) { - intern->obj = reference; + ZVAL_COPY_VALUE(&intern->obj, reference); } } /* }}} */ @@ -2324,7 +2292,8 @@ ZEND_METHOD(reflection_parameter, __toString) GET_REFLECTION_OBJECT_PTR(param); string_init(&str); _parameter_string(&str, param->fptr, param->arg_info, param->offset, param->required, "" TSRMLS_CC); - RETURN_STRINGL(str.string, str.len - 1, 0); +///??? RETURN_STRINGL(str.string, str.len - 1, 0); + RETURN_STRINGL(str.string, str.len - 1); } /* }}} */ @@ -2335,7 +2304,7 @@ ZEND_METHOD(reflection_parameter, getName) if (zend_parse_parameters_none() == FAILURE) { return; } - _default_get_entry(getThis(), "name", sizeof("name"), return_value TSRMLS_CC); + _default_get_entry(getThis(), "name", sizeof("name")-1, return_value TSRMLS_CC); } /* }}} */ @@ -2352,9 +2321,9 @@ ZEND_METHOD(reflection_parameter, getDeclaringFunction) GET_REFLECTION_OBJECT_PTR(param); if (!param->fptr->common.scope) { - reflection_function_factory(_copy_function(param->fptr TSRMLS_CC), intern->obj, return_value TSRMLS_CC); + reflection_function_factory(_copy_function(param->fptr TSRMLS_CC), &intern->obj, return_value TSRMLS_CC); } else { - reflection_method_factory(param->fptr->common.scope, _copy_function(param->fptr TSRMLS_CC), intern->obj, return_value TSRMLS_CC); + reflection_method_factory(param->fptr->common.scope, _copy_function(param->fptr TSRMLS_CC), &intern->obj, return_value TSRMLS_CC); } } /* }}} */ @@ -2383,7 +2352,7 @@ ZEND_METHOD(reflection_parameter, getClass) { reflection_object *intern; parameter_reference *param; - zend_class_entry **pce, *ce; + zend_class_entry *ce; if (zend_parse_parameters_none() == FAILURE) { return; @@ -2410,7 +2379,6 @@ ZEND_METHOD(reflection_parameter, getClass) "Parameter uses 'self' as type hint but function is not a class member!"); return; } - pce= &ce; } else if (0 == zend_binary_strcasecmp(param->arg_info->class_name, param->arg_info->class_name_len, "parent", sizeof("parent")- 1)) { ce = param->fptr->common.scope; if (!ce) { @@ -2423,13 +2391,18 @@ ZEND_METHOD(reflection_parameter, getClass) "Parameter uses 'parent' as type hint although class does not have a parent!"); return; } - pce= &ce->parent; - } else if (zend_lookup_class(param->arg_info->class_name, param->arg_info->class_name_len, &pce TSRMLS_CC) == FAILURE) { - zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, - "Class %s does not exist", param->arg_info->class_name); - return; + ce = ce->parent; + } else { + zend_string *name = STR_INIT(param->arg_info->class_name, param->arg_info->class_name_len, 0); + ce = zend_lookup_class(name TSRMLS_CC); + STR_FREE(name); + if (!ce) { + zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, + "Class %s does not exist", param->arg_info->class_name); + return; + } } - zend_reflection_class_factory(*pce, return_value TSRMLS_CC); + zend_reflection_class_factory(ce, return_value TSRMLS_CC); } } /* }}} */ @@ -2594,12 +2567,12 @@ ZEND_METHOD(reflection_parameter, getDefaultValue) return; } - *return_value = *precv->op2.zv; - INIT_PZVAL(return_value); + ZVAL_COPY_VALUE(return_value, precv->op2.zv); +//??? INIT_PZVAL(return_value); if (!IS_CONSTANT_TYPE(Z_TYPE_P(return_value))) { zval_copy_ctor(return_value); } - zval_update_constant_ex(&return_value, (void*)0, param->fptr->common.scope TSRMLS_CC); + zval_update_constant_ex(return_value, (void*)0, param->fptr->common.scope TSRMLS_CC); } /* }}} */ @@ -2646,7 +2619,7 @@ ZEND_METHOD(reflection_parameter, getDefaultValueConstantName) precv = _reflection_param_get_default_precv(INTERNAL_FUNCTION_PARAM_PASSTHRU, param); if (precv && (Z_TYPE_P(precv->op2.zv) & IS_CONSTANT_TYPE_MASK) == IS_CONSTANT) { - RETURN_STRINGL(Z_STRVAL_P(precv->op2.zv), Z_STRLEN_P(precv->op2.zv), 1); + RETURN_STR(STR_COPY(Z_STR_P(precv->op2.zv))); } } /* }}} */ @@ -2679,11 +2652,10 @@ ZEND_METHOD(reflection_method, export) Constructor. Throws an Exception in case the given method does not exist */ ZEND_METHOD(reflection_method, __construct) { - zval *name, *classname; + zval name, *classname; zval *object, *orig_obj; reflection_object *intern; char *lcname; - zend_class_entry **pce; zend_class_entry *ce; zend_function *mptr; char *name_str, *tmp; @@ -2700,7 +2672,7 @@ ZEND_METHOD(reflection_method, __construct) } classname = &ztmp; tmp_len = tmp - name_str; - ZVAL_STRINGL(classname, name_str, tmp_len, 1); + ZVAL_STRINGL(classname, name_str, tmp_len); name_len = name_len - (tmp_len + 2); name_str = tmp + 2; orig_obj = NULL; @@ -2711,7 +2683,7 @@ ZEND_METHOD(reflection_method, __construct) } object = getThis(); - intern = (reflection_object *) zend_object_store_get_object(object TSRMLS_CC); + intern = (reflection_object *) Z_OBJ_P(object); if (intern == NULL) { return; } @@ -2719,7 +2691,7 @@ ZEND_METHOD(reflection_method, __construct) /* Find the class entry */ switch (Z_TYPE_P(classname)) { case IS_STRING: - if (zend_lookup_class(Z_STRVAL_P(classname), Z_STRLEN_P(classname), &pce TSRMLS_CC) == FAILURE) { + if ((ce = zend_lookup_class(Z_STR_P(classname) TSRMLS_CC)) == NULL) { zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Class %s does not exist", Z_STRVAL_P(classname)); if (classname == &ztmp) { @@ -2727,7 +2699,6 @@ ZEND_METHOD(reflection_method, __construct) } return; } - ce = *pce; break; case IS_OBJECT: @@ -2753,22 +2724,18 @@ ZEND_METHOD(reflection_method, __construct) && (mptr = zend_get_closure_invoke_method(orig_obj TSRMLS_CC)) != NULL) { /* do nothing, mptr already set */ - } else if (zend_hash_find(&ce->function_table, lcname, name_len + 1, (void **) &mptr) == FAILURE) { + } else if ((mptr = zend_hash_str_find_ptr(&ce->function_table, lcname, name_len)) == NULL) { efree(lcname); zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, - "Method %s::%s() does not exist", ce->name, name_str); + "Method %s::%s() does not exist", ce->name->val, name_str); return; } efree(lcname); - MAKE_STD_ZVAL(classname); - ZVAL_STRINGL(classname, mptr->common.scope->name, mptr->common.scope->name_length, 1); - - reflection_update_property(object, "class", classname); - - MAKE_STD_ZVAL(name); - ZVAL_STRING(name, mptr->common.function_name, 1); - reflection_update_property(object, "name", name); + ZVAL_STR(&name, STR_COPY(mptr->common.scope->name)); + reflection_update_property(object, "class", &name); + ZVAL_STR(&name, STR_COPY(mptr->common.function_name)); + reflection_update_property(object, "name", &name); intern->ptr = mptr; intern->ref_type = REF_TYPE_FUNCTION; intern->ce = ce; @@ -2789,7 +2756,8 @@ ZEND_METHOD(reflection_method, __toString) GET_REFLECTION_OBJECT_PTR(mptr); string_init(&str); _function_string(&str, mptr, intern->ce, "" TSRMLS_CC); - RETURN_STRINGL(str.string, str.len - 1, 0); +//??? RETURN_STRINGL(str.string, str.len - 1, 0); + RETURN_STRINGL(str.string, str.len - 1); } /* }}} */ @@ -2832,9 +2800,10 @@ ZEND_METHOD(reflection_method, getClosure) Invokes the method. */ ZEND_METHOD(reflection_method, invoke) { - zval *retval_ptr; - zval ***params = NULL; - zval *object_ptr; + zval retval; +//??? + zval *params = NULL; + zval object; reflection_object *intern; zend_function *mptr; int result, num_args = 0; @@ -2875,16 +2844,16 @@ ZEND_METHOD(reflection_method, invoke) * Else, we verify that the given object is an instance of the class. */ if (mptr->common.fn_flags & ZEND_ACC_STATIC) { - object_ptr = NULL; + ZVAL_UNDEF(&object); obj_ce = mptr->common.scope; } else { - if (Z_TYPE_PP(params[0]) != IS_OBJECT) { + if (Z_TYPE(params[0]) != IS_OBJECT) { efree(params); _DO_THROW("Non-object passed to Invoke()"); /* Returns from this function */ } - obj_ce = Z_OBJCE_PP(params[0]); + obj_ce = Z_OBJCE(params[0]); if (!instanceof_function(obj_ce, mptr->common.scope TSRMLS_CC)) { if (params) { @@ -2894,15 +2863,15 @@ ZEND_METHOD(reflection_method, invoke) /* Returns from this function */ } - object_ptr = *params[0]; + ZVAL_COPY_VALUE(&object, ¶ms[0]); } fci.size = sizeof(fci); fci.function_table = NULL; - fci.function_name = NULL; + ZVAL_UNDEF(&fci.function_name); fci.symbol_table = NULL; - fci.object_ptr = object_ptr; - fci.retval_ptr_ptr = &retval_ptr; + fci.object_ptr = &object; + fci.retval = &retval; fci.param_count = num_args - 1; fci.params = params + 1; fci.no_separation = 1; @@ -2911,7 +2880,7 @@ ZEND_METHOD(reflection_method, invoke) fcc.function_handler = mptr; fcc.calling_scope = obj_ce; fcc.called_scope = intern->ce; - fcc.object_ptr = object_ptr; + fcc.object_ptr = &object; result = zend_call_function(&fci, &fcc TSRMLS_CC); @@ -2925,8 +2894,8 @@ ZEND_METHOD(reflection_method, invoke) return; } - if (retval_ptr) { - COPY_PZVAL_TO_ZVAL(*return_value, retval_ptr); + if (Z_TYPE(retval) != IS_UNDEF) { + COPY_PZVAL_TO_ZVAL(*return_value, &retval); } } /* }}} */ @@ -2935,8 +2904,8 @@ ZEND_METHOD(reflection_method, invoke) Invokes the function and pass its arguments as array. */ ZEND_METHOD(reflection_method, invokeArgs) { - zval *retval_ptr; - zval ***params; + zval retval; + zval *params; zval *object; reflection_object *intern; zend_function *mptr; @@ -2975,7 +2944,7 @@ ZEND_METHOD(reflection_method, invokeArgs) argc = zend_hash_num_elements(Z_ARRVAL_P(param_array)); - params = safe_emalloc(sizeof(zval **), argc, 0); + params = safe_emalloc(sizeof(zval), argc, 0); zend_hash_apply_with_argument(Z_ARRVAL_P(param_array), (apply_func_arg_t)_zval_array_to_c_array, ¶ms TSRMLS_CC); params -= argc; @@ -3008,10 +2977,10 @@ ZEND_METHOD(reflection_method, invokeArgs) fci.size = sizeof(fci); fci.function_table = NULL; - fci.function_name = NULL; + ZVAL_UNDEF(&fci.function_name); fci.symbol_table = NULL; fci.object_ptr = object; - fci.retval_ptr_ptr = &retval_ptr; + fci.retval = &retval; fci.param_count = argc; fci.params = params; fci.no_separation = 1; @@ -3040,8 +3009,8 @@ ZEND_METHOD(reflection_method, invokeArgs) return; } - if (retval_ptr) { - COPY_PZVAL_TO_ZVAL(*return_value, retval_ptr); + if (Z_TYPE(retval) != IS_UNDEF) { + COPY_PZVAL_TO_ZVAL(*return_value, &retval); } } /* }}} */ @@ -3122,18 +3091,18 @@ ZEND_METHOD(reflection_function, isVariadic) Returns whether this function is defined in namespace */ ZEND_METHOD(reflection_function, inNamespace) { - zval **name; + zval *name; const char *backslash; if (zend_parse_parameters_none() == FAILURE) { return; } - if (zend_hash_find(Z_OBJPROP_P(getThis()), "name", sizeof("name"), (void **) &name) == FAILURE) { + if ((name = zend_hash_str_find(Z_OBJPROP_P(getThis()), "name", sizeof("name")-1)) == NULL) { RETURN_FALSE; } - if (Z_TYPE_PP(name) == IS_STRING - && (backslash = zend_memrchr(Z_STRVAL_PP(name), '\\', Z_STRLEN_PP(name))) - && backslash > Z_STRVAL_PP(name)) + if (Z_TYPE_P(name) == IS_STRING + && (backslash = zend_memrchr(Z_STRVAL_P(name), '\\', Z_STRLEN_P(name))) + && backslash > Z_STRVAL_P(name)) { RETURN_TRUE; } @@ -3145,20 +3114,20 @@ ZEND_METHOD(reflection_function, inNamespace) Returns the name of namespace where this function is defined */ ZEND_METHOD(reflection_function, getNamespaceName) { - zval **name; + zval *name; const char *backslash; if (zend_parse_parameters_none() == FAILURE) { return; } - if (zend_hash_find(Z_OBJPROP_P(getThis()), "name", sizeof("name"), (void **) &name) == FAILURE) { + if ((name = zend_hash_str_find(Z_OBJPROP_P(getThis()), "name", sizeof("name")-1)) == NULL) { RETURN_FALSE; } - if (Z_TYPE_PP(name) == IS_STRING - && (backslash = zend_memrchr(Z_STRVAL_PP(name), '\\', Z_STRLEN_PP(name))) - && backslash > Z_STRVAL_PP(name)) + if (Z_TYPE_P(name) == IS_STRING + && (backslash = zend_memrchr(Z_STRVAL_P(name), '\\', Z_STRLEN_P(name))) + && backslash > Z_STRVAL_P(name)) { - RETURN_STRINGL(Z_STRVAL_PP(name), backslash - Z_STRVAL_PP(name), 1); + RETURN_STRINGL(Z_STRVAL_P(name), backslash - Z_STRVAL_P(name)); } RETURN_EMPTY_STRING(); } @@ -3168,22 +3137,22 @@ ZEND_METHOD(reflection_function, getNamespaceName) Returns the short name of the function (without namespace part) */ ZEND_METHOD(reflection_function, getShortName) { - zval **name; + zval *name; const char *backslash; if (zend_parse_parameters_none() == FAILURE) { return; } - if (zend_hash_find(Z_OBJPROP_P(getThis()), "name", sizeof("name"), (void **) &name) == FAILURE) { + if ((name = zend_hash_str_find(Z_OBJPROP_P(getThis()), "name", sizeof("name")-1)) == NULL) { RETURN_FALSE; } - if (Z_TYPE_PP(name) == IS_STRING - && (backslash = zend_memrchr(Z_STRVAL_PP(name), '\\', Z_STRLEN_PP(name))) - && backslash > Z_STRVAL_PP(name)) + if (Z_TYPE_P(name) == IS_STRING + && (backslash = zend_memrchr(Z_STRVAL_P(name), '\\', Z_STRLEN_P(name))) + && backslash > Z_STRVAL_P(name)) { - RETURN_STRINGL(backslash + 1, Z_STRLEN_PP(name) - (backslash - Z_STRVAL_PP(name) + 1), 1); + RETURN_STRINGL(backslash + 1, Z_STRLEN_P(name) - (backslash - Z_STRVAL_P(name) + 1)); } - RETURN_ZVAL(*name, 1, 0); + RETURN_ZVAL(name, 1, 0); } /* }}} */ @@ -3289,7 +3258,7 @@ ZEND_METHOD(reflection_method, setAccessible) return; } - intern = (reflection_object *) zend_object_store_get_object(getThis() TSRMLS_CC); + intern = (reflection_object *) Z_OBJ_P(getThis()); if (intern == NULL) { return; @@ -3312,9 +3281,9 @@ static void reflection_class_object_ctor(INTERNAL_FUNCTION_PARAMETERS, int is_ob { zval *argument; zval *object; - zval *classname; + zval classname; reflection_object *intern; - zend_class_entry **ce; + zend_class_entry *ce; if (is_object) { if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &argument) == FAILURE) { @@ -3327,34 +3296,32 @@ static void reflection_class_object_ctor(INTERNAL_FUNCTION_PARAMETERS, int is_ob } object = getThis(); - intern = (reflection_object *) zend_object_store_get_object(object TSRMLS_CC); + intern = (reflection_object *) Z_OBJ_P(object); if (intern == NULL) { return; } if (Z_TYPE_P(argument) == IS_OBJECT) { - MAKE_STD_ZVAL(classname); - ZVAL_STRINGL(classname, Z_OBJCE_P(argument)->name, Z_OBJCE_P(argument)->name_length, 1); - reflection_update_property(object, "name", classname); + ZVAL_STR(&classname, STR_COPY(Z_OBJCE_P(argument)->name)); + reflection_update_property(object, "name", &classname); intern->ptr = Z_OBJCE_P(argument); if (is_object) { - intern->obj = argument; - zval_add_ref(&argument); + ZVAL_COPY_VALUE(&intern->obj, argument); + zval_add_ref(argument); } } else { - convert_to_string_ex(&argument); - if (zend_lookup_class(Z_STRVAL_P(argument), Z_STRLEN_P(argument), &ce TSRMLS_CC) == FAILURE) { + convert_to_string_ex(argument); + if ((ce = zend_lookup_class(Z_STR_P(argument) TSRMLS_CC)) == NULL) { if (!EG(exception)) { zend_throw_exception_ex(reflection_exception_ptr, -1 TSRMLS_CC, "Class %s does not exist", Z_STRVAL_P(argument)); } return; } - MAKE_STD_ZVAL(classname); - ZVAL_STRINGL(classname, (*ce)->name, (*ce)->name_length, 1); - reflection_update_property(object, "name", classname); + ZVAL_STR(&classname, STR_COPY(ce->name)); + reflection_update_property(object, "name", &classname); - intern->ptr = *ce; + intern->ptr = ce; } intern->ref_type = REF_TYPE_OTHER; } @@ -3373,14 +3340,13 @@ static void add_class_vars(zend_class_entry *ce, int statics, zval *return_value { HashPosition pos; zend_property_info *prop_info; - zval *prop, *prop_copy; - char *key; - uint key_len; + zval *prop, prop_copy; + zend_string *key; ulong num_index; zend_hash_internal_pointer_reset_ex(&ce->properties_info, &pos); - while (zend_hash_get_current_data_ex(&ce->properties_info, (void **) &prop_info, &pos) == SUCCESS) { - zend_hash_get_current_key_ex(&ce->properties_info, &key, &key_len, &num_index, 0, &pos); + while ((prop_info = zend_hash_get_current_data_ptr_ex(&ce->properties_info, &pos)) != NULL) { + zend_hash_get_current_key_ex(&ce->properties_info, &key, &num_index, 0, &pos); zend_hash_move_forward_ex(&ce->properties_info, &pos); if (((prop_info->flags & ZEND_ACC_SHADOW) && prop_info->ce != ce) || @@ -3393,9 +3359,9 @@ static void add_class_vars(zend_class_entry *ce, int statics, zval *return_value prop = NULL; if (prop_info->offset >= 0) { if (statics && (prop_info->flags & ZEND_ACC_STATIC) != 0) { - prop = ce->default_static_members_table[prop_info->offset]; + prop = &ce->default_static_members_table[prop_info->offset]; } else if (!statics && (prop_info->flags & ZEND_ACC_STATIC) == 0) { - prop = ce->default_properties_table[prop_info->offset]; + prop = &ce->default_properties_table[prop_info->offset]; } } if (!prop) { @@ -3403,18 +3369,17 @@ static void add_class_vars(zend_class_entry *ce, int statics, zval *return_value } /* copy: enforce read only access */ - ALLOC_ZVAL(prop_copy); - *prop_copy = *prop; - zval_copy_ctor(prop_copy); - INIT_PZVAL(prop_copy); + ZVAL_DUP(&prop_copy, prop); +//??? INIT_PZVAL(prop_copy); /* this is necessary to make it able to work with default array * properties, returned to user */ - if (IS_CONSTANT_TYPE(Z_TYPE_P(prop_copy))) { + if (IS_CONSTANT_TYPE(Z_TYPE(prop_copy))) { zval_update_constant(&prop_copy, (void *) 1 TSRMLS_CC); } - add_assoc_zval(return_value, key, prop_copy); +//??? add_assoc_zval(return_value, key, &prop_copy); + add_assoc_zval(return_value, key->val, &prop_copy); } } /* }}} */ @@ -3445,28 +3410,27 @@ ZEND_METHOD(reflection_class, getStaticPropertyValue) { reflection_object *intern; zend_class_entry *ce; - char *name; - int name_len; - zval **prop, *def_value = NULL; + zend_string *name; + zval *prop, *def_value = NULL; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|z", &name, &name_len, &def_value) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S|z", &name, &def_value) == FAILURE) { return; } GET_REFLECTION_OBJECT_PTR(ce); zend_update_class_constants(ce TSRMLS_CC); - prop = zend_std_get_static_property(ce, name, name_len, 1, NULL TSRMLS_CC); + prop = zend_std_get_static_property(ce, name, 1, NULL TSRMLS_CC); if (!prop) { if (def_value) { RETURN_ZVAL(def_value, 1, 0); } else { zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, - "Class %s does not have a property named %s", ce->name, name); + "Class %s does not have a property named %s", ce->name->val, name); } return; } else { - RETURN_ZVAL(*prop, 1, 0); + RETURN_ZVAL(prop, 1, 0); } } /* }}} */ @@ -3477,32 +3441,30 @@ ZEND_METHOD(reflection_class, setStaticPropertyValue) { reflection_object *intern; zend_class_entry *ce; - char *name; - int name_len; - zval **variable_ptr, *value; - int refcount; - zend_uchar is_ref; + zend_string *name; + zval *variable_ptr, *value; +//??? int refcount; +//??? zend_uchar is_ref; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz", &name, &name_len, &value) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Sz", &name, &value) == FAILURE) { return; } GET_REFLECTION_OBJECT_PTR(ce); zend_update_class_constants(ce TSRMLS_CC); - variable_ptr = zend_std_get_static_property(ce, name, name_len, 1, NULL TSRMLS_CC); + variable_ptr = zend_std_get_static_property(ce, name, 1, NULL TSRMLS_CC); if (!variable_ptr) { zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, - "Class %s does not have a property named %s", ce->name, name); + "Class %s does not have a property named %s", ce->name->val, name); return; } - refcount = Z_REFCOUNT_PP(variable_ptr); - is_ref = Z_ISREF_PP(variable_ptr); - zval_dtor(*variable_ptr); - **variable_ptr = *value; - zval_copy_ctor(*variable_ptr); - Z_SET_REFCOUNT_PP(variable_ptr, refcount); - Z_SET_ISREF_TO_PP(variable_ptr, is_ref); +//??? refcount = Z_REFCOUNT_PP(variable_ptr); +//??? is_ref = Z_ISREF_PP(variable_ptr); + zval_dtor(variable_ptr); + ZVAL_DUP(variable_ptr, value); +//??? Z_SET_REFCOUNT_PP(variable_ptr, refcount); +//??? Z_SET_ISREF_TO_PP(variable_ptr, is_ref); } /* }}} */ @@ -3538,8 +3500,9 @@ ZEND_METHOD(reflection_class, __toString) } GET_REFLECTION_OBJECT_PTR(ce); string_init(&str); - _class_string(&str, ce, intern->obj, "" TSRMLS_CC); - RETURN_STRINGL(str.string, str.len - 1, 0); + _class_string(&str, ce, &intern->obj, "" TSRMLS_CC); +//??? RETURN_STRINGL(str.string, str.len - 1, 0); + RETURN_STRINGL(str.string, str.len - 1); } /* }}} */ @@ -3550,7 +3513,7 @@ ZEND_METHOD(reflection_class, getName) if (zend_parse_parameters_none() == FAILURE) { return; } - _default_get_entry(getThis(), "name", sizeof("name"), return_value TSRMLS_CC); + _default_get_entry(getThis(), "name", sizeof("name")-1, return_value TSRMLS_CC); } /* }}} */ @@ -3596,7 +3559,7 @@ ZEND_METHOD(reflection_class, getFileName) } GET_REFLECTION_OBJECT_PTR(ce); if (ce->type == ZEND_USER_CLASS) { - RETURN_STRING(ce->info.user.filename, 1); + RETURN_STR(STR_COPY(ce->info.user.filename)); } RETURN_FALSE; } @@ -3650,7 +3613,7 @@ ZEND_METHOD(reflection_class, getDocComment) } GET_REFLECTION_OBJECT_PTR(ce); if (ce->type == ZEND_USER_CLASS && ce->info.user.doc_comment) { - RETURN_STRINGL(ce->info.user.doc_comment, ce->info.user.doc_comment_len, 1); + RETURN_STR(STR_COPY(ce->info.user.doc_comment)); } RETURN_FALSE; } @@ -3694,7 +3657,7 @@ ZEND_METHOD(reflection_class, hasMethod) lc_name = zend_str_tolower_dup(name, name_len); if ((ce == zend_ce_closure && (name_len == sizeof(ZEND_INVOKE_FUNC_NAME)-1) && memcmp(lc_name, ZEND_INVOKE_FUNC_NAME, sizeof(ZEND_INVOKE_FUNC_NAME)-1) == 0) - || zend_hash_exists(&ce->function_table, lc_name, name_len + 1)) { + || zend_hash_str_exists(&ce->function_table, lc_name, name_len)) { efree(lc_name); RETURN_TRUE; } else { @@ -3722,15 +3685,15 @@ ZEND_METHOD(reflection_class, getMethod) GET_REFLECTION_OBJECT_PTR(ce); lc_name = zend_str_tolower_dup(name, name_len); - if (ce == zend_ce_closure && intern->obj && (name_len == sizeof(ZEND_INVOKE_FUNC_NAME)-1) + if (ce == zend_ce_closure && Z_TYPE(intern->obj) != IS_UNDEF && (name_len == sizeof(ZEND_INVOKE_FUNC_NAME)-1) && memcmp(lc_name, ZEND_INVOKE_FUNC_NAME, sizeof(ZEND_INVOKE_FUNC_NAME)-1) == 0 - && (mptr = zend_get_closure_invoke_method(intern->obj TSRMLS_CC)) != NULL) + && (mptr = zend_get_closure_invoke_method(&intern->obj TSRMLS_CC)) != NULL) { /* don't assign closure_object since we only reflect the invoke handler method and not the closure definition itself */ reflection_method_factory(ce, mptr, NULL, return_value TSRMLS_CC); efree(lc_name); - } else if (ce == zend_ce_closure && !intern->obj && (name_len == sizeof(ZEND_INVOKE_FUNC_NAME)-1) + } else if (ce == zend_ce_closure && Z_TYPE(intern->obj) == IS_UNDEF && (name_len == sizeof(ZEND_INVOKE_FUNC_NAME)-1) && memcmp(lc_name, ZEND_INVOKE_FUNC_NAME, sizeof(ZEND_INVOKE_FUNC_NAME)-1) == 0 && object_init_ex(&obj_tmp, ce) == SUCCESS && (mptr = zend_get_closure_invoke_method(&obj_tmp TSRMLS_CC)) != NULL) { /* don't assign closure_object since we only reflect the invoke handler @@ -3738,7 +3701,7 @@ ZEND_METHOD(reflection_class, getMethod) reflection_method_factory(ce, mptr, NULL, return_value TSRMLS_CC); zval_dtor(&obj_tmp); efree(lc_name); - } else if (zend_hash_find(&ce->function_table, lc_name, name_len + 1, (void**) &mptr) == SUCCESS) { + } else if ((mptr = zend_hash_str_find_ptr(&ce->function_table, lc_name, name_len)) != NULL) { reflection_method_factory(ce, mptr, NULL, return_value TSRMLS_CC); efree(lc_name); } else { @@ -3753,14 +3716,13 @@ ZEND_METHOD(reflection_class, getMethod) /* {{{ _addmethod */ static void _addmethod(zend_function *mptr, zend_class_entry *ce, zval *retval, long filter, zval *obj TSRMLS_DC) { - zval *method; - uint len = strlen(mptr->common.function_name); + zval method; + uint len = mptr->common.function_name->len; zend_function *closure; if (mptr->common.fn_flags & filter) { - ALLOC_ZVAL(method); if (ce == zend_ce_closure && obj && (len == sizeof(ZEND_INVOKE_FUNC_NAME)-1) - && memcmp(mptr->common.function_name, ZEND_INVOKE_FUNC_NAME, sizeof(ZEND_INVOKE_FUNC_NAME)-1) == 0 + && memcmp(mptr->common.function_name->val, ZEND_INVOKE_FUNC_NAME, sizeof(ZEND_INVOKE_FUNC_NAME)-1) == 0 && (closure = zend_get_closure_invoke_method(obj TSRMLS_CC)) != NULL) { mptr = closure; @@ -3768,8 +3730,8 @@ static void _addmethod(zend_function *mptr, zend_class_entry *ce, zval *retval, /* don't assign closure_object since we only reflect the invoke handler method and not the closure definition itself, even if we have a closure */ - reflection_method_factory(ce, mptr, NULL, method TSRMLS_CC); - add_next_index_zval(retval, method); + reflection_method_factory(ce, mptr, NULL, &method TSRMLS_CC); + add_next_index_zval(retval, &method); } } /* }}} */ @@ -3810,10 +3772,10 @@ ZEND_METHOD(reflection_class, getMethods) array_init(return_value); zend_hash_apply_with_arguments(&ce->function_table TSRMLS_CC, (apply_func_args_t) _addmethod_va, 4, &ce, return_value, filter, intern->obj); - if (intern->obj && instanceof_function(ce, zend_ce_closure TSRMLS_CC)) { - zend_function *closure = zend_get_closure_invoke_method(intern->obj TSRMLS_CC); + if (Z_TYPE(intern->obj) != IS_UNDEF && instanceof_function(ce, zend_ce_closure TSRMLS_CC)) { + zend_function *closure = zend_get_closure_invoke_method(&intern->obj TSRMLS_CC); if (closure) { - _addmethod(closure, ce, return_value, filter, intern->obj TSRMLS_CC); + _addmethod(closure, ce, return_value, filter, &intern->obj TSRMLS_CC); _free_function(closure TSRMLS_CC); } } @@ -3827,26 +3789,24 @@ ZEND_METHOD(reflection_class, hasProperty) reflection_object *intern; zend_property_info *property_info; zend_class_entry *ce; - char *name; - int name_len; - zval *property; + zend_string *name; + zval property; METHOD_NOTSTATIC(reflection_class_ptr); - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S", &name) == FAILURE) { return; } GET_REFLECTION_OBJECT_PTR(ce); - if (zend_hash_find(&ce->properties_info, name, name_len+1, (void **) &property_info) == SUCCESS) { + if ((property_info = zend_hash_find_ptr(&ce->properties_info, name)) != NULL) { if (property_info->flags & ZEND_ACC_SHADOW) { RETURN_FALSE; } RETURN_TRUE; } else { - if (intern->obj && Z_OBJ_HANDLER_P(intern->obj, has_property)) { - MAKE_STD_ZVAL(property); - ZVAL_STRINGL(property, name, name_len, 1); - if (Z_OBJ_HANDLER_P(intern->obj, has_property)(intern->obj, property, 2, 0 TSRMLS_CC)) { + if (Z_TYPE(intern->obj) != IS_UNDEF && Z_OBJ_HANDLER(intern->obj, has_property)) { + ZVAL_STR(&property, STR_COPY(name)); + if (Z_OBJ_HANDLER(intern->obj, has_property)(&intern->obj, &property, 2, 0 TSRMLS_CC)) { zval_ptr_dtor(&property); RETURN_TRUE; } @@ -3862,75 +3822,77 @@ ZEND_METHOD(reflection_class, hasProperty) ZEND_METHOD(reflection_class, getProperty) { reflection_object *intern; - zend_class_entry *ce, **pce; + zend_class_entry *ce, *ce2; zend_property_info *property_info; - char *name, *tmp, *classname; - int name_len, classname_len; + zend_string *name, *classname; + char *tmp, *str_name; + int classname_len, str_name_len; METHOD_NOTSTATIC(reflection_class_ptr); - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S", &name) == FAILURE) { return; } GET_REFLECTION_OBJECT_PTR(ce); - if (zend_hash_find(&ce->properties_info, name, name_len + 1, (void**) &property_info) == SUCCESS) { + if ((property_info = zend_hash_find_ptr(&ce->properties_info, name)) != NULL) { if ((property_info->flags & ZEND_ACC_SHADOW) == 0) { reflection_property_factory(ce, property_info, return_value TSRMLS_CC); return; } - } else if (intern->obj) { + } else if (Z_TYPE(intern->obj) != IS_UNDEF) { /* Check for dynamic properties */ - if (zend_hash_exists(Z_OBJ_HT_P(intern->obj)->get_properties(intern->obj TSRMLS_CC), name, name_len+1)) { + if (zend_hash_exists(Z_OBJ_HT(intern->obj)->get_properties(&intern->obj TSRMLS_CC), name)) { zend_property_info property_info_tmp; property_info_tmp.flags = ZEND_ACC_IMPLICIT_PUBLIC; - property_info_tmp.name = estrndup(name, name_len); - property_info_tmp.name_length = name_len; - property_info_tmp.h = zend_get_hash_value(name, name_len+1); + property_info_tmp.name = STR_COPY(name); property_info_tmp.doc_comment = NULL; property_info_tmp.ce = ce; reflection_property_factory(ce, &property_info_tmp, return_value TSRMLS_CC); - intern = (reflection_object *) zend_object_store_get_object(return_value TSRMLS_CC); + intern = (reflection_object *) Z_OBJ_P(return_value); intern->ref_type = REF_TYPE_DYNAMIC_PROPERTY; return; } } - if ((tmp = strstr(name, "::")) != NULL) { - classname_len = tmp - name; - classname = zend_str_tolower_dup(name, classname_len); - classname[classname_len] = '\0'; - name_len = name_len - (classname_len + 2); - name = tmp + 2; - - if (zend_lookup_class(classname, classname_len, &pce TSRMLS_CC) == FAILURE) { + str_name = name->val; + str_name_len = name->len; + if ((tmp = strstr(name->val, "::")) != NULL) { + classname_len = tmp - name->val; + classname = STR_ALLOC(classname_len, 0); + zend_str_tolower_copy(classname->val, name->val, classname_len); + classname->val[classname_len] = '\0'; + str_name_len = name->len - (classname_len + 2); + str_name = tmp + 2; + + ce2 = zend_lookup_class(classname TSRMLS_CC); + STR_FREE(classname); + if (!ce2) { if (!EG(exception)) { zend_throw_exception_ex(reflection_exception_ptr, -1 TSRMLS_CC, "Class %s does not exist", classname); } - efree(classname); return; } - efree(classname); - if (!instanceof_function(ce, *pce TSRMLS_CC)) { - zend_throw_exception_ex(reflection_exception_ptr, -1 TSRMLS_CC, "Fully qualified property name %s::%s does not specify a base class of %s", (*pce)->name, name, ce->name); + if (!instanceof_function(ce, ce2 TSRMLS_CC)) { + zend_throw_exception_ex(reflection_exception_ptr, -1 TSRMLS_CC, "Fully qualified property name %s::%s does not specify a base class of %s", ce2->name, str_name, ce->name->val); return; } - ce = *pce; + ce = ce2; - if (zend_hash_find(&ce->properties_info, name, name_len + 1, (void**) &property_info) == SUCCESS && (property_info->flags & ZEND_ACC_SHADOW) == 0) { + if ((property_info = zend_hash_str_find_ptr(&ce->properties_info, str_name, str_name_len)) != NULL && (property_info->flags & ZEND_ACC_SHADOW) == 0) { reflection_property_factory(ce, property_info, return_value TSRMLS_CC); return; } } zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, - "Property %s does not exist", name); + "Property %s does not exist", str_name); } /* }}} */ /* {{{ _addproperty */ static int _addproperty(zend_property_info *pptr TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key) { - zval *property; + zval property; zend_class_entry *ce = *va_arg(args, zend_class_entry**); zval *retval = va_arg(args, zval*); long filter = va_arg(args, long); @@ -3940,38 +3902,36 @@ static int _addproperty(zend_property_info *pptr TSRMLS_DC, int num_args, va_lis } if (pptr->flags & filter) { - ALLOC_ZVAL(property); - reflection_property_factory(ce, pptr, property TSRMLS_CC); - add_next_index_zval(retval, property); + reflection_property_factory(ce, pptr, &property TSRMLS_CC); + add_next_index_zval(retval, &property); } return 0; } /* }}} */ /* {{{ _adddynproperty */ -static int _adddynproperty(zval **pptr TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key) +static int _adddynproperty(zval *ptr TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key) { - zval *property; + zval property; zend_class_entry *ce = *va_arg(args, zend_class_entry**); zval *retval = va_arg(args, zval*), member; /* under some circumstances, the properties hash table may contain numeric * properties (e.g. when casting from array). This is a WONT FIX bug, at * least for the moment. Ignore these */ - if (hash_key->nKeyLength == 0) { + if (hash_key->key == NULL) { return 0; } - if (hash_key->arKey[0] == '\0') { + if (hash_key->key->val[0] == '\0') { return 0; /* non public cannot be dynamic */ } - ZVAL_STRINGL(&member, hash_key->arKey, hash_key->nKeyLength-1, 0); + ZVAL_STR(&member, hash_key->key); if (zend_get_property_info(ce, &member, 1 TSRMLS_CC) == &EG(std_property_info)) { - MAKE_STD_ZVAL(property); EG(std_property_info).flags = ZEND_ACC_IMPLICIT_PUBLIC; - reflection_property_factory(ce, &EG(std_property_info), property TSRMLS_CC); - add_next_index_zval(retval, property); + reflection_property_factory(ce, &EG(std_property_info), &property TSRMLS_CC); + add_next_index_zval(retval, &property); } return 0; } @@ -4001,8 +3961,8 @@ ZEND_METHOD(reflection_class, getProperties) array_init(return_value); zend_hash_apply_with_arguments(&ce->properties_info TSRMLS_CC, (apply_func_args_t) _addproperty, 3, &ce, return_value, filter); - if (intern->obj && (filter & ZEND_ACC_PUBLIC) != 0 && Z_OBJ_HT_P(intern->obj)->get_properties) { - HashTable *properties = Z_OBJ_HT_P(intern->obj)->get_properties(intern->obj TSRMLS_CC); + if (Z_TYPE(intern->obj) != IS_UNDEF && (filter & ZEND_ACC_PUBLIC) != 0 && Z_OBJ_HT(intern->obj)->get_properties) { + HashTable *properties = Z_OBJ_HT(intern->obj)->get_properties(&intern->obj TSRMLS_CC); zend_hash_apply_with_arguments(properties TSRMLS_CC, (apply_func_args_t) _adddynproperty, 2, &ce, return_value); } } @@ -4014,16 +3974,15 @@ ZEND_METHOD(reflection_class, hasConstant) { reflection_object *intern; zend_class_entry *ce; - char *name; - int name_len; + zend_string *name; METHOD_NOTSTATIC(reflection_class_ptr); - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S", &name) == FAILURE) { return; } GET_REFLECTION_OBJECT_PTR(ce); - if (zend_hash_exists(&ce->constants_table, name, name_len + 1)) { + if (zend_hash_exists(&ce->constants_table, name)) { RETURN_TRUE; } else { RETURN_FALSE; @@ -4035,7 +3994,6 @@ ZEND_METHOD(reflection_class, hasConstant) Returns an associative array containing this class' constants and their values */ ZEND_METHOD(reflection_class, getConstants) { - zval *tmp_copy; reflection_object *intern; zend_class_entry *ce; @@ -4045,7 +4003,7 @@ ZEND_METHOD(reflection_class, getConstants) GET_REFLECTION_OBJECT_PTR(ce); array_init(return_value); zend_hash_apply_with_argument(&ce->constants_table, (apply_func_arg_t)zval_update_constant_inline_change, ce TSRMLS_CC); - zend_hash_copy(Z_ARRVAL_P(return_value), &ce->constants_table, (copy_ctor_func_t) zval_add_ref, (void *) &tmp_copy, sizeof(zval *)); + zend_hash_copy(Z_ARRVAL_P(return_value), &ce->constants_table, zval_add_ref); } /* }}} */ @@ -4055,21 +4013,20 @@ ZEND_METHOD(reflection_class, getConstant) { reflection_object *intern; zend_class_entry *ce; - zval **value; - char *name; - int name_len; + zval *value; + zend_string *name; METHOD_NOTSTATIC(reflection_class_ptr); - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S", &name) == FAILURE) { return; } GET_REFLECTION_OBJECT_PTR(ce); zend_hash_apply_with_argument(&ce->constants_table, (apply_func_arg_t)zval_update_constant_inline_change, ce TSRMLS_CC); - if (zend_hash_find(&ce->constants_table, name, name_len + 1, (void **) &value) == FAILURE) { + if ((value = zend_hash_find(&ce->constants_table, name)) == NULL) { RETURN_FALSE; } - MAKE_COPY_ZVAL(value, return_value); + ZVAL_DUP(return_value, value); } /* }}} */ @@ -4127,11 +4084,11 @@ ZEND_METHOD(reflection_class, isCloneable) if (ce->ce_flags & (ZEND_ACC_INTERFACE | ZEND_ACC_TRAIT | ZEND_ACC_EXPLICIT_ABSTRACT_CLASS | ZEND_ACC_IMPLICIT_ABSTRACT_CLASS)) { RETURN_FALSE; } - if (intern->obj) { + if (Z_TYPE(intern->obj) != IS_UNDEF) { if (ce->clone) { RETURN_BOOL(ce->clone->common.fn_flags & ZEND_ACC_PUBLIC); } else { - RETURN_BOOL(Z_OBJ_HANDLER_P(intern->obj, clone_obj) != NULL); + RETURN_BOOL(Z_OBJ_HANDLER(intern->obj, clone_obj) != NULL); } } else { if (ce->clone) { @@ -4231,7 +4188,8 @@ ZEND_METHOD(reflection_class, newInstance) /* Run the constructor if there is one */ if (constructor) { - zval ***params = NULL; +//??? + zval *params = NULL; int num_args = 0; zend_fcall_info fci; zend_fcall_info_cache fcc; @@ -4252,10 +4210,10 @@ ZEND_METHOD(reflection_class, newInstance) fci.size = sizeof(fci); fci.function_table = EG(function_table); - fci.function_name = NULL; + ZVAL_UNDEF(&fci.function_name); fci.symbol_table = NULL; fci.object_ptr = return_value; - fci.retval_ptr_ptr = &retval_ptr; + fci.retval = retval_ptr; fci.param_count = num_args; fci.params = params; fci.no_separation = 1; @@ -4271,14 +4229,14 @@ ZEND_METHOD(reflection_class, newInstance) efree(params); } if (retval_ptr) { - zval_ptr_dtor(&retval_ptr); + zval_ptr_dtor(retval_ptr); } - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invocation of %s's constructor failed", ce->name); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invocation of %s's constructor failed", ce->name->val); zval_dtor(return_value); RETURN_NULL(); } if (retval_ptr) { - zval_ptr_dtor(&retval_ptr); + zval_ptr_dtor(retval_ptr); } if (params) { efree(params); @@ -4339,7 +4297,8 @@ ZEND_METHOD(reflection_class, newInstanceArgs) /* Run the constructor if there is one */ if (constructor) { - zval ***params = NULL; +//??? + zval *params = NULL; zend_fcall_info fci; zend_fcall_info_cache fcc; @@ -4350,17 +4309,17 @@ ZEND_METHOD(reflection_class, newInstanceArgs) } if (argc) { - params = safe_emalloc(sizeof(zval **), argc, 0); + params = safe_emalloc(sizeof(zval), argc, 0); zend_hash_apply_with_argument(args, (apply_func_arg_t)_zval_array_to_c_array, ¶ms TSRMLS_CC); params -= argc; } fci.size = sizeof(fci); fci.function_table = EG(function_table); - fci.function_name = NULL; + ZVAL_UNDEF(&fci.function_name); fci.symbol_table = NULL; fci.object_ptr = return_value; - fci.retval_ptr_ptr = &retval_ptr; + fci.retval = retval_ptr; fci.param_count = argc; fci.params = params; fci.no_separation = 1; @@ -4376,20 +4335,20 @@ ZEND_METHOD(reflection_class, newInstanceArgs) efree(params); } if (retval_ptr) { - zval_ptr_dtor(&retval_ptr); + zval_ptr_dtor(retval_ptr); } - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invocation of %s's constructor failed", ce->name); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invocation of %s's constructor failed", ce->name->val); zval_dtor(return_value); RETURN_NULL(); } if (retval_ptr) { - zval_ptr_dtor(&retval_ptr); + zval_ptr_dtor(retval_ptr); } if (params) { efree(params); } } else if (argc) { - zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Class %s does not have a constructor, so you cannot pass any constructor arguments", ce->name); + zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Class %s does not have a constructor, so you cannot pass any constructor arguments", ce->name->val); } } /* }}} */ @@ -4413,10 +4372,10 @@ ZEND_METHOD(reflection_class, getInterfaces) zend_uint i; for (i=0; i < ce->num_interfaces; i++) { - zval *interface; - ALLOC_ZVAL(interface); - zend_reflection_class_factory(ce->interfaces[i], interface TSRMLS_CC); - add_assoc_zval_ex(return_value, ce->interfaces[i]->name, ce->interfaces[i]->name_length + 1, interface); + zval interface; + zend_reflection_class_factory(ce->interfaces[i], &interface TSRMLS_CC); +//??? + add_assoc_zval_ex(return_value, ce->interfaces[i]->name->val, ce->interfaces[i]->name->len, &interface); } } } @@ -4439,7 +4398,7 @@ ZEND_METHOD(reflection_class, getInterfaceNames) array_init(return_value); for (i=0; i < ce->num_interfaces; i++) { - add_next_index_stringl(return_value, ce->interfaces[i]->name, ce->interfaces[i]->name_length, 1); + add_next_index_str(return_value, STR_COPY(ce->interfaces[i]->name)); } } /* }}} */ @@ -4460,10 +4419,10 @@ ZEND_METHOD(reflection_class, getTraits) array_init(return_value); for (i=0; i < ce->num_traits; i++) { - zval *trait; - ALLOC_ZVAL(trait); - zend_reflection_class_factory(ce->traits[i], trait TSRMLS_CC); - add_assoc_zval_ex(return_value, ce->traits[i]->name, ce->traits[i]->name_length + 1, trait); + zval trait; + zend_reflection_class_factory(ce->traits[i], &trait TSRMLS_CC); +//??? + add_assoc_zval_ex(return_value, ce->traits[i]->name->val, ce->traits[i]->name->len, &trait); } } /* }}} */ @@ -4484,7 +4443,7 @@ ZEND_METHOD(reflection_class, getTraitNames) array_init(return_value); for (i=0; i < ce->num_traits; i++) { - add_next_index_stringl(return_value, ce->traits[i]->name, ce->traits[i]->name_length, 1); + add_next_index_str(return_value, STR_COPY(ce->traits[i]->name)); } } /* }}} */ @@ -4511,8 +4470,9 @@ ZEND_METHOD(reflection_class, getTraitAliases) zend_trait_method_reference *cur_ref = ce->trait_aliases[i]->trait_method; if (ce->trait_aliases[i]->alias) { - method_name_len = spprintf(&method_name, 0, "%s::%s", cur_ref->ce->name, cur_ref->method_name); - add_assoc_stringl_ex(return_value, ce->trait_aliases[i]->alias, ce->trait_aliases[i]->alias_len + 1, method_name, method_name_len, 0); + method_name_len = spprintf(&method_name, 0, "%s::%s", cur_ref->ce->name->val, cur_ref->method_name->val); +//??? + add_assoc_stringl_ex(return_value, ce->trait_aliases[i]->alias->val, ce->trait_aliases[i]->alias->len, method_name, method_name_len, 0); } i++; } @@ -4545,7 +4505,7 @@ ZEND_METHOD(reflection_class, getParentClass) ZEND_METHOD(reflection_class, isSubclassOf) { reflection_object *intern, *argument; - zend_class_entry *ce, **pce, *class_ce; + zend_class_entry *ce, *class_ce; zval *class_name; METHOD_NOTSTATIC(reflection_class_ptr); @@ -4557,16 +4517,15 @@ ZEND_METHOD(reflection_class, isSubclassOf) switch(class_name->type) { case IS_STRING: - if (zend_lookup_class(Z_STRVAL_P(class_name), Z_STRLEN_P(class_name), &pce TSRMLS_CC) == FAILURE) { + if ((class_ce = zend_lookup_class(Z_STR_P(class_name) TSRMLS_CC)) == NULL) { zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Class %s does not exist", Z_STRVAL_P(class_name)); return; } - class_ce = *pce; break; case IS_OBJECT: if (instanceof_function(Z_OBJCE_P(class_name), reflection_class_ptr TSRMLS_CC)) { - argument = (reflection_object *) zend_object_store_get_object(class_name TSRMLS_CC); + argument = (reflection_object *) Z_OBJ_P(class_name); if (argument == NULL || argument->ptr == NULL) { php_error_docref(NULL TSRMLS_CC, E_ERROR, "Internal error: Failed to retrieve the argument's reflection object"); /* Bails out */ @@ -4590,7 +4549,7 @@ ZEND_METHOD(reflection_class, isSubclassOf) ZEND_METHOD(reflection_class, implementsInterface) { reflection_object *intern, *argument; - zend_class_entry *ce, *interface_ce, **pce; + zend_class_entry *ce, *interface_ce; zval *interface; METHOD_NOTSTATIC(reflection_class_ptr); @@ -4602,16 +4561,15 @@ ZEND_METHOD(reflection_class, implementsInterface) switch(interface->type) { case IS_STRING: - if (zend_lookup_class(Z_STRVAL_P(interface), Z_STRLEN_P(interface), &pce TSRMLS_CC) == FAILURE) { + if ((interface_ce = zend_lookup_class(Z_STR_P(interface) TSRMLS_CC)) == NULL) { zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Interface %s does not exist", Z_STRVAL_P(interface)); return; } - interface_ce = *pce; break; case IS_OBJECT: if (instanceof_function(Z_OBJCE_P(interface), reflection_class_ptr TSRMLS_CC)) { - argument = (reflection_object *) zend_object_store_get_object(interface TSRMLS_CC); + argument = (reflection_object *) Z_OBJ_P(interface); if (argument == NULL || argument->ptr == NULL) { php_error_docref(NULL TSRMLS_CC, E_ERROR, "Internal error: Failed to retrieve the argument's reflection object"); /* Bails out */ @@ -4688,7 +4646,7 @@ ZEND_METHOD(reflection_class, getExtensionName) GET_REFLECTION_OBJECT_PTR(ce); if ((ce->type == ZEND_INTERNAL_CLASS) && ce->info.internal.module) { - RETURN_STRING(ce->info.internal.module->name, 1); + RETURN_STRING(ce->info.internal.module->name); } else { RETURN_FALSE; } @@ -4699,18 +4657,18 @@ ZEND_METHOD(reflection_class, getExtensionName) Returns whether this class is defined in namespace */ ZEND_METHOD(reflection_class, inNamespace) { - zval **name; + zval *name; const char *backslash; if (zend_parse_parameters_none() == FAILURE) { return; } - if (zend_hash_find(Z_OBJPROP_P(getThis()), "name", sizeof("name"), (void **) &name) == FAILURE) { + if ((name = zend_hash_str_find(Z_OBJPROP_P(getThis()), "name", sizeof("name")-1)) == NULL) { RETURN_FALSE; } - if (Z_TYPE_PP(name) == IS_STRING - && (backslash = zend_memrchr(Z_STRVAL_PP(name), '\\', Z_STRLEN_PP(name))) - && backslash > Z_STRVAL_PP(name)) + if (Z_TYPE_P(name) == IS_STRING + && (backslash = zend_memrchr(Z_STRVAL_P(name), '\\', Z_STRLEN_P(name))) + && backslash > Z_STRVAL_P(name)) { RETURN_TRUE; } @@ -4722,20 +4680,20 @@ ZEND_METHOD(reflection_class, inNamespace) Returns the name of namespace where this class is defined */ ZEND_METHOD(reflection_class, getNamespaceName) { - zval **name; + zval *name; const char *backslash; if (zend_parse_parameters_none() == FAILURE) { return; } - if (zend_hash_find(Z_OBJPROP_P(getThis()), "name", sizeof("name"), (void **) &name) == FAILURE) { + if ((name = zend_hash_str_find(Z_OBJPROP_P(getThis()), "name", sizeof("name")-1)) == NULL) { RETURN_FALSE; } - if (Z_TYPE_PP(name) == IS_STRING - && (backslash = zend_memrchr(Z_STRVAL_PP(name), '\\', Z_STRLEN_PP(name))) - && backslash > Z_STRVAL_PP(name)) + if (Z_TYPE_P(name) == IS_STRING + && (backslash = zend_memrchr(Z_STRVAL_P(name), '\\', Z_STRLEN_P(name))) + && backslash > Z_STRVAL_P(name)) { - RETURN_STRINGL(Z_STRVAL_PP(name), backslash - Z_STRVAL_PP(name), 1); + RETURN_STRINGL(Z_STRVAL_P(name), backslash - Z_STRVAL_P(name)); } RETURN_EMPTY_STRING(); } @@ -4745,22 +4703,22 @@ ZEND_METHOD(reflection_class, getNamespaceName) Returns the short name of the class (without namespace part) */ ZEND_METHOD(reflection_class, getShortName) { - zval **name; + zval *name; const char *backslash; if (zend_parse_parameters_none() == FAILURE) { return; } - if (zend_hash_find(Z_OBJPROP_P(getThis()), "name", sizeof("name"), (void **) &name) == FAILURE) { + if ((name = zend_hash_str_find(Z_OBJPROP_P(getThis()), "name", sizeof("name")-1)) == NULL) { RETURN_FALSE; } - if (Z_TYPE_PP(name) == IS_STRING - && (backslash = zend_memrchr(Z_STRVAL_PP(name), '\\', Z_STRLEN_PP(name))) - && backslash > Z_STRVAL_PP(name)) + if (Z_TYPE_P(name) == IS_STRING + && (backslash = zend_memrchr(Z_STRVAL_P(name), '\\', Z_STRLEN_P(name))) + && backslash > Z_STRVAL_P(name)) { - RETURN_STRINGL(backslash + 1, Z_STRLEN_PP(name) - (backslash - Z_STRVAL_PP(name) + 1), 1); + RETURN_STRINGL(backslash + 1, Z_STRLEN_P(name) - (backslash - Z_STRVAL_P(name) + 1)); } - RETURN_ZVAL(*name, 1, 0); + RETURN_ZVAL(name, 1, 0); } /* }}} */ @@ -4792,13 +4750,12 @@ ZEND_METHOD(reflection_property, export) Constructor. Throws an Exception in case the given property does not exist */ ZEND_METHOD(reflection_property, __construct) { - zval *propname, *classname; + zval propname, cname, *classname; char *name_str; const char *class_name, *prop_name; int name_len, dynam_prop = 0; zval *object; reflection_object *intern; - zend_class_entry **pce; zend_class_entry *ce; zend_property_info *property_info = NULL; property_reference *reference; @@ -4808,7 +4765,7 @@ ZEND_METHOD(reflection_property, __construct) } object = getThis(); - intern = (reflection_object *) zend_object_store_get_object(object TSRMLS_CC); + intern = (reflection_object *) Z_OBJ_P(object); if (intern == NULL) { return; } @@ -4816,12 +4773,11 @@ ZEND_METHOD(reflection_property, __construct) /* Find the class entry */ switch (Z_TYPE_P(classname)) { case IS_STRING: - if (zend_lookup_class(Z_STRVAL_P(classname), Z_STRLEN_P(classname), &pce TSRMLS_CC) == FAILURE) { + if ((ce = zend_lookup_class(Z_STR_P(classname) TSRMLS_CC)) == NULL) { zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Class %s does not exist", Z_STRVAL_P(classname)); return; } - ce = *pce; break; case IS_OBJECT: @@ -4833,10 +4789,10 @@ ZEND_METHOD(reflection_property, __construct) /* returns out of this function */ } - if (zend_hash_find(&ce->properties_info, name_str, name_len + 1, (void **) &property_info) == FAILURE || (property_info->flags & ZEND_ACC_SHADOW)) { + if ((property_info = zend_hash_str_find_ptr(&ce->properties_info, name_str, name_len)) == NULL || (property_info->flags & ZEND_ACC_SHADOW)) { /* Check for dynamic properties */ if (property_info == NULL && Z_TYPE_P(classname) == IS_OBJECT && Z_OBJ_HT_P(classname)->get_properties) { - if (zend_hash_exists(Z_OBJ_HT_P(classname)->get_properties(classname TSRMLS_CC), name_str, name_len+1)) { + if (zend_hash_str_exists(Z_OBJ_HT_P(classname)->get_properties(classname TSRMLS_CC), name_str, name_len)) { dynam_prop = 1; } } @@ -4851,33 +4807,28 @@ ZEND_METHOD(reflection_property, __construct) zend_class_entry *tmp_ce = ce; zend_property_info *tmp_info; - while (tmp_ce && zend_hash_find(&tmp_ce->properties_info, name_str, name_len + 1, (void **) &tmp_info) != SUCCESS) { + while (tmp_ce && (tmp_info = zend_hash_str_find_ptr(&tmp_ce->properties_info, name_str, name_len)) == NULL) { ce = tmp_ce; property_info = tmp_info; tmp_ce = tmp_ce->parent; } } - MAKE_STD_ZVAL(classname); - MAKE_STD_ZVAL(propname); - if (dynam_prop == 0) { - zend_unmangle_property_name(property_info->name, property_info->name_length, &class_name, &prop_name); - ZVAL_STRINGL(classname, property_info->ce->name, property_info->ce->name_length, 1); - ZVAL_STRING(propname, prop_name, 1); + zend_unmangle_property_name(property_info->name->val, property_info->name->len, &class_name, &prop_name); + ZVAL_STR(&cname, STR_COPY(property_info->ce->name)); + ZVAL_STRING(&propname, prop_name); } else { - ZVAL_STRINGL(classname, ce->name, ce->name_length, 1); - ZVAL_STRINGL(propname, name_str, name_len, 1); + ZVAL_STR(&cname, STR_COPY(ce->name)); + ZVAL_STRINGL(&propname, name_str, name_len); } - reflection_update_property(object, "class", classname); - reflection_update_property(object, "name", propname); + reflection_update_property(object, "class", &cname); + reflection_update_property(object, "name", &propname); reference = (property_reference*) emalloc(sizeof(property_reference)); if (dynam_prop) { reference->prop.flags = ZEND_ACC_IMPLICIT_PUBLIC; - reference->prop.name = Z_STRVAL_P(propname); - reference->prop.name_length = Z_STRLEN_P(propname); - reference->prop.h = zend_get_hash_value(name_str, name_len+1); + reference->prop.name = Z_STR(propname); reference->prop.doc_comment = NULL; reference->prop.ce = ce; } else { @@ -4905,7 +4856,8 @@ ZEND_METHOD(reflection_property, __toString) GET_REFLECTION_OBJECT_PTR(ref); string_init(&str); _property_string(&str, &ref->prop, NULL, "" TSRMLS_CC); - RETURN_STRINGL(str.string, str.len - 1, 0); +//??? RETURN_STRINGL(str.string, str.len - 1, 0); + RETURN_STRINGL(str.string, str.len - 1); } /* }}} */ @@ -4916,7 +4868,7 @@ ZEND_METHOD(reflection_property, getName) if (zend_parse_parameters_none() == FAILURE) { return; } - _default_get_entry(getThis(), "name", sizeof("name"), return_value TSRMLS_CC); + _default_get_entry(getThis(), "name", sizeof("name")-1, return_value TSRMLS_CC); } /* }}} */ @@ -5002,7 +4954,7 @@ ZEND_METHOD(reflection_property, getValue) GET_REFLECTION_OBJECT_PTR(ref); if (!(ref->prop.flags & (ZEND_ACC_PUBLIC | ZEND_ACC_IMPLICIT_PUBLIC)) && intern->ignore_visibility == 0) { - _default_get_entry(getThis(), "name", sizeof("name"), &name TSRMLS_CC); + _default_get_entry(getThis(), "name", sizeof("name")-1, &name TSRMLS_CC); zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Cannot access non-public member %s::%s", intern->ce->name, Z_STRVAL(name)); zval_dtor(&name); @@ -5011,25 +4963,25 @@ ZEND_METHOD(reflection_property, getValue) if ((ref->prop.flags & ZEND_ACC_STATIC)) { zend_update_class_constants(intern->ce TSRMLS_CC); - if (!CE_STATIC_MEMBERS(intern->ce)[ref->prop.offset]) { - php_error_docref(NULL TSRMLS_CC, E_ERROR, "Internal error: Could not find the property %s::%s", intern->ce->name, ref->prop.name); + if (Z_TYPE(CE_STATIC_MEMBERS(intern->ce)[ref->prop.offset]) == IS_UNDEF) { + php_error_docref(NULL TSRMLS_CC, E_ERROR, "Internal error: Could not find the property %s::%s", intern->ce->name->val, ref->prop.name->val); /* Bails out */ } - *return_value= *CE_STATIC_MEMBERS(intern->ce)[ref->prop.offset]; - zval_copy_ctor(return_value); - INIT_PZVAL(return_value); + ZVAL_DUP(return_value, &CE_STATIC_MEMBERS(intern->ce)[ref->prop.offset]); +//??? INIT_PZVAL(return_value); } else { const char *class_name, *prop_name; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &object) == FAILURE) { return; } - zend_unmangle_property_name(ref->prop.name, ref->prop.name_length, &class_name, &prop_name); + 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); - MAKE_COPY_ZVAL(&member_p, return_value); - if (member_p != EG(uninitialized_zval_ptr)) { - zval_add_ref(&member_p); - zval_ptr_dtor(&member_p); + ZVAL_DUP(return_value, member_p); +//??? + if (member_p != &EG(uninitialized_zval)) { + zval_add_ref(member_p); + zval_ptr_dtor(member_p); } } } @@ -5041,7 +4993,7 @@ ZEND_METHOD(reflection_property, setValue) { reflection_object *intern; property_reference *ref; - zval **variable_ptr; + zval *variable_ptr; zval *object, name; zval *value; zval *tmp; @@ -5050,7 +5002,7 @@ ZEND_METHOD(reflection_property, setValue) GET_REFLECTION_OBJECT_PTR(ref); if (!(ref->prop.flags & ZEND_ACC_PUBLIC) && intern->ignore_visibility == 0) { - _default_get_entry(getThis(), "name", sizeof("name"), &name TSRMLS_CC); + _default_get_entry(getThis(), "name", sizeof("name")-1, &name TSRMLS_CC); zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Cannot access non-public member %s::%s", intern->ce->name, Z_STRVAL(name)); zval_dtor(&name); @@ -5065,31 +5017,33 @@ ZEND_METHOD(reflection_property, setValue) } zend_update_class_constants(intern->ce TSRMLS_CC); - if (!CE_STATIC_MEMBERS(intern->ce)[ref->prop.offset]) { - php_error_docref(NULL TSRMLS_CC, E_ERROR, "Internal error: Could not find the property %s::%s", intern->ce->name, ref->prop.name); + if (Z_TYPE(CE_STATIC_MEMBERS(intern->ce)[ref->prop.offset]) == IS_UNDEF) { + php_error_docref(NULL TSRMLS_CC, E_ERROR, "Internal error: Could not find the property %s::%s", intern->ce->name->val, ref->prop.name->val); /* Bails out */ } variable_ptr = &CE_STATIC_MEMBERS(intern->ce)[ref->prop.offset]; - if (*variable_ptr != value) { - if (PZVAL_IS_REF(*variable_ptr)) { - zval garbage = **variable_ptr; /* old value should be destroyed */ + if (variable_ptr != value) { + if (Z_ISREF_P(variable_ptr)) { + zval garbage; + + ZVAL_COPY_VALUE(&garbage, variable_ptr); /* old value should be destroyed */ /* To check: can't *variable_ptr be some system variable like error_zval here? */ - Z_TYPE_PP(variable_ptr) = Z_TYPE_P(value); - (*variable_ptr)->value = value->value; + ZVAL_COPY_VALUE(variable_ptr, value); if (Z_REFCOUNT_P(value) > 0) { - zval_copy_ctor(*variable_ptr); + zval_copy_ctor(variable_ptr); } zval_dtor(&garbage); } else { - zval *garbage = *variable_ptr; - + zval garbage; + + ZVAL_COPY_VALUE(&garbage, variable_ptr); /* if we assign referenced variable, we should separate it */ Z_ADDREF_P(value); - if (PZVAL_IS_REF(value)) { - SEPARATE_ZVAL(&value); + if (Z_ISREF_P(value)) { + SEPARATE_ZVAL(value); } - *variable_ptr = value; + ZVAL_COPY_VALUE(variable_ptr, value); zval_ptr_dtor(&garbage); } } @@ -5099,7 +5053,7 @@ ZEND_METHOD(reflection_property, setValue) if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "oz", &object, &value) == FAILURE) { return; } - zend_unmangle_property_name(ref->prop.name, ref->prop.name_length, &class_name, &prop_name); + zend_unmangle_property_name(ref->prop.name->val, ref->prop.name->len, &class_name, &prop_name); zend_update_property(ref->ce, object, prop_name, strlen(prop_name), value TSRMLS_CC); } } @@ -5121,13 +5075,13 @@ ZEND_METHOD(reflection_property, getDeclaringClass) } GET_REFLECTION_OBJECT_PTR(ref); - if (zend_unmangle_property_name(ref->prop.name, ref->prop.name_length, &class_name, &prop_name) != SUCCESS) { + if (zend_unmangle_property_name(ref->prop.name->val, ref->prop.name->len, &class_name, &prop_name) != SUCCESS) { RETURN_FALSE; } prop_name_len = strlen(prop_name); ce = tmp_ce = ref->ce; - while (tmp_ce && zend_hash_find(&tmp_ce->properties_info, prop_name, prop_name_len + 1, (void **) &tmp_info) == SUCCESS) { + while (tmp_ce && (tmp_info = zend_hash_str_find_ptr(&tmp_ce->properties_info, prop_name, prop_name_len)) != NULL) { if (tmp_info->flags & ZEND_ACC_PRIVATE || tmp_info->flags & ZEND_ACC_SHADOW) { /* it's a private property, so it can't be inherited */ break; @@ -5156,7 +5110,7 @@ ZEND_METHOD(reflection_property, getDocComment) } GET_REFLECTION_OBJECT_PTR(ref); if (ref->prop.doc_comment) { - RETURN_STRINGL(ref->prop.doc_comment, ref->prop.doc_comment_len, 1); + RETURN_STR(STR_COPY(ref->prop.doc_comment)); } RETURN_FALSE; } @@ -5173,7 +5127,7 @@ ZEND_METHOD(reflection_property, setAccessible) return; } - intern = (reflection_object *) zend_object_store_get_object(getThis() TSRMLS_CC); + intern = (reflection_object *) Z_OBJ_P(getThis()); if (intern == NULL) { return; @@ -5195,7 +5149,7 @@ ZEND_METHOD(reflection_extension, export) Constructor. Throws an Exception in case the given extension does not exist */ ZEND_METHOD(reflection_extension, __construct) { - zval *name; + zval name; zval *object; char *lcname; reflection_object *intern; @@ -5209,22 +5163,21 @@ ZEND_METHOD(reflection_extension, __construct) } object = getThis(); - intern = (reflection_object *) zend_object_store_get_object(object TSRMLS_CC); + intern = (reflection_object *) Z_OBJ_P(object); if (intern == NULL) { return; } lcname = do_alloca(name_len + 1, use_heap); zend_str_tolower_copy(lcname, name_str, name_len); - if (zend_hash_find(&module_registry, lcname, name_len + 1, (void **)&module) == FAILURE) { + if ((module = zend_hash_str_find_ptr(&module_registry, lcname, name_len)) == NULL) { free_alloca(lcname, use_heap); zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Extension %s does not exist", name_str); return; } free_alloca(lcname, use_heap); - MAKE_STD_ZVAL(name); - ZVAL_STRING(name, module->name, 1); - reflection_update_property( object, "name", name); + ZVAL_STRING(&name, module->name); + reflection_update_property(object, "name", &name); intern->ptr = module; intern->ref_type = REF_TYPE_OTHER; intern->ce = NULL; @@ -5245,7 +5198,8 @@ ZEND_METHOD(reflection_extension, __toString) GET_REFLECTION_OBJECT_PTR(module); string_init(&str); _extension_string(&str, module, "" TSRMLS_CC); - RETURN_STRINGL(str.string, str.len - 1, 0); +//??? RETURN_STRINGL(str.string, str.len - 1, 0); + RETURN_STRINGL(str.string, str.len - 1); } /* }}} */ @@ -5256,7 +5210,7 @@ ZEND_METHOD(reflection_extension, getName) if (zend_parse_parameters_none() == FAILURE) { return; } - _default_get_entry(getThis(), "name", sizeof("name"), return_value TSRMLS_CC); + _default_get_entry(getThis(), "name", sizeof("name")-1, return_value TSRMLS_CC); } /* }}} */ @@ -5276,7 +5230,7 @@ ZEND_METHOD(reflection_extension, getVersion) if (module->version == NO_VERSION_YET) { RETURN_NULL(); } else { - RETURN_STRING(module->version, 1); + RETURN_STRING(module->version); } } /* }}} */ @@ -5288,7 +5242,7 @@ ZEND_METHOD(reflection_extension, getFunctions) reflection_object *intern; zend_module_entry *module; HashPosition iterator; - zval *function; + zval function; zend_function *fptr; if (zend_parse_parameters_none() == FAILURE) { @@ -5298,12 +5252,12 @@ ZEND_METHOD(reflection_extension, getFunctions) array_init(return_value); zend_hash_internal_pointer_reset_ex(CG(function_table), &iterator); - while (zend_hash_get_current_data_ex(CG(function_table), (void **) &fptr, &iterator) == SUCCESS) { + while ((fptr = zend_hash_get_current_data_ptr_ex(CG(function_table), &iterator)) != NULL) { if (fptr->common.type==ZEND_INTERNAL_FUNCTION && fptr->internal_function.module == module) { - ALLOC_ZVAL(function); - reflection_function_factory(fptr, NULL, function TSRMLS_CC); - add_assoc_zval(return_value, fptr->common.function_name, function); + reflection_function_factory(fptr, NULL, &function TSRMLS_CC); +//??? + add_assoc_zval(return_value, fptr->common.function_name->val, &function); } zend_hash_move_forward_ex(CG(function_table), &iterator); } @@ -5312,16 +5266,15 @@ ZEND_METHOD(reflection_extension, getFunctions) static int _addconstant(zend_constant *constant TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key) /* {{{ */ { - zval *const_val; + zval const_val; zval *retval = va_arg(args, zval*); int number = va_arg(args, int); if (number == constant->module_number) { - ALLOC_ZVAL(const_val); - *const_val = constant->value; - zval_copy_ctor(const_val); - INIT_PZVAL(const_val); - add_assoc_zval_ex(retval, constant->name, constant->name_len, const_val); + ZVAL_DUP(&const_val, &constant->value); +//??? INIT_PZVAL(const_val); +//??? + add_assoc_zval_ex(retval, constant->name->val, constant->name->len, &const_val); } return 0; } @@ -5381,17 +5334,17 @@ ZEND_METHOD(reflection_extension, getINIEntries) /* {{{ add_extension_class */ static int add_extension_class(zend_class_entry **pce TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key) { - zval *class_array = va_arg(args, zval*), *zclass; + zval *class_array = va_arg(args, zval*), zclass; struct _zend_module_entry *module = va_arg(args, struct _zend_module_entry*); int add_reflection_class = va_arg(args, int); if (((*pce)->type == ZEND_INTERNAL_CLASS) && (*pce)->info.internal.module && !strcasecmp((*pce)->info.internal.module->name, module->name)) { if (add_reflection_class) { - ALLOC_ZVAL(zclass); - zend_reflection_class_factory(*pce, zclass TSRMLS_CC); - add_assoc_zval_ex(class_array, (*pce)->name, (*pce)->name_length + 1, zclass); + zend_reflection_class_factory(*pce, &zclass TSRMLS_CC); +//??? + add_assoc_zval_ex(class_array, (*pce)->name->val, (*pce)->name->len, &zclass); } else { - add_next_index_stringl(class_array, (*pce)->name, (*pce)->name_length, 1); + add_next_index_str(class_array, STR_COPY((*pce)->name)); } } return ZEND_HASH_APPLY_KEEP; @@ -5546,7 +5499,7 @@ ZEND_METHOD(reflection_zend_extension, export) Constructor. Throws an Exception in case the given Zend extension does not exist */ ZEND_METHOD(reflection_zend_extension, __construct) { - zval *name; + zval name; zval *object; reflection_object *intern; zend_extension *extension; @@ -5558,7 +5511,7 @@ ZEND_METHOD(reflection_zend_extension, __construct) } object = getThis(); - intern = (reflection_object *) zend_object_store_get_object(object TSRMLS_CC); + intern = (reflection_object *) Z_OBJ_P(object); if (intern == NULL) { return; } @@ -5569,9 +5522,8 @@ ZEND_METHOD(reflection_zend_extension, __construct) "Zend Extension %s does not exist", name_str); return; } - MAKE_STD_ZVAL(name); - ZVAL_STRING(name, extension->name, 1); - reflection_update_property(object, "name", name); + ZVAL_STRING(&name, extension->name); + reflection_update_property(object, "name", &name); intern->ptr = extension; intern->ref_type = REF_TYPE_OTHER; intern->ce = NULL; @@ -5592,7 +5544,8 @@ ZEND_METHOD(reflection_zend_extension, __toString) GET_REFLECTION_OBJECT_PTR(extension); string_init(&str); _zend_extension_string(&str, extension, "" TSRMLS_CC); - RETURN_STRINGL(str.string, str.len - 1, 0); +//??? RETURN_STRINGL(str.string, str.len - 1, 0); + RETURN_STRINGL(str.string, str.len - 1); } /* }}} */ @@ -5608,7 +5561,7 @@ ZEND_METHOD(reflection_zend_extension, getName) } GET_REFLECTION_OBJECT_PTR(extension); - RETURN_STRING(extension->name, 1); + RETURN_STRING(extension->name); } /* }}} */ @@ -5624,7 +5577,11 @@ ZEND_METHOD(reflection_zend_extension, getVersion) } GET_REFLECTION_OBJECT_PTR(extension); - RETURN_STRING(extension->version ? extension->version : "", 1); + if (extension->version) { + RETURN_STRING(extension->version); + } else { + RETURN_EMPTY_STRING(); + } } /* }}} */ @@ -5640,7 +5597,11 @@ ZEND_METHOD(reflection_zend_extension, getAuthor) } GET_REFLECTION_OBJECT_PTR(extension); - RETURN_STRING(extension->author ? extension->author : "", 1); + if (extension->author) { + RETURN_STRING(extension->author); + } else { + RETURN_EMPTY_STRING(); + } } /* }}} */ @@ -5656,7 +5617,11 @@ ZEND_METHOD(reflection_zend_extension, getURL) } GET_REFLECTION_OBJECT_PTR(extension); - RETURN_STRING(extension->URL ? extension->URL : "", 1); + if (extension->URL) { + RETURN_STRING(extension->URL); + } else { + RETURN_EMPTY_STRING(); + } } /* }}} */ @@ -5672,7 +5637,11 @@ ZEND_METHOD(reflection_zend_extension, getCopyright) } GET_REFLECTION_OBJECT_PTR(extension); - RETURN_STRING(extension->copyright ? extension->copyright : "", 1); + if (extension->copyright) { + RETURN_STRING(extension->copyright); + } else { + RETURN_EMPTY_STRING(); + } } /* }}} */ @@ -6095,7 +6064,7 @@ static zend_object_handlers *zend_std_obj_handlers; static void _reflection_write_property(zval *object, zval *member, zval *value, const zend_literal *key TSRMLS_DC) { if ((Z_TYPE_P(member) == IS_STRING) - && zend_hash_exists(&Z_OBJCE_P(object)->properties_info, Z_STRVAL_P(member), Z_STRLEN_P(member)+1) + && zend_hash_exists(&Z_OBJCE_P(object)->properties_info, Z_STR_P(member)) && ((Z_STRLEN_P(member) == sizeof("name") - 1 && !memcmp(Z_STRVAL_P(member), "name", sizeof("name"))) || (Z_STRLEN_P(member) == sizeof("class") - 1 && !memcmp(Z_STRVAL_P(member), "class", sizeof("class"))))) { @@ -6115,11 +6084,12 @@ PHP_MINIT_FUNCTION(reflection) /* {{{ */ zend_std_obj_handlers = zend_get_std_object_handlers(); memcpy(&reflection_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); + reflection_object_handlers.free_obj = reflection_free_objects_storage; reflection_object_handlers.clone_obj = NULL; reflection_object_handlers.write_property = _reflection_write_property; INIT_CLASS_ENTRY(_reflection_entry, "ReflectionException", reflection_exception_functions); - reflection_exception_ptr = zend_register_internal_class_ex(&_reflection_entry, zend_exception_get_default(TSRMLS_C), NULL TSRMLS_CC); + reflection_exception_ptr = zend_register_internal_class_ex(&_reflection_entry, zend_exception_get_default(TSRMLS_C) TSRMLS_CC); INIT_CLASS_ENTRY(_reflection_entry, "Reflection", reflection_functions); reflection_ptr = zend_register_internal_class(&_reflection_entry TSRMLS_CC); @@ -6135,7 +6105,7 @@ PHP_MINIT_FUNCTION(reflection) /* {{{ */ INIT_CLASS_ENTRY(_reflection_entry, "ReflectionFunction", reflection_function_functions); _reflection_entry.create_object = reflection_objects_new; - reflection_function_ptr = zend_register_internal_class_ex(&_reflection_entry, reflection_function_abstract_ptr, NULL TSRMLS_CC); + reflection_function_ptr = zend_register_internal_class_ex(&_reflection_entry, reflection_function_abstract_ptr TSRMLS_CC); zend_declare_property_string(reflection_function_ptr, "name", sizeof("name")-1, "", ZEND_ACC_PUBLIC TSRMLS_CC); REGISTER_REFLECTION_CLASS_CONST_LONG(function, "IS_DEPRECATED", ZEND_ACC_DEPRECATED); @@ -6148,7 +6118,7 @@ PHP_MINIT_FUNCTION(reflection) /* {{{ */ INIT_CLASS_ENTRY(_reflection_entry, "ReflectionMethod", reflection_method_functions); _reflection_entry.create_object = reflection_objects_new; - reflection_method_ptr = zend_register_internal_class_ex(&_reflection_entry, reflection_function_abstract_ptr, NULL TSRMLS_CC); + reflection_method_ptr = zend_register_internal_class_ex(&_reflection_entry, reflection_function_abstract_ptr TSRMLS_CC); zend_declare_property_string(reflection_method_ptr, "name", sizeof("name")-1, "", ZEND_ACC_PUBLIC TSRMLS_CC); zend_declare_property_string(reflection_method_ptr, "class", sizeof("class")-1, "", ZEND_ACC_PUBLIC TSRMLS_CC); @@ -6171,7 +6141,7 @@ PHP_MINIT_FUNCTION(reflection) /* {{{ */ INIT_CLASS_ENTRY(_reflection_entry, "ReflectionObject", reflection_object_functions); _reflection_entry.create_object = reflection_objects_new; - reflection_object_ptr = zend_register_internal_class_ex(&_reflection_entry, reflection_class_ptr, NULL TSRMLS_CC); + reflection_object_ptr = zend_register_internal_class_ex(&_reflection_entry, reflection_class_ptr TSRMLS_CC); INIT_CLASS_ENTRY(_reflection_entry, "ReflectionProperty", reflection_property_functions); _reflection_entry.create_object = reflection_objects_new; -- cgit v1.2.1 From c077742b2a5c6d2a640ce64e76b0edc95ed5c74c Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Tue, 25 Feb 2014 17:03:48 +0400 Subject: Fixed reflection object destruction --- ext/reflection/php_reflection.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'ext/reflection/php_reflection.c') diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index e566711c1a..5219053ec3 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -204,6 +204,7 @@ typedef enum { /* Struct for reflection objects */ typedef struct { zend_object zo; + zval dummy; /* holder for the second property */ void *ptr; reflection_type_t ref_type; zval obj; @@ -310,7 +311,7 @@ static void reflection_free_objects_storage(zend_object *object TSRMLS_DC) /* {{ } intern->ptr = NULL; zval_ptr_dtor(&intern->obj); -//??? zend_objects_free_object_storage(object TSRMLS_CC); + zend_object_free(object TSRMLS_CC); } /* }}} */ @@ -1222,7 +1223,7 @@ static void reflection_parameter_factory(zend_function *fptr, zval *closure_obje zval name; if (closure_object) { - Z_ADDREF_P(closure_object); + if (Z_REFCOUNTED_P(closure_object)) Z_ADDREF_P(closure_object); } if (arg_info->name) { ZVAL_STRINGL(&name, arg_info->name, arg_info->name_len); @@ -1616,7 +1617,11 @@ ZEND_METHOD(reflection_function, __construct) reflection_update_property(object, "name", &name); intern->ptr = fptr; intern->ref_type = REF_TYPE_FUNCTION; - ZVAL_COPY_VALUE(&intern->obj, closure); + if (closure) { + ZVAL_COPY_VALUE(&intern->obj, closure); + } else { + ZVAL_UNDEF(&intern->obj); + } intern->ce = NULL; } /* }}} */ -- cgit v1.2.1 From 4a1ecf0e8b04363901c92aea55a203fc73a24b95 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Wed, 26 Feb 2014 02:02:57 +0400 Subject: Reflection related fixes --- ext/reflection/php_reflection.c | 172 +++++++++++++++++++--------------------- 1 file changed, 83 insertions(+), 89 deletions(-) (limited to 'ext/reflection/php_reflection.c') diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 5219053ec3..e82e13248e 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -112,17 +112,16 @@ ZEND_DECLARE_MODULE_GLOBALS(reflection) /* {{{ Smart string functions */ typedef struct _string { - char *string; - int len; + zend_string *buf; int alloced; } string; static void string_init(string *str) { - str->string = (char *) emalloc(1024); - str->len = 1; + str->buf= STR_ALLOC(1024, 0); str->alloced = 1024; - *str->string = '\0'; + str->buf->val[0] = '\0'; + str->buf->len = 0; } static string *string_printf(string *str, const char *format, ...) @@ -134,13 +133,15 @@ static string *string_printf(string *str, const char *format, ...) va_start(arg, format); len = zend_vspprintf(&s_tmp, 0, format, arg); if (len) { - register int nlen = (str->len + len + (1024 - 1)) & ~(1024 - 1); + register int nlen = (str->buf->len + 1 + len + (1024 - 1)) & ~(1024 - 1); if (str->alloced < nlen) { + int old_len = str->buf->len; str->alloced = nlen; - str->string = erealloc(str->string, str->alloced); + str->buf = STR_REALLOC(str->buf, str->alloced, 0); + str->buf->len = old_len; } - memcpy(str->string + str->len - 1, s_tmp, len + 1); - str->len += len; + memcpy(str->buf->val + str->buf->len, s_tmp, len + 1); + str->buf->len += len; } efree(s_tmp); va_end(arg); @@ -149,31 +150,32 @@ static string *string_printf(string *str, const char *format, ...) static string *string_write(string *str, char *buf, int len) { - register int nlen = (str->len + len + (1024 - 1)) & ~(1024 - 1); + register int nlen = (str->buf->len + 1 + len + (1024 - 1)) & ~(1024 - 1); if (str->alloced < nlen) { + int old_len = str->buf->len; str->alloced = nlen; - str->string = erealloc(str->string, str->alloced); + str->buf = STR_REALLOC(str->buf, str->alloced, 0); + str->buf->len = old_len; } - memcpy(str->string + str->len - 1, buf, len); - str->len += len; - str->string[str->len - 1] = '\0'; + memcpy(str->buf->val + str->buf->len, buf, len); + str->buf->len += len; + str->buf->val[str->buf->len] = '\0'; return str; } static string *string_append(string *str, string *append) { - if (append->len > 1) { - string_write(str, append->string, append->len - 1); + if (append->buf->len > 0) { + string_write(str, append->buf->val, append->buf->len); } return str; } static void string_free(string *str) { - efree(str->string); - str->len = 0; + STR_RELEASE(str->buf); str->alloced = 0; - str->string = NULL; + str->buf = NULL; } /* }}} */ @@ -275,7 +277,7 @@ static void _free_function(zend_function *fptr TSRMLS_DC) /* {{{ */ && fptr->type == ZEND_INTERNAL_FUNCTION && (fptr->internal_function.fn_flags & ZEND_ACC_CALL_VIA_HANDLER) != 0) { - efree((char*)fptr->internal_function.function_name); + STR_RELEASE(fptr->internal_function.function_name); efree(fptr); } } @@ -358,7 +360,7 @@ static void _class_string(string *str, zend_class_entry *ce, zval *obj, char *in string_write(str, "\n", 1); } - if (obj) { + if (obj && Z_TYPE_P(obj) == IS_OBJECT) { string_printf(str, "%sObject of class [ ", indent); } else { char *kind = "Class"; @@ -390,28 +392,28 @@ static void _class_string(string *str, zend_class_entry *ce, zval *obj, char *in } string_printf(str, "class "); } - string_printf(str, "%s", ce->name); + string_printf(str, "%s", ce->name->val); if (ce->parent) { - string_printf(str, " extends %s", ce->parent->name); + string_printf(str, " extends %s", ce->parent->name->val); } if (ce->num_interfaces) { zend_uint i; if (ce->ce_flags & ZEND_ACC_INTERFACE) { - string_printf(str, " extends %s", ce->interfaces[0]->name); + string_printf(str, " extends %s", ce->interfaces[0]->name->val); } else { - string_printf(str, " implements %s", ce->interfaces[0]->name); + string_printf(str, " implements %s", ce->interfaces[0]->name->val); } for (i = 1; i < ce->num_interfaces; ++i) { - string_printf(str, ", %s", ce->interfaces[i]->name); + string_printf(str, ", %s", ce->interfaces[i]->name->val); } } string_printf(str, " ] {\n"); /* The information where a class is declared is only available for user classes */ if (ce->type == ZEND_USER_CLASS) { - string_printf(str, "%s @@ %s %d-%d\n", indent, ce->info.user.filename, + string_printf(str, "%s @@ %s %d-%d\n", indent, ce->info.user.filename->val, ce->info.user.line_start, ce->info.user.line_end); } @@ -469,7 +471,7 @@ static void _class_string(string *str, zend_class_entry *ce, zval *obj, char *in while ((prop = zend_hash_get_current_data_ptr_ex(&ce->properties_info, &pos)) != NULL) { if ((prop->flags & ZEND_ACC_STATIC) && !(prop->flags & ZEND_ACC_SHADOW)) { - _property_string(str, prop, NULL, sub_indent.string TSRMLS_CC); + _property_string(str, prop, NULL, sub_indent.buf->val TSRMLS_CC); } zend_hash_move_forward_ex(&ce->properties_info, &pos); @@ -511,7 +513,7 @@ static void _class_string(string *str, zend_class_entry *ce, zval *obj, char *in && ((mptr->common.fn_flags & ZEND_ACC_PRIVATE) == 0 || mptr->common.scope == ce)) { string_printf(str, "\n"); - _function_string(str, mptr, ce, sub_indent.string TSRMLS_CC); + _function_string(str, mptr, ce, sub_indent.buf->val TSRMLS_CC); } zend_hash_move_forward_ex(&ce->function_table, &pos); } @@ -533,7 +535,7 @@ static void _class_string(string *str, zend_class_entry *ce, zval *obj, char *in while ((prop = zend_hash_get_current_data_ptr_ex(&ce->properties_info, &pos)) != NULL) { if (!(prop->flags & (ZEND_ACC_STATIC|ZEND_ACC_SHADOW))) { - _property_string(str, prop, NULL, sub_indent.string TSRMLS_CC); + _property_string(str, prop, NULL, sub_indent.buf->val TSRMLS_CC); } zend_hash_move_forward_ex(&ce->properties_info, &pos); } @@ -541,7 +543,7 @@ static void _class_string(string *str, zend_class_entry *ce, zval *obj, char *in string_printf(str, "%s }\n", indent); } - if (obj && Z_OBJ_HT_P(obj)->get_properties) { + if (obj && Z_TYPE_P(obj) == IS_OBJECT && Z_OBJ_HT_P(obj)->get_properties) { string dyn; HashTable *properties = Z_OBJ_HT_P(obj)->get_properties(obj TSRMLS_CC); HashPosition pos; @@ -561,7 +563,7 @@ static void _class_string(string *str, zend_class_entry *ce, zval *obj, char *in if (prop_name->len && prop_name->val[0]) { /* skip all private and protected properties */ if (!zend_hash_exists(&ce->properties_info, prop_name)) { count++; - _property_string(&dyn, NULL, prop_name->val, sub_indent.string TSRMLS_CC); + _property_string(&dyn, NULL, prop_name->val, sub_indent.buf->val TSRMLS_CC); } } efree(prop_name); @@ -605,7 +607,7 @@ static void _class_string(string *str, zend_class_entry *ce, zval *obj, char *in zend_function *closure; /* see if this is a closure */ if (ce == zend_ce_closure && obj && (len == sizeof(ZEND_INVOKE_FUNC_NAME)-1) - && memcmp(mptr->common.function_name, ZEND_INVOKE_FUNC_NAME, sizeof(ZEND_INVOKE_FUNC_NAME)-1) == 0 + && memcmp(mptr->common.function_name->val, ZEND_INVOKE_FUNC_NAME, sizeof(ZEND_INVOKE_FUNC_NAME)-1) == 0 && (closure = zend_get_closure_invoke_method(obj TSRMLS_CC)) != NULL) { mptr = closure; @@ -613,7 +615,7 @@ static void _class_string(string *str, zend_class_entry *ce, zval *obj, char *in closure = NULL; } string_printf(&dyn, "\n"); - _function_string(&dyn, mptr, ce, sub_indent.string TSRMLS_CC); + _function_string(&dyn, mptr, ce, sub_indent.buf->val TSRMLS_CC); count++; _free_function(closure TSRMLS_CC); } @@ -833,21 +835,21 @@ static void _function_string(string *str, zend_function *fptr, zend_class_entry if (scope && fptr->common.scope) { if (fptr->common.scope != scope) { - string_printf(str, ", inherits %s", fptr->common.scope->name); + string_printf(str, ", inherits %s", fptr->common.scope->name->val); } else if (fptr->common.scope->parent) { lc_name_len = fptr->common.function_name->len; lc_name = STR_ALLOC(lc_name_len, 0); zend_str_tolower_copy(lc_name->val, fptr->common.function_name->val, lc_name_len); if ((overwrites = zend_hash_find_ptr(&fptr->common.scope->parent->function_table, lc_name)) != NULL) { if (fptr->common.scope != overwrites->common.scope) { - string_printf(str, ", overwrites %s", overwrites->common.scope->name); + string_printf(str, ", overwrites %s", overwrites->common.scope->name->val); } } efree(lc_name); } } if (fptr->common.prototype && fptr->common.prototype->common.scope) { - string_printf(str, ", prototype %s", fptr->common.prototype->common.scope->name); + string_printf(str, ", prototype %s", fptr->common.prototype->common.scope->name->val); } if (fptr->common.fn_flags & ZEND_ACC_CTOR) { string_printf(str, ", ctor"); @@ -891,20 +893,20 @@ static void _function_string(string *str, zend_function *fptr, zend_class_entry if (fptr->op_array.fn_flags & ZEND_ACC_RETURN_REFERENCE) { string_printf(str, "&"); } - string_printf(str, "%s ] {\n", fptr->common.function_name); + string_printf(str, "%s ] {\n", fptr->common.function_name->val); /* The information where a function is declared is only available for user classes */ if (fptr->type == ZEND_USER_FUNCTION) { string_printf(str, "%s @@ %s %d - %d\n", indent, - fptr->op_array.filename, + fptr->op_array.filename->val, fptr->op_array.line_start, fptr->op_array.line_end); } string_init(¶m_indent); string_printf(¶m_indent, "%s ", indent); if (fptr->common.fn_flags & ZEND_ACC_CLOSURE) { - _function_closure_string(str, fptr, param_indent.string TSRMLS_CC); + _function_closure_string(str, fptr, param_indent.buf->val TSRMLS_CC); } - _function_parameter_string(str, fptr, param_indent.string TSRMLS_CC); + _function_parameter_string(str, fptr, param_indent.buf->val TSRMLS_CC); string_free(¶m_indent); string_printf(str, "%s}\n", indent); } @@ -1071,7 +1073,7 @@ static void _extension_string(string *str, zend_module_entry *module, char *inde string str_ini; string_init(&str_ini); zend_hash_apply_with_arguments(EG(ini_directives) TSRMLS_CC, (apply_func_args_t) _extension_ini_string, 3, &str_ini, indent, module->module_number); - if (str_ini.len > 1) { + if (str_ini.buf->len > 0) { string_printf(str, "\n - INI {\n"); string_append(str, &str_ini); string_printf(str, "%s }\n", indent); @@ -1123,7 +1125,7 @@ static void _extension_string(string *str, zend_module_entry *module, char *inde string_init(&sub_indent); string_printf(&sub_indent, "%s ", indent); string_init(&str_classes); - zend_hash_apply_with_arguments(EG(class_table) TSRMLS_CC, (apply_func_args_t) _extension_class_string, 4, &str_classes, sub_indent.string, module, &num_classes); + zend_hash_apply_with_arguments(EG(class_table) TSRMLS_CC, (apply_func_args_t) _extension_class_string, 4, &str_classes, sub_indent.buf->val, module, &num_classes); if (num_classes) { string_printf(str, "\n - Classes [%d] {", num_classes); string_append(str, &str_classes); @@ -1351,10 +1353,14 @@ static void _reflection_export(INTERNAL_FUNCTION_PARAMETERS, zend_class_entry *c if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|b", &argument_ptr, &return_output) == FAILURE) { return; } + ZVAL_COPY_VALUE(¶ms[0], argument_ptr); + ZVAL_NULL(¶ms[1]); } else { if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz|b", &argument_ptr, &argument2_ptr, &return_output) == FAILURE) { return; } + ZVAL_COPY_VALUE(¶ms[0], argument_ptr); + ZVAL_COPY_VALUE(¶ms[1], argument2_ptr); } //??? INIT_PZVAL(&output); @@ -1365,8 +1371,6 @@ static void _reflection_export(INTERNAL_FUNCTION_PARAMETERS, zend_class_entry *c } /* Call __construct() */ - ZVAL_COPY_VALUE(¶ms[0], argument_ptr); - ZVAL_COPY_VALUE(¶ms[1], argument2_ptr); fci.size = sizeof(fci); fci.function_table = NULL; @@ -1402,8 +1406,7 @@ static void _reflection_export(INTERNAL_FUNCTION_PARAMETERS, zend_class_entry *c ZVAL_COPY_VALUE(¶ms[0], &reflector); ZVAL_COPY_VALUE(¶ms[1], output_ptr); -//??? ZVAL_STRINGL(&fname, "reflection::export", sizeof("reflection::export") - 1, 0); - ZVAL_STRINGL(&fci.function_name, "reflection::export", sizeof("reflection::export") - 1); + ZVAL_STRINGL(&fci.function_name, "reflection::export", sizeof("reflection::export") - 1); fci.function_table = &reflection_ptr->function_table; fci.object_ptr = NULL; fci.retval = &retval; @@ -1413,6 +1416,8 @@ static void _reflection_export(INTERNAL_FUNCTION_PARAMETERS, zend_class_entry *c result = zend_call_function(&fci, NULL TSRMLS_CC); + zval_ptr_dtor(&fci.function_name); + if (result == FAILURE && EG(exception) == NULL) { zval_ptr_dtor(&reflector); zval_ptr_dtor(&retval); @@ -1640,8 +1645,7 @@ ZEND_METHOD(reflection_function, __toString) GET_REFLECTION_OBJECT_PTR(fptr); string_init(&str); _function_string(&str, fptr, intern->ce, "" TSRMLS_CC); -//??? RETURN_STRINGL(str.string, str.len - 1, 0); - RETURN_STRINGL(str.string, str.len - 1); + RETURN_STR(str.buf); } /* }}} */ @@ -1871,7 +1875,6 @@ ZEND_METHOD(reflection_function, getStaticVariables) ZEND_METHOD(reflection_function, invoke) { zval retval; -//??? zval *params = NULL; int result, num_args = 0; zend_fcall_info fci; @@ -1910,7 +1913,7 @@ ZEND_METHOD(reflection_function, invoke) if (result == FAILURE) { zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, - "Invocation of function %s() failed", fptr->common.function_name); + "Invocation of function %s() failed", fptr->common.function_name->val); return; } @@ -1976,7 +1979,7 @@ ZEND_METHOD(reflection_function, invokeArgs) if (result == FAILURE) { zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, - "Invocation of function %s() failed", fptr->common.function_name); + "Invocation of function %s() failed", fptr->common.function_name->val); return; } @@ -2207,7 +2210,7 @@ ZEND_METHOD(reflection_parameter, __construct) is_closure = 1; } else if ((fptr = zend_hash_str_find_ptr(&ce->function_table, ZEND_INVOKE_FUNC_NAME, sizeof(ZEND_INVOKE_FUNC_NAME))) == NULL) { zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, - "Method %s::%s() does not exist", ce->name, ZEND_INVOKE_FUNC_NAME); + "Method %s::%s() does not exist", ce->name->val, ZEND_INVOKE_FUNC_NAME); return; } } @@ -2297,8 +2300,7 @@ ZEND_METHOD(reflection_parameter, __toString) GET_REFLECTION_OBJECT_PTR(param); string_init(&str); _parameter_string(&str, param->fptr, param->arg_info, param->offset, param->required, "" TSRMLS_CC); -///??? RETURN_STRINGL(str.string, str.len - 1, 0); - RETURN_STRINGL(str.string, str.len - 1); + RETURN_STR(str.buf); } /* }}} */ @@ -2761,8 +2763,7 @@ ZEND_METHOD(reflection_method, __toString) GET_REFLECTION_OBJECT_PTR(mptr); string_init(&str); _function_string(&str, mptr, intern->ce, "" TSRMLS_CC); -//??? RETURN_STRINGL(str.string, str.len - 1, 0); - RETURN_STRINGL(str.string, str.len - 1); + RETURN_STR(str.buf); } /* }}} */ @@ -2806,7 +2807,6 @@ ZEND_METHOD(reflection_method, getClosure) ZEND_METHOD(reflection_method, invoke) { zval retval; -//??? zval *params = NULL; zval object; reflection_object *intern; @@ -2827,13 +2827,13 @@ ZEND_METHOD(reflection_method, invoke) if (mptr->common.fn_flags & ZEND_ACC_ABSTRACT) { zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Trying to invoke abstract method %s::%s()", - mptr->common.scope->name, mptr->common.function_name); + mptr->common.scope->name->val, mptr->common.function_name->val); } else { zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Trying to invoke %s method %s::%s() from scope %s", mptr->common.fn_flags & ZEND_ACC_PROTECTED ? "protected" : "private", - mptr->common.scope->name, mptr->common.function_name, - Z_OBJCE_P(getThis())->name); + mptr->common.scope->name->val, mptr->common.function_name->val, + Z_OBJCE_P(getThis())->name->val); } return; } @@ -2895,7 +2895,7 @@ ZEND_METHOD(reflection_method, invoke) if (result == FAILURE) { zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, - "Invocation of method %s::%s() failed", mptr->common.scope->name, mptr->common.function_name); + "Invocation of method %s::%s() failed", mptr->common.scope->name->val, mptr->common.function_name->val); return; } @@ -2936,13 +2936,13 @@ ZEND_METHOD(reflection_method, invokeArgs) if (mptr->common.fn_flags & ZEND_ACC_ABSTRACT) { zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Trying to invoke abstract method %s::%s()", - mptr->common.scope->name, mptr->common.function_name); + mptr->common.scope->name->val, mptr->common.function_name->val); } else { zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Trying to invoke %s method %s::%s() from scope %s", mptr->common.fn_flags & ZEND_ACC_PROTECTED ? "protected" : "private", - mptr->common.scope->name, mptr->common.function_name, - Z_OBJCE_P(getThis())->name); + mptr->common.scope->name->val, mptr->common.function_name->val, + Z_OBJCE_P(getThis())->name->val); } return; } @@ -2967,7 +2967,7 @@ ZEND_METHOD(reflection_method, invokeArgs) efree(params); zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Trying to invoke non static method %s::%s() without an object", - mptr->common.scope->name, mptr->common.function_name); + mptr->common.scope->name->val, mptr->common.function_name->val); return; } @@ -3010,7 +3010,7 @@ ZEND_METHOD(reflection_method, invokeArgs) if (result == FAILURE) { zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, - "Invocation of method %s::%s() failed", mptr->common.scope->name, mptr->common.function_name); + "Invocation of method %s::%s() failed", mptr->common.scope->name->val, mptr->common.function_name->val); return; } @@ -3244,7 +3244,7 @@ ZEND_METHOD(reflection_method, getPrototype) if (!mptr->common.prototype) { zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, - "Method %s::%s does not have a prototype", intern->ce->name, mptr->common.function_name); + "Method %s::%s does not have a prototype", intern->ce->name->val, mptr->common.function_name->val); return; } @@ -3506,8 +3506,7 @@ ZEND_METHOD(reflection_class, __toString) GET_REFLECTION_OBJECT_PTR(ce); string_init(&str); _class_string(&str, ce, &intern->obj, "" TSRMLS_CC); -//??? RETURN_STRINGL(str.string, str.len - 1, 0); - RETURN_STRINGL(str.string, str.len - 1); + RETURN_STR(str.buf); } /* }}} */ @@ -3879,7 +3878,7 @@ ZEND_METHOD(reflection_class, getProperty) } if (!instanceof_function(ce, ce2 TSRMLS_CC)) { - zend_throw_exception_ex(reflection_exception_ptr, -1 TSRMLS_CC, "Fully qualified property name %s::%s does not specify a base class of %s", ce2->name, str_name, ce->name->val); + zend_throw_exception_ex(reflection_exception_ptr, -1 TSRMLS_CC, "Fully qualified property name %s::%s does not specify a base class of %s", ce2->name->val, str_name, ce->name->val); return; } ce = ce2; @@ -4193,14 +4192,13 @@ ZEND_METHOD(reflection_class, newInstance) /* Run the constructor if there is one */ if (constructor) { -//??? zval *params = NULL; int num_args = 0; zend_fcall_info fci; zend_fcall_info_cache fcc; if (!(constructor->common.fn_flags & ZEND_ACC_PUBLIC)) { - zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Access to non-public constructor of class %s", ce->name); + zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Access to non-public constructor of class %s", ce->name->val); zval_dtor(return_value); RETURN_NULL(); } @@ -4247,7 +4245,7 @@ ZEND_METHOD(reflection_class, newInstance) efree(params); } } else if (ZEND_NUM_ARGS()) { - zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Class %s does not have a constructor, so you cannot pass any constructor arguments", ce->name); + zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Class %s does not have a constructor, so you cannot pass any constructor arguments", ce->name->val); } } /* }}} */ @@ -4263,7 +4261,7 @@ ZEND_METHOD(reflection_class, newInstanceWithoutConstructor) GET_REFLECTION_OBJECT_PTR(ce); if (ce->create_object != NULL) { - zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Class %s is an internal class that cannot be instantiated without invoking its constructor", ce->name); + zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Class %s is an internal class that cannot be instantiated without invoking its constructor", ce->name->val); } object_init_ex(return_value, ce); @@ -4302,13 +4300,12 @@ ZEND_METHOD(reflection_class, newInstanceArgs) /* Run the constructor if there is one */ if (constructor) { -//??? zval *params = NULL; zend_fcall_info fci; zend_fcall_info_cache fcc; if (!(constructor->common.fn_flags & ZEND_ACC_PUBLIC)) { - zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Access to non-public constructor of class %s", ce->name); + zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Access to non-public constructor of class %s", ce->name->val); zval_dtor(return_value); RETURN_NULL(); } @@ -4591,7 +4588,7 @@ ZEND_METHOD(reflection_class, implementsInterface) if (!(interface_ce->ce_flags & ZEND_ACC_INTERFACE)) { zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, - "Interface %s is a Class", interface_ce->name); + "Interface %s is a Class", interface_ce->name->val); return; } RETURN_BOOL(instanceof_function(ce, interface_ce TSRMLS_CC)); @@ -4802,7 +4799,7 @@ ZEND_METHOD(reflection_property, __construct) } } if (dynam_prop == 0) { - zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Property %s::$%s does not exist", ce->name, name_str); + zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Property %s::$%s does not exist", ce->name->val, name_str); return; } } @@ -4861,8 +4858,7 @@ ZEND_METHOD(reflection_property, __toString) GET_REFLECTION_OBJECT_PTR(ref); string_init(&str); _property_string(&str, &ref->prop, NULL, "" TSRMLS_CC); -//??? RETURN_STRINGL(str.string, str.len - 1, 0); - RETURN_STRINGL(str.string, str.len - 1); + RETURN_STR(str.buf); } /* }}} */ @@ -4961,7 +4957,7 @@ ZEND_METHOD(reflection_property, getValue) if (!(ref->prop.flags & (ZEND_ACC_PUBLIC | ZEND_ACC_IMPLICIT_PUBLIC)) && intern->ignore_visibility == 0) { _default_get_entry(getThis(), "name", sizeof("name")-1, &name TSRMLS_CC); zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, - "Cannot access non-public member %s::%s", intern->ce->name, Z_STRVAL(name)); + "Cannot access non-public member %s::%s", intern->ce->name->val, Z_STRVAL(name)); zval_dtor(&name); return; } @@ -5009,7 +5005,7 @@ ZEND_METHOD(reflection_property, setValue) if (!(ref->prop.flags & ZEND_ACC_PUBLIC) && intern->ignore_visibility == 0) { _default_get_entry(getThis(), "name", sizeof("name")-1, &name TSRMLS_CC); zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, - "Cannot access non-public member %s::%s", intern->ce->name, Z_STRVAL(name)); + "Cannot access non-public member %s::%s", intern->ce->name->val, Z_STRVAL(name)); zval_dtor(&name); return; } @@ -5203,8 +5199,7 @@ ZEND_METHOD(reflection_extension, __toString) GET_REFLECTION_OBJECT_PTR(module); string_init(&str); _extension_string(&str, module, "" TSRMLS_CC); -//??? RETURN_STRINGL(str.string, str.len - 1, 0); - RETURN_STRINGL(str.string, str.len - 1); + RETURN_STR(str.buf); } /* }}} */ @@ -5278,7 +5273,7 @@ static int _addconstant(zend_constant *constant TSRMLS_DC, int num_args, va_list if (number == constant->module_number) { ZVAL_DUP(&const_val, &constant->value); //??? INIT_PZVAL(const_val); -//??? + add_assoc_zval_ex(retval, constant->name->val, constant->name->len, &const_val); } return 0; @@ -5549,8 +5544,7 @@ ZEND_METHOD(reflection_zend_extension, __toString) GET_REFLECTION_OBJECT_PTR(extension); string_init(&str); _zend_extension_string(&str, extension, "" TSRMLS_CC); -//??? RETURN_STRINGL(str.string, str.len - 1, 0); - RETURN_STRINGL(str.string, str.len - 1); + RETURN_STR(str.buf); } /* }}} */ @@ -6074,7 +6068,7 @@ static void _reflection_write_property(zval *object, zval *member, zval *value, || (Z_STRLEN_P(member) == sizeof("class") - 1 && !memcmp(Z_STRVAL_P(member), "class", sizeof("class"))))) { zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, - "Cannot set read-only property %s::$%s", Z_OBJCE_P(object)->name, Z_STRVAL_P(member)); + "Cannot set read-only property %s::$%s", Z_OBJCE_P(object)->name->val, Z_STRVAL_P(member)); } else { -- cgit v1.2.1 From 8ced4f0ac906fd9a28b968801487630326c45bc8 Mon Sep 17 00:00:00 2001 From: Xinchen Hui Date: Fri, 28 Feb 2014 12:59:51 +0800 Subject: Move zend_objects_store_put out of zend_object_std_init --- ext/reflection/php_reflection.c | 1 + 1 file changed, 1 insertion(+) (limited to 'ext/reflection/php_reflection.c') diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index e82e13248e..075a642f6d 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -325,6 +325,7 @@ static zend_object *reflection_objects_new(zend_class_entry *class_type TSRMLS_D intern->zo.ce = class_type; zend_object_std_init(&intern->zo, class_type TSRMLS_CC); + zend_objects_store_put(&intern->zo TSRMLS_CC); object_properties_init(&intern->zo, class_type); intern->zo.handlers = &reflection_object_handlers; return (zend_object*)intern; -- cgit v1.2.1 From a5ce7d526e77a7d0cce650c7b2c09a1c31ad39bb Mon Sep 17 00:00:00 2001 From: Xinchen Hui Date: Fri, 28 Feb 2014 13:59:07 +0800 Subject: Revert "Move zend_objects_store_put out of zend_object_std_init" This reverts commit 8ced4f0ac906fd9a28b968801487630326c45bc8. --- ext/reflection/php_reflection.c | 1 - 1 file changed, 1 deletion(-) (limited to 'ext/reflection/php_reflection.c') diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 075a642f6d..e82e13248e 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -325,7 +325,6 @@ static zend_object *reflection_objects_new(zend_class_entry *class_type TSRMLS_D intern->zo.ce = class_type; zend_object_std_init(&intern->zo, class_type TSRMLS_CC); - zend_objects_store_put(&intern->zo TSRMLS_CC); object_properties_init(&intern->zo, class_type); intern->zo.handlers = &reflection_object_handlers; return (zend_object*)intern; -- cgit v1.2.1 From b353d5abe95675fab70f66ee79d8f503bc7f1e69 Mon Sep 17 00:00:00 2001 From: Xinchen Hui Date: Fri, 28 Feb 2014 16:06:47 +0800 Subject: Fixed un-initilized iterator in DirectoyItrator --- ext/reflection/php_reflection.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'ext/reflection/php_reflection.c') diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index e82e13248e..bbe66fbc6c 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -4175,7 +4175,7 @@ ZEND_METHOD(reflection_class, isInstance) Returns an instance of this class */ ZEND_METHOD(reflection_class, newInstance) { - zval *retval_ptr = NULL; + zval retval; reflection_object *intern; zend_class_entry *ce, *old_scope; zend_function *constructor; @@ -4216,7 +4216,7 @@ ZEND_METHOD(reflection_class, newInstance) ZVAL_UNDEF(&fci.function_name); fci.symbol_table = NULL; fci.object_ptr = return_value; - fci.retval = retval_ptr; + fci.retval = &retval; fci.param_count = num_args; fci.params = params; fci.no_separation = 1; @@ -4231,15 +4231,15 @@ ZEND_METHOD(reflection_class, newInstance) if (params) { efree(params); } - if (retval_ptr) { - zval_ptr_dtor(retval_ptr); + if (!ZVAL_IS_UNDEF(&retval)) { + zval_ptr_dtor(&retval); } php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invocation of %s's constructor failed", ce->name->val); zval_dtor(return_value); RETURN_NULL(); } - if (retval_ptr) { - zval_ptr_dtor(retval_ptr); + if (!ZVAL_IS_UNDEF(&retval)) { + zval_ptr_dtor(&retval); } if (params) { efree(params); -- cgit v1.2.1 From ff5870a28805812bce4a4bfcd877d8e7e17f61ff Mon Sep 17 00:00:00 2001 From: Xinchen Hui Date: Sun, 2 Mar 2014 15:14:00 +0800 Subject: Fixed reflection (incompeleted) --- ext/reflection/php_reflection.c | 82 ++++++++++++++++++++--------------------- 1 file changed, 41 insertions(+), 41 deletions(-) (limited to 'ext/reflection/php_reflection.c') diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index bbe66fbc6c..45a719e64b 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -953,8 +953,9 @@ static void _property_string(string *str, zend_property_info *prop, char *prop_n } /* }}} */ -static int _extension_ini_string(zend_ini_entry *ini_entry TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key) /* {{{ */ +static int _extension_ini_string(zval *el TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key) /* {{{ */ { + zend_ini_entry *ini_entry = (zend_ini_entry*)Z_PTR_P(el); string *str = va_arg(args, string *); char *indent = va_arg(args, char *); int number = va_arg(args, int); @@ -989,24 +990,26 @@ static int _extension_ini_string(zend_ini_entry *ini_entry TSRMLS_DC, int num_ar } /* }}} */ -static int _extension_class_string(zend_class_entry **pce TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key) /* {{{ */ +static int _extension_class_string(zval *el TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key) /* {{{ */ { + zend_class_entry *ce = (zend_class_entry*)Z_PTR_P(el); string *str = va_arg(args, string *); char *indent = va_arg(args, char *); struct _zend_module_entry *module = va_arg(args, struct _zend_module_entry*); int *num_classes = va_arg(args, int*); - if (((*pce)->type == ZEND_INTERNAL_CLASS) && (*pce)->info.internal.module && !strcasecmp((*pce)->info.internal.module->name, module->name)) { + if ((ce->type == ZEND_INTERNAL_CLASS) && ce->info.internal.module && !strcasecmp(ce->info.internal.module->name, module->name)) { string_printf(str, "\n"); - _class_string(str, *pce, NULL, indent TSRMLS_CC); + _class_string(str, ce, NULL, indent TSRMLS_CC); (*num_classes)++; } return ZEND_HASH_APPLY_KEEP; } /* }}} */ -static int _extension_const_string(zend_constant *constant TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key) /* {{{ */ +static int _extension_const_string(zval *el TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key) /* {{{ */ { + zend_constant *constant = (zend_constant*)Z_PTR_P(el); string *str = va_arg(args, string *); char *indent = va_arg(args, char *); struct _zend_module_entry *module = va_arg(args, struct _zend_module_entry*); @@ -1020,8 +1023,7 @@ static int _extension_const_string(zend_constant *constant TSRMLS_DC, int num_ar } /* }}} */ -/* {{{ _extension_string */ -static void _extension_string(string *str, zend_module_entry *module, char *indent TSRMLS_DC) +static void _extension_string(string *str, zend_module_entry *module, char *indent TSRMLS_DC) /* {{{ */ { string_printf(str, "%sExtension [ ", indent); if (module->type == MODULE_PERSISTENT) { @@ -1224,9 +1226,6 @@ static void reflection_parameter_factory(zend_function *fptr, zval *closure_obje parameter_reference *reference; zval name; - if (closure_object) { - if (Z_REFCOUNTED_P(closure_object)) Z_ADDREF_P(closure_object); - } if (arg_info->name) { ZVAL_STRINGL(&name, arg_info->name, arg_info->name_len); } else { @@ -1242,7 +1241,10 @@ static void reflection_parameter_factory(zend_function *fptr, zval *closure_obje intern->ptr = reference; intern->ref_type = REF_TYPE_PARAMETER; intern->ce = fptr->common.scope; - ZVAL_COPY_VALUE(&intern->obj, closure_object); + if (closure_object) { + Z_ADDREF_P(closure_object); + ZVAL_COPY_VALUE(&intern->obj, closure_object); + } reflection_update_property(object, "name", &name); } /* }}} */ @@ -1253,9 +1255,6 @@ static void reflection_function_factory(zend_function *function, zval *closure_o reflection_object *intern; zval name; - if (closure_object) { - Z_ADDREF_P(closure_object); - } ZVAL_STR(&name, STR_COPY(function->common.function_name)); reflection_instantiate(reflection_function_ptr, object TSRMLS_CC); @@ -1263,7 +1262,10 @@ static void reflection_function_factory(zend_function *function, zval *closure_o intern->ptr = function; intern->ref_type = REF_TYPE_FUNCTION; intern->ce = NULL; - ZVAL_COPY_VALUE(&intern->obj, closure_object); + if (closure_object) { + Z_ADDREF_P(closure_object); + ZVAL_COPY_VALUE(&intern->obj, closure_object); + } reflection_update_property(object, "name", &name); } /* }}} */ @@ -1275,9 +1277,6 @@ static void reflection_method_factory(zend_class_entry *ce, zend_function *metho zval name; zval classname; - if (closure_object) { - Z_ADDREF_P(closure_object); - } ZVAL_STR(&name, STR_COPY((method->common.scope && method->common.scope->trait_aliases)? zend_resolve_method_name(ce, method) : method->common.function_name)); ZVAL_STR(&classname, STR_COPY(method->common.scope->name)); @@ -1286,7 +1285,10 @@ static void reflection_method_factory(zend_class_entry *ce, zend_function *metho intern->ptr = method; intern->ref_type = REF_TYPE_FUNCTION; intern->ce = ce; - ZVAL_COPY_VALUE(&intern->obj, closure_object); + if (closure_object) { + Z_ADDREF_P(closure_object); + ZVAL_COPY_VALUE(&intern->obj, closure_object); + } reflection_update_property(object, "name", &name); reflection_update_property(object, "class", &classname); } @@ -1687,7 +1689,7 @@ ZEND_METHOD(reflection_function, getClosureThis) return; } GET_REFLECTION_OBJECT_PTR(fptr); - if (Z_TYPE(intern->obj) != IS_UNDEF) { + if (!ZVAL_IS_UNDEF(&intern->obj)) { closure_this = zend_get_closure_this_ptr(&intern->obj TSRMLS_CC); if (closure_this) { RETURN_ZVAL(closure_this, 1, 0); @@ -1708,7 +1710,7 @@ ZEND_METHOD(reflection_function, getClosureScopeClass) return; } GET_REFLECTION_OBJECT_PTR(fptr); - if (Z_TYPE(intern->obj) != IS_UNDEF) { + if (!ZVAL_IS_UNDEF(&intern->obj)) { closure_func = zend_get_closure_method_def(&intern->obj TSRMLS_CC); if (closure_func && closure_func->common.scope) { zend_reflection_class_factory(closure_func->common.scope, return_value TSRMLS_CC); @@ -1733,7 +1735,6 @@ ZEND_METHOD(reflection_function, getClosure) } /* }}} */ - /* {{{ proto public bool ReflectionFunction::isInternal() Returns whether this is an internal function */ ZEND_METHOD(reflection_function, isInternal) @@ -2049,7 +2050,7 @@ ZEND_METHOD(reflection_function, getParameters) for (i = 0; i < fptr->common.num_args; i++) { zval parameter; - reflection_parameter_factory(_copy_function(fptr TSRMLS_CC), &intern->obj, arg_info, i, fptr->common.required_num_args, ¶meter TSRMLS_CC); + reflection_parameter_factory(_copy_function(fptr TSRMLS_CC), ZVAL_IS_UNDEF(&intern->obj)? NULL : &intern->obj, arg_info, i, fptr->common.required_num_args, ¶meter TSRMLS_CC); add_next_index_zval(return_value, ¶meter); arg_info++; @@ -2328,9 +2329,9 @@ ZEND_METHOD(reflection_parameter, getDeclaringFunction) GET_REFLECTION_OBJECT_PTR(param); if (!param->fptr->common.scope) { - reflection_function_factory(_copy_function(param->fptr TSRMLS_CC), &intern->obj, return_value TSRMLS_CC); + reflection_function_factory(_copy_function(param->fptr TSRMLS_CC), ZVAL_IS_UNDEF(&intern->obj)? NULL : &intern->obj, return_value TSRMLS_CC); } else { - reflection_method_factory(param->fptr->common.scope, _copy_function(param->fptr TSRMLS_CC), &intern->obj, return_value TSRMLS_CC); + reflection_method_factory(param->fptr->common.scope, _copy_function(param->fptr TSRMLS_CC), ZVAL_IS_UNDEF(&intern->obj)? NULL : &intern->obj, return_value TSRMLS_CC); } } /* }}} */ @@ -3689,7 +3690,7 @@ ZEND_METHOD(reflection_class, getMethod) GET_REFLECTION_OBJECT_PTR(ce); lc_name = zend_str_tolower_dup(name, name_len); - if (ce == zend_ce_closure && Z_TYPE(intern->obj) != IS_UNDEF && (name_len == sizeof(ZEND_INVOKE_FUNC_NAME)-1) + if (ce == zend_ce_closure && !ZVAL_IS_UNDEF(&intern->obj) && (name_len == sizeof(ZEND_INVOKE_FUNC_NAME)-1) && memcmp(lc_name, ZEND_INVOKE_FUNC_NAME, sizeof(ZEND_INVOKE_FUNC_NAME)-1) == 0 && (mptr = zend_get_closure_invoke_method(&intern->obj TSRMLS_CC)) != NULL) { @@ -3697,7 +3698,7 @@ ZEND_METHOD(reflection_class, getMethod) method and not the closure definition itself */ reflection_method_factory(ce, mptr, NULL, return_value TSRMLS_CC); efree(lc_name); - } else if (ce == zend_ce_closure && Z_TYPE(intern->obj) == IS_UNDEF && (name_len == sizeof(ZEND_INVOKE_FUNC_NAME)-1) + } else if (ce == zend_ce_closure && !ZVAL_IS_UNDEF(&intern->obj) && (name_len == sizeof(ZEND_INVOKE_FUNC_NAME)-1) && memcmp(lc_name, ZEND_INVOKE_FUNC_NAME, sizeof(ZEND_INVOKE_FUNC_NAME)-1) == 0 && object_init_ex(&obj_tmp, ce) == SUCCESS && (mptr = zend_get_closure_invoke_method(&obj_tmp TSRMLS_CC)) != NULL) { /* don't assign closure_object since we only reflect the invoke handler @@ -3723,7 +3724,6 @@ static void _addmethod(zend_function *mptr, zend_class_entry *ce, zval *retval, zval method; uint len = mptr->common.function_name->len; zend_function *closure; - if (mptr->common.fn_flags & filter) { if (ce == zend_ce_closure && obj && (len == sizeof(ZEND_INVOKE_FUNC_NAME)-1) && memcmp(mptr->common.function_name->val, ZEND_INVOKE_FUNC_NAME, sizeof(ZEND_INVOKE_FUNC_NAME)-1) == 0 @@ -3741,8 +3741,9 @@ static void _addmethod(zend_function *mptr, zend_class_entry *ce, zval *retval, /* }}} */ /* {{{ _addmethod */ -static int _addmethod_va(zend_function *mptr TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key) +static int _addmethod_va(zval *el TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key) { + zend_function *mptr = (zend_function*)Z_PTR_P(el); zend_class_entry *ce = *va_arg(args, zend_class_entry**); zval *retval = va_arg(args, zval*); long filter = va_arg(args, long); @@ -3894,9 +3895,10 @@ ZEND_METHOD(reflection_class, getProperty) /* }}} */ /* {{{ _addproperty */ -static int _addproperty(zend_property_info *pptr TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key) +static int _addproperty(zval *el TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key) { zval property; + zend_property_info *pptr = (zend_property_info*)Z_PTR_P(el); zend_class_entry *ce = *va_arg(args, zend_class_entry**); zval *retval = va_arg(args, zval*); long filter = va_arg(args, long); @@ -4088,7 +4090,7 @@ ZEND_METHOD(reflection_class, isCloneable) if (ce->ce_flags & (ZEND_ACC_INTERFACE | ZEND_ACC_TRAIT | ZEND_ACC_EXPLICIT_ABSTRACT_CLASS | ZEND_ACC_IMPLICIT_ABSTRACT_CLASS)) { RETURN_FALSE; } - if (Z_TYPE(intern->obj) != IS_UNDEF) { + if (!ZVAL_IS_UNDEF(&intern->obj)) { if (ce->clone) { RETURN_BOOL(ce->clone->common.fn_flags & ZEND_ACC_PUBLIC); } else { @@ -4272,7 +4274,7 @@ ZEND_METHOD(reflection_class, newInstanceWithoutConstructor) Returns an instance of this class */ ZEND_METHOD(reflection_class, newInstanceArgs) { - zval *retval_ptr = NULL; + zval retval; reflection_object *intern; zend_class_entry *ce, *old_scope; int argc = 0; @@ -4321,7 +4323,7 @@ ZEND_METHOD(reflection_class, newInstanceArgs) ZVAL_UNDEF(&fci.function_name); fci.symbol_table = NULL; fci.object_ptr = return_value; - fci.retval = retval_ptr; + fci.retval = &retval; fci.param_count = argc; fci.params = params; fci.no_separation = 1; @@ -4336,16 +4338,12 @@ ZEND_METHOD(reflection_class, newInstanceArgs) if (params) { efree(params); } - if (retval_ptr) { - zval_ptr_dtor(retval_ptr); - } + zval_ptr_dtor(&retval); php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invocation of %s's constructor failed", ce->name->val); zval_dtor(return_value); RETURN_NULL(); } - if (retval_ptr) { - zval_ptr_dtor(retval_ptr); - } + zval_ptr_dtor(&retval); if (params) { efree(params); } @@ -5264,9 +5262,10 @@ ZEND_METHOD(reflection_extension, getFunctions) } /* }}} */ -static int _addconstant(zend_constant *constant TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key) /* {{{ */ +static int _addconstant(zval *el TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key) /* {{{ */ { zval const_val; + zend_constant *constant = (zend_constant*)Z_PTR_P(el); zval *retval = va_arg(args, zval*); int number = va_arg(args, int); @@ -5298,8 +5297,9 @@ ZEND_METHOD(reflection_extension, getConstants) /* }}} */ /* {{{ _addinientry */ -static int _addinientry(zend_ini_entry *ini_entry TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key) +static int _addinientry(zval *el TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key) { + zend_ini_entry *ini_entry = (zend_ini_entry*)Z_PTR_P(el); zval *retval = va_arg(args, zval*); int number = va_arg(args, int); -- cgit v1.2.1 From 8d2c1f58a16c4343204cc828bae6291c1064d565 Mon Sep 17 00:00:00 2001 From: Xinchen Hui Date: Sun, 2 Mar 2014 15:15:51 +0800 Subject: Fixed refcounting --- ext/reflection/php_reflection.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'ext/reflection/php_reflection.c') diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 45a719e64b..d2583621e3 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -5038,7 +5038,9 @@ ZEND_METHOD(reflection_property, setValue) ZVAL_COPY_VALUE(&garbage, variable_ptr); /* if we assign referenced variable, we should separate it */ - Z_ADDREF_P(value); + if (Z_REFCOUNTED_P(value)) { + Z_ADDREF_P(value); + } if (Z_ISREF_P(value)) { SEPARATE_ZVAL(value); } -- cgit v1.2.1 From 26e993a7ae908971acaa9135abd3b6559777e5e5 Mon Sep 17 00:00:00 2001 From: Xinchen Hui Date: Sun, 2 Mar 2014 16:02:32 +0800 Subject: Fixed zend_string --- ext/reflection/php_reflection.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'ext/reflection/php_reflection.c') diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index d2583621e3..e19a8661cc 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -820,7 +820,7 @@ static void _function_string(string *str, zend_function *fptr, zend_class_entry * swallowed, leading to an unaligned comment. */ if (fptr->type == ZEND_USER_FUNCTION && fptr->op_array.doc_comment) { - string_printf(str, "%s%s\n", indent, fptr->op_array.doc_comment); + string_printf(str, "%s%s\n", indent, fptr->op_array.doc_comment->val); } string_write(str, indent, strlen(indent)); @@ -3432,7 +3432,7 @@ ZEND_METHOD(reflection_class, getStaticPropertyValue) RETURN_ZVAL(def_value, 1, 0); } else { zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, - "Class %s does not have a property named %s", ce->name->val, name); + "Class %s does not have a property named %s", ce->name->val, name->val); } return; } else { @@ -3870,13 +3870,14 @@ ZEND_METHOD(reflection_class, getProperty) str_name = tmp + 2; ce2 = zend_lookup_class(classname TSRMLS_CC); - STR_FREE(classname); if (!ce2) { if (!EG(exception)) { - zend_throw_exception_ex(reflection_exception_ptr, -1 TSRMLS_CC, "Class %s does not exist", classname); + zend_throw_exception_ex(reflection_exception_ptr, -1 TSRMLS_CC, "Class %s does not exist", classname->val); } + STR_FREE(classname); return; } + STR_FREE(classname); if (!instanceof_function(ce, ce2 TSRMLS_CC)) { zend_throw_exception_ex(reflection_exception_ptr, -1 TSRMLS_CC, "Fully qualified property name %s::%s does not specify a base class of %s", ce2->name->val, str_name, ce->name->val); -- cgit v1.2.1 From 30c20084d78e7a3c02d1b74ebda0975624d5f9bd Mon Sep 17 00:00:00 2001 From: Xinchen Hui Date: Sun, 2 Mar 2014 21:36:51 +0800 Subject: Fixed memory leak --- ext/reflection/php_reflection.c | 1 + 1 file changed, 1 insertion(+) (limited to 'ext/reflection/php_reflection.c') diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index e19a8661cc..16323923ea 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -5437,6 +5437,7 @@ ZEND_METHOD(reflection_extension, getDependencies) dep->version ? " " : "", dep->version ? dep->version : ""); add_assoc_stringl(return_value, dep->name, relation, len, 0); + efree(relation); dep++; } } -- cgit v1.2.1 From 4eeee08ec8d82cf2cfb39a43ee764b4632a0a074 Mon Sep 17 00:00:00 2001 From: Xinchen Hui Date: Sun, 2 Mar 2014 21:40:20 +0800 Subject: Fixed getClosureThis() --- ext/reflection/php_reflection.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ext/reflection/php_reflection.c') diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 16323923ea..f1db730c8a 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -1691,7 +1691,7 @@ ZEND_METHOD(reflection_function, getClosureThis) GET_REFLECTION_OBJECT_PTR(fptr); if (!ZVAL_IS_UNDEF(&intern->obj)) { closure_this = zend_get_closure_this_ptr(&intern->obj TSRMLS_CC); - if (closure_this) { + if (!ZVAL_IS_UNDEF(closure_this)) { RETURN_ZVAL(closure_this, 1, 0); } } -- cgit v1.2.1 From 35742a74e230a3ccee2badc43de7ee5a348fe9cb Mon Sep 17 00:00:00 2001 From: Xinchen Hui Date: Sun, 2 Mar 2014 21:42:21 +0800 Subject: Fixed zend_string --- ext/reflection/php_reflection.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ext/reflection/php_reflection.c') diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index f1db730c8a..8111de92f7 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -3462,7 +3462,7 @@ ZEND_METHOD(reflection_class, setStaticPropertyValue) variable_ptr = zend_std_get_static_property(ce, name, 1, NULL TSRMLS_CC); if (!variable_ptr) { zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, - "Class %s does not have a property named %s", ce->name->val, name); + "Class %s does not have a property named %s", ce->name->val, name->val); return; } //??? refcount = Z_REFCOUNT_PP(variable_ptr); -- cgit v1.2.1 From 18363f42b2bb915009a052e330848ba70ead506b Mon Sep 17 00:00:00 2001 From: Xinchen Hui Date: Sun, 2 Mar 2014 21:44:17 +0800 Subject: Fixed invalid free --- ext/reflection/php_reflection.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ext/reflection/php_reflection.c') diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 8111de92f7..98d90a9bf6 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -304,7 +304,7 @@ static void reflection_free_objects_storage(zend_object *object TSRMLS_DC) /* {{ break; case REF_TYPE_DYNAMIC_PROPERTY: prop_reference = (property_reference*)intern->ptr; - efree((char*)prop_reference->prop.name); + STR_RELEASE(prop_reference->prop.name); efree(intern->ptr); break; case REF_TYPE_OTHER: -- cgit v1.2.1 From 8cb468d5e3e234ca939ac55c5ef36d958c864ee4 Mon Sep 17 00:00:00 2001 From: Xinchen Hui Date: Sun, 2 Mar 2014 21:48:38 +0800 Subject: Fixed wrong condition (introduced by previous ci) --- ext/reflection/php_reflection.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ext/reflection/php_reflection.c') diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 98d90a9bf6..fbec2788f4 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -3698,7 +3698,7 @@ ZEND_METHOD(reflection_class, getMethod) method and not the closure definition itself */ reflection_method_factory(ce, mptr, NULL, return_value TSRMLS_CC); efree(lc_name); - } else if (ce == zend_ce_closure && !ZVAL_IS_UNDEF(&intern->obj) && (name_len == sizeof(ZEND_INVOKE_FUNC_NAME)-1) + } else if (ce == zend_ce_closure && ZVAL_IS_UNDEF(&intern->obj) && (name_len == sizeof(ZEND_INVOKE_FUNC_NAME)-1) && memcmp(lc_name, ZEND_INVOKE_FUNC_NAME, sizeof(ZEND_INVOKE_FUNC_NAME)-1) == 0 && object_init_ex(&obj_tmp, ce) == SUCCESS && (mptr = zend_get_closure_invoke_method(&obj_tmp TSRMLS_CC)) != NULL) { /* don't assign closure_object since we only reflect the invoke handler -- cgit v1.2.1 From 6ed82f71046768e42302539d7ff206cfaff87631 Mon Sep 17 00:00:00 2001 From: Xinchen Hui Date: Sun, 2 Mar 2014 21:54:46 +0800 Subject: Use zend_string to avoid memleak --- ext/reflection/php_reflection.c | 56 +++++++++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 22 deletions(-) (limited to 'ext/reflection/php_reflection.c') diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index fbec2788f4..032bee2283 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -4466,14 +4466,14 @@ ZEND_METHOD(reflection_class, getTraitAliases) if (ce->trait_aliases) { zend_uint i = 0; while (ce->trait_aliases[i]) { - char *method_name; - int method_name_len; + zend_string *mname; zend_trait_method_reference *cur_ref = ce->trait_aliases[i]->trait_method; if (ce->trait_aliases[i]->alias) { - method_name_len = spprintf(&method_name, 0, "%s::%s", cur_ref->ce->name->val, cur_ref->method_name->val); -//??? - add_assoc_stringl_ex(return_value, ce->trait_aliases[i]->alias->val, ce->trait_aliases[i]->alias->len, method_name, method_name_len, 0); + + mname = STR_ALLOC(cur_ref->ce->name->len + cur_ref->method_name->len + 2, 0); + snprintf(mname->val, mname->len + 1, "%s::%s", cur_ref->ce->name->val, cur_ref->method_name->val); + add_assoc_str_ex(return_value, ce->trait_aliases[i]->alias->val, ce->trait_aliases[i]->alias->len, mname); } i++; } @@ -5411,33 +5411,45 @@ ZEND_METHOD(reflection_extension, getDependencies) } while(dep->name) { - char *relation; + zend_string *relation; char *rel_type; - int len; + int len = 0; switch(dep->type) { - case MODULE_DEP_REQUIRED: - rel_type = "Required"; - break; - case MODULE_DEP_CONFLICTS: - rel_type = "Conflicts"; - break; - case MODULE_DEP_OPTIONAL: - rel_type = "Optional"; - break; - default: - rel_type = "Error"; /* shouldn't happen */ - break; + case MODULE_DEP_REQUIRED: + rel_type = "Required"; + len += sizeof("Required") - 1; + break; + case MODULE_DEP_CONFLICTS: + rel_type = "Conflicts"; + len += sizeof("Conflicts") - 1; + break; + case MODULE_DEP_OPTIONAL: + rel_type = "Optional"; + len += sizeof("Optional") - 1; + break; + default: + rel_type = "Error"; /* shouldn't happen */ + len += sizeof("Error") - 1; + break; + } + + if (dep->rel) { + len += strlen(dep->rel) + 1; + } + + if (dep->version) { + len += strlen(dep->version) + 1; } - len = spprintf(&relation, 0, "%s%s%s%s%s", + relation = STR_ALLOC(len, 0); + snprintf(relation->val, relation->len + 1, "%s%s%s%s%s", rel_type, dep->rel ? " " : "", dep->rel ? dep->rel : "", dep->version ? " " : "", dep->version ? dep->version : ""); - add_assoc_stringl(return_value, dep->name, relation, len, 0); - efree(relation); + add_assoc_str(return_value, dep->name, relation); dep++; } } -- cgit v1.2.1 From 19670c2bbcd5fc1339e160929cc81db3ae940392 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Wed, 5 Mar 2014 01:54:21 +0400 Subject: Fixied calling object closures from internal functions --- ext/reflection/php_reflection.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'ext/reflection/php_reflection.c') diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 032bee2283..3c74ff75ba 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -1388,7 +1388,7 @@ static void _reflection_export(INTERNAL_FUNCTION_PARAMETERS, zend_class_entry *c fcc.function_handler = ce_ptr->constructor; fcc.calling_scope = ce_ptr; fcc.called_scope = Z_OBJCE(reflector); - fcc.object_ptr = &reflector; + ZVAL_COPY_VALUE(&fcc.object, &reflector); result = zend_call_function(&fci, &fcc TSRMLS_CC); @@ -1904,7 +1904,7 @@ ZEND_METHOD(reflection_function, invoke) fcc.function_handler = fptr; fcc.calling_scope = EG(scope); fcc.called_scope = NULL; - fcc.object_ptr = NULL; + ZVAL_UNDEF(&fcc.object); result = zend_call_function(&fci, &fcc TSRMLS_CC); @@ -1972,7 +1972,7 @@ ZEND_METHOD(reflection_function, invokeArgs) fcc.function_handler = fptr; fcc.calling_scope = EG(scope); fcc.called_scope = NULL; - fcc.object_ptr = NULL; + ZVAL_UNDEF(&fcc.object); result = zend_call_function(&fci, &fcc TSRMLS_CC); @@ -2886,7 +2886,7 @@ ZEND_METHOD(reflection_method, invoke) fcc.function_handler = mptr; fcc.calling_scope = obj_ce; fcc.called_scope = intern->ce; - fcc.object_ptr = &object; + ZVAL_COPY_VALUE(&fcc.object, &object); result = zend_call_function(&fci, &fcc TSRMLS_CC); @@ -2995,7 +2995,7 @@ ZEND_METHOD(reflection_method, invokeArgs) fcc.function_handler = mptr; fcc.calling_scope = obj_ce; fcc.called_scope = intern->ce; - fcc.object_ptr = object; + ZVAL_COPY_VALUE(&fcc.object, object); /* * Copy the zend_function when calling via handler (e.g. Closure::__invoke()) @@ -4228,7 +4228,7 @@ ZEND_METHOD(reflection_class, newInstance) fcc.function_handler = constructor; fcc.calling_scope = EG(scope); fcc.called_scope = Z_OBJCE_P(return_value); - fcc.object_ptr = return_value; + ZVAL_COPY_VALUE(&fcc.object, return_value); if (zend_call_function(&fci, &fcc TSRMLS_CC) == FAILURE) { if (params) { @@ -4333,7 +4333,7 @@ ZEND_METHOD(reflection_class, newInstanceArgs) fcc.function_handler = constructor; fcc.calling_scope = EG(scope); fcc.called_scope = Z_OBJCE_P(return_value); - fcc.object_ptr = return_value; + ZVAL_COPY_VALUE(&fcc.object, return_value); if (zend_call_function(&fci, &fcc TSRMLS_CC) == FAILURE) { if (params) { -- cgit v1.2.1 From 040dea8b82a00083b3975351271f34f3775d9a60 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Wed, 5 Mar 2014 11:10:52 +0400 Subject: Arguments taken by internal functions using zend_parse_parameters() with "+" and "*" specifications must not be deallocated anymore. --- ext/reflection/php_reflection.c | 21 --------------------- 1 file changed, 21 deletions(-) (limited to 'ext/reflection/php_reflection.c') diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 3c74ff75ba..c236f0d765 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -1908,10 +1908,6 @@ ZEND_METHOD(reflection_function, invoke) result = zend_call_function(&fci, &fcc TSRMLS_CC); - if (num_args) { - efree(params); - } - if (result == FAILURE) { zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Invocation of function %s() failed", fptr->common.function_name->val); @@ -2854,7 +2850,6 @@ ZEND_METHOD(reflection_method, invoke) obj_ce = mptr->common.scope; } else { if (Z_TYPE(params[0]) != IS_OBJECT) { - efree(params); _DO_THROW("Non-object passed to Invoke()"); /* Returns from this function */ } @@ -2862,9 +2857,6 @@ ZEND_METHOD(reflection_method, invoke) obj_ce = Z_OBJCE(params[0]); if (!instanceof_function(obj_ce, mptr->common.scope TSRMLS_CC)) { - if (params) { - efree(params); - } _DO_THROW("Given object is not an instance of the class this method was declared in"); /* Returns from this function */ } @@ -2890,10 +2882,6 @@ ZEND_METHOD(reflection_method, invoke) result = zend_call_function(&fci, &fcc TSRMLS_CC); - if (params) { - efree(params); - } - if (result == FAILURE) { zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Invocation of method %s::%s() failed", mptr->common.scope->name->val, mptr->common.function_name->val); @@ -4207,9 +4195,6 @@ ZEND_METHOD(reflection_class, newInstance) } if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "*", ¶ms, &num_args) == FAILURE) { - if (params) { - efree(params); - } zval_dtor(return_value); RETURN_FALSE; } @@ -4231,9 +4216,6 @@ ZEND_METHOD(reflection_class, newInstance) ZVAL_COPY_VALUE(&fcc.object, return_value); if (zend_call_function(&fci, &fcc TSRMLS_CC) == FAILURE) { - if (params) { - efree(params); - } if (!ZVAL_IS_UNDEF(&retval)) { zval_ptr_dtor(&retval); } @@ -4244,9 +4226,6 @@ ZEND_METHOD(reflection_class, newInstance) if (!ZVAL_IS_UNDEF(&retval)) { zval_ptr_dtor(&retval); } - if (params) { - efree(params); - } } else if (ZEND_NUM_ARGS()) { zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Class %s does not have a constructor, so you cannot pass any constructor arguments", ce->name->val); } -- cgit v1.2.1 From 37337373287544f39d696c2fb357a56e99e6cecc Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Wed, 5 Mar 2014 13:55:56 +0400 Subject: Handle interned strings as non-refcounted scalars --- ext/reflection/php_reflection.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ext/reflection/php_reflection.c') diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index c236f0d765..20d644d804 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -45,7 +45,7 @@ zval member; \ ZVAL_STRINGL(&member, name, sizeof(name)-1); \ zend_std_write_property(object, &member, value, NULL TSRMLS_CC); \ - Z_DELREF_P(value); \ + if (Z_REFCOUNTED_P(value)) Z_DELREF_P(value); \ zval_ptr_dtor(&member); \ } while (0) -- cgit v1.2.1 From 466dbfee888a52d0bd4918321f072516e2065f0d Mon Sep 17 00:00:00 2001 From: Xinchen Hui Date: Mon, 17 Mar 2014 12:05:52 +0800 Subject: Fixed NULL pointer dereference --- ext/reflection/php_reflection.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'ext/reflection/php_reflection.c') diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 20d644d804..c6fa805d98 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -2983,7 +2983,11 @@ ZEND_METHOD(reflection_method, invokeArgs) fcc.function_handler = mptr; fcc.calling_scope = obj_ce; fcc.called_scope = intern->ce; - ZVAL_COPY_VALUE(&fcc.object, object); + if (object) { + ZVAL_COPY_VALUE(&fcc.object, object); + } else { + ZVAL_UNDEF(&fcc.object); + } /* * Copy the zend_function when calling via handler (e.g. Closure::__invoke()) -- cgit v1.2.1 From 897a4d255aa297fb3aaca09c30f884daac2704b8 Mon Sep 17 00:00:00 2001 From: Xinchen Hui Date: Mon, 17 Mar 2014 12:15:22 +0800 Subject: Refactor reflection_object to fix bug after default_properties changed --- ext/reflection/php_reflection.c | 58 +++++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 26 deletions(-) (limited to 'ext/reflection/php_reflection.c') diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index c6fa805d98..e01cd24821 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -99,7 +99,7 @@ ZEND_DECLARE_MODULE_GLOBALS(reflection) } #define GET_REFLECTION_OBJECT_PTR(target) \ - intern = (reflection_object *) Z_OBJ_P(getThis()); \ + intern = Z_REFLECTION_P(getThis()); \ if (intern == NULL || intern->ptr == NULL) { \ RETURN_ON_EXCEPTION \ php_error_docref(NULL TSRMLS_CC, E_ERROR, "Internal error: Failed to retrieve the reflection object"); \ @@ -205,15 +205,20 @@ typedef enum { /* Struct for reflection objects */ typedef struct { - zend_object zo; zval dummy; /* holder for the second property */ void *ptr; reflection_type_t ref_type; zval obj; zend_class_entry *ce; unsigned int ignore_visibility:1; + zend_object zo; } reflection_object; +static inline reflection_object *reflection_object_from_obj(zend_object *obj) /* {{{ */ { + return (reflection_object*)((char*)(obj) - XtOffsetOf(reflection_object, zo)); +} + +#define Z_REFLECTION_P(zv) reflection_object_from_obj(Z_OBJ_P((zv))) /* }}} */ static zend_object_handlers reflection_object_handlers; @@ -285,7 +290,7 @@ static void _free_function(zend_function *fptr TSRMLS_DC) /* {{{ */ static void reflection_free_objects_storage(zend_object *object TSRMLS_DC) /* {{{ */ { - reflection_object *intern = (reflection_object *) object; + reflection_object *intern = reflection_object_from_obj(object); parameter_reference *reference; property_reference *prop_reference; @@ -313,7 +318,8 @@ static void reflection_free_objects_storage(zend_object *object TSRMLS_DC) /* {{ } intern->ptr = NULL; zval_ptr_dtor(&intern->obj); - zend_object_free(object TSRMLS_CC); + zend_object_std_dtor(object TSRMLS_CC); + efree(intern); } /* }}} */ @@ -321,17 +327,17 @@ static zend_object *reflection_objects_new(zend_class_entry *class_type TSRMLS_D { reflection_object *intern; - intern = ecalloc(1, sizeof(reflection_object)); + intern = ecalloc(1, sizeof(reflection_object) + sizeof(zval) * (class_type->default_properties_count - 1)); intern->zo.ce = class_type; zend_object_std_init(&intern->zo, class_type TSRMLS_CC); object_properties_init(&intern->zo, class_type); intern->zo.handlers = &reflection_object_handlers; - return (zend_object*)intern; + return &intern->zo; } /* }}} */ -static zval * reflection_instantiate(zend_class_entry *pce, zval *object TSRMLS_DC) /* {{{ */ +static zval *reflection_instantiate(zend_class_entry *pce, zval *object TSRMLS_DC) /* {{{ */ { object_init_ex(object, pce); return object; @@ -1184,7 +1190,7 @@ PHPAPI void zend_reflection_class_factory(zend_class_entry *ce, zval *object TSR ZVAL_STR(&name, STR_COPY(ce->name)); reflection_instantiate(reflection_class_ptr, object TSRMLS_CC); - intern = (reflection_object *) Z_STR_P(object); + intern = Z_REFLECTION_P(object); intern->ptr = ce; intern->ref_type = REF_TYPE_OTHER; intern->ce = ce; @@ -1210,7 +1216,7 @@ static void reflection_extension_factory(zval *object, const char *name_str TSRM } reflection_instantiate(reflection_extension_ptr, object TSRMLS_CC); - intern = (reflection_object *) Z_OBJ_P(object); + intern = Z_REFLECTION_P(object); ZVAL_STRINGL(&name, module->name, name_len); intern->ptr = module; intern->ref_type = REF_TYPE_OTHER; @@ -1232,7 +1238,7 @@ static void reflection_parameter_factory(zend_function *fptr, zval *closure_obje ZVAL_NULL(&name); } reflection_instantiate(reflection_parameter_ptr, object TSRMLS_CC); - intern = (reflection_object *) Z_OBJ_P(object); + intern = Z_REFLECTION_P(object); reference = (parameter_reference*) emalloc(sizeof(parameter_reference)); reference->arg_info = arg_info; reference->offset = offset; @@ -1258,7 +1264,7 @@ static void reflection_function_factory(zend_function *function, zval *closure_o ZVAL_STR(&name, STR_COPY(function->common.function_name)); reflection_instantiate(reflection_function_ptr, object TSRMLS_CC); - intern = (reflection_object *) Z_OBJ_P(object); + intern = Z_REFLECTION_P(object); intern->ptr = function; intern->ref_type = REF_TYPE_FUNCTION; intern->ce = NULL; @@ -1281,7 +1287,7 @@ static void reflection_method_factory(zend_class_entry *ce, zend_function *metho zend_resolve_method_name(ce, method) : method->common.function_name)); ZVAL_STR(&classname, STR_COPY(method->common.scope->name)); reflection_instantiate(reflection_method_ptr, object TSRMLS_CC); - intern = (reflection_object *) Z_OBJ_P(object); + intern = Z_REFLECTION_P(object); intern->ptr = method; intern->ref_type = REF_TYPE_FUNCTION; intern->ce = ce; @@ -1326,7 +1332,7 @@ static void reflection_property_factory(zend_class_entry *ce, zend_property_info ZVAL_STR(&classname, STR_COPY(prop->ce->name)); reflection_instantiate(reflection_property_ptr, object TSRMLS_CC); - intern = (reflection_object *) Z_OBJ_P(object); + intern = Z_REFLECTION_P(object); reference = (property_reference*) emalloc(sizeof(property_reference)); reference->ce = ce; reference->prop = *prop; @@ -1443,7 +1449,7 @@ static parameter_reference *_reflection_param_get_default_param(INTERNAL_FUNCTIO reflection_object *intern; parameter_reference *param; - intern = (reflection_object *) Z_OBJ_P(getThis()); + intern = Z_REFLECTION_P(getThis()); if (intern == NULL || intern->ptr == NULL) { if (EG(exception) && EG(exception)->ce == reflection_exception_ptr) { return NULL; @@ -1589,7 +1595,7 @@ ZEND_METHOD(reflection_function, __construct) int name_len; object = getThis(); - intern = (reflection_object *) Z_OBJ_P(object); + intern = Z_REFLECTION_P(object); if (intern == NULL) { return; } @@ -2130,7 +2136,7 @@ ZEND_METHOD(reflection_parameter, __construct) } object = getThis(); - intern = (reflection_object *) Z_OBJ_P(object); + intern = Z_REFLECTION_P(object); if (intern == NULL) { return; } @@ -2687,7 +2693,7 @@ ZEND_METHOD(reflection_method, __construct) } object = getThis(); - intern = (reflection_object *) Z_OBJ_P(object); + intern = Z_REFLECTION_P(object); if (intern == NULL) { return; } @@ -3256,7 +3262,7 @@ ZEND_METHOD(reflection_method, setAccessible) return; } - intern = (reflection_object *) Z_OBJ_P(getThis()); + intern = Z_REFLECTION_P(getThis()); if (intern == NULL) { return; @@ -3294,7 +3300,7 @@ static void reflection_class_object_ctor(INTERNAL_FUNCTION_PARAMETERS, int is_ob } object = getThis(); - intern = (reflection_object *) Z_OBJ_P(object); + intern = Z_REFLECTION_P(object); if (intern == NULL) { return; } @@ -3846,7 +3852,7 @@ ZEND_METHOD(reflection_class, getProperty) property_info_tmp.ce = ce; reflection_property_factory(ce, &property_info_tmp, return_value TSRMLS_CC); - intern = (reflection_object *) Z_OBJ_P(return_value); + intern = Z_REFLECTION_P(return_value); intern->ref_type = REF_TYPE_DYNAMIC_PROPERTY; return; } @@ -4509,7 +4515,7 @@ ZEND_METHOD(reflection_class, isSubclassOf) break; case IS_OBJECT: if (instanceof_function(Z_OBJCE_P(class_name), reflection_class_ptr TSRMLS_CC)) { - argument = (reflection_object *) Z_OBJ_P(class_name); + argument = Z_REFLECTION_P(class_name); if (argument == NULL || argument->ptr == NULL) { php_error_docref(NULL TSRMLS_CC, E_ERROR, "Internal error: Failed to retrieve the argument's reflection object"); /* Bails out */ @@ -4553,7 +4559,7 @@ ZEND_METHOD(reflection_class, implementsInterface) break; case IS_OBJECT: if (instanceof_function(Z_OBJCE_P(interface), reflection_class_ptr TSRMLS_CC)) { - argument = (reflection_object *) Z_OBJ_P(interface); + argument = Z_REFLECTION_P(interface); if (argument == NULL || argument->ptr == NULL) { php_error_docref(NULL TSRMLS_CC, E_ERROR, "Internal error: Failed to retrieve the argument's reflection object"); /* Bails out */ @@ -4749,7 +4755,7 @@ ZEND_METHOD(reflection_property, __construct) } object = getThis(); - intern = (reflection_object *) Z_OBJ_P(object); + intern = Z_REFLECTION_P(object); if (intern == NULL) { return; } @@ -5112,7 +5118,7 @@ ZEND_METHOD(reflection_property, setAccessible) return; } - intern = (reflection_object *) Z_OBJ_P(getThis()); + intern = Z_REFLECTION_P(getThis()); if (intern == NULL) { return; @@ -5148,7 +5154,7 @@ ZEND_METHOD(reflection_extension, __construct) } object = getThis(); - intern = (reflection_object *) Z_OBJ_P(object); + intern = Z_REFLECTION_P(object); if (intern == NULL) { return; } @@ -5510,7 +5516,7 @@ ZEND_METHOD(reflection_zend_extension, __construct) } object = getThis(); - intern = (reflection_object *) Z_OBJ_P(object); + intern = Z_REFLECTION_P(object); if (intern == NULL) { return; } -- cgit v1.2.1 From 7d8e990f29183dd6dd6f2892a79e7c7135f54032 Mon Sep 17 00:00:00 2001 From: Xinchen Hui Date: Mon, 17 Mar 2014 12:16:46 +0800 Subject: Fixed add_ref asseration fail --- ext/reflection/php_reflection.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ext/reflection/php_reflection.c') diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index e01cd24821..4531e3b1d5 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -5019,7 +5019,7 @@ ZEND_METHOD(reflection_property, setValue) /* To check: can't *variable_ptr be some system variable like error_zval here? */ ZVAL_COPY_VALUE(variable_ptr, value); - if (Z_REFCOUNT_P(value) > 0) { + if (Z_REFCOUNTED_P(value) && Z_REFCOUNT_P(value) > 0) { zval_copy_ctor(variable_ptr); } zval_dtor(&garbage); -- cgit v1.2.1 From 648f1081c971ff1ed96e1d45c72f4cbaca5ec148 Mon Sep 17 00:00:00 2001 From: Xinchen Hui Date: Mon, 17 Mar 2014 12:32:42 +0800 Subject: Fixed function name comparation --- ext/reflection/php_reflection.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ext/reflection/php_reflection.c') diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 4531e3b1d5..9c822029fe 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -608,7 +608,7 @@ static void _class_string(string *str, zend_class_entry *ce, zval *obj, char *in if ((mptr->common.fn_flags & ZEND_ACC_CTOR) == 0 || mptr->common.scope == ce || zend_hash_get_current_key_ex(&ce->function_table, &key, &num_index, 0, &pos) != HASH_KEY_IS_STRING - || zend_binary_strcasecmp(key->val, key->len-1, mptr->common.function_name->val, len) == 0) + || zend_binary_strcasecmp(key->val, key->len, mptr->common.function_name->val, len) == 0) { zend_function *closure; /* see if this is a closure */ -- cgit v1.2.1 From b7938ab1bd765897bd6f08a48a8aea494a961ea9 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Wed, 19 Mar 2014 17:00:28 +0400 Subject: Refactored GC (incomplete) --- ext/reflection/php_reflection.c | 1 + 1 file changed, 1 insertion(+) (limited to 'ext/reflection/php_reflection.c') diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 9c822029fe..148dae4378 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -319,6 +319,7 @@ static void reflection_free_objects_storage(zend_object *object TSRMLS_DC) /* {{ intern->ptr = NULL; zval_ptr_dtor(&intern->obj); zend_object_std_dtor(object TSRMLS_CC); + GC_REMOVE_FROM_BUFFER(object); efree(intern); } /* }}} */ -- cgit v1.2.1 From 887189ca31eeac5f1f7dbcaf54405de0dc432f2d Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Wed, 26 Mar 2014 18:07:31 +0400 Subject: Refactored IS_INDIRECT usage for CV and object properties to support HashTable resizing --- ext/reflection/php_reflection.c | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) (limited to 'ext/reflection/php_reflection.c') diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 148dae4378..53101b4623 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -223,14 +223,23 @@ static inline reflection_object *reflection_object_from_obj(zend_object *obj) /* static zend_object_handlers reflection_object_handlers; +static zval *_default_load_entry(zval *object, char *name, int name_len TSRMLS_DC) /* {{{ */ +{ + zval *value; + + if ((value = zend_hash_str_find_ind(Z_OBJPROP_P(object), name, name_len)) == NULL) { + return NULL; + } + return value; +} + static void _default_get_entry(zval *object, char *name, int name_len, zval *return_value TSRMLS_DC) /* {{{ */ { zval *value; - if ((value = zend_hash_str_find(Z_OBJPROP_P(object), name, name_len)) == NULL) { + if ((value = _default_load_entry(object, name, name_len TSRMLS_CC)) == NULL) { RETURN_FALSE; } - ZVAL_DUP(return_value, value); } /* }}} */ @@ -3102,7 +3111,7 @@ ZEND_METHOD(reflection_function, inNamespace) if (zend_parse_parameters_none() == FAILURE) { return; } - if ((name = zend_hash_str_find(Z_OBJPROP_P(getThis()), "name", sizeof("name")-1)) == NULL) { + if ((name = _default_load_entry(getThis(), "name", sizeof("name")-1) TSRMLS_CC) == NULL) { RETURN_FALSE; } if (Z_TYPE_P(name) == IS_STRING @@ -3125,7 +3134,7 @@ ZEND_METHOD(reflection_function, getNamespaceName) if (zend_parse_parameters_none() == FAILURE) { return; } - if ((name = zend_hash_str_find(Z_OBJPROP_P(getThis()), "name", sizeof("name")-1)) == NULL) { + if ((name = _default_load_entry(getThis(), "name", sizeof("name")-1) TSRMLS_CC) == NULL) { RETURN_FALSE; } if (Z_TYPE_P(name) == IS_STRING @@ -3148,7 +3157,7 @@ ZEND_METHOD(reflection_function, getShortName) if (zend_parse_parameters_none() == FAILURE) { return; } - if ((name = zend_hash_str_find(Z_OBJPROP_P(getThis()), "name", sizeof("name")-1)) == NULL) { + if ((name = _default_load_entry(getThis(), "name", sizeof("name")-1) TSRMLS_CC) == NULL) { RETURN_FALSE; } if (Z_TYPE_P(name) == IS_STRING @@ -4654,7 +4663,7 @@ ZEND_METHOD(reflection_class, inNamespace) if (zend_parse_parameters_none() == FAILURE) { return; } - if ((name = zend_hash_str_find(Z_OBJPROP_P(getThis()), "name", sizeof("name")-1)) == NULL) { + if ((name = _default_load_entry(getThis(), "name", sizeof("name")-1) TSRMLS_CC) == NULL) { RETURN_FALSE; } if (Z_TYPE_P(name) == IS_STRING @@ -4677,7 +4686,7 @@ ZEND_METHOD(reflection_class, getNamespaceName) if (zend_parse_parameters_none() == FAILURE) { return; } - if ((name = zend_hash_str_find(Z_OBJPROP_P(getThis()), "name", sizeof("name")-1)) == NULL) { + if ((name = _default_load_entry(getThis(), "name", sizeof("name")-1) TSRMLS_CC) == NULL) { RETURN_FALSE; } if (Z_TYPE_P(name) == IS_STRING @@ -4700,7 +4709,7 @@ ZEND_METHOD(reflection_class, getShortName) if (zend_parse_parameters_none() == FAILURE) { return; } - if ((name = zend_hash_str_find(Z_OBJPROP_P(getThis()), "name", sizeof("name")-1)) == NULL) { + if ((name = _default_load_entry(getThis(), "name", sizeof("name")-1) TSRMLS_CC) == NULL) { RETURN_FALSE; } if (Z_TYPE_P(name) == IS_STRING @@ -4937,17 +4946,16 @@ ZEND_METHOD(reflection_property, getValue) { reflection_object *intern; property_reference *ref; - zval *object, name; + zval *object, *name; zval *member_p = NULL; METHOD_NOTSTATIC(reflection_property_ptr); GET_REFLECTION_OBJECT_PTR(ref); if (!(ref->prop.flags & (ZEND_ACC_PUBLIC | ZEND_ACC_IMPLICIT_PUBLIC)) && intern->ignore_visibility == 0) { - _default_get_entry(getThis(), "name", sizeof("name")-1, &name TSRMLS_CC); + name = _default_load_entry(getThis(), "name", sizeof("name")-1 TSRMLS_CC); zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, - "Cannot access non-public member %s::%s", intern->ce->name->val, Z_STRVAL(name)); - zval_dtor(&name); + "Cannot access non-public member %s::%s", intern->ce->name->val, Z_STRVAL_P(name)); return; } @@ -4984,7 +4992,7 @@ ZEND_METHOD(reflection_property, setValue) reflection_object *intern; property_reference *ref; zval *variable_ptr; - zval *object, name; + zval *object, *name; zval *value; zval *tmp; @@ -4992,10 +5000,9 @@ ZEND_METHOD(reflection_property, setValue) GET_REFLECTION_OBJECT_PTR(ref); if (!(ref->prop.flags & ZEND_ACC_PUBLIC) && intern->ignore_visibility == 0) { - _default_get_entry(getThis(), "name", sizeof("name")-1, &name TSRMLS_CC); + name = _default_load_entry(getThis(), "name", sizeof("name")-1 TSRMLS_CC); zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, - "Cannot access non-public member %s::%s", intern->ce->name->val, Z_STRVAL(name)); - zval_dtor(&name); + "Cannot access non-public member %s::%s", intern->ce->name->val, Z_STRVAL_P(name)); return; } -- cgit v1.2.1 From ea85451b65b904d0670c4011c819a15431720432 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Fri, 28 Mar 2014 02:11:22 +0400 Subject: Refactored data structures to keep zend_object* instead of a whole zval in some places --- ext/reflection/php_reflection.c | 60 +++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 32 deletions(-) (limited to 'ext/reflection/php_reflection.c') diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 53101b4623..20d3eb0e73 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -83,7 +83,7 @@ ZEND_DECLARE_MODULE_GLOBALS(reflection) /* Method macros */ #define METHOD_NOTSTATIC(ce) \ - if (!this_ptr || !instanceof_function(Z_OBJCE_P(this_ptr), ce TSRMLS_CC)) { \ + if (!Z_OBJ(EG(This)) || !instanceof_function(Z_OBJCE(EG(This)), ce TSRMLS_CC)) { \ php_error_docref(NULL TSRMLS_CC, E_ERROR, "%s() cannot be called statically", get_active_function_name(TSRMLS_C)); \ return; \ } \ @@ -624,7 +624,7 @@ static void _class_string(string *str, zend_class_entry *ce, zval *obj, char *in /* see if this is a closure */ if (ce == zend_ce_closure && obj && (len == sizeof(ZEND_INVOKE_FUNC_NAME)-1) && memcmp(mptr->common.function_name->val, ZEND_INVOKE_FUNC_NAME, sizeof(ZEND_INVOKE_FUNC_NAME)-1) == 0 - && (closure = zend_get_closure_invoke_method(obj TSRMLS_CC)) != NULL) + && (closure = zend_get_closure_invoke_method(Z_OBJ_P(obj) TSRMLS_CC)) != NULL) { mptr = closure; } else { @@ -1394,7 +1394,7 @@ static void _reflection_export(INTERNAL_FUNCTION_PARAMETERS, zend_class_entry *c fci.function_table = NULL; ZVAL_UNDEF(&fci.function_name); fci.symbol_table = NULL; - fci.object_ptr = &reflector; + fci.object = Z_OBJ(reflector); fci.retval = &retval; fci.param_count = ctor_argc; fci.params = params; @@ -1404,7 +1404,7 @@ static void _reflection_export(INTERNAL_FUNCTION_PARAMETERS, zend_class_entry *c fcc.function_handler = ce_ptr->constructor; fcc.calling_scope = ce_ptr; fcc.called_scope = Z_OBJCE(reflector); - ZVAL_COPY_VALUE(&fcc.object, &reflector); + fcc.object = Z_OBJ(reflector); result = zend_call_function(&fci, &fcc TSRMLS_CC); @@ -1426,7 +1426,7 @@ static void _reflection_export(INTERNAL_FUNCTION_PARAMETERS, zend_class_entry *c ZVAL_STRINGL(&fci.function_name, "reflection::export", sizeof("reflection::export") - 1); fci.function_table = &reflection_ptr->function_table; - fci.object_ptr = NULL; + fci.object = NULL; fci.retval = &retval; fci.param_count = 2; fci.params = params; @@ -1910,7 +1910,7 @@ ZEND_METHOD(reflection_function, invoke) fci.function_table = NULL; ZVAL_UNDEF(&fci.function_name); fci.symbol_table = NULL; - fci.object_ptr = NULL; + fci.object = NULL; fci.retval = &retval; fci.param_count = num_args; fci.params = params; @@ -1920,7 +1920,7 @@ ZEND_METHOD(reflection_function, invoke) fcc.function_handler = fptr; fcc.calling_scope = EG(scope); fcc.called_scope = NULL; - ZVAL_UNDEF(&fcc.object); + fcc.object = NULL; result = zend_call_function(&fci, &fcc TSRMLS_CC); @@ -1974,7 +1974,7 @@ ZEND_METHOD(reflection_function, invokeArgs) fci.function_table = NULL; ZVAL_UNDEF(&fci.function_name); fci.symbol_table = NULL; - fci.object_ptr = NULL; + fci.object = NULL; fci.retval = &retval; fci.param_count = argc; fci.params = params; @@ -1984,7 +1984,7 @@ ZEND_METHOD(reflection_function, invokeArgs) fcc.function_handler = fptr; fcc.calling_scope = EG(scope); fcc.called_scope = NULL; - ZVAL_UNDEF(&fcc.object); + fcc.object = NULL; result = zend_call_function(&fci, &fcc TSRMLS_CC); @@ -2200,7 +2200,7 @@ ZEND_METHOD(reflection_parameter, __construct) if (ce == zend_ce_closure && Z_TYPE_P(classref) == IS_OBJECT && (lcname_len == sizeof(ZEND_INVOKE_FUNC_NAME)-1) && memcmp(lcname, ZEND_INVOKE_FUNC_NAME, sizeof(ZEND_INVOKE_FUNC_NAME)-1) == 0 - && (fptr = zend_get_closure_invoke_method(classref TSRMLS_CC)) != NULL) + && (fptr = zend_get_closure_invoke_method(Z_OBJ_P(classref) TSRMLS_CC)) != NULL) { /* nothing to do. don't set is_closure since is the invoke handler, - not the closure itself */ @@ -2741,7 +2741,7 @@ ZEND_METHOD(reflection_method, __construct) if (ce == zend_ce_closure && orig_obj && (name_len == sizeof(ZEND_INVOKE_FUNC_NAME)-1) && memcmp(lcname, ZEND_INVOKE_FUNC_NAME, sizeof(ZEND_INVOKE_FUNC_NAME)-1) == 0 - && (mptr = zend_get_closure_invoke_method(orig_obj TSRMLS_CC)) != NULL) + && (mptr = zend_get_closure_invoke_method(Z_OBJ_P(orig_obj) TSRMLS_CC)) != NULL) { /* do nothing, mptr already set */ } else if ((mptr = zend_hash_str_find_ptr(&ce->function_table, lcname, name_len)) == NULL) { @@ -2821,7 +2821,7 @@ ZEND_METHOD(reflection_method, invoke) { zval retval; zval *params = NULL; - zval object; + zend_object *object; reflection_object *intern; zend_function *mptr; int result, num_args = 0; @@ -2862,7 +2862,7 @@ ZEND_METHOD(reflection_method, invoke) * Else, we verify that the given object is an instance of the class. */ if (mptr->common.fn_flags & ZEND_ACC_STATIC) { - ZVAL_UNDEF(&object); + object = NULL; obj_ce = mptr->common.scope; } else { if (Z_TYPE(params[0]) != IS_OBJECT) { @@ -2877,14 +2877,14 @@ ZEND_METHOD(reflection_method, invoke) /* Returns from this function */ } - ZVAL_COPY_VALUE(&object, ¶ms[0]); + object = Z_OBJ(params[0]); } fci.size = sizeof(fci); fci.function_table = NULL; ZVAL_UNDEF(&fci.function_name); fci.symbol_table = NULL; - fci.object_ptr = &object; + fci.object = object; fci.retval = &retval; fci.param_count = num_args - 1; fci.params = params + 1; @@ -2894,7 +2894,7 @@ ZEND_METHOD(reflection_method, invoke) fcc.function_handler = mptr; fcc.calling_scope = obj_ce; fcc.called_scope = intern->ce; - ZVAL_COPY_VALUE(&fcc.object, &object); + fcc.object = object; result = zend_call_function(&fci, &fcc TSRMLS_CC); @@ -2989,7 +2989,7 @@ ZEND_METHOD(reflection_method, invokeArgs) fci.function_table = NULL; ZVAL_UNDEF(&fci.function_name); fci.symbol_table = NULL; - fci.object_ptr = object; + fci.object = object ? Z_OBJ_P(object) : NULL; fci.retval = &retval; fci.param_count = argc; fci.params = params; @@ -2999,11 +2999,7 @@ ZEND_METHOD(reflection_method, invokeArgs) fcc.function_handler = mptr; fcc.calling_scope = obj_ce; fcc.called_scope = intern->ce; - if (object) { - ZVAL_COPY_VALUE(&fcc.object, object); - } else { - ZVAL_UNDEF(&fcc.object); - } + fcc.object = (object) ? Z_OBJ_P(object) : NULL; /* * Copy the zend_function when calling via handler (e.g. Closure::__invoke()) @@ -3700,7 +3696,7 @@ ZEND_METHOD(reflection_class, getMethod) lc_name = zend_str_tolower_dup(name, name_len); if (ce == zend_ce_closure && !ZVAL_IS_UNDEF(&intern->obj) && (name_len == sizeof(ZEND_INVOKE_FUNC_NAME)-1) && memcmp(lc_name, ZEND_INVOKE_FUNC_NAME, sizeof(ZEND_INVOKE_FUNC_NAME)-1) == 0 - && (mptr = zend_get_closure_invoke_method(&intern->obj TSRMLS_CC)) != NULL) + && (mptr = zend_get_closure_invoke_method(Z_OBJ(intern->obj) TSRMLS_CC)) != NULL) { /* don't assign closure_object since we only reflect the invoke handler method and not the closure definition itself */ @@ -3708,7 +3704,7 @@ ZEND_METHOD(reflection_class, getMethod) efree(lc_name); } else if (ce == zend_ce_closure && ZVAL_IS_UNDEF(&intern->obj) && (name_len == sizeof(ZEND_INVOKE_FUNC_NAME)-1) && memcmp(lc_name, ZEND_INVOKE_FUNC_NAME, sizeof(ZEND_INVOKE_FUNC_NAME)-1) == 0 - && object_init_ex(&obj_tmp, ce) == SUCCESS && (mptr = zend_get_closure_invoke_method(&obj_tmp TSRMLS_CC)) != NULL) { + && object_init_ex(&obj_tmp, ce) == SUCCESS && (mptr = zend_get_closure_invoke_method(Z_OBJ(obj_tmp) TSRMLS_CC)) != NULL) { /* don't assign closure_object since we only reflect the invoke handler method and not the closure definition itself */ reflection_method_factory(ce, mptr, NULL, return_value TSRMLS_CC); @@ -3735,7 +3731,7 @@ static void _addmethod(zend_function *mptr, zend_class_entry *ce, zval *retval, if (mptr->common.fn_flags & filter) { if (ce == zend_ce_closure && obj && (len == sizeof(ZEND_INVOKE_FUNC_NAME)-1) && memcmp(mptr->common.function_name->val, ZEND_INVOKE_FUNC_NAME, sizeof(ZEND_INVOKE_FUNC_NAME)-1) == 0 - && (closure = zend_get_closure_invoke_method(obj TSRMLS_CC)) != NULL) + && (closure = zend_get_closure_invoke_method(Z_OBJ_P(obj) TSRMLS_CC)) != NULL) { mptr = closure; } @@ -3786,7 +3782,7 @@ ZEND_METHOD(reflection_class, getMethods) array_init(return_value); zend_hash_apply_with_arguments(&ce->function_table TSRMLS_CC, (apply_func_args_t) _addmethod_va, 4, &ce, return_value, filter, intern->obj); if (Z_TYPE(intern->obj) != IS_UNDEF && instanceof_function(ce, zend_ce_closure TSRMLS_CC)) { - zend_function *closure = zend_get_closure_invoke_method(&intern->obj TSRMLS_CC); + zend_function *closure = zend_get_closure_invoke_method(Z_OBJ(intern->obj) TSRMLS_CC); if (closure) { _addmethod(closure, ce, return_value, filter, &intern->obj TSRMLS_CC); _free_function(closure TSRMLS_CC); @@ -4198,7 +4194,7 @@ ZEND_METHOD(reflection_class, newInstance) old_scope = EG(scope); EG(scope) = ce; - constructor = Z_OBJ_HT_P(return_value)->get_constructor(return_value TSRMLS_CC); + constructor = Z_OBJ_HT_P(return_value)->get_constructor(Z_OBJ_P(return_value) TSRMLS_CC); EG(scope) = old_scope; /* Run the constructor if there is one */ @@ -4223,7 +4219,7 @@ ZEND_METHOD(reflection_class, newInstance) fci.function_table = EG(function_table); ZVAL_UNDEF(&fci.function_name); fci.symbol_table = NULL; - fci.object_ptr = return_value; + fci.object = Z_OBJ_P(return_value); fci.retval = &retval; fci.param_count = num_args; fci.params = params; @@ -4233,7 +4229,7 @@ ZEND_METHOD(reflection_class, newInstance) fcc.function_handler = constructor; fcc.calling_scope = EG(scope); fcc.called_scope = Z_OBJCE_P(return_value); - ZVAL_COPY_VALUE(&fcc.object, return_value); + fcc.object = Z_OBJ_P(return_value); if (zend_call_function(&fci, &fcc TSRMLS_CC) == FAILURE) { if (!ZVAL_IS_UNDEF(&retval)) { @@ -4297,7 +4293,7 @@ ZEND_METHOD(reflection_class, newInstanceArgs) old_scope = EG(scope); EG(scope) = ce; - constructor = Z_OBJ_HT_P(return_value)->get_constructor(return_value TSRMLS_CC); + constructor = Z_OBJ_HT_P(return_value)->get_constructor(Z_OBJ_P(return_value) TSRMLS_CC); EG(scope) = old_scope; /* Run the constructor if there is one */ @@ -4322,7 +4318,7 @@ ZEND_METHOD(reflection_class, newInstanceArgs) fci.function_table = EG(function_table); ZVAL_UNDEF(&fci.function_name); fci.symbol_table = NULL; - fci.object_ptr = return_value; + fci.object = Z_OBJ_P(return_value); fci.retval = &retval; fci.param_count = argc; fci.params = params; @@ -4332,7 +4328,7 @@ ZEND_METHOD(reflection_class, newInstanceArgs) fcc.function_handler = constructor; fcc.calling_scope = EG(scope); fcc.called_scope = Z_OBJCE_P(return_value); - ZVAL_COPY_VALUE(&fcc.object, return_value); + fcc.object = Z_OBJ_P(return_value); if (zend_call_function(&fci, &fcc TSRMLS_CC) == FAILURE) { if (params) { -- cgit v1.2.1 From a25a1ba0ef263e9e1d65b8eaebd3e764878c55c7 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Tue, 1 Apr 2014 16:31:03 +0400 Subject: STR_DUP() doesn't duplicate interned strings anymore. In case new string is required STR_INIT() or STR_ALLOC() should be used. --- ext/reflection/php_reflection.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'ext/reflection/php_reflection.c') diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 20d3eb0e73..869a68d45c 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -575,14 +575,13 @@ static void _class_string(string *str, zend_class_entry *ce, zval *obj, char *in zend_string *prop_name; ulong index; - if (zend_hash_get_current_key_ex(properties, &prop_name, &index, 1, &pos) == HASH_KEY_IS_STRING) { + if (zend_hash_get_current_key_ex(properties, &prop_name, &index, 0, &pos) == HASH_KEY_IS_STRING) { if (prop_name->len && prop_name->val[0]) { /* skip all private and protected properties */ if (!zend_hash_exists(&ce->properties_info, prop_name)) { count++; _property_string(&dyn, NULL, prop_name->val, sub_indent.buf->val TSRMLS_CC); } } - efree(prop_name); } zend_hash_move_forward_ex(properties, &pos); } -- cgit v1.2.1 From 042c937f6915876a1aec014394daa1db8f75cea6 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Tue, 1 Apr 2014 17:10:15 +0400 Subject: Use STR_COPY() instead of STR_DUP() where possible --- ext/reflection/php_reflection.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ext/reflection/php_reflection.c') diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 869a68d45c..efb32713bd 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -276,7 +276,7 @@ static zend_function *_copy_function(zend_function *fptr TSRMLS_DC) /* {{{ */ zend_function *copy_fptr; copy_fptr = emalloc(sizeof(zend_function)); memcpy(copy_fptr, fptr, sizeof(zend_function)); - copy_fptr->internal_function.function_name = STR_DUP(fptr->internal_function.function_name, 0); + copy_fptr->internal_function.function_name = STR_COPY(fptr->internal_function.function_name); return copy_fptr; } else { /* no copy needed */ -- cgit v1.2.1 From 6b2ed577fd5c3eeee55be394d8faac50ab8602f9 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Tue, 1 Apr 2014 22:36:17 +0400 Subject: Avoid unnecessry reallocations --- ext/reflection/php_reflection.c | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) (limited to 'ext/reflection/php_reflection.c') diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index efb32713bd..34755690ca 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -3387,8 +3387,7 @@ static void add_class_vars(zend_class_entry *ce, int statics, zval *return_value zval_update_constant(&prop_copy, (void *) 1 TSRMLS_CC); } -//??? add_assoc_zval(return_value, key, &prop_copy); - add_assoc_zval(return_value, key->val, &prop_copy); + zend_hash_update(Z_ARRVAL_P(return_value), key, &prop_copy); } } /* }}} */ @@ -4369,8 +4368,7 @@ ZEND_METHOD(reflection_class, getInterfaces) for (i=0; i < ce->num_interfaces; i++) { zval interface; zend_reflection_class_factory(ce->interfaces[i], &interface TSRMLS_CC); -//??? - add_assoc_zval_ex(return_value, ce->interfaces[i]->name->val, ce->interfaces[i]->name->len, &interface); + zend_hash_update(Z_ARRVAL_P(return_value), ce->interfaces[i]->name, &interface); } } } @@ -4416,8 +4414,7 @@ ZEND_METHOD(reflection_class, getTraits) for (i=0; i < ce->num_traits; i++) { zval trait; zend_reflection_class_factory(ce->traits[i], &trait TSRMLS_CC); -//??? - add_assoc_zval_ex(return_value, ce->traits[i]->name->val, ce->traits[i]->name->len, &trait); + zend_hash_update(Z_ARRVAL_P(return_value), ce->traits[i]->name, &trait); } } /* }}} */ @@ -5249,8 +5246,7 @@ ZEND_METHOD(reflection_extension, getFunctions) if (fptr->common.type==ZEND_INTERNAL_FUNCTION && fptr->internal_function.module == module) { reflection_function_factory(fptr, NULL, &function TSRMLS_CC); -//??? - add_assoc_zval(return_value, fptr->common.function_name->val, &function); + zend_hash_update(Z_ARRVAL_P(return_value), fptr->common.function_name, &function); } zend_hash_move_forward_ex(CG(function_table), &iterator); } @@ -5266,9 +5262,7 @@ static int _addconstant(zval *el TSRMLS_DC, int num_args, va_list args, zend_has if (number == constant->module_number) { ZVAL_DUP(&const_val, &constant->value); -//??? INIT_PZVAL(const_val); - - add_assoc_zval_ex(retval, constant->name->val, constant->name->len, &const_val); + zend_hash_update(Z_ARRVAL_P(retval), constant->name, &const_val); } return 0; } @@ -5327,19 +5321,19 @@ ZEND_METHOD(reflection_extension, getINIEntries) /* }}} */ /* {{{ add_extension_class */ -static int add_extension_class(zend_class_entry **pce TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key) +static int add_extension_class(zval *zv TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key) { + zend_class_entry *ce = Z_PTR_P(zv); zval *class_array = va_arg(args, zval*), zclass; struct _zend_module_entry *module = va_arg(args, struct _zend_module_entry*); int add_reflection_class = va_arg(args, int); - if (((*pce)->type == ZEND_INTERNAL_CLASS) && (*pce)->info.internal.module && !strcasecmp((*pce)->info.internal.module->name, module->name)) { + if ((ce->type == ZEND_INTERNAL_CLASS) && ce->info.internal.module && !strcasecmp(ce->info.internal.module->name, module->name)) { if (add_reflection_class) { - zend_reflection_class_factory(*pce, &zclass TSRMLS_CC); -//??? - add_assoc_zval_ex(class_array, (*pce)->name->val, (*pce)->name->len, &zclass); + zend_reflection_class_factory(ce, &zclass TSRMLS_CC); + zend_hash_update(Z_ARRVAL_P(class_array), ce->name, &zclass); } else { - add_next_index_str(class_array, STR_COPY((*pce)->name)); + add_next_index_str(class_array, STR_COPY(ce->name)); } } return ZEND_HASH_APPLY_KEEP; -- cgit v1.2.1 From d8099d0468426dbee59f540048376653535270ce Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Wed, 2 Apr 2014 14:34:44 +0400 Subject: Changed data layout to allow more efficient operations --- ext/reflection/php_reflection.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'ext/reflection/php_reflection.c') diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 34755690ca..60580b86f5 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -4507,7 +4507,7 @@ ZEND_METHOD(reflection_class, isSubclassOf) return; } - switch(class_name->type) { + switch (Z_TYPE_P(class_name)) { case IS_STRING: if ((class_ce = zend_lookup_class(Z_STR_P(class_name) TSRMLS_CC)) == NULL) { zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, @@ -4551,7 +4551,7 @@ ZEND_METHOD(reflection_class, implementsInterface) return; } - switch(interface->type) { + switch (Z_TYPE_P(interface)) { case IS_STRING: if ((interface_ce = zend_lookup_class(Z_STR_P(interface) TSRMLS_CC)) == NULL) { zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, -- cgit v1.2.1 From 76cc99fe60d1e446a0250b4d778f02bcdbd7fc09 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Thu, 3 Apr 2014 15:26:23 +0400 Subject: Refactored ZVAL flags usage to simplify various checks (e.g. Z_REFCOUNTED(), candidate for GC, etc) --- ext/reflection/php_reflection.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'ext/reflection/php_reflection.c') diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 60580b86f5..1abb471fbc 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -2588,7 +2588,7 @@ ZEND_METHOD(reflection_parameter, getDefaultValue) ZVAL_COPY_VALUE(return_value, precv->op2.zv); //??? INIT_PZVAL(return_value); - if (!IS_CONSTANT_TYPE(Z_TYPE_P(return_value))) { + if (!(Z_TYPE_FLAGS_P(return_value) & IS_TYPE_CONSTANT)) { zval_copy_ctor(return_value); } zval_update_constant_ex(return_value, (void*)0, param->fptr->common.scope TSRMLS_CC); @@ -2612,7 +2612,7 @@ ZEND_METHOD(reflection_parameter, isDefaultValueConstant) } precv = _reflection_param_get_default_precv(INTERNAL_FUNCTION_PARAM_PASSTHRU, param); - if (precv && (Z_TYPE_P(precv->op2.zv) & IS_CONSTANT_TYPE_MASK) == IS_CONSTANT) { + if (precv && Z_TYPE_P(precv->op2.zv) == IS_CONSTANT) { RETURN_TRUE; } @@ -2637,7 +2637,7 @@ ZEND_METHOD(reflection_parameter, getDefaultValueConstantName) } precv = _reflection_param_get_default_precv(INTERNAL_FUNCTION_PARAM_PASSTHRU, param); - if (precv && (Z_TYPE_P(precv->op2.zv) & IS_CONSTANT_TYPE_MASK) == IS_CONSTANT) { + if (precv && Z_TYPE_P(precv->op2.zv) == IS_CONSTANT) { RETURN_STR(STR_COPY(Z_STR_P(precv->op2.zv))); } } @@ -3383,7 +3383,7 @@ static void add_class_vars(zend_class_entry *ce, int statics, zval *return_value /* this is necessary to make it able to work with default array * properties, returned to user */ - if (IS_CONSTANT_TYPE(Z_TYPE(prop_copy))) { + if (Z_TYPE_FLAGS(prop_copy) & IS_TYPE_CONSTANT) { zval_update_constant(&prop_copy, (void *) 1 TSRMLS_CC); } -- cgit v1.2.1 From 3bc8810b1eb0c0b5f44da4ee1d348053bd98463a Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Fri, 4 Apr 2014 03:55:27 +0400 Subject: Constant duplication optimization Argument receiving optimization --- ext/reflection/php_reflection.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'ext/reflection/php_reflection.c') diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 1abb471fbc..ff5d8e2091 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -2588,7 +2588,7 @@ ZEND_METHOD(reflection_parameter, getDefaultValue) ZVAL_COPY_VALUE(return_value, precv->op2.zv); //??? INIT_PZVAL(return_value); - if (!(Z_TYPE_FLAGS_P(return_value) & IS_TYPE_CONSTANT)) { + if (!Z_CONSTANT_P(return_value)) { zval_copy_ctor(return_value); } zval_update_constant_ex(return_value, (void*)0, param->fptr->common.scope TSRMLS_CC); @@ -3383,7 +3383,7 @@ static void add_class_vars(zend_class_entry *ce, int statics, zval *return_value /* this is necessary to make it able to work with default array * properties, returned to user */ - if (Z_TYPE_FLAGS(prop_copy) & IS_TYPE_CONSTANT) { + if (Z_CONSTANT(prop_copy)) { zval_update_constant(&prop_copy, (void *) 1 TSRMLS_CC); } -- cgit v1.2.1 From 7402af380b3a700dda0e89470770fde15bd56204 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Wed, 9 Apr 2014 01:50:15 +0400 Subject: Fixed destruction of objects and iterators on unclean request shutdown and GC (few cases are still unfixed). Now we destroy objects it two steps. At first - object properties of all objects and only then the objects their selves. --- ext/reflection/php_reflection.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'ext/reflection/php_reflection.c') diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index ff5d8e2091..447f17ecae 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -328,8 +328,6 @@ static void reflection_free_objects_storage(zend_object *object TSRMLS_DC) /* {{ intern->ptr = NULL; zval_ptr_dtor(&intern->obj); zend_object_std_dtor(object TSRMLS_CC); - GC_REMOVE_FROM_BUFFER(object); - efree(intern); } /* }}} */ @@ -6085,6 +6083,7 @@ PHP_MINIT_FUNCTION(reflection) /* {{{ */ zend_std_obj_handlers = zend_get_std_object_handlers(); memcpy(&reflection_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); + reflection_object_handlers.offset = XtOffsetOf(reflection_object, zo); reflection_object_handlers.free_obj = reflection_free_objects_storage; reflection_object_handlers.clone_obj = NULL; reflection_object_handlers.write_property = _reflection_write_property; -- cgit v1.2.1 From 20f2e5986e7d9e5978eaed8d6d60cd6bf917ea37 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Wed, 9 Apr 2014 15:51:28 +0200 Subject: Fix ZTS build This only makes it compile, it doesn't actually work, presumably because interned strings are assumed in some places. --- ext/reflection/php_reflection.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'ext/reflection/php_reflection.c') diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 447f17ecae..1ef849f92a 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -3104,7 +3104,7 @@ ZEND_METHOD(reflection_function, inNamespace) if (zend_parse_parameters_none() == FAILURE) { return; } - if ((name = _default_load_entry(getThis(), "name", sizeof("name")-1) TSRMLS_CC) == NULL) { + if ((name = _default_load_entry(getThis(), "name", sizeof("name")-1 TSRMLS_CC)) == NULL) { RETURN_FALSE; } if (Z_TYPE_P(name) == IS_STRING @@ -3127,7 +3127,7 @@ ZEND_METHOD(reflection_function, getNamespaceName) if (zend_parse_parameters_none() == FAILURE) { return; } - if ((name = _default_load_entry(getThis(), "name", sizeof("name")-1) TSRMLS_CC) == NULL) { + if ((name = _default_load_entry(getThis(), "name", sizeof("name")-1 TSRMLS_CC)) == NULL) { RETURN_FALSE; } if (Z_TYPE_P(name) == IS_STRING @@ -3150,7 +3150,7 @@ ZEND_METHOD(reflection_function, getShortName) if (zend_parse_parameters_none() == FAILURE) { return; } - if ((name = _default_load_entry(getThis(), "name", sizeof("name")-1) TSRMLS_CC) == NULL) { + if ((name = _default_load_entry(getThis(), "name", sizeof("name")-1 TSRMLS_CC)) == NULL) { RETURN_FALSE; } if (Z_TYPE_P(name) == IS_STRING @@ -4653,7 +4653,7 @@ ZEND_METHOD(reflection_class, inNamespace) if (zend_parse_parameters_none() == FAILURE) { return; } - if ((name = _default_load_entry(getThis(), "name", sizeof("name")-1) TSRMLS_CC) == NULL) { + if ((name = _default_load_entry(getThis(), "name", sizeof("name")-1 TSRMLS_CC)) == NULL) { RETURN_FALSE; } if (Z_TYPE_P(name) == IS_STRING @@ -4676,7 +4676,7 @@ ZEND_METHOD(reflection_class, getNamespaceName) if (zend_parse_parameters_none() == FAILURE) { return; } - if ((name = _default_load_entry(getThis(), "name", sizeof("name")-1) TSRMLS_CC) == NULL) { + if ((name = _default_load_entry(getThis(), "name", sizeof("name")-1 TSRMLS_CC)) == NULL) { RETURN_FALSE; } if (Z_TYPE_P(name) == IS_STRING @@ -4699,7 +4699,7 @@ ZEND_METHOD(reflection_class, getShortName) if (zend_parse_parameters_none() == FAILURE) { return; } - if ((name = _default_load_entry(getThis(), "name", sizeof("name")-1) TSRMLS_CC) == NULL) { + if ((name = _default_load_entry(getThis(), "name", sizeof("name")-1 TSRMLS_CC)) == NULL) { RETURN_FALSE; } if (Z_TYPE_P(name) == IS_STRING -- cgit v1.2.1 From 35b895fdf0fd2b4fe9ba0e9e7edc513a0a39e205 Mon Sep 17 00:00:00 2001 From: Bob Weinand Date: Fri, 11 Apr 2014 19:18:58 +0200 Subject: Removed useless void* parameter and replaced with zend_bool on zval_update_constant* functions --- ext/reflection/php_reflection.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'ext/reflection/php_reflection.c') diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index a24153dc20..703e14113f 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -733,7 +733,7 @@ static void _parameter_string(string *str, zend_function *fptr, struct _zend_arg *zv = *precv->op2.zv; zval_copy_ctor(zv); INIT_PZVAL(zv); - zval_update_constant_ex(&zv, (void*)1, fptr->common.scope TSRMLS_CC); + zval_update_constant_ex(&zv, 1, fptr->common.scope TSRMLS_CC); if (Z_TYPE_P(zv) == IS_BOOL) { if (Z_LVAL_P(zv)) { string_write(str, "true", sizeof("true")-1); @@ -2599,7 +2599,7 @@ ZEND_METHOD(reflection_parameter, getDefaultValue) if (!IS_CONSTANT_TYPE(Z_TYPE_P(return_value))) { zval_copy_ctor(return_value); } - zval_update_constant_ex(&return_value, (void*)0, param->fptr->common.scope TSRMLS_CC); + zval_update_constant_ex(&return_value, 0, param->fptr->common.scope TSRMLS_CC); } /* }}} */ @@ -3411,7 +3411,7 @@ static void add_class_vars(zend_class_entry *ce, int statics, zval *return_value /* this is necessary to make it able to work with default array * properties, returned to user */ if (IS_CONSTANT_TYPE(Z_TYPE_P(prop_copy))) { - zval_update_constant(&prop_copy, (void *) 1 TSRMLS_CC); + zval_update_constant(&prop_copy, 1 TSRMLS_CC); } add_assoc_zval(return_value, key, prop_copy); -- cgit v1.2.1 From 5dc52e488048d93767b78fe7fce34a6a0febc5e0 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Mon, 14 Apr 2014 13:24:43 +0400 Subject: Fixed interface constants inheritance. Now we use IS_REFERENCE for inhereted class constants. I might miss some edje cases. --- ext/reflection/php_reflection.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ext/reflection/php_reflection.c') diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 1ef849f92a..224bec75ba 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -4010,7 +4010,7 @@ ZEND_METHOD(reflection_class, getConstants) GET_REFLECTION_OBJECT_PTR(ce); array_init(return_value); zend_hash_apply_with_argument(&ce->constants_table, (apply_func_arg_t)zval_update_constant_inline_change, ce TSRMLS_CC); - zend_hash_copy(Z_ARRVAL_P(return_value), &ce->constants_table, zval_add_ref); + zend_hash_copy(Z_ARRVAL_P(return_value), &ce->constants_table, zval_add_ref_unref); } /* }}} */ -- cgit v1.2.1 From 050d7e38ad4163e7fa65e26724d3516ce7b33601 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Tue, 15 Apr 2014 15:40:40 +0400 Subject: Cleanup (1-st round) --- ext/reflection/php_reflection.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'ext/reflection/php_reflection.c') diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 224bec75ba..6dc4ef2edf 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -1440,7 +1440,7 @@ static void _reflection_export(INTERNAL_FUNCTION_PARAMETERS, zend_class_entry *c } if (return_output) { - COPY_PZVAL_TO_ZVAL(*return_value, &retval); + ZVAL_COPY_VALUE(return_value, &retval); } else { zval_ptr_dtor(&retval); } @@ -1529,7 +1529,7 @@ ZEND_METHOD(reflection, export) } if (return_output) { - COPY_PZVAL_TO_ZVAL(*return_value, &retval); + 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); @@ -1552,30 +1552,30 @@ ZEND_METHOD(reflection, getModifierNames) array_init(return_value); if (modifiers & (ZEND_ACC_ABSTRACT | ZEND_ACC_EXPLICIT_ABSTRACT_CLASS)) { - add_next_index_stringl(return_value, "abstract", sizeof("abstract")-1, 1); + add_next_index_stringl(return_value, "abstract", sizeof("abstract")-1); } if (modifiers & (ZEND_ACC_FINAL | ZEND_ACC_FINAL_CLASS)) { - add_next_index_stringl(return_value, "final", sizeof("final")-1, 1); + add_next_index_stringl(return_value, "final", sizeof("final")-1); } if (modifiers & ZEND_ACC_IMPLICIT_PUBLIC) { - add_next_index_stringl(return_value, "public", sizeof("public")-1, 1); + add_next_index_stringl(return_value, "public", sizeof("public")-1); } /* These are mutually exclusive */ switch (modifiers & ZEND_ACC_PPP_MASK) { case ZEND_ACC_PUBLIC: - add_next_index_stringl(return_value, "public", sizeof("public")-1, 1); + add_next_index_stringl(return_value, "public", sizeof("public")-1); break; case ZEND_ACC_PRIVATE: - add_next_index_stringl(return_value, "private", sizeof("private")-1, 1); + add_next_index_stringl(return_value, "private", sizeof("private")-1); break; case ZEND_ACC_PROTECTED: - add_next_index_stringl(return_value, "protected", sizeof("protected")-1, 1); + add_next_index_stringl(return_value, "protected", sizeof("protected")-1); break; } if (modifiers & ZEND_ACC_STATIC) { - add_next_index_stringl(return_value, "static", sizeof("static")-1, 1); + add_next_index_stringl(return_value, "static", sizeof("static")-1); } } /* }}} */ @@ -1928,7 +1928,7 @@ ZEND_METHOD(reflection_function, invoke) } if (Z_TYPE(retval) != IS_UNDEF) { - COPY_PZVAL_TO_ZVAL(*return_value, &retval); + ZVAL_COPY_VALUE(return_value, &retval); } } /* }}} */ @@ -1994,7 +1994,7 @@ ZEND_METHOD(reflection_function, invokeArgs) } if (Z_TYPE(retval) != IS_UNDEF) { - COPY_PZVAL_TO_ZVAL(*return_value, &retval); + ZVAL_COPY_VALUE(return_value, &retval); } } /* }}} */ @@ -2902,7 +2902,7 @@ ZEND_METHOD(reflection_method, invoke) } if (Z_TYPE(retval) != IS_UNDEF) { - COPY_PZVAL_TO_ZVAL(*return_value, &retval); + ZVAL_COPY_VALUE(return_value, &retval); } } /* }}} */ @@ -3017,7 +3017,7 @@ ZEND_METHOD(reflection_method, invokeArgs) } if (Z_TYPE(retval) != IS_UNDEF) { - COPY_PZVAL_TO_ZVAL(*return_value, &retval); + ZVAL_COPY_VALUE(return_value, &retval); } } /* }}} */ @@ -5292,7 +5292,7 @@ static int _addinientry(zval *el TSRMLS_DC, int num_args, va_list args, zend_has if (number == ini_entry->module_number) { if (ini_entry->value) { - add_assoc_stringl(retval, ini_entry->name, ini_entry->value, ini_entry->value_length, 1); + add_assoc_stringl(retval, ini_entry->name, ini_entry->value, ini_entry->value_length); } else { add_assoc_null(retval, ini_entry->name); } -- cgit v1.2.1 From f9b26bc39a9ea9b1380628eeb0e6dad3c93cfcb0 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Tue, 15 Apr 2014 21:56:30 +0400 Subject: Cleanup (2-nd round) --- ext/reflection/php_reflection.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'ext/reflection/php_reflection.c') diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 6dc4ef2edf..0b8027dd85 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -732,7 +732,6 @@ static void _parameter_string(string *str, zend_function *fptr, struct _zend_arg int use_copy; string_write(str, " = ", sizeof(" = ")-1); ZVAL_DUP(&zv, precv->op2.zv); -//??? INIT_PZVAL(zv); zval_update_constant_ex(&zv, (void*)1, fptr->common.scope TSRMLS_CC); if (Z_TYPE(zv) == IS_BOOL) { if (Z_LVAL(zv)) { @@ -1378,8 +1377,6 @@ static void _reflection_export(INTERNAL_FUNCTION_PARAMETERS, zend_class_entry *c ZVAL_COPY_VALUE(¶ms[1], argument2_ptr); } -//??? INIT_PZVAL(&output); - /* Create object */ if (object_and_properties_init(&reflector, ce_ptr, NULL) == FAILURE) { _DO_THROW("Could not create reflector"); @@ -2585,11 +2582,11 @@ ZEND_METHOD(reflection_parameter, getDefaultValue) } ZVAL_COPY_VALUE(return_value, precv->op2.zv); -//??? INIT_PZVAL(return_value); - if (!Z_CONSTANT_P(return_value)) { + if (Z_CONSTANT_P(return_value)) { + zval_update_constant_ex(return_value, (void*)0, param->fptr->common.scope TSRMLS_CC); + } else { zval_copy_ctor(return_value); } - zval_update_constant_ex(return_value, (void*)0, param->fptr->common.scope TSRMLS_CC); } /* }}} */ @@ -3377,7 +3374,6 @@ static void add_class_vars(zend_class_entry *ce, int statics, zval *return_value /* copy: enforce read only access */ ZVAL_DUP(&prop_copy, prop); -//??? INIT_PZVAL(prop_copy); /* this is necessary to make it able to work with default array * properties, returned to user */ @@ -4956,7 +4952,6 @@ ZEND_METHOD(reflection_property, getValue) /* Bails out */ } ZVAL_DUP(return_value, &CE_STATIC_MEMBERS(intern->ce)[ref->prop.offset]); -//??? INIT_PZVAL(return_value); } else { const char *class_name, *prop_name; -- cgit v1.2.1 From c44eee153f2697d62f6c7478dcdc406f58e5d5e0 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Wed, 16 Apr 2014 17:06:25 +0400 Subject: Fixed reference counting --- ext/reflection/php_reflection.c | 48 +++++++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 19 deletions(-) (limited to 'ext/reflection/php_reflection.c') diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 0b8027dd85..9aea15c882 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -1932,7 +1932,7 @@ ZEND_METHOD(reflection_function, invoke) static int _zval_array_to_c_array(zval *arg, zval **params TSRMLS_DC) /* {{{ */ { - ZVAL_COPY_VALUE((*params), arg); + ZVAL_COPY((*params), arg); (*params)++; return ZEND_HASH_APPLY_KEEP; } /* }}} */ @@ -1944,7 +1944,7 @@ ZEND_METHOD(reflection_function, invokeArgs) zval retval; zval *params; int result; - int argc; + int i, argc; zend_fcall_info fci; zend_fcall_info_cache fcc; reflection_object *intern; @@ -1982,6 +1982,9 @@ ZEND_METHOD(reflection_function, invokeArgs) result = zend_call_function(&fci, &fcc TSRMLS_CC); + for (i = 0; i < argc; i++) { + zval_ptr_dtor(¶ms[i]); + } efree(params); if (result == FAILURE) { @@ -2913,7 +2916,7 @@ ZEND_METHOD(reflection_method, invokeArgs) zval *object; reflection_object *intern; zend_function *mptr; - int argc; + int i, argc; int result; zend_fcall_info fci; zend_fcall_info_cache fcc; @@ -3005,6 +3008,9 @@ ZEND_METHOD(reflection_method, invokeArgs) result = zend_call_function(&fci, &fcc TSRMLS_CC); + for (i = 0; i < argc; i++) { + zval_ptr_dtor(¶ms[i]); + } efree(params); if (result == FAILURE) { @@ -4192,7 +4198,7 @@ ZEND_METHOD(reflection_class, newInstance) /* Run the constructor if there is one */ if (constructor) { zval *params = NULL; - int num_args = 0; + int ret, i, num_args = 0; zend_fcall_info fci; zend_fcall_info_cache fcc; @@ -4207,6 +4213,10 @@ ZEND_METHOD(reflection_class, newInstance) RETURN_FALSE; } + for (i = 0; i < num_args; i++) { + if (Z_REFCOUNTED(params[i])) Z_ADDREF(params[i]); + } + fci.size = sizeof(fci); fci.function_table = EG(function_table); ZVAL_UNDEF(&fci.function_name); @@ -4223,17 +4233,16 @@ ZEND_METHOD(reflection_class, newInstance) fcc.called_scope = Z_OBJCE_P(return_value); fcc.object = Z_OBJ_P(return_value); - if (zend_call_function(&fci, &fcc TSRMLS_CC) == FAILURE) { - if (!ZVAL_IS_UNDEF(&retval)) { - zval_ptr_dtor(&retval); - } + ret = zend_call_function(&fci, &fcc TSRMLS_CC); + zval_ptr_dtor(&retval); + for (i = 0; i < num_args; i++) { + zval_ptr_dtor(¶ms[i]); + } + if (ret == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invocation of %s's constructor failed", ce->name->val); zval_dtor(return_value); RETURN_NULL(); } - if (!ZVAL_IS_UNDEF(&retval)) { - zval_ptr_dtor(&retval); - } } else if (ZEND_NUM_ARGS()) { zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Class %s does not have a constructor, so you cannot pass any constructor arguments", ce->name->val); } @@ -4265,7 +4274,7 @@ ZEND_METHOD(reflection_class, newInstanceArgs) zval retval; reflection_object *intern; zend_class_entry *ce, *old_scope; - int argc = 0; + int ret, i, argc = 0; HashTable *args; zend_function *constructor; @@ -4322,19 +4331,20 @@ ZEND_METHOD(reflection_class, newInstanceArgs) fcc.called_scope = Z_OBJCE_P(return_value); fcc.object = Z_OBJ_P(return_value); - if (zend_call_function(&fci, &fcc TSRMLS_CC) == FAILURE) { - if (params) { - efree(params); + ret = zend_call_function(&fci, &fcc TSRMLS_CC); + zval_ptr_dtor(&retval); + if (params) { + for (i = 0; i < argc; i++) { + zval_ptr_dtor(¶ms[i]); } + efree(params); + } + if (ret == FAILURE) { zval_ptr_dtor(&retval); php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invocation of %s's constructor failed", ce->name->val); zval_dtor(return_value); RETURN_NULL(); } - zval_ptr_dtor(&retval); - if (params) { - efree(params); - } } else if (argc) { zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Class %s does not have a constructor, so you cannot pass any constructor arguments", ce->name->val); } -- cgit v1.2.1 From cc576c74d2894abde062d1f41c8e309f9ec569a6 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Wed, 16 Apr 2014 22:41:07 +0400 Subject: op_array->function_name, op_array->doc_comments and op_array->filename may be kept in opcache SHM --- ext/reflection/php_reflection.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'ext/reflection/php_reflection.c') diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 9aea15c882..d080b81467 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -1800,7 +1800,8 @@ ZEND_METHOD(reflection_function, getFileName) } GET_REFLECTION_OBJECT_PTR(fptr); if (fptr->type == ZEND_USER_FUNCTION) { - RETURN_STR(STR_COPY(fptr->op_array.filename)); +// TODO: we have to duplicate it, becaise it may be in opcache SHM ??? + RETURN_STR(STR_DUP(fptr->op_array.filename, 0)); } RETURN_FALSE; } @@ -1854,7 +1855,8 @@ ZEND_METHOD(reflection_function, getDocComment) } GET_REFLECTION_OBJECT_PTR(fptr); if (fptr->type == ZEND_USER_FUNCTION && fptr->op_array.doc_comment) { - RETURN_STR(STR_COPY(fptr->op_array.doc_comment)); +// TODO: we have to duplicate it, becaise it may be stored in opcache SHM ??? + RETURN_STR(STR_DUP(fptr->op_array.doc_comment, 0)); } RETURN_FALSE; } @@ -3566,7 +3568,8 @@ ZEND_METHOD(reflection_class, getFileName) } GET_REFLECTION_OBJECT_PTR(ce); if (ce->type == ZEND_USER_CLASS) { - RETURN_STR(STR_COPY(ce->info.user.filename)); +// TODO: we have to duplicate it, becaise it may be stored in opcache SHM ??? + RETURN_STR(STR_DUP(ce->info.user.filename, 0)); } RETURN_FALSE; } -- cgit v1.2.1 From e96073b1e40c4999dee70db684721a582ea5e055 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Thu, 17 Apr 2014 15:40:45 +0400 Subject: Moved zend_literal->cache_slot right into zval. It should be accessed using Z_CACHE_SLOT() macro. zend_literal structure is removed. API functions that accepted pointer to zend_literal now accept pointer to zval or cache_slot directly. Calls of such functiond that now accept cache_slot need to be changed to pass -1 instead of NULL. --- ext/reflection/php_reflection.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'ext/reflection/php_reflection.c') diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index d080b81467..d2a6790d6b 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -44,7 +44,7 @@ #define reflection_update_property(object, name, value) do { \ zval member; \ ZVAL_STRINGL(&member, name, sizeof(name)-1); \ - zend_std_write_property(object, &member, value, NULL TSRMLS_CC); \ + zend_std_write_property(object, &member, value, -1 TSRMLS_CC); \ if (Z_REFCOUNTED_P(value)) Z_DELREF_P(value); \ zval_ptr_dtor(&member); \ } while (0) @@ -3430,7 +3430,7 @@ ZEND_METHOD(reflection_class, getStaticPropertyValue) GET_REFLECTION_OBJECT_PTR(ce); zend_update_class_constants(ce TSRMLS_CC); - prop = zend_std_get_static_property(ce, name, 1, NULL TSRMLS_CC); + prop = zend_std_get_static_property(ce, name, 1, -1 TSRMLS_CC); if (!prop) { if (def_value) { RETURN_ZVAL(def_value, 1, 0); @@ -3463,7 +3463,7 @@ ZEND_METHOD(reflection_class, setStaticPropertyValue) GET_REFLECTION_OBJECT_PTR(ce); zend_update_class_constants(ce TSRMLS_CC); - variable_ptr = zend_std_get_static_property(ce, name, 1, NULL TSRMLS_CC); + variable_ptr = zend_std_get_static_property(ce, name, 1, -1 TSRMLS_CC); if (!variable_ptr) { zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Class %s does not have a property named %s", ce->name->val, name->val); @@ -3816,7 +3816,7 @@ ZEND_METHOD(reflection_class, hasProperty) } else { if (Z_TYPE(intern->obj) != IS_UNDEF && Z_OBJ_HANDLER(intern->obj, has_property)) { ZVAL_STR(&property, STR_COPY(name)); - if (Z_OBJ_HANDLER(intern->obj, has_property)(&intern->obj, &property, 2, 0 TSRMLS_CC)) { + if (Z_OBJ_HANDLER(intern->obj, has_property)(&intern->obj, &property, 2, -1 TSRMLS_CC)) { zval_ptr_dtor(&property); RETURN_TRUE; } @@ -6068,7 +6068,7 @@ const zend_function_entry reflection_ext_functions[] = { /* {{{ */ static zend_object_handlers *zend_std_obj_handlers; /* {{{ _reflection_write_property */ -static void _reflection_write_property(zval *object, zval *member, zval *value, const zend_literal *key TSRMLS_DC) +static void _reflection_write_property(zval *object, zval *member, zval *value, zend_uint cache_slot TSRMLS_DC) { if ((Z_TYPE_P(member) == IS_STRING) && zend_hash_exists(&Z_OBJCE_P(object)->properties_info, Z_STR_P(member)) @@ -6080,7 +6080,7 @@ static void _reflection_write_property(zval *object, zval *member, zval *value, } else { - zend_std_obj_handlers->write_property(object, member, value, key TSRMLS_CC); + zend_std_obj_handlers->write_property(object, member, value, cache_slot TSRMLS_CC); } } /* }}} */ -- cgit v1.2.1 From afe66d89a122d0349f56ddd4c4abfd5d2da68f19 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Mon, 21 Apr 2014 16:34:40 +0400 Subject: Cleanup --- ext/reflection/php_reflection.c | 5 ----- 1 file changed, 5 deletions(-) (limited to 'ext/reflection/php_reflection.c') diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index d2a6790d6b..0ef31460bd 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -4974,11 +4974,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); - } } } /* }}} */ -- cgit v1.2.1 From bda96e3c589b2b923e70abd4a5e66dfa824e8f5d Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Mon, 21 Apr 2014 17:12:10 +0200 Subject: Use zval_get_string in print_zval and propagate TSRMLS --- ext/reflection/php_reflection.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ext/reflection/php_reflection.c') diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 0ef31460bd..86391115d0 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -1529,7 +1529,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); } -- cgit v1.2.1 From 0d43a277b8dec6ea9f804eeb1a68c05047a22c4f Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Mon, 21 Apr 2014 17:51:15 +0200 Subject: Use zval_get_string in a few more places --- ext/reflection/php_reflection.c | 29 ++++++++--------------------- 1 file changed, 8 insertions(+), 21 deletions(-) (limited to 'ext/reflection/php_reflection.c') diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 86391115d0..b78311868a 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 TSRMLS_CC); 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); } -- cgit v1.2.1 From 4ed452c1b5b81f99212594ec7f57475a16372d45 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Mon, 21 Apr 2014 22:36:01 +0400 Subject: Convert zval_get_string() into "fast path" macro and "slow path" function --- ext/reflection/php_reflection.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ext/reflection/php_reflection.c') diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index b78311868a..4940457333 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -656,7 +656,7 @@ static void _class_string(string *str, zend_class_entry *ce, zval *obj, char *in static void _const_string(string *str, char *name, zval *value, char *indent TSRMLS_DC) { char *type = zend_zval_type_name(value); - zend_string *value_str = zval_get_string(value TSRMLS_CC); + zend_string *value_str = zval_get_string(value); string_printf(str, "%s Constant [ %s %s ] { %s }\n", indent, type, name, value_str->val); -- cgit v1.2.1 From 5864ce8a447b718d0912cb073afe87eddc47b2e8 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Tue, 22 Apr 2014 17:46:34 +0400 Subject: Fixed compilation warnings --- ext/reflection/php_reflection.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'ext/reflection/php_reflection.c') diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 4940457333..4af0b7383d 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -98,12 +98,15 @@ ZEND_DECLARE_MODULE_GLOBALS(reflection) return; \ } -#define GET_REFLECTION_OBJECT_PTR(target) \ - intern = Z_REFLECTION_P(getThis()); \ +#define GET_REFLECTION_OBJECT() \ + intern = Z_REFLECTION_P(getThis()); \ if (intern == NULL || intern->ptr == NULL) { \ RETURN_ON_EXCEPTION \ php_error_docref(NULL TSRMLS_CC, E_ERROR, "Internal error: Failed to retrieve the reflection object"); \ } \ + +#define GET_REFLECTION_OBJECT_PTR(target) \ + GET_REFLECTION_OBJECT() \ target = intern->ptr; \ /* Class constants */ @@ -1679,13 +1682,12 @@ ZEND_METHOD(reflection_function, isClosure) ZEND_METHOD(reflection_function, getClosureThis) { reflection_object *intern; - zend_function *fptr; zval* closure_this; if (zend_parse_parameters_none() == FAILURE) { return; } - GET_REFLECTION_OBJECT_PTR(fptr); + GET_REFLECTION_OBJECT(); if (!ZVAL_IS_UNDEF(&intern->obj)) { closure_this = zend_get_closure_this_ptr(&intern->obj TSRMLS_CC); if (!ZVAL_IS_UNDEF(closure_this)) { @@ -1700,13 +1702,12 @@ ZEND_METHOD(reflection_function, getClosureThis) ZEND_METHOD(reflection_function, getClosureScopeClass) { reflection_object *intern; - zend_function *fptr; const zend_function *closure_func; if (zend_parse_parameters_none() == FAILURE) { return; } - GET_REFLECTION_OBJECT_PTR(fptr); + GET_REFLECTION_OBJECT(); if (!ZVAL_IS_UNDEF(&intern->obj)) { closure_func = zend_get_closure_method_def(&intern->obj TSRMLS_CC); if (closure_func && closure_func->common.scope) { -- cgit v1.2.1 From 17d027ed47c1f07b397a611431d28ad0e0107146 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Wed, 30 Apr 2014 18:32:42 +0400 Subject: Split IS_BOOL into IS_FALSE and IS_TRUE --- ext/reflection/php_reflection.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'ext/reflection/php_reflection.c') diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index c3f02fe079..f16c39272d 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -725,12 +725,10 @@ static void _parameter_string(string *str, zend_function *fptr, struct _zend_arg string_write(str, " = ", sizeof(" = ")-1); ZVAL_DUP(&zv, precv->op2.zv); zval_update_constant_ex(&zv, 1, fptr->common.scope TSRMLS_CC); - if (Z_TYPE(zv) == IS_BOOL) { - if (Z_LVAL(zv)) { - string_write(str, "true", sizeof("true")-1); - } else { - string_write(str, "false", sizeof("false")-1); - } + if (Z_TYPE(zv) == IS_TRUE) { + string_write(str, "true", sizeof("true")-1); + } else if (Z_TYPE(zv) == IS_FALSE) { + string_write(str, "false", sizeof("false")-1); } else if (Z_TYPE(zv) == IS_NULL) { string_write(str, "NULL", sizeof("NULL")-1); } else if (Z_TYPE(zv) == IS_STRING) { -- cgit v1.2.1 From d8651fbe1c4caaaedc42cef1dee0dd3b3f1e447e Mon Sep 17 00:00:00 2001 From: Xinchen Hui Date: Sat, 3 May 2014 16:06:27 +0800 Subject: Make they are in the same style of Z_ISREF --- ext/reflection/php_reflection.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'ext/reflection/php_reflection.c') diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index f16c39272d..df4ba16bc4 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -1686,9 +1686,9 @@ ZEND_METHOD(reflection_function, getClosureThis) return; } GET_REFLECTION_OBJECT(); - if (!ZVAL_IS_UNDEF(&intern->obj)) { + if (!Z_ISUNDEF(intern->obj)) { closure_this = zend_get_closure_this_ptr(&intern->obj TSRMLS_CC); - if (!ZVAL_IS_UNDEF(closure_this)) { + if (!Z_ISUNDEF_P(closure_this)) { RETURN_ZVAL(closure_this, 1, 0); } } @@ -1706,7 +1706,7 @@ ZEND_METHOD(reflection_function, getClosureScopeClass) return; } GET_REFLECTION_OBJECT(); - if (!ZVAL_IS_UNDEF(&intern->obj)) { + if (!Z_ISUNDEF(intern->obj)) { closure_func = zend_get_closure_method_def(&intern->obj TSRMLS_CC); if (closure_func && closure_func->common.scope) { zend_reflection_class_factory(closure_func->common.scope, return_value TSRMLS_CC); @@ -2047,7 +2047,7 @@ ZEND_METHOD(reflection_function, getParameters) for (i = 0; i < fptr->common.num_args; i++) { zval parameter; - reflection_parameter_factory(_copy_function(fptr TSRMLS_CC), ZVAL_IS_UNDEF(&intern->obj)? NULL : &intern->obj, arg_info, i, fptr->common.required_num_args, ¶meter TSRMLS_CC); + reflection_parameter_factory(_copy_function(fptr TSRMLS_CC), Z_ISUNDEF(intern->obj)? NULL : &intern->obj, arg_info, i, fptr->common.required_num_args, ¶meter TSRMLS_CC); add_next_index_zval(return_value, ¶meter); arg_info++; @@ -2326,9 +2326,9 @@ ZEND_METHOD(reflection_parameter, getDeclaringFunction) GET_REFLECTION_OBJECT_PTR(param); if (!param->fptr->common.scope) { - reflection_function_factory(_copy_function(param->fptr TSRMLS_CC), ZVAL_IS_UNDEF(&intern->obj)? NULL : &intern->obj, return_value TSRMLS_CC); + reflection_function_factory(_copy_function(param->fptr TSRMLS_CC), Z_ISUNDEF(intern->obj)? NULL : &intern->obj, return_value TSRMLS_CC); } else { - reflection_method_factory(param->fptr->common.scope, _copy_function(param->fptr TSRMLS_CC), ZVAL_IS_UNDEF(&intern->obj)? NULL : &intern->obj, return_value TSRMLS_CC); + reflection_method_factory(param->fptr->common.scope, _copy_function(param->fptr TSRMLS_CC), Z_ISUNDEF(intern->obj)? NULL : &intern->obj, return_value TSRMLS_CC); } } /* }}} */ @@ -3681,7 +3681,7 @@ ZEND_METHOD(reflection_class, getMethod) GET_REFLECTION_OBJECT_PTR(ce); lc_name = zend_str_tolower_dup(name, name_len); - if (ce == zend_ce_closure && !ZVAL_IS_UNDEF(&intern->obj) && (name_len == sizeof(ZEND_INVOKE_FUNC_NAME)-1) + if (ce == zend_ce_closure && !Z_ISUNDEF(intern->obj) && (name_len == sizeof(ZEND_INVOKE_FUNC_NAME)-1) && memcmp(lc_name, ZEND_INVOKE_FUNC_NAME, sizeof(ZEND_INVOKE_FUNC_NAME)-1) == 0 && (mptr = zend_get_closure_invoke_method(Z_OBJ(intern->obj) TSRMLS_CC)) != NULL) { @@ -3689,7 +3689,7 @@ ZEND_METHOD(reflection_class, getMethod) method and not the closure definition itself */ reflection_method_factory(ce, mptr, NULL, return_value TSRMLS_CC); efree(lc_name); - } else if (ce == zend_ce_closure && ZVAL_IS_UNDEF(&intern->obj) && (name_len == sizeof(ZEND_INVOKE_FUNC_NAME)-1) + } else if (ce == zend_ce_closure && Z_ISUNDEF(intern->obj) && (name_len == sizeof(ZEND_INVOKE_FUNC_NAME)-1) && memcmp(lc_name, ZEND_INVOKE_FUNC_NAME, sizeof(ZEND_INVOKE_FUNC_NAME)-1) == 0 && object_init_ex(&obj_tmp, ce) == SUCCESS && (mptr = zend_get_closure_invoke_method(Z_OBJ(obj_tmp) TSRMLS_CC)) != NULL) { /* don't assign closure_object since we only reflect the invoke handler @@ -4082,7 +4082,7 @@ ZEND_METHOD(reflection_class, isCloneable) if (ce->ce_flags & (ZEND_ACC_INTERFACE | ZEND_ACC_TRAIT | ZEND_ACC_EXPLICIT_ABSTRACT_CLASS | ZEND_ACC_IMPLICIT_ABSTRACT_CLASS)) { RETURN_FALSE; } - if (!ZVAL_IS_UNDEF(&intern->obj)) { + if (!Z_ISUNDEF(intern->obj)) { if (ce->clone) { RETURN_BOOL(ce->clone->common.fn_flags & ZEND_ACC_PUBLIC); } else { -- cgit v1.2.1 From c9062917ebac6d2726360fca6ae3e3ac3a964e0e Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Wed, 28 May 2014 12:34:08 +0400 Subject: Use new zend_hash API --- ext/reflection/php_reflection.c | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) (limited to 'ext/reflection/php_reflection.c') diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index df4ba16bc4..8611c9c8e2 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -1918,19 +1918,12 @@ ZEND_METHOD(reflection_function, invoke) } /* }}} */ -static int _zval_array_to_c_array(zval *arg, zval **params TSRMLS_DC) /* {{{ */ -{ - ZVAL_COPY((*params), arg); - (*params)++; - return ZEND_HASH_APPLY_KEEP; -} /* }}} */ - /* {{{ proto public mixed ReflectionFunction::invokeArgs(array args) Invokes the function and pass its arguments as array. */ ZEND_METHOD(reflection_function, invokeArgs) { zval retval; - zval *params; + zval *params, *val; int result; int i, argc; zend_fcall_info fci; @@ -1949,8 +1942,11 @@ ZEND_METHOD(reflection_function, invokeArgs) argc = zend_hash_num_elements(Z_ARRVAL_P(param_array)); params = safe_emalloc(sizeof(zval), argc, 0); - zend_hash_apply_with_argument(Z_ARRVAL_P(param_array), (apply_func_arg_t)_zval_array_to_c_array, ¶ms TSRMLS_CC); - params -= argc; + argc = 0; + ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(param_array), val) { + ZVAL_COPY(¶ms[argc], val); + argc++; + } ZEND_HASH_FOREACH_END(); fci.size = sizeof(fci); fci.function_table = NULL; @@ -2900,8 +2896,7 @@ ZEND_METHOD(reflection_method, invoke) ZEND_METHOD(reflection_method, invokeArgs) { zval retval; - zval *params; - zval *object; + zval *params, *val, *object; reflection_object *intern; zend_function *mptr; int i, argc; @@ -2940,8 +2935,11 @@ ZEND_METHOD(reflection_method, invokeArgs) argc = zend_hash_num_elements(Z_ARRVAL_P(param_array)); params = safe_emalloc(sizeof(zval), argc, 0); - zend_hash_apply_with_argument(Z_ARRVAL_P(param_array), (apply_func_arg_t)_zval_array_to_c_array, ¶ms TSRMLS_CC); - params -= argc; + argc = 0; + ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(param_array), val) { + ZVAL_COPY(¶ms[argc], val); + argc++; + } ZEND_HASH_FOREACH_END(); /* In case this is a static method, we should'nt pass an object_ptr * (which is used as calling context aka $this). We can thus ignore the @@ -4260,7 +4258,7 @@ ZEND_METHOD(reflection_class, newInstanceWithoutConstructor) Returns an instance of this class */ ZEND_METHOD(reflection_class, newInstanceArgs) { - zval retval; + zval retval, *val; reflection_object *intern; zend_class_entry *ce, *old_scope; int ret, i, argc = 0; @@ -4300,8 +4298,11 @@ ZEND_METHOD(reflection_class, newInstanceArgs) if (argc) { params = safe_emalloc(sizeof(zval), argc, 0); - zend_hash_apply_with_argument(args, (apply_func_arg_t)_zval_array_to_c_array, ¶ms TSRMLS_CC); - params -= argc; + argc = 0; + ZEND_HASH_FOREACH_VAL(args, val) { + ZVAL_COPY(¶ms[argc], val); + argc++; + } ZEND_HASH_FOREACH_END(); } fci.size = sizeof(fci); -- cgit v1.2.1 From 909acec2319d8343a6e14665e6c5731e6839af6d Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Mon, 16 Jun 2014 23:32:58 +0400 Subject: Avoid useles constants update --- ext/reflection/php_reflection.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ext/reflection/php_reflection.c') diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 8611c9c8e2..678e328f68 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -4142,7 +4142,7 @@ ZEND_METHOD(reflection_class, getModifiers) } GET_REFLECTION_OBJECT_PTR(ce); - RETURN_LONG(ce->ce_flags); + RETURN_LONG(ce->ce_flags & ~ZEND_ACC_CONSTANTS_UPDATED); } /* }}} */ -- cgit v1.2.1 From 2ed8a170456c085491670a9beb62d4a6cac0903b Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Mon, 7 Jul 2014 20:54:31 +0400 Subject: Refactored run_time_cache usage in object handlers --- ext/reflection/php_reflection.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'ext/reflection/php_reflection.c') diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 678e328f68..afa1a3dd06 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -44,7 +44,7 @@ #define reflection_update_property(object, name, value) do { \ zval member; \ ZVAL_STRINGL(&member, name, sizeof(name)-1); \ - zend_std_write_property(object, &member, value, -1 TSRMLS_CC); \ + zend_std_write_property(object, &member, value, NULL TSRMLS_CC); \ if (Z_REFCOUNTED_P(value)) Z_DELREF_P(value); \ zval_ptr_dtor(&member); \ } while (0) @@ -3414,7 +3414,7 @@ ZEND_METHOD(reflection_class, getStaticPropertyValue) GET_REFLECTION_OBJECT_PTR(ce); zend_update_class_constants(ce TSRMLS_CC); - prop = zend_std_get_static_property(ce, name, 1, -1 TSRMLS_CC); + prop = zend_std_get_static_property(ce, name, 1, NULL TSRMLS_CC); if (!prop) { if (def_value) { RETURN_ZVAL(def_value, 1, 0); @@ -3447,7 +3447,7 @@ ZEND_METHOD(reflection_class, setStaticPropertyValue) GET_REFLECTION_OBJECT_PTR(ce); zend_update_class_constants(ce TSRMLS_CC); - variable_ptr = zend_std_get_static_property(ce, name, 1, -1 TSRMLS_CC); + variable_ptr = zend_std_get_static_property(ce, name, 1, NULL TSRMLS_CC); if (!variable_ptr) { zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Class %s does not have a property named %s", ce->name->val, name->val); @@ -3800,7 +3800,7 @@ ZEND_METHOD(reflection_class, hasProperty) } else { if (Z_TYPE(intern->obj) != IS_UNDEF && Z_OBJ_HANDLER(intern->obj, has_property)) { ZVAL_STR(&property, STR_COPY(name)); - if (Z_OBJ_HANDLER(intern->obj, has_property)(&intern->obj, &property, 2, -1 TSRMLS_CC)) { + if (Z_OBJ_HANDLER(intern->obj, has_property)(&intern->obj, &property, 2, NULL TSRMLS_CC)) { zval_ptr_dtor(&property); RETURN_TRUE; } @@ -6050,7 +6050,7 @@ const zend_function_entry reflection_ext_functions[] = { /* {{{ */ static zend_object_handlers *zend_std_obj_handlers; /* {{{ _reflection_write_property */ -static void _reflection_write_property(zval *object, zval *member, zval *value, zend_uint cache_slot TSRMLS_DC) +static void _reflection_write_property(zval *object, zval *member, zval *value, void **cache_slot TSRMLS_DC) { if ((Z_TYPE_P(member) == IS_STRING) && zend_hash_exists(&Z_OBJCE_P(object)->properties_info, Z_STR_P(member)) -- cgit v1.2.1 From 27f38798a1963de1c60aae4ef8a3675138255574 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Fri, 11 Jul 2014 16:32:20 +0400 Subject: Fast parameter parsing API This API is experemental. It may be changed or removed. It should be used only for really often used functions. (Keep the original parsing code and wrap usage with #ifndef FAST_ZPP) --- ext/reflection/php_reflection.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'ext/reflection/php_reflection.c') diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index afa1a3dd06..7247542951 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -1494,9 +1494,17 @@ ZEND_METHOD(reflection, export) int result; zend_bool return_output = 0; +#ifndef FAST_ZPP if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O|b", &object, reflector_ptr, &return_output) == FAILURE) { return; } +#else + ZEND_PARSE_PARAMETERS_START(1, 2) + Z_PARAM_OBJECT_OF_CLASS(object, reflector_ptr) + Z_PARAM_OPTIONAL + Z_PARAM_BOOL(return_output) + ZEND_PARSE_PARAMETERS_END(); +#endif /* Invoke the __toString() method */ ZVAL_STRINGL(&fname, "__tostring", sizeof("__tostring") - 1); -- cgit v1.2.1 From d909b6330e314bb434350317fda5bec185ea12c0 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Thu, 24 Jul 2014 00:37:15 +0400 Subject: Fixed crash on self-referencing constant expression (part of a constant AST) --- ext/reflection/php_reflection.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'ext/reflection/php_reflection.c') diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 703e14113f..02a19c0aaa 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -728,12 +728,17 @@ static void _parameter_string(string *str, zend_function *fptr, struct _zend_arg if (precv && precv->opcode == ZEND_RECV_INIT && precv->op2_type != IS_UNUSED) { zval *zv, zv_copy; int use_copy; + zend_class_entry *old_scope; + string_write(str, " = ", sizeof(" = ")-1); ALLOC_ZVAL(zv); *zv = *precv->op2.zv; zval_copy_ctor(zv); INIT_PZVAL(zv); - zval_update_constant_ex(&zv, 1, fptr->common.scope TSRMLS_CC); + old_scope = EG(scope); + EG(scope) = fptr->common.scope; + zval_update_constant_ex(&zv, 1, NULL TSRMLS_CC); + EG(scope) = old_scope; if (Z_TYPE_P(zv) == IS_BOOL) { if (Z_LVAL_P(zv)) { string_write(str, "true", sizeof("true")-1); @@ -2579,6 +2584,7 @@ ZEND_METHOD(reflection_parameter, getDefaultValue) { parameter_reference *param; zend_op *precv; + zend_class_entry *old_scope; if (zend_parse_parameters_none() == FAILURE) { return; @@ -2599,7 +2605,10 @@ ZEND_METHOD(reflection_parameter, getDefaultValue) if (!IS_CONSTANT_TYPE(Z_TYPE_P(return_value))) { zval_copy_ctor(return_value); } - zval_update_constant_ex(&return_value, 0, param->fptr->common.scope TSRMLS_CC); + old_scope = EG(scope); + EG(scope) = param->fptr->common.scope; + zval_update_constant_ex(&return_value, 0, NULL TSRMLS_CC); + EG(scope) = old_scope; } /* }}} */ -- cgit v1.2.1 From d586441d902ebabf2300b6724a2217e07bb12803 Mon Sep 17 00:00:00 2001 From: Ferenc Kovacs Date: Wed, 23 Jul 2014 07:45:02 +0200 Subject: ReflectionClass::newInstanceWithoutConstructor() should be allowed to instantiate every class except those internal classes with a final __construct() --- ext/reflection/php_reflection.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'ext/reflection/php_reflection.c') diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 02a19c0aaa..8ccd5e6f62 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -4308,8 +4308,8 @@ ZEND_METHOD(reflection_class, newInstanceWithoutConstructor) METHOD_NOTSTATIC(reflection_class_ptr); GET_REFLECTION_OBJECT_PTR(ce); - if (ce->create_object != NULL) { - zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Class %s is an internal class that cannot be instantiated without invoking its constructor", ce->name); + if (ce->create_object != NULL && ce->ce_flags & ZEND_ACC_FINAL_CLASS) { + zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Class %s is an internal class with a final __construct thus cannot be instantiated without invoking its constructor", ce->name); } object_init_ex(return_value, ce); -- cgit v1.2.1 From d18b16244c0cf3daf806bbad5a459fbd3195f152 Mon Sep 17 00:00:00 2001 From: Ferenc Kovacs Date: Wed, 30 Jul 2014 10:08:26 +0200 Subject: update the exception message to better match the actual check --- ext/reflection/php_reflection.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ext/reflection/php_reflection.c') diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 8ccd5e6f62..8e5fcadef4 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -4309,7 +4309,7 @@ ZEND_METHOD(reflection_class, newInstanceWithoutConstructor) GET_REFLECTION_OBJECT_PTR(ce); if (ce->create_object != NULL && ce->ce_flags & ZEND_ACC_FINAL_CLASS) { - zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Class %s is an internal class with a final __construct thus cannot be instantiated without invoking its constructor", ce->name); + zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Class %s is an internal class marked as final that cannot be instantiated without invoking its constructor", ce->name); } object_init_ex(return_value, ce); -- cgit v1.2.1 From be010e26c4e3ccf489747bc3626211400dd192d7 Mon Sep 17 00:00:00 2001 From: Xinchen Hui Date: Thu, 31 Jul 2014 12:55:53 +0800 Subject: Fixed getDefaultProperties (it should not return reference) --- ext/reflection/php_reflection.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'ext/reflection/php_reflection.c') diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index f2d3059c3d..508ddceacd 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -3351,16 +3351,12 @@ ZEND_METHOD(reflection_class, __construct) /* {{{ add_class_vars */ static void add_class_vars(zend_class_entry *ce, int statics, zval *return_value TSRMLS_DC) { - HashPosition pos; zend_property_info *prop_info; zval *prop, prop_copy; zend_string *key; ulong num_index; - zend_hash_internal_pointer_reset_ex(&ce->properties_info, &pos); - while ((prop_info = zend_hash_get_current_data_ptr_ex(&ce->properties_info, &pos)) != NULL) { - zend_hash_get_current_key_ex(&ce->properties_info, &key, &num_index, 0, &pos); - zend_hash_move_forward_ex(&ce->properties_info, &pos); + ZEND_HASH_FOREACH_KEY_PTR(&ce->properties_info, num_index, key, prop_info) { if (((prop_info->flags & ZEND_ACC_SHADOW) && prop_info->ce != ce) || ((prop_info->flags & ZEND_ACC_PROTECTED) && @@ -3382,6 +3378,7 @@ static void add_class_vars(zend_class_entry *ce, int statics, zval *return_value } /* copy: enforce read only access */ + ZVAL_DEREF(prop); ZVAL_DUP(&prop_copy, prop); /* this is necessary to make it able to work with default array @@ -3391,7 +3388,7 @@ static void add_class_vars(zend_class_entry *ce, int statics, zval *return_value } zend_hash_update(Z_ARRVAL_P(return_value), key, &prop_copy); - } + } ZEND_HASH_FOREACH_END(); } /* }}} */ -- cgit v1.2.1 From b8517e410ce4209d05f911d35d9ec77a2cc191c9 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Wed, 13 Aug 2014 12:36:10 +0400 Subject: cleanup --- ext/reflection/php_reflection.c | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) (limited to 'ext/reflection/php_reflection.c') diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index fd7569bcb8..4248de834d 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -1799,8 +1799,7 @@ ZEND_METHOD(reflection_function, getFileName) } GET_REFLECTION_OBJECT_PTR(fptr); if (fptr->type == ZEND_USER_FUNCTION) { -// TODO: we have to duplicate it, becaise it may be in opcache SHM ??? - RETURN_STR(STR_DUP(fptr->op_array.filename, 0)); + RETURN_STR(STR_COPY(fptr->op_array.filename)); } RETURN_FALSE; } @@ -1854,8 +1853,7 @@ ZEND_METHOD(reflection_function, getDocComment) } GET_REFLECTION_OBJECT_PTR(fptr); if (fptr->type == ZEND_USER_FUNCTION && fptr->op_array.doc_comment) { -// TODO: we have to duplicate it, becaise it may be stored in opcache SHM ??? - RETURN_STR(STR_DUP(fptr->op_array.doc_comment, 0)); + RETURN_STR(STR_COPY(fptr->op_array.doc_comment)); } RETURN_FALSE; } @@ -3451,8 +3449,6 @@ ZEND_METHOD(reflection_class, setStaticPropertyValue) zend_class_entry *ce; zend_string *name; zval *variable_ptr, *value; -//??? int refcount; -//??? zend_uchar is_ref; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Sz", &name, &value) == FAILURE) { return; @@ -3467,13 +3463,8 @@ ZEND_METHOD(reflection_class, setStaticPropertyValue) "Class %s does not have a property named %s", ce->name->val, name->val); return; } -//??? refcount = Z_REFCOUNT_PP(variable_ptr); -//??? is_ref = Z_ISREF_PP(variable_ptr); - zval_dtor(variable_ptr); - ZVAL_DUP(variable_ptr, value); -//??? Z_SET_REFCOUNT_PP(variable_ptr, refcount); -//??? Z_SET_ISREF_TO_PP(variable_ptr, is_ref); - + zval_ptr_dtor(variable_ptr); + ZVAL_COPY(variable_ptr, value); } /* }}} */ @@ -3566,8 +3557,7 @@ ZEND_METHOD(reflection_class, getFileName) } GET_REFLECTION_OBJECT_PTR(ce); if (ce->type == ZEND_USER_CLASS) { -// TODO: we have to duplicate it, becaise it may be stored in opcache SHM ??? - RETURN_STR(STR_DUP(ce->info.user.filename, 0)); + RETURN_STR(STR_COPY(ce->info.user.filename)); } RETURN_FALSE; } -- cgit v1.2.1 From 87afa6bdc9b310ebafec5d965734c4e467e27c6d Mon Sep 17 00:00:00 2001 From: Tjerk Meesters Date: Thu, 14 Aug 2014 09:25:14 +0800 Subject: Fixes missing Reflector interface constraints being enforced by the engine --- ext/reflection/php_reflection.c | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) (limited to 'ext/reflection/php_reflection.c') diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 4248de834d..e4ad9416f0 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -261,15 +261,6 @@ static void _default_lookup_entry(zval *object, char *name, int name_len, zval * /* }}} */ #endif -static void reflection_register_implement(zend_class_entry *class_entry, zend_class_entry *interface_entry TSRMLS_DC) /* {{{ */ -{ - zend_uint num_interfaces = ++class_entry->num_interfaces; - - class_entry->interfaces = (zend_class_entry **) realloc(class_entry->interfaces, sizeof(zend_class_entry *) * num_interfaces); - class_entry->interfaces[num_interfaces - 1] = interface_entry; -} -/* }}} */ - static zend_function *_copy_function(zend_function *fptr TSRMLS_DC) /* {{{ */ { if (fptr @@ -5687,7 +5678,6 @@ ZEND_END_ARG_INFO() static const zend_function_entry reflection_function_abstract_functions[] = { ZEND_ME(reflection, __clone, arginfo_reflection__void, ZEND_ACC_PRIVATE|ZEND_ACC_FINAL) - PHP_ABSTRACT_ME(reflection_function, __toString, arginfo_reflection__void) ZEND_ME(reflection_function, inNamespace, arginfo_reflection__void, 0) ZEND_ME(reflection_function, isClosure, arginfo_reflection__void, 0) ZEND_ME(reflection_function, isDeprecated, arginfo_reflection__void, 0) @@ -6094,7 +6084,7 @@ PHP_MINIT_FUNCTION(reflection) /* {{{ */ INIT_CLASS_ENTRY(_reflection_entry, "ReflectionFunctionAbstract", reflection_function_abstract_functions); _reflection_entry.create_object = reflection_objects_new; reflection_function_abstract_ptr = zend_register_internal_class(&_reflection_entry TSRMLS_CC); - reflection_register_implement(reflection_function_abstract_ptr, reflector_ptr TSRMLS_CC); + zend_class_implements(reflection_function_abstract_ptr TSRMLS_CC, 1, reflector_ptr); zend_declare_property_string(reflection_function_abstract_ptr, "name", sizeof("name")-1, "", ZEND_ACC_ABSTRACT TSRMLS_CC); INIT_CLASS_ENTRY(_reflection_entry, "ReflectionFunction", reflection_function_functions); @@ -6107,7 +6097,7 @@ PHP_MINIT_FUNCTION(reflection) /* {{{ */ INIT_CLASS_ENTRY(_reflection_entry, "ReflectionParameter", reflection_parameter_functions); _reflection_entry.create_object = reflection_objects_new; reflection_parameter_ptr = zend_register_internal_class(&_reflection_entry TSRMLS_CC); - reflection_register_implement(reflection_parameter_ptr, reflector_ptr TSRMLS_CC); + zend_class_implements(reflection_parameter_ptr TSRMLS_CC, 1, reflector_ptr); zend_declare_property_string(reflection_parameter_ptr, "name", sizeof("name")-1, "", ZEND_ACC_PUBLIC TSRMLS_CC); INIT_CLASS_ENTRY(_reflection_entry, "ReflectionMethod", reflection_method_functions); @@ -6126,7 +6116,7 @@ PHP_MINIT_FUNCTION(reflection) /* {{{ */ INIT_CLASS_ENTRY(_reflection_entry, "ReflectionClass", reflection_class_functions); _reflection_entry.create_object = reflection_objects_new; reflection_class_ptr = zend_register_internal_class(&_reflection_entry TSRMLS_CC); - reflection_register_implement(reflection_class_ptr, reflector_ptr TSRMLS_CC); + zend_class_implements(reflection_class_ptr TSRMLS_CC, 1, reflector_ptr); zend_declare_property_string(reflection_class_ptr, "name", sizeof("name")-1, "", ZEND_ACC_PUBLIC TSRMLS_CC); REGISTER_REFLECTION_CLASS_CONST_LONG(class, "IS_IMPLICIT_ABSTRACT", ZEND_ACC_IMPLICIT_ABSTRACT_CLASS); @@ -6140,7 +6130,7 @@ PHP_MINIT_FUNCTION(reflection) /* {{{ */ INIT_CLASS_ENTRY(_reflection_entry, "ReflectionProperty", reflection_property_functions); _reflection_entry.create_object = reflection_objects_new; reflection_property_ptr = zend_register_internal_class(&_reflection_entry TSRMLS_CC); - reflection_register_implement(reflection_property_ptr, reflector_ptr TSRMLS_CC); + zend_class_implements(reflection_property_ptr TSRMLS_CC, 1, reflector_ptr); zend_declare_property_string(reflection_property_ptr, "name", sizeof("name")-1, "", ZEND_ACC_PUBLIC TSRMLS_CC); zend_declare_property_string(reflection_property_ptr, "class", sizeof("class")-1, "", ZEND_ACC_PUBLIC TSRMLS_CC); @@ -6152,13 +6142,13 @@ PHP_MINIT_FUNCTION(reflection) /* {{{ */ INIT_CLASS_ENTRY(_reflection_entry, "ReflectionExtension", reflection_extension_functions); _reflection_entry.create_object = reflection_objects_new; reflection_extension_ptr = zend_register_internal_class(&_reflection_entry TSRMLS_CC); - reflection_register_implement(reflection_extension_ptr, reflector_ptr TSRMLS_CC); + zend_class_implements(reflection_extension_ptr TSRMLS_CC, 1, reflector_ptr); zend_declare_property_string(reflection_extension_ptr, "name", sizeof("name")-1, "", ZEND_ACC_PUBLIC TSRMLS_CC); INIT_CLASS_ENTRY(_reflection_entry, "ReflectionZendExtension", reflection_zend_extension_functions); _reflection_entry.create_object = reflection_objects_new; reflection_zend_extension_ptr = zend_register_internal_class(&_reflection_entry TSRMLS_CC); - reflection_register_implement(reflection_zend_extension_ptr, reflector_ptr TSRMLS_CC); + zend_class_implements(reflection_zend_extension_ptr TSRMLS_CC, 1, reflector_ptr); zend_declare_property_string(reflection_zend_extension_ptr, "name", sizeof("name")-1, "", ZEND_ACC_PUBLIC TSRMLS_CC); return SUCCESS; -- cgit v1.2.1 From cb25136f4ef1042295650475b2c20ace81e2b9b7 Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Sat, 16 Aug 2014 11:37:14 +0200 Subject: fix macros in the 5 basic extensions --- ext/reflection/php_reflection.c | 84 ++++++++++++++++++++--------------------- 1 file changed, 42 insertions(+), 42 deletions(-) (limited to 'ext/reflection/php_reflection.c') diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 4248de834d..639016179f 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -110,8 +110,8 @@ ZEND_DECLARE_MODULE_GLOBALS(reflection) target = intern->ptr; \ /* Class constants */ -#define REGISTER_REFLECTION_CLASS_CONST_LONG(class_name, const_name, value) \ - zend_declare_class_constant_long(reflection_ ## class_name ## _ptr, const_name, sizeof(const_name)-1, (long)value TSRMLS_CC); +#define REGISTER_REFLECTION_CLASS_CONST_INT(class_name, const_name, value) \ + zend_declare_class_constant_int(reflection_ ## class_name ## _ptr, const_name, sizeof(const_name)-1, (long)value TSRMLS_CC); /* {{{ Smart string functions */ typedef struct _string { @@ -738,8 +738,8 @@ static void _parameter_string(string *str, zend_function *fptr, struct _zend_arg string_write(str, "NULL", sizeof("NULL")-1); } else if (Z_TYPE(zv) == IS_STRING) { string_write(str, "'", sizeof("'")-1); - string_write(str, Z_STRVAL(zv), MIN(Z_STRLEN(zv), 15)); - if (Z_STRLEN(zv) > 15) { + string_write(str, Z_STRVAL(zv), MIN(Z_STRSIZE(zv), 15)); + if (Z_STRSIZE(zv) > 15) { string_write(str, "...", sizeof("...")-1); } string_write(str, "'", sizeof("'")-1); @@ -1817,7 +1817,7 @@ ZEND_METHOD(reflection_function, getStartLine) } GET_REFLECTION_OBJECT_PTR(fptr); if (fptr->type == ZEND_USER_FUNCTION) { - RETURN_LONG(fptr->op_array.line_start); + RETURN_INT(fptr->op_array.line_start); } RETURN_FALSE; } @@ -1835,7 +1835,7 @@ ZEND_METHOD(reflection_function, getEndLine) } GET_REFLECTION_OBJECT_PTR(fptr); if (fptr->type == ZEND_USER_FUNCTION) { - RETURN_LONG(fptr->op_array.line_end); + RETURN_INT(fptr->op_array.line_end); } RETURN_FALSE; } @@ -2018,7 +2018,7 @@ ZEND_METHOD(reflection_function, getNumberOfParameters) METHOD_NOTSTATIC(reflection_function_abstract_ptr); GET_REFLECTION_OBJECT_PTR(fptr); - RETURN_LONG(fptr->common.num_args); + RETURN_INT(fptr->common.num_args); } /* }}} */ @@ -2032,7 +2032,7 @@ ZEND_METHOD(reflection_function, getNumberOfRequiredParameters) METHOD_NOTSTATIC(reflection_function_abstract_ptr); GET_REFLECTION_OBJECT_PTR(fptr); - RETURN_LONG(fptr->common.required_num_args); + RETURN_INT(fptr->common.required_num_args); } /* }}} */ @@ -2149,7 +2149,7 @@ ZEND_METHOD(reflection_parameter, __construct) unsigned int lcname_len; char *lcname; - lcname_len = Z_STRLEN_P(reference); + lcname_len = Z_STRSIZE_P(reference); lcname = zend_str_tolower_dup(Z_STRVAL_P(reference), lcname_len); if ((fptr = zend_hash_str_find_ptr(EG(function_table), lcname, lcname_len)) == NULL) { efree(lcname); @@ -2187,7 +2187,7 @@ ZEND_METHOD(reflection_parameter, __construct) } convert_to_string_ex(method); - lcname_len = Z_STRLEN_P(method); + lcname_len = Z_STRSIZE_P(method); lcname = zend_str_tolower_dup(Z_STRVAL_P(method), lcname_len); if (ce == zend_ce_closure && Z_TYPE_P(classref) == IS_OBJECT && (lcname_len == sizeof(ZEND_INVOKE_FUNC_NAME)-1) @@ -2228,8 +2228,8 @@ ZEND_METHOD(reflection_parameter, __construct) /* Now, search for the parameter */ arg_info = fptr->common.arg_info; - if (Z_TYPE_P(parameter) == IS_LONG) { - position= Z_LVAL_P(parameter); + if (Z_TYPE_P(parameter) == IS_INT) { + position= Z_IVAL_P(parameter); if (position < 0 || (zend_uint)position >= fptr->common.num_args) { if (fptr->common.fn_flags & ZEND_ACC_CALL_VIA_HANDLER) { if (fptr->type != ZEND_OVERLOADED_FUNCTION) { @@ -2512,7 +2512,7 @@ ZEND_METHOD(reflection_parameter, getPosition) } GET_REFLECTION_OBJECT_PTR(param); - RETVAL_LONG(param->offset); + RETVAL_INT(param->offset); } /* }}} */ @@ -3112,7 +3112,7 @@ ZEND_METHOD(reflection_function, inNamespace) RETURN_FALSE; } if (Z_TYPE_P(name) == IS_STRING - && (backslash = zend_memrchr(Z_STRVAL_P(name), '\\', Z_STRLEN_P(name))) + && (backslash = zend_memrchr(Z_STRVAL_P(name), '\\', Z_STRSIZE_P(name))) && backslash > Z_STRVAL_P(name)) { RETURN_TRUE; @@ -3135,7 +3135,7 @@ ZEND_METHOD(reflection_function, getNamespaceName) RETURN_FALSE; } if (Z_TYPE_P(name) == IS_STRING - && (backslash = zend_memrchr(Z_STRVAL_P(name), '\\', Z_STRLEN_P(name))) + && (backslash = zend_memrchr(Z_STRVAL_P(name), '\\', Z_STRSIZE_P(name))) && backslash > Z_STRVAL_P(name)) { RETURN_STRINGL(Z_STRVAL_P(name), backslash - Z_STRVAL_P(name)); @@ -3158,10 +3158,10 @@ ZEND_METHOD(reflection_function, getShortName) RETURN_FALSE; } if (Z_TYPE_P(name) == IS_STRING - && (backslash = zend_memrchr(Z_STRVAL_P(name), '\\', Z_STRLEN_P(name))) + && (backslash = zend_memrchr(Z_STRVAL_P(name), '\\', Z_STRSIZE_P(name))) && backslash > Z_STRVAL_P(name)) { - RETURN_STRINGL(backslash + 1, Z_STRLEN_P(name) - (backslash - Z_STRVAL_P(name) + 1)); + RETURN_STRINGL(backslash + 1, Z_STRSIZE_P(name) - (backslash - Z_STRVAL_P(name) + 1)); } RETURN_ZVAL(name, 1, 0); } @@ -3212,7 +3212,7 @@ ZEND_METHOD(reflection_method, getModifiers) } GET_REFLECTION_OBJECT_PTR(mptr); - RETURN_LONG(mptr->common.fn_flags); + RETURN_INT(mptr->common.fn_flags); } /* }}} */ @@ -3575,7 +3575,7 @@ ZEND_METHOD(reflection_class, getStartLine) } GET_REFLECTION_OBJECT_PTR(ce); if (ce->type == ZEND_USER_FUNCTION) { - RETURN_LONG(ce->info.user.line_start); + RETURN_INT(ce->info.user.line_start); } RETURN_FALSE; } @@ -3593,7 +3593,7 @@ ZEND_METHOD(reflection_class, getEndLine) } GET_REFLECTION_OBJECT_PTR(ce); if (ce->type == ZEND_USER_CLASS) { - RETURN_LONG(ce->info.user.line_end); + RETURN_INT(ce->info.user.line_end); } RETURN_FALSE; } @@ -4146,7 +4146,7 @@ ZEND_METHOD(reflection_class, getModifiers) } GET_REFLECTION_OBJECT_PTR(ce); - RETURN_LONG(ce->ce_flags & ~ZEND_ACC_CONSTANTS_UPDATED); + RETURN_INT(ce->ce_flags & ~ZEND_ACC_CONSTANTS_UPDATED); } /* }}} */ @@ -4657,7 +4657,7 @@ ZEND_METHOD(reflection_class, inNamespace) RETURN_FALSE; } if (Z_TYPE_P(name) == IS_STRING - && (backslash = zend_memrchr(Z_STRVAL_P(name), '\\', Z_STRLEN_P(name))) + && (backslash = zend_memrchr(Z_STRVAL_P(name), '\\', Z_STRSIZE_P(name))) && backslash > Z_STRVAL_P(name)) { RETURN_TRUE; @@ -4680,7 +4680,7 @@ ZEND_METHOD(reflection_class, getNamespaceName) RETURN_FALSE; } if (Z_TYPE_P(name) == IS_STRING - && (backslash = zend_memrchr(Z_STRVAL_P(name), '\\', Z_STRLEN_P(name))) + && (backslash = zend_memrchr(Z_STRVAL_P(name), '\\', Z_STRSIZE_P(name))) && backslash > Z_STRVAL_P(name)) { RETURN_STRINGL(Z_STRVAL_P(name), backslash - Z_STRVAL_P(name)); @@ -4703,10 +4703,10 @@ ZEND_METHOD(reflection_class, getShortName) RETURN_FALSE; } if (Z_TYPE_P(name) == IS_STRING - && (backslash = zend_memrchr(Z_STRVAL_P(name), '\\', Z_STRLEN_P(name))) + && (backslash = zend_memrchr(Z_STRVAL_P(name), '\\', Z_STRSIZE_P(name))) && backslash > Z_STRVAL_P(name)) { - RETURN_STRINGL(backslash + 1, Z_STRLEN_P(name) - (backslash - Z_STRVAL_P(name) + 1)); + RETURN_STRINGL(backslash + 1, Z_STRSIZE_P(name) - (backslash - Z_STRVAL_P(name) + 1)); } RETURN_ZVAL(name, 1, 0); } @@ -4926,7 +4926,7 @@ ZEND_METHOD(reflection_property, getModifiers) } GET_REFLECTION_OBJECT_PTR(ref); - RETURN_LONG(ref->prop.flags); + RETURN_INT(ref->prop.flags); } /* }}} */ @@ -6058,8 +6058,8 @@ static void _reflection_write_property(zval *object, zval *member, zval *value, { if ((Z_TYPE_P(member) == IS_STRING) && zend_hash_exists(&Z_OBJCE_P(object)->properties_info, Z_STR_P(member)) - && ((Z_STRLEN_P(member) == sizeof("name") - 1 && !memcmp(Z_STRVAL_P(member), "name", sizeof("name"))) - || (Z_STRLEN_P(member) == sizeof("class") - 1 && !memcmp(Z_STRVAL_P(member), "class", sizeof("class"))))) + && ((Z_STRSIZE_P(member) == sizeof("name") - 1 && !memcmp(Z_STRVAL_P(member), "name", sizeof("name"))) + || (Z_STRSIZE_P(member) == sizeof("class") - 1 && !memcmp(Z_STRVAL_P(member), "class", sizeof("class"))))) { zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Cannot set read-only property %s::$%s", Z_OBJCE_P(object)->name->val, Z_STRVAL_P(member)); @@ -6102,7 +6102,7 @@ PHP_MINIT_FUNCTION(reflection) /* {{{ */ reflection_function_ptr = zend_register_internal_class_ex(&_reflection_entry, reflection_function_abstract_ptr TSRMLS_CC); zend_declare_property_string(reflection_function_ptr, "name", sizeof("name")-1, "", ZEND_ACC_PUBLIC TSRMLS_CC); - REGISTER_REFLECTION_CLASS_CONST_LONG(function, "IS_DEPRECATED", ZEND_ACC_DEPRECATED); + REGISTER_REFLECTION_CLASS_CONST_INT(function, "IS_DEPRECATED", ZEND_ACC_DEPRECATED); INIT_CLASS_ENTRY(_reflection_entry, "ReflectionParameter", reflection_parameter_functions); _reflection_entry.create_object = reflection_objects_new; @@ -6116,12 +6116,12 @@ PHP_MINIT_FUNCTION(reflection) /* {{{ */ zend_declare_property_string(reflection_method_ptr, "name", sizeof("name")-1, "", ZEND_ACC_PUBLIC TSRMLS_CC); zend_declare_property_string(reflection_method_ptr, "class", sizeof("class")-1, "", ZEND_ACC_PUBLIC TSRMLS_CC); - REGISTER_REFLECTION_CLASS_CONST_LONG(method, "IS_STATIC", ZEND_ACC_STATIC); - REGISTER_REFLECTION_CLASS_CONST_LONG(method, "IS_PUBLIC", ZEND_ACC_PUBLIC); - REGISTER_REFLECTION_CLASS_CONST_LONG(method, "IS_PROTECTED", ZEND_ACC_PROTECTED); - REGISTER_REFLECTION_CLASS_CONST_LONG(method, "IS_PRIVATE", ZEND_ACC_PRIVATE); - REGISTER_REFLECTION_CLASS_CONST_LONG(method, "IS_ABSTRACT", ZEND_ACC_ABSTRACT); - REGISTER_REFLECTION_CLASS_CONST_LONG(method, "IS_FINAL", ZEND_ACC_FINAL); + REGISTER_REFLECTION_CLASS_CONST_INT(method, "IS_STATIC", ZEND_ACC_STATIC); + REGISTER_REFLECTION_CLASS_CONST_INT(method, "IS_PUBLIC", ZEND_ACC_PUBLIC); + REGISTER_REFLECTION_CLASS_CONST_INT(method, "IS_PROTECTED", ZEND_ACC_PROTECTED); + REGISTER_REFLECTION_CLASS_CONST_INT(method, "IS_PRIVATE", ZEND_ACC_PRIVATE); + REGISTER_REFLECTION_CLASS_CONST_INT(method, "IS_ABSTRACT", ZEND_ACC_ABSTRACT); + REGISTER_REFLECTION_CLASS_CONST_INT(method, "IS_FINAL", ZEND_ACC_FINAL); INIT_CLASS_ENTRY(_reflection_entry, "ReflectionClass", reflection_class_functions); _reflection_entry.create_object = reflection_objects_new; @@ -6129,9 +6129,9 @@ PHP_MINIT_FUNCTION(reflection) /* {{{ */ reflection_register_implement(reflection_class_ptr, reflector_ptr TSRMLS_CC); zend_declare_property_string(reflection_class_ptr, "name", sizeof("name")-1, "", ZEND_ACC_PUBLIC TSRMLS_CC); - REGISTER_REFLECTION_CLASS_CONST_LONG(class, "IS_IMPLICIT_ABSTRACT", ZEND_ACC_IMPLICIT_ABSTRACT_CLASS); - REGISTER_REFLECTION_CLASS_CONST_LONG(class, "IS_EXPLICIT_ABSTRACT", ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); - REGISTER_REFLECTION_CLASS_CONST_LONG(class, "IS_FINAL", ZEND_ACC_FINAL_CLASS); + REGISTER_REFLECTION_CLASS_CONST_INT(class, "IS_IMPLICIT_ABSTRACT", ZEND_ACC_IMPLICIT_ABSTRACT_CLASS); + REGISTER_REFLECTION_CLASS_CONST_INT(class, "IS_EXPLICIT_ABSTRACT", ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); + REGISTER_REFLECTION_CLASS_CONST_INT(class, "IS_FINAL", ZEND_ACC_FINAL_CLASS); INIT_CLASS_ENTRY(_reflection_entry, "ReflectionObject", reflection_object_functions); _reflection_entry.create_object = reflection_objects_new; @@ -6144,10 +6144,10 @@ PHP_MINIT_FUNCTION(reflection) /* {{{ */ zend_declare_property_string(reflection_property_ptr, "name", sizeof("name")-1, "", ZEND_ACC_PUBLIC TSRMLS_CC); zend_declare_property_string(reflection_property_ptr, "class", sizeof("class")-1, "", ZEND_ACC_PUBLIC TSRMLS_CC); - REGISTER_REFLECTION_CLASS_CONST_LONG(property, "IS_STATIC", ZEND_ACC_STATIC); - REGISTER_REFLECTION_CLASS_CONST_LONG(property, "IS_PUBLIC", ZEND_ACC_PUBLIC); - REGISTER_REFLECTION_CLASS_CONST_LONG(property, "IS_PROTECTED", ZEND_ACC_PROTECTED); - REGISTER_REFLECTION_CLASS_CONST_LONG(property, "IS_PRIVATE", ZEND_ACC_PRIVATE); + REGISTER_REFLECTION_CLASS_CONST_INT(property, "IS_STATIC", ZEND_ACC_STATIC); + REGISTER_REFLECTION_CLASS_CONST_INT(property, "IS_PUBLIC", ZEND_ACC_PUBLIC); + REGISTER_REFLECTION_CLASS_CONST_INT(property, "IS_PROTECTED", ZEND_ACC_PROTECTED); + REGISTER_REFLECTION_CLASS_CONST_INT(property, "IS_PRIVATE", ZEND_ACC_PRIVATE); INIT_CLASS_ENTRY(_reflection_entry, "ReflectionExtension", reflection_extension_functions); _reflection_entry.create_object = reflection_objects_new; -- cgit v1.2.1 From 1169de3e61975fe00fbf4768318eb095f22c63ec Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Sat, 16 Aug 2014 14:00:02 +0200 Subject: fix some cases with fast zpp --- ext/reflection/php_reflection.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'ext/reflection/php_reflection.c') diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 639016179f..f5eb473e0e 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -444,7 +444,7 @@ static void _class_string(string *str, zend_class_entry *ce, zval *obj, char *in HashPosition pos; zval *value; zend_string *key; - ulong num_index; + php_uint_t num_index; zend_hash_internal_pointer_reset_ex(&ce->constants_table, &pos); @@ -574,7 +574,7 @@ static void _class_string(string *str, zend_class_entry *ce, zval *obj, char *in while ((prop = zend_hash_get_current_data_ptr_ex(properties, &pos)) != NULL) { zend_string *prop_name; - ulong index; + php_uint_t index; if (zend_hash_get_current_key_ex(properties, &prop_name, &index, 0, &pos) == HASH_KEY_IS_STRING) { if (prop_name->len && prop_name->val[0]) { /* skip all private and protected properties */ @@ -611,7 +611,7 @@ static void _class_string(string *str, zend_class_entry *ce, zval *obj, char *in && ((mptr->common.fn_flags & ZEND_ACC_PRIVATE) == 0 || mptr->common.scope == ce)) { zend_string *key; - ulong num_index; + php_uint_t num_index; uint len = mptr->common.function_name->len; /* Do not display old-style inherited constructors */ @@ -783,7 +783,7 @@ static void _function_parameter_string(string *str, zend_function *fptr, char* i static void _function_closure_string(string *str, zend_function *fptr, char* indent TSRMLS_DC) { zend_uint i, count; - ulong num_index; + php_uint_t num_index; zend_string *key; HashTable *static_variables; HashPosition pos; @@ -3352,7 +3352,7 @@ static void add_class_vars(zend_class_entry *ce, int statics, zval *return_value zend_property_info *prop_info; zval *prop, prop_copy; zend_string *key; - ulong num_index; + php_uint_t num_index; ZEND_HASH_FOREACH_KEY_PTR(&ce->properties_info, num_index, key, prop_info) { if (((prop_info->flags & ZEND_ACC_SHADOW) && -- cgit v1.2.1 From fb8c41101d0e213494247783d7ce74f3809cb56e Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Thu, 21 Aug 2014 15:39:29 +0200 Subject: fix zpp --- ext/reflection/php_reflection.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'ext/reflection/php_reflection.c') diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index fa94785153..8d3e0494f6 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -1532,9 +1532,9 @@ ZEND_METHOD(reflection, export) Returns an array of modifier names */ ZEND_METHOD(reflection, getModifierNames) { - long modifiers; + php_int_t modifiers; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &modifiers) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "i", &modifiers) == FAILURE) { return; } @@ -3744,12 +3744,12 @@ ZEND_METHOD(reflection_class, getMethods) { reflection_object *intern; zend_class_entry *ce; - long filter = 0; + php_int_t filter = 0; int argc = ZEND_NUM_ARGS(); METHOD_NOTSTATIC(reflection_class_ptr); if (argc) { - if (zend_parse_parameters(argc TSRMLS_CC, "|l", &filter) == FAILURE) { + if (zend_parse_parameters(argc TSRMLS_CC, "|i", &filter) == FAILURE) { return; } } else { @@ -3934,12 +3934,12 @@ ZEND_METHOD(reflection_class, getProperties) { reflection_object *intern; zend_class_entry *ce; - long filter = 0; + php_int_t filter = 0; int argc = ZEND_NUM_ARGS(); METHOD_NOTSTATIC(reflection_class_ptr); if (argc) { - if (zend_parse_parameters(argc TSRMLS_CC, "|l", &filter) == FAILURE) { + if (zend_parse_parameters(argc TSRMLS_CC, "|i", &filter) == FAILURE) { return; } } else { -- cgit v1.2.1 From c3e3c98ec666812daaaca896cf5ef758a8a6df14 Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Mon, 25 Aug 2014 19:24:55 +0200 Subject: master renames phase 1 --- ext/reflection/php_reflection.c | 194 ++++++++++++++++++++-------------------- 1 file changed, 97 insertions(+), 97 deletions(-) (limited to 'ext/reflection/php_reflection.c') diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 8d3e0494f6..8262b86e1d 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -110,8 +110,8 @@ ZEND_DECLARE_MODULE_GLOBALS(reflection) target = intern->ptr; \ /* Class constants */ -#define REGISTER_REFLECTION_CLASS_CONST_INT(class_name, const_name, value) \ - zend_declare_class_constant_int(reflection_ ## class_name ## _ptr, const_name, sizeof(const_name)-1, (long)value TSRMLS_CC); +#define REGISTER_REFLECTION_CLASS_CONST_LONG(class_name, const_name, value) \ + zend_declare_class_constant_long(reflection_ ## class_name ## _ptr, const_name, sizeof(const_name)-1, (long)value TSRMLS_CC); /* {{{ Smart string functions */ typedef struct _string { @@ -121,7 +121,7 @@ typedef struct _string { static void string_init(string *str) { - str->buf= STR_ALLOC(1024, 0); + str->buf= zend_string_alloc(1024, 0); str->alloced = 1024; str->buf->val[0] = '\0'; str->buf->len = 0; @@ -140,7 +140,7 @@ static string *string_printf(string *str, const char *format, ...) if (str->alloced < nlen) { int old_len = str->buf->len; str->alloced = nlen; - str->buf = STR_REALLOC(str->buf, str->alloced, 0); + str->buf = zend_string_realloc(str->buf, str->alloced, 0); str->buf->len = old_len; } memcpy(str->buf->val + str->buf->len, s_tmp, len + 1); @@ -157,7 +157,7 @@ static string *string_write(string *str, char *buf, int len) if (str->alloced < nlen) { int old_len = str->buf->len; str->alloced = nlen; - str->buf = STR_REALLOC(str->buf, str->alloced, 0); + str->buf = zend_string_realloc(str->buf, str->alloced, 0); str->buf->len = old_len; } memcpy(str->buf->val + str->buf->len, buf, len); @@ -176,7 +176,7 @@ static string *string_append(string *str, string *append) static void string_free(string *str) { - STR_RELEASE(str->buf); + zend_string_release(str->buf); str->alloced = 0; str->buf = NULL; } @@ -270,7 +270,7 @@ static zend_function *_copy_function(zend_function *fptr TSRMLS_DC) /* {{{ */ zend_function *copy_fptr; copy_fptr = emalloc(sizeof(zend_function)); memcpy(copy_fptr, fptr, sizeof(zend_function)); - copy_fptr->internal_function.function_name = STR_COPY(fptr->internal_function.function_name); + copy_fptr->internal_function.function_name = zend_string_copy(fptr->internal_function.function_name); return copy_fptr; } else { /* no copy needed */ @@ -285,7 +285,7 @@ static void _free_function(zend_function *fptr TSRMLS_DC) /* {{{ */ && fptr->type == ZEND_INTERNAL_FUNCTION && (fptr->internal_function.fn_flags & ZEND_ACC_CALL_VIA_HANDLER) != 0) { - STR_RELEASE(fptr->internal_function.function_name); + zend_string_release(fptr->internal_function.function_name); efree(fptr); } } @@ -312,7 +312,7 @@ static void reflection_free_objects_storage(zend_object *object TSRMLS_DC) /* {{ break; case REF_TYPE_DYNAMIC_PROPERTY: prop_reference = (property_reference*)intern->ptr; - STR_RELEASE(prop_reference->prop.name); + zend_string_release(prop_reference->prop.name); efree(intern->ptr); break; case REF_TYPE_OTHER: @@ -435,7 +435,7 @@ static void _class_string(string *str, zend_class_entry *ce, zval *obj, char *in HashPosition pos; zval *value; zend_string *key; - php_uint_t num_index; + zend_ulong num_index; zend_hash_internal_pointer_reset_ex(&ce->constants_table, &pos); @@ -565,7 +565,7 @@ static void _class_string(string *str, zend_class_entry *ce, zval *obj, char *in while ((prop = zend_hash_get_current_data_ptr_ex(properties, &pos)) != NULL) { zend_string *prop_name; - php_uint_t index; + zend_ulong index; if (zend_hash_get_current_key_ex(properties, &prop_name, &index, 0, &pos) == HASH_KEY_IS_STRING) { if (prop_name->len && prop_name->val[0]) { /* skip all private and protected properties */ @@ -602,7 +602,7 @@ static void _class_string(string *str, zend_class_entry *ce, zval *obj, char *in && ((mptr->common.fn_flags & ZEND_ACC_PRIVATE) == 0 || mptr->common.scope == ce)) { zend_string *key; - php_uint_t num_index; + zend_ulong num_index; uint len = mptr->common.function_name->len; /* Do not display old-style inherited constructors */ @@ -655,7 +655,7 @@ static void _const_string(string *str, char *name, zval *value, char *indent TSR string_printf(str, "%s Constant [ %s %s ] { %s }\n", indent, type, name, value_str->val); - STR_RELEASE(value_str); + zend_string_release(value_str); } /* }}} */ @@ -729,8 +729,8 @@ static void _parameter_string(string *str, zend_function *fptr, struct _zend_arg string_write(str, "NULL", sizeof("NULL")-1); } else if (Z_TYPE(zv) == IS_STRING) { string_write(str, "'", sizeof("'")-1); - string_write(str, Z_STRVAL(zv), MIN(Z_STRSIZE(zv), 15)); - if (Z_STRSIZE(zv) > 15) { + string_write(str, Z_STRVAL(zv), MIN(Z_STRLEN(zv), 15)); + if (Z_STRLEN(zv) > 15) { string_write(str, "...", sizeof("...")-1); } string_write(str, "'", sizeof("'")-1); @@ -739,7 +739,7 @@ static void _parameter_string(string *str, zend_function *fptr, struct _zend_arg } else { zend_string *zv_str = zval_get_string(&zv); string_write(str, zv_str->val, zv_str->len); - STR_RELEASE(zv_str); + zend_string_release(zv_str); } zval_ptr_dtor(&zv); } @@ -774,7 +774,7 @@ static void _function_parameter_string(string *str, zend_function *fptr, char* i static void _function_closure_string(string *str, zend_function *fptr, char* indent TSRMLS_DC) { zend_uint i, count; - php_uint_t num_index; + zend_ulong num_index; zend_string *key; HashTable *static_variables; HashPosition pos; @@ -834,7 +834,7 @@ static void _function_string(string *str, zend_function *fptr, zend_class_entry string_printf(str, ", inherits %s", fptr->common.scope->name->val); } else if (fptr->common.scope->parent) { lc_name_len = fptr->common.function_name->len; - lc_name = STR_ALLOC(lc_name_len, 0); + lc_name = zend_string_alloc(lc_name_len, 0); zend_str_tolower_copy(lc_name->val, fptr->common.function_name->val, lc_name_len); if ((overwrites = zend_hash_find_ptr(&fptr->common.scope->parent->function_table, lc_name)) != NULL) { if (fptr->common.scope != overwrites->common.scope) { @@ -1178,7 +1178,7 @@ PHPAPI void zend_reflection_class_factory(zend_class_entry *ce, zval *object TSR reflection_object *intern; zval name; - ZVAL_STR(&name, STR_COPY(ce->name)); + ZVAL_STR(&name, zend_string_copy(ce->name)); reflection_instantiate(reflection_class_ptr, object TSRMLS_CC); intern = Z_REFLECTION_P(object); intern->ptr = ce; @@ -1197,10 +1197,10 @@ static void reflection_extension_factory(zval *object, const char *name_str TSRM zend_string *lcname; struct _zend_module_entry *module; - lcname = STR_ALLOC(name_len, 0); + lcname = zend_string_alloc(name_len, 0); zend_str_tolower_copy(lcname->val, name_str, name_len); module = zend_hash_find_ptr(&module_registry, lcname); - STR_FREE(lcname); + zend_string_free(lcname); if (!module) { return; } @@ -1251,7 +1251,7 @@ static void reflection_function_factory(zend_function *function, zval *closure_o reflection_object *intern; zval name; - ZVAL_STR(&name, STR_COPY(function->common.function_name)); + ZVAL_STR(&name, zend_string_copy(function->common.function_name)); reflection_instantiate(reflection_function_ptr, object TSRMLS_CC); intern = Z_REFLECTION_P(object); @@ -1273,9 +1273,9 @@ static void reflection_method_factory(zend_class_entry *ce, zend_function *metho zval name; zval classname; - ZVAL_STR(&name, STR_COPY((method->common.scope && method->common.scope->trait_aliases)? + ZVAL_STR(&name, zend_string_copy((method->common.scope && method->common.scope->trait_aliases)? zend_resolve_method_name(ce, method) : method->common.function_name)); - ZVAL_STR(&classname, STR_COPY(method->common.scope->name)); + ZVAL_STR(&classname, zend_string_copy(method->common.scope->name)); reflection_instantiate(reflection_method_ptr, object TSRMLS_CC); intern = Z_REFLECTION_P(object); intern->ptr = method; @@ -1319,7 +1319,7 @@ static void reflection_property_factory(zend_class_entry *ce, zend_property_info } ZVAL_STRING(&name, prop_name); - ZVAL_STR(&classname, STR_COPY(prop->ce->name)); + ZVAL_STR(&classname, zend_string_copy(prop->ce->name)); reflection_instantiate(reflection_property_ptr, object TSRMLS_CC); intern = Z_REFLECTION_P(object); @@ -1532,9 +1532,9 @@ ZEND_METHOD(reflection, export) Returns an array of modifier names */ ZEND_METHOD(reflection, getModifierNames) { - php_int_t modifiers; + zend_long modifiers; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "i", &modifiers) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &modifiers) == FAILURE) { return; } @@ -1622,7 +1622,7 @@ ZEND_METHOD(reflection_function, __construct) return; } - ZVAL_STR(&name, STR_COPY(fptr->common.function_name)); + ZVAL_STR(&name, zend_string_copy(fptr->common.function_name)); reflection_update_property(object, "name", &name); intern->ptr = fptr; intern->ref_type = REF_TYPE_FUNCTION; @@ -1790,7 +1790,7 @@ ZEND_METHOD(reflection_function, getFileName) } GET_REFLECTION_OBJECT_PTR(fptr); if (fptr->type == ZEND_USER_FUNCTION) { - RETURN_STR(STR_COPY(fptr->op_array.filename)); + RETURN_STR(zend_string_copy(fptr->op_array.filename)); } RETURN_FALSE; } @@ -1808,7 +1808,7 @@ ZEND_METHOD(reflection_function, getStartLine) } GET_REFLECTION_OBJECT_PTR(fptr); if (fptr->type == ZEND_USER_FUNCTION) { - RETURN_INT(fptr->op_array.line_start); + RETURN_LONG(fptr->op_array.line_start); } RETURN_FALSE; } @@ -1826,7 +1826,7 @@ ZEND_METHOD(reflection_function, getEndLine) } GET_REFLECTION_OBJECT_PTR(fptr); if (fptr->type == ZEND_USER_FUNCTION) { - RETURN_INT(fptr->op_array.line_end); + RETURN_LONG(fptr->op_array.line_end); } RETURN_FALSE; } @@ -1844,7 +1844,7 @@ ZEND_METHOD(reflection_function, getDocComment) } GET_REFLECTION_OBJECT_PTR(fptr); if (fptr->type == ZEND_USER_FUNCTION && fptr->op_array.doc_comment) { - RETURN_STR(STR_COPY(fptr->op_array.doc_comment)); + RETURN_STR(zend_string_copy(fptr->op_array.doc_comment)); } RETURN_FALSE; } @@ -2009,7 +2009,7 @@ ZEND_METHOD(reflection_function, getNumberOfParameters) METHOD_NOTSTATIC(reflection_function_abstract_ptr); GET_REFLECTION_OBJECT_PTR(fptr); - RETURN_INT(fptr->common.num_args); + RETURN_LONG(fptr->common.num_args); } /* }}} */ @@ -2023,7 +2023,7 @@ ZEND_METHOD(reflection_function, getNumberOfRequiredParameters) METHOD_NOTSTATIC(reflection_function_abstract_ptr); GET_REFLECTION_OBJECT_PTR(fptr); - RETURN_INT(fptr->common.required_num_args); + RETURN_LONG(fptr->common.required_num_args); } /* }}} */ @@ -2140,7 +2140,7 @@ ZEND_METHOD(reflection_parameter, __construct) unsigned int lcname_len; char *lcname; - lcname_len = Z_STRSIZE_P(reference); + lcname_len = Z_STRLEN_P(reference); lcname = zend_str_tolower_dup(Z_STRVAL_P(reference), lcname_len); if ((fptr = zend_hash_str_find_ptr(EG(function_table), lcname, lcname_len)) == NULL) { efree(lcname); @@ -2178,7 +2178,7 @@ ZEND_METHOD(reflection_parameter, __construct) } convert_to_string_ex(method); - lcname_len = Z_STRSIZE_P(method); + lcname_len = Z_STRLEN_P(method); lcname = zend_str_tolower_dup(Z_STRVAL_P(method), lcname_len); if (ce == zend_ce_closure && Z_TYPE_P(classref) == IS_OBJECT && (lcname_len == sizeof(ZEND_INVOKE_FUNC_NAME)-1) @@ -2219,12 +2219,12 @@ ZEND_METHOD(reflection_parameter, __construct) /* Now, search for the parameter */ arg_info = fptr->common.arg_info; - if (Z_TYPE_P(parameter) == IS_INT) { - position= Z_IVAL_P(parameter); + if (Z_TYPE_P(parameter) == IS_LONG) { + position= Z_LVAL_P(parameter); if (position < 0 || (zend_uint)position >= fptr->common.num_args) { if (fptr->common.fn_flags & ZEND_ACC_CALL_VIA_HANDLER) { if (fptr->type != ZEND_OVERLOADED_FUNCTION) { - STR_RELEASE(fptr->common.function_name); + zend_string_release(fptr->common.function_name); } efree(fptr); } @@ -2248,7 +2248,7 @@ ZEND_METHOD(reflection_parameter, __construct) if (position == -1) { if (fptr->common.fn_flags & ZEND_ACC_CALL_VIA_HANDLER) { if (fptr->type != ZEND_OVERLOADED_FUNCTION) { - STR_RELEASE(fptr->common.function_name); + zend_string_release(fptr->common.function_name); } efree(fptr); } @@ -2396,9 +2396,9 @@ ZEND_METHOD(reflection_parameter, getClass) } ce = ce->parent; } else { - zend_string *name = STR_INIT(param->arg_info->class_name, param->arg_info->class_name_len, 0); + zend_string *name = zend_string_init(param->arg_info->class_name, param->arg_info->class_name_len, 0); ce = zend_lookup_class(name TSRMLS_CC); - STR_FREE(name); + zend_string_free(name); if (!ce) { zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Class %s does not exist", param->arg_info->class_name); @@ -2503,7 +2503,7 @@ ZEND_METHOD(reflection_parameter, getPosition) } GET_REFLECTION_OBJECT_PTR(param); - RETVAL_INT(param->offset); + RETVAL_LONG(param->offset); } /* }}} */ @@ -2626,7 +2626,7 @@ ZEND_METHOD(reflection_parameter, getDefaultValueConstantName) precv = _reflection_param_get_default_precv(INTERNAL_FUNCTION_PARAM_PASSTHRU, param); if (precv && Z_TYPE_P(precv->op2.zv) == IS_CONSTANT) { - RETURN_STR(STR_COPY(Z_STR_P(precv->op2.zv))); + RETURN_STR(zend_string_copy(Z_STR_P(precv->op2.zv))); } } /* }}} */ @@ -2739,9 +2739,9 @@ ZEND_METHOD(reflection_method, __construct) } efree(lcname); - ZVAL_STR(&name, STR_COPY(mptr->common.scope->name)); + ZVAL_STR(&name, zend_string_copy(mptr->common.scope->name)); reflection_update_property(object, "class", &name); - ZVAL_STR(&name, STR_COPY(mptr->common.function_name)); + ZVAL_STR(&name, zend_string_copy(mptr->common.function_name)); reflection_update_property(object, "name", &name); intern->ptr = mptr; intern->ref_type = REF_TYPE_FUNCTION; @@ -3103,7 +3103,7 @@ ZEND_METHOD(reflection_function, inNamespace) RETURN_FALSE; } if (Z_TYPE_P(name) == IS_STRING - && (backslash = zend_memrchr(Z_STRVAL_P(name), '\\', Z_STRSIZE_P(name))) + && (backslash = zend_memrchr(Z_STRVAL_P(name), '\\', Z_STRLEN_P(name))) && backslash > Z_STRVAL_P(name)) { RETURN_TRUE; @@ -3126,7 +3126,7 @@ ZEND_METHOD(reflection_function, getNamespaceName) RETURN_FALSE; } if (Z_TYPE_P(name) == IS_STRING - && (backslash = zend_memrchr(Z_STRVAL_P(name), '\\', Z_STRSIZE_P(name))) + && (backslash = zend_memrchr(Z_STRVAL_P(name), '\\', Z_STRLEN_P(name))) && backslash > Z_STRVAL_P(name)) { RETURN_STRINGL(Z_STRVAL_P(name), backslash - Z_STRVAL_P(name)); @@ -3149,10 +3149,10 @@ ZEND_METHOD(reflection_function, getShortName) RETURN_FALSE; } if (Z_TYPE_P(name) == IS_STRING - && (backslash = zend_memrchr(Z_STRVAL_P(name), '\\', Z_STRSIZE_P(name))) + && (backslash = zend_memrchr(Z_STRVAL_P(name), '\\', Z_STRLEN_P(name))) && backslash > Z_STRVAL_P(name)) { - RETURN_STRINGL(backslash + 1, Z_STRSIZE_P(name) - (backslash - Z_STRVAL_P(name) + 1)); + RETURN_STRINGL(backslash + 1, Z_STRLEN_P(name) - (backslash - Z_STRVAL_P(name) + 1)); } RETURN_ZVAL(name, 1, 0); } @@ -3203,7 +3203,7 @@ ZEND_METHOD(reflection_method, getModifiers) } GET_REFLECTION_OBJECT_PTR(mptr); - RETURN_INT(mptr->common.fn_flags); + RETURN_LONG(mptr->common.fn_flags); } /* }}} */ @@ -3304,7 +3304,7 @@ static void reflection_class_object_ctor(INTERNAL_FUNCTION_PARAMETERS, int is_ob } if (Z_TYPE_P(argument) == IS_OBJECT) { - ZVAL_STR(&classname, STR_COPY(Z_OBJCE_P(argument)->name)); + ZVAL_STR(&classname, zend_string_copy(Z_OBJCE_P(argument)->name)); reflection_update_property(object, "name", &classname); intern->ptr = Z_OBJCE_P(argument); if (is_object) { @@ -3320,7 +3320,7 @@ static void reflection_class_object_ctor(INTERNAL_FUNCTION_PARAMETERS, int is_ob return; } - ZVAL_STR(&classname, STR_COPY(ce->name)); + ZVAL_STR(&classname, zend_string_copy(ce->name)); reflection_update_property(object, "name", &classname); intern->ptr = ce; @@ -3343,7 +3343,7 @@ static void add_class_vars(zend_class_entry *ce, int statics, zval *return_value zend_property_info *prop_info; zval *prop, prop_copy; zend_string *key; - php_uint_t num_index; + zend_ulong num_index; ZEND_HASH_FOREACH_KEY_PTR(&ce->properties_info, num_index, key, prop_info) { if (((prop_info->flags & ZEND_ACC_SHADOW) && @@ -3548,7 +3548,7 @@ ZEND_METHOD(reflection_class, getFileName) } GET_REFLECTION_OBJECT_PTR(ce); if (ce->type == ZEND_USER_CLASS) { - RETURN_STR(STR_COPY(ce->info.user.filename)); + RETURN_STR(zend_string_copy(ce->info.user.filename)); } RETURN_FALSE; } @@ -3566,7 +3566,7 @@ ZEND_METHOD(reflection_class, getStartLine) } GET_REFLECTION_OBJECT_PTR(ce); if (ce->type == ZEND_USER_FUNCTION) { - RETURN_INT(ce->info.user.line_start); + RETURN_LONG(ce->info.user.line_start); } RETURN_FALSE; } @@ -3584,7 +3584,7 @@ ZEND_METHOD(reflection_class, getEndLine) } GET_REFLECTION_OBJECT_PTR(ce); if (ce->type == ZEND_USER_CLASS) { - RETURN_INT(ce->info.user.line_end); + RETURN_LONG(ce->info.user.line_end); } RETURN_FALSE; } @@ -3602,7 +3602,7 @@ ZEND_METHOD(reflection_class, getDocComment) } GET_REFLECTION_OBJECT_PTR(ce); if (ce->type == ZEND_USER_CLASS && ce->info.user.doc_comment) { - RETURN_STR(STR_COPY(ce->info.user.doc_comment)); + RETURN_STR(zend_string_copy(ce->info.user.doc_comment)); } RETURN_FALSE; } @@ -3744,12 +3744,12 @@ ZEND_METHOD(reflection_class, getMethods) { reflection_object *intern; zend_class_entry *ce; - php_int_t filter = 0; + zend_long filter = 0; int argc = ZEND_NUM_ARGS(); METHOD_NOTSTATIC(reflection_class_ptr); if (argc) { - if (zend_parse_parameters(argc TSRMLS_CC, "|i", &filter) == FAILURE) { + if (zend_parse_parameters(argc TSRMLS_CC, "|l", &filter) == FAILURE) { return; } } else { @@ -3794,7 +3794,7 @@ ZEND_METHOD(reflection_class, hasProperty) RETURN_TRUE; } else { if (Z_TYPE(intern->obj) != IS_UNDEF && Z_OBJ_HANDLER(intern->obj, has_property)) { - ZVAL_STR(&property, STR_COPY(name)); + ZVAL_STR(&property, zend_string_copy(name)); if (Z_OBJ_HANDLER(intern->obj, has_property)(&intern->obj, &property, 2, NULL TSRMLS_CC)) { zval_ptr_dtor(&property); RETURN_TRUE; @@ -3833,7 +3833,7 @@ ZEND_METHOD(reflection_class, getProperty) if (zend_hash_exists(Z_OBJ_HT(intern->obj)->get_properties(&intern->obj TSRMLS_CC), name)) { zend_property_info property_info_tmp; property_info_tmp.flags = ZEND_ACC_IMPLICIT_PUBLIC; - property_info_tmp.name = STR_COPY(name); + property_info_tmp.name = zend_string_copy(name); property_info_tmp.doc_comment = NULL; property_info_tmp.ce = ce; @@ -3847,7 +3847,7 @@ ZEND_METHOD(reflection_class, getProperty) str_name_len = name->len; if ((tmp = strstr(name->val, "::")) != NULL) { classname_len = tmp - name->val; - classname = STR_ALLOC(classname_len, 0); + classname = zend_string_alloc(classname_len, 0); zend_str_tolower_copy(classname->val, name->val, classname_len); classname->val[classname_len] = '\0'; str_name_len = name->len - (classname_len + 2); @@ -3858,10 +3858,10 @@ ZEND_METHOD(reflection_class, getProperty) if (!EG(exception)) { zend_throw_exception_ex(reflection_exception_ptr, -1 TSRMLS_CC, "Class %s does not exist", classname->val); } - STR_FREE(classname); + zend_string_free(classname); return; } - STR_FREE(classname); + zend_string_free(classname); if (!instanceof_function(ce, ce2 TSRMLS_CC)) { zend_throw_exception_ex(reflection_exception_ptr, -1 TSRMLS_CC, "Fully qualified property name %s::%s does not specify a base class of %s", ce2->name->val, str_name, ce->name->val); @@ -3934,12 +3934,12 @@ ZEND_METHOD(reflection_class, getProperties) { reflection_object *intern; zend_class_entry *ce; - php_int_t filter = 0; + zend_long filter = 0; int argc = ZEND_NUM_ARGS(); METHOD_NOTSTATIC(reflection_class_ptr); if (argc) { - if (zend_parse_parameters(argc TSRMLS_CC, "|i", &filter) == FAILURE) { + if (zend_parse_parameters(argc TSRMLS_CC, "|l", &filter) == FAILURE) { return; } } else { @@ -4137,7 +4137,7 @@ ZEND_METHOD(reflection_class, getModifiers) } GET_REFLECTION_OBJECT_PTR(ce); - RETURN_INT(ce->ce_flags & ~ZEND_ACC_CONSTANTS_UPDATED); + RETURN_LONG(ce->ce_flags & ~ZEND_ACC_CONSTANTS_UPDATED); } /* }}} */ @@ -4380,7 +4380,7 @@ ZEND_METHOD(reflection_class, getInterfaceNames) array_init(return_value); for (i=0; i < ce->num_interfaces; i++) { - add_next_index_str(return_value, STR_COPY(ce->interfaces[i]->name)); + add_next_index_str(return_value, zend_string_copy(ce->interfaces[i]->name)); } } /* }}} */ @@ -4424,7 +4424,7 @@ ZEND_METHOD(reflection_class, getTraitNames) array_init(return_value); for (i=0; i < ce->num_traits; i++) { - add_next_index_str(return_value, STR_COPY(ce->traits[i]->name)); + add_next_index_str(return_value, zend_string_copy(ce->traits[i]->name)); } } /* }}} */ @@ -4451,7 +4451,7 @@ ZEND_METHOD(reflection_class, getTraitAliases) if (ce->trait_aliases[i]->alias) { - mname = STR_ALLOC(cur_ref->ce->name->len + cur_ref->method_name->len + 2, 0); + mname = zend_string_alloc(cur_ref->ce->name->len + cur_ref->method_name->len + 2, 0); snprintf(mname->val, mname->len + 1, "%s::%s", cur_ref->ce->name->val, cur_ref->method_name->val); add_assoc_str_ex(return_value, ce->trait_aliases[i]->alias->val, ce->trait_aliases[i]->alias->len, mname); } @@ -4648,7 +4648,7 @@ ZEND_METHOD(reflection_class, inNamespace) RETURN_FALSE; } if (Z_TYPE_P(name) == IS_STRING - && (backslash = zend_memrchr(Z_STRVAL_P(name), '\\', Z_STRSIZE_P(name))) + && (backslash = zend_memrchr(Z_STRVAL_P(name), '\\', Z_STRLEN_P(name))) && backslash > Z_STRVAL_P(name)) { RETURN_TRUE; @@ -4671,7 +4671,7 @@ ZEND_METHOD(reflection_class, getNamespaceName) RETURN_FALSE; } if (Z_TYPE_P(name) == IS_STRING - && (backslash = zend_memrchr(Z_STRVAL_P(name), '\\', Z_STRSIZE_P(name))) + && (backslash = zend_memrchr(Z_STRVAL_P(name), '\\', Z_STRLEN_P(name))) && backslash > Z_STRVAL_P(name)) { RETURN_STRINGL(Z_STRVAL_P(name), backslash - Z_STRVAL_P(name)); @@ -4694,10 +4694,10 @@ ZEND_METHOD(reflection_class, getShortName) RETURN_FALSE; } if (Z_TYPE_P(name) == IS_STRING - && (backslash = zend_memrchr(Z_STRVAL_P(name), '\\', Z_STRSIZE_P(name))) + && (backslash = zend_memrchr(Z_STRVAL_P(name), '\\', Z_STRLEN_P(name))) && backslash > Z_STRVAL_P(name)) { - RETURN_STRINGL(backslash + 1, Z_STRSIZE_P(name) - (backslash - Z_STRVAL_P(name) + 1)); + RETURN_STRINGL(backslash + 1, Z_STRLEN_P(name) - (backslash - Z_STRVAL_P(name) + 1)); } RETURN_ZVAL(name, 1, 0); } @@ -4797,10 +4797,10 @@ ZEND_METHOD(reflection_property, __construct) if (dynam_prop == 0) { zend_unmangle_property_name(property_info->name->val, property_info->name->len, &class_name, &prop_name); - ZVAL_STR(&cname, STR_COPY(property_info->ce->name)); + ZVAL_STR(&cname, zend_string_copy(property_info->ce->name)); ZVAL_STRING(&propname, prop_name); } else { - ZVAL_STR(&cname, STR_COPY(ce->name)); + ZVAL_STR(&cname, zend_string_copy(ce->name)); ZVAL_STRINGL(&propname, name_str, name_len); } reflection_update_property(object, "class", &cname); @@ -4917,7 +4917,7 @@ ZEND_METHOD(reflection_property, getModifiers) } GET_REFLECTION_OBJECT_PTR(ref); - RETURN_INT(ref->prop.flags); + RETURN_LONG(ref->prop.flags); } /* }}} */ @@ -5084,7 +5084,7 @@ ZEND_METHOD(reflection_property, getDocComment) } GET_REFLECTION_OBJECT_PTR(ref); if (ref->prop.doc_comment) { - RETURN_STR(STR_COPY(ref->prop.doc_comment)); + RETURN_STR(zend_string_copy(ref->prop.doc_comment)); } RETURN_FALSE; } @@ -5316,7 +5316,7 @@ static int add_extension_class(zval *zv TSRMLS_DC, int num_args, va_list args, z zend_reflection_class_factory(ce, &zclass TSRMLS_CC); zend_hash_update(Z_ARRVAL_P(class_array), ce->name, &zclass); } else { - add_next_index_str(class_array, STR_COPY(ce->name)); + add_next_index_str(class_array, zend_string_copy(ce->name)); } } return ZEND_HASH_APPLY_KEEP; @@ -5411,7 +5411,7 @@ ZEND_METHOD(reflection_extension, getDependencies) len += strlen(dep->version) + 1; } - relation = STR_ALLOC(len, 0); + relation = zend_string_alloc(len, 0); snprintf(relation->val, relation->len + 1, "%s%s%s%s%s", rel_type, dep->rel ? " " : "", @@ -6048,8 +6048,8 @@ static void _reflection_write_property(zval *object, zval *member, zval *value, { if ((Z_TYPE_P(member) == IS_STRING) && zend_hash_exists(&Z_OBJCE_P(object)->properties_info, Z_STR_P(member)) - && ((Z_STRSIZE_P(member) == sizeof("name") - 1 && !memcmp(Z_STRVAL_P(member), "name", sizeof("name"))) - || (Z_STRSIZE_P(member) == sizeof("class") - 1 && !memcmp(Z_STRVAL_P(member), "class", sizeof("class"))))) + && ((Z_STRLEN_P(member) == sizeof("name") - 1 && !memcmp(Z_STRVAL_P(member), "name", sizeof("name"))) + || (Z_STRLEN_P(member) == sizeof("class") - 1 && !memcmp(Z_STRVAL_P(member), "class", sizeof("class"))))) { zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Cannot set read-only property %s::$%s", Z_OBJCE_P(object)->name->val, Z_STRVAL_P(member)); @@ -6092,7 +6092,7 @@ PHP_MINIT_FUNCTION(reflection) /* {{{ */ reflection_function_ptr = zend_register_internal_class_ex(&_reflection_entry, reflection_function_abstract_ptr TSRMLS_CC); zend_declare_property_string(reflection_function_ptr, "name", sizeof("name")-1, "", ZEND_ACC_PUBLIC TSRMLS_CC); - REGISTER_REFLECTION_CLASS_CONST_INT(function, "IS_DEPRECATED", ZEND_ACC_DEPRECATED); + REGISTER_REFLECTION_CLASS_CONST_LONG(function, "IS_DEPRECATED", ZEND_ACC_DEPRECATED); INIT_CLASS_ENTRY(_reflection_entry, "ReflectionParameter", reflection_parameter_functions); _reflection_entry.create_object = reflection_objects_new; @@ -6106,12 +6106,12 @@ PHP_MINIT_FUNCTION(reflection) /* {{{ */ zend_declare_property_string(reflection_method_ptr, "name", sizeof("name")-1, "", ZEND_ACC_PUBLIC TSRMLS_CC); zend_declare_property_string(reflection_method_ptr, "class", sizeof("class")-1, "", ZEND_ACC_PUBLIC TSRMLS_CC); - REGISTER_REFLECTION_CLASS_CONST_INT(method, "IS_STATIC", ZEND_ACC_STATIC); - REGISTER_REFLECTION_CLASS_CONST_INT(method, "IS_PUBLIC", ZEND_ACC_PUBLIC); - REGISTER_REFLECTION_CLASS_CONST_INT(method, "IS_PROTECTED", ZEND_ACC_PROTECTED); - REGISTER_REFLECTION_CLASS_CONST_INT(method, "IS_PRIVATE", ZEND_ACC_PRIVATE); - REGISTER_REFLECTION_CLASS_CONST_INT(method, "IS_ABSTRACT", ZEND_ACC_ABSTRACT); - REGISTER_REFLECTION_CLASS_CONST_INT(method, "IS_FINAL", ZEND_ACC_FINAL); + REGISTER_REFLECTION_CLASS_CONST_LONG(method, "IS_STATIC", ZEND_ACC_STATIC); + REGISTER_REFLECTION_CLASS_CONST_LONG(method, "IS_PUBLIC", ZEND_ACC_PUBLIC); + REGISTER_REFLECTION_CLASS_CONST_LONG(method, "IS_PROTECTED", ZEND_ACC_PROTECTED); + REGISTER_REFLECTION_CLASS_CONST_LONG(method, "IS_PRIVATE", ZEND_ACC_PRIVATE); + REGISTER_REFLECTION_CLASS_CONST_LONG(method, "IS_ABSTRACT", ZEND_ACC_ABSTRACT); + REGISTER_REFLECTION_CLASS_CONST_LONG(method, "IS_FINAL", ZEND_ACC_FINAL); INIT_CLASS_ENTRY(_reflection_entry, "ReflectionClass", reflection_class_functions); _reflection_entry.create_object = reflection_objects_new; @@ -6119,9 +6119,9 @@ PHP_MINIT_FUNCTION(reflection) /* {{{ */ zend_class_implements(reflection_class_ptr TSRMLS_CC, 1, reflector_ptr); zend_declare_property_string(reflection_class_ptr, "name", sizeof("name")-1, "", ZEND_ACC_PUBLIC TSRMLS_CC); - REGISTER_REFLECTION_CLASS_CONST_INT(class, "IS_IMPLICIT_ABSTRACT", ZEND_ACC_IMPLICIT_ABSTRACT_CLASS); - REGISTER_REFLECTION_CLASS_CONST_INT(class, "IS_EXPLICIT_ABSTRACT", ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); - REGISTER_REFLECTION_CLASS_CONST_INT(class, "IS_FINAL", ZEND_ACC_FINAL_CLASS); + REGISTER_REFLECTION_CLASS_CONST_LONG(class, "IS_IMPLICIT_ABSTRACT", ZEND_ACC_IMPLICIT_ABSTRACT_CLASS); + REGISTER_REFLECTION_CLASS_CONST_LONG(class, "IS_EXPLICIT_ABSTRACT", ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); + REGISTER_REFLECTION_CLASS_CONST_LONG(class, "IS_FINAL", ZEND_ACC_FINAL_CLASS); INIT_CLASS_ENTRY(_reflection_entry, "ReflectionObject", reflection_object_functions); _reflection_entry.create_object = reflection_objects_new; @@ -6134,10 +6134,10 @@ PHP_MINIT_FUNCTION(reflection) /* {{{ */ zend_declare_property_string(reflection_property_ptr, "name", sizeof("name")-1, "", ZEND_ACC_PUBLIC TSRMLS_CC); zend_declare_property_string(reflection_property_ptr, "class", sizeof("class")-1, "", ZEND_ACC_PUBLIC TSRMLS_CC); - REGISTER_REFLECTION_CLASS_CONST_INT(property, "IS_STATIC", ZEND_ACC_STATIC); - REGISTER_REFLECTION_CLASS_CONST_INT(property, "IS_PUBLIC", ZEND_ACC_PUBLIC); - REGISTER_REFLECTION_CLASS_CONST_INT(property, "IS_PROTECTED", ZEND_ACC_PROTECTED); - REGISTER_REFLECTION_CLASS_CONST_INT(property, "IS_PRIVATE", ZEND_ACC_PRIVATE); + REGISTER_REFLECTION_CLASS_CONST_LONG(property, "IS_STATIC", ZEND_ACC_STATIC); + REGISTER_REFLECTION_CLASS_CONST_LONG(property, "IS_PUBLIC", ZEND_ACC_PUBLIC); + REGISTER_REFLECTION_CLASS_CONST_LONG(property, "IS_PROTECTED", ZEND_ACC_PROTECTED); + REGISTER_REFLECTION_CLASS_CONST_LONG(property, "IS_PRIVATE", ZEND_ACC_PRIVATE); INIT_CLASS_ENTRY(_reflection_entry, "ReflectionExtension", reflection_extension_functions); _reflection_entry.create_object = reflection_objects_new; -- cgit v1.2.1 From 6f9f0bf2056f0dc17d9bcc6dd3b7d28ac878c6fc Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Mon, 25 Aug 2014 19:28:33 +0200 Subject: master renames phase 2 --- ext/reflection/php_reflection.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'ext/reflection/php_reflection.c') diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 8262b86e1d..94cb3fb273 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -192,8 +192,8 @@ typedef struct _property_reference { /* Struct for parameters */ typedef struct _parameter_reference { - zend_uint offset; - zend_uint required; + uint32_t offset; + uint32_t required; struct _zend_arg_info *arg_info; zend_function *fptr; } parameter_reference; @@ -406,7 +406,7 @@ static void _class_string(string *str, zend_class_entry *ce, zval *obj, char *in } if (ce->num_interfaces) { - zend_uint i; + uint32_t i; if (ce->ce_flags & ZEND_ACC_INTERFACE) { string_printf(str, " extends %s", ce->interfaces[0]->name->val); @@ -660,7 +660,7 @@ static void _const_string(string *str, char *name, zval *value, char *indent TSR /* }}} */ /* {{{ _get_recv_opcode */ -static zend_op* _get_recv_op(zend_op_array *op_array, zend_uint offset) +static zend_op* _get_recv_op(zend_op_array *op_array, uint32_t offset) { zend_op *op = op_array->opcodes; zend_op *end = op + op_array->last; @@ -679,7 +679,7 @@ static zend_op* _get_recv_op(zend_op_array *op_array, zend_uint offset) /* }}} */ /* {{{ _parameter_string */ -static void _parameter_string(string *str, zend_function *fptr, struct _zend_arg_info *arg_info, zend_uint offset, zend_uint required, char* indent TSRMLS_DC) +static void _parameter_string(string *str, zend_function *fptr, struct _zend_arg_info *arg_info, uint32_t offset, uint32_t required, char* indent TSRMLS_DC) { string_printf(str, "Parameter #%d [ ", offset); if (offset >= required) { @@ -752,7 +752,7 @@ static void _parameter_string(string *str, zend_function *fptr, struct _zend_arg static void _function_parameter_string(string *str, zend_function *fptr, char* indent TSRMLS_DC) { struct _zend_arg_info *arg_info = fptr->common.arg_info; - zend_uint i, required = fptr->common.required_num_args; + uint32_t i, required = fptr->common.required_num_args; if (!arg_info) { return; @@ -773,7 +773,7 @@ static void _function_parameter_string(string *str, zend_function *fptr, char* i /* {{{ _function_closure_string */ static void _function_closure_string(string *str, zend_function *fptr, char* indent TSRMLS_DC) { - zend_uint i, count; + uint32_t i, count; zend_ulong num_index; zend_string *key; HashTable *static_variables; @@ -1216,7 +1216,7 @@ static void reflection_extension_factory(zval *object, const char *name_str TSRM /* }}} */ /* {{{ reflection_parameter_factory */ -static void reflection_parameter_factory(zend_function *fptr, zval *closure_object, struct _zend_arg_info *arg_info, zend_uint offset, zend_uint required, zval *object TSRMLS_DC) +static void reflection_parameter_factory(zend_function *fptr, zval *closure_object, struct _zend_arg_info *arg_info, uint32_t offset, uint32_t required, zval *object TSRMLS_DC) { reflection_object *intern; parameter_reference *reference; @@ -2033,7 +2033,7 @@ ZEND_METHOD(reflection_function, getParameters) { reflection_object *intern; zend_function *fptr; - zend_uint i; + uint32_t i; struct _zend_arg_info *arg_info; METHOD_NOTSTATIC(reflection_function_abstract_ptr); @@ -2221,7 +2221,7 @@ ZEND_METHOD(reflection_parameter, __construct) arg_info = fptr->common.arg_info; if (Z_TYPE_P(parameter) == IS_LONG) { position= Z_LVAL_P(parameter); - if (position < 0 || (zend_uint)position >= fptr->common.num_args) { + if (position < 0 || (uint32_t)position >= fptr->common.num_args) { if (fptr->common.fn_flags & ZEND_ACC_CALL_VIA_HANDLER) { if (fptr->type != ZEND_OVERLOADED_FUNCTION) { zend_string_release(fptr->common.function_name); @@ -2235,7 +2235,7 @@ ZEND_METHOD(reflection_parameter, __construct) /* returns out of this function */ } } else { - zend_uint i; + uint32_t i; position= -1; convert_to_string_ex(parameter); @@ -2269,7 +2269,7 @@ ZEND_METHOD(reflection_parameter, __construct) ref = (parameter_reference*) emalloc(sizeof(parameter_reference)); ref->arg_info = &arg_info[position]; - ref->offset = (zend_uint)position; + ref->offset = (uint32_t)position; ref->required = fptr->common.required_num_args; ref->fptr = fptr; /* TODO: copy fptr */ @@ -4352,7 +4352,7 @@ ZEND_METHOD(reflection_class, getInterfaces) array_init(return_value); if (ce->num_interfaces) { - zend_uint i; + uint32_t i; for (i=0; i < ce->num_interfaces; i++) { zval interface; @@ -4369,7 +4369,7 @@ ZEND_METHOD(reflection_class, getInterfaceNames) { reflection_object *intern; zend_class_entry *ce; - zend_uint i; + uint32_t i; if (zend_parse_parameters_none() == FAILURE) { return; @@ -4391,7 +4391,7 @@ ZEND_METHOD(reflection_class, getTraits) { reflection_object *intern; zend_class_entry *ce; - zend_uint i; + uint32_t i; if (zend_parse_parameters_none() == FAILURE) { return; @@ -4414,7 +4414,7 @@ ZEND_METHOD(reflection_class, getTraitNames) { reflection_object *intern; zend_class_entry *ce; - zend_uint i; + uint32_t i; if (zend_parse_parameters_none() == FAILURE) { return; @@ -4444,7 +4444,7 @@ ZEND_METHOD(reflection_class, getTraitAliases) array_init(return_value); if (ce->trait_aliases) { - zend_uint i = 0; + uint32_t i = 0; while (ce->trait_aliases[i]) { zend_string *mname; zend_trait_method_reference *cur_ref = ce->trait_aliases[i]->trait_method; -- cgit v1.2.1 From 202e8db1dc8e1203039327d81ce6fd82c1c2d909 Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Tue, 26 Aug 2014 11:23:25 +0200 Subject: fixed several long vs zend_long casts --- ext/reflection/php_reflection.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'ext/reflection/php_reflection.c') diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 94cb3fb273..36e1588fe2 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -111,7 +111,7 @@ ZEND_DECLARE_MODULE_GLOBALS(reflection) /* Class constants */ #define REGISTER_REFLECTION_CLASS_CONST_LONG(class_name, const_name, value) \ - zend_declare_class_constant_long(reflection_ ## class_name ## _ptr, const_name, sizeof(const_name)-1, (long)value TSRMLS_CC); + zend_declare_class_constant_long(reflection_ ## class_name ## _ptr, const_name, sizeof(const_name)-1, (zend_long)value TSRMLS_CC); /* {{{ Smart string functions */ typedef struct _string { @@ -668,7 +668,7 @@ static zend_op* _get_recv_op(zend_op_array *op_array, uint32_t offset) ++offset; while (op < end) { if ((op->opcode == ZEND_RECV || op->opcode == ZEND_RECV_INIT - || op->opcode == ZEND_RECV_VARIADIC) && op->op1.num == (long)offset) + || op->opcode == ZEND_RECV_VARIADIC) && op->op1.num == (zend_long)offset) { return op; } -- cgit v1.2.1 From 3234480827b27ff5d3469a732167afd289632a96 Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Wed, 27 Aug 2014 15:31:48 +0200 Subject: first show to make 's' work with size_t --- ext/reflection/php_reflection.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'ext/reflection/php_reflection.c') diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 36e1588fe2..962f59dc68 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -226,7 +226,7 @@ static inline reflection_object *reflection_object_from_obj(zend_object *obj) /* static zend_object_handlers reflection_object_handlers; -static zval *_default_load_entry(zval *object, char *name, int name_len TSRMLS_DC) /* {{{ */ +static zval *_default_load_entry(zval *object, char *name, size_t name_len TSRMLS_DC) /* {{{ */ { zval *value; @@ -1588,7 +1588,7 @@ ZEND_METHOD(reflection_function, __construct) reflection_object *intern; zend_function *fptr; char *name_str; - int name_len; + size_t name_len; object = getThis(); intern = Z_REFLECTION_P(object); @@ -2666,7 +2666,7 @@ ZEND_METHOD(reflection_method, __construct) zend_class_entry *ce; zend_function *mptr; char *name_str, *tmp; - int name_len, tmp_len; + size_t name_len, tmp_len; zval ztmp; if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "zs", &classname, &name_str, &name_len) == FAILURE) { -- cgit v1.2.1 From 257ed4061ae88802538a6f22724c57fda052e36e Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Wed, 27 Aug 2014 17:31:24 +0200 Subject: 's' works with size_t round 2 --- ext/reflection/php_reflection.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'ext/reflection/php_reflection.c') diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 962f59dc68..8c4c487da3 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -3635,7 +3635,7 @@ ZEND_METHOD(reflection_class, hasMethod) reflection_object *intern; zend_class_entry *ce; char *name, *lc_name; - int name_len; + size_t name_len; METHOD_NOTSTATIC(reflection_class_ptr); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len) == FAILURE) { @@ -3665,7 +3665,7 @@ ZEND_METHOD(reflection_class, getMethod) zend_function *mptr; zval obj_tmp; char *name, *lc_name; - int name_len; + size_t name_len; METHOD_NOTSTATIC(reflection_class_ptr); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len) == FAILURE) { @@ -4734,7 +4734,8 @@ ZEND_METHOD(reflection_property, __construct) zval propname, cname, *classname; char *name_str; const char *class_name, *prop_name; - int name_len, dynam_prop = 0; + size_t name_len; + int dynam_prop = 0; zval *object; reflection_object *intern; zend_class_entry *ce; @@ -5129,7 +5130,7 @@ ZEND_METHOD(reflection_extension, __construct) reflection_object *intern; zend_module_entry *module; char *name_str; - int name_len; + size_t name_len; ALLOCA_FLAG(use_heap) if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name_str, &name_len) == FAILURE) { @@ -5489,7 +5490,7 @@ ZEND_METHOD(reflection_zend_extension, __construct) reflection_object *intern; zend_extension *extension; char *name_str; - int name_len; + size_t name_len; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name_str, &name_len) == FAILURE) { return; -- cgit v1.2.1 From 88d7ca44f645c6e1bbdb17affd7a34113911093d Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Mon, 1 Sep 2014 20:57:33 +0400 Subject: Refactored INI subsystem to use zend_string* instead of char* --- ext/reflection/php_reflection.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'ext/reflection/php_reflection.c') diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 8c4c487da3..a2c88044fd 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -958,7 +958,7 @@ static int _extension_ini_string(zval *el TSRMLS_DC, int num_args, va_list args, char *comma = ""; if (number == ini_entry->module_number) { - string_printf(str, " %sEntry [ %s <", indent, ini_entry->name); + string_printf(str, " %sEntry [ %s <", indent, ini_entry->name->val); if (ini_entry->modifiable == ZEND_INI_ALL) { string_printf(str, "ALL"); } else { @@ -976,9 +976,9 @@ static int _extension_ini_string(zval *el TSRMLS_DC, int num_args, va_list args, } string_printf(str, "> ]\n"); - string_printf(str, " %s Current = '%s'\n", indent, ini_entry->value ? ini_entry->value : ""); + string_printf(str, " %s Current = '%s'\n", indent, ini_entry->value ? ini_entry->value->val : ""); if (ini_entry->modified) { - string_printf(str, " %s Default = '%s'\n", indent, ini_entry->orig_value ? ini_entry->orig_value : ""); + string_printf(str, " %s Default = '%s'\n", indent, ini_entry->orig_value ? ini_entry->orig_value->val : ""); } string_printf(str, " %s}\n", indent); } @@ -5278,9 +5278,12 @@ static int _addinientry(zval *el TSRMLS_DC, int num_args, va_list args, zend_has if (number == ini_entry->module_number) { if (ini_entry->value) { - add_assoc_stringl(retval, ini_entry->name, ini_entry->value, ini_entry->value_length); + zval zv; + + ZVAL_STR(&zv, ini_entry->value); + zend_symtable_update(Z_ARRVAL_P(retval), ini_entry->name, &zv); } else { - add_assoc_null(retval, ini_entry->name); + zend_symtable_update(Z_ARRVAL_P(retval), ini_entry->name, &EG(uninitialized_zval)); } } return ZEND_HASH_APPLY_KEEP; -- cgit v1.2.1 From e51677b2e6ce72a3c1325e14ff932720f5b5d523 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Tue, 2 Sep 2014 11:24:52 +0400 Subject: fixed reference counting --- ext/reflection/php_reflection.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ext/reflection/php_reflection.c') diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index a2c88044fd..ad6a2fb841 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -5280,7 +5280,7 @@ static int _addinientry(zval *el TSRMLS_DC, int num_args, va_list args, zend_has if (ini_entry->value) { zval zv; - ZVAL_STR(&zv, ini_entry->value); + ZVAL_STR(&zv, zend_string_copy(ini_entry->value)); zend_symtable_update(Z_ARRVAL_P(retval), ini_entry->name, &zv); } else { zend_symtable_update(Z_ARRVAL_P(retval), ini_entry->name, &EG(uninitialized_zval)); -- cgit v1.2.1 From 0b40abf41d67cacb605ea4def917428e078ca758 Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Sun, 14 Sep 2014 12:30:01 +0200 Subject: avoid repeated strlen() usage --- ext/reflection/php_reflection.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'ext/reflection/php_reflection.c') diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index ad6a2fb841..cd9f65dfd3 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -1298,15 +1298,18 @@ static void reflection_property_factory(zend_class_entry *ce, zend_property_info zval classname; property_reference *reference; const char *class_name, *prop_name; + int prop_name_len; zend_unmangle_property_name(prop->name->val, prop->name->len, &class_name, &prop_name); + prop_name_len = (int)strlen(prop_name); + if (!(prop->flags & ZEND_ACC_PRIVATE)) { /* we have to search the class hierarchy for this (implicit) public or protected property */ zend_class_entry *tmp_ce = ce, *store_ce = ce; zend_property_info *tmp_info = NULL; - while (tmp_ce && (tmp_info = zend_hash_str_find_ptr(&tmp_ce->properties_info, prop_name, strlen(prop_name))) == NULL) { + while (tmp_ce && (tmp_info = zend_hash_str_find_ptr(&tmp_ce->properties_info, prop_name, prop_name_len)) == NULL) { ce = tmp_ce; tmp_ce = tmp_ce->parent; } @@ -1318,7 +1321,7 @@ static void reflection_property_factory(zend_class_entry *ce, zend_property_info } } - ZVAL_STRING(&name, prop_name); + ZVAL_STRINGL(&name, prop_name, prop_name_len); ZVAL_STR(&classname, zend_string_copy(prop->ce->name)); reflection_instantiate(reflection_property_ptr, object TSRMLS_CC); -- cgit v1.2.1 From f1ba5389cd0e13da2230dd411c6151dedde88552 Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Sun, 14 Sep 2014 12:32:38 +0200 Subject: reduce struct size by 8 bytes on 64 bit --- ext/reflection/php_reflection.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'ext/reflection/php_reflection.c') diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index cd9f65dfd3..9274ed5fe5 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -209,10 +209,10 @@ typedef enum { /* Struct for reflection objects */ typedef struct { zval dummy; /* holder for the second property */ - void *ptr; - reflection_type_t ref_type; zval obj; + void *ptr; zend_class_entry *ce; + reflection_type_t ref_type; unsigned int ignore_visibility:1; zend_object zo; } reflection_object; -- cgit v1.2.1 From 734d0b6bfdddfcedf3958eb92912c4709c4957fd Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Sun, 14 Sep 2014 15:09:54 +0200 Subject: use nice way to achieve the property name length --- ext/reflection/php_reflection.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'ext/reflection/php_reflection.c') diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 9274ed5fe5..6888a6c5d9 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -1300,9 +1300,7 @@ static void reflection_property_factory(zend_class_entry *ce, zend_property_info const char *class_name, *prop_name; int prop_name_len; - zend_unmangle_property_name(prop->name->val, prop->name->len, &class_name, &prop_name); - - prop_name_len = (int)strlen(prop_name); + zend_unmangle_property_name_ex(prop->name->val, prop->name->len, &class_name, &prop_name, &prop_name_len); if (!(prop->flags & ZEND_ACC_PRIVATE)) { /* we have to search the class hierarchy for this (implicit) public or protected property */ -- cgit v1.2.1 From ebc6da5628d356bafba45f4632ecd4f3db1ad128 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Sat, 13 Sep 2014 23:14:04 +0200 Subject: zend_get_property_info takes a zend_string* now --- ext/reflection/php_reflection.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'ext/reflection/php_reflection.c') diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 6888a6c5d9..c52f8d155c 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -3906,7 +3906,7 @@ static int _adddynproperty(zval *ptr TSRMLS_DC, int num_args, va_list args, zend { zval property; zend_class_entry *ce = *va_arg(args, zend_class_entry**); - zval *retval = va_arg(args, zval*), member; + zval *retval = va_arg(args, zval*); /* under some circumstances, the properties hash table may contain numeric * properties (e.g. when casting from array). This is a WONT FIX bug, at @@ -3919,8 +3919,7 @@ static int _adddynproperty(zval *ptr TSRMLS_DC, int num_args, va_list args, zend return 0; /* non public cannot be dynamic */ } - ZVAL_STR(&member, hash_key->key); - if (zend_get_property_info(ce, &member, 1 TSRMLS_CC) == &EG(std_property_info)) { + if (zend_get_property_info(ce, hash_key->key, 1 TSRMLS_CC) == &EG(std_property_info)) { EG(std_property_info).flags = ZEND_ACC_IMPLICIT_PUBLIC; reflection_property_factory(ce, &EG(std_property_info), &property TSRMLS_CC); add_next_index_zval(retval, &property); -- cgit v1.2.1 From 079409bbc232f16fd446935a2103ece9d12082ed Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Tue, 16 Sep 2014 00:23:58 +0200 Subject: Switch (un)mangle property name to size_t and zend_string Also use the _ex variants where possible. --- ext/reflection/php_reflection.c | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) (limited to 'ext/reflection/php_reflection.c') diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index c52f8d155c..c2e2610308 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -941,7 +941,7 @@ static void _property_string(string *str, zend_property_info *prop, char *prop_n string_printf(str, "static "); } - zend_unmangle_property_name(prop->name->val, prop->name->len, &class_name, (const char**)&prop_name); + zend_unmangle_property_name(prop->name, &class_name, (const char**)&prop_name); string_printf(str, "$%s", prop_name); } @@ -1298,9 +1298,9 @@ static void reflection_property_factory(zend_class_entry *ce, zend_property_info zval classname; property_reference *reference; const char *class_name, *prop_name; - int prop_name_len; + size_t prop_name_len; - zend_unmangle_property_name_ex(prop->name->val, prop->name->len, &class_name, &prop_name, &prop_name_len); + zend_unmangle_property_name_ex(prop->name, &class_name, &prop_name, &prop_name_len); if (!(prop->flags & ZEND_ACC_PRIVATE)) { /* we have to search the class hierarchy for this (implicit) public or protected property */ @@ -4733,7 +4733,6 @@ ZEND_METHOD(reflection_property, __construct) { zval propname, cname, *classname; char *name_str; - const char *class_name, *prop_name; size_t name_len; int dynam_prop = 0; zval *object; @@ -4797,9 +4796,11 @@ ZEND_METHOD(reflection_property, __construct) } if (dynam_prop == 0) { - zend_unmangle_property_name(property_info->name->val, property_info->name->len, &class_name, &prop_name); + const char *class_name, *prop_name; + size_t prop_name_len; + zend_unmangle_property_name_ex(property_info->name, &class_name, &prop_name, &prop_name_len); ZVAL_STR(&cname, zend_string_copy(property_info->ce->name)); - ZVAL_STRING(&propname, prop_name); + ZVAL_STRINGL(&propname, prop_name, prop_name_len); } else { ZVAL_STR(&cname, zend_string_copy(ce->name)); ZVAL_STRINGL(&propname, name_str, name_len); @@ -4950,12 +4951,14 @@ ZEND_METHOD(reflection_property, getValue) ZVAL_DUP(return_value, &CE_STATIC_MEMBERS(intern->ce)[ref->prop.offset]); } else { const char *class_name, *prop_name; + size_t prop_name_len; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &object) == FAILURE) { return; } - 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); + + zend_unmangle_property_name_ex(ref->prop.name, &class_name, &prop_name, &prop_name_len); + member_p = zend_read_property(ref->ce, object, prop_name, prop_name_len, 1 TSRMLS_CC); ZVAL_DUP(return_value, member_p); } } @@ -5024,12 +5027,14 @@ ZEND_METHOD(reflection_property, setValue) } } else { const char *class_name, *prop_name; + size_t prop_name_len; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "oz", &object, &value) == FAILURE) { return; } - zend_unmangle_property_name(ref->prop.name->val, ref->prop.name->len, &class_name, &prop_name); - zend_update_property(ref->ce, object, prop_name, strlen(prop_name), value TSRMLS_CC); + + zend_unmangle_property_name_ex(ref->prop.name, &class_name, &prop_name, &prop_name_len); + zend_update_property(ref->ce, object, prop_name, prop_name_len, value TSRMLS_CC); } } /* }}} */ @@ -5043,18 +5048,17 @@ ZEND_METHOD(reflection_property, getDeclaringClass) zend_class_entry *tmp_ce, *ce; zend_property_info *tmp_info; const char *prop_name, *class_name; - int prop_name_len; + size_t prop_name_len; if (zend_parse_parameters_none() == FAILURE) { return; } GET_REFLECTION_OBJECT_PTR(ref); - if (zend_unmangle_property_name(ref->prop.name->val, ref->prop.name->len, &class_name, &prop_name) != SUCCESS) { + if (zend_unmangle_property_name_ex(ref->prop.name, &class_name, &prop_name, &prop_name_len) != SUCCESS) { RETURN_FALSE; } - prop_name_len = strlen(prop_name); ce = tmp_ce = ref->ce; while (tmp_ce && (tmp_info = zend_hash_str_find_ptr(&tmp_ce->properties_info, prop_name, prop_name_len)) != NULL) { if (tmp_info->flags & ZEND_ACC_PRIVATE || tmp_info->flags & ZEND_ACC_SHADOW) { -- cgit v1.2.1 From bccc653185d2fe8aa6ff83cf84db56a396c6bc05 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Fri, 19 Sep 2014 17:32:50 +0400 Subject: Avoid double IS_INTERNED() check --- ext/reflection/php_reflection.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'ext/reflection/php_reflection.c') diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index c2e2610308..7e4f4ab7fb 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -1178,7 +1178,7 @@ PHPAPI void zend_reflection_class_factory(zend_class_entry *ce, zval *object TSR reflection_object *intern; zval name; - ZVAL_STR(&name, zend_string_copy(ce->name)); + ZVAL_STR_COPY(&name, ce->name); reflection_instantiate(reflection_class_ptr, object TSRMLS_CC); intern = Z_REFLECTION_P(object); intern->ptr = ce; @@ -1251,7 +1251,7 @@ static void reflection_function_factory(zend_function *function, zval *closure_o reflection_object *intern; zval name; - ZVAL_STR(&name, zend_string_copy(function->common.function_name)); + ZVAL_STR_COPY(&name, function->common.function_name); reflection_instantiate(reflection_function_ptr, object TSRMLS_CC); intern = Z_REFLECTION_P(object); @@ -1273,9 +1273,9 @@ static void reflection_method_factory(zend_class_entry *ce, zend_function *metho zval name; zval classname; - ZVAL_STR(&name, zend_string_copy((method->common.scope && method->common.scope->trait_aliases)? - zend_resolve_method_name(ce, method) : method->common.function_name)); - ZVAL_STR(&classname, zend_string_copy(method->common.scope->name)); + ZVAL_STR_COPY(&name, (method->common.scope && method->common.scope->trait_aliases)? + zend_resolve_method_name(ce, method) : method->common.function_name); + ZVAL_STR_COPY(&classname, method->common.scope->name); reflection_instantiate(reflection_method_ptr, object TSRMLS_CC); intern = Z_REFLECTION_P(object); intern->ptr = method; @@ -1320,7 +1320,7 @@ static void reflection_property_factory(zend_class_entry *ce, zend_property_info } ZVAL_STRINGL(&name, prop_name, prop_name_len); - ZVAL_STR(&classname, zend_string_copy(prop->ce->name)); + ZVAL_STR_COPY(&classname, prop->ce->name); reflection_instantiate(reflection_property_ptr, object TSRMLS_CC); intern = Z_REFLECTION_P(object); @@ -1623,7 +1623,7 @@ ZEND_METHOD(reflection_function, __construct) return; } - ZVAL_STR(&name, zend_string_copy(fptr->common.function_name)); + ZVAL_STR_COPY(&name, fptr->common.function_name); reflection_update_property(object, "name", &name); intern->ptr = fptr; intern->ref_type = REF_TYPE_FUNCTION; @@ -2740,9 +2740,9 @@ ZEND_METHOD(reflection_method, __construct) } efree(lcname); - ZVAL_STR(&name, zend_string_copy(mptr->common.scope->name)); + ZVAL_STR_COPY(&name, mptr->common.scope->name); reflection_update_property(object, "class", &name); - ZVAL_STR(&name, zend_string_copy(mptr->common.function_name)); + ZVAL_STR_COPY(&name, mptr->common.function_name); reflection_update_property(object, "name", &name); intern->ptr = mptr; intern->ref_type = REF_TYPE_FUNCTION; @@ -3305,7 +3305,7 @@ static void reflection_class_object_ctor(INTERNAL_FUNCTION_PARAMETERS, int is_ob } if (Z_TYPE_P(argument) == IS_OBJECT) { - ZVAL_STR(&classname, zend_string_copy(Z_OBJCE_P(argument)->name)); + ZVAL_STR_COPY(&classname, Z_OBJCE_P(argument)->name); reflection_update_property(object, "name", &classname); intern->ptr = Z_OBJCE_P(argument); if (is_object) { @@ -3321,7 +3321,7 @@ static void reflection_class_object_ctor(INTERNAL_FUNCTION_PARAMETERS, int is_ob return; } - ZVAL_STR(&classname, zend_string_copy(ce->name)); + ZVAL_STR_COPY(&classname, ce->name); reflection_update_property(object, "name", &classname); intern->ptr = ce; @@ -3795,7 +3795,7 @@ ZEND_METHOD(reflection_class, hasProperty) RETURN_TRUE; } else { if (Z_TYPE(intern->obj) != IS_UNDEF && Z_OBJ_HANDLER(intern->obj, has_property)) { - ZVAL_STR(&property, zend_string_copy(name)); + ZVAL_STR_COPY(&property, name); if (Z_OBJ_HANDLER(intern->obj, has_property)(&intern->obj, &property, 2, NULL TSRMLS_CC)) { zval_ptr_dtor(&property); RETURN_TRUE; @@ -4799,10 +4799,10 @@ ZEND_METHOD(reflection_property, __construct) const char *class_name, *prop_name; size_t prop_name_len; zend_unmangle_property_name_ex(property_info->name, &class_name, &prop_name, &prop_name_len); - ZVAL_STR(&cname, zend_string_copy(property_info->ce->name)); + ZVAL_STR_COPY(&cname, property_info->ce->name); ZVAL_STRINGL(&propname, prop_name, prop_name_len); } else { - ZVAL_STR(&cname, zend_string_copy(ce->name)); + ZVAL_STR_COPY(&cname, ce->name); ZVAL_STRINGL(&propname, name_str, name_len); } reflection_update_property(object, "class", &cname); @@ -5284,7 +5284,7 @@ static int _addinientry(zval *el TSRMLS_DC, int num_args, va_list args, zend_has if (ini_entry->value) { zval zv; - ZVAL_STR(&zv, zend_string_copy(ini_entry->value)); + ZVAL_STR_COPY(&zv, ini_entry->value); zend_symtable_update(Z_ARRVAL_P(retval), ini_entry->name, &zv); } else { zend_symtable_update(Z_ARRVAL_P(retval), ini_entry->name, &EG(uninitialized_zval)); -- cgit v1.2.1 From d0cb715373c3fbe9dc095378ec5ed8c71f799f67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Schl=C3=BCter?= Date: Fri, 19 Sep 2014 18:33:14 +0200 Subject: s/PHP 5/PHP 7/ --- ext/reflection/php_reflection.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ext/reflection/php_reflection.c') diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 7e4f4ab7fb..c99f066834 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2014 The PHP Group | +----------------------------------------------------------------------+ -- cgit v1.2.1 From efa7f87de4d16bd8a8e1292b5c7431912d41f7a6 Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Fri, 26 Sep 2014 08:56:42 +0200 Subject: Fixed bug #68103 Dupplicate entry in Reflection $ php -r '$r=new ReflectionExtension("pthreads"); print_r($r->getClassNames());' Array ( [0] => Threaded [1] => stackable [2] => Thread [3] => Worker [4] => Mutex [5] => Cond [6] => Collectable [7] => Pool ) In getClasses() output, it is possible to compare key (ex "stackable") with $obj->name (ex "Threaded") to detect class alias. ... [Threaded] => ReflectionClass Object ( [name] => Threaded ) [stackable] => ReflectionClass Object ( [name] => Threaded ) ... --- ext/reflection/php_reflection.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'ext/reflection/php_reflection.c') diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 31d836a7ac..4294ceac81 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -1007,9 +1007,12 @@ static int _extension_class_string(zend_class_entry **pce TSRMLS_DC, int num_arg int *num_classes = va_arg(args, int*); if (((*pce)->type == ZEND_INTERNAL_CLASS) && (*pce)->info.internal.module && !strcasecmp((*pce)->info.internal.module->name, module->name)) { - string_printf(str, "\n"); - _class_string(str, *pce, NULL, indent TSRMLS_CC); - (*num_classes)++; + /* dump class if it is not an alias */ + if (!zend_binary_strcasecmp((*pce)->name, (*pce)->name_length, hash_key->arKey, hash_key->nKeyLength-1)) { + string_printf(str, "\n"); + _class_string(str, *pce, NULL, indent TSRMLS_CC); + (*num_classes)++; + } } return ZEND_HASH_APPLY_KEEP; } @@ -5360,12 +5363,24 @@ static int add_extension_class(zend_class_entry **pce TSRMLS_DC, int num_args, v int add_reflection_class = va_arg(args, int); if (((*pce)->type == ZEND_INTERNAL_CLASS) && (*pce)->info.internal.module && !strcasecmp((*pce)->info.internal.module->name, module->name)) { + const char *name; + int nlen; + + if (zend_binary_strcasecmp((*pce)->name, (*pce)->name_length, hash_key->arKey, hash_key->nKeyLength-1)) { + /* This is an class alias, use alias name */ + name = hash_key->arKey; + nlen = hash_key->nKeyLength-1; + } else { + /* Use class name */ + name = (*pce)->name; + nlen = (*pce)->name_length; + } if (add_reflection_class) { ALLOC_ZVAL(zclass); zend_reflection_class_factory(*pce, zclass TSRMLS_CC); - add_assoc_zval_ex(class_array, (*pce)->name, (*pce)->name_length + 1, zclass); + add_assoc_zval_ex(class_array, name, nlen+1, zclass); } else { - add_next_index_stringl(class_array, (*pce)->name, (*pce)->name_length, 1); + add_next_index_stringl(class_array, name, nlen, 1); } } return ZEND_HASH_APPLY_KEEP; -- cgit v1.2.1 From bd9a234645772a4f3116b3c4f1d5a83efb158d80 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Fri, 3 Oct 2014 19:32:46 +0400 Subject: Replaced EG(This) and EX(object) with EX(This). Internal functions now recieves zend_execute_data as the first argument. --- ext/reflection/php_reflection.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ext/reflection/php_reflection.c') diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 2c29229e8e..fc279e2d12 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -83,7 +83,7 @@ ZEND_DECLARE_MODULE_GLOBALS(reflection) /* Method macros */ #define METHOD_NOTSTATIC(ce) \ - if (!Z_OBJ(EG(This)) || !instanceof_function(Z_OBJCE(EG(This)), ce TSRMLS_CC)) { \ + if (!Z_OBJ(EX(This)) || !instanceof_function(Z_OBJCE(EX(This)), ce TSRMLS_CC)) { \ php_error_docref(NULL TSRMLS_CC, E_ERROR, "%s() cannot be called statically", get_active_function_name(TSRMLS_C)); \ return; \ } \ -- cgit v1.2.1 From 136dd53ac29fabce18127b8ecb95b606f141d42d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Schl=C3=BCter?= Date: Sat, 4 Oct 2014 19:59:21 +0200 Subject: Fix arginfo --- ext/reflection/php_reflection.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'ext/reflection/php_reflection.c') diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 4294ceac81..5040de5e19 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -5670,7 +5670,7 @@ static const zend_function_entry reflection_exception_functions[] = { PHP_FE_END }; -ZEND_BEGIN_ARG_INFO(arginfo_reflection__void, 0) +ZEND_BEGIN_ARG_INF(arginfo_reflection__void, 0) ZEND_END_ARG_INFO() @@ -6061,7 +6061,7 @@ ZEND_END_ARG_INFO() static const zend_function_entry reflection_zend_extension_functions[] = { ZEND_ME(reflection, __clone, arginfo_reflection__void, ZEND_ACC_PRIVATE|ZEND_ACC_FINAL) ZEND_ME(reflection_zend_extension, export, arginfo_reflection_extension_export, ZEND_ACC_STATIC|ZEND_ACC_PUBLIC) - ZEND_ME(reflection_zend_extension, __construct, arginfo_reflection_extension___construct, 0) + ZEND_ME(reflection_zend_extension, __construct, arginfo_reflection_zend_extension___construct, 0) ZEND_ME(reflection_zend_extension, __toString, arginfo_reflection__void, 0) ZEND_ME(reflection_zend_extension, getName, arginfo_reflection__void, 0) ZEND_ME(reflection_zend_extension, getVersion, arginfo_reflection__void, 0) -- cgit v1.2.1 From b386991471bc0f2af793a44c1509464cbcd73f6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Schl=C3=BCter?= Date: Sat, 4 Oct 2014 20:06:02 +0200 Subject: Fix accidental edit in previous commit --- ext/reflection/php_reflection.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ext/reflection/php_reflection.c') diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 5040de5e19..95b780d3f0 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -5670,7 +5670,7 @@ static const zend_function_entry reflection_exception_functions[] = { PHP_FE_END }; -ZEND_BEGIN_ARG_INF(arginfo_reflection__void, 0) +ZEND_BEGIN_ARG_INFO(arginfo_reflection__void, 0) ZEND_END_ARG_INFO() -- cgit v1.2.1 From ee5b30fa197046973e813a80dd0b7c67827c0ae1 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Thu, 9 Oct 2014 13:58:14 +0200 Subject: Remove support for classes without class entries get_class_entry must be non-NULL and return non-NULL. --- ext/reflection/php_reflection.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ext/reflection/php_reflection.c') diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index d6c37e37fb..7291d64213 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -4157,7 +4157,7 @@ ZEND_METHOD(reflection_class, isInstance) return; } GET_REFLECTION_OBJECT_PTR(ce); - RETURN_BOOL(HAS_CLASS_ENTRY(*object) && instanceof_function(Z_OBJCE_P(object), ce TSRMLS_CC)); + RETURN_BOOL(instanceof_function(Z_OBJCE_P(object), ce TSRMLS_CC)); } /* }}} */ -- cgit v1.2.1 From c4ab08ac9d7a407f4b2ab43790cd0eae738615c6 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Sun, 12 Oct 2014 19:01:45 +0200 Subject: Fix invalid zend_string_frees in reflection zend_lookup_class can share the name --- ext/reflection/php_reflection.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'ext/reflection/php_reflection.c') diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 7291d64213..57e11945c1 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -2402,7 +2402,7 @@ ZEND_METHOD(reflection_parameter, getClass) } else { zend_string *name = zend_string_init(param->arg_info->class_name, param->arg_info->class_name_len, 0); ce = zend_lookup_class(name TSRMLS_CC); - zend_string_free(name); + zend_string_release(name); if (!ce) { zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Class %s does not exist", param->arg_info->class_name); @@ -3862,10 +3862,10 @@ ZEND_METHOD(reflection_class, getProperty) if (!EG(exception)) { zend_throw_exception_ex(reflection_exception_ptr, -1 TSRMLS_CC, "Class %s does not exist", classname->val); } - zend_string_free(classname); + zend_string_release(classname); return; } - zend_string_free(classname); + zend_string_release(classname); if (!instanceof_function(ce, ce2 TSRMLS_CC)) { zend_throw_exception_ex(reflection_exception_ptr, -1 TSRMLS_CC, "Fully qualified property name %s::%s does not specify a base class of %s", ce2->name->val, str_name, ce->name->val); -- cgit v1.2.1 From 7471c217810397f05ae7a8c518af80da7baf0f4a Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Fri, 17 Oct 2014 19:10:05 +0400 Subject: Optimized property access handlers. Removed EG(std_property_info). --- ext/reflection/php_reflection.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'ext/reflection/php_reflection.c') diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 57e11945c1..cc4ed54dea 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -3922,9 +3922,14 @@ static int _adddynproperty(zval *ptr TSRMLS_DC, int num_args, va_list args, zend return 0; /* non public cannot be dynamic */ } - if (zend_get_property_info(ce, hash_key->key, 1 TSRMLS_CC) == &EG(std_property_info)) { - EG(std_property_info).flags = ZEND_ACC_IMPLICIT_PUBLIC; - reflection_property_factory(ce, &EG(std_property_info), &property TSRMLS_CC); + if (zend_get_property_info(ce, hash_key->key, 1 TSRMLS_CC) == NULL) { + zend_property_info property_info; + + property_info.flags = ZEND_ACC_IMPLICIT_PUBLIC; + property_info.name = hash_key->key; + property_info.ce = ce; + property_info.offset = -1; + reflection_property_factory(ce, &property_info, &property TSRMLS_CC); add_next_index_zval(retval, &property); } return 0; -- cgit v1.2.1