summaryrefslogtreecommitdiff
path: root/ext/spl/php_spl.c
diff options
context:
space:
mode:
authorDmitry Stogov <dmitry@zend.com>2014-03-28 02:11:22 +0400
committerDmitry Stogov <dmitry@zend.com>2014-03-28 02:11:22 +0400
commitea85451b65b904d0670c4011c819a15431720432 (patch)
tree83bde21b41665b493d7337ff34d622f67cd5c78c /ext/spl/php_spl.c
parent68385716a4bb233ba17acb587b0a7aa5d2e3d448 (diff)
downloadphp-git-ea85451b65b904d0670c4011c819a15431720432.tar.gz
Refactored data structures to keep zend_object* instead of a whole zval in some places
Diffstat (limited to 'ext/spl/php_spl.c')
-rw-r--r--ext/spl/php_spl.c27
1 files changed, 14 insertions, 13 deletions
diff --git a/ext/spl/php_spl.c b/ext/spl/php_spl.c
index 935e64be60..55d72e6753 100644
--- a/ext/spl/php_spl.c
+++ b/ext/spl/php_spl.c
@@ -485,7 +485,7 @@ PHP_FUNCTION(spl_autoload_register)
zend_bool prepend = 0;
zend_function *spl_func_ptr;
autoload_func_info alfi;
- zval *obj_ptr;
+ zend_object *obj_ptr;
zend_fcall_info_cache fcc;
if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "|zbb", &zcallable, &do_throw, &prepend) == FAILURE) {
@@ -496,9 +496,9 @@ PHP_FUNCTION(spl_autoload_register)
if (!zend_is_callable_ex(zcallable, NULL, IS_CALLABLE_STRICT, &func_name, &fcc, &error TSRMLS_CC)) {
alfi.ce = fcc.calling_scope;
alfi.func_ptr = fcc.function_handler;
- obj_ptr = &fcc.object;
+ obj_ptr = fcc.object;
if (Z_TYPE_P(zcallable) == IS_ARRAY) {
- if (Z_TYPE_P(obj_ptr) == IS_UNDEF && alfi.func_ptr && !(alfi.func_ptr->common.fn_flags & ZEND_ACC_STATIC)) {
+ if (!obj_ptr && alfi.func_ptr && !(alfi.func_ptr->common.fn_flags & ZEND_ACC_STATIC)) {
if (do_throw) {
zend_throw_exception_ex(spl_ce_LogicException, 0 TSRMLS_CC, "Passed array specifies a non static method but no object (%s)", error);
}
@@ -508,7 +508,7 @@ PHP_FUNCTION(spl_autoload_register)
STR_RELEASE(func_name);
RETURN_FALSE;
} else if (do_throw) {
- zend_throw_exception_ex(spl_ce_LogicException, 0 TSRMLS_CC, "Passed array does not specify %s %smethod (%s)", alfi.func_ptr ? "a callable" : "an existing", Z_TYPE_P(obj_ptr) == IS_UNDEF ? "static " : "", error);
+ zend_throw_exception_ex(spl_ce_LogicException, 0 TSRMLS_CC, "Passed array does not specify %s %smethod (%s)", alfi.func_ptr ? "a callable" : "an existing", !obj_ptr ? "static " : "", error);
}
if (error) {
efree(error);
@@ -547,7 +547,7 @@ PHP_FUNCTION(spl_autoload_register)
}
alfi.ce = fcc.calling_scope;
alfi.func_ptr = fcc.function_handler;
- obj_ptr = &fcc.object;
+ obj_ptr = fcc.object;
if (error) {
efree(error);
}
@@ -573,12 +573,13 @@ PHP_FUNCTION(spl_autoload_register)
goto skip;
}
- if (Z_TYPE_P(obj_ptr) == IS_OBJECT && !(alfi.func_ptr->common.fn_flags & ZEND_ACC_STATIC)) {
+ if (obj_ptr && !(alfi.func_ptr->common.fn_flags & ZEND_ACC_STATIC)) {
/* add object id to the hash to ensure uniqueness, for more reference look at bug #40091 */
lc_name = STR_REALLOC(lc_name, lc_name->len + sizeof(zend_uint), 0);
- memcpy(lc_name->val + lc_name->len - sizeof(zend_uint), &Z_OBJ_HANDLE_P(obj_ptr), sizeof(zend_uint));
+ memcpy(lc_name->val + lc_name->len - sizeof(zend_uint), &obj_ptr->handle, sizeof(zend_uint));
lc_name->val[lc_name->len] = '\0';
- ZVAL_COPY(&alfi.obj, obj_ptr);
+ ZVAL_OBJ(&alfi.obj, obj_ptr);
+ Z_ADDREF(alfi.obj);
} else {
ZVAL_UNDEF(&alfi.obj);
}
@@ -606,7 +607,7 @@ PHP_FUNCTION(spl_autoload_register)
}
if (zend_hash_add_mem(SPL_G(autoload_functions), lc_name, &alfi, sizeof(autoload_func_info)) == NULL) {
- if (Z_TYPE_P(obj_ptr) == IS_OBJECT && !(alfi.func_ptr->common.fn_flags & ZEND_ACC_STATIC)) {
+ if (obj_ptr && !(alfi.func_ptr->common.fn_flags & ZEND_ACC_STATIC)) {
Z_DELREF(alfi.obj);
}
if (!ZVAL_IS_UNDEF(&alfi.closure)) {
@@ -640,7 +641,7 @@ PHP_FUNCTION(spl_autoload_unregister)
zval *zcallable;
int success = FAILURE;
zend_function *spl_func_ptr;
- zval *obj_ptr;
+ zend_object *obj_ptr;
zend_fcall_info_cache fcc;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &zcallable) == FAILURE) {
@@ -657,7 +658,7 @@ PHP_FUNCTION(spl_autoload_unregister)
}
RETURN_FALSE;
}
- obj_ptr = &fcc.object;
+ obj_ptr = fcc.object;
if (error) {
efree(error);
}
@@ -684,9 +685,9 @@ PHP_FUNCTION(spl_autoload_unregister)
} else {
/* remove specific */
success = zend_hash_del(SPL_G(autoload_functions), lc_name);
- if (success != SUCCESS && Z_TYPE_P(obj_ptr) == IS_OBJECT) {
+ if (success != SUCCESS && obj_ptr) {
lc_name = STR_REALLOC(lc_name, lc_name->len + sizeof(zend_uint), 0);
- memcpy(lc_name->val + lc_name->len - sizeof(zend_uint), &Z_OBJ_HANDLE_P(obj_ptr), sizeof(zend_uint));
+ memcpy(lc_name->val + lc_name->len - sizeof(zend_uint), &obj_ptr->handle, sizeof(zend_uint));
lc_name->val[lc_name->len] = '\0';
success = zend_hash_del(SPL_G(autoload_functions), lc_name);
}