/Zend/zend_API.c
C | 3561 lines | 2851 code | 478 blank | 232 comment | 721 complexity | 7ac15605f35356bce15a1814ce6d9a67 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, LGPL-2.1, BSD-3-Clause
Large files files are truncated, but you can click here to view the full file
- /*
- +----------------------------------------------------------------------+
- | Zend Engine |
- +----------------------------------------------------------------------+
- | Copyright (c) 1998-2011 Zend Technologies Ltd. (http://www.zend.com) |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.00 of the Zend license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available through the world-wide-web at the following url: |
- | http://www.zend.com/license/2_00.txt. |
- | If you did not receive a copy of the Zend license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@zend.com so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Andi Gutmans <andi@zend.com> |
- | Zeev Suraski <zeev@zend.com> |
- | Andrei Zmievski <andrei@php.net> |
- +----------------------------------------------------------------------+
- */
- /* $Id: zend_API.c 307424 2011-01-12 22:17:10Z felipe $ */
- #include "zend.h"
- #include "zend_execute.h"
- #include "zend_API.h"
- #include "zend_modules.h"
- #include "zend_constants.h"
- #include "zend_exceptions.h"
- #include "zend_closures.h"
- #ifdef HAVE_STDARG_H
- #include <stdarg.h>
- #endif
- /* these variables are true statics/globals, and have to be mutex'ed on every access */
- static int module_count=0;
- ZEND_API HashTable module_registry;
- /* this function doesn't check for too many parameters */
- ZEND_API int zend_get_parameters(int ht, int param_count, ...) /* {{{ */
- {
- void **p;
- int arg_count;
- va_list ptr;
- zval **param, *param_ptr;
- TSRMLS_FETCH();
- p = zend_vm_stack_top(TSRMLS_C) - 1;
- arg_count = (int)(zend_uintptr_t) *p;
- if (param_count>arg_count) {
- return FAILURE;
- }
- va_start(ptr, param_count);
- while (param_count-->0) {
- param = va_arg(ptr, zval **);
- param_ptr = *(p-arg_count);
- if (!PZVAL_IS_REF(param_ptr) && Z_REFCOUNT_P(param_ptr) > 1) {
- zval *new_tmp;
- ALLOC_ZVAL(new_tmp);
- *new_tmp = *param_ptr;
- zval_copy_ctor(new_tmp);
- INIT_PZVAL(new_tmp);
- param_ptr = new_tmp;
- Z_DELREF_P((zval *) *(p-arg_count));
- *(p-arg_count) = param_ptr;
- }
- *param = param_ptr;
- arg_count--;
- }
- va_end(ptr);
- return SUCCESS;
- }
- /* }}} */
- ZEND_API int _zend_get_parameters_array(int ht, int param_count, zval **argument_array TSRMLS_DC) /* {{{ */
- {
- void **p;
- int arg_count;
- zval *param_ptr;
- p = zend_vm_stack_top(TSRMLS_C) - 1;
- arg_count = (int)(zend_uintptr_t) *p;
- if (param_count>arg_count) {
- return FAILURE;
- }
- while (param_count-->0) {
- param_ptr = *(p-arg_count);
- if (!PZVAL_IS_REF(param_ptr) && Z_REFCOUNT_P(param_ptr) > 1) {
- zval *new_tmp;
- ALLOC_ZVAL(new_tmp);
- *new_tmp = *param_ptr;
- zval_copy_ctor(new_tmp);
- INIT_PZVAL(new_tmp);
- param_ptr = new_tmp;
- Z_DELREF_P((zval *) *(p-arg_count));
- *(p-arg_count) = param_ptr;
- }
- *(argument_array++) = param_ptr;
- arg_count--;
- }
- return SUCCESS;
- }
- /* }}} */
- /* Zend-optimized Extended functions */
- /* this function doesn't check for too many parameters */
- ZEND_API int zend_get_parameters_ex(int param_count, ...) /* {{{ */
- {
- void **p;
- int arg_count;
- va_list ptr;
- zval ***param;
- TSRMLS_FETCH();
- p = zend_vm_stack_top(TSRMLS_C) - 1;
- arg_count = (int)(zend_uintptr_t) *p;
- if (param_count>arg_count) {
- return FAILURE;
- }
- va_start(ptr, param_count);
- while (param_count-->0) {
- param = va_arg(ptr, zval ***);
- *param = (zval **) p-(arg_count--);
- }
- va_end(ptr);
- return SUCCESS;
- }
- /* }}} */
- ZEND_API int _zend_get_parameters_array_ex(int param_count, zval ***argument_array TSRMLS_DC) /* {{{ */
- {
- void **p;
- int arg_count;
- p = zend_vm_stack_top(TSRMLS_C) - 1;
- arg_count = (int)(zend_uintptr_t) *p;
- if (param_count>arg_count) {
- return FAILURE;
- }
- while (param_count-->0) {
- zval **value = (zval**)(p-arg_count);
- *(argument_array++) = value;
- arg_count--;
- }
- return SUCCESS;
- }
- /* }}} */
- ZEND_API int zend_copy_parameters_array(int param_count, zval *argument_array TSRMLS_DC) /* {{{ */
- {
- void **p;
- int arg_count;
- p = zend_vm_stack_top(TSRMLS_C) - 1;
- arg_count = (int)(zend_uintptr_t) *p;
- if (param_count>arg_count) {
- return FAILURE;
- }
- while (param_count-->0) {
- zval **param = (zval **) p-(arg_count--);
- zval_add_ref(param);
- add_next_index_zval(argument_array, *param);
- }
- return SUCCESS;
- }
- /* }}} */
- ZEND_API void zend_wrong_param_count(TSRMLS_D) /* {{{ */
- {
- char *space;
- char *class_name = get_active_class_name(&space TSRMLS_CC);
- zend_error(E_WARNING, "Wrong parameter count for %s%s%s()", class_name, space, get_active_function_name(TSRMLS_C));
- }
- /* }}} */
- /* Argument parsing API -- andrei */
- ZEND_API char *zend_get_type_by_const(int type) /* {{{ */
- {
- switch(type) {
- case IS_BOOL:
- return "boolean";
- case IS_LONG:
- return "integer";
- case IS_DOUBLE:
- return "double";
- case IS_STRING:
- return "string";
- case IS_OBJECT:
- return "object";
- case IS_RESOURCE:
- return "resource";
- case IS_NULL:
- return "null";
- case IS_ARRAY:
- return "array";
- default:
- return "unknown";
- }
- }
- /* }}} */
- ZEND_API char *zend_zval_type_name(const zval *arg) /* {{{ */
- {
- return zend_get_type_by_const(Z_TYPE_P(arg));
- }
- /* }}} */
- ZEND_API zend_class_entry *zend_get_class_entry(const zval *zobject TSRMLS_DC) /* {{{ */
- {
- if (Z_OBJ_HT_P(zobject)->get_class_entry) {
- return Z_OBJ_HT_P(zobject)->get_class_entry(zobject TSRMLS_CC);
- } else {
- zend_error(E_ERROR, "Class entry requested for an object without PHP class");
- return NULL;
- }
- }
- /* }}} */
- /* returns 1 if you need to copy result, 0 if it's already a copy */
- ZEND_API int zend_get_object_classname(const zval *object, char **class_name, zend_uint *class_name_len TSRMLS_DC) /* {{{ */
- {
- if (Z_OBJ_HT_P(object)->get_class_name == NULL ||
- Z_OBJ_HT_P(object)->get_class_name(object, class_name, class_name_len, 0 TSRMLS_CC) != SUCCESS) {
- zend_class_entry *ce = Z_OBJCE_P(object);
- *class_name = ce->name;
- *class_name_len = ce->name_length;
- return 1;
- }
- return 0;
- }
- /* }}} */
- static int parse_arg_object_to_string(zval **arg TSRMLS_DC) /* {{{ */
- {
- if (Z_OBJ_HANDLER_PP(arg, cast_object)) {
- SEPARATE_ZVAL_IF_NOT_REF(arg);
- if (Z_OBJ_HANDLER_PP(arg, cast_object)(*arg, *arg, IS_STRING TSRMLS_CC) == SUCCESS) {
- return SUCCESS;
- }
- }
- /* Standard PHP objects */
- if (Z_OBJ_HT_PP(arg) == &std_object_handlers || !Z_OBJ_HANDLER_PP(arg, cast_object)) {
- SEPARATE_ZVAL_IF_NOT_REF(arg);
- if (zend_std_cast_object_tostring(*arg, *arg, IS_STRING TSRMLS_CC) == SUCCESS) {
- return SUCCESS;
- }
- }
- if (!Z_OBJ_HANDLER_PP(arg, cast_object) && Z_OBJ_HANDLER_PP(arg, get)) {
- int use_copy;
- zval *z = Z_OBJ_HANDLER_PP(arg, get)(*arg TSRMLS_CC);
- Z_ADDREF_P(z);
- if(Z_TYPE_P(z) != IS_OBJECT) {
- zval_dtor(*arg);
- Z_TYPE_P(*arg) = IS_NULL;
- zend_make_printable_zval(z, *arg, &use_copy);
- if (!use_copy) {
- ZVAL_ZVAL(*arg, z, 1, 1);
- }
- return SUCCESS;
- }
- zval_ptr_dtor(&z);
- }
- return FAILURE;
- }
- /* }}} */
- static char *zend_parse_arg_impl(int arg_num, zval **arg, va_list *va, char **spec, char **error, int *severity TSRMLS_DC) /* {{{ */
- {
- char *spec_walk = *spec;
- char c = *spec_walk++;
- int return_null = 0;
- /* scan through modifiers */
- while (1) {
- if (*spec_walk == '/') {
- SEPARATE_ZVAL_IF_NOT_REF(arg);
- } else if (*spec_walk == '!') {
- if (Z_TYPE_PP(arg) == IS_NULL) {
- return_null = 1;
- }
- } else {
- break;
- }
- spec_walk++;
- }
- switch (c) {
- case 'l':
- case 'L':
- {
- long *p = va_arg(*va, long *);
- switch (Z_TYPE_PP(arg)) {
- case IS_STRING:
- {
- double d;
- int type;
- if ((type = is_numeric_string(Z_STRVAL_PP(arg), Z_STRLEN_PP(arg), p, &d, -1)) == 0) {
- return "long";
- } else if (type == IS_DOUBLE) {
- if (c == 'L') {
- if (d > LONG_MAX) {
- *p = LONG_MAX;
- break;
- } else if (d < LONG_MIN) {
- *p = LONG_MIN;
- break;
- }
- }
- *p = zend_dval_to_lval(d);
- }
- }
- break;
- case IS_DOUBLE:
- if (c == 'L') {
- if (Z_DVAL_PP(arg) > LONG_MAX) {
- *p = LONG_MAX;
- break;
- } else if (Z_DVAL_PP(arg) < LONG_MIN) {
- *p = LONG_MIN;
- break;
- }
- }
- case IS_NULL:
- case IS_LONG:
- case IS_BOOL:
- convert_to_long_ex(arg);
- *p = Z_LVAL_PP(arg);
- break;
- case IS_ARRAY:
- case IS_OBJECT:
- case IS_RESOURCE:
- default:
- return "long";
- }
- }
- break;
- case 'd':
- {
- double *p = va_arg(*va, double *);
- switch (Z_TYPE_PP(arg)) {
- case IS_STRING:
- {
- long l;
- int type;
- if ((type = is_numeric_string(Z_STRVAL_PP(arg), Z_STRLEN_PP(arg), &l, p, -1)) == 0) {
- return "double";
- } else if (type == IS_LONG) {
- *p = (double) l;
- }
- }
- break;
- case IS_NULL:
- case IS_LONG:
- case IS_DOUBLE:
- case IS_BOOL:
- convert_to_double_ex(arg);
- *p = Z_DVAL_PP(arg);
- break;
- case IS_ARRAY:
- case IS_OBJECT:
- case IS_RESOURCE:
- default:
- return "double";
- }
- }
- break;
- case 's':
- {
- char **p = va_arg(*va, char **);
- int *pl = va_arg(*va, int *);
- switch (Z_TYPE_PP(arg)) {
- case IS_NULL:
- if (return_null) {
- *p = NULL;
- *pl = 0;
- break;
- }
- /* break omitted intentionally */
- case IS_STRING:
- case IS_LONG:
- case IS_DOUBLE:
- case IS_BOOL:
- convert_to_string_ex(arg);
- if (UNEXPECTED(Z_ISREF_PP(arg) != 0)) {
- /* it's dangerous to return pointers to string
- buffer of referenced variable, because it can
- be clobbered throug magic callbacks */
- SEPARATE_ZVAL(arg);
- }
- *p = Z_STRVAL_PP(arg);
- *pl = Z_STRLEN_PP(arg);
- break;
- case IS_OBJECT:
- case IS_ARRAY:
- case IS_RESOURCE:
- default:
- return "string";
- }
- }
- break;
- case 'b':
- {
- zend_bool *p = va_arg(*va, zend_bool *);
- switch (Z_TYPE_PP(arg)) {
- case IS_NULL:
- case IS_STRING:
- case IS_LONG:
- case IS_DOUBLE:
- case IS_BOOL:
- convert_to_boolean_ex(arg);
- *p = Z_BVAL_PP(arg);
- break;
- case IS_ARRAY:
- case IS_OBJECT:
- case IS_RESOURCE:
- default:
- return "boolean";
- }
- }
- break;
- case 'r':
- {
- zval **p = va_arg(*va, zval **);
- if (return_null) {
- *p = NULL;
- break;
- }
- if (Z_TYPE_PP(arg) == IS_RESOURCE) {
- *p = *arg;
- } else {
- return "resource";
- }
- }
- break;
- case 'A':
- case 'a':
- {
- zval **p = va_arg(*va, zval **);
- if (return_null) {
- *p = NULL;
- break;
- }
- if (Z_TYPE_PP(arg) == IS_ARRAY || (c == 'A' && Z_TYPE_PP(arg) == IS_OBJECT)) {
- *p = *arg;
- } else {
- return "array";
- }
- }
- break;
- case 'H':
- case 'h':
- {
- HashTable **p = va_arg(*va, HashTable **);
- if (return_null) {
- *p = NULL;
- break;
- }
- if (Z_TYPE_PP(arg) == IS_ARRAY) {
- *p = Z_ARRVAL_PP(arg);
- } else if(c == 'H' && Z_TYPE_PP(arg) == IS_OBJECT) {
- *p = HASH_OF(*arg);
- if(*p == NULL) {
- return "array";
- }
- } else {
- return "array";
- }
- }
- break;
- case 'o':
- {
- zval **p = va_arg(*va, zval **);
- if (return_null) {
- *p = NULL;
- break;
- }
- if (Z_TYPE_PP(arg) == IS_OBJECT) {
- *p = *arg;
- } else {
- return "object";
- }
- }
- break;
- case 'O':
- {
- zval **p = va_arg(*va, zval **);
- zend_class_entry *ce = va_arg(*va, zend_class_entry *);
- if (return_null) {
- *p = NULL;
- break;
- }
- if (Z_TYPE_PP(arg) == IS_OBJECT &&
- (!ce || instanceof_function(Z_OBJCE_PP(arg), ce TSRMLS_CC))) {
- *p = *arg;
- } else {
- if (ce) {
- return ce->name;
- } else {
- return "object";
- }
- }
- }
- break;
- case 'C':
- {
- zend_class_entry **lookup, **pce = va_arg(*va, zend_class_entry **);
- zend_class_entry *ce_base = *pce;
- if (return_null) {
- *pce = NULL;
- break;
- }
- convert_to_string_ex(arg);
- if (zend_lookup_class(Z_STRVAL_PP(arg), Z_STRLEN_PP(arg), &lookup TSRMLS_CC) == FAILURE) {
- *pce = NULL;
- } else {
- *pce = *lookup;
- }
- if (ce_base) {
- if ((!*pce || !instanceof_function(*pce, ce_base TSRMLS_CC))) {
- zend_spprintf(error, 0, "to be a class name derived from %s, '%s' given",
- ce_base->name, Z_STRVAL_PP(arg));
- *pce = NULL;
- return "";
- }
- }
- if (!*pce) {
- zend_spprintf(error, 0, "to be a valid class name, '%s' given",
- Z_STRVAL_PP(arg));
- return "";
- }
- break;
- }
- break;
- case 'f':
- {
- zend_fcall_info *fci = va_arg(*va, zend_fcall_info *);
- zend_fcall_info_cache *fcc = va_arg(*va, zend_fcall_info_cache *);
- char *is_callable_error = NULL;
- if (return_null) {
- fci->size = 0;
- fcc->initialized = 0;
- break;
- }
- if (zend_fcall_info_init(*arg, 0, fci, fcc, NULL, &is_callable_error TSRMLS_CC) == SUCCESS) {
- if (is_callable_error) {
- *severity = E_STRICT;
- zend_spprintf(error, 0, "to be a valid callback, %s", is_callable_error);
- efree(is_callable_error);
- *spec = spec_walk;
- return "";
- }
- break;
- } else {
- if (is_callable_error) {
- *severity = E_WARNING;
- zend_spprintf(error, 0, "to be a valid callback, %s", is_callable_error);
- efree(is_callable_error);
- return "";
- } else {
- return "valid callback";
- }
- }
- }
- case 'z':
- {
- zval **p = va_arg(*va, zval **);
- if (return_null) {
- *p = NULL;
- } else {
- *p = *arg;
- }
- }
- break;
- case 'Z':
- {
- zval ***p = va_arg(*va, zval ***);
- if (return_null) {
- *p = NULL;
- } else {
- *p = arg;
- }
- }
- break;
- default:
- return "unknown";
- }
- *spec = spec_walk;
- return NULL;
- }
- /* }}} */
- static int zend_parse_arg(int arg_num, zval **arg, va_list *va, char **spec, int quiet TSRMLS_DC) /* {{{ */
- {
- char *expected_type = NULL, *error = NULL;
- int severity = E_WARNING;
- expected_type = zend_parse_arg_impl(arg_num, arg, va, spec, &error, &severity TSRMLS_CC);
- if (expected_type) {
- if (!quiet && (*expected_type || error)) {
- char *space;
- char *class_name = get_active_class_name(&space TSRMLS_CC);
- if (error) {
- zend_error(severity, "%s%s%s() expects parameter %d %s",
- class_name, space, get_active_function_name(TSRMLS_C), arg_num, error);
- efree(error);
- } else {
- zend_error(severity, "%s%s%s() expects parameter %d to be %s, %s given",
- class_name, space, get_active_function_name(TSRMLS_C), arg_num, expected_type,
- zend_zval_type_name(*arg));
- }
- }
- if (severity != E_STRICT) {
- return FAILURE;
- }
- }
- return SUCCESS;
- }
- /* }}} */
- static int zend_parse_va_args(int num_args, char *type_spec, va_list *va, int flags TSRMLS_DC) /* {{{ */
- {
- char *spec_walk;
- int c, i;
- int min_num_args = -1;
- int max_num_args = 0;
- int post_varargs = 0;
- zval **arg;
- int arg_count = (int)(zend_uintptr_t) *(zend_vm_stack_top(TSRMLS_C) - 1);
- int quiet = flags & ZEND_PARSE_PARAMS_QUIET;
- zend_bool have_varargs = 0;
- zval ****varargs = NULL;
- int *n_varargs = NULL;
- for (spec_walk = type_spec; *spec_walk; spec_walk++) {
- c = *spec_walk;
- switch (c) {
- case 's':
- if (max_num_args < arg_count) {
- arg = (zval **) (zend_vm_stack_top(TSRMLS_C) - 1 - (arg_count - max_num_args));
- if (Z_TYPE_PP(arg) == IS_OBJECT) {
- parse_arg_object_to_string(arg TSRMLS_CC);
- }
- }
- /* break missing intentionally */
- case 'l': case 'd':
- case 'H': case 'b':
- case 'r': case 'a':
- case 'o': case 'O':
- case 'z': case 'Z':
- case 'C': case 'h':
- case 'f': case 'A':
- max_num_args++;
- break;
- case '|':
- min_num_args = max_num_args;
- break;
- case '/':
- case '!':
- /* Pass */
- break;
- case '*':
- case '+':
- if (have_varargs) {
- if (!quiet) {
- zend_function *active_function = EG(current_execute_data)->function_state.function;
- char *class_name = active_function->common.scope ? active_function->common.scope->name : "";
- zend_error(E_WARNING, "%s%s%s(): only one varargs specifier (* or +) is permitted",
- class_name,
- class_name[0] ? "::" : "",
- active_function->common.function_name);
- }
- return FAILURE;
- }
- have_varargs = 1;
- /* we expect at least one parameter in varargs */
- if (c == '+') {
- max_num_args++;
- }
- /* mark the beginning of varargs */
- post_varargs = max_num_args;
- break;
- default:
- if (!quiet) {
- zend_function *active_function = EG(current_execute_data)->function_state.function;
- char *class_name = active_function->common.scope ? active_function->common.scope->name : "";
- zend_error(E_WARNING, "%s%s%s(): bad type specifier while parsing parameters",
- class_name,
- class_name[0] ? "::" : "",
- active_function->common.function_name);
- }
- return FAILURE;
- }
- }
- if (min_num_args < 0) {
- min_num_args = max_num_args;
- }
- if (have_varargs) {
- /* calculate how many required args are at the end of the specifier list */
- post_varargs = max_num_args - post_varargs;
- max_num_args = -1;
- }
- if (num_args < min_num_args || (num_args > max_num_args && max_num_args > 0)) {
- if (!quiet) {
- zend_function *active_function = EG(current_execute_data)->function_state.function;
- char *class_name = active_function->common.scope ? active_function->common.scope->name : "";
- zend_error(E_WARNING, "%s%s%s() expects %s %d parameter%s, %d given",
- class_name,
- class_name[0] ? "::" : "",
- active_function->common.function_name,
- min_num_args == max_num_args ? "exactly" : num_args < min_num_args ? "at least" : "at most",
- num_args < min_num_args ? min_num_args : max_num_args,
- (num_args < min_num_args ? min_num_args : max_num_args) == 1 ? "" : "s",
- num_args);
- }
- return FAILURE;
- }
- if (num_args > arg_count) {
- zend_error(E_WARNING, "%s(): could not obtain parameters for parsing",
- get_active_function_name(TSRMLS_C));
- return FAILURE;
- }
- i = 0;
- while (num_args-- > 0) {
- if (*type_spec == '|') {
- type_spec++;
- }
- if (*type_spec == '*' || *type_spec == '+') {
- int num_varargs = num_args + 1 - post_varargs;
- /* eat up the passed in storage even if it won't be filled in with varargs */
- varargs = va_arg(*va, zval ****);
- n_varargs = va_arg(*va, int *);
- type_spec++;
- if (num_varargs > 0) {
- int iv = 0;
- zval **p = (zval **) (zend_vm_stack_top(TSRMLS_C) - 1 - (arg_count - i));
- *n_varargs = num_varargs;
- /* allocate space for array and store args */
- *varargs = safe_emalloc(num_varargs, sizeof(zval **), 0);
- while (num_varargs-- > 0) {
- (*varargs)[iv++] = p++;
- }
- /* adjust how many args we have left and restart loop */
- num_args = num_args + 1 - iv;
- i += iv;
- continue;
- } else {
- *varargs = NULL;
- *n_varargs = 0;
- }
- }
- arg = (zval **) (zend_vm_stack_top(TSRMLS_C) - 1 - (arg_count-i));
- if (zend_parse_arg(i+1, arg, va, &type_spec, quiet TSRMLS_CC) == FAILURE) {
- /* clean up varargs array if it was used */
- if (varargs && *varargs) {
- efree(*varargs);
- *varargs = NULL;
- }
- return FAILURE;
- }
- i++;
- }
- return SUCCESS;
- }
- /* }}} */
- #define RETURN_IF_ZERO_ARGS(num_args, type_spec, quiet) { \
- int __num_args = (num_args); \
- \
- if (0 == (type_spec)[0] && 0 != __num_args && !(quiet)) { \
- char *__space; \
- char * __class_name = get_active_class_name(&__space TSRMLS_CC); \
- zend_error(E_WARNING, "%s%s%s() expects exactly 0 parameters, %d given", \
- __class_name, __space, \
- get_active_function_name(TSRMLS_C), __num_args); \
- return FAILURE; \
- }\
- }
- ZEND_API int zend_parse_parameters_ex(int flags, int num_args TSRMLS_DC, char *type_spec, ...) /* {{{ */
- {
- va_list va;
- int retval;
- RETURN_IF_ZERO_ARGS(num_args, type_spec, flags & ZEND_PARSE_PARAMS_QUIET);
- va_start(va, type_spec);
- retval = zend_parse_va_args(num_args, type_spec, &va, flags TSRMLS_CC);
- va_end(va);
- return retval;
- }
- /* }}} */
- ZEND_API int zend_parse_parameters(int num_args TSRMLS_DC, char *type_spec, ...) /* {{{ */
- {
- va_list va;
- int retval;
- RETURN_IF_ZERO_ARGS(num_args, type_spec, 0);
- va_start(va, type_spec);
- retval = zend_parse_va_args(num_args, type_spec, &va, 0 TSRMLS_CC);
- va_end(va);
- return retval;
- }
- /* }}} */
- ZEND_API int zend_parse_method_parameters(int num_args TSRMLS_DC, zval *this_ptr, char *type_spec, ...) /* {{{ */
- {
- va_list va;
- int retval;
- char *p = type_spec;
- zval **object;
- zend_class_entry *ce;
- if (!this_ptr) {
- RETURN_IF_ZERO_ARGS(num_args, p, 0);
- va_start(va, type_spec);
- retval = zend_parse_va_args(num_args, type_spec, &va, 0 TSRMLS_CC);
- va_end(va);
- } else {
- p++;
- RETURN_IF_ZERO_ARGS(num_args, p, 0);
- va_start(va, type_spec);
- object = va_arg(va, zval **);
- ce = va_arg(va, zend_class_entry *);
- *object = this_ptr;
- if (ce && !instanceof_function(Z_OBJCE_P(this_ptr), ce TSRMLS_CC)) {
- zend_error(E_CORE_ERROR, "%s::%s() must be derived from %s::%s",
- ce->name, get_active_function_name(TSRMLS_C), Z_OBJCE_P(this_ptr)->name, get_active_function_name(TSRMLS_C));
- }
- retval = zend_parse_va_args(num_args, p, &va, 0 TSRMLS_CC);
- va_end(va);
- }
- return retval;
- }
- /* }}} */
- ZEND_API int zend_parse_method_parameters_ex(int flags, int num_args TSRMLS_DC, zval *this_ptr, char *type_spec, ...) /* {{{ */
- {
- va_list va;
- int retval;
- char *p = type_spec;
- zval **object;
- zend_class_entry *ce;
- int quiet = flags & ZEND_PARSE_PARAMS_QUIET;
- if (!this_ptr) {
- RETURN_IF_ZERO_ARGS(num_args, p, quiet);
- va_start(va, type_spec);
- retval = zend_parse_va_args(num_args, type_spec, &va, flags TSRMLS_CC);
- va_end(va);
- } else {
- p++;
- RETURN_IF_ZERO_ARGS(num_args, p, quiet);
- va_start(va, type_spec);
- object = va_arg(va, zval **);
- ce = va_arg(va, zend_class_entry *);
- *object = this_ptr;
- if (ce && !instanceof_function(Z_OBJCE_P(this_ptr), ce TSRMLS_CC)) {
- if (!quiet) {
- zend_error(E_CORE_ERROR, "%s::%s() must be derived from %s::%s",
- ce->name, get_active_function_name(TSRMLS_C), Z_OBJCE_P(this_ptr)->name, get_active_function_name(TSRMLS_C));
- }
- return FAILURE;
- }
- retval = zend_parse_va_args(num_args, p, &va, flags TSRMLS_CC);
- va_end(va);
- }
- return retval;
- }
- /* }}} */
- /* Argument parsing API -- andrei */
- ZEND_API int _array_init(zval *arg, uint size ZEND_FILE_LINE_DC) /* {{{ */
- {
- ALLOC_HASHTABLE_REL(Z_ARRVAL_P(arg));
- _zend_hash_init(Z_ARRVAL_P(arg), size, NULL, ZVAL_PTR_DTOR, 0 ZEND_FILE_LINE_RELAY_CC);
- Z_TYPE_P(arg) = IS_ARRAY;
- return SUCCESS;
- }
- /* }}} */
- static int zend_merge_property(zval **value TSRMLS_DC, int num_args, va_list args, const zend_hash_key *hash_key) /* {{{ */
- {
- /* which name should a numeric property have ? */
- if (hash_key->nKeyLength) {
- zval *obj = va_arg(args, zval *);
- zend_object_handlers *obj_ht = va_arg(args, zend_object_handlers *);
- zval *member;
- MAKE_STD_ZVAL(member);
- ZVAL_STRINGL(member, hash_key->arKey, hash_key->nKeyLength-1, 1);
- obj_ht->write_property(obj, member, *value TSRMLS_CC);
- zval_ptr_dtor(&member);
- }
- return ZEND_HASH_APPLY_KEEP;
- }
- /* }}} */
- /* This function should be called after the constructor has been called
- * because it may call __set from the uninitialized object otherwise. */
- ZEND_API void zend_merge_properties(zval *obj, HashTable *properties, int destroy_ht TSRMLS_DC) /* {{{ */
- {
- zend_object_handlers *obj_ht = Z_OBJ_HT_P(obj);
- zend_class_entry *old_scope = EG(scope);
- EG(scope) = Z_OBJCE_P(obj);
- zend_hash_apply_with_arguments(properties TSRMLS_CC, (apply_func_args_t)zend_merge_property, 2, obj, obj_ht);
- EG(scope) = old_scope;
- if (destroy_ht) {
- zend_hash_destroy(properties);
- FREE_HASHTABLE(properties);
- }
- }
- /* }}} */
- ZEND_API void zend_update_class_constants(zend_class_entry *class_type TSRMLS_DC) /* {{{ */
- {
- if (!class_type->constants_updated || !CE_STATIC_MEMBERS(class_type)) {
- zend_class_entry **scope = EG(in_execution)?&EG(scope):&CG(active_class_entry);
- zend_class_entry *old_scope = *scope;
- *scope = class_type;
- zend_hash_apply_with_argument(&class_type->constants_table, (apply_func_arg_t) zval_update_constant, (void*)1 TSRMLS_CC);
- zend_hash_apply_with_argument(&class_type->default_properties, (apply_func_arg_t) zval_update_constant, (void *) 1 TSRMLS_CC);
- if (!CE_STATIC_MEMBERS(class_type)) {
- HashPosition pos;
- zval **p;
- if (class_type->parent) {
- zend_update_class_constants(class_type->parent TSRMLS_CC);
- }
- #if ZTS
- ALLOC_HASHTABLE(CG(static_members)[(zend_intptr_t)(class_type->static_members)]);
- #else
- ALLOC_HASHTABLE(class_type->static_members);
- #endif
- zend_hash_init(CE_STATIC_MEMBERS(class_type), zend_hash_num_elements(&class_type->default_static_members), NULL, ZVAL_PTR_DTOR, 0);
- zend_hash_internal_pointer_reset_ex(&class_type->default_static_members, &pos);
- while (zend_hash_get_current_data_ex(&class_type->default_static_members, (void**)&p, &pos) == SUCCESS) {
- char *str_index;
- uint str_length;
- ulong num_index;
- zval **q;
- zend_hash_get_current_key_ex(&class_type->default_static_members, &str_index, &str_length, &num_index, 0, &pos);
- if (Z_ISREF_PP(p) &&
- class_type->parent &&
- zend_hash_find(&class_type->parent->default_static_members, str_index, str_length, (void**)&q) == SUCCESS &&
- *p == *q &&
- zend_hash_find(CE_STATIC_MEMBERS(class_type->parent), str_index, str_length, (void**)&q) == SUCCESS
- ) {
- Z_ADDREF_PP(q);
- Z_SET_ISREF_PP(q);
- zend_hash_add(CE_STATIC_MEMBERS(class_type), str_index, str_length, (void**)q, sizeof(zval*), NULL);
- } else {
- zval *r;
- ALLOC_ZVAL(r);
- *r = **p;
- INIT_PZVAL(r);
- zval_copy_ctor(r);
- zend_hash_add(CE_STATIC_MEMBERS(class_type), str_index, str_length, (void**)&r, sizeof(zval*), NULL);
- }
- zend_hash_move_forward_ex(&class_type->default_static_members, &pos);
- }
- }
- zend_hash_apply_with_argument(CE_STATIC_MEMBERS(class_type), (apply_func_arg_t) zval_update_constant, (void *) 1 TSRMLS_CC);
- *scope = old_scope;
- class_type->constants_updated = 1;
- }
- }
- /* }}} */
- /* This function requires 'properties' to contain all props declared in the
- * class and all props being public. If only a subset is given or the class
- * has protected members then you need to merge the properties seperately by
- * calling zend_merge_properties(). */
- ZEND_API int _object_and_properties_init(zval *arg, zend_class_entry *class_type, HashTable *properties ZEND_FILE_LINE_DC TSRMLS_DC) /* {{{ */
- {
- zval *tmp;
- zend_object *object;
- if (class_type->ce_flags & (ZEND_ACC_INTERFACE|ZEND_ACC_IMPLICIT_ABSTRACT_CLASS|ZEND_ACC_EXPLICIT_ABSTRACT_CLASS)) {
- char *what = class_type->ce_flags & ZEND_ACC_INTERFACE ? "interface" : "abstract class";
- zend_error(E_ERROR, "Cannot instantiate %s %s", what, class_type->name);
- }
- zend_update_class_constants(class_type TSRMLS_CC);
- Z_TYPE_P(arg) = IS_OBJECT;
- if (class_type->create_object == NULL) {
- Z_OBJVAL_P(arg) = zend_objects_new(&object, class_type TSRMLS_CC);
- if (properties) {
- object->properties = properties;
- } else {
- ALLOC_HASHTABLE_REL(object->properties);
- zend_hash_init(object->properties, zend_hash_num_elements(&class_type->default_properties), NULL, ZVAL_PTR_DTOR, 0);
- zend_hash_copy(object->properties, &class_type->default_properties, zval_copy_property_ctor(class_type), (void *) &tmp, sizeof(zval *));
- }
- } else {
- Z_OBJVAL_P(arg) = class_type->create_object(class_type TSRMLS_CC);
- }
- return SUCCESS;
- }
- /* }}} */
- ZEND_API int _object_init_ex(zval *arg, zend_class_entry *class_type ZEND_FILE_LINE_DC TSRMLS_DC) /* {{{ */
- {
- return _object_and_properties_init(arg, class_type, 0 ZEND_FILE_LINE_RELAY_CC TSRMLS_CC);
- }
- /* }}} */
- ZEND_API int _object_init(zval *arg ZEND_FILE_LINE_DC TSRMLS_DC) /* {{{ */
- {
- return _object_init_ex(arg, zend_standard_class_def ZEND_FILE_LINE_RELAY_CC TSRMLS_CC);
- }
- /* }}} */
- ZEND_API int add_assoc_function(zval *arg, const char *key, void (*function_ptr)(INTERNAL_FUNCTION_PARAMETERS)) /* {{{ */
- {
- zend_error(E_WARNING, "add_assoc_function() is no longer supported");
- return FAILURE;
- }
- /* }}} */
- ZEND_API int add_assoc_long_ex(zval *arg, const char *key, uint key_len, long n) /* {{{ */
- {
- zval *tmp;
- MAKE_STD_ZVAL(tmp);
- ZVAL_LONG(tmp, n);
- return zend_symtable_update(Z_ARRVAL_P(arg), key, key_len, (void *) &tmp, sizeof(zval *), NULL);
- }
- /* }}} */
- ZEND_API int add_assoc_null_ex(zval *arg, const char *key, uint key_len) /* {{{ */
- {
- zval *tmp;
- MAKE_STD_ZVAL(tmp);
- ZVAL_NULL(tmp);
- return zend_symtable_update(Z_ARRVAL_P(arg), key, key_len, (void *) &tmp, sizeof(zval *), NULL);
- }
- /* }}} */
- ZEND_API int add_assoc_bool_ex(zval *arg, const char *key, uint key_len, int b) /* {{{ */
- {
- zval *tmp;
- MAKE_STD_ZVAL(tmp);
- ZVAL_BOOL(tmp, b);
- return zend_symtable_update(Z_ARRVAL_P(arg), key, key_len, (void *) &tmp, sizeof(zval *), NULL);
- }
- /* }}} */
- ZEND_API int add_assoc_resource_ex(zval *arg, const char *key, uint key_len, int r) /* {{{ */
- {
- zval *tmp;
- MAKE_STD_ZVAL(tmp);
- ZVAL_RESOURCE(tmp, r);
- return zend_symtable_update(Z_ARRVAL_P(arg), key, key_len, (void *) &tmp, sizeof(zval *), NULL);
- }
- /* }}} */
- ZEND_API int add_assoc_double_ex(zval *arg, const char *key, uint key_len, double d) /* {{{ */
- {
- zval *tmp;
- MAKE_STD_ZVAL(tmp);
- ZVAL_DOUBLE(tmp, d);
- return zend_symtable_update(Z_ARRVAL_P(arg), key, key_len, (void *) &tmp, sizeof(zval *), NULL);
- }
- /* }}} */
- ZEND_API int add_assoc_string_ex(zval *arg, const char *key, uint key_len, char *str, int duplicate) /* {{{ */
- {
- zval *tmp;
- MAKE_STD_ZVAL(tmp);
- ZVAL_STRING(tmp, str, duplicate);
- return zend_symtable_update(Z_ARRVAL_P(arg), key, key_len, (void *) &tmp, sizeof(zval *), NULL);
- }
- /* }}} */
- ZEND_API int add_assoc_stringl_ex(zval *arg, const char *key, uint key_len, char *str, uint length, int duplicate) /* {{{ */
- {
- zval *tmp;
- MAKE_STD_ZVAL(tmp);
- ZVAL_STRINGL(tmp, str, length, duplicate);
- return zend_symtable_update(Z_ARRVAL_P(arg), key, key_len, (void *) &tmp, sizeof(zval *), NULL);
- }
- /* }}} */
- ZEND_API int add_assoc_zval_ex(zval *arg, const char *key, uint key_len, zval *value) /* {{{ */
- {
- return zend_symtable_update(Z_ARRVAL_P(arg), key, key_len, (void *) &value, sizeof(zval *), NULL);
- }
- /* }}} */
- ZEND_API int add_index_long(zval *arg, ulong index, long n) /* {{{ */
- {
- zval *tmp;
- MAKE_STD_ZVAL(tmp);
- ZVAL_LONG(tmp, n);
- return zend_hash_index_update(Z_ARRVAL_P(arg), index, (void *) &tmp, sizeof(zval *), NULL);
- }
- /* }}} */
- ZEND_API int add_index_null(zval *arg, ulong index) /* {{{ */
- {
- zval *tmp;
- MAKE_STD_ZVAL(tmp);
- ZVAL_NULL(tmp);
- return zend_hash_index_update(Z_ARRVAL_P(arg), index, (void *) &tmp, sizeof(zval *), NULL);
- }
- /* }}} */
- ZEND_API int add_index_bool(zval *arg, ulong index, int b) /* {{{ */
- {
- zval *tmp;
- MAKE_STD_ZVAL(tmp);
- ZVAL_BOOL(tmp, b);
- return zend_hash_index_update(Z_ARRVAL_P(arg), index, (void *) &tmp, sizeof(zval *), NULL);
- }
- /* }}} */
- ZEND_API int add_index_resource(zval *arg, ulong index, int r) /* {{{ */
- {
- zval *tmp;
- MAKE_STD_ZVAL(tmp);
- ZVAL_RESOURCE(tmp, r);
- return zend_hash_index_update(Z_ARRVAL_P(arg), index, (void *) &tmp, sizeof(zval *), NULL);
- }
- /* }}} */
- ZEND_API int add_index_double(zval *arg, ulong index, double d) /* {{{ */
- {
- zval *tmp;
- MAKE_STD_ZVAL(tmp);
- ZVAL_DOUBLE(tmp, d);
- return zend_hash_index_update(Z_ARRVAL_P(arg), index, (void *) &tmp, sizeof(zval *), NULL);
- }
- /* }}} */
- ZEND_API int add_index_string(zval *arg, ulong index, const char *str, int duplicate) /* {{{ */
- {
- zval *tmp;
- MAKE_STD_ZVAL(tmp);
- ZVAL_STRING(tmp, str, duplicate);
- return zend_hash_index_update(Z_ARRVAL_P(arg), index, (void *) &tmp, sizeof(zval *), NULL);
- }
- /* }}} */
- ZEND_API int add_index_stringl(zval *arg, ulong index, const char *str, uint length, int duplicate) /* {{{ */
- {
- zval *tmp;
- MAKE_STD_ZVAL(tmp);
- ZVAL_STRINGL(tmp, str, length, duplicate);
- return zend_hash_index_update(Z_ARRVAL_P(arg), index, (void *) &tmp, sizeof(zval *), NULL);
- }
- /* }}} */
- ZEND_API int add_index_zval(zval *arg, ulong index, zval *value) /* {{{ */
- {
- return zend_hash_index_update(Z_ARRVAL_P(arg), index, (void *) &value, sizeof(zval *), NULL);
- }
- /* }}} */
- ZEND_API int add_next_index_long(zval *arg, long n) /* {{{ */
- {
- zval *tmp;
- MAKE_STD_ZVAL(tmp);
- ZVAL_LONG(tmp, n);
- return zend_hash_next_index_insert(Z_ARRVAL_P(arg), &tmp, sizeof(zval *), NULL);
- }
- /* }}} */
- ZEND_API int add_next_index_null(zval *arg) /* {{{ */
- {
- zval *tmp;
- MAKE_STD_ZVAL(tmp);
- ZVAL_NULL(tmp);
- return zend_hash_next_index_insert(Z_ARRVAL_P(arg), &tmp, sizeof(zval *), NULL);
- }
- /* }}} */
- ZEND_API int add_next_index_bool(zval *arg, int b) /* {{{ */
- {
- zval *tmp;
- MAKE_STD_ZVAL(tmp);
- ZVAL_BOOL(tmp, b);
- return zend_hash_next_index_insert(Z_ARRVAL_P(arg), &tmp, sizeof(zval *), NULL);
- }
- /* }}} */
- ZEND_API int add_next_index_resource(zval *arg, int r) /* {{{ */
- {
- zval *tmp;
- MAKE_STD_ZVAL(tmp);
- ZVAL_RESOURCE(tmp, r);
- return zend_hash_next_index_insert(Z_ARRVAL_P(arg), &tmp, sizeof(zval *), NULL);
- }
- /* }}} */
- ZEND_API int add_next_index_double(zval *arg, double d) /* {{{ */
- {
- zval *tmp;
- MAKE_STD_ZVAL(tmp);
- ZVAL_DOUBLE(tmp, d);
- return zend_hash_next_index_insert(Z_ARRVAL_P(arg), &tmp, sizeof(zval *), NULL);
- }
- /* }}} */
- ZEND_API int add_next_index_string(zval *arg, const char *str, int duplicate) /* {{{ */
- {
- zval *tmp;
- MAKE_STD_ZVAL(tmp);
- ZVAL_STRING(tmp, str, duplicate);
- return zend_hash_next_index_insert(Z_ARRVAL_P(arg), &tmp, sizeof(zval *), NULL);
- }
- /* }}} */
- ZEND_API int add_next_index_stringl(zval *arg, const char *str, uint length, int duplicate) /* {{{ */
- {
- zval *tmp;
- MAKE_STD_ZVAL(tmp);
- ZVAL_STRINGL(tmp, str, length, duplicate);
- return zend_hash_next_index_insert(Z_ARRVAL_P(arg), &tmp, sizeof(zval *), NULL);
- }
- /* }}} */
- ZEND_API int add_next_index_zval(zval *arg, zval *value) /* {{{ */
- {
- return zend_hash_next_index_insert(Z_ARRVAL_P(arg), &value, sizeof(zval *), NULL);
- }
- /* }}} */
- ZEND_API int add_get_assoc_string_ex(zval *arg, const char *key, uint key_len, const char *str, void **dest, int duplicate) /* {{{ */
- {
- zval *tmp;
- MAKE_STD_ZVAL(tmp);
- ZVAL_STRING(tmp, str, duplicate);
- return zend_symtable_update(Z_ARRVAL_P(arg), key, key_len, (void *) &tmp, sizeof(zval *), dest);
- }
- /* }}} */
- ZEND_API int add_get_assoc_stringl_ex(zval *arg, const char *key, uint key_len, const char *str, uint length, void **dest, int duplicate) /* {{{ */
- {
- zval *tmp;
- MAKE_STD_ZVAL(tmp);
- ZVAL_STRINGL(tmp, str, length, duplicate);
- return zend_symtable_update(Z_ARRVAL_P(arg), key, key_len, (void *) &tmp, sizeof(zval *), dest);
- }
- /* }}} */
- ZEND_API int add_get_index_long(zval *arg, ulong index, long l, void **dest) /* {{{ */
- {
- zval *tmp;
- MAKE_STD_ZVAL(tmp);
- ZVAL_LONG(tmp, l);
- return zend_hash_index_update(Z_ARRVAL_P(arg), index, (void *) &tmp, sizeof(zval *), dest);
- }
- /* }}} */
- ZEND_API int add_get_index_double(zval *arg, ulong index, double d, void **dest) /* {{{ */
- {
- zval *tmp;
- MAKE_STD_ZVAL(tmp);
- ZVAL_DOUBLE(tmp, d);
- return zend_hash_index_update(Z_ARRVAL_P(arg), index, (void *) &tmp, sizeof(zval *), dest);
- }
- /* }}} */
- ZEND_API int add_get_index_string(zval *arg, ulong index, const char *str, void **dest, int duplicate) /* {{{ */
- {
- zval *tmp;
- MAKE_STD_ZVAL(tmp);
- ZVAL_STRING(tmp, str, duplicate);
- return zend_hash_index_update(Z_ARRVAL_P(arg), index, (void *) &tmp, sizeof(zval *), dest);
- }
- /* }}} */
- ZEND_API int add_get_index_stringl(zval *arg, ulong index, const char *str, uint length, void **dest, int duplicate) /* {{{ */
- {
- zval *tmp;
- MAKE_STD_ZVAL(tmp);
- ZVAL_STRINGL(tmp, str, length, duplicate);
- return zend_hash_index_update(Z_ARRVAL_P(arg), index, (void *) &tmp, sizeof(zval *), dest);
- }
- /* }}} */
- ZEND_API int add_property_long_ex(zval *arg, const char *key, uint key_len, long n TSRMLS_DC) /* {{{ */
- {
- zval *tmp;
- zval *z_key;
- MAKE_STD_ZVAL(tmp);
- ZVAL_LONG(tmp, n);
- MAKE_STD_ZVAL(z_key);
- ZVAL_STRINGL(z_key, key, key_len-1, 1);
- Z_OBJ_HANDLER_P(arg, write_property)(arg, z_key, tmp TSRMLS_CC);
- zval_ptr_dtor(&tmp); /* write_property will add 1 to refcount */
- zval_ptr_dtor(&z_key);
- return SUCCESS;
- }
- /* }}} */
- ZEND_API int add_property_bool_ex(zval *arg, const char *key, uint key_len, int b TSRMLS_DC) /* {{{ */
- {
- zval *tmp;
- zval *z_key;
- MAKE_STD_ZVAL(tmp);
- ZVAL_BOOL(tmp, b);
- MAKE_STD_ZVAL(z_key);
- ZVAL_STRINGL(z_key, key, key_len-1, 1);
- Z_OBJ_HANDLER_P(arg, write_property)(arg, z_key, tmp TSRMLS_CC);
- zval_ptr_dtor(&tmp); /* write_property will add 1 to refcount */
- zval_ptr_dtor(&z_key);
- return SUCCESS;
- }
- /* }}} */
- ZEND_API int add_property_null_ex(zval *arg, const char *key, uint key_len TSRMLS_DC) /* {{{ */
- {
- zval *tmp;
- zval *z_key;
- MAKE_STD_ZVAL(tmp);
- ZVAL_NULL(tmp);
- MAKE_STD_ZVAL(z_key);
- ZVAL_STRINGL(z_key, key, key_len-1, 1);
- Z_OBJ_HANDLER_P(arg, write_property)(arg, z_key, tmp TSRMLS_CC);
- zval_ptr_dtor(&tmp); /* write_property will add 1 to refcount */
- zval_ptr_dtor(&z_key);
- return SUCCESS;
- }
- /* }}} */
- ZEND_API int add_property_resource_ex(zval *arg, const char *key, uint key_len, long n TSRMLS_DC) /* {{{ */
- {
- zval *tmp;
- zval *z_key;
- MAKE_STD_ZVAL(tmp);
- ZVAL_RESOURCE(tmp, n);
- MAKE_STD_ZVAL(z_key);
- ZVAL_STRINGL(z_key, key, key_len-1, 1);
- Z_OBJ_HANDLER_P(arg, write_property)(arg, z_key, tmp TSRMLS_CC);
- zval_ptr_dtor(&tmp); /* write_property will add 1 to refcount */
- zval_ptr_dtor(&z_key);
- return SUCCESS;
- }
- /* }}} */
- ZEND_API int add_property_double_ex(zval *arg, const char *key, uint key_len, double d TSRMLS_DC) /* {{{ */
- {
- zval *tmp;
- zval *z_key;
- MAKE_STD_ZVAL(tmp);
- ZVAL_DOUBLE(tmp, d);
- MAKE_STD_ZVAL(z_key);
- ZVAL_STRINGL(z_key, key, key_len-1, 1);
- Z_OBJ_HANDLER_P(arg, write_property)(arg, z_key, tmp TSRMLS_CC);
- zval_ptr_dtor(&tmp); /* write_property will add 1 to refcount */
- zval_ptr_dtor(&z_key);
- return SUCCESS;
- }
- /* }}} */
- ZEND_API int add_property_string_ex(zval *arg, const char *key, uint key_len, char *str, int duplicate TSRMLS_DC) /* {{{ */
- {
- zval *tmp;
- zval *z_key;
- MAKE_STD_ZVAL(tmp);
- ZVAL_STRING(tmp, str, duplicate);
- MAKE_STD_ZVAL(z_key);
- ZVAL_STRINGL(z_key, key, key_len-1, 1);
- Z_OBJ_HANDLER_P(arg, write_property)(arg, z_key, tmp TSRMLS_CC);
- zval_ptr_dtor(&tmp); /* write_property will add 1 to refcount */
- zval_ptr_dtor(&z_key);
- return SUCCESS;
- }
- /* }}} */
- ZEND_API int add_property_stringl_ex(zval *arg, const char *key, uint key_len, char *str, uint length, int duplicate TSRMLS_DC) /* {{{ */
- {
- zval *tmp;
- zval *z_key;
- MAKE_STD_ZVAL(tmp);
- ZVAL_STRINGL(tmp, str, length, duplicate);
- MAKE_STD_ZVAL(z_key);
- ZVAL_STRINGL(z_key, key, key_len-1, 1);
- Z_OBJ_HANDLER_P(arg, write_property)(arg, z_key, tmp TSRMLS_CC);
- zval_ptr_dtor(&tmp); /* write_property will add 1 to refcount */
- zval_ptr_dtor(&z_key);
- return SUCCESS;
- }
- /* }}} */
- ZEND_API int add_property_zval_ex(zval *arg, const char *key, uint key_len, zval *value TSRMLS_DC) /* {{{ */
- {
- zval *z_key;
- MAKE_STD_ZVAL(z_key);
- ZVAL_STRINGL(z_key, key, key_len-1, 1);
- Z_OBJ_HANDLER_P(arg, write_property)(arg, z_key, value TSRMLS_CC);
- zval_ptr_dtor(&z_key);
- return SUCCESS;
- }
- /* }}} */
- ZEND_API int zend_startup_module_ex(zend_module_entry *module TSRMLS_DC) /* {{{ */
- {
- int name_len;
- char *lcname;
- if (module->module_started) {
- return SUCCESS;
- }
- module->module_started = 1;
- /* Check module dependencies */
- if (module->deps) {
- const zend_module_dep *dep = module->deps;
- while (dep->name) {
- if (dep->type == MODULE_DEP_REQUIRED) {
- zend_module_entry *req_mod;
- name_len = strlen(dep->name);
- lcname = zend_str_tolower_dup(dep->name, name_len);
- if (zend_hash_find(&module_registry, lcname, name_len+1, (void**)&req_mod) == FAILURE || !req_mod->module_started) {
- efree(lcname);
- /* TODO: Check version relationship */
- zend_error(E_CORE_WARNING, "Cannot load module '%s' because required module '%s' is not loaded", module->name, dep->name);
- module->module_started = 0;
- return FAILURE;
- }
- efree(lcname);
- }
- ++dep;
- }
- }
- /* Initialize module globals */
- if (module->globals_size) {
- #ifdef ZTS
- ts_allocate_id(module->globals_id_ptr, module->globals_size, (ts_allocate_ctor) module->globals_ctor, (ts_allocate_dtor) module->globals_dtor);
- #else
- if (module->globals_ctor) {
- module->globals_ctor(module->globals_ptr TSRMLS_CC);
- }
- #endif
- }
- if (module->module_startup_func) {
- EG(current_module) = module;
- if (module->module_startup_func(module->type, module->module_number TSRMLS_CC)==FAILURE) {
- zend_error(E_CORE_ERROR,"Unable to start %s module", module->name);
- EG(current_module) = NULL;
- return FAILURE;
- }
- EG(current_module) = NULL;
- }
- return SUCCESS;
- }
- /* }}} */
- static void zend_sort_modules(void *base, size_t count, size_t siz, compare_func_t compare TSRMLS_DC) /* {{{ */
- {
- Bucket **b1 = base;
- Bucket **b2;
- Bucket **end = b1 + count;
- Bucket *tmp;
- zend_module_entry *m, *r;
- while (b1 < end) {
- try_again:
- m = (zend_module_entry*)(*b1)->pData;
- if (!m->module_started && m->deps) {
- const zend_module_dep *dep = m->deps;
- while (dep->name) {
- if (dep->type == MODULE_DEP_REQUIRED || dep->type == MODULE_DEP_OPTIONAL) {
- b2 = b1 + 1;
- while (b2 < end) {
- r = (zend_module_entry*)(*b2)->pData;
- if (strcasecmp(dep->name, r->name) == 0) {
- tmp = *b1;
- *b1 = *b2;
- *b2 = tmp;
- goto try_again;
- }
- b2++;
- }
- }
- dep++;
- }
- }
- b1++;
- }
- }
- /* }}} */
- ZEND_API int zend_startup_modules(TSRMLS_D) /* {{{ */
- {
- zend_hash_sort(&module_registry, zend_sort_modules, NULL, 0 TSRMLS_CC);
- zend_hash_apply(&module_registry, (apply_func_t)zend_startup_module_ex TSRMLS_CC);
- return SUCCESS;
- }
- /* }}} */
- ZEND_API zend_module_entry* zend_register_module_ex(zend_module_entry *module TSRMLS_DC) /* {{{ */
- {
- int name_len;
- char *lcname;
- zend_module_entry *module_ptr;
- if (!module) {
- return NULL;
- }
- #if 0
- zend_printf("%s: Registering module %d\n", module->name, module->module_number);
- #endif
- /* Check module dependencies */
- if (module->deps) {
- const zend_module_dep *dep = module->deps;
- while (dep->name) {
- if (dep->type == MODULE_DEP_CONFLICTS) {
- name_len = strlen(dep->name);
- lcname = zend_str_tolower_dup(dep->name, name_len);
- if (zend_hash_exists(&module_registry, lcname, name_len+1)) {
- efree(lcname);
- /* TODO: Check version relationship */
- zend_error(E_CORE_WARNING, "Cannot load module '%s' because conflicting module '%s' is already loaded", module->name, dep->name);
- return NULL;
- }
- efree(lcname);
- }
- ++dep;
- }
- }
- name_len = strlen(module->name);
- lcname = zend_str_tolower_dup(module->name, name_len);
- if (zend_hash_add(&module_registry, lcname, name_len+1, (void *)module, sizeof(zend_module_entry), (void**)&module_ptr)==FAILURE) {
- zend_error(E_CORE_WARNING, "Module '%s' already loaded", module->name);
- efree(lcname);
- return NULL;
- }
- efree(lcname);
- module = module_ptr;
- EG(current_module) = module;
- if (module->functions && zend_register_functions(NULL, module->functions, NULL, module->type TSRMLS_CC)==FAILURE) {
- EG(current_module) = NULL;
- zend_error(E_CORE_WARNING,"%s: Unable to register functions, unable to load", module->name);
- return NULL;
- }
- EG(current_module) = NULL;
- return module;
- }
- /* }}} */
- ZEND_API zend_module_entry* zend_register_internal_module(zend_module_entry *module TSRMLS_DC) /* {{{ */
- {
- module->module_number = zend_next_free_module();
- module->type = MODULE_PERSISTENT;
- return zend_register_module_ex(module TSRMLS_CC);
- }
- /* }}} */
- ZEND_API void zend_check_magic_method_implementation(const zend_class_entry *ce, const zend_function *fptr, int error_type TSRMLS_DC) /* {{{ */
- {
- char lcname[16];
- int name_len;
- /* we don't care if the function name is longer, in fact lowercasing only
- * the beginning of the name speeds up the check process */
- name_len = strlen(fptr->common.function_name);
- zend_str_tolower_copy(lcname, fptr->common.function_name, MIN(name_len, sizeof(lcname)-1));
- lcname[sizeof(lcname)-1] = '\0'; /* zend_str_tolower_copy won't necessarily set the zero byte */
- if (name_len == sizeof(ZEND_DESTRUCTOR_FUNC_NAME) - 1 && !memcmp(lcname, ZEND_DESTRUCTOR_FUNC_NAME, sizeof(ZEND_DESTRUCTOR_FUNC_NAME)) && fptr->common.num_args != 0) {
- zend_error(error_type, "Destructor %s::%s() cannot take arguments", ce->name, ZEND_DESTRUCTOR_FUNC_NAME);
- } else if (name_len == sizeof(ZEND_CLONE_FUNC_NAME) - 1 && !memcmp(lcname, ZEND_CLONE_FUNC_NAME, sizeof(ZEND_CLONE_FUNC_NAME)) && fptr->common.num_args != 0) {
- zend_error(error_type, "Method %s::%s() cannot accept any arguments", ce->name, ZEND_CLONE_FUNC_NAME);
- } else if (name_len == sizeof(ZEND_GET_FUNC_NAME) - 1 && !memcmp(lcname, ZEND_GET_FUNC_NAME, sizeof(ZEND_GET_FUNC_NAME))) {
- if (fptr->common.num_args != 1) {
- zend_error(error_type, "Method %s::%s() must take exactly 1 argument", ce->name, ZEND_GET_FUNC_NAME);
- } else if (ARG_SHOULD_BE_SENT_BY_REF(fptr, 1)) {
- zend_error(error_type, "Method %s::%s() cannot take arguments by reference", ce->name, ZEND_GET_FUNC_NAME);
- }
- } else if (name_len == sizeof(ZEND_SET_FUNC_NAME) - 1 && !memcmp(lcname, ZEND_SET_FUNC_NAME, sizeof(ZEND_SET_FUNC_NAME))) {
- if (fptr->common.num_args != 2) {
- zend_error(error_type, "Method %s::%s() must take exactly 2 arguments", ce->name, ZEND_SET_FUNC_NAME);
- } else if (ARG_SHOULD_BE_SENT_BY_REF(fptr, 1) || ARG_SHOULD_BE_SENT_BY_REF(fptr, 2)) {
- zend_error(error_type, "Method %s::%s() cannot take arguments by reference", ce->name, ZEND_SET_FUNC_NAME);
- }
- } else if (name_len == sizeof(ZEND_UNSET_FUNC_NAME) - 1 && !memcmp(lcname, ZEND_UNSET_FUNC_NAME, sizeof(ZEND_UNSET_FUNC_NAME))) {
- if (fptr->common.num_args != 1) {
- zend_error(error_type, "Method %s::%s() must take exactly 1 argument", ce->name, ZEND_UNSET_FUNC_NAME);
- } else if (ARG_SHOULD_BE_SENT_BY_REF(fptr, 1)) {
- zend_error(error_type, "Method %s::%s() cannot take arguments by reference", ce->name, ZEND_UNSET_FUNC_NAME);
- }
- } else if (name_len == sizeof(ZEND_ISSET_FUNC_NAME) - 1 && !memcmp(lcname, ZEND_ISSET_FUNC_NAME, sizeof(ZEND_ISSET_FUNC_NAME))) {
- if (fptr->common.num_args != 1) {
- zend_error(error_type, "Method %s::%s() must take exactly 1 argument", ce->name, ZEND_ISSET_FUNC_NAME);
- } else if (ARG_SHOULD_BE_SENT_BY_REF(fptr, 1)) {
- zend_error(error_type, "Method %s::%s() cannot take arguments by reference", ce->name, ZEND_ISSET_FUNC_NAME);
- }
- } else if (name_len == sizeof(ZEND_CALL_FUNC_NAME) - 1 && !memcmp(lcname, ZEND_CALL_FUNC_NAME, sizeof(ZEND_CALL_FUNC_NAME))) {
- if (fptr->common.num_args != 2) {
- zend_error(error_type, "Method %s::%s() must take exactly 2 arguments", ce->name, ZEND_CALL_FUNC_NAME);
- } else if (ARG_SHOULD_BE_SENT_BY_REF(fptr, 1) || ARG_SHOULD_BE_SENT_BY_REF(fptr, 2)) {
- zend_error(error_type, "Method %s::%s() cannot take arguments by reference", ce->name, ZEND_CALL_FUNC_NAME);
- }
- } else if (name_len == sizeof(ZEND_CALLSTATIC_FUNC_NAME) - 1 &&
- !memcmp(lcname, ZEND_CALLSTATIC_FUNC_NAME, sizeof(ZEND_CALLSTATIC_FUNC_NAME)-1)
- ) {
- if (fptr->common.num_args != 2) {
- zend_error(error_type, "Method %s::%s() must take exactly 2 arguments", ce->name, ZEND_CALLSTATIC_FUNC_NAME);
- } else if (ARG_SHOULD_BE_SENT_BY_REF(fptr, 1) || ARG_SHOULD_BE_SENT_BY_REF(fptr, 2)) {
- zend_error(error_type, "Method %s::%s() cannot take arguments by reference", ce->name, ZEND_CALLSTATIC_FUNC_NAME);
- }
- } else if (name_len == sizeof(ZEND_TOSTRING_FUNC_NAME) - 1 &&
- !memcmp(lcname, ZEND_TOSTRING_FUNC_NAME, sizeof(ZEND_TOSTRING_FUNC_NAME)-1) && fptr->common.num_args != 0
- ) {
- zend_error(error_type, "Method %s::%s() cannot take arguments", ce->name, ZEND_TOSTRING_FUNC_NAME);
- }
- }
- /* }}} */
- /* registers all functions in *library_functions in the function hash */
- ZEND_API int zend_register_functions(zend_class_entry *scope, const zend_function_entry *functions, HashTable *function_table, int type TSRMLS_DC) /* {{{ */
- {
- const zend_function_entry *ptr = functions;
- zend_function function, *reg_function;
- zend_internal_function *internal_function = (zend_internal_function *)&function;
- int count=0, unload=0;
- HashTable *target_function_table = function_table;
- int error_type;
- zend_function *ctor = NULL, *dtor = NULL, *clone = NULL, *__get = NULL, *__set = NULL, *__unset = NULL, *__isset = NULL, *__call = NULL, *__callstatic = NULL, *__tostring = NULL;
- char *lowercase_name;
- int fname_len;
- char *lc_class_name = NULL;
- int class_name_len = 0;
- if (type==MODULE_PERSISTENT) {
- error_type = E_CORE_WARNING;
- } else {
- error_type = E_WARNING;
- }
- if (!target_function_table) {
- target_function_table = CG(function_table);
- }
- internal_function->type = ZEND_INTERNAL_FUNCTION;
- internal_function->module = EG(current_module);
- if (scope) {
- class_name_len = strlen(scope->name);
- if ((lc_class_name = zend_memrchr(scope->name, '\\', class_name_len))) {
- ++lc_class_name;
- class_name_len -= (lc_class_name - scope->name);
- lc_class_name = zend_str_tolower_dup(lc_class_name, class_name_len);
- } else {
- lc_class_name = zend_str_tolower_dup(scope->name, class_name_len);
- }
- }
- while (ptr->fname) {
- internal_function->handler = ptr->handler;
- internal_function->function_name = (char*)ptr->fname;
- internal_function->scope = scope;
- internal_function->prototype = NULL;
- if (ptr->arg_info) {
- internal_function->arg_info = (zend_arg_info*)ptr->arg_info+1;
- internal_function->num_args = ptr->num_args;
- /* Currently you cannot denote that the function can accept less arguments than num_args */
- if (ptr->arg_info[0].required_num_args == -1)…
Large files files are truncated, but you can click here to view the full file