summaryrefslogtreecommitdiff
path: root/Zend/zend_builtin_functions.c
diff options
context:
space:
mode:
Diffstat (limited to 'Zend/zend_builtin_functions.c')
-rw-r--r--Zend/zend_builtin_functions.c129
1 files changed, 44 insertions, 85 deletions
diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c
index f320585e70..728d90acdf 100644
--- a/Zend/zend_builtin_functions.c
+++ b/Zend/zend_builtin_functions.c
@@ -400,7 +400,7 @@ ZEND_FUNCTION(gc_disable)
Get the number of arguments that were passed to the function */
ZEND_FUNCTION(func_num_args)
{
- zend_execute_data *ex = EG(current_execute_data)->prev_execute_data;
+ zend_execute_data *ex = EX(prev_execute_data);
if (ex->frame_kind == VM_FRAME_NESTED_FUNCTION || ex->frame_kind == VM_FRAME_TOP_FUNCTION) {
RETURN_LONG(ex->num_args);
@@ -415,7 +415,7 @@ ZEND_FUNCTION(func_num_args)
Get the $arg_num'th argument that was passed to the function */
ZEND_FUNCTION(func_get_arg)
{
- int arg_count, first_extra_arg;
+ uint32_t arg_count, first_extra_arg;
zval *arg;
zend_long requested_offset;
zend_execute_data *ex;
@@ -429,7 +429,7 @@ ZEND_FUNCTION(func_get_arg)
RETURN_FALSE;
}
- ex = EG(current_execute_data)->prev_execute_data;
+ ex = EX(prev_execute_data);
if (ex->frame_kind != VM_FRAME_NESTED_FUNCTION && ex->frame_kind != VM_FRAME_TOP_FUNCTION) {
zend_error(E_WARNING, "func_get_arg(): Called from the global scope - no function context");
RETURN_FALSE;
@@ -460,9 +460,9 @@ ZEND_FUNCTION(func_get_arg)
ZEND_FUNCTION(func_get_args)
{
zval *p;
- int arg_count, first_extra_arg;
- int i;
- zend_execute_data *ex = EG(current_execute_data)->prev_execute_data;
+ uint32_t arg_count, first_extra_arg;
+ uint32_t i;
+ zend_execute_data *ex = EX(prev_execute_data);
if (ex->frame_kind != VM_FRAME_NESTED_FUNCTION && ex->frame_kind != VM_FRAME_TOP_FUNCTION) {
zend_error(E_WARNING, "func_get_args(): Called from the global scope - no function context");
@@ -539,7 +539,6 @@ ZEND_FUNCTION(strlen)
}
/* }}} */
-
/* {{{ proto int strcmp(string str1, string str2)
Binary safe string comparison */
ZEND_FUNCTION(strcmp)
@@ -554,7 +553,6 @@ ZEND_FUNCTION(strcmp)
}
/* }}} */
-
/* {{{ proto int strncmp(string str1, string str2, int len)
Binary safe string comparison */
ZEND_FUNCTION(strncmp)
@@ -575,7 +573,6 @@ ZEND_FUNCTION(strncmp)
}
/* }}} */
-
/* {{{ proto int strcasecmp(string str1, string str2)
Binary safe case-insensitive string comparison */
ZEND_FUNCTION(strcasecmp)
@@ -590,7 +587,6 @@ ZEND_FUNCTION(strcasecmp)
}
/* }}} */
-
/* {{{ proto int strncasecmp(string str1, string str2, int len)
Binary safe string comparison */
ZEND_FUNCTION(strncasecmp)
@@ -611,7 +607,6 @@ ZEND_FUNCTION(strncasecmp)
}
/* }}} */
-
/* {{{ proto array each(array arr)
Return the currently pointed key..value pair in the passed array, and advance the pointer to the next element */
ZEND_FUNCTION(each)
@@ -660,7 +655,7 @@ ZEND_FUNCTION(each)
/* add the key elements */
if (zend_hash_get_current_key(target_hash, &key, &num_key, 0) == HASH_KEY_IS_STRING) {
- ZVAL_STR(&tmp, zend_string_copy(key));
+ ZVAL_STR_COPY(&tmp, key);
if (Z_REFCOUNTED(tmp)) Z_ADDREF(tmp);
} else {
ZVAL_LONG(&tmp, num_key);
@@ -671,7 +666,6 @@ ZEND_FUNCTION(each)
}
/* }}} */
-
/* {{{ proto int error_reporting([int new_error_level])
Return the current error_reporting level, and if an argument was passed - change to the new level */
ZEND_FUNCTION(error_reporting)
@@ -694,7 +688,6 @@ ZEND_FUNCTION(error_reporting)
}
/* }}} */
-
/* {{{ proto bool define(string constant_name, mixed value, boolean case_insensitive=false)
Define a new constant */
ZEND_FUNCTION(define)
@@ -774,7 +767,6 @@ repeat:
}
/* }}} */
-
/* {{{ proto bool defined(string constant_name)
Check whether a constant exists
Warning: This function is special-cased by zend_compile.c and so is usually bypassed */
@@ -800,7 +792,6 @@ ZEND_FUNCTION(defined)
}
/* }}} */
-
/* {{{ proto string get_class([object object])
Retrieves the class name */
ZEND_FUNCTION(get_class)
@@ -824,7 +815,6 @@ ZEND_FUNCTION(get_class)
}
/* }}} */
-
/* {{{ proto string get_called_class()
Retrieves the "Late Static Binding" class name */
ZEND_FUNCTION(get_called_class)
@@ -833,8 +823,8 @@ ZEND_FUNCTION(get_called_class)
return;
}
- if (EG(current_execute_data)->called_scope) {
- RETURN_STR(zend_string_copy(EG(current_execute_data)->called_scope->name));
+ if (EX(called_scope)) {
+ RETURN_STR(zend_string_copy(EX(called_scope)->name));
} else if (!EG(scope)) {
zend_error(E_WARNING, "get_called_class() called from outside a class");
}
@@ -842,7 +832,6 @@ ZEND_FUNCTION(get_called_class)
}
/* }}} */
-
/* {{{ proto string get_parent_class([mixed object])
Retrieves the parent class name for object or class or current scope. */
ZEND_FUNCTION(get_parent_class)
@@ -883,8 +872,7 @@ ZEND_FUNCTION(get_parent_class)
}
/* }}} */
-
-static void is_a_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool only_subclass)
+static void is_a_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool only_subclass) /* {{{ */
{
zval *obj;
zend_string *class_name;
@@ -936,7 +924,7 @@ static void is_a_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool only_subclass)
RETURN_BOOL(retval);
}
-
+/* }}} */
/* {{{ proto bool is_subclass_of(mixed object_or_string, string class_name [, bool allow_string=true])
Returns true if the object has this class as one of its parents */
@@ -946,7 +934,6 @@ ZEND_FUNCTION(is_subclass_of)
}
/* }}} */
-
/* {{{ proto bool is_a(mixed object_or_string, string class_name [, bool allow_string=false])
Returns true if the first argument is an object and is this class or has this class as one of its parents, */
ZEND_FUNCTION(is_a)
@@ -955,7 +942,6 @@ ZEND_FUNCTION(is_a)
}
/* }}} */
-
/* {{{ add_class_vars */
static void add_class_vars(zend_class_entry *ce, int statics, zval *return_value TSRMLS_DC)
{
@@ -1003,7 +989,6 @@ static void add_class_vars(zend_class_entry *ce, int statics, zval *return_value
}
/* }}} */
-
/* {{{ proto array get_class_vars(string class_name)
Returns an array of default properties of the class. */
ZEND_FUNCTION(get_class_vars)
@@ -1027,7 +1012,6 @@ ZEND_FUNCTION(get_class_vars)
}
/* }}} */
-
/* {{{ proto array get_object_vars(object obj)
Returns an array of object properties */
ZEND_FUNCTION(get_object_vars)
@@ -1036,8 +1020,6 @@ ZEND_FUNCTION(get_object_vars)
zval *value;
HashTable *properties;
zend_string *key;
- const char *prop_name, *class_name;
- uint prop_len;
zend_object *zobj;
#ifndef FAST_ZPP
@@ -1070,7 +1052,9 @@ ZEND_FUNCTION(get_object_vars)
/* Not separating references */
if (Z_REFCOUNTED_P(value)) Z_ADDREF_P(value);
if (key->val[0] == 0) {
- zend_unmangle_property_name_ex(key->val, key->len, &class_name, &prop_name, (int*) &prop_len);
+ const char *prop_name, *class_name;
+ size_t prop_len;
+ zend_unmangle_property_name_ex(key, &class_name, &prop_name, &prop_len);
zend_hash_str_add_new(Z_ARRVAL_P(return_value), prop_name, prop_len, value);
} else {
zend_hash_add_new(Z_ARRVAL_P(return_value), key, value);
@@ -1081,13 +1065,14 @@ ZEND_FUNCTION(get_object_vars)
}
/* }}} */
-static int same_name(const char *key, const char *name, uint32_t name_len)
+static int same_name(const char *key, const char *name, uint32_t name_len) /* {{{ */
{
char *lcname = zend_str_tolower_dup(name, name_len);
int ret = memcmp(lcname, key, name_len) == 0;
efree(lcname);
return ret;
}
+/* }}} */
/* {{{ proto array get_class_methods(mixed class)
Returns an array of method names for class or class instance. */
@@ -1131,7 +1116,7 @@ ZEND_FUNCTION(get_class_methods)
/* Do not display old-style inherited constructors */
if (!key) {
- ZVAL_STR(&method_name, zend_string_copy(mptr->common.function_name));
+ ZVAL_STR_COPY(&method_name, mptr->common.function_name);
zend_hash_next_index_insert_new(Z_ARRVAL_P(return_value), &method_name);
} else if ((mptr->common.fn_flags & ZEND_ACC_CTOR) == 0 ||
mptr->common.scope == ce ||
@@ -1141,10 +1126,10 @@ ZEND_FUNCTION(get_class_methods)
*mptr->op_array.refcount > 1 &&
(len != key->len ||
!same_name(key->val, mptr->common.function_name->val, len))) {
- ZVAL_STR(&method_name, zend_string_copy(zend_find_alias_name(mptr->common.scope, key)));
+ ZVAL_STR_COPY(&method_name, zend_find_alias_name(mptr->common.scope, key));
zend_hash_next_index_insert_new(Z_ARRVAL_P(return_value), &method_name);
} else {
- ZVAL_STR(&method_name, zend_string_copy(mptr->common.function_name));
+ ZVAL_STR_COPY(&method_name, mptr->common.function_name);
zend_hash_next_index_insert_new(Z_ARRVAL_P(return_value), &method_name);
}
}
@@ -1153,7 +1138,6 @@ ZEND_FUNCTION(get_class_methods)
}
/* }}} */
-
/* {{{ proto bool method_exists(object object, string method)
Checks if the class method exists */
ZEND_FUNCTION(method_exists)
@@ -1262,7 +1246,6 @@ ZEND_FUNCTION(property_exists)
}
/* }}} */
-
/* {{{ proto bool class_exists(string classname [, bool autoload])
Checks if the class exists */
ZEND_FUNCTION(class_exists)
@@ -1393,7 +1376,6 @@ ZEND_FUNCTION(trait_exists)
}
/* }}} */
-
/* {{{ proto bool function_exists(string function_name)
Checks if the function exists */
ZEND_FUNCTION(function_exists)
@@ -1537,7 +1519,6 @@ ZEND_FUNCTION(get_included_files)
}
/* }}} */
-
/* {{{ proto void trigger_error(string message [, int error_type])
Generates a user-level error/warning/notice message */
ZEND_FUNCTION(trigger_error)
@@ -1567,7 +1548,6 @@ ZEND_FUNCTION(trigger_error)
}
/* }}} */
-
/* {{{ proto string set_error_handler(string error_handler [, int error_types])
Sets a user-defined error handler function. Returns the previously defined error handler, or false on error */
ZEND_FUNCTION(set_error_handler)
@@ -1607,7 +1587,6 @@ ZEND_FUNCTION(set_error_handler)
}
/* }}} */
-
/* {{{ proto void restore_error_handler(void)
Restores the previously defined error handler function */
ZEND_FUNCTION(restore_error_handler)
@@ -1634,7 +1613,6 @@ ZEND_FUNCTION(restore_error_handler)
}
/* }}} */
-
/* {{{ proto string set_exception_handler(callable exception_handler)
Sets a user-defined exception handler function. Returns the previously defined exception handler, or false on error */
ZEND_FUNCTION(set_exception_handler)
@@ -1671,7 +1649,6 @@ ZEND_FUNCTION(set_exception_handler)
}
/* }}} */
-
/* {{{ proto void restore_exception_handler(void)
Restores the previously defined exception handler function */
ZEND_FUNCTION(restore_exception_handler)
@@ -1690,7 +1667,7 @@ ZEND_FUNCTION(restore_exception_handler)
}
/* }}} */
-static int copy_class_or_interface_name(zval *el TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key)
+static int copy_class_or_interface_name(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);
zval *array = va_arg(args, zval *);
@@ -1710,6 +1687,7 @@ static int copy_class_or_interface_name(zval *el TSRMLS_DC, int num_args, va_lis
}
return ZEND_HASH_APPLY_KEEP;
}
+/* }}} */
/* {{{ proto array get_declared_traits()
Returns an array of all declared traits. */
@@ -1727,7 +1705,6 @@ ZEND_FUNCTION(get_declared_traits)
}
/* }}} */
-
/* {{{ proto array get_declared_classes()
Returns an array of all declared classes. */
ZEND_FUNCTION(get_declared_classes)
@@ -1760,8 +1737,7 @@ ZEND_FUNCTION(get_declared_interfaces)
}
/* }}} */
-
-static int copy_function_name(zval *zv TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key)
+static int copy_function_name(zval *zv TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key) /* {{{ */
{
zend_function *func = Z_PTR_P(zv);
zval *internal_ar = va_arg(args, zval *),
@@ -1779,13 +1755,13 @@ static int copy_function_name(zval *zv TSRMLS_DC, int num_args, va_list args, ze
return 0;
}
-
+/* }}} */
/* {{{ proto array get_defined_functions(void)
Returns an array of all defined functions */
ZEND_FUNCTION(get_defined_functions)
{
- zval internal, user, *ret;
+ zval internal, user;
if (zend_parse_parameters_none() == FAILURE) {
return;
@@ -1797,27 +1773,11 @@ ZEND_FUNCTION(get_defined_functions)
zend_hash_apply_with_arguments(EG(function_table) TSRMLS_CC, copy_function_name, 2, &internal, &user);
- ret = zend_hash_str_add_new(Z_ARRVAL_P(return_value), "internal", sizeof("internal")-1, &internal);
-
- if (!ret) {
- zval_ptr_dtor(&internal);
- zval_ptr_dtor(&user);
- zval_dtor(return_value);
- zend_error(E_WARNING, "Cannot add internal functions to return value from get_defined_functions()");
- RETURN_FALSE;
- }
-
- ret = zend_hash_str_add_new(Z_ARRVAL_P(return_value), "user", sizeof("user")-1, &user);
- if (!ret) {
- zval_ptr_dtor(&user);
- zval_dtor(return_value);
- zend_error(E_WARNING, "Cannot add user functions to return value from get_defined_functions()");
- RETURN_FALSE;
- }
+ zend_hash_str_add_new(Z_ARRVAL_P(return_value), "internal", sizeof("internal")-1, &internal);
+ zend_hash_str_add_new(Z_ARRVAL_P(return_value), "user", sizeof("user")-1, &user);
}
/* }}} */
-
/* {{{ proto array get_defined_vars(void)
Returns an associative array of names and values of all currently defined variable names (variables in the current scope) */
ZEND_FUNCTION(get_defined_vars)
@@ -1829,7 +1789,6 @@ ZEND_FUNCTION(get_defined_vars)
}
/* }}} */
-
#define LAMBDA_TEMP_FUNCNAME "__lambda_func"
/* {{{ proto string create_function(string args, string code)
Creates an anonymous function, and returns its name (funny, eh?) */
@@ -1900,7 +1859,6 @@ ZEND_FUNCTION(create_function)
}
/* }}} */
-
#if ZEND_DEBUG
ZEND_FUNCTION(zend_test_func)
{
@@ -1986,22 +1944,24 @@ ZEND_FUNCTION(get_resources)
}
/* }}} */
-static int add_extension_info(zval *item, void *arg TSRMLS_DC)
+static int add_extension_info(zval *item, void *arg TSRMLS_DC) /* {{{ */
{
zval *name_array = (zval *)arg;
zend_module_entry *module = (zend_module_entry*)Z_PTR_P(item);
add_next_index_string(name_array, module->name);
return 0;
}
+/* }}} */
-static int add_zendext_info(zend_extension *ext, void *arg TSRMLS_DC)
+static int add_zendext_info(zend_extension *ext, void *arg TSRMLS_DC) /* {{{ */
{
zval *name_array = (zval *)arg;
add_next_index_string(name_array, ext->name);
return 0;
}
+/* }}} */
-static int add_constant_info(zval *item, void *arg TSRMLS_DC)
+static int add_constant_info(zval *item, void *arg TSRMLS_DC) /* {{{ */
{
zval *name_array = (zval *)arg;
zend_constant *constant = (zend_constant*)Z_PTR_P(item);
@@ -2016,7 +1976,7 @@ static int add_constant_info(zval *item, void *arg TSRMLS_DC)
zend_hash_add_new(Z_ARRVAL_P(name_array), constant->name, &const_val);
return 0;
}
-
+/* }}} */
/* {{{ proto array get_loaded_extensions([bool zend_extensions]) U
Return an array containing names of loaded extensions */
@@ -2038,7 +1998,6 @@ ZEND_FUNCTION(get_loaded_extensions)
}
/* }}} */
-
/* {{{ proto array get_defined_constants([bool categorize])
Return an array containing the names and values of all defined constants */
ZEND_FUNCTION(get_defined_constants)
@@ -2101,18 +2060,17 @@ ZEND_FUNCTION(get_defined_constants)
}
/* }}} */
-
-static void debug_backtrace_get_args(zend_execute_data *call, zval *arg_array TSRMLS_DC)
+static void debug_backtrace_get_args(zend_execute_data *call, zval *arg_array TSRMLS_DC) /* {{{ */
{
- int num_args = call->num_args;
+ uint32_t num_args = call->num_args;
array_init_size(arg_array, num_args);
if (num_args) {
- int i = 0;
+ uint32_t i = 0;
zval *p = ZEND_CALL_ARG(call, 1);
if (call->func->type == ZEND_USER_FUNCTION) {
- int first_extra_arg = call->func->op_array.num_args;
+ uint32_t first_extra_arg = call->func->op_array.num_args;
if (call->func->op_array.fn_flags & ZEND_ACC_VARIADIC) {
first_extra_arg--;
@@ -2136,8 +2094,9 @@ static void debug_backtrace_get_args(zend_execute_data *call, zval *arg_array TS
}
}
}
+/* }}} */
-void debug_print_backtrace_args(zval *arg_array TSRMLS_DC)
+void debug_print_backtrace_args(zval *arg_array TSRMLS_DC) /* {{{ */
{
zval *tmp;
int i = 0;
@@ -2149,6 +2108,7 @@ void debug_print_backtrace_args(zval *arg_array TSRMLS_DC)
zend_print_flat_zval_r(tmp TSRMLS_CC);
} ZEND_HASH_FOREACH_END();
}
+/* }}} */
/* {{{ proto void debug_print_backtrace([int options[, int limit]]) */
ZEND_FUNCTION(debug_print_backtrace)
@@ -2172,7 +2132,7 @@ ZEND_FUNCTION(debug_print_backtrace)
}
ZVAL_UNDEF(&arg_array);
- ptr = EG(current_execute_data)->prev_execute_data;
+ ptr = EX(prev_execute_data);
/* skip debug_backtrace() */
call = ptr;
@@ -2212,7 +2172,7 @@ ZEND_FUNCTION(debug_print_backtrace)
}
/* $this may be passed into regular internal functions */
- object = call->object;
+ object = Z_OBJ(call->This);
if (object &&
call &&
call->func->type == ZEND_INTERNAL_FUNCTION &&
@@ -2339,7 +2299,7 @@ ZEND_FUNCTION(debug_print_backtrace)
/* }}} */
-ZEND_API void zend_fetch_debug_backtrace(zval *return_value, int skip_last, int options, int limit TSRMLS_DC)
+ZEND_API void zend_fetch_debug_backtrace(zval *return_value, int skip_last, int options, int limit TSRMLS_DC) /* {{{ */
{
zend_execute_data *call, *ptr, *skip;
zend_object *object;
@@ -2434,8 +2394,9 @@ ZEND_API void zend_fetch_debug_backtrace(zval *return_value, int skip_last, int
}
/* $this may be passed into regular internal functions */
- object = call ? call->object : NULL;
+ object = call ? Z_OBJ(call->This) : NULL;
if (object &&
+ call->func &&
call->func->type == ZEND_INTERNAL_FUNCTION &&
!call->func->common.scope) {
object = NULL;
@@ -2547,7 +2508,6 @@ ZEND_API void zend_fetch_debug_backtrace(zval *return_value, int skip_last, int
}
/* }}} */
-
/* {{{ proto array debug_backtrace([int options[, int limit]])
Return backtrace as array */
ZEND_FUNCTION(debug_backtrace)
@@ -2586,7 +2546,6 @@ ZEND_FUNCTION(extension_loaded)
}
/* }}} */
-
/* {{{ proto array get_extension_funcs(string extension_name)
Returns an array with the names of functions belonging to the named extension */
ZEND_FUNCTION(get_extension_funcs)