php-src/Zend/zend_execute.c

1807 lines
56 KiB
C
Raw Normal View History

1999-04-07 18:10:10 +00:00
/*
+----------------------------------------------------------------------+
| Zend Engine |
+----------------------------------------------------------------------+
2014-01-03 03:08:10 +00:00
| Copyright (c) 1998-2014 Zend Technologies Ltd. (http://www.zend.com) |
1999-04-07 18:10:10 +00:00
+----------------------------------------------------------------------+
2001-12-11 15:16:21 +00:00
| 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: |
2001-12-11 15:16:21 +00:00
| http://www.zend.com/license/2_00.txt. |
1999-07-16 14:58:16 +00:00
| 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. |
1999-04-07 18:10:10 +00:00
+----------------------------------------------------------------------+
| Authors: Andi Gutmans <andi@zend.com> |
| Zeev Suraski <zeev@zend.com> |
+----------------------------------------------------------------------+
*/
/* $Id$ */
#define ZEND_INTENSIVE_DEBUGGING 0
1999-07-16 14:58:16 +00:00
1999-04-07 18:10:10 +00:00
#include <stdio.h>
#include <signal.h>
#include "zend.h"
#include "zend_compile.h"
#include "zend_execute.h"
#include "zend_API.h"
#include "zend_ptr_stack.h"
#include "zend_constants.h"
#include "zend_extensions.h"
2002-11-19 17:51:30 +00:00
#include "zend_ini.h"
#include "zend_exceptions.h"
#include "zend_interfaces.h"
#include "zend_closures.h"
#include "zend_generators.h"
#include "zend_vm.h"
2010-04-24 13:32:30 +00:00
#include "zend_dtrace.h"
#include "zend_inheritance.h"
/* Virtual current working directory support */
#include "zend_virtual_cwd.h"
#define _CONST_CODE 0
#define _TMP_CODE 1
#define _VAR_CODE 2
#define _UNUSED_CODE 3
#define _CV_CODE 4
typedef int (*incdec_t)(zval *);
1999-04-07 18:10:10 +00:00
#define get_zval_ptr(op_type, node, ex, should_free, type) _get_zval_ptr(op_type, node, ex, should_free, type TSRMLS_CC)
#define get_zval_ptr_deref(op_type, node, ex, should_free, type) _get_zval_ptr_deref(op_type, node, ex, should_free, type TSRMLS_CC)
#define get_zval_ptr_ptr(op_type, node, ex, should_free, type) _get_zval_ptr_ptr(op_type, node, ex, should_free, type TSRMLS_CC)
#define get_zval_ptr_ptr_undef(op_type, node, ex, should_free, type) _get_zval_ptr_ptr(op_type, node, ex, should_free, type TSRMLS_CC)
#define get_obj_zval_ptr(op_type, node, ex, should_free, type) _get_obj_zval_ptr(op_type, node, ex, should_free, type TSRMLS_CC)
#define get_obj_zval_ptr_ptr(op_type, node, ex, should_free, type) _get_obj_zval_ptr_ptr(op_type, node, ex, should_free, type TSRMLS_CC)
1999-04-07 18:10:10 +00:00
/* Prototypes */
static void zend_extension_statement_handler(const zend_extension *extension, zend_op_array *op_array TSRMLS_DC);
static void zend_extension_fcall_begin_handler(const zend_extension *extension, zend_op_array *op_array TSRMLS_DC);
static void zend_extension_fcall_end_handler(const zend_extension *extension, zend_op_array *op_array TSRMLS_DC);
1999-04-07 18:10:10 +00:00
#define RETURN_VALUE_USED(opline) (!((opline)->result_type & EXT_TYPE_UNUSED))
1999-12-21 15:55:46 +00:00
static ZEND_FUNCTION(pass)
{
}
static const zend_internal_function zend_pass_function = {
ZEND_INTERNAL_FUNCTION, /* type */
0, /* fn_flags */
NULL, /* name */
NULL, /* scope */
NULL, /* prototype */
0, /* num_args */
0, /* required_num_args */
NULL, /* arg_info */
ZEND_FN(pass), /* handler */
NULL /* module */
};
#undef zval_ptr_dtor
#define zval_ptr_dtor(zv) i_zval_ptr_dtor(zv ZEND_FILE_LINE_CC TSRMLS_CC)
2014-02-21 16:35:40 +00:00
#define PZVAL_LOCK(z) if (Z_REFCOUNTED_P(z)) Z_ADDREF_P((z))
#define SELECTIVE_PZVAL_LOCK(pzv, opline) if (RETURN_VALUE_USED(opline)) { PZVAL_LOCK(pzv); }
2014-08-27 15:10:29 +00:00
#define READY_TO_DESTROY(zv) \
(zv && Z_REFCOUNTED_P(zv) && Z_REFCOUNT_P(zv) == 1)
#define EXTRACT_ZVAL_PTR(zv) do { \
zval *__zv = (zv); \
if (Z_TYPE_P(__zv) == IS_INDIRECT) { \
ZVAL_COPY(__zv, Z_INDIRECT_P(__zv)); \
} \
} while (0)
2007-12-14 14:14:50 +00:00
#define FREE_OP(should_free) \
if (should_free.var) { \
2007-04-16 08:09:56 +00:00
if ((zend_uintptr_t)should_free.var & 1L) { \
zval_dtor((zval*)((zend_uintptr_t)should_free.var & ~1L)); \
} else { \
zval_ptr_dtor_nogc(should_free.var); \
} \
}
#define FREE_OP_IF_VAR(should_free) \
2007-04-16 08:09:56 +00:00
if (should_free.var != NULL && (((zend_uintptr_t)should_free.var & 1L) == 0)) { \
zval_ptr_dtor_nogc(should_free.var); \
}
#define FREE_OP_VAR_PTR(should_free) \
if (should_free.var) { \
zval_ptr_dtor_nogc(should_free.var); \
}
2007-04-16 08:09:56 +00:00
#define TMP_FREE(z) (zval*)(((zend_uintptr_t)(z)) | 1L)
2007-04-16 08:09:56 +00:00
#define IS_TMP_FREE(should_free) ((zend_uintptr_t)should_free.var & 1L)
/* End of zend_execute_locks.h */
2014-08-08 09:47:34 +00:00
#define CV_DEF_OF(i) (EX(func)->op_array.vars[i])
#define CTOR_CALL_BIT 0x1
#define CTOR_USED_BIT 0x2
#define IS_CTOR_CALL(ce) (((zend_uintptr_t)(ce)) & CTOR_CALL_BIT)
#define IS_CTOR_USED(ce) (((zend_uintptr_t)(ce)) & CTOR_USED_BIT)
#define ENCODE_CTOR(ce, used) \
((zend_class_entry*)(((zend_uintptr_t)(ce)) | CTOR_CALL_BIT | ((used) ? CTOR_USED_BIT : 0)))
#define DECODE_CTOR(ce) \
((zend_class_entry*)(((zend_uintptr_t)(ce)) & ~(CTOR_CALL_BIT|CTOR_USED_BIT)))
2012-12-05 09:23:37 +00:00
#undef EX
#define EX(element) execute_data->element
2014-08-25 17:28:33 +00:00
ZEND_API zval* zend_get_compiled_variable_value(const zend_execute_data *execute_data, uint32_t var)
{
return EX_VAR(var);
}
2014-08-25 17:28:33 +00:00
static zend_always_inline zval *_get_zval_ptr_tmp(uint32_t var, const zend_execute_data *execute_data, zend_free_op *should_free TSRMLS_DC)
2005-06-13 17:50:07 +00:00
{
zval *ret = EX_VAR(var);
should_free->var = ret;
ZEND_ASSERT(Z_TYPE_P(ret) != IS_REFERENCE);
return ret;
2005-06-13 17:50:07 +00:00
}
2014-08-25 17:28:33 +00:00
static zend_always_inline zval *_get_zval_ptr_var(uint32_t var, const zend_execute_data *execute_data, zend_free_op *should_free TSRMLS_DC)
{
zval *ret = EX_VAR(var);
should_free->var = ret;
return ret;
}
2014-08-25 17:28:33 +00:00
static zend_always_inline zval *_get_zval_ptr_var_deref(uint32_t var, const zend_execute_data *execute_data, zend_free_op *should_free TSRMLS_DC)
{
zval *ret = EX_VAR(var);
should_free->var = ret;
2014-03-27 09:39:09 +00:00
ZVAL_DEREF(ret);
return ret;
}
2014-08-25 17:28:33 +00:00
static zend_never_inline zval *_get_zval_cv_lookup(zval *ptr, uint32_t var, int type, const zend_execute_data *execute_data TSRMLS_DC)
{
zend_string *cv;
switch (type) {
case BP_VAR_R:
case BP_VAR_UNSET:
cv = CV_DEF_OF(EX_VAR_TO_NUM(var));
zend_error(E_NOTICE, "Undefined variable: %s", cv->val);
/* break missing intentionally */
case BP_VAR_IS:
ptr = &EG(uninitialized_zval);
break;
case BP_VAR_RW:
cv = CV_DEF_OF(EX_VAR_TO_NUM(var));
zend_error(E_NOTICE, "Undefined variable: %s", cv->val);
/* break missing intentionally */
case BP_VAR_W:
ZVAL_NULL(ptr);
break;
}
return ptr;
}
2014-08-25 17:28:33 +00:00
static zend_always_inline zval *_get_zval_cv_lookup_BP_VAR_R(zval *ptr, uint32_t var, const zend_execute_data *execute_data TSRMLS_DC)
{
zend_string *cv = CV_DEF_OF(EX_VAR_TO_NUM(var));
zend_error(E_NOTICE, "Undefined variable: %s", cv->val);
return &EG(uninitialized_zval);
}
2014-08-25 17:28:33 +00:00
static zend_always_inline zval *_get_zval_cv_lookup_BP_VAR_UNSET(zval *ptr, uint32_t var, const zend_execute_data *execute_data TSRMLS_DC)
{
zend_string *cv = CV_DEF_OF(EX_VAR_TO_NUM(var));
zend_error(E_NOTICE, "Undefined variable: %s", cv->val);
return &EG(uninitialized_zval);
}
2014-08-25 17:28:33 +00:00
static zend_always_inline zval *_get_zval_cv_lookup_BP_VAR_RW(zval *ptr, uint32_t var, const zend_execute_data *execute_data TSRMLS_DC)
{
zend_string *cv = CV_DEF_OF(EX_VAR_TO_NUM(var));
ZVAL_NULL(ptr);
zend_error(E_NOTICE, "Undefined variable: %s", cv->val);
return ptr;
}
2014-08-25 17:28:33 +00:00
static zend_always_inline zval *_get_zval_cv_lookup_BP_VAR_W(zval *ptr, uint32_t var, const zend_execute_data *execute_data TSRMLS_DC)
{
ZVAL_NULL(ptr);
return ptr;
}
2014-08-25 17:28:33 +00:00
static zend_always_inline zval *_get_zval_ptr_cv(const zend_execute_data *execute_data, uint32_t var, int type TSRMLS_DC)
{
zval *ret = EX_VAR(var);
if (UNEXPECTED(Z_TYPE_P(ret) == IS_UNDEF)) {
2014-08-08 09:47:34 +00:00
return _get_zval_cv_lookup(ret, var, type, execute_data TSRMLS_CC);
}
return ret;
}
2014-08-25 17:28:33 +00:00
static zend_always_inline zval *_get_zval_ptr_cv_deref(const zend_execute_data *execute_data, uint32_t var, int type TSRMLS_DC)
{
zval *ret = EX_VAR(var);
if (UNEXPECTED(Z_TYPE_P(ret) == IS_UNDEF)) {
2014-08-08 09:47:34 +00:00
return _get_zval_cv_lookup(ret, var, type, execute_data TSRMLS_CC);
}
2014-03-27 09:39:09 +00:00
ZVAL_DEREF(ret);
return ret;
}
2014-08-25 17:28:33 +00:00
static zend_always_inline zval *_get_zval_ptr_cv_BP_VAR_R(const zend_execute_data *execute_data, uint32_t var TSRMLS_DC)
{
zval *ret = EX_VAR(var);
if (UNEXPECTED(Z_TYPE_P(ret) == IS_UNDEF)) {
2014-08-08 09:47:34 +00:00
return _get_zval_cv_lookup_BP_VAR_R(ret, var, execute_data TSRMLS_CC);
}
return ret;
}
2014-08-25 17:28:33 +00:00
static zend_always_inline zval *_get_zval_ptr_cv_deref_BP_VAR_R(const zend_execute_data *execute_data, uint32_t var TSRMLS_DC)
{
zval *ret = EX_VAR(var);
if (UNEXPECTED(Z_TYPE_P(ret) == IS_UNDEF)) {
2014-08-08 09:47:34 +00:00
return _get_zval_cv_lookup_BP_VAR_R(ret, var, execute_data TSRMLS_CC);
}
2014-03-27 09:39:09 +00:00
ZVAL_DEREF(ret);
return ret;
}
2014-08-25 17:28:33 +00:00
static zend_always_inline zval *_get_zval_ptr_cv_BP_VAR_UNSET(const zend_execute_data *execute_data, uint32_t var TSRMLS_DC)
{
zval *ret = EX_VAR(var);
if (UNEXPECTED(Z_TYPE_P(ret) == IS_UNDEF)) {
2014-08-08 09:47:34 +00:00
return _get_zval_cv_lookup_BP_VAR_UNSET(ret, var, execute_data TSRMLS_CC);
}
return ret;
}
2014-08-25 17:28:33 +00:00
static zend_always_inline zval *_get_zval_ptr_cv_deref_BP_VAR_UNSET(const zend_execute_data *execute_data, uint32_t var TSRMLS_DC)
{
zval *ret = EX_VAR(var);
if (UNEXPECTED(Z_TYPE_P(ret) == IS_UNDEF)) {
2014-08-08 09:47:34 +00:00
return _get_zval_cv_lookup_BP_VAR_UNSET(ret, var, execute_data TSRMLS_CC);
}
2014-03-27 09:39:09 +00:00
ZVAL_DEREF(ret);
return ret;
}
2014-08-25 17:28:33 +00:00
static zend_always_inline zval *_get_zval_ptr_cv_BP_VAR_IS(const zend_execute_data *execute_data, uint32_t var TSRMLS_DC)
{
zval *ret = EX_VAR(var);
return ret;
}
2014-08-25 17:28:33 +00:00
static zend_always_inline zval *_get_zval_ptr_cv_deref_BP_VAR_IS(const zend_execute_data *execute_data, uint32_t var TSRMLS_DC)
{
zval *ret = EX_VAR(var);
2014-03-27 09:39:09 +00:00
ZVAL_DEREF(ret);
return ret;
}
2014-08-25 17:28:33 +00:00
static zend_always_inline zval *_get_zval_ptr_cv_BP_VAR_RW(const zend_execute_data *execute_data, uint32_t var TSRMLS_DC)
{
zval *ret = EX_VAR(var);
if (UNEXPECTED(Z_TYPE_P(ret) == IS_UNDEF)) {
2014-08-08 09:47:34 +00:00
return _get_zval_cv_lookup_BP_VAR_RW(ret, var, execute_data TSRMLS_CC);
}
return ret;
}
2014-08-25 17:28:33 +00:00
static zend_always_inline zval *_get_zval_ptr_cv_deref_BP_VAR_RW(const zend_execute_data *execute_data, uint32_t var TSRMLS_DC)
{
zval *ret = EX_VAR(var);
if (UNEXPECTED(Z_TYPE_P(ret) == IS_UNDEF)) {
2014-08-08 09:47:34 +00:00
return _get_zval_cv_lookup_BP_VAR_RW(ret, var, execute_data TSRMLS_CC);
}
2014-03-27 09:39:09 +00:00
ZVAL_DEREF(ret);
return ret;
}
2014-08-25 17:28:33 +00:00
static zend_always_inline zval *_get_zval_ptr_cv_BP_VAR_W(const zend_execute_data *execute_data, uint32_t var TSRMLS_DC)
{
zval *ret = EX_VAR(var);
if (Z_TYPE_P(ret) == IS_UNDEF) {
2014-08-08 09:47:34 +00:00
return _get_zval_cv_lookup_BP_VAR_W(ret, var, execute_data TSRMLS_CC);
}
return ret;
}
2014-08-25 17:28:33 +00:00
static zend_always_inline zval *_get_zval_ptr_cv_undef_BP_VAR_W(const zend_execute_data *execute_data, uint32_t var TSRMLS_DC)
2014-04-04 10:36:34 +00:00
{
return EX_VAR(var);
}
2014-08-25 17:28:33 +00:00
static zend_always_inline zval *_get_zval_ptr_cv_deref_BP_VAR_W(const zend_execute_data *execute_data, uint32_t var TSRMLS_DC)
{
zval *ret = EX_VAR(var);
if (Z_TYPE_P(ret) == IS_UNDEF) {
2014-08-08 09:47:34 +00:00
return _get_zval_cv_lookup_BP_VAR_W(ret, var, execute_data TSRMLS_CC);
}
2014-03-27 09:39:09 +00:00
ZVAL_DEREF(ret);
return ret;
}
static inline zval *_get_zval_ptr(int op_type, const znode_op *node, const zend_execute_data *execute_data, zend_free_op *should_free, int type TSRMLS_DC)
{
zval *ret;
switch (op_type) {
2005-06-13 17:50:07 +00:00
case IS_CONST:
should_free->var = NULL;
return node->zv;
2005-06-13 17:50:07 +00:00
break;
case IS_TMP_VAR:
ret = EX_VAR(node->var);
should_free->var = TMP_FREE(ret);
return ret;
2005-06-13 17:50:07 +00:00
break;
case IS_VAR:
return _get_zval_ptr_var(node->var, execute_data, should_free TSRMLS_CC);
2005-06-13 17:50:07 +00:00
break;
case IS_UNUSED:
should_free->var = NULL;
2005-06-13 17:50:07 +00:00
return NULL;
break;
case IS_CV:
2014-04-22 13:46:34 +00:00
default:
should_free->var = NULL;
return _get_zval_ptr_cv(execute_data, node->var, type TSRMLS_CC);
2005-06-13 17:50:07 +00:00
break;
}
return NULL;
}
static inline zval *_get_zval_ptr_deref(int op_type, const znode_op *node, const zend_execute_data *execute_data, zend_free_op *should_free, int type TSRMLS_DC)
{
zval *ret;
switch (op_type) {
case IS_CONST:
should_free->var = NULL;
return node->zv;
break;
case IS_TMP_VAR:
ret = EX_VAR(node->var);
should_free->var = TMP_FREE(ret);
return ret;
break;
case IS_VAR:
return _get_zval_ptr_var_deref(node->var, execute_data, should_free TSRMLS_CC);
break;
case IS_UNUSED:
should_free->var = NULL;
return NULL;
break;
case IS_CV:
2014-04-22 13:46:34 +00:00
default:
should_free->var = NULL;
return _get_zval_ptr_cv_deref(execute_data, node->var, type TSRMLS_CC);
break;
}
return NULL;
}
2014-08-25 17:28:33 +00:00
static zend_always_inline zval *_get_zval_ptr_ptr_var(uint32_t var, const zend_execute_data *execute_data, zend_free_op *should_free TSRMLS_DC)
{
zval *ret = EX_VAR(var);
2005-06-13 17:50:07 +00:00
if (EXPECTED(Z_TYPE_P(ret) == IS_INDIRECT)) {
should_free->var = NULL;
return Z_INDIRECT_P(ret);
2014-08-27 15:10:29 +00:00
} else if (!Z_REFCOUNTED_P(ret) || Z_REFCOUNT_P(ret) == 1) {
should_free->var = ret;
return ret;
} else {
2014-08-27 15:10:29 +00:00
Z_DELREF_P(ret);
should_free->var = NULL;
return ret;
}
}
static inline zval *_get_zval_ptr_ptr(int op_type, const znode_op *node, const zend_execute_data *execute_data, zend_free_op *should_free, int type TSRMLS_DC)
{
if (op_type == IS_CV) {
should_free->var = NULL;
return _get_zval_ptr_cv(execute_data, node->var, type TSRMLS_CC);
} else /* if (op_type == IS_VAR) */ {
ZEND_ASSERT(op_type == IS_VAR);
return _get_zval_ptr_ptr_var(node->var, execute_data, should_free TSRMLS_CC);
}
}
2009-03-18 14:15:28 +00:00
static zend_always_inline zval *_get_obj_zval_ptr_unused(TSRMLS_D)
{
if (EXPECTED(Z_OBJ(EG(This)) != NULL)) {
return &EG(This);
} else {
zend_error_noreturn(E_ERROR, "Using $this when not in object context");
return NULL;
}
}
static inline zval *_get_obj_zval_ptr(int op_type, znode_op *op, const zend_execute_data *execute_data, zend_free_op *should_free, int type TSRMLS_DC)
2005-06-13 17:50:07 +00:00
{
if (op_type == IS_UNUSED) {
if (EXPECTED(Z_OBJ(EG(This)) != NULL)) {
should_free->var = NULL;
return &EG(This);
2005-06-13 17:50:07 +00:00
} else {
zend_error_noreturn(E_ERROR, "Using $this when not in object context");
}
}
return get_zval_ptr(op_type, op, execute_data, should_free, type);
2005-06-13 17:50:07 +00:00
}
static inline zval *_get_obj_zval_ptr_ptr(int op_type, const znode_op *node, const zend_execute_data *execute_data, zend_free_op *should_free, int type TSRMLS_DC)
{
if (op_type == IS_UNUSED) {
if (EXPECTED(Z_OBJ(EG(This)) != NULL)) {
should_free->var = NULL;
return &EG(This);
} else {
zend_error_noreturn(E_ERROR, "Using $this when not in object context");
}
}
return get_zval_ptr_ptr(op_type, node, execute_data, should_free, type);
}
2014-04-03 12:53:30 +00:00
static inline void zend_assign_to_variable_reference(zval *variable_ptr, zval *value_ptr TSRMLS_DC)
{
2014-04-03 12:53:30 +00:00
if (EXPECTED(variable_ptr != value_ptr)) {
ZVAL_MAKE_REF(value_ptr);
2014-04-03 12:53:30 +00:00
Z_ADDREF_P(value_ptr);
zval_ptr_dtor(variable_ptr);
ZVAL_REF(variable_ptr, Z_REF_P(value_ptr));
} else {
ZVAL_MAKE_REF(variable_ptr);
}
}
/* this should modify object only if it's empty */
2014-04-03 22:52:53 +00:00
static inline zval* make_real_object(zval *object_ptr TSRMLS_DC)
2002-03-10 21:02:00 +00:00
{
2014-03-13 18:56:18 +00:00
zval *object = object_ptr;
2014-03-27 09:39:09 +00:00
ZVAL_DEREF(object);
2014-04-03 22:52:53 +00:00
if (UNEXPECTED(Z_TYPE_P(object) != IS_OBJECT)) {
if (Z_TYPE_P(object) == IS_NULL
|| Z_TYPE_P(object) == IS_FALSE
2014-08-25 17:24:55 +00:00
|| (Z_TYPE_P(object) == IS_STRING && Z_STRLEN_P(object) == 0)) {
zval_ptr_dtor_nogc(object);
2014-04-03 22:52:53 +00:00
object_init(object);
zend_error(E_WARNING, "Creating default object from empty value");
2014-03-13 18:56:18 +00:00
}
}
2014-04-03 22:52:53 +00:00
return object;
}
2014-08-25 17:24:55 +00:00
ZEND_API char * zend_verify_arg_class_kind(const zend_arg_info *cur_arg_info, zend_ulong fetch_type, char **class_name, zend_class_entry **pce TSRMLS_DC)
{
zend_string *key;
ALLOCA_FLAG(use_heap);
STR_ALLOCA_INIT(key, cur_arg_info->class_name, cur_arg_info->class_name_len, use_heap);
*pce = zend_fetch_class(key, (fetch_type | ZEND_FETCH_CLASS_AUTO | ZEND_FETCH_CLASS_NO_AUTOLOAD) TSRMLS_CC);
STR_ALLOCA_FREE(key, use_heap);
*class_name = (*pce) ? (*pce)->name->val : (char*)cur_arg_info->class_name;
if (*pce && (*pce)->ce_flags & ZEND_ACC_INTERFACE) {
return "implement interface ";
} else {
return "be an instance of ";
}
}
2014-08-25 17:28:33 +00:00
ZEND_API void zend_verify_arg_error(int error_type, const zend_function *zf, uint32_t arg_num, const char *need_msg, const char *need_kind, const char *given_msg, const char *given_kind, zval *arg TSRMLS_DC)
{
zend_execute_data *ptr = EG(current_execute_data)->prev_execute_data;
const char *fname = zf->common.function_name->val;
const char *fsep;
const char *fclass;
zval old_arg;
if (zf->common.scope) {
fsep = "::";
fclass = zf->common.scope->name->val;
} else {
fsep = "";
fclass = "";
}
if (arg && zf->common.type == ZEND_USER_FUNCTION) {
ZVAL_COPY_VALUE(&old_arg, arg);
ZVAL_UNDEF(arg);
}
if (zf->common.type == ZEND_USER_FUNCTION && ptr && ptr->func && ZEND_USER_CODE(ptr->func->common.type)) {
zend_error(error_type, "Argument %d passed to %s%s%s() must %s%s, %s%s given, called in %s on line %d and defined", arg_num, fclass, fsep, fname, need_msg, need_kind, given_msg, given_kind, ptr->func->op_array.filename->val, ptr->opline->lineno);
} else {
zend_error(error_type, "Argument %d passed to %s%s%s() must %s%s, %s%s given", arg_num, fclass, fsep, fname, need_msg, need_kind, given_msg, given_kind);
}
if (arg && zf->common.type == ZEND_USER_FUNCTION) {
ZVAL_COPY_VALUE(arg, &old_arg);
}
}
2014-08-25 17:28:33 +00:00
static void zend_verify_arg_type(zend_function *zf, uint32_t arg_num, zval *arg, zend_ulong fetch_type TSRMLS_DC)
{
zend_arg_info *cur_arg_info;
char *need_msg;
2006-05-21 18:10:31 +00:00
zend_class_entry *ce;
2014-04-04 10:36:34 +00:00
if (UNEXPECTED(!zf->common.arg_info)) {
return;
}
2014-04-04 10:36:34 +00:00
if (EXPECTED(arg_num <= zf->common.num_args)) {
cur_arg_info = &zf->common.arg_info[arg_num-1];
} else if (zf->common.fn_flags & ZEND_ACC_VARIADIC) {
cur_arg_info = &zf->common.arg_info[zf->common.num_args-1];
} else {
2014-04-04 10:36:34 +00:00
return;
}
if (cur_arg_info->class_name) {
char *class_name;
2014-03-27 09:39:09 +00:00
ZVAL_DEREF(arg);
if (Z_TYPE_P(arg) == IS_OBJECT) {
need_msg = zend_verify_arg_class_kind(cur_arg_info, fetch_type, &class_name, &ce TSRMLS_CC);
if (!ce || !instanceof_function(Z_OBJCE_P(arg), ce TSRMLS_CC)) {
zend_verify_arg_error(E_RECOVERABLE_ERROR, zf, arg_num, need_msg, class_name, "instance of ", Z_OBJCE_P(arg)->name->val, arg TSRMLS_CC);
2006-05-21 18:10:31 +00:00
}
} else if (Z_TYPE_P(arg) != IS_NULL || !cur_arg_info->allow_null) {
need_msg = zend_verify_arg_class_kind(cur_arg_info, fetch_type, &class_name, &ce TSRMLS_CC);
zend_verify_arg_error(E_RECOVERABLE_ERROR, zf, arg_num, need_msg, class_name, zend_zval_type_name(arg), "", arg TSRMLS_CC);
}
} else if (cur_arg_info->type_hint) {
2014-06-05 14:42:17 +00:00
if (cur_arg_info->type_hint == IS_ARRAY) {
ZVAL_DEREF(arg);
if (Z_TYPE_P(arg) != IS_ARRAY && (Z_TYPE_P(arg) != IS_NULL || !cur_arg_info->allow_null)) {
zend_verify_arg_error(E_RECOVERABLE_ERROR, zf, arg_num, "be of the type array", "", zend_zval_type_name(arg), "", arg TSRMLS_CC);
2014-06-05 14:42:17 +00:00
}
} else if (cur_arg_info->type_hint == IS_CALLABLE) {
if (!zend_is_callable(arg, IS_CALLABLE_CHECK_SILENT, NULL TSRMLS_CC) && (Z_TYPE_P(arg) != IS_NULL || !cur_arg_info->allow_null)) {
zend_verify_arg_error(E_RECOVERABLE_ERROR, zf, arg_num, "be callable", "", zend_zval_type_name(arg), "", arg TSRMLS_CC);
2014-06-05 14:42:17 +00:00
}
#if ZEND_DEBUG
} else {
zend_error(E_ERROR, "Unknown typehint");
#endif
2010-05-20 19:18:35 +00:00
}
}
2014-04-04 10:36:34 +00:00
}
2014-08-25 17:28:33 +00:00
static inline int zend_verify_missing_arg_type(zend_function *zf, uint32_t arg_num, zend_ulong fetch_type TSRMLS_DC)
2014-04-04 10:36:34 +00:00
{
zend_arg_info *cur_arg_info;
char *need_msg;
zend_class_entry *ce;
if (UNEXPECTED(!zf->common.arg_info)) {
return 1;
}
if (EXPECTED(arg_num <= zf->common.num_args)) {
cur_arg_info = &zf->common.arg_info[arg_num-1];
} else if (zf->common.fn_flags & ZEND_ACC_VARIADIC) {
cur_arg_info = &zf->common.arg_info[zf->common.num_args-1];
} else {
return 1;
}
if (cur_arg_info->class_name) {
char *class_name;
need_msg = zend_verify_arg_class_kind(cur_arg_info, fetch_type, &class_name, &ce TSRMLS_CC);
zend_verify_arg_error(E_RECOVERABLE_ERROR, zf, arg_num, need_msg, class_name, "none", "", NULL TSRMLS_CC);
2014-09-10 09:02:01 +00:00
return 0;
2014-04-04 10:36:34 +00:00
} else if (cur_arg_info->type_hint) {
2014-06-05 14:42:17 +00:00
if (cur_arg_info->type_hint == IS_ARRAY) {
zend_verify_arg_error(E_RECOVERABLE_ERROR, zf, arg_num, "be of the type array", "", "none", "", NULL TSRMLS_CC);
2014-06-05 14:42:17 +00:00
} else if (cur_arg_info->type_hint == IS_CALLABLE) {
zend_verify_arg_error(E_RECOVERABLE_ERROR, zf, arg_num, "be callable", "", "none", "", NULL TSRMLS_CC);
2014-06-05 14:42:17 +00:00
#if ZEND_DEBUG
} else {
zend_error(E_ERROR, "Unknown typehint");
#endif
2014-04-04 10:36:34 +00:00
}
2014-09-10 09:02:01 +00:00
return 0;
2014-04-04 10:36:34 +00:00
}
2014-09-10 09:02:01 +00:00
return 1;
2014-04-04 10:36:34 +00:00
}
2014-08-25 17:28:33 +00:00
static void zend_verify_missing_arg(zend_execute_data *execute_data, uint32_t arg_num TSRMLS_DC)
2014-04-04 10:36:34 +00:00
{
if (EXPECTED(!(EX(func)->common.fn_flags & ZEND_ACC_HAS_TYPE_HINTS)) ||
zend_verify_missing_arg_type(EX(func), arg_num, EX(opline)->extended_value TSRMLS_CC)) {
const char *class_name = EX(func)->common.scope ? EX(func)->common.scope->name->val : "";
const char *space = EX(func)->common.scope ? "::" : "";
const char *func_name = EX(func)->common.function_name ? EX(func)->common.function_name->val : "main";
2014-04-04 10:36:34 +00:00
zend_execute_data *ptr = EX(prev_execute_data);
if (ptr && ptr->func && ZEND_USER_CODE(ptr->func->common.type)) {
zend_error(E_WARNING, "Missing argument %u for %s%s%s(), called in %s on line %d and defined", arg_num, class_name, space, func_name, ptr->func->op_array.filename->val, ptr->opline->lineno);
2014-04-04 10:36:34 +00:00
} else {
zend_error(E_WARNING, "Missing argument %u for %s%s%s()", arg_num, class_name, space, func_name);
}
}
}
static inline void zend_assign_to_object(zval *retval, zval *object_ptr, zval *property_name, int value_type, const znode_op *value_op, const zend_execute_data *execute_data, int opcode, void **cache_slot TSRMLS_DC)
{
2007-12-14 14:14:50 +00:00
zend_free_op free_value;
zval *value = get_zval_ptr(value_type, value_op, execute_data, &free_value, BP_VAR_R);
zval tmp;
2014-02-27 20:21:12 +00:00
zval *object = object_ptr;
2014-03-27 09:39:09 +00:00
ZVAL_DEREF(object);
2014-09-22 09:18:49 +00:00
if (UNEXPECTED(Z_TYPE_P(object) != IS_OBJECT)) {
if (UNEXPECTED(object == &EG(error_zval))) {
if (retval) {
ZVAL_NULL(retval);
2007-12-14 14:14:50 +00:00
}
FREE_OP(free_value);
return;
}
2014-09-22 09:18:49 +00:00
if (EXPECTED(Z_TYPE_P(object) == IS_NULL ||
Z_TYPE_P(object) == IS_FALSE ||
2014-09-22 09:18:49 +00:00
(Z_TYPE_P(object) == IS_STRING && Z_STRLEN_P(object) == 0))) {
2014-07-29 10:34:43 +00:00
zend_object *obj;
zval_ptr_dtor(object);
object_init(object);
Z_ADDREF_P(object);
obj = Z_OBJ_P(object);
zend_error(E_WARNING, "Creating default object from empty value");
if (GC_REFCOUNT(obj) == 1) {
/* the enclosing container was deleted, obj is unreferenced */
if (retval) {
ZVAL_NULL(retval);
}
2014-07-29 10:34:43 +00:00
FREE_OP(free_value);
OBJ_RELEASE(obj);
return;
2014-04-15 11:40:40 +00:00
}
2014-07-29 10:34:43 +00:00
Z_DELREF_P(object);
2007-12-14 14:14:50 +00:00
} else {
zend_error(E_WARNING, "Attempt to assign property of non-object");
if (retval) {
ZVAL_NULL(retval);
2007-12-14 14:14:50 +00:00
}
FREE_OP(free_value);
return;
}
}
/* separate our value if necessary */
if (value_type == IS_TMP_VAR) {
2014-03-27 09:39:09 +00:00
ZVAL_COPY_VALUE(&tmp, value);
value = &tmp;
} else if (value_type == IS_CONST) {
if (UNEXPECTED(Z_OPT_COPYABLE_P(value))) {
ZVAL_COPY_VALUE(&tmp, value);
zval_copy_ctor_func(&tmp);
value = &tmp;
}
} else if (Z_REFCOUNTED_P(value)) {
Z_ADDREF_P(value);
}
if (opcode == ZEND_ASSIGN_OBJ) {
2007-12-14 14:14:50 +00:00
if (!Z_OBJ_HT_P(object)->write_property) {
zend_error(E_WARNING, "Attempt to assign property of non-object");
if (retval) {
ZVAL_NULL(retval);
2007-12-14 14:14:50 +00:00
}
if (value_type == IS_CONST) {
zval_ptr_dtor(value);
}
2007-12-14 14:14:50 +00:00
FREE_OP(free_value);
return;
}
Z_OBJ_HT_P(object)->write_property(object, property_name, value, cache_slot TSRMLS_CC);
} else {
/* Note: property_name in this case is really the array index! */
if (!Z_OBJ_HT_P(object)->write_dimension) {
zend_error_noreturn(E_ERROR, "Cannot use object as array");
}
Z_OBJ_HT_P(object)->write_dimension(object, property_name, value TSRMLS_CC);
}
if (retval && !EG(exception)) {
ZVAL_COPY(retval, value);
}
zval_ptr_dtor(value);
FREE_OP_IF_VAR(free_value);
}
static void zend_assign_to_string_offset(zval *str, zend_long offset, zval *value, int value_type, zval *result TSRMLS_DC)
2014-09-06 22:54:47 +00:00
{
2014-04-03 22:52:53 +00:00
zend_string *old_str;
1999-04-07 18:10:10 +00:00
2014-09-06 22:54:47 +00:00
if (offset < 0) {
zend_error(E_WARNING, "Illegal string offset: " ZEND_LONG_FMT, offset);
2014-08-25 17:24:55 +00:00
zend_string_release(Z_STR_P(str));
2014-04-03 22:52:53 +00:00
if (result) {
ZVAL_NULL(result);
}
return;
}
2014-04-03 22:52:53 +00:00
old_str = Z_STR_P(str);
if ((size_t)offset >= Z_STRLEN_P(str)) {
2014-09-06 22:54:47 +00:00
zend_long old_len = Z_STRLEN_P(str);
2014-08-25 17:24:55 +00:00
Z_STR_P(str) = zend_string_realloc(Z_STR_P(str), offset + 1, 0);
Z_TYPE_INFO_P(str) = IS_STRING_EX;
2014-02-28 13:39:08 +00:00
memset(Z_STRVAL_P(str) + old_len, ' ', offset - old_len);
Z_STRVAL_P(str)[offset+1] = 0;
} else if (!Z_REFCOUNTED_P(str)) {
2014-08-25 17:24:55 +00:00
Z_STR_P(str) = zend_string_init(Z_STRVAL_P(str), Z_STRLEN_P(str), 0);
Z_TYPE_INFO_P(str) = IS_STRING_EX;
}
1999-04-07 18:10:10 +00:00
if (Z_TYPE_P(value) != IS_STRING) {
zend_string *tmp = zval_get_string(value);
Z_STRVAL_P(str)[offset] = tmp->val[0];
2014-08-25 17:24:55 +00:00
zend_string_release(tmp);
} else {
2014-02-28 13:39:08 +00:00
Z_STRVAL_P(str)[offset] = Z_STRVAL_P(value)[0];
if (value_type == IS_TMP_VAR) {
/* we can safely free final_value here
* because separation is done only
* in case value_type == IS_VAR */
zval_dtor(value);
}
1999-04-07 18:10:10 +00:00
}
/*
* the value of an assignment to a string offset is undefined
T(result->u.var).var = &T->str_offset.str;
*/
2014-04-03 22:52:53 +00:00
2014-08-25 17:24:55 +00:00
zend_string_release(old_str);
2014-04-03 22:52:53 +00:00
if (result) {
zend_uchar c = (zend_uchar)Z_STRVAL_P(str)[offset];
if (CG(one_char_string)[c]) {
2014-08-25 17:28:33 +00:00
ZVAL_INTERNED_STR(result, CG(one_char_string)[c]);
2014-04-03 22:52:53 +00:00
} else {
2014-08-25 17:24:55 +00:00
ZVAL_NEW_STR(result, zend_string_init(Z_STRVAL_P(str) + offset, 1, 0));
2014-04-03 22:52:53 +00:00
}
}
2007-12-14 14:14:50 +00:00
}
1999-04-07 18:10:10 +00:00
2014-09-11 13:00:06 +00:00
static zend_always_inline zval* zend_assign_to_variable(zval *variable_ptr, zval *value, zend_uchar value_type TSRMLS_DC)
2007-12-14 14:14:50 +00:00
{
2014-09-11 13:00:06 +00:00
do {
if (UNEXPECTED(Z_REFCOUNTED_P(variable_ptr))) {
zend_refcounted *garbage;
2014-09-11 13:00:06 +00:00
if (Z_ISREF_P(variable_ptr)) {
variable_ptr = Z_REFVAL_P(variable_ptr);
if (EXPECTED(!Z_REFCOUNTED_P(variable_ptr))) {
break;
}
2014-04-03 22:52:53 +00:00
}
2014-09-11 13:00:06 +00:00
if (Z_TYPE_P(variable_ptr) == IS_OBJECT &&
UNEXPECTED(Z_OBJ_HANDLER_P(variable_ptr, set) != NULL)) {
Z_OBJ_HANDLER_P(variable_ptr, set)(variable_ptr, value TSRMLS_CC);
return variable_ptr;
2014-04-03 22:52:53 +00:00
}
2014-09-11 13:00:06 +00:00
if ((value_type & (IS_VAR|IS_CV)) && variable_ptr == value) {
return variable_ptr;
2014-04-03 22:52:53 +00:00
}
2014-03-19 13:00:28 +00:00
garbage = Z_COUNTED_P(variable_ptr);
2014-09-11 13:00:06 +00:00
if (GC_REFCOUNT(garbage) == 1) {
ZVAL_COPY_VALUE(variable_ptr, value);
if (value_type == IS_CONST) {
/* IS_CONST can't be IS_OBJECT, IS_RESOURCE or IS_REFERENCE */
if (UNEXPECTED(Z_OPT_COPYABLE_P(variable_ptr))) {
zval_copy_ctor_func(variable_ptr);
2014-06-11 11:11:29 +00:00
}
2014-09-11 13:00:06 +00:00
} else if (value_type != IS_TMP_VAR) {
if (UNEXPECTED(Z_OPT_REFCOUNTED_P(variable_ptr))) {
Z_ADDREF_P(variable_ptr);
2014-06-11 11:11:29 +00:00
}
}
2014-09-11 13:00:06 +00:00
_zval_dtor_func(garbage ZEND_FILE_LINE_CC);
return variable_ptr;
} else { /* we need to split */
GC_REFCOUNT(garbage)--;
/* optimized version of GC_ZVAL_CHECK_POSSIBLE_ROOT(variable_ptr) */
if ((Z_COLLECTABLE_P(variable_ptr)) &&
UNEXPECTED(!GC_INFO(garbage))) {
gc_possible_root(garbage TSRMLS_CC);
}
2010-08-11 15:34:06 +00:00
}
2014-09-11 13:00:06 +00:00
}
} while (0);
ZVAL_COPY_VALUE(variable_ptr, value);
if (value_type == IS_CONST) {
/* IS_CONST can't be IS_OBJECT, IS_RESOURCE or IS_REFERENCE */
if (UNEXPECTED(Z_OPT_COPYABLE_P(variable_ptr))) {
zval_copy_ctor_func(variable_ptr);
}
} else if (value_type != IS_TMP_VAR) {
if (UNEXPECTED(Z_OPT_REFCOUNTED_P(variable_ptr))) {
Z_ADDREF_P(variable_ptr);
}
}
return variable_ptr;
1999-04-07 18:10:10 +00:00
}
/* Utility Functions for Extensions */
static void zend_extension_statement_handler(const zend_extension *extension, zend_op_array *op_array TSRMLS_DC)
1999-04-07 18:10:10 +00:00
{
if (extension->statement_handler) {
extension->statement_handler(op_array);
}
}
static void zend_extension_fcall_begin_handler(const zend_extension *extension, zend_op_array *op_array TSRMLS_DC)
1999-04-07 18:10:10 +00:00
{
if (extension->fcall_begin_handler) {
extension->fcall_begin_handler(op_array);
}
}
static void zend_extension_fcall_end_handler(const zend_extension *extension, zend_op_array *op_array TSRMLS_DC)
1999-04-07 18:10:10 +00:00
{
if (extension->fcall_end_handler) {
extension->fcall_end_handler(op_array);
}
}
static zend_always_inline HashTable *zend_get_target_symbol_table(zend_execute_data *execute_data, int fetch_type TSRMLS_DC)
1999-04-07 18:10:10 +00:00
{
2014-04-07 20:38:54 +00:00
HashTable *ht;
if (EXPECTED(fetch_type == ZEND_FETCH_GLOBAL_LOCK) ||
EXPECTED(fetch_type == ZEND_FETCH_GLOBAL)) {
ht = &EG(symbol_table).ht;
} else if (EXPECTED(fetch_type == ZEND_FETCH_STATIC)) {
ZEND_ASSERT(EX(func)->op_array.static_variables != NULL);
ht = EX(func)->op_array.static_variables;
2014-04-07 20:38:54 +00:00
} else {
ZEND_ASSERT(fetch_type == ZEND_FETCH_LOCAL);
if (!EX(symbol_table)) {
2014-04-07 20:38:54 +00:00
zend_rebuild_symbol_table(TSRMLS_C);
}
ht = &EX(symbol_table)->ht;
1999-04-07 18:10:10 +00:00
}
2014-04-07 20:38:54 +00:00
return ht;
}
2014-04-04 21:56:51 +00:00
static zend_always_inline zval *zend_fetch_dimension_address_inner(HashTable *ht, const zval *dim, int dim_type, int type TSRMLS_DC)
1999-04-07 18:10:10 +00:00
{
zval *retval;
zend_string *offset_key;
2014-08-25 17:24:55 +00:00
zend_ulong hval;
1999-04-07 18:10:10 +00:00
2014-08-25 17:24:55 +00:00
if (EXPECTED(Z_TYPE_P(dim) == IS_LONG)) {
hval = Z_LVAL_P(dim);
2014-04-04 21:56:51 +00:00
num_index:
retval = zend_hash_index_find(ht, hval);
if (retval == NULL) {
switch (type) {
case BP_VAR_R:
2014-08-25 18:22:49 +00:00
zend_error(E_NOTICE,"Undefined offset: " ZEND_ULONG_FMT, hval);
2014-04-04 21:56:51 +00:00
/* break missing intentionally */
case BP_VAR_UNSET:
case BP_VAR_IS:
retval = &EG(uninitialized_zval);
break;
case BP_VAR_RW:
2014-08-25 18:22:49 +00:00
zend_error(E_NOTICE,"Undefined offset: " ZEND_ULONG_FMT, hval);
2014-04-04 21:56:51 +00:00
/* break missing intentionally */
case BP_VAR_W:
2014-05-26 20:38:58 +00:00
retval = zend_hash_index_add_new(ht, hval, &EG(uninitialized_zval));
2014-04-04 21:56:51 +00:00
break;
}
2014-04-04 21:56:51 +00:00
}
} else if (EXPECTED(Z_TYPE_P(dim) == IS_STRING)) {
offset_key = Z_STR_P(dim);
if (dim_type != IS_CONST) {
if (ZEND_HANDLE_NUMERIC(offset_key, hval)) {
goto num_index;
}
2014-04-04 21:56:51 +00:00
}
str_index:
retval = zend_hash_find(ht, offset_key);
if (retval) {
/* support for $GLOBALS[...] */
if (UNEXPECTED(Z_TYPE_P(retval) == IS_INDIRECT)) {
retval = Z_INDIRECT_P(retval);
if (UNEXPECTED(Z_TYPE_P(retval) == IS_UNDEF)) {
switch (type) {
case BP_VAR_R:
zend_error(E_NOTICE, "Undefined index: %s", offset_key->val);
/* break missing intentionally */
case BP_VAR_UNSET:
case BP_VAR_IS:
retval = &EG(uninitialized_zval);
break;
case BP_VAR_RW:
zend_error(E_NOTICE,"Undefined index: %s", offset_key->val);
/* break missing intentionally */
case BP_VAR_W:
ZVAL_NULL(retval);
break;
}
}
1999-04-07 18:10:10 +00:00
}
2014-04-04 21:56:51 +00:00
} else {
switch (type) {
case BP_VAR_R:
zend_error(E_NOTICE, "Undefined index: %s", offset_key->val);
/* break missing intentionally */
case BP_VAR_UNSET:
case BP_VAR_IS:
retval = &EG(uninitialized_zval);
break;
case BP_VAR_RW:
zend_error(E_NOTICE,"Undefined index: %s", offset_key->val);
/* break missing intentionally */
case BP_VAR_W:
retval = zend_hash_add_new(ht, offset_key, &EG(uninitialized_zval));
2014-04-04 21:56:51 +00:00
break;
1999-04-07 18:10:10 +00:00
}
2014-04-04 21:56:51 +00:00
}
} else {
switch (Z_TYPE_P(dim)) {
case IS_NULL:
offset_key = STR_EMPTY_ALLOC();
goto str_index;
case IS_DOUBLE:
2014-08-25 17:24:55 +00:00
hval = zend_dval_to_lval(Z_DVAL_P(dim));
2014-04-04 21:56:51 +00:00
goto num_index;
case IS_RESOURCE:
2014-08-24 00:35:34 +00:00
zend_error(E_STRICT, "Resource ID#%pd used as offset, casting to integer (%pd)", Z_RES_HANDLE_P(dim), Z_RES_HANDLE_P(dim));
2014-04-04 21:56:51 +00:00
hval = Z_RES_HANDLE_P(dim);
goto num_index;
case IS_FALSE:
hval = 0;
goto num_index;
case IS_TRUE:
hval = 1;
2014-04-04 21:56:51 +00:00
goto num_index;
default:
zend_error(E_WARNING, "Illegal offset type");
retval = (type == BP_VAR_W || type == BP_VAR_RW) ?
&EG(error_zval) : &EG(uninitialized_zval);
}
1999-04-07 18:10:10 +00:00
}
return retval;
}
static zend_always_inline zval *zend_fetch_dimension_address(zval *result, zval *container_ptr, zval *dim, int dim_type, int type, int is_ref, int allow_str_offset TSRMLS_DC)
1999-04-07 18:10:10 +00:00
{
zval *retval;
2014-02-24 20:17:13 +00:00
zval *container = container_ptr;
1999-04-07 18:10:10 +00:00
2014-03-27 09:39:09 +00:00
ZVAL_DEREF(container);
2014-04-04 21:56:51 +00:00
if (EXPECTED(Z_TYPE_P(container) == IS_ARRAY)) {
SEPARATE_ARRAY(container);
2007-11-20 11:01:28 +00:00
fetch_from_array:
2014-04-04 21:56:51 +00:00
if (dim == NULL) {
retval = zend_hash_next_index_insert(Z_ARRVAL_P(container), &EG(uninitialized_zval));
2014-09-22 09:18:49 +00:00
if (UNEXPECTED(retval == NULL)) {
2014-04-04 21:56:51 +00:00
zend_error(E_WARNING, "Cannot add element to the array as the next element is already occupied");
retval = &EG(error_zval);
}
2014-04-04 21:56:51 +00:00
} else {
retval = zend_fetch_dimension_address_inner(Z_ARRVAL_P(container), dim, dim_type, type TSRMLS_CC);
}
if (is_ref) {
ZVAL_MAKE_REF(retval);
Z_ADDREF_P(retval);
ZVAL_REF(result, Z_REF_P(retval));
2014-04-04 21:56:51 +00:00
} else {
ZVAL_INDIRECT(result, retval);
}
} else if (EXPECTED(Z_TYPE_P(container) == IS_STRING)) {
2014-08-25 17:24:55 +00:00
zend_long offset;
2014-08-25 17:24:55 +00:00
if (type != BP_VAR_UNSET && UNEXPECTED(Z_STRLEN_P(container) == 0)) {
2014-04-10 11:50:25 +00:00
zval_dtor(container);
2014-06-09 11:41:29 +00:00
convert_to_array:
ZVAL_NEW_ARR(container);
zend_hash_init(Z_ARRVAL_P(container), 8, NULL, ZVAL_PTR_DTOR, 0);
2014-04-04 21:56:51 +00:00
goto fetch_from_array;
}
2014-09-06 22:54:47 +00:00
2014-04-04 21:56:51 +00:00
if (dim == NULL) {
zend_error_noreturn(E_ERROR, "[] operator not supported for strings");
}
2007-11-20 11:01:28 +00:00
if (UNEXPECTED(Z_TYPE_P(dim) != IS_LONG)) {
switch(Z_TYPE_P(dim)) {
case IS_STRING:
if (IS_LONG == is_numeric_string(Z_STRVAL_P(dim), Z_STRLEN_P(dim), NULL, NULL, -1)) {
break;
}
if (type != BP_VAR_UNSET) {
zend_error(E_WARNING, "Illegal string offset '%s'", Z_STRVAL_P(dim));
}
break;
case IS_DOUBLE:
case IS_NULL:
case IS_FALSE:
case IS_TRUE:
zend_error(E_NOTICE, "String offset cast occurred");
break;
default:
zend_error(E_WARNING, "Illegal offset type");
break;
}
2014-04-04 21:56:51 +00:00
offset = zval_get_long(dim);
} else {
offset = Z_LVAL_P(dim);
}
2014-09-06 22:54:47 +00:00
if (allow_str_offset) {
if (Z_REFCOUNTED_P(container)) {
if (Z_REFCOUNT_P(container) > 1) {
Z_DELREF_P(container);
zval_copy_ctor_func(container);
}
Z_ADDREF_P(container);
}
ZVAL_LONG(result, offset);
return container; /* assignment to string offset */
} else {
ZVAL_INDIRECT(result, NULL); /* wrong string offset */
}
2014-04-04 21:56:51 +00:00
} else if (EXPECTED(Z_TYPE_P(container) == IS_OBJECT)) {
if (!Z_OBJ_HT_P(container)->read_dimension) {
zend_error_noreturn(E_ERROR, "Cannot use object as array");
} else {
retval = Z_OBJ_HT_P(container)->read_dimension(container, dim, type, result TSRMLS_CC);
2014-04-09 19:49:58 +00:00
if (UNEXPECTED(retval == &EG(uninitialized_zval))) {
zend_class_entry *ce = Z_OBJCE_P(container);
2014-04-09 19:49:58 +00:00
ZVAL_NULL(result);
zend_error(E_NOTICE, "Indirect modification of overloaded element of %s has no effect", ce->name->val);
2014-09-22 09:18:49 +00:00
} else if (EXPECTED(retval && Z_TYPE_P(retval) != IS_UNDEF)) {
2014-04-04 21:56:51 +00:00
if (!Z_ISREF_P(retval)) {
if (Z_REFCOUNTED_P(retval) &&
Z_REFCOUNT_P(retval) > 1) {
if (Z_TYPE_P(retval) != IS_OBJECT) {
Z_DELREF_P(retval);
ZVAL_DUP(result, retval);
retval = result;
} else {
2014-04-04 21:56:51 +00:00
ZVAL_COPY(result, retval);
retval = result;
}
}
2014-04-04 21:56:51 +00:00
if (Z_TYPE_P(retval) != IS_OBJECT) {
zend_class_entry *ce = Z_OBJCE_P(container);
zend_error(E_NOTICE, "Indirect modification of overloaded element of %s has no effect", ce->name->val);
}
}
if (result != retval) {
2014-04-09 19:49:58 +00:00
if (is_ref) {
ZVAL_MAKE_REF(retval);
Z_ADDREF_P(retval);
ZVAL_REF(result, Z_REF_P(retval));
2014-04-04 21:56:51 +00:00
} else {
ZVAL_INDIRECT(result, retval);
}
}
2007-12-14 14:14:50 +00:00
} else {
ZVAL_INDIRECT(result, &EG(error_zval));
2007-12-14 14:14:50 +00:00
}
2014-04-04 21:56:51 +00:00
}
} else if (EXPECTED(Z_TYPE_P(container) == IS_NULL)) {
2014-09-22 09:18:49 +00:00
if (UNEXPECTED(container == &EG(error_zval))) {
2014-04-04 21:56:51 +00:00
ZVAL_INDIRECT(result, &EG(error_zval));
} else if (type != BP_VAR_UNSET) {
goto convert_to_array;
} else {
/* for read-mode only */
ZVAL_NULL(result);
}
} else {
if (type != BP_VAR_UNSET &&
Z_TYPE_P(container) == IS_FALSE) {
2014-04-04 21:56:51 +00:00
goto convert_to_array;
}
if (type == BP_VAR_UNSET) {
zend_error(E_WARNING, "Cannot unset offset in a non-array variable");
ZVAL_NULL(result);
} else {
zend_error(E_WARNING, "Cannot use a scalar value as an array");
ZVAL_INDIRECT(result, &EG(error_zval));
}
2007-12-14 14:14:50 +00:00
}
return NULL; /* not an assignment to string offset */
2007-12-14 14:14:50 +00:00
}
2014-04-04 21:56:51 +00:00
static zend_never_inline void zend_fetch_dimension_address_W(zval *result, zval *container_ptr, zval *dim, int dim_type TSRMLS_DC)
2007-12-14 14:14:50 +00:00
{
zend_fetch_dimension_address(result, container_ptr, dim, dim_type, BP_VAR_W, 0, 0 TSRMLS_CC);
}
static zend_never_inline zval *zend_fetch_dimension_address_W_str(zval *result, zval *container_ptr, zval *dim, int dim_type TSRMLS_DC)
{
return zend_fetch_dimension_address(result, container_ptr, dim, dim_type, BP_VAR_W, 0, 1 TSRMLS_CC);
2014-04-04 21:56:51 +00:00
}
2007-12-14 14:14:50 +00:00
2014-04-04 21:56:51 +00:00
static zend_never_inline void zend_fetch_dimension_address_W_ref(zval *result, zval *container_ptr, zval *dim, int dim_type TSRMLS_DC)
{
zend_fetch_dimension_address(result, container_ptr, dim, dim_type, BP_VAR_W, 1, 0 TSRMLS_CC);
2014-04-04 21:56:51 +00:00
}
2007-12-14 14:14:50 +00:00
2014-04-04 21:56:51 +00:00
static zend_never_inline void zend_fetch_dimension_address_RW(zval *result, zval *container_ptr, zval *dim, int dim_type TSRMLS_DC)
{
zend_fetch_dimension_address(result, container_ptr, dim, dim_type, BP_VAR_RW, 0, 0 TSRMLS_CC);
2014-04-04 21:56:51 +00:00
}
2007-12-14 14:14:50 +00:00
2014-04-04 21:56:51 +00:00
static zend_never_inline void zend_fetch_dimension_address_UNSET(zval *result, zval *container_ptr, zval *dim, int dim_type TSRMLS_DC)
{
zend_fetch_dimension_address(result, container_ptr, dim, dim_type, BP_VAR_UNSET, 0, 0 TSRMLS_CC);
2014-04-04 21:56:51 +00:00
}
2007-12-14 14:14:50 +00:00
2014-04-04 21:56:51 +00:00
static zend_always_inline void zend_fetch_dimension_address_read(zval *result, zval *container, zval *dim, int dim_type, int type TSRMLS_DC)
{
zval *retval;
2014-04-04 21:56:51 +00:00
ZVAL_DEREF(container);
if (EXPECTED(Z_TYPE_P(container) == IS_ARRAY)) {
retval = zend_fetch_dimension_address_inner(Z_ARRVAL_P(container), dim, dim_type, type TSRMLS_CC);
ZVAL_COPY(result, retval);
} else if (EXPECTED(Z_TYPE_P(container) == IS_STRING)) {
2014-08-25 17:24:55 +00:00
zend_long offset;
2014-04-04 21:56:51 +00:00
2014-08-25 17:24:55 +00:00
if (UNEXPECTED(Z_TYPE_P(dim) != IS_LONG)) {
2014-04-04 21:56:51 +00:00
switch(Z_TYPE_P(dim)) {
2014-08-25 17:24:55 +00:00
/* case IS_LONG: */
2014-04-04 21:56:51 +00:00
case IS_STRING:
2014-08-25 17:24:55 +00:00
if (IS_LONG == is_numeric_string(Z_STRVAL_P(dim), Z_STRLEN_P(dim), NULL, NULL, -1)) {
2014-04-04 21:56:51 +00:00
break;
}
if (type != BP_VAR_IS) {
2014-04-04 21:56:51 +00:00
zend_error(E_WARNING, "Illegal string offset '%s'", Z_STRVAL_P(dim));
}
2014-04-04 21:56:51 +00:00
break;
case IS_DOUBLE:
case IS_NULL:
case IS_FALSE:
case IS_TRUE:
2014-04-04 21:56:51 +00:00
if (type != BP_VAR_IS) {
zend_error(E_NOTICE, "String offset cast occurred");
}
2014-04-04 21:56:51 +00:00
break;
default:
zend_error(E_WARNING, "Illegal offset type");
break;
2007-12-14 14:14:50 +00:00
}
2014-08-25 17:24:55 +00:00
offset = zval_get_long(dim);
} else {
2014-08-25 17:24:55 +00:00
offset = Z_LVAL_P(dim);
2014-04-04 21:56:51 +00:00
}
if (UNEXPECTED(offset < 0) || UNEXPECTED(Z_STRLEN_P(container) <= (size_t)offset)) {
2014-04-04 21:56:51 +00:00
if (type != BP_VAR_IS) {
2014-09-03 13:57:28 +00:00
zend_error(E_NOTICE, "Uninitialized string offset: %pd", offset);
2014-04-04 21:56:51 +00:00
}
ZVAL_EMPTY_STRING(result);
} else {
zend_uchar c = (zend_uchar)Z_STRVAL_P(container)[offset];
2014-04-04 21:56:51 +00:00
if (CG(one_char_string)[c]) {
2014-08-25 17:28:33 +00:00
ZVAL_INTERNED_STR(result, CG(one_char_string)[c]);
2007-12-14 14:14:50 +00:00
} else {
2014-08-25 17:24:55 +00:00
ZVAL_NEW_STR(result, zend_string_init(Z_STRVAL_P(container) + offset, 1, 0));
2014-04-04 21:56:51 +00:00
}
}
} else if (EXPECTED(Z_TYPE_P(container) == IS_OBJECT)) {
if (!Z_OBJ_HT_P(container)->read_dimension) {
zend_error_noreturn(E_ERROR, "Cannot use object as array");
} else {
retval = Z_OBJ_HT_P(container)->read_dimension(container, dim, type, result TSRMLS_CC);
if (result) {
if (retval) {
if (result != retval) {
ZVAL_COPY(result, retval);
2013-11-27 16:30:35 +00:00
}
2014-04-04 21:56:51 +00:00
} else {
ZVAL_NULL(result);
2007-12-14 14:14:50 +00:00
}
1999-04-07 18:10:10 +00:00
}
2014-04-04 21:56:51 +00:00
}
} else {
ZVAL_NULL(result);
1999-04-07 18:10:10 +00:00
}
}
2014-04-04 21:56:51 +00:00
static zend_never_inline void zend_fetch_dimension_address_read_R(zval *result, zval *container, zval *dim, int dim_type TSRMLS_DC)
{
zend_fetch_dimension_address_read(result, container, dim, dim_type, BP_VAR_R TSRMLS_CC);
}
static zend_never_inline void zend_fetch_dimension_address_read_IS(zval *result, zval *container, zval *dim, int dim_type TSRMLS_DC)
{
zend_fetch_dimension_address_read(result, container, dim, dim_type, BP_VAR_IS TSRMLS_CC);
}
ZEND_API void zend_fetch_dimension_by_zval(zval *result, zval *container, zval *dim TSRMLS_DC)
{
zend_fetch_dimension_address_read_R(result, container, dim, IS_TMP_VAR TSRMLS_CC);
}
static void zend_fetch_property_address(zval *result, zval *container_ptr, zval *prop_ptr, void **cache_slot, int type, int is_ref TSRMLS_DC)
1999-04-07 18:10:10 +00:00
{
2014-02-27 20:21:12 +00:00
zval *container = container_ptr;
2014-03-27 09:39:09 +00:00
ZVAL_DEREF(container);
2014-09-22 09:18:49 +00:00
if (UNEXPECTED(Z_TYPE_P(container) != IS_OBJECT)) {
if (UNEXPECTED(container == &EG(error_zval))) {
2014-02-25 19:39:25 +00:00
ZVAL_INDIRECT(result, &EG(error_zval));
2007-12-14 14:14:50 +00:00
return;
1999-04-07 18:10:10 +00:00
}
2007-12-14 14:14:50 +00:00
/* this should modify object only if it's empty */
if (type != BP_VAR_UNSET &&
2014-09-22 09:18:49 +00:00
EXPECTED((Z_TYPE_P(container) == IS_NULL ||
Z_TYPE_P(container) == IS_FALSE ||
2014-08-25 17:24:55 +00:00
(Z_TYPE_P(container) == IS_STRING && Z_STRLEN_P(container)==0)))) {
zval_ptr_dtor_nogc(container);
2007-12-14 14:14:50 +00:00
object_init(container);
} else {
zend_error(E_WARNING, "Attempt to modify property of non-object");
2014-02-25 19:39:25 +00:00
ZVAL_INDIRECT(result, &EG(error_zval));
2007-12-14 14:14:50 +00:00
return;
1999-04-07 18:10:10 +00:00
}
}
2014-09-22 09:18:49 +00:00
if (EXPECTED(Z_OBJ_HT_P(container)->get_property_ptr_ptr)) {
zval *ptr = Z_OBJ_HT_P(container)->get_property_ptr_ptr(container, prop_ptr, type, cache_slot TSRMLS_CC);
if (NULL == ptr) {
if (Z_OBJ_HT_P(container)->read_property &&
(ptr = Z_OBJ_HT_P(container)->read_property(container, prop_ptr, type, cache_slot, result TSRMLS_CC)) != NULL) {
if (ptr != result) {
if (is_ref && ptr != &EG(uninitialized_zval)) {
ZVAL_MAKE_REF(ptr);
Z_ADDREF_P(ptr);
ZVAL_REF(result, Z_REF_P(ptr));
} else {
ZVAL_INDIRECT(result, ptr);
}
}
} else {
2008-01-23 17:55:55 +00:00
zend_error_noreturn(E_ERROR, "Cannot access undefined property for object with overloaded property access");
}
2008-01-23 17:55:55 +00:00
} else {
if (is_ref) {
ZVAL_MAKE_REF(ptr);
Z_ADDREF_P(ptr);
ZVAL_REF(result, Z_REF_P(ptr));
} else {
ZVAL_INDIRECT(result, ptr);
}
}
2014-09-22 09:18:49 +00:00
} else if (EXPECTED(Z_OBJ_HT_P(container)->read_property)) {
zval *ptr = Z_OBJ_HT_P(container)->read_property(container, prop_ptr, type, cache_slot, result TSRMLS_CC);
if (ptr != result) {
if (is_ref && ptr != &EG(uninitialized_zval)) {
ZVAL_MAKE_REF(ptr);
Z_ADDREF_P(ptr);
ZVAL_REF(result, Z_REF_P(ptr));
} else {
ZVAL_INDIRECT(result, ptr);
}
}
} else {
zend_error(E_WARNING, "This object doesn't support property references");
2014-02-25 19:39:25 +00:00
ZVAL_INDIRECT(result, &EG(error_zval));
}
1999-04-07 18:10:10 +00:00
}
static inline zend_brk_cont_element* zend_brk_cont(int nest_levels, int array_offset, const zend_op_array *op_array, const zend_execute_data *execute_data TSRMLS_DC)
{
int original_nest_levels = nest_levels;
zend_brk_cont_element *jmp_to;
do {
if (array_offset==-1) {
zend_error_noreturn(E_ERROR, "Cannot break/continue %d level%s", original_nest_levels, (original_nest_levels == 1) ? "" : "s");
2004-09-09 16:47:22 +00:00
}
jmp_to = &op_array->brk_cont_array[array_offset];
if (nest_levels>1) {
zend_op *brk_opline = &op_array->opcodes[jmp_to->brk];
2004-09-09 16:47:22 +00:00
2014-06-05 14:42:17 +00:00
if (brk_opline->opcode == ZEND_SWITCH_FREE) {
if (!(brk_opline->extended_value & EXT_TYPE_FREE_ON_RETURN)) {
zval_ptr_dtor(EX_VAR(brk_opline->op1.var));
}
} else if (brk_opline->opcode == ZEND_FREE) {
if (!(brk_opline->extended_value & EXT_TYPE_FREE_ON_RETURN)) {
zval_dtor(EX_VAR(brk_opline->op1.var));
}
2004-09-09 16:47:22 +00:00
}
}
array_offset = jmp_to->parent;
} while (--nest_levels > 0);
return jmp_to;
}
#if ZEND_INTENSIVE_DEBUGGING
#define CHECK_SYMBOL_TABLES() \
zend_hash_apply(&EG(symbol_table), zend_check_symbol TSRMLS_CC); \
if (&EG(symbol_table)!=EX(symbol_table)) { \
zend_hash_apply(EX(symbol_table), zend_check_symbol TSRMLS_CC); \
}
static int zend_check_symbol(zval *pz TSRMLS_DC)
{
if (Z_TYPE_P(pz) == IS_INDIRECT) {
pz = Z_INDIRECT_P(pz);
}
if (Z_TYPE_P(pz) > 10) {
fprintf(stderr, "Warning! %x has invalid type!\n", *pz);
/* See http://support.microsoft.com/kb/190351 */
#ifdef PHP_WIN32
fflush(stderr);
#endif
} else if (Z_TYPE_P(pz) == IS_ARRAY) {
zend_hash_apply(Z_ARRVAL_P(pz), zend_check_symbol TSRMLS_CC);
} else if (Z_TYPE_P(pz) == IS_OBJECT) {
/* OBJ-TBI - doesn't support new object model! */
zend_hash_apply(Z_OBJPROP_P(pz), zend_check_symbol TSRMLS_CC);
}
return 0;
}
#else
#define CHECK_SYMBOL_TABLES()
#endif
ZEND_API opcode_handler_t *zend_opcode_handlers;
2001-08-30 15:26:30 +00:00
2014-07-07 11:50:44 +00:00
ZEND_API void execute_internal(zend_execute_data *execute_data, zval *return_value TSRMLS_DC)
{
2014-07-07 11:50:44 +00:00
execute_data->func->internal_function.handler(execute_data->num_args, return_value TSRMLS_CC);
}
void zend_clean_and_cache_symbol_table(zend_array *symbol_table TSRMLS_DC) /* {{{ */
{
if (EG(symtable_cache_ptr) >= EG(symtable_cache_limit)) {
zend_hash_destroy(&symbol_table->ht);
2014-04-25 07:54:10 +00:00
FREE_HASHTABLE(symbol_table);
} else {
/* clean before putting into the cache, since clean
could call dtors, which could use cached hash */
zend_hash_clean(&symbol_table->ht);
*(++EG(symtable_cache_ptr)) = symbol_table;
}
}
/* }}} */
static zend_always_inline void i_free_compiled_variables(zend_execute_data *execute_data TSRMLS_DC) /* {{{ */
{
if (EXPECTED(EX(func)->op_array.last_var > 0)) {
2014-06-16 09:25:23 +00:00
zval *cv = EX_VAR_NUM(0);
zval *end = cv + EX(func)->op_array.last_var;
2014-06-16 09:25:23 +00:00
do {
zval_ptr_dtor(cv);
cv++;
} while (cv != end);
}
2012-12-05 09:23:37 +00:00
}
/* }}} */
void zend_free_compiled_variables(zend_execute_data *execute_data TSRMLS_DC) /* {{{ */
2012-12-05 09:23:37 +00:00
{
i_free_compiled_variables(execute_data TSRMLS_CC);
}
/* }}} */
/*
* Stack Frame Layout (the whole stack frame is allocated at once)
* ==================
*
* +========================================+
* EG(current_execute_data) -> | zend_execute_data |
* +----------------------------------------+
* EX_CV_NUM(0) ---------> | VAR[0] = ARG[1] |
* | ... |
* | VAR[op_array->num_args-1] = ARG[N] |
* | ... |
* | VAR[op_array->last_var-1] |
* | VAR[op_array->last_var] = TMP[0] |
* | ... |
* | VAR[op_array->last_var+op_array->T-1] |
* | ARG[N+1] (extra_args) |
* | ... |
* +----------------------------------------+
*/
static zend_always_inline void i_init_func_execute_data(zend_execute_data *execute_data, zend_op_array *op_array, zval *return_value, vm_frame_kind frame_kind TSRMLS_DC) /* {{{ */
{
2014-09-17 12:17:58 +00:00
uint32_t first_extra_arg, num_args;
ZEND_ASSERT(EX(func) == (zend_function*)op_array);
ZEND_ASSERT(EX(object) == Z_OBJ(EG(This)));
2014-07-07 17:33:09 +00:00
EX(opline) = op_array->opcodes;
2014-09-17 12:17:58 +00:00
EX(call) = NULL;
EX(frame_kind) = frame_kind;
EX(return_value) = return_value;
EX(scope) = EG(scope);
2014-09-17 12:17:58 +00:00
EX(delayed_exception) = NULL;
ZVAL_UNDEF(&EX(old_error_reporting));
2014-09-17 12:17:58 +00:00
/* Handle arguments */
first_extra_arg = op_array->num_args;
if (UNEXPECTED((op_array->fn_flags & ZEND_ACC_VARIADIC) != 0)) {
first_extra_arg--;
}
2014-09-17 12:17:58 +00:00
num_args = EX(num_args);
if (UNEXPECTED(num_args > first_extra_arg)) {
zval *end, *src, *dst;
2014-09-17 12:17:58 +00:00
if (EXPECTED((op_array->fn_flags & ZEND_ACC_HAS_TYPE_HINTS) == 0)) {
/* Skip useless ZEND_RECV and ZEND_RECV_INIT opcodes */
EX(opline) += first_extra_arg;
}
2014-09-17 12:17:58 +00:00
/* move extra args into separate array after all CV and TMP vars */
end = EX_VAR_NUM(first_extra_arg - 1);
src = end + (num_args - first_extra_arg);
dst = src + (op_array->last_var + op_array->T - first_extra_arg);
if (EXPECTED(src != dst)) {
do {
2014-09-17 12:17:58 +00:00
ZVAL_COPY_VALUE(dst, src);
ZVAL_UNDEF(src);
src--;
dst--;
} while (src != end);
}
2014-09-17 12:17:58 +00:00
} else if (EXPECTED((op_array->fn_flags & ZEND_ACC_HAS_TYPE_HINTS) == 0)) {
/* Skip useless ZEND_RECV and ZEND_RECV_INIT opcodes */
EX(opline) += num_args;
}
/* Initialize CV variables (skip arguments) */
if (EXPECTED(num_args < op_array->last_var)) {
zval *var = EX_VAR_NUM(num_args);
zval *end = EX_VAR_NUM(op_array->last_var);
do {
ZVAL_UNDEF(var);
var++;
} while (var != end);
}
if (op_array->this_var != -1 && EX(object)) {
ZVAL_OBJ(EX_VAR(op_array->this_var), EX(object));
GC_REFCOUNT(EX(object))++;
}
if (!op_array->run_time_cache && op_array->last_cache_slot) {
2014-09-17 12:17:58 +00:00
op_array->run_time_cache = zend_arena_calloc(&CG(arena), op_array->last_cache_slot, sizeof(void*));
}
EX(run_time_cache) = op_array->run_time_cache;
EG(current_execute_data) = execute_data;
}
2014-07-08 09:53:13 +00:00
/* }}} */
static zend_always_inline void i_init_code_execute_data(zend_execute_data *execute_data, zend_op_array *op_array, zval *return_value, vm_frame_kind frame_kind TSRMLS_DC) /* {{{ */
{
ZEND_ASSERT(EX(func) == (zend_function*)op_array);
ZEND_ASSERT(EX(object) == Z_OBJ(EG(This)));
EX(opline) = op_array->opcodes;
2014-09-17 12:17:58 +00:00
EX(call) = NULL;
EX(frame_kind) = frame_kind;
EX(return_value) = return_value;
EX(scope) = EG(scope);
2014-09-17 12:17:58 +00:00
EX(delayed_exception) = NULL;
ZVAL_UNDEF(&EX(old_error_reporting));
zend_attach_symbol_table(execute_data);
if (!op_array->run_time_cache && op_array->last_cache_slot) {
2014-09-17 12:17:58 +00:00
op_array->run_time_cache = ecalloc(op_array->last_cache_slot, sizeof(void*));
}
EX(run_time_cache) = op_array->run_time_cache;
EG(current_execute_data) = execute_data;
}
2014-07-08 09:53:13 +00:00
/* }}} */
static zend_always_inline void i_init_execute_data(zend_execute_data *execute_data, zend_op_array *op_array, zval *return_value, vm_frame_kind frame_kind TSRMLS_DC) /* {{{ */
{
ZEND_ASSERT(EX(func) == (zend_function*)op_array);
ZEND_ASSERT(EX(object) == Z_OBJ(EG(This)));
EX(opline) = op_array->opcodes;
2014-09-17 12:17:58 +00:00
EX(call) = NULL;
EX(frame_kind) = frame_kind;
EX(return_value) = return_value;
EX(scope) = EG(scope);
2014-09-17 12:17:58 +00:00
EX(delayed_exception) = NULL;
ZVAL_UNDEF(&EX(old_error_reporting));
if (UNEXPECTED(EX(symbol_table) != NULL)) {
2014-04-18 09:46:36 +00:00
zend_attach_symbol_table(execute_data);
} else {
2014-09-17 12:17:58 +00:00
uint32_t first_extra_arg, num_args;
2014-09-17 12:17:58 +00:00
/* Handle arguments */
first_extra_arg = op_array->num_args;
if (UNEXPECTED((op_array->fn_flags & ZEND_ACC_VARIADIC) != 0)) {
first_extra_arg--;
}
2014-09-17 12:17:58 +00:00
num_args = EX(num_args);
if (UNEXPECTED(num_args > first_extra_arg)) {
zval *end, *src, *dst;
2014-09-17 12:17:58 +00:00
if (EXPECTED((op_array->fn_flags & ZEND_ACC_HAS_TYPE_HINTS) == 0)) {
/* Skip useless ZEND_RECV and ZEND_RECV_INIT opcodes */
EX(opline) += first_extra_arg;
}
2014-09-17 12:17:58 +00:00
/* move extra args into separate array after all CV and TMP vars */
end = EX_VAR_NUM(first_extra_arg - 1);
src = end + (num_args - first_extra_arg);
dst = src + (op_array->last_var + op_array->T - first_extra_arg);
if (EXPECTED(src != dst)) {
do {
2014-09-17 12:17:58 +00:00
ZVAL_COPY_VALUE(dst, src);
ZVAL_UNDEF(src);
src--;
dst--;
} while (src != end);
}
2014-09-17 12:17:58 +00:00
} else if (EXPECTED((op_array->fn_flags & ZEND_ACC_HAS_TYPE_HINTS) == 0)) {
/* Skip useless ZEND_RECV and ZEND_RECV_INIT opcodes */
EX(opline) += num_args;
}
/* Initialize CV variables (skip arguments) */
if (EXPECTED(num_args < op_array->last_var)) {
zval *var = EX_VAR_NUM(num_args);
zval *end = EX_VAR_NUM(op_array->last_var);
do {
ZVAL_UNDEF(var);
var++;
} while (var != end);
}
if (op_array->this_var != -1 && EX(object)) {
ZVAL_OBJ(EX_VAR(op_array->this_var), EX(object));
GC_REFCOUNT(EX(object))++;
}
}
if (!op_array->run_time_cache && op_array->last_cache_slot) {
if (op_array->function_name) {
op_array->run_time_cache = zend_arena_calloc(&CG(arena), op_array->last_cache_slot, sizeof(void*));
} else {
op_array->run_time_cache = ecalloc(op_array->last_cache_slot, sizeof(void*));
}
}
EX(run_time_cache) = op_array->run_time_cache;
EG(current_execute_data) = execute_data;
}
/* }}} */
2014-07-07 11:50:44 +00:00
ZEND_API zend_execute_data *zend_create_generator_execute_data(zend_execute_data *call, zend_op_array *op_array, zval *return_value TSRMLS_DC) /* {{{ */
{
/*
* Normally the execute_data is allocated on the VM stack (because it does
* not actually do any allocation and thus is faster). For generators
* though this behavior would be suboptimal, because the (rather large)
* structure would have to be copied back and forth every time execution is
* suspended or resumed. That's why for generators the execution context
* is allocated using a separate VM stack, thus allowing to save and
* restore it simply by replacing a pointer.
*/
zend_execute_data *execute_data;
2014-08-25 17:28:33 +00:00
uint32_t num_args = call->num_args;
EG(argument_stack) = zend_vm_stack_new_page(
MAX(ZEND_VM_STACK_PAGE_SIZE,
ZEND_CALL_FRAME_SLOT + MAX(op_array->last_var + op_array->T, num_args)));
EG(argument_stack)->prev = NULL;
execute_data = zend_vm_stack_push_call_frame(
(zend_function*)op_array,
num_args,
2014-07-07 11:50:44 +00:00
call->flags,
call->called_scope,
call->object,
NULL TSRMLS_CC);
EX(num_args) = num_args;
/* copy arguments */
if (num_args > 0) {
2014-07-07 11:50:44 +00:00
zval *arg_src = ZEND_CALL_ARG(call, 1);
zval *arg_dst = ZEND_CALL_ARG(execute_data, 1);
2014-09-15 10:12:18 +00:00
uint32_t i;
for (i = 0; i < num_args; i++) {
ZVAL_COPY_VALUE(arg_dst + i, arg_src + i);
}
}
EX(symbol_table) = NULL;
i_init_func_execute_data(execute_data, op_array, return_value, VM_FRAME_TOP_FUNCTION TSRMLS_CC);
return execute_data;
}
/* }}} */
2014-07-07 11:50:44 +00:00
ZEND_API void zend_init_execute_data(zend_execute_data *execute_data, zend_op_array *op_array, zval *return_value, vm_frame_kind frame_kind TSRMLS_DC) /* {{{ */
2012-12-05 09:23:37 +00:00
{
EX(prev_execute_data) = EG(current_execute_data);
i_init_execute_data(execute_data, op_array, return_value, frame_kind TSRMLS_CC);
2012-12-05 09:23:37 +00:00
}
/* }}} */
static zend_always_inline zend_bool zend_is_by_ref_func_arg_fetch(const zend_op *opline, zend_execute_data *call TSRMLS_DC) /* {{{ */
{
2014-08-25 17:28:33 +00:00
uint32_t arg_num = opline->extended_value & ZEND_FETCH_ARG_MASK;
return ARG_SHOULD_BE_SENT_BY_REF(call->func, arg_num);
}
/* }}} */
2014-08-25 17:28:33 +00:00
static zend_execute_data *zend_vm_stack_copy_call_frame(zend_execute_data *call, uint32_t passed_args, uint32_t additional_args TSRMLS_DC) /* {{{ */
{
zend_execute_data *new_call;
int used_stack = (EG(argument_stack)->top - (zval*)call) + additional_args;
/* copy call frame into new stack segment */
zend_vm_stack_extend(used_stack TSRMLS_CC);
new_call = (zend_execute_data*)EG(argument_stack)->top;
EG(argument_stack)->top += used_stack;
*new_call = *call;
if (passed_args) {
zval *src = ZEND_CALL_ARG(call, 1);
zval *dst = ZEND_CALL_ARG(new_call, 1);
do {
ZVAL_COPY_VALUE(dst, src);
passed_args--;
src++;
dst++;
} while (passed_args);
}
/* delete old call_frame from previous stack segment */
EG(argument_stack)->prev->top = (zval*)call;
/* delete previous stack segment if it becames empty */
if (UNEXPECTED(EG(argument_stack)->prev->top == ZEND_VM_STACK_ELEMETS(EG(argument_stack)->prev))) {
zend_vm_stack r = EG(argument_stack)->prev;
EG(argument_stack)->prev = r->prev;
efree(r);
}
return new_call;
}
/* }}} */
2014-08-25 17:28:33 +00:00
static zend_always_inline void zend_vm_stack_extend_call_frame(zend_execute_data **call, uint32_t passed_args, uint32_t additional_args TSRMLS_DC) /* {{{ */
{
if (EXPECTED(EG(argument_stack)->end - EG(argument_stack)->top > additional_args)) {
EG(argument_stack)->top += additional_args;
} else {
*call = zend_vm_stack_copy_call_frame(*call, passed_args, additional_args TSRMLS_CC);
}
}
/* }}} */
2012-12-05 09:23:37 +00:00
#define ZEND_VM_NEXT_OPCODE() \
CHECK_SYMBOL_TABLES() \
ZEND_VM_INC_OPCODE(); \
ZEND_VM_CONTINUE()
#define ZEND_VM_SET_OPCODE(new_op) \
CHECK_SYMBOL_TABLES() \
OPLINE = new_op
#define ZEND_VM_SET_RELATIVE_OPCODE(opline, offset) \
CHECK_SYMBOL_TABLES() \
OPLINE = ((zend_op*)(((char*)opline)+(offset)))
2012-12-05 09:23:37 +00:00
#define ZEND_VM_JMP(new_op) \
if (EXPECTED(!EG(exception))) { \
ZEND_VM_SET_OPCODE(new_op); \
} else { \
LOAD_OPLINE(); \
} \
ZEND_VM_CONTINUE()
#define ZEND_VM_INC_OPCODE() \
OPLINE++
#ifdef __GNUC__
# define ZEND_VM_GUARD(name) __asm__("#" #name)
#else
# define ZEND_VM_GUARD(name)
#endif
#include "zend_vm_execute.h"
ZEND_API int zend_set_user_opcode_handler(zend_uchar opcode, user_opcode_handler_t handler)
{
if (opcode != ZEND_USER_OPCODE) {
if (handler == NULL) {
/* restore the original handler */
zend_user_opcodes[opcode] = opcode;
} else {
zend_user_opcodes[opcode] = ZEND_USER_OPCODE;
}
zend_user_opcode_handlers[opcode] = handler;
return SUCCESS;
}
return FAILURE;
}
ZEND_API user_opcode_handler_t zend_get_user_opcode_handler(zend_uchar opcode)
{
return zend_user_opcode_handlers[opcode];
}
ZEND_API zval *zend_get_zval_ptr(int op_type, const znode_op *node, const zend_execute_data *execute_data, zend_free_op *should_free, int type TSRMLS_DC) {
return get_zval_ptr(op_type, node, execute_data, should_free, type);
}
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* indent-tabs-mode: t
* End:
*/