1999-04-07 18:10:10 +00:00
|
|
|
/*
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| Zend Engine |
|
|
|
|
+----------------------------------------------------------------------+
|
2007-01-01 09:36:18 +00:00
|
|
|
| Copyright (c) 1998-2007 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, |
|
1999-07-16 14:58:16 +00:00
|
|
|
| that is bundled with this package in the file LICENSE, and is |
|
2003-06-10 20:04:29 +00:00
|
|
|
| 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> |
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
*/
|
|
|
|
|
2003-02-01 01:49:15 +00:00
|
|
|
/* $Id$ */
|
1999-07-16 14:58:16 +00:00
|
|
|
|
1999-04-07 18:10:10 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "zend.h"
|
|
|
|
#include "zend_alloc.h"
|
|
|
|
#include "zend_compile.h"
|
|
|
|
#include "zend_extensions.h"
|
|
|
|
#include "zend_API.h"
|
|
|
|
|
2004-09-23 21:43:32 +00:00
|
|
|
#include "zend_vm.h"
|
|
|
|
|
2001-07-31 04:53:54 +00:00
|
|
|
static void zend_extension_op_array_ctor_handler(zend_extension *extension, zend_op_array *op_array TSRMLS_DC)
|
1999-04-07 18:10:10 +00:00
|
|
|
{
|
|
|
|
if (extension->op_array_ctor) {
|
2000-04-29 11:55:20 +00:00
|
|
|
extension->op_array_ctor(op_array);
|
1999-04-07 18:10:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-07-31 04:53:54 +00:00
|
|
|
static void zend_extension_op_array_dtor_handler(zend_extension *extension, zend_op_array *op_array TSRMLS_DC)
|
1999-04-07 18:10:10 +00:00
|
|
|
{
|
|
|
|
if (extension->op_array_dtor) {
|
2000-04-29 11:55:20 +00:00
|
|
|
extension->op_array_dtor(op_array);
|
1999-04-07 18:10:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void op_array_alloc_ops(zend_op_array *op_array)
|
|
|
|
{
|
|
|
|
op_array->opcodes = erealloc(op_array->opcodes, (op_array->size)*sizeof(zend_op));
|
|
|
|
}
|
|
|
|
|
2002-04-23 18:06:54 +00:00
|
|
|
void init_op_array(zend_op_array *op_array, zend_uchar type, int initial_ops_size TSRMLS_DC)
|
1999-04-07 18:10:10 +00:00
|
|
|
{
|
2000-04-29 01:30:17 +00:00
|
|
|
op_array->type = type;
|
2001-07-15 14:08:58 +00:00
|
|
|
|
|
|
|
op_array->backpatch_count = 0;
|
|
|
|
if (CG(interactive)) {
|
|
|
|
/* We must avoid a realloc() on the op_array in interactive mode, since pointers to constants
|
|
|
|
* will become invalid
|
|
|
|
*/
|
|
|
|
initial_ops_size = 8192;
|
1999-04-07 18:10:10 +00:00
|
|
|
}
|
|
|
|
|
2000-03-26 16:00:35 +00:00
|
|
|
op_array->refcount = (zend_uint *) emalloc(sizeof(zend_uint));
|
1999-04-07 18:10:10 +00:00
|
|
|
*op_array->refcount = 1;
|
|
|
|
op_array->size = initial_ops_size;
|
|
|
|
op_array->last = 0;
|
|
|
|
op_array->opcodes = NULL;
|
|
|
|
op_array_alloc_ops(op_array);
|
|
|
|
|
2004-10-04 19:54:35 +00:00
|
|
|
op_array->size_var = 0; /* FIXME:??? */
|
|
|
|
op_array->last_var = 0;
|
|
|
|
op_array->vars = NULL;
|
|
|
|
|
1999-04-07 18:10:10 +00:00
|
|
|
op_array->T = 0;
|
|
|
|
|
|
|
|
op_array->function_name = NULL;
|
2001-07-28 10:51:54 +00:00
|
|
|
op_array->filename = zend_get_compiled_filename(TSRMLS_C);
|
2004-02-20 06:59:37 +00:00
|
|
|
op_array->doc_comment = NULL;
|
|
|
|
op_array->doc_comment_len = 0;
|
1999-04-07 18:10:10 +00:00
|
|
|
|
ntroduce infrastructure for supplying information about arguments,
including:
- Whether or not to pass by ref (replaces the old arg_types, with arg_info)
- Argument name (for future use, maybe introspection)
- Class/Interface name (for type hints)
- If a class/interface name is available, whether to allow a null instance
Both user and builtin functions share the same data structures.
To declare a builtin function that expects its first arg to be an instance
of class 'Person', its second argument as a regular arg, and its third by
reference, use:
ZEND_BEGIN_ARG_INFO(my_func_arg_info, 0)
ZEND_ARG_OBJ_INFO(0, someone, Person, 1)
ZEND_ARG_PASS_INFO(0)
ZEND_ARG_PASS_INFO(1)
ZEND_END_ARG_INFO();
and use my_func_arg_info as the arg_info parameter to the ZEND_FE() family
of macros.
The first arg to each ZEND_ARG_*() macro is whether or not to pass by ref.
The boolean arg to ZEND_BEGIN_ARG_INFO() tells the engine whether to treat
the arguments for which there's no explicit information as pass by reference
or not.
The boolean argument to ZEND_ARG_OBJ_INFO() (4th arg) is whether or not to allownull values.
2003-08-03 17:40:44 +00:00
|
|
|
op_array->arg_info = NULL;
|
|
|
|
op_array->num_args = 0;
|
2004-02-25 09:25:37 +00:00
|
|
|
op_array->required_num_args = 0;
|
1999-04-07 18:10:10 +00:00
|
|
|
|
2002-03-01 14:04:51 +00:00
|
|
|
op_array->scope = NULL;
|
|
|
|
|
1999-04-07 18:10:10 +00:00
|
|
|
op_array->brk_cont_array = NULL;
|
2004-02-03 12:17:09 +00:00
|
|
|
op_array->try_catch_array = NULL;
|
1999-04-07 18:10:10 +00:00
|
|
|
op_array->last_brk_cont = 0;
|
|
|
|
op_array->current_brk_cont = -1;
|
|
|
|
|
|
|
|
op_array->static_variables = NULL;
|
2004-02-03 12:17:09 +00:00
|
|
|
op_array->last_try_catch = 0;
|
1999-04-07 18:10:10 +00:00
|
|
|
|
1999-12-15 20:15:32 +00:00
|
|
|
op_array->return_reference = 0;
|
2000-04-29 02:56:44 +00:00
|
|
|
op_array->done_pass_two = 0;
|
1999-12-15 20:15:32 +00:00
|
|
|
|
2002-03-15 15:09:46 +00:00
|
|
|
op_array->uses_this = 0;
|
|
|
|
|
2001-07-15 14:08:58 +00:00
|
|
|
op_array->start_op = NULL;
|
|
|
|
|
2001-07-31 04:53:54 +00:00
|
|
|
zend_llist_apply_with_argument(&zend_extensions, (llist_apply_with_arg_func_t) zend_extension_op_array_ctor_handler, op_array TSRMLS_CC);
|
1999-04-07 18:10:10 +00:00
|
|
|
}
|
|
|
|
|
2003-03-26 07:44:11 +00:00
|
|
|
ZEND_API void destroy_zend_function(zend_function *function TSRMLS_DC)
|
1999-04-07 18:10:10 +00:00
|
|
|
{
|
|
|
|
switch (function->type) {
|
|
|
|
case ZEND_USER_FUNCTION:
|
2003-03-26 07:44:11 +00:00
|
|
|
destroy_op_array((zend_op_array *) function TSRMLS_CC);
|
1999-04-07 18:10:10 +00:00
|
|
|
break;
|
|
|
|
case ZEND_INTERNAL_FUNCTION:
|
|
|
|
/* do nothing */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-06-06 08:37:12 +00:00
|
|
|
ZEND_API void zend_function_dtor(zend_function *function)
|
|
|
|
{
|
|
|
|
TSRMLS_FETCH();
|
|
|
|
|
|
|
|
destroy_zend_function(function TSRMLS_CC);
|
|
|
|
}
|
|
|
|
|
2003-01-29 17:54:48 +00:00
|
|
|
static void zend_cleanup_op_array_data(zend_op_array *op_array)
|
|
|
|
{
|
|
|
|
if (op_array->static_variables) {
|
|
|
|
zend_hash_clean(op_array->static_variables);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ZEND_API int zend_cleanup_function_data(zend_function *function TSRMLS_DC)
|
|
|
|
{
|
2003-06-30 20:22:35 +00:00
|
|
|
if (function->type == ZEND_USER_FUNCTION) {
|
2003-01-29 17:54:48 +00:00
|
|
|
zend_cleanup_op_array_data((zend_op_array *) function);
|
2006-03-13 11:13:42 +00:00
|
|
|
return ZEND_HASH_APPLY_KEEP;
|
|
|
|
} else {
|
|
|
|
return ZEND_HASH_APPLY_STOP;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ZEND_API int zend_cleanup_function_data_full(zend_function *function TSRMLS_DC)
|
|
|
|
{
|
|
|
|
if (function->type == ZEND_USER_FUNCTION) {
|
|
|
|
zend_cleanup_op_array_data((zend_op_array *) function);
|
|
|
|
}
|
2006-03-14 11:24:45 +00:00
|
|
|
return 0;
|
2003-01-29 17:54:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ZEND_API int zend_cleanup_class_data(zend_class_entry **pce TSRMLS_DC)
|
|
|
|
{
|
2003-06-30 20:22:35 +00:00
|
|
|
if ((*pce)->type == ZEND_USER_CLASS) {
|
2003-01-29 17:54:48 +00:00
|
|
|
/* Clean all parts that can contain run-time data */
|
|
|
|
/* Note that only run-time accessed data need to be cleaned up, pre-defined data can
|
|
|
|
not contain objects and thus are not probelmatic */
|
2006-03-13 11:13:42 +00:00
|
|
|
zend_hash_apply(&(*pce)->function_table, (apply_func_t) zend_cleanup_function_data_full TSRMLS_CC);
|
2005-12-01 11:48:17 +00:00
|
|
|
(*pce)->static_members = NULL;
|
|
|
|
} else if (CE_STATIC_MEMBERS(*pce)) {
|
|
|
|
zend_hash_destroy(CE_STATIC_MEMBERS(*pce));
|
|
|
|
FREE_HASHTABLE(CE_STATIC_MEMBERS(*pce));
|
|
|
|
#ifdef ZTS
|
|
|
|
CG(static_members)[(long)((*pce)->static_members)] = NULL;
|
|
|
|
#else
|
|
|
|
(*pce)->static_members = NULL;
|
|
|
|
#endif
|
2003-01-29 17:54:48 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
1999-04-14 19:53:33 +00:00
|
|
|
|
2002-03-12 10:08:47 +00:00
|
|
|
ZEND_API void destroy_zend_class(zend_class_entry **pce)
|
1999-04-07 18:10:10 +00:00
|
|
|
{
|
2002-03-12 10:08:47 +00:00
|
|
|
zend_class_entry *ce = *pce;
|
|
|
|
|
2002-03-12 19:22:29 +00:00
|
|
|
if (--ce->refcount > 0) {
|
2000-01-17 17:33:37 +00:00
|
|
|
return;
|
1999-04-18 15:11:52 +00:00
|
|
|
}
|
1999-04-07 18:10:10 +00:00
|
|
|
switch (ce->type) {
|
|
|
|
case ZEND_USER_CLASS:
|
2002-01-25 12:55:03 +00:00
|
|
|
zend_hash_destroy(&ce->default_properties);
|
2003-02-05 13:35:52 +00:00
|
|
|
zend_hash_destroy(&ce->properties_info);
|
2005-09-01 10:05:32 +00:00
|
|
|
zend_hash_destroy(&ce->default_static_members);
|
1999-04-07 18:10:10 +00:00
|
|
|
efree(ce->name);
|
|
|
|
zend_hash_destroy(&ce->function_table);
|
2001-12-11 18:46:43 +00:00
|
|
|
zend_hash_destroy(&ce->constants_table);
|
2003-06-01 17:28:52 +00:00
|
|
|
if (ce->num_interfaces > 0 && ce->interfaces) {
|
2003-03-05 11:14:44 +00:00
|
|
|
efree(ce->interfaces);
|
|
|
|
}
|
2003-03-31 20:42:01 +00:00
|
|
|
if (ce->doc_comment) {
|
|
|
|
efree(ce->doc_comment);
|
|
|
|
}
|
2002-03-12 10:08:47 +00:00
|
|
|
efree(ce);
|
1999-04-07 18:10:10 +00:00
|
|
|
break;
|
|
|
|
case ZEND_INTERNAL_CLASS:
|
2002-01-25 12:55:03 +00:00
|
|
|
zend_hash_destroy(&ce->default_properties);
|
2003-02-05 13:35:52 +00:00
|
|
|
zend_hash_destroy(&ce->properties_info);
|
2005-09-01 10:05:32 +00:00
|
|
|
zend_hash_destroy(&ce->default_static_members);
|
1999-04-07 18:10:10 +00:00
|
|
|
free(ce->name);
|
|
|
|
zend_hash_destroy(&ce->function_table);
|
2001-12-11 18:46:43 +00:00
|
|
|
zend_hash_destroy(&ce->constants_table);
|
2003-04-18 18:40:53 +00:00
|
|
|
if (ce->num_interfaces > 0) {
|
|
|
|
free(ce->interfaces);
|
|
|
|
}
|
|
|
|
if (ce->doc_comment) {
|
|
|
|
free(ce->doc_comment);
|
|
|
|
}
|
2002-03-12 10:08:47 +00:00
|
|
|
free(ce);
|
1999-04-07 18:10:10 +00:00
|
|
|
break;
|
2003-03-31 20:42:01 +00:00
|
|
|
}
|
2003-02-16 11:12:43 +00:00
|
|
|
}
|
1999-04-07 18:10:10 +00:00
|
|
|
|
2002-03-12 18:53:27 +00:00
|
|
|
void zend_class_add_ref(zend_class_entry **ce)
|
1999-04-26 14:10:42 +00:00
|
|
|
{
|
2002-03-12 19:22:29 +00:00
|
|
|
(*ce)->refcount++;
|
1999-04-26 14:10:42 +00:00
|
|
|
}
|
|
|
|
|
2003-03-26 07:44:11 +00:00
|
|
|
ZEND_API void destroy_op_array(zend_op_array *op_array TSRMLS_DC)
|
1999-04-07 18:10:10 +00:00
|
|
|
{
|
|
|
|
zend_op *opline = op_array->opcodes;
|
|
|
|
zend_op *end = op_array->opcodes+op_array->last;
|
ntroduce infrastructure for supplying information about arguments,
including:
- Whether or not to pass by ref (replaces the old arg_types, with arg_info)
- Argument name (for future use, maybe introspection)
- Class/Interface name (for type hints)
- If a class/interface name is available, whether to allow a null instance
Both user and builtin functions share the same data structures.
To declare a builtin function that expects its first arg to be an instance
of class 'Person', its second argument as a regular arg, and its third by
reference, use:
ZEND_BEGIN_ARG_INFO(my_func_arg_info, 0)
ZEND_ARG_OBJ_INFO(0, someone, Person, 1)
ZEND_ARG_PASS_INFO(0)
ZEND_ARG_PASS_INFO(1)
ZEND_END_ARG_INFO();
and use my_func_arg_info as the arg_info parameter to the ZEND_FE() family
of macros.
The first arg to each ZEND_ARG_*() macro is whether or not to pass by ref.
The boolean arg to ZEND_BEGIN_ARG_INFO() tells the engine whether to treat
the arguments for which there's no explicit information as pass by reference
or not.
The boolean argument to ZEND_ARG_OBJ_INFO() (4th arg) is whether or not to allownull values.
2003-08-03 17:40:44 +00:00
|
|
|
zend_uint i;
|
1999-04-07 18:10:10 +00:00
|
|
|
|
1999-12-23 19:23:36 +00:00
|
|
|
if (op_array->static_variables) {
|
|
|
|
zend_hash_destroy(op_array->static_variables);
|
1999-12-27 19:07:33 +00:00
|
|
|
FREE_HASHTABLE(op_array->static_variables);
|
1999-12-23 19:23:36 +00:00
|
|
|
}
|
|
|
|
|
1999-04-07 18:10:10 +00:00
|
|
|
if (--(*op_array->refcount)>0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
efree(op_array->refcount);
|
|
|
|
|
2004-10-04 19:54:35 +00:00
|
|
|
if (op_array->vars) {
|
|
|
|
i = op_array->last_var;
|
|
|
|
while (i > 0) {
|
|
|
|
i--;
|
|
|
|
efree(op_array->vars[i].name);
|
|
|
|
}
|
|
|
|
efree(op_array->vars);
|
|
|
|
}
|
|
|
|
|
1999-04-07 18:10:10 +00:00
|
|
|
while (opline<end) {
|
|
|
|
if (opline->op1.op_type==IS_CONST) {
|
|
|
|
#if DEBUG_ZEND>2
|
|
|
|
printf("Reducing refcount for %x 1=>0 (destroying)\n", &opline->op1.u.constant);
|
|
|
|
#endif
|
|
|
|
zval_dtor(&opline->op1.u.constant);
|
|
|
|
}
|
|
|
|
if (opline->op2.op_type==IS_CONST) {
|
|
|
|
#if DEBUG_ZEND>2
|
|
|
|
printf("Reducing refcount for %x 1=>0 (destroying)\n", &opline->op2.u.constant);
|
|
|
|
#endif
|
|
|
|
zval_dtor(&opline->op2.u.constant);
|
|
|
|
}
|
|
|
|
opline++;
|
|
|
|
}
|
|
|
|
efree(op_array->opcodes);
|
2004-07-29 15:23:47 +00:00
|
|
|
|
1999-04-07 18:10:10 +00:00
|
|
|
if (op_array->function_name) {
|
|
|
|
efree(op_array->function_name);
|
|
|
|
}
|
2004-02-20 06:59:37 +00:00
|
|
|
if (op_array->doc_comment) {
|
|
|
|
efree(op_array->doc_comment);
|
|
|
|
}
|
1999-04-07 18:10:10 +00:00
|
|
|
if (op_array->brk_cont_array) {
|
|
|
|
efree(op_array->brk_cont_array);
|
|
|
|
}
|
2004-02-03 12:17:09 +00:00
|
|
|
if (op_array->try_catch_array) {
|
|
|
|
efree(op_array->try_catch_array);
|
|
|
|
}
|
2000-04-29 02:56:44 +00:00
|
|
|
if (op_array->done_pass_two) {
|
2001-07-31 04:53:54 +00:00
|
|
|
zend_llist_apply_with_argument(&zend_extensions, (llist_apply_with_arg_func_t) zend_extension_op_array_dtor_handler, op_array TSRMLS_CC);
|
2000-04-29 02:56:44 +00:00
|
|
|
}
|
ntroduce infrastructure for supplying information about arguments,
including:
- Whether or not to pass by ref (replaces the old arg_types, with arg_info)
- Argument name (for future use, maybe introspection)
- Class/Interface name (for type hints)
- If a class/interface name is available, whether to allow a null instance
Both user and builtin functions share the same data structures.
To declare a builtin function that expects its first arg to be an instance
of class 'Person', its second argument as a regular arg, and its third by
reference, use:
ZEND_BEGIN_ARG_INFO(my_func_arg_info, 0)
ZEND_ARG_OBJ_INFO(0, someone, Person, 1)
ZEND_ARG_PASS_INFO(0)
ZEND_ARG_PASS_INFO(1)
ZEND_END_ARG_INFO();
and use my_func_arg_info as the arg_info parameter to the ZEND_FE() family
of macros.
The first arg to each ZEND_ARG_*() macro is whether or not to pass by ref.
The boolean arg to ZEND_BEGIN_ARG_INFO() tells the engine whether to treat
the arguments for which there's no explicit information as pass by reference
or not.
The boolean argument to ZEND_ARG_OBJ_INFO() (4th arg) is whether or not to allownull values.
2003-08-03 17:40:44 +00:00
|
|
|
if (op_array->arg_info) {
|
|
|
|
for (i=0; i<op_array->num_args; i++) {
|
2003-08-04 07:52:09 +00:00
|
|
|
efree(op_array->arg_info[i].name);
|
2003-08-03 22:28:14 +00:00
|
|
|
if (op_array->arg_info[i].class_name) {
|
|
|
|
efree(op_array->arg_info[i].class_name);
|
|
|
|
}
|
ntroduce infrastructure for supplying information about arguments,
including:
- Whether or not to pass by ref (replaces the old arg_types, with arg_info)
- Argument name (for future use, maybe introspection)
- Class/Interface name (for type hints)
- If a class/interface name is available, whether to allow a null instance
Both user and builtin functions share the same data structures.
To declare a builtin function that expects its first arg to be an instance
of class 'Person', its second argument as a regular arg, and its third by
reference, use:
ZEND_BEGIN_ARG_INFO(my_func_arg_info, 0)
ZEND_ARG_OBJ_INFO(0, someone, Person, 1)
ZEND_ARG_PASS_INFO(0)
ZEND_ARG_PASS_INFO(1)
ZEND_END_ARG_INFO();
and use my_func_arg_info as the arg_info parameter to the ZEND_FE() family
of macros.
The first arg to each ZEND_ARG_*() macro is whether or not to pass by ref.
The boolean arg to ZEND_BEGIN_ARG_INFO() tells the engine whether to treat
the arguments for which there's no explicit information as pass by reference
or not.
The boolean argument to ZEND_ARG_OBJ_INFO() (4th arg) is whether or not to allownull values.
2003-08-03 17:40:44 +00:00
|
|
|
}
|
|
|
|
efree(op_array->arg_info);
|
|
|
|
}
|
1999-04-07 18:10:10 +00:00
|
|
|
}
|
|
|
|
|
2001-07-28 10:51:54 +00:00
|
|
|
void init_op(zend_op *op TSRMLS_DC)
|
1999-09-20 15:44:30 +00:00
|
|
|
{
|
2004-02-04 15:51:07 +00:00
|
|
|
memset(op, 0, sizeof(zend_op));
|
1999-09-20 15:44:30 +00:00
|
|
|
op->lineno = CG(zend_lineno);
|
2000-11-11 17:41:28 +00:00
|
|
|
SET_UNUSED(op->result);
|
1999-09-20 15:44:30 +00:00
|
|
|
}
|
|
|
|
|
2001-07-28 10:51:54 +00:00
|
|
|
zend_op *get_next_op(zend_op_array *op_array TSRMLS_DC)
|
1999-04-07 18:10:10 +00:00
|
|
|
{
|
2000-03-15 16:18:21 +00:00
|
|
|
zend_uint next_op_num = op_array->last++;
|
1999-04-07 18:10:10 +00:00
|
|
|
zend_op *next_op;
|
|
|
|
|
|
|
|
if (next_op_num >= op_array->size) {
|
2001-07-15 14:08:58 +00:00
|
|
|
if (CG(interactive)) {
|
1999-04-07 18:10:10 +00:00
|
|
|
/* we messed up */
|
|
|
|
zend_printf("Ran out of opcode space!\n"
|
|
|
|
"You should probably consider writing this huge script into a file!\n");
|
|
|
|
zend_bailout();
|
|
|
|
}
|
2000-10-15 19:52:01 +00:00
|
|
|
op_array->size *= 4;
|
1999-04-07 18:10:10 +00:00
|
|
|
op_array_alloc_ops(op_array);
|
|
|
|
}
|
|
|
|
|
|
|
|
next_op = &(op_array->opcodes[next_op_num]);
|
1999-09-20 15:44:30 +00:00
|
|
|
|
2001-07-28 10:51:54 +00:00
|
|
|
init_op(next_op TSRMLS_CC);
|
1999-04-07 18:10:10 +00:00
|
|
|
|
|
|
|
return next_op;
|
|
|
|
}
|
|
|
|
|
|
|
|
int get_next_op_number(zend_op_array *op_array)
|
|
|
|
{
|
|
|
|
return op_array->last;
|
|
|
|
}
|
|
|
|
|
|
|
|
zend_brk_cont_element *get_next_brk_cont_element(zend_op_array *op_array)
|
|
|
|
{
|
|
|
|
op_array->last_brk_cont++;
|
|
|
|
op_array->brk_cont_array = erealloc(op_array->brk_cont_array, sizeof(zend_brk_cont_element)*op_array->last_brk_cont);
|
|
|
|
return &op_array->brk_cont_array[op_array->last_brk_cont-1];
|
|
|
|
}
|
|
|
|
|
2001-07-28 10:51:54 +00:00
|
|
|
static void zend_update_extended_info(zend_op_array *op_array TSRMLS_DC)
|
1999-04-07 18:10:10 +00:00
|
|
|
{
|
|
|
|
zend_op *opline = op_array->opcodes, *end=opline+op_array->last;
|
|
|
|
|
|
|
|
while (opline<end) {
|
|
|
|
if (opline->opcode == ZEND_EXT_STMT) {
|
|
|
|
if (opline+1<end) {
|
|
|
|
if ((opline+1)->opcode == ZEND_EXT_STMT) {
|
|
|
|
opline->opcode = ZEND_NOP;
|
|
|
|
opline++;
|
|
|
|
continue;
|
|
|
|
}
|
2000-12-30 15:32:12 +00:00
|
|
|
if (opline+1<end) {
|
|
|
|
opline->lineno = (opline+1)->lineno;
|
|
|
|
}
|
1999-04-07 18:10:10 +00:00
|
|
|
} else {
|
|
|
|
opline->opcode = ZEND_NOP;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
opline++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-07-31 04:53:54 +00:00
|
|
|
static void zend_extension_op_array_handler(zend_extension *extension, zend_op_array *op_array TSRMLS_DC)
|
1999-04-07 18:10:10 +00:00
|
|
|
{
|
|
|
|
if (extension->op_array_handler) {
|
|
|
|
extension->op_array_handler(op_array);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-07-31 04:53:54 +00:00
|
|
|
int pass_two(zend_op_array *op_array TSRMLS_DC)
|
1999-04-07 18:10:10 +00:00
|
|
|
{
|
2001-05-11 14:29:06 +00:00
|
|
|
zend_op *opline, *end;
|
1999-04-07 18:10:10 +00:00
|
|
|
|
1999-04-27 11:00:59 +00:00
|
|
|
if (op_array->type!=ZEND_USER_FUNCTION && op_array->type!=ZEND_EVAL_CODE) {
|
1999-04-07 18:10:10 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (CG(extended_info)) {
|
2001-07-28 10:51:54 +00:00
|
|
|
zend_update_extended_info(op_array TSRMLS_CC);
|
1999-04-07 18:10:10 +00:00
|
|
|
}
|
|
|
|
if (CG(handle_op_arrays)) {
|
2001-07-31 04:53:54 +00:00
|
|
|
zend_llist_apply_with_argument(&zend_extensions, (llist_apply_with_arg_func_t) zend_extension_op_array_handler, op_array TSRMLS_CC);
|
1999-04-07 18:10:10 +00:00
|
|
|
}
|
2001-05-11 14:29:06 +00:00
|
|
|
|
2006-04-10 12:26:53 +00:00
|
|
|
if (!CG(interactive) && op_array->size != op_array->last) {
|
|
|
|
op_array->opcodes = (zend_op *) erealloc(op_array->opcodes, sizeof(zend_op)*op_array->last);
|
|
|
|
op_array->size = op_array->last;
|
|
|
|
}
|
2002-10-24 18:04:12 +00:00
|
|
|
|
2001-05-11 14:29:06 +00:00
|
|
|
opline = op_array->opcodes;
|
|
|
|
end = opline + op_array->last;
|
|
|
|
while (opline < end) {
|
|
|
|
if (opline->op1.op_type == IS_CONST) {
|
1999-10-01 23:31:39 +00:00
|
|
|
opline->op1.u.constant.is_ref = 1;
|
2000-01-26 05:03:22 +00:00
|
|
|
opline->op1.u.constant.refcount = 2; /* Make sure is_ref won't be reset */
|
1999-04-07 18:10:10 +00:00
|
|
|
}
|
2001-05-11 14:29:06 +00:00
|
|
|
if (opline->op2.op_type == IS_CONST) {
|
1999-10-01 23:31:39 +00:00
|
|
|
opline->op2.u.constant.is_ref = 1;
|
2000-01-26 05:03:22 +00:00
|
|
|
opline->op2.u.constant.refcount = 2;
|
1999-04-07 18:10:10 +00:00
|
|
|
}
|
2002-10-24 18:24:55 +00:00
|
|
|
switch (opline->opcode) {
|
|
|
|
case ZEND_JMP:
|
|
|
|
opline->op1.u.jmp_addr = &op_array->opcodes[opline->op1.u.opline_num];
|
|
|
|
break;
|
|
|
|
case ZEND_JMPZ:
|
|
|
|
case ZEND_JMPNZ:
|
|
|
|
case ZEND_JMPZ_EX:
|
|
|
|
case ZEND_JMPNZ_EX:
|
|
|
|
opline->op2.u.jmp_addr = &op_array->opcodes[opline->op2.u.opline_num];
|
|
|
|
break;
|
2002-10-24 18:04:12 +00:00
|
|
|
}
|
2004-09-23 21:43:32 +00:00
|
|
|
ZEND_VM_SET_OPCODE_HANDLER(opline);
|
1999-04-07 18:10:10 +00:00
|
|
|
opline++;
|
|
|
|
}
|
2002-10-24 18:04:12 +00:00
|
|
|
|
2000-08-09 19:22:35 +00:00
|
|
|
op_array->done_pass_two = 1;
|
|
|
|
return 0;
|
1999-04-07 18:10:10 +00:00
|
|
|
}
|
|
|
|
|
2001-07-31 04:53:54 +00:00
|
|
|
int print_class(zend_class_entry *class_entry TSRMLS_DC)
|
1999-04-07 18:10:10 +00:00
|
|
|
{
|
|
|
|
printf("Class %s:\n", class_entry->name);
|
2001-07-31 04:53:54 +00:00
|
|
|
zend_hash_apply(&class_entry->function_table, (apply_func_t) pass_two TSRMLS_CC);
|
1999-04-07 18:10:10 +00:00
|
|
|
printf("End of class %s.\n\n", class_entry->name);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1999-05-30 13:28:56 +00:00
|
|
|
ZEND_API unary_op_type get_unary_op(int opcode)
|
1999-04-07 18:10:10 +00:00
|
|
|
{
|
2002-11-30 11:20:25 +00:00
|
|
|
switch (opcode) {
|
1999-04-07 18:10:10 +00:00
|
|
|
case ZEND_BW_NOT:
|
1999-06-04 11:44:02 +00:00
|
|
|
return (unary_op_type) bitwise_not_function;
|
1999-04-07 18:10:10 +00:00
|
|
|
break;
|
|
|
|
case ZEND_BOOL_NOT:
|
1999-06-04 11:44:02 +00:00
|
|
|
return (unary_op_type) boolean_not_function;
|
1999-04-07 18:10:10 +00:00
|
|
|
break;
|
|
|
|
default:
|
1999-05-30 13:28:56 +00:00
|
|
|
return (unary_op_type) NULL;
|
1999-04-07 18:10:10 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ZEND_API void *get_binary_op(int opcode)
|
|
|
|
{
|
|
|
|
switch (opcode) {
|
|
|
|
case ZEND_ADD:
|
1999-04-24 00:12:55 +00:00
|
|
|
case ZEND_ASSIGN_ADD:
|
1999-04-07 18:10:10 +00:00
|
|
|
return (void *) add_function;
|
|
|
|
break;
|
|
|
|
case ZEND_SUB:
|
1999-04-24 00:12:55 +00:00
|
|
|
case ZEND_ASSIGN_SUB:
|
1999-04-07 18:10:10 +00:00
|
|
|
return (void *) sub_function;
|
|
|
|
break;
|
|
|
|
case ZEND_MUL:
|
1999-04-24 00:12:55 +00:00
|
|
|
case ZEND_ASSIGN_MUL:
|
1999-04-07 18:10:10 +00:00
|
|
|
return (void *) mul_function;
|
|
|
|
break;
|
|
|
|
case ZEND_DIV:
|
1999-04-24 00:12:55 +00:00
|
|
|
case ZEND_ASSIGN_DIV:
|
1999-04-07 18:10:10 +00:00
|
|
|
return (void *) div_function;
|
|
|
|
break;
|
|
|
|
case ZEND_MOD:
|
1999-04-24 00:12:55 +00:00
|
|
|
case ZEND_ASSIGN_MOD:
|
1999-04-07 18:10:10 +00:00
|
|
|
return (void *) mod_function;
|
|
|
|
break;
|
|
|
|
case ZEND_SL:
|
1999-04-24 00:12:55 +00:00
|
|
|
case ZEND_ASSIGN_SL:
|
1999-04-07 18:10:10 +00:00
|
|
|
return (void *) shift_left_function;
|
|
|
|
break;
|
|
|
|
case ZEND_SR:
|
1999-04-24 00:12:55 +00:00
|
|
|
case ZEND_ASSIGN_SR:
|
1999-04-07 18:10:10 +00:00
|
|
|
return (void *) shift_right_function;
|
|
|
|
break;
|
|
|
|
case ZEND_CONCAT:
|
1999-04-24 00:12:55 +00:00
|
|
|
case ZEND_ASSIGN_CONCAT:
|
1999-04-07 18:10:10 +00:00
|
|
|
return (void *) concat_function;
|
|
|
|
break;
|
1999-10-19 13:33:17 +00:00
|
|
|
case ZEND_IS_IDENTICAL:
|
|
|
|
return (void *) is_identical_function;
|
|
|
|
break;
|
2000-03-29 22:05:19 +00:00
|
|
|
case ZEND_IS_NOT_IDENTICAL:
|
|
|
|
return (void *) is_not_identical_function;
|
|
|
|
break;
|
1999-04-24 00:12:55 +00:00
|
|
|
case ZEND_IS_EQUAL:
|
1999-04-07 18:10:10 +00:00
|
|
|
return (void *) is_equal_function;
|
|
|
|
break;
|
1999-04-24 00:12:55 +00:00
|
|
|
case ZEND_IS_NOT_EQUAL:
|
1999-04-07 18:10:10 +00:00
|
|
|
return (void *) is_not_equal_function;
|
|
|
|
break;
|
|
|
|
case ZEND_IS_SMALLER:
|
|
|
|
return (void *) is_smaller_function;
|
|
|
|
break;
|
1999-04-24 00:12:55 +00:00
|
|
|
case ZEND_IS_SMALLER_OR_EQUAL:
|
1999-04-07 18:10:10 +00:00
|
|
|
return (void *) is_smaller_or_equal_function;
|
|
|
|
break;
|
|
|
|
case ZEND_BW_OR:
|
1999-04-24 00:12:55 +00:00
|
|
|
case ZEND_ASSIGN_BW_OR:
|
1999-04-07 18:10:10 +00:00
|
|
|
return (void *) bitwise_or_function;
|
|
|
|
break;
|
|
|
|
case ZEND_BW_AND:
|
1999-04-24 00:12:55 +00:00
|
|
|
case ZEND_ASSIGN_BW_AND:
|
1999-04-07 18:10:10 +00:00
|
|
|
return (void *) bitwise_and_function;
|
|
|
|
break;
|
|
|
|
case ZEND_BW_XOR:
|
1999-04-24 00:12:55 +00:00
|
|
|
case ZEND_ASSIGN_BW_XOR:
|
1999-04-07 18:10:10 +00:00
|
|
|
return (void *) bitwise_xor_function;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return (void *) NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2003-02-01 01:49:15 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Local variables:
|
|
|
|
* tab-width: 4
|
|
|
|
* c-basic-offset: 4
|
|
|
|
* indent-tabs-mode: t
|
|
|
|
* End:
|
|
|
|
*/
|