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: 81 91 89.0 %
Date: 2014-12-13 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 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, size_t 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, size_t str_len, zval *retval_ptr, char *string_name, int handle_exceptions TSRMLS_DC);
      50             : 
      51             : ZEND_API char * zend_verify_internal_arg_class_kind(const zend_internal_arg_info *cur_arg_info, char **class_name, zend_class_entry **pce TSRMLS_DC);
      52             : ZEND_API char * zend_verify_arg_class_kind(const zend_arg_info *cur_arg_info, char **class_name, zend_class_entry **pce TSRMLS_DC);
      53             : 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);
      54             : 
      55             : static zend_always_inline int i_zend_is_true(zval *op TSRMLS_DC)
      56             : {
      57             :         int result;
      58             : 
      59             : again:
      60     2874404 :         switch (Z_TYPE_P(op)) {
      61             :                 case IS_UNDEF:
      62             :                 case IS_NULL:
      63             :                 case IS_FALSE:
      64      119576 :                         result = 0;
      65             :                         break;
      66             :                 case IS_TRUE:
      67       66011 :                         result = 1;
      68             :                         break;
      69             :                 case IS_LONG:
      70     2191460 :                         result = (Z_LVAL_P(op)?1:0);
      71             :                         break;
      72             :                 case IS_RESOURCE:
      73       40318 :                         result = (Z_RES_HANDLE_P(op)?1:0);
      74             :                         break;
      75             :                 case IS_DOUBLE:
      76          48 :                         result = (Z_DVAL_P(op) ? 1 : 0);
      77             :                         break;
      78             :                 case IS_STRING:
      79      155922 :                         if (Z_STRLEN_P(op) == 0
      80      101354 :                                 || (Z_STRLEN_P(op)==1 && Z_STRVAL_P(op)[0]=='0')) {
      81        8325 :                                 result = 0;
      82             :                         } else {
      83       46243 :                                 result = 1;
      84             :                         }
      85             :                         break;
      86             :                 case IS_ARRAY:
      87       97223 :                         result = (zend_hash_num_elements(Z_ARRVAL_P(op))?1:0);
      88             :                         break;
      89             :                 case IS_OBJECT:
      90       92354 :                         if (Z_OBJ_HT_P(op)->cast_object) {
      91             :                                 zval tmp;
      92       92354 :                                 if (Z_OBJ_HT_P(op)->cast_object(op, &tmp, _IS_BOOL TSRMLS_CC) == SUCCESS) {
      93       92353 :                                         result = Z_TYPE(tmp) == IS_TRUE;
      94             :                                         break;
      95             :                                 }
      96           1 :                                 zend_error(E_RECOVERABLE_ERROR, "Object of class %s could not be converted to boolean", Z_OBJ_P(op)->ce->name->val);
      97           0 :                         } else if (Z_OBJ_HT_P(op)->get) {
      98             :                                 zval rv;
      99           0 :                                 zval *tmp = Z_OBJ_HT_P(op)->get(op, &rv TSRMLS_CC);
     100           0 :                                 if (Z_TYPE_P(tmp) != IS_OBJECT) {
     101             :                                         /* for safety - avoid loop */
     102           0 :                                         convert_to_boolean(tmp);
     103           0 :                                         result = Z_TYPE_P(tmp) == IS_TRUE;
     104           0 :                                         zval_ptr_dtor(tmp);
     105             :                                         break;
     106             :                                 }
     107             :                         }
     108           0 :                         result = 1;
     109             :                         break;
     110             :                 case IS_REFERENCE:
     111      212846 :                         op = Z_REFVAL_P(op);
     112             :                         goto again;
     113             :                         break;
     114             :                 default:
     115           0 :                         result = 0;
     116             :                         break;
     117             :         }
     118     2661557 :         return result;
     119             : }
     120             : 
     121             : static zend_always_inline zval* zend_assign_to_variable(zval *variable_ptr, zval *value, zend_uchar value_type TSRMLS_DC)
     122             : {
     123             :         do {
     124    20065901 :                 if (UNEXPECTED(Z_REFCOUNTED_P(variable_ptr))) { 
     125             :                         zend_refcounted *garbage;
     126             : 
     127    12507202 :                         if (Z_ISREF_P(variable_ptr)) {
     128     2792205 :                                 variable_ptr = Z_REFVAL_P(variable_ptr);
     129     2792205 :                                 if (EXPECTED(!Z_REFCOUNTED_P(variable_ptr))) {
     130             :                                         break;
     131             :                                 }
     132             :                         }
     133    11582087 :                         if (Z_TYPE_P(variable_ptr) == IS_OBJECT &&
     134      860246 :                         UNEXPECTED(Z_OBJ_HANDLER_P(variable_ptr, set) != NULL)) {
     135           0 :                                 Z_OBJ_HANDLER_P(variable_ptr, set)(variable_ptr, value TSRMLS_CC);
     136           0 :                                 return variable_ptr;
     137             :                         }
     138    10721841 :                         if ((value_type & (IS_VAR|IS_CV)) && variable_ptr == value) {
     139         120 :                                 return variable_ptr;
     140             :                         }
     141    10721721 :                         garbage = Z_COUNTED_P(variable_ptr);
     142    10721721 :                         if (--GC_REFCOUNT(garbage) == 0) {
     143     5572974 :                                 ZVAL_COPY_VALUE(variable_ptr, value);
     144     5572974 :                                 if (value_type == IS_CONST) {
     145             :                                         /* IS_CONST can't be IS_OBJECT, IS_RESOURCE or IS_REFERENCE */
     146      109982 :                                         if (UNEXPECTED(Z_OPT_COPYABLE_P(variable_ptr))) {
     147       13804 :                                                 zval_copy_ctor_func(variable_ptr);
     148             :                                         }
     149     5462992 :                                 } else if (value_type != IS_TMP_VAR) {
     150     5382178 :                                         if (UNEXPECTED(Z_OPT_REFCOUNTED_P(variable_ptr))) {
     151             :                                                 Z_ADDREF_P(variable_ptr);
     152             :                                         }
     153             :                                 }
     154     5572974 :                                 _zval_dtor_func_for_ptr(garbage ZEND_FILE_LINE_CC);
     155     5572970 :                                 return variable_ptr;
     156             :                         } else { /* we need to split */
     157             :                                 /* optimized version of GC_ZVAL_CHECK_POSSIBLE_ROOT(variable_ptr) */
     158     5376152 :                                 if ((Z_COLLECTABLE_P(variable_ptr)) &&
     159      227405 :                                 UNEXPECTED(!GC_INFO(garbage))) {
     160       18257 :                                         gc_possible_root(garbage TSRMLS_CC);
     161             :                                 }
     162             :                         }
     163             :                 }
     164             :         } while (0);
     165             : 
     166    14492807 :         ZVAL_COPY_VALUE(variable_ptr, value);
     167    14492807 :         if (value_type == IS_CONST) {
     168             :                 /* IS_CONST can't be IS_OBJECT, IS_RESOURCE or IS_REFERENCE */
     169     3105821 :                 if (UNEXPECTED(Z_OPT_COPYABLE_P(variable_ptr))) {
     170      203771 :                         zval_copy_ctor_func(variable_ptr);
     171             :                 }
     172    11386986 :         } else if (value_type != IS_TMP_VAR) {
     173     8536534 :                 if (UNEXPECTED(Z_OPT_REFCOUNTED_P(variable_ptr))) {
     174             :                         Z_ADDREF_P(variable_ptr);
     175             :                 }
     176             :         }
     177    14492807 :         return variable_ptr;
     178             : }
     179             : 
     180             : ZEND_API int zval_update_constant(zval *pp, zend_bool inline_change TSRMLS_DC);
     181             : ZEND_API int zval_update_constant_inline_change(zval *pp, zend_class_entry *scope TSRMLS_DC);
     182             : ZEND_API int zval_update_constant_no_inline_change(zval *pp, zend_class_entry *scope TSRMLS_DC);
     183             : ZEND_API int zval_update_constant_ex(zval *pp, zend_bool inline_change, zend_class_entry *scope TSRMLS_DC);
     184             : 
     185             : /* dedicated Zend executor functions - do not use! */
     186             : struct _zend_vm_stack {
     187             :         zval *top;
     188             :         zval *end;
     189             :         zend_vm_stack prev;
     190             : };
     191             : 
     192             : #define ZEND_VM_STACK_HEADER_SLOTS \
     193             :         ((ZEND_MM_ALIGNED_SIZE(sizeof(struct _zend_vm_stack)) + ZEND_MM_ALIGNED_SIZE(sizeof(zval)) - 1) / ZEND_MM_ALIGNED_SIZE(sizeof(zval)))
     194             : 
     195             : #define ZEND_VM_STACK_ELEMETS(stack) \
     196             :         (((zval*)(stack)) + ZEND_VM_STACK_HEADER_SLOTS)
     197             : 
     198             : ZEND_API void zend_vm_stack_init(TSRMLS_D);
     199             : ZEND_API void zend_vm_stack_destroy(TSRMLS_D);
     200             : ZEND_API void* zend_vm_stack_extend(size_t size TSRMLS_DC);
     201             : 
     202             : static zend_always_inline zval* zend_vm_stack_alloc(size_t size TSRMLS_DC)
     203             : {
     204    19046409 :         char *top = (char*)EG(vm_stack_top);
     205             : 
     206    19046409 :         if (UNEXPECTED(size > (size_t)(((char*)EG(vm_stack_end)) - top))) {
     207           4 :                 return (zval*)zend_vm_stack_extend(size TSRMLS_CC);
     208             :         }
     209    19046405 :         EG(vm_stack_top) = (zval*)(top + size);
     210    19046405 :         return (zval*)top;
     211             : }
     212             : 
     213             : 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, zend_execute_data *prev TSRMLS_DC)
     214             : {
     215    19046409 :         uint32_t used_stack = ZEND_CALL_FRAME_SLOT + num_args;
     216             :         zend_execute_data *call;
     217             :         
     218    19046409 :         if (ZEND_USER_CODE(func->type)) {
     219     2086266 :                 used_stack += func->op_array.last_var + func->op_array.T - MIN(func->op_array.num_args, num_args);
     220             :         }
     221    38092818 :         call = (zend_execute_data*)zend_vm_stack_alloc(used_stack * sizeof(zval) TSRMLS_CC);
     222    19046409 :         call->func = func;
     223    19046409 :         Z_OBJ(call->This) = object;
     224    19046409 :         ZEND_SET_CALL_INFO(call, call_info);
     225    19046409 :         ZEND_CALL_NUM_ARGS(call) = 0;
     226    19046409 :         call->called_scope = called_scope;
     227    19046409 :         call->prev_execute_data = prev;
     228    19046409 :         return call;
     229             : }
     230             : 
     231             : static zend_always_inline void zend_vm_stack_free_extra_args(zend_execute_data *call TSRMLS_DC)
     232             : {
     233     2056373 :         uint32_t first_extra_arg = call->func->op_array.num_args - ((call->func->common.fn_flags & ZEND_ACC_VARIADIC) != 0);
     234             : 
     235     2056373 :         if (UNEXPECTED(ZEND_CALL_NUM_ARGS(call) > first_extra_arg)) {
     236        1089 :                 zval *end = ZEND_CALL_VAR_NUM(call, call->func->op_array.last_var + call->func->op_array.T);
     237        1089 :                 zval *p = end + (ZEND_CALL_NUM_ARGS(call) - first_extra_arg);
     238             :                 do {
     239       23144 :                         p--;
     240             :                         zval_ptr_dtor_nogc(p);
     241       23144 :                 } while (p != end);
     242             :         }
     243             : }
     244             : 
     245             : static zend_always_inline void zend_vm_stack_free_args(zend_execute_data *call TSRMLS_DC)
     246             : {
     247    16959853 :         uint32_t num_args = ZEND_CALL_NUM_ARGS(call);
     248             : 
     249    16959853 :         if (num_args > 0) {
     250    16384689 :                 zval *end = ZEND_CALL_ARG(call, 1);
     251    16384689 :                 zval *p = end + num_args;
     252             : 
     253             :                 do {
     254    30845618 :                         p--;
     255             :                         zval_ptr_dtor_nogc(p);
     256    30845618 :                 } while (p != end);
     257             :         }
     258             : }
     259             : 
     260             : static zend_always_inline void zend_vm_stack_free_call_frame(zend_execute_data *call TSRMLS_DC)
     261             : {
     262    19044126 :         zend_vm_stack p = EG(vm_stack);
     263    19044126 :         if (UNEXPECTED(ZEND_VM_STACK_ELEMETS(p) == (zval*)call)) {
     264           7 :                 zend_vm_stack prev = p->prev;
     265             : 
     266           7 :                 EG(vm_stack_top) = prev->top;
     267           7 :                 EG(vm_stack_end) = prev->end;
     268           7 :                 EG(vm_stack) = prev;
     269           7 :                 efree(p);
     270             :         } else {
     271    19044119 :                 EG(vm_stack_top) = (zval*)call;
     272             :         }
     273             : }
     274             : 
     275             : /* services */
     276             : ZEND_API const char *get_active_class_name(const char **space TSRMLS_DC);
     277             : ZEND_API const char *get_active_function_name(TSRMLS_D);
     278             : ZEND_API const char *zend_get_executed_filename(TSRMLS_D);
     279             : ZEND_API uint zend_get_executed_lineno(TSRMLS_D);
     280             : ZEND_API zend_bool zend_is_executing(TSRMLS_D);
     281             : 
     282             : ZEND_API void zend_set_timeout(zend_long seconds, int reset_signals);
     283             : ZEND_API void zend_unset_timeout(TSRMLS_D);
     284             : ZEND_API void zend_timeout(int dummy);
     285             : ZEND_API zend_class_entry *zend_fetch_class(zend_string *class_name, int fetch_type TSRMLS_DC);
     286             : ZEND_API zend_class_entry *zend_fetch_class_by_name(zend_string *class_name, const zval *key, int fetch_type TSRMLS_DC);
     287             : void zend_verify_abstract_class(zend_class_entry *ce TSRMLS_DC);
     288             : 
     289             : ZEND_API void zend_fetch_dimension_by_zval(zval *result, zval *container, zval *dim TSRMLS_DC);
     290             : 
     291             : #ifdef ZEND_WIN32
     292             : void zend_init_timeout_thread(void);
     293             : void zend_shutdown_timeout_thread(void);
     294             : #define WM_REGISTER_ZEND_TIMEOUT                (WM_USER+1)
     295             : #define WM_UNREGISTER_ZEND_TIMEOUT              (WM_USER+2)
     296             : #endif
     297             : 
     298             : ZEND_API zval* zend_get_compiled_variable_value(const zend_execute_data *execute_data_ptr, uint32_t var);
     299             : 
     300             : #define ZEND_USER_OPCODE_CONTINUE   0 /* execute next opcode */
     301             : #define ZEND_USER_OPCODE_RETURN     1 /* exit from executor (return from function) */
     302             : #define ZEND_USER_OPCODE_DISPATCH   2 /* call original opcode handler */
     303             : #define ZEND_USER_OPCODE_ENTER      3 /* enter into new op_array without recursion */
     304             : #define ZEND_USER_OPCODE_LEAVE      4 /* return to calling op_array within the same executor */
     305             : 
     306             : #define ZEND_USER_OPCODE_DISPATCH_TO 0x100 /* call original handler of returned opcode */
     307             : 
     308             : ZEND_API int zend_set_user_opcode_handler(zend_uchar opcode, user_opcode_handler_t handler);
     309             : ZEND_API user_opcode_handler_t zend_get_user_opcode_handler(zend_uchar opcode);
     310             : 
     311             : /* former zend_execute_locks.h */
     312             : typedef zval* zend_free_op;
     313             : 
     314             : 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);
     315             : 
     316             : ZEND_API int zend_do_fcall(ZEND_OPCODE_HANDLER_ARGS);
     317             : 
     318             : ZEND_API void zend_clean_and_cache_symbol_table(zend_array *symbol_table TSRMLS_DC);
     319             : void zend_free_compiled_variables(zend_execute_data *execute_data TSRMLS_DC);
     320             : 
     321             : #define CACHED_PTR(num) \
     322             :         EX(run_time_cache)[(num)]
     323             : 
     324             : #define CACHE_PTR(num, ptr) do { \
     325             :                 EX(run_time_cache)[(num)] = (ptr); \
     326             :         } while (0)
     327             : 
     328             : #define CACHED_POLYMORPHIC_PTR(num, ce) \
     329             :         ((EX(run_time_cache)[(num)] == (ce)) ? \
     330             :                 EX(run_time_cache)[(num) + 1] : \
     331             :                 NULL)
     332             : 
     333             : #define CACHE_POLYMORPHIC_PTR(num, ce, ptr) do { \
     334             :                 EX(run_time_cache)[(num)] = (ce); \
     335             :                 EX(run_time_cache)[(num) + 1] = (ptr); \
     336             :         } while (0)
     337             : 
     338             : #define CACHED_PTR_EX(slot) \
     339             :         (slot)[0]
     340             : 
     341             : #define CACHE_PTR_EX(slot, ptr) do { \
     342             :                 (slot)[0] = (ptr); \
     343             :         } while (0)
     344             : 
     345             : #define CACHED_POLYMORPHIC_PTR_EX(slot, ce) \
     346             :         (((slot)[0] == (ce)) ? (slot)[1] : NULL)
     347             : 
     348             : #define CACHE_POLYMORPHIC_PTR_EX(slot, ce, ptr) do { \
     349             :                 (slot)[0] = (ce); \
     350             :                 (slot)[1] = (ptr); \
     351             :         } while (0)
     352             : 
     353             : END_EXTERN_C()
     354             : 
     355             : #endif /* ZEND_EXECUTE_H */
     356             : 
     357             : /*
     358             :  * Local variables:
     359             :  * tab-width: 4
     360             :  * c-basic-offset: 4
     361             :  * indent-tabs-mode: t
     362             :  * End:
     363             :  */

Generated by: LCOV version 1.10

Generated at Sat, 13 Dec 2014 06:16:10 +0000 (4 days ago)

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