summaryrefslogtreecommitdiff
path: root/Zend/zend_interfaces.c
diff options
context:
space:
mode:
authorDmitry Stogov <dmitry@zend.com>2014-02-10 10:04:30 +0400
committerDmitry Stogov <dmitry@zend.com>2014-02-10 10:04:30 +0400
commitf4cfaf36e23ca47da3e352e1c60909104c059647 (patch)
tree0db3e2a323b12c5bbf1a958c857f92eb58c240d1 /Zend/zend_interfaces.c
parent89a9acea1f9d821a9805b3857bf4febbba08690d (diff)
downloadphp-git-f4cfaf36e23ca47da3e352e1c60909104c059647.tar.gz
Use better data structures (incomplete)
Diffstat (limited to 'Zend/zend_interfaces.c')
-rw-r--r--Zend/zend_interfaces.c131
1 files changed, 63 insertions, 68 deletions
diff --git a/Zend/zend_interfaces.c b/Zend/zend_interfaces.c
index f9a020c656..c8898e1694 100644
--- a/Zend/zend_interfaces.c
+++ b/Zend/zend_interfaces.c
@@ -31,24 +31,23 @@ ZEND_API zend_class_entry *zend_ce_serializable;
/* {{{ zend_call_method
Only returns the returned zval if retval_ptr != NULL */
-ZEND_API zval* zend_call_method(zval **object_pp, zend_class_entry *obj_ce, zend_function **fn_proxy, const char *function_name, int function_name_len, zval **retval_ptr_ptr, int param_count, zval* arg1, zval* arg2 TSRMLS_DC)
+ZEND_API zval* zend_call_method(zval *object, zend_class_entry *obj_ce, zend_function **fn_proxy, const char *function_name, int function_name_len, zval *retval_ptr, int param_count, zval* arg1, zval* arg2 TSRMLS_DC)
{
int result;
zend_fcall_info fci;
- zval z_fname;
- zval *retval;
+ zval retval;
HashTable *function_table;
- zval **params[2];
+ zval params[2];
- params[0] = &arg1;
- params[1] = &arg2;
+ ZVAL_COPY_VALUE(&params[0], arg1);
+ ZVAL_COPY_VALUE(&params[1], arg2);
fci.size = sizeof(fci);
/*fci.function_table = NULL; will be read form zend_class_entry of object if needed */
- fci.object_ptr = object_pp ? *object_pp : NULL;
- fci.function_name = &z_fname;
- fci.retval_ptr_ptr = retval_ptr_ptr ? retval_ptr_ptr : &retval;
+ fci.object_ptr = object;
+ ZVAL_STRINGL(&fci.function_name, function_name, function_name_len);
+ fci.retval = retval_ptr ? retval_ptr : &retval;
fci.param_count = param_count;
fci.params = params;
fci.no_separation = 1;
@@ -57,15 +56,14 @@ ZEND_API zval* zend_call_method(zval **object_pp, zend_class_entry *obj_ce, zend
if (!fn_proxy && !obj_ce) {
/* no interest in caching and no information already present that is
* needed later inside zend_call_function. */
- ZVAL_STRINGL(&z_fname, function_name, function_name_len, 0);
- fci.function_table = !object_pp ? EG(function_table) : NULL;
+ fci.function_table = !object ? EG(function_table) : NULL;
result = zend_call_function(&fci, NULL TSRMLS_CC);
} else {
zend_fcall_info_cache fcic;
fcic.initialized = 1;
if (!obj_ce) {
- obj_ce = object_pp ? Z_OBJCE_PP(object_pp) : NULL;
+ obj_ce = object ? Z_OBJCE_P(object) : NULL;
}
if (obj_ce) {
function_table = &obj_ce->function_table;
@@ -73,9 +71,9 @@ ZEND_API zval* zend_call_method(zval **object_pp, zend_class_entry *obj_ce, zend
function_table = EG(function_table);
}
if (!fn_proxy || !*fn_proxy) {
- if (zend_hash_find(function_table, function_name, function_name_len+1, (void **) &fcic.function_handler) == FAILURE) {
+ if ((fcic.function_handler = zend_hash_find_ptr(function_table, Z_STR(fci.function_name))) == NULL) {
/* error at c-level */
- zend_error(E_CORE_ERROR, "Couldn't find implementation for method %s%s%s", obj_ce ? obj_ce->name : "", obj_ce ? "::" : "", function_name);
+ zend_error(E_CORE_ERROR, "Couldn't find implementation for method %s%s%s", obj_ce ? obj_ce->name->val : "", obj_ce ? "::" : "", function_name);
}
if (fn_proxy) {
*fn_proxy = fcic.function_handler;
@@ -84,8 +82,8 @@ ZEND_API zval* zend_call_method(zval **object_pp, zend_class_entry *obj_ce, zend
fcic.function_handler = *fn_proxy;
}
fcic.calling_scope = obj_ce;
- if (object_pp) {
- fcic.called_scope = Z_OBJCE_PP(object_pp);
+ if (object) {
+ fcic.called_scope = Z_OBJCE_P(object);
} else if (obj_ce &&
!(EG(called_scope) &&
instanceof_function(EG(called_scope), obj_ce TSRMLS_CC))) {
@@ -93,25 +91,23 @@ ZEND_API zval* zend_call_method(zval **object_pp, zend_class_entry *obj_ce, zend
} else {
fcic.called_scope = EG(called_scope);
}
- fcic.object_ptr = object_pp ? *object_pp : NULL;
+ fcic.object_ptr = object;
result = zend_call_function(&fci, &fcic TSRMLS_CC);
}
if (result == FAILURE) {
/* error at c-level */
if (!obj_ce) {
- obj_ce = object_pp ? Z_OBJCE_PP(object_pp) : NULL;
+ obj_ce = object ? Z_OBJCE_P(object) : NULL;
}
if (!EG(exception)) {
- zend_error(E_CORE_ERROR, "Couldn't execute method %s%s%s", obj_ce ? obj_ce->name : "", obj_ce ? "::" : "", function_name);
+ zend_error(E_CORE_ERROR, "Couldn't execute method %s%s%s", obj_ce ? obj_ce->name->val : "", obj_ce ? "::" : "", function_name);
}
}
- if (!retval_ptr_ptr) {
- if (retval) {
- zval_ptr_dtor(&retval);
- }
+ if (!retval_ptr) {
+ zval_ptr_dtor(&retval);
return NULL;
}
- return *retval_ptr_ptr;
+ return retval_ptr;
}
/* }}} */
@@ -120,9 +116,9 @@ ZEND_API zval* zend_call_method(zval **object_pp, zend_class_entry *obj_ce, zend
/* {{{ zend_user_it_new_iterator */
ZEND_API zval *zend_user_it_new_iterator(zend_class_entry *ce, zval *object TSRMLS_DC)
{
- zval *retval;
+ zval retval;
- return zend_call_method_with_0_params(&object, ce, &ce->iterator_funcs.zf_new_iterator, "getiterator", &retval);
+ return zend_call_method_with_0_params(object, ce, &ce->iterator_funcs.zf_new_iterator, "getiterator", &retval);
}
/* }}} */
@@ -133,7 +129,7 @@ ZEND_API void zend_user_it_invalidate_current(zend_object_iterator *_iter TSRMLS
zend_user_iterator *iter = (zend_user_iterator*)_iter;
if (iter->value) {
- zval_ptr_dtor(&iter->value);
+ zval_ptr_dtor(iter->value);
iter->value = NULL;
}
}
@@ -146,7 +142,7 @@ static void zend_user_it_dtor(zend_object_iterator *_iter TSRMLS_DC)
zval *object = (zval*)iter->it.data;
zend_user_it_invalidate_current(_iter TSRMLS_CC);
- zval_ptr_dtor(&object);
+ zval_ptr_dtor(object);
efree(iter);
}
/* }}} */
@@ -157,12 +153,12 @@ ZEND_API int zend_user_it_valid(zend_object_iterator *_iter TSRMLS_DC)
if (_iter) {
zend_user_iterator *iter = (zend_user_iterator*)_iter;
zval *object = (zval*)iter->it.data;
- zval *more;
+ zval more;
int result;
- zend_call_method_with_0_params(&object, iter->ce, &iter->ce->iterator_funcs.zf_valid, "valid", &more);
- if (more) {
- result = i_zend_is_true(more TSRMLS_CC);
+ zend_call_method_with_0_params(object, iter->ce, &iter->ce->iterator_funcs.zf_valid, "valid", &more);
+ if (Z_TYPE(more) != IS_UNDEF) {
+ result = i_zend_is_true(&more TSRMLS_CC);
zval_ptr_dtor(&more);
return result ? SUCCESS : FAILURE;
}
@@ -172,15 +168,15 @@ ZEND_API int zend_user_it_valid(zend_object_iterator *_iter TSRMLS_DC)
/* }}} */
/* {{{ zend_user_it_get_current_data */
-ZEND_API void zend_user_it_get_current_data(zend_object_iterator *_iter, zval ***data TSRMLS_DC)
+ZEND_API zval *zend_user_it_get_current_data(zend_object_iterator *_iter TSRMLS_DC)
{
zend_user_iterator *iter = (zend_user_iterator*)_iter;
zval *object = (zval*)iter->it.data;
if (!iter->value) {
- zend_call_method_with_0_params(&object, iter->ce, &iter->ce->iterator_funcs.zf_current, "current", &iter->value);
+ zend_call_method_with_0_params(object, iter->ce, &iter->ce->iterator_funcs.zf_current, "current", iter->value);
}
- *data = &iter->value;
+ return iter->value;
}
/* }}} */
@@ -199,15 +195,15 @@ ZEND_API void zend_user_it_get_current_key(zend_object_iterator *_iter, zval *ke
{
zend_user_iterator *iter = (zend_user_iterator*)_iter;
zval *object = (zval*)iter->it.data;
- zval *retval;
+ zval retval;
- zend_call_method_with_0_params(&object, iter->ce, &iter->ce->iterator_funcs.zf_key, "key", &retval);
+ zend_call_method_with_0_params(object, iter->ce, &iter->ce->iterator_funcs.zf_key, "key", &retval);
- if (retval) {
- ZVAL_ZVAL(key, retval, 1, 1);
+ if (Z_TYPE(retval) != IS_UNDEF) {
+ ZVAL_ZVAL(key, &retval, 1, 1);
} else {
if (!EG(exception)) {
- zend_error(E_WARNING, "Nothing returned from %s::key()", iter->ce->name);
+ zend_error(E_WARNING, "Nothing returned from %s::key()", iter->ce->name->val);
}
ZVAL_LONG(key, 0);
@@ -221,7 +217,7 @@ ZEND_API void zend_user_it_move_forward(zend_object_iterator *_iter TSRMLS_DC)
zval *object = (zval*)iter->it.data;
zend_user_it_invalidate_current(_iter TSRMLS_CC);
- zend_call_method_with_0_params(&object, iter->ce, &iter->ce->iterator_funcs.zf_next, "next", NULL);
+ zend_call_method_with_0_params(object, iter->ce, &iter->ce->iterator_funcs.zf_next, "next", NULL);
}
/* }}} */
@@ -232,7 +228,7 @@ ZEND_API void zend_user_it_rewind(zend_object_iterator *_iter TSRMLS_DC)
zval *object = (zval*)iter->it.data;
zend_user_it_invalidate_current(_iter TSRMLS_CC);
- zend_call_method_with_0_params(&object, iter->ce, &iter->ce->iterator_funcs.zf_rewind, "rewind", NULL);
+ zend_call_method_with_0_params(object, iter->ce, &iter->ce->iterator_funcs.zf_rewind, "rewind", NULL);
}
/* }}} */
@@ -279,13 +275,13 @@ ZEND_API zend_object_iterator *zend_user_it_get_new_iterator(zend_class_entry *c
zend_throw_exception_ex(NULL, 0 TSRMLS_CC, "Objects returned by %s::getIterator() must be traversable or implement interface Iterator", ce ? ce->name : Z_OBJCE_P(object)->name);
}
if (iterator) {
- zval_ptr_dtor(&iterator);
+ zval_ptr_dtor(iterator);
}
return NULL;
}
new_iterator = ce_it->get_iterator(ce_it, iterator, by_ref TSRMLS_CC);
- zval_ptr_dtor(&iterator);
+ zval_ptr_dtor(iterator);
return new_iterator;
}
/* }}} */
@@ -305,10 +301,10 @@ static int zend_implement_traversable(zend_class_entry *interface, zend_class_en
}
}
zend_error(E_CORE_ERROR, "Class %s must implement interface %s as part of either %s or %s",
- class_type->name,
- zend_ce_traversable->name,
- zend_ce_iterator->name,
- zend_ce_aggregate->name);
+ class_type->name->val,
+ zend_ce_traversable->name->val,
+ zend_ce_iterator->name->val,
+ zend_ce_aggregate->name->val);
return FAILURE;
}
/* }}} */
@@ -328,9 +324,9 @@ static int zend_implement_aggregate(zend_class_entry *interface, zend_class_entr
for (i = 0; i < class_type->num_interfaces; i++) {
if (class_type->interfaces[i] == zend_ce_iterator) {
zend_error(E_ERROR, "Class %s cannot implement both %s and %s at the same time",
- class_type->name,
- interface->name,
- zend_ce_iterator->name);
+ class_type->name->val,
+ interface->name->val,
+ zend_ce_iterator->name->val);
return FAILURE;
}
if (class_type->interfaces[i] == zend_ce_traversable) {
@@ -360,9 +356,9 @@ static int zend_implement_iterator(zend_class_entry *interface, zend_class_entry
/* c-level get_iterator cannot be changed */
if (class_type->get_iterator == zend_user_it_get_new_iterator) {
zend_error(E_ERROR, "Class %s cannot implement both %s and %s at the same time",
- class_type->name,
- interface->name,
- zend_ce_aggregate->name);
+ class_type->name->val,
+ interface->name->val,
+ zend_ce_aggregate->name->val);
}
return FAILURE;
}
@@ -400,23 +396,23 @@ static int zend_implement_arrayaccess(zend_class_entry *interface, zend_class_en
ZEND_API int zend_user_serialize(zval *object, unsigned char **buffer, zend_uint *buf_len, zend_serialize_data *data TSRMLS_DC)
{
zend_class_entry * ce = Z_OBJCE_P(object);
- zval *retval;
+ zval retval;
int result;
- zend_call_method_with_0_params(&object, ce, &ce->serialize_func, "serialize", &retval);
+ zend_call_method_with_0_params(object, ce, &ce->serialize_func, "serialize", &retval);
- if (!retval || EG(exception)) {
+ if (Z_TYPE(retval) == IS_UNDEF || EG(exception)) {
result = FAILURE;
} else {
- switch(Z_TYPE_P(retval)) {
+ switch(Z_TYPE(retval)) {
case IS_NULL:
/* we could also make this '*buf_len = 0' but this allows to skip variables */
zval_ptr_dtor(&retval);
return FAILURE;
case IS_STRING:
- *buffer = (unsigned char*)estrndup(Z_STRVAL_P(retval), Z_STRLEN_P(retval));
- *buf_len = Z_STRLEN_P(retval);
+ *buffer = (unsigned char*)estrndup(Z_STRVAL(retval), Z_STRLEN(retval));
+ *buf_len = Z_STRLEN(retval);
result = SUCCESS;
break;
default: /* failure */
@@ -434,16 +430,15 @@ ZEND_API int zend_user_serialize(zval *object, unsigned char **buffer, zend_uint
/* }}} */
/* {{{ zend_user_unserialize */
-ZEND_API int zend_user_unserialize(zval **object, zend_class_entry *ce, const unsigned char *buf, zend_uint buf_len, zend_unserialize_data *data TSRMLS_DC)
+ZEND_API int zend_user_unserialize(zval *object, zend_class_entry *ce, const unsigned char *buf, zend_uint buf_len, zend_unserialize_data *data TSRMLS_DC)
{
- zval * zdata;
+ zval zdata;
- object_init_ex(*object, ce);
+ object_init_ex(object, ce);
- MAKE_STD_ZVAL(zdata);
- ZVAL_STRINGL(zdata, (char*)buf, buf_len, 1);
+ ZVAL_STRINGL(&zdata, (char*)buf, buf_len);
- zend_call_method_with_1_params(object, ce, &ce->unserialize_func, "unserialize", NULL, zdata);
+ zend_call_method_with_1_params(object, ce, &ce->unserialize_func, "unserialize", NULL, &zdata);
zval_ptr_dtor(&zdata);
@@ -463,9 +458,9 @@ ZEND_API int zend_class_serialize_deny(zval *object, unsigned char **buffer, zen
}
/* }}} */
-ZEND_API int zend_class_unserialize_deny(zval **object, zend_class_entry *ce, const unsigned char *buf, zend_uint buf_len, zend_unserialize_data *data TSRMLS_DC) /* {{{ */
+ZEND_API int zend_class_unserialize_deny(zval *object, zend_class_entry *ce, const unsigned char *buf, zend_uint buf_len, zend_unserialize_data *data TSRMLS_DC) /* {{{ */
{
- zend_throw_exception_ex(NULL, 0 TSRMLS_CC, "Unserialization of '%s' is not allowed", ce->name);
+ zend_throw_exception_ex(NULL, 0 TSRMLS_CC, "Unserialization of '%s' is not allowed", ce->name->val);
return FAILURE;
}
/* }}} */