PHP  
 PHP: Test and Code Coverage Analysis
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

LCOV - code coverage report
Current view: top level - Zend - zend_execute.h (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 87 90 96.7 %
Date: 2015-05-21 Functions: 0 0 -
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    +----------------------------------------------------------------------+
       3             :    | Zend Engine                                                          |
       4             :    +----------------------------------------------------------------------+
       5             :    | Copyright (c) 1998-2015 Zend Technologies Ltd. (http://www.zend.com) |
       6             :    +----------------------------------------------------------------------+
       7             :    | This source file is subject to version 2.00 of the Zend license,     |
       8             :    | that is bundled with this package in the file LICENSE, and is        |
       9             :    | available through the world-wide-web at the following url:           |
      10             :    | http://www.zend.com/license/2_00.txt.                                |
      11             :    | If you did not receive a copy of the Zend license and are unable to  |
      12             :    | obtain it through the world-wide-web, please send a note to          |
      13             :    | license@zend.com so we can mail you a copy immediately.              |
      14             :    +----------------------------------------------------------------------+
      15             :    | Authors: Andi Gutmans <andi@zend.com>                                |
      16             :    |          Zeev Suraski <zeev@zend.com>                                |
      17             :    +----------------------------------------------------------------------+
      18             : */
      19             : 
      20             : /* $Id$ */
      21             : 
      22             : #ifndef ZEND_EXECUTE_H
      23             : #define ZEND_EXECUTE_H
      24             : 
      25             : #include "zend_compile.h"
      26             : #include "zend_hash.h"
      27             : #include "zend_operators.h"
      28             : #include "zend_variables.h"
      29             : 
      30             : BEGIN_EXTERN_C()
      31             : struct _zend_fcall_info;
      32             : ZEND_API extern void (*zend_execute_ex)(zend_execute_data *execute_data);
      33             : ZEND_API extern void (*zend_execute_internal)(zend_execute_data *execute_data, zval *return_value);
      34             : 
      35             : void init_executor(void);
      36             : void shutdown_executor(void);
      37             : void shutdown_destructors(void);
      38             : ZEND_API void zend_init_execute_data(zend_execute_data *execute_data, zend_op_array *op_array, zval *return_value);
      39             : ZEND_API zend_execute_data *zend_create_generator_execute_data(zend_execute_data *call, zend_op_array *op_array, zval *return_value);
      40             : ZEND_API void zend_execute(zend_op_array *op_array, zval *return_value);
      41             : ZEND_API void execute_ex(zend_execute_data *execute_data);
      42             : ZEND_API void execute_internal(zend_execute_data *execute_data, zval *return_value);
      43             : ZEND_API zend_class_entry *zend_lookup_class(zend_string *name);
      44             : ZEND_API zend_class_entry *zend_lookup_class_ex(zend_string *name, const zval *key, int use_autoload);
      45             : ZEND_API zend_class_entry *zend_get_called_scope(zend_execute_data *ex);
      46             : ZEND_API zend_object *zend_get_this_object(zend_execute_data *ex);
      47             : ZEND_API int zend_eval_string(char *str, zval *retval_ptr, char *string_name);
      48             : ZEND_API int zend_eval_stringl(char *str, size_t str_len, zval *retval_ptr, char *string_name);
      49             : ZEND_API int zend_eval_string_ex(char *str, zval *retval_ptr, char *string_name, int handle_exceptions);
      50             : ZEND_API int zend_eval_stringl_ex(char *str, size_t str_len, zval *retval_ptr, char *string_name, int handle_exceptions);
      51             : 
      52             : ZEND_API char * zend_verify_internal_arg_class_kind(const zend_internal_arg_info *cur_arg_info, char **class_name, zend_class_entry **pce);
      53             : ZEND_API char * zend_verify_arg_class_kind(const zend_arg_info *cur_arg_info, char **class_name, zend_class_entry **pce);
      54             : ZEND_API void zend_verify_arg_error(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);
      55             : ZEND_API void zend_verify_return_error(const zend_function *zf, const char *need_msg, const char *need_kind, const char *returned_msg, const char *returned_kind);
      56             : ZEND_API void zend_verify_internal_return_error(const zend_function *zf, const char *need_msg, const char *need_kind, const char *returned_msg, const char *returned_kind);
      57             : 
      58             : static zend_always_inline zval* zend_assign_to_variable(zval *variable_ptr, zval *value, zend_uchar value_type)
      59             : {
      60    25303046 :         zend_refcounted *ref = NULL;
      61             : 
      62    42348856 :         if ((value_type & (IS_VAR|IS_CV)) && Z_ISREF_P(value)) {
      63      841234 :                 ref = Z_COUNTED_P(value);
      64      841234 :                 value = Z_REFVAL_P(value);
      65             :         }
      66             : 
      67             :         do {
      68    25303046 :                 if (UNEXPECTED(Z_REFCOUNTED_P(variable_ptr))) {
      69             :                         zend_refcounted *garbage;
      70             : 
      71    16698568 :                         if (Z_ISREF_P(variable_ptr)) {
      72     2770231 :                                 variable_ptr = Z_REFVAL_P(variable_ptr);
      73     2770231 :                                 if (EXPECTED(!Z_REFCOUNTED_P(variable_ptr))) {
      74             :                                         break;
      75             :                                 }
      76             :                         }
      77    15771076 :                         if (Z_TYPE_P(variable_ptr) == IS_OBJECT &&
      78      840834 :                         UNEXPECTED(Z_OBJ_HANDLER_P(variable_ptr, set) != NULL)) {
      79           0 :                                 Z_OBJ_HANDLER_P(variable_ptr, set)(variable_ptr, value);
      80           0 :                                 return variable_ptr;
      81             :                         }
      82    14930242 :                         if ((value_type & (IS_VAR|IS_CV)) && variable_ptr == value) {
      83         120 :                                 return variable_ptr;
      84             :                         }
      85    14930122 :                         garbage = Z_COUNTED_P(variable_ptr);
      86    14930122 :                         if (--GC_REFCOUNT(garbage) == 0) {
      87     8322767 :                                 ZVAL_COPY_VALUE(variable_ptr, value);
      88     8322767 :                                 if (value_type == IS_CONST) {
      89             :                                         /* IS_CONST can't be IS_OBJECT, IS_RESOURCE or IS_REFERENCE */
      90     1012107 :                                         if (UNEXPECTED(Z_OPT_COPYABLE_P(variable_ptr))) {
      91       14957 :                                                 zval_copy_ctor_func(variable_ptr);
      92             :                                         }
      93     7310660 :                                 } else if (value_type == IS_CV) {
      94     1484672 :                                         if (UNEXPECTED(Z_OPT_REFCOUNTED_P(variable_ptr))) {
      95             :                                                 Z_ADDREF_P(variable_ptr);
      96             :                                         }
      97     5825988 :                                 } else if (/* value_type == IS_VAR && */ UNEXPECTED(ref)) {
      98           4 :                                         if (UNEXPECTED(--GC_REFCOUNT(ref) == 0)) {
      99           0 :                                                 efree_size(ref, sizeof(zend_reference));
     100           4 :                                         } else if (Z_OPT_REFCOUNTED_P(variable_ptr)) {
     101             :                                                 Z_ADDREF_P(variable_ptr);
     102             :                                         }
     103             :                                 }
     104     8322767 :                                 zval_dtor_func_for_ptr(garbage);
     105     8322766 :                                 return variable_ptr;
     106             :                         } else { /* we need to split */
     107             :                                 /* optimized version of GC_ZVAL_CHECK_POSSIBLE_ROOT(variable_ptr) */
     108     6923079 :                                 if ((Z_COLLECTABLE_P(variable_ptr)) &&
     109      315724 :                                 UNEXPECTED(!GC_INFO(garbage))) {
     110       30013 :                                         gc_possible_root(garbage);
     111             :                                 }
     112             :                         }
     113             :                 }
     114             :         } while (0);
     115             : 
     116    16980159 :         ZVAL_COPY_VALUE(variable_ptr, value);
     117    16980159 :         if (value_type == IS_CONST) {
     118             :                 /* IS_CONST can't be IS_OBJECT, IS_RESOURCE or IS_REFERENCE */
     119     4418666 :                 if (UNEXPECTED(Z_OPT_COPYABLE_P(variable_ptr))) {
     120      204705 :                         zval_copy_ctor_func(variable_ptr);
     121             :                 }
     122    12561493 :         } else if (value_type == IS_CV) {
     123     4044275 :                 if (UNEXPECTED(Z_OPT_REFCOUNTED_P(variable_ptr))) {
     124             :                         Z_ADDREF_P(variable_ptr);
     125             :                 }
     126     8517218 :         } else if (/* value_type == IS_VAR && */ UNEXPECTED(ref)) {
     127          15 :                 if (UNEXPECTED(--GC_REFCOUNT(ref) == 0)) {
     128           1 :                         efree_size(ref, sizeof(zend_reference));
     129          14 :                 } else if (Z_OPT_REFCOUNTED_P(variable_ptr)) {
     130             :                         Z_ADDREF_P(variable_ptr);
     131             :                 }
     132             :         }
     133    16980159 :         return variable_ptr;
     134             : }
     135             : 
     136             : ZEND_API int zval_update_constant(zval *pp, zend_bool inline_change);
     137             : ZEND_API int zval_update_constant_ex(zval *pp, zend_bool inline_change, zend_class_entry *scope);
     138             : 
     139             : /* dedicated Zend executor functions - do not use! */
     140             : struct _zend_vm_stack {
     141             :         zval *top;
     142             :         zval *end;
     143             :         zend_vm_stack prev;
     144             : };
     145             : 
     146             : #define ZEND_VM_STACK_HEADER_SLOTS \
     147             :         ((ZEND_MM_ALIGNED_SIZE(sizeof(struct _zend_vm_stack)) + ZEND_MM_ALIGNED_SIZE(sizeof(zval)) - 1) / ZEND_MM_ALIGNED_SIZE(sizeof(zval)))
     148             : 
     149             : #define ZEND_VM_STACK_ELEMETS(stack) \
     150             :         (((zval*)(stack)) + ZEND_VM_STACK_HEADER_SLOTS)
     151             : 
     152             : ZEND_API void zend_vm_stack_init(void);
     153             : ZEND_API void zend_vm_stack_destroy(void);
     154             : ZEND_API void* zend_vm_stack_extend(size_t size);
     155             : 
     156             : static zend_always_inline zend_execute_data *zend_vm_stack_push_call_frame_ex(uint32_t used_stack, uint32_t call_info, zend_function *func, uint32_t num_args, zend_class_entry *called_scope, zend_object *object)
     157             : {
     158    28029752 :         zend_execute_data *call = (zend_execute_data*)EG(vm_stack_top);
     159             : 
     160    28029752 :         if (UNEXPECTED(used_stack > (size_t)(((char*)EG(vm_stack_end)) - (char*)call))) {
     161           4 :                 call = (zend_execute_data*)zend_vm_stack_extend(used_stack);
     162           4 :                 ZEND_SET_CALL_INFO(call, call_info | ZEND_CALL_ALLOCATED);
     163             :         } else {
     164    28029748 :                 EG(vm_stack_top) = (zval*)((char*)call + used_stack);
     165    28029748 :                 ZEND_SET_CALL_INFO(call, call_info);
     166             :         }
     167    28029752 :         call->func = func;
     168    28029752 :         Z_OBJ(call->This) = object;
     169    28029752 :         ZEND_CALL_NUM_ARGS(call) = num_args;
     170    28029752 :         call->called_scope = called_scope;
     171    28029752 :         return call;
     172             : }
     173             : 
     174             : static zend_always_inline uint32_t zend_vm_calc_used_stack(uint32_t num_args, zend_function *func)
     175             : {
     176     4400540 :         uint32_t used_stack = ZEND_CALL_FRAME_SLOT + num_args;
     177             : 
     178     4400540 :         if (EXPECTED(ZEND_USER_CODE(func->type))) {
     179      959742 :                 used_stack += func->op_array.last_var + func->op_array.T - MIN(func->op_array.num_args, num_args);
     180             :         }
     181     4400540 :         return used_stack * sizeof(zval);
     182             : }
     183             : 
     184             : static zend_always_inline zend_execute_data *zend_vm_stack_push_call_frame(uint32_t call_info, zend_function *func, uint32_t num_args, zend_class_entry *called_scope, zend_object *object)
     185             : {
     186     4167899 :         uint32_t used_stack = zend_vm_calc_used_stack(num_args, func);
     187             : 
     188     4167899 :         return zend_vm_stack_push_call_frame_ex(used_stack, call_info,
     189             :                 func, num_args, called_scope, object);
     190             : }
     191             : 
     192             : static zend_always_inline void zend_vm_stack_free_extra_args_ex(uint32_t call_info, zend_execute_data *call)
     193             : {
     194     1739228 :         if (UNEXPECTED(call_info & ZEND_CALL_FREE_EXTRA_ARGS)) {
     195         395 :                 zval *end = ZEND_CALL_VAR_NUM(call, call->func->op_array.last_var + call->func->op_array.T);
     196         395 :                 zval *p = end + (ZEND_CALL_NUM_ARGS(call) - call->func->op_array.num_args);
     197             :                 do {
     198        1087 :                         p--;
     199        1087 :                         if (Z_REFCOUNTED_P(p)) {
     200         726 :                                 if (!Z_DELREF_P(p)) {
     201           8 :                                         zend_refcounted *r = Z_COUNTED_P(p);
     202           8 :                                         ZVAL_NULL(p);
     203           8 :                                         zval_dtor_func_for_ptr(r);
     204             :                                 } else {
     205             :                                         GC_ZVAL_CHECK_POSSIBLE_ROOT(p);
     206             :                                 }
     207             :                         }
     208        1087 :                 } while (p != end);
     209             :         }
     210             : }
     211             : 
     212             : static zend_always_inline void zend_vm_stack_free_extra_args(zend_execute_data *call)
     213             : {
     214       50378 :         zend_vm_stack_free_extra_args_ex(ZEND_CALL_INFO(call), call);
     215             : }
     216             : 
     217             : static zend_always_inline void zend_vm_stack_free_args(zend_execute_data *call)
     218             : {
     219    26209769 :         uint32_t num_args = ZEND_CALL_NUM_ARGS(call);
     220             : 
     221    26209769 :         if (EXPECTED(num_args > 0)) {
     222    19425553 :                 zval *end = ZEND_CALL_ARG(call, 1);
     223    19425553 :                 zval *p = end + num_args;
     224             : 
     225             :                 do {
     226    34567784 :                         p--;
     227    34567784 :                         if (Z_REFCOUNTED_P(p)) {
     228    20546547 :                                 if (!Z_DELREF_P(p)) {
     229     1629082 :                                         zend_refcounted *r = Z_COUNTED_P(p);
     230     1629082 :                                         ZVAL_NULL(p);
     231     1629082 :                                         zval_dtor_func_for_ptr(r);
     232             :                                 }
     233             :                         }
     234    34567784 :                 } while (p != end);
     235             :         }
     236             : }
     237             : 
     238             : static zend_always_inline void zend_vm_stack_free_call_frame_ex(uint32_t call_info, zend_execute_data *call)
     239             : {
     240    27977785 :         if (UNEXPECTED(call_info & ZEND_CALL_ALLOCATED)) {
     241           4 :                 zend_vm_stack p = EG(vm_stack);
     242             : 
     243           4 :                 zend_vm_stack prev = p->prev;
     244             : 
     245           4 :                 EG(vm_stack_top) = prev->top;
     246           4 :                 EG(vm_stack_end) = prev->end;
     247           4 :                 EG(vm_stack) = prev;
     248           4 :                 efree(p);
     249             :         } else {
     250    27977781 :                 EG(vm_stack_top) = (zval*)call;
     251             :         }
     252             : }
     253             : 
     254             : static zend_always_inline void zend_vm_stack_free_call_frame(zend_execute_data *call)
     255             : {
     256    26721658 :         zend_vm_stack_free_call_frame_ex(ZEND_CALL_INFO(call), call);
     257             : }
     258             : 
     259             : /* services */
     260             : ZEND_API const char *get_active_class_name(const char **space);
     261             : ZEND_API const char *get_active_function_name(void);
     262             : ZEND_API const char *zend_get_executed_filename(void);
     263             : ZEND_API zend_string *zend_get_executed_filename_ex(void);
     264             : ZEND_API uint zend_get_executed_lineno(void);
     265             : ZEND_API zend_bool zend_is_executing(void);
     266             : 
     267             : ZEND_API void zend_set_timeout(zend_long seconds, int reset_signals);
     268             : ZEND_API void zend_unset_timeout(void);
     269             : ZEND_API void zend_timeout(int dummy);
     270             : ZEND_API zend_class_entry *zend_fetch_class(zend_string *class_name, int fetch_type);
     271             : ZEND_API zend_class_entry *zend_fetch_class_by_name(zend_string *class_name, const zval *key, int fetch_type);
     272             : void zend_verify_abstract_class(zend_class_entry *ce);
     273             : 
     274             : ZEND_API void zend_fetch_dimension_by_zval(zval *result, zval *container, zval *dim);
     275             : 
     276             : ZEND_API zval* zend_get_compiled_variable_value(const zend_execute_data *execute_data_ptr, uint32_t var);
     277             : 
     278             : #define ZEND_USER_OPCODE_CONTINUE   0 /* execute next opcode */
     279             : #define ZEND_USER_OPCODE_RETURN     1 /* exit from executor (return from function) */
     280             : #define ZEND_USER_OPCODE_DISPATCH   2 /* call original opcode handler */
     281             : #define ZEND_USER_OPCODE_ENTER      3 /* enter into new op_array without recursion */
     282             : #define ZEND_USER_OPCODE_LEAVE      4 /* return to calling op_array within the same executor */
     283             : 
     284             : #define ZEND_USER_OPCODE_DISPATCH_TO 0x100 /* call original handler of returned opcode */
     285             : 
     286             : ZEND_API int zend_set_user_opcode_handler(zend_uchar opcode, user_opcode_handler_t handler);
     287             : ZEND_API user_opcode_handler_t zend_get_user_opcode_handler(zend_uchar opcode);
     288             : 
     289             : /* former zend_execute_locks.h */
     290             : typedef zval* zend_free_op;
     291             : 
     292             : 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);
     293             : 
     294             : ZEND_API void zend_clean_and_cache_symbol_table(zend_array *symbol_table);
     295             : void zend_free_compiled_variables(zend_execute_data *execute_data);
     296             : 
     297             : #define CACHE_ADDR(num) \
     298             :         ((void**)((char*)EX_RUN_TIME_CACHE() + (num)))
     299             : 
     300             : #define CACHED_PTR(num) \
     301             :         ((void**)((char*)EX_RUN_TIME_CACHE() + (num)))[0]
     302             : 
     303             : #define CACHE_PTR(num, ptr) do { \
     304             :                 ((void**)((char*)EX_RUN_TIME_CACHE() + (num)))[0] = (ptr); \
     305             :         } while (0)
     306             : 
     307             : #define CACHED_POLYMORPHIC_PTR(num, ce) \
     308             :         (EXPECTED(((void**)((char*)EX_RUN_TIME_CACHE() + (num)))[0] == (void*)(ce)) ? \
     309             :                 ((void**)((char*)EX_RUN_TIME_CACHE() + (num)))[1] : \
     310             :                 NULL)
     311             : 
     312             : #define CACHE_POLYMORPHIC_PTR(num, ce, ptr) do { \
     313             :                 void **slot = (void**)((char*)EX_RUN_TIME_CACHE() + (num)); \
     314             :                 slot[0] = (ce); \
     315             :                 slot[1] = (ptr); \
     316             :         } while (0)
     317             : 
     318             : #define CACHED_PTR_EX(slot) \
     319             :         (slot)[0]
     320             : 
     321             : #define CACHE_PTR_EX(slot, ptr) do { \
     322             :                 (slot)[0] = (ptr); \
     323             :         } while (0)
     324             : 
     325             : #define CACHED_POLYMORPHIC_PTR_EX(slot, ce) \
     326             :         (EXPECTED((slot)[0] == (ce)) ? (slot)[1] : NULL)
     327             : 
     328             : #define CACHE_POLYMORPHIC_PTR_EX(slot, ce, ptr) do { \
     329             :                 (slot)[0] = (ce); \
     330             :                 (slot)[1] = (ptr); \
     331             :         } while (0)
     332             : 
     333             : END_EXTERN_C()
     334             : 
     335             : #endif /* ZEND_EXECUTE_H */
     336             : 
     337             : /*
     338             :  * Local variables:
     339             :  * tab-width: 4
     340             :  * c-basic-offset: 4
     341             :  * indent-tabs-mode: t
     342             :  * End:
     343             :  */

Generated by: LCOV version 1.10

Generated at Thu, 21 May 2015 19:58:52 +0000 (6 days ago)

Copyright © 2005-2015 The PHP Group
All rights reserved.