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: 68 76 89.5 %
Date: 2014-09-19 Functions: 0 0 -
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    +----------------------------------------------------------------------+
       3             :    | Zend Engine                                                          |
       4             :    +----------------------------------------------------------------------+
       5             :    | Copyright (c) 1998-2014 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 TSRMLS_DC);
      33             : ZEND_API extern void (*zend_execute_internal)(zend_execute_data *execute_data, zval *return_value TSRMLS_DC);
      34             : 
      35             : void init_executor(TSRMLS_D);
      36             : void shutdown_executor(TSRMLS_D);
      37             : void shutdown_destructors(TSRMLS_D);
      38             : 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);
      39             : ZEND_API zend_execute_data *zend_create_generator_execute_data(zend_execute_data *call, zend_op_array *op_array, zval *return_value TSRMLS_DC);
      40             : ZEND_API void zend_execute(zend_op_array *op_array, zval *return_value TSRMLS_DC);
      41             : ZEND_API void execute_ex(zend_execute_data *execute_data TSRMLS_DC);
      42             : ZEND_API void execute_internal(zend_execute_data *execute_data, zval *return_value TSRMLS_DC);
      43             : ZEND_API int zend_is_true(zval *op TSRMLS_DC);
      44             : ZEND_API zend_class_entry *zend_lookup_class(zend_string *name TSRMLS_DC);
      45             : ZEND_API zend_class_entry *zend_lookup_class_ex(zend_string *name, const zval *key, int use_autoload TSRMLS_DC);
      46             : ZEND_API int zend_eval_string(char *str, zval *retval_ptr, char *string_name TSRMLS_DC);
      47             : ZEND_API int zend_eval_stringl(char *str, int str_len, zval *retval_ptr, char *string_name TSRMLS_DC);
      48             : ZEND_API int zend_eval_string_ex(char *str, zval *retval_ptr, char *string_name, int handle_exceptions TSRMLS_DC);
      49             : ZEND_API int zend_eval_stringl_ex(char *str, int str_len, zval *retval_ptr, char *string_name, int handle_exceptions TSRMLS_DC);
      50             : 
      51             : 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);
      52             : 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);
      53             : 
      54             : static zend_always_inline void i_zval_ptr_dtor(zval *zval_ptr ZEND_FILE_LINE_DC TSRMLS_DC)
      55             : {
      56    30264270 :         if (Z_REFCOUNTED_P(zval_ptr)) {
      57    18880474 :                 if (!Z_DELREF_P(zval_ptr)) {
      58             :                         ZEND_ASSERT(zval_ptr != &EG(uninitialized_zval));
      59     6779875 :                         _zval_dtor_func_for_ptr(Z_COUNTED_P(zval_ptr) ZEND_FILE_LINE_CC);
      60             :                 } else {
      61             :                         GC_ZVAL_CHECK_POSSIBLE_ROOT(zval_ptr);
      62             :                 }
      63             :         }
      64             : }
      65             : 
      66             : static zend_always_inline int i_zend_is_true(zval *op TSRMLS_DC)
      67             : {
      68             :         int result;
      69             : 
      70             : again:
      71     7449402 :         switch (Z_TYPE_P(op)) {
      72             :                 case IS_UNDEF:
      73             :                 case IS_NULL:
      74             :                 case IS_FALSE:
      75     1694713 :                         result = 0;
      76             :                         break;
      77             :                 case IS_TRUE:
      78     3480424 :                         result = 1;
      79             :                         break;
      80             :                 case IS_LONG:
      81     2056102 :                         result = (Z_LVAL_P(op)?1:0);
      82             :                         break;
      83             :                 case IS_RESOURCE:
      84       13740 :                         result = (Z_RES_HANDLE_P(op)?1:0);
      85             :                         break;
      86             :                 case IS_DOUBLE:
      87          48 :                         result = (Z_DVAL_P(op) ? 1 : 0);
      88             :                         break;
      89             :                 case IS_STRING:
      90      146532 :                         if (Z_STRLEN_P(op) == 0
      91       95308 :                                 || (Z_STRLEN_P(op)==1 && Z_STRVAL_P(op)[0]=='0')) {
      92        7646 :                                 result = 0;
      93             :                         } else {
      94       43578 :                                 result = 1;
      95             :                         }
      96             :                         break;
      97             :                 case IS_ARRAY:
      98       65462 :                         result = (zend_hash_num_elements(Z_ARRVAL_P(op))?1:0);
      99             :                         break;
     100             :                 case IS_OBJECT:
     101       87687 :                         if (IS_ZEND_STD_OBJECT(*op)) {
     102       87687 :                                 if (Z_OBJ_HT_P(op)->cast_object) {
     103             :                                         zval tmp;
     104       87687 :                                         if (Z_OBJ_HT_P(op)->cast_object(op, &tmp, _IS_BOOL TSRMLS_CC) == SUCCESS) {
     105       87686 :                                                 result = Z_TYPE(tmp) == IS_TRUE;
     106             :                                                 break;
     107             :                                         }
     108           1 :                                         zend_error(E_RECOVERABLE_ERROR, "Object of class %s could not be converted to boolean", Z_OBJ_P(op)->ce->name->val);
     109           0 :                                 } else if (Z_OBJ_HT_P(op)->get) {
     110             :                                         zval rv;
     111           0 :                                         zval *tmp = Z_OBJ_HT_P(op)->get(op, &rv TSRMLS_CC);
     112           0 :                                         if (Z_TYPE_P(tmp) != IS_OBJECT) {
     113             :                                                 /* for safety - avoid loop */
     114           0 :                                                 convert_to_boolean(tmp);
     115           0 :                                                 result = Z_TYPE_P(tmp) == IS_TRUE;
     116           0 :                                                 zval_ptr_dtor(tmp);
     117             :                                                 break;
     118             :                                         }
     119             :                                 }
     120             :                         }
     121           0 :                         result = 1;
     122             :                         break;
     123             :                 case IS_REFERENCE:
     124           2 :                         op = Z_REFVAL_P(op);
     125             :                         goto again;
     126             :                         break;
     127             :                 default:
     128           0 :                         result = 0;
     129             :                         break;
     130             :         }
     131     7449399 :         return result;
     132             : }
     133             : 
     134             : ZEND_API int zval_update_constant(zval *pp, zend_bool inline_change TSRMLS_DC);
     135             : ZEND_API int zval_update_constant_inline_change(zval *pp, zend_class_entry *scope TSRMLS_DC);
     136             : ZEND_API int zval_update_constant_no_inline_change(zval *pp, zend_class_entry *scope TSRMLS_DC);
     137             : ZEND_API int zval_update_constant_ex(zval *pp, zend_bool inline_change, zend_class_entry *scope TSRMLS_DC);
     138             : 
     139             : /* dedicated Zend executor functions - do not use! */
     140             : #define ZEND_VM_STACK_PAGE_SIZE (16 * 1024) /* should be a power of 2 */
     141             : 
     142             : struct _zend_vm_stack {
     143             :         zval *top;
     144             :         zval *end;
     145             :         zend_vm_stack prev;
     146             : };
     147             : 
     148             : #define ZEND_VM_STACK_HEADER_SLOT \
     149             :         ((ZEND_MM_ALIGNED_SIZE(sizeof(struct _zend_vm_stack)) + ZEND_MM_ALIGNED_SIZE(sizeof(zval)) - 1) / ZEND_MM_ALIGNED_SIZE(sizeof(zval)))
     150             : 
     151             : #define ZEND_VM_STACK_ELEMETS(stack) \
     152             :         (((zval*)(stack)) + ZEND_VM_STACK_HEADER_SLOT)
     153             : 
     154             : #define ZEND_VM_STACK_GROW_IF_NEEDED(count)                                                             \
     155             :         do {                                                                                                                            \
     156             :                 if (UNEXPECTED(((count) * ZEND_MM_ALIGNED_SIZE(sizeof(zval))) >      \
     157             :                         (size_t)(((char*)EG(argument_stack)->end) -                                  \
     158             :                     ((char*)EG(argument_stack)->top)))) {                                            \
     159             :                         zend_vm_stack_extend((count) TSRMLS_CC);                                        \
     160             :                 }                                                                                                                               \
     161             :         } while (0)
     162             : 
     163             : static zend_always_inline zend_vm_stack zend_vm_stack_new_page(int count) {
     164       20380 :         zend_vm_stack page = (zend_vm_stack)emalloc(count * ZEND_MM_ALIGNED_SIZE(sizeof(zval)));
     165             : 
     166       20380 :         page->top = ZEND_VM_STACK_ELEMETS(page);
     167       20380 :         page->end = (zval*)page + count;
     168       20380 :         page->prev = NULL;
     169       20380 :         return page;
     170             : }
     171             : 
     172             : static zend_always_inline void zend_vm_stack_init(TSRMLS_D)
     173             : {
     174       20292 :         EG(argument_stack) = zend_vm_stack_new_page(ZEND_VM_STACK_PAGE_SIZE);
     175       20292 :         EG(argument_stack)->top++;
     176             : }
     177             : 
     178             : static zend_always_inline void zend_vm_stack_destroy(TSRMLS_D)
     179             : {
     180       20328 :         zend_vm_stack stack = EG(argument_stack);
     181             : 
     182       40656 :         while (stack != NULL) {
     183       20328 :                 zend_vm_stack p = stack->prev;
     184       20328 :                 efree(stack);
     185       20328 :                 stack = p;
     186             :         }
     187             : }
     188             : 
     189             : static zend_always_inline void zend_vm_stack_extend(uint32_t count TSRMLS_DC)
     190             : {
     191           6 :         uint32_t size = count * ZEND_MM_ALIGNED_SIZE(sizeof(zval));
     192           6 :         zend_vm_stack p = zend_vm_stack_new_page(
     193             :                 (size >= (ZEND_VM_STACK_PAGE_SIZE - ZEND_VM_STACK_HEADER_SLOT) * ZEND_MM_ALIGNED_SIZE(sizeof(zval))) ? 
     194             :                 (size + ((ZEND_VM_STACK_HEADER_SLOT + ZEND_VM_STACK_PAGE_SIZE) * ZEND_MM_ALIGNED_SIZE(sizeof(zval))) - 1) & 
     195             :                         ~((ZEND_VM_STACK_PAGE_SIZE * ZEND_MM_ALIGNED_SIZE(sizeof(zval))) - 1) : 
     196           6 :                 ZEND_VM_STACK_PAGE_SIZE);
     197           6 :         p->prev = EG(argument_stack);
     198           6 :         EG(argument_stack) = p;
     199             : }
     200             : 
     201             : static zend_always_inline zend_execute_data *zend_vm_stack_push_call_frame(zend_function *func, uint32_t num_args, zend_uchar flags, zend_class_entry *called_scope, zend_object *object, zend_execute_data *prev TSRMLS_DC)
     202             : {
     203    18610528 :         uint32_t used_stack = ZEND_CALL_FRAME_SLOT + num_args;
     204             :         zend_execute_data *call;
     205             :         
     206    18610528 :         if (ZEND_USER_CODE(func->type)) {
     207     2062474 :                 used_stack += func->op_array.last_var + func->op_array.T - MIN(func->op_array.num_args, num_args);
     208             :         }
     209    18610528 :         ZEND_VM_STACK_GROW_IF_NEEDED(used_stack);
     210    18610528 :         call = (zend_execute_data*)EG(argument_stack)->top;
     211    18610528 :         EG(argument_stack)->top += used_stack;
     212    18610528 :         call->func = func;
     213    18610528 :         call->num_args = 0;
     214    18610528 :         call->flags = flags;
     215    18610528 :         call->called_scope = called_scope;
     216    18610528 :         call->object = object;
     217    18610528 :         call->prev_nested_call = prev;
     218    18610528 :         return call;
     219             : }
     220             : 
     221             : static zend_always_inline void zend_vm_stack_free_extra_args(zend_execute_data *call TSRMLS_DC)
     222             : {
     223     2033003 :         uint32_t first_extra_arg = call->func->op_array.num_args - ((call->func->common.fn_flags & ZEND_ACC_VARIADIC) != 0);
     224             : 
     225     2033003 :         if (UNEXPECTED(call->num_args > first_extra_arg)) {
     226         862 :                 zval *end = EX_VAR_NUM_2(call, call->func->op_array.last_var + call->func->op_array.T);
     227         862 :                 zval *p = end + (call->num_args - first_extra_arg);
     228             :                 do {
     229       22528 :                         p--;
     230             :                         zval_ptr_dtor_nogc(p);
     231       22528 :                 } while (p != end);
     232             :         }
     233             : }
     234             : 
     235             : static zend_always_inline void zend_vm_stack_free_args(zend_execute_data *call TSRMLS_DC)
     236             : {
     237    16547756 :         uint32_t num_args = call->num_args;  
     238             : 
     239    16547756 :         if (num_args > 0) {
     240    16009213 :                 zval *end = ZEND_CALL_ARG(call, 1);
     241    16009213 :                 zval *p = end + num_args;
     242             : 
     243             :                 do {
     244    30134803 :                         p--;
     245             :                         zval_ptr_dtor_nogc(p);
     246    30134803 :                 } while (p != end);
     247             :         }
     248             : }
     249             : 
     250             : static zend_always_inline void zend_vm_stack_free_call_frame(zend_execute_data *call TSRMLS_DC)
     251             : {
     252    18608196 :         if (UNEXPECTED(ZEND_VM_STACK_ELEMETS(EG(argument_stack)) == (zval*)call)) {
     253           6 :                 zend_vm_stack p = EG(argument_stack);
     254             : 
     255           6 :                 EG(argument_stack) = p->prev;
     256           6 :                 efree(p);
     257             :         } else {
     258    18608190 :                 EG(argument_stack)->top = (zval*)call;
     259             :         }
     260             : }
     261             : 
     262             : /* services */
     263             : ZEND_API const char *get_active_class_name(const char **space TSRMLS_DC);
     264             : ZEND_API const char *get_active_function_name(TSRMLS_D);
     265             : ZEND_API const char *zend_get_executed_filename(TSRMLS_D);
     266             : ZEND_API uint zend_get_executed_lineno(TSRMLS_D);
     267             : ZEND_API zend_bool zend_is_executing(TSRMLS_D);
     268             : 
     269             : ZEND_API void zend_set_timeout(zend_long seconds, int reset_signals);
     270             : ZEND_API void zend_unset_timeout(TSRMLS_D);
     271             : ZEND_API void zend_timeout(int dummy);
     272             : ZEND_API zend_class_entry *zend_fetch_class(zend_string *class_name, int fetch_type TSRMLS_DC);
     273             : ZEND_API zend_class_entry *zend_fetch_class_by_name(zend_string *class_name, const zval *key, int fetch_type TSRMLS_DC);
     274             : void zend_verify_abstract_class(zend_class_entry *ce TSRMLS_DC);
     275             : 
     276             : ZEND_API void zend_fetch_dimension_by_zval(zval *result, zval *container, zval *dim TSRMLS_DC);
     277             : 
     278             : #ifdef ZEND_WIN32
     279             : void zend_init_timeout_thread(void);
     280             : void zend_shutdown_timeout_thread(void);
     281             : #define WM_REGISTER_ZEND_TIMEOUT                (WM_USER+1)
     282             : #define WM_UNREGISTER_ZEND_TIMEOUT              (WM_USER+2)
     283             : #endif
     284             : 
     285             : /* The following tries to resolve the classname of a zval of type object.
     286             :  * Since it is slow it should be only used in error messages.
     287             :  */
     288             : #define Z_OBJ_CLASS_NAME_P(obj) (((obj) && (obj)->handlers->get_class_entry != NULL && (obj)->handlers->get_class_entry) ? (obj)->handlers->get_class_entry(obj TSRMLS_CC)->name->val : "")
     289             : 
     290             : ZEND_API zval* zend_get_compiled_variable_value(const zend_execute_data *execute_data_ptr, uint32_t var);
     291             : 
     292             : #define ZEND_USER_OPCODE_CONTINUE   0 /* execute next opcode */
     293             : #define ZEND_USER_OPCODE_RETURN     1 /* exit from executor (return from function) */
     294             : #define ZEND_USER_OPCODE_DISPATCH   2 /* call original opcode handler */
     295             : #define ZEND_USER_OPCODE_ENTER      3 /* enter into new op_array without recursion */
     296             : #define ZEND_USER_OPCODE_LEAVE      4 /* return to calling op_array within the same executor */
     297             : 
     298             : #define ZEND_USER_OPCODE_DISPATCH_TO 0x100 /* call original handler of returned opcode */
     299             : 
     300             : ZEND_API int zend_set_user_opcode_handler(zend_uchar opcode, user_opcode_handler_t handler);
     301             : ZEND_API user_opcode_handler_t zend_get_user_opcode_handler(zend_uchar opcode);
     302             : 
     303             : /* former zend_execute_locks.h */
     304             : typedef struct _zend_free_op {
     305             :         zval *var;
     306             : /*      int   is_var; */
     307             : } zend_free_op;
     308             : 
     309             : 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);
     310             : 
     311             : ZEND_API int zend_do_fcall(ZEND_OPCODE_HANDLER_ARGS);
     312             : 
     313             : void zend_clean_and_cache_symbol_table(zend_array *symbol_table TSRMLS_DC);
     314             : void zend_free_compiled_variables(zend_execute_data *execute_data TSRMLS_DC);
     315             : 
     316             : #define CACHED_PTR(num) \
     317             :         EX(run_time_cache)[(num)]
     318             : 
     319             : #define CACHE_PTR(num, ptr) do { \
     320             :                 EX(run_time_cache)[(num)] = (ptr); \
     321             :         } while (0)
     322             : 
     323             : #define CACHED_POLYMORPHIC_PTR(num, ce) \
     324             :         ((EX(run_time_cache)[(num)] == (ce)) ? \
     325             :                 EX(run_time_cache)[(num) + 1] : \
     326             :                 NULL)
     327             : 
     328             : #define CACHE_POLYMORPHIC_PTR(num, ce, ptr) do { \
     329             :                 EX(run_time_cache)[(num)] = (ce); \
     330             :                 EX(run_time_cache)[(num) + 1] = (ptr); \
     331             :         } while (0)
     332             : 
     333             : #define CACHED_PTR_EX(slot) \
     334             :         (slot)[0]
     335             : 
     336             : #define CACHE_PTR_EX(slot, ptr) do { \
     337             :                 (slot)[0] = (ptr); \
     338             :         } while (0)
     339             : 
     340             : #define CACHED_POLYMORPHIC_PTR_EX(slot, ce) \
     341             :         (((slot)[0] == (ce)) ? (slot)[1] : NULL)
     342             : 
     343             : #define CACHE_POLYMORPHIC_PTR_EX(slot, ce, ptr) do { \
     344             :                 (slot)[0] = (ce); \
     345             :                 (slot)[1] = (ptr); \
     346             :         } while (0)
     347             : 
     348             : END_EXTERN_C()
     349             : 
     350             : #endif /* ZEND_EXECUTE_H */
     351             : 
     352             : /*
     353             :  * Local variables:
     354             :  * tab-width: 4
     355             :  * c-basic-offset: 4
     356             :  * indent-tabs-mode: t
     357             :  * End:
     358             :  */

Generated by: LCOV version 1.10

Generated at Fri, 19 Sep 2014 17:11:04 +0000 (3 days ago)

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