Use 'const' qualifier for pointrs to code used at run-time (the code must not be...
authorDmitry Stogov <dmitry@zend.com>
Wed, 27 Aug 2014 22:44:06 +0000 (02:44 +0400)
committerDmitry Stogov <dmitry@zend.com>
Wed, 27 Aug 2014 22:44:06 +0000 (02:44 +0400)
Zend/zend.c
Zend/zend_compile.c
Zend/zend_compile.h
Zend/zend_execute.c
Zend/zend_globals.h
Zend/zend_vm_def.h
Zend/zend_vm_execute.h
Zend/zend_vm_gen.php
ext/opcache/ZendAccelerator.h

index edb04cdf39074731a05fe6bca94674dba8293661..5a3f904f9f5342dd78aa23f72e6a82034cf4816e 100644 (file)
@@ -1029,7 +1029,7 @@ ZEND_API void zend_error(int type, const char *format, ...) /* {{{ */
        /* Report about uncaught exception in case of fatal errors */
        if (EG(exception)) {
                zend_execute_data *ex;
-               zend_op *opline;
+               const zend_op *opline;
 
                switch (type) {
                        case E_CORE_ERROR:
index 40a59167b1cf6e076e936efd42e2aca0695dd8f3..47d38c5ee57d8dc03f4ab945e2cd4f676b095b08 100644 (file)
@@ -2475,7 +2475,7 @@ ZEND_API void zend_do_bind_traits(zend_class_entry *ce TSRMLS_DC) /* {{{ */
 }
 /* }}} */
 
-ZEND_API int do_bind_function(const zend_op_array *op_array, zend_op *opline, HashTable *function_table, zend_bool compile_time TSRMLS_DC) /* {{{ */
+ZEND_API int do_bind_function(const zend_op_array *op_array, const zend_op *opline, HashTable *function_table, zend_bool compile_time TSRMLS_DC) /* {{{ */
 {
        zend_function *function, *new_function;
        zval *op1, *op2;
index 4325711dd203c8c1e8d98c80bcb2779a762cd6a4..4fe18b9166cdb03177d4cd579930bbd2088bbcb7 100644 (file)
@@ -362,7 +362,7 @@ typedef enum _vm_frame_kind {
 } vm_frame_kind;
 
 struct _zend_execute_data {
-       struct _zend_op     *opline;           /* executed opline                */
+       const zend_op       *opline;           /* executed opline                */
        zend_execute_data   *call;             /* current call                   */
        void               **run_time_cache;
        zend_function       *func;             /* executed op_array              */
@@ -376,7 +376,7 @@ struct _zend_execute_data {
        zval                *return_value;
        zend_class_entry    *scope;            /* function scope (self)          */
        zend_array          *symbol_table;
-       struct _zend_op     *fast_ret; /* used by FAST_CALL/FAST_RET (finally keyword) */
+       const zend_op       *fast_ret; /* used by FAST_CALL/FAST_RET (finally keyword) */
        zend_object         *delayed_exception;
        zval                 old_error_reporting;
 };
@@ -453,7 +453,7 @@ void zend_handle_encoding_declaration(zend_ast_list *declares TSRMLS_DC);
 /* parser-driven code generators */
 void zend_do_free(znode *op1 TSRMLS_DC);
 
-ZEND_API int do_bind_function(const zend_op_array *op_array, zend_op *opline, HashTable *function_table, zend_bool compile_time TSRMLS_DC);
+ZEND_API int do_bind_function(const zend_op_array *op_array, const zend_op *opline, HashTable *function_table, zend_bool compile_time TSRMLS_DC);
 ZEND_API zend_class_entry *do_bind_class(const zend_op_array *op_array, const zend_op *opline, HashTable *class_table, zend_bool compile_time TSRMLS_DC);
 ZEND_API zend_class_entry *do_bind_inherited_class(const zend_op_array *op_array, const zend_op *opline, HashTable *class_table, zend_class_entry *parent_ce, zend_bool compile_time TSRMLS_DC);
 ZEND_API void zend_do_inherit_interfaces(zend_class_entry *ce, const zend_class_entry *iface TSRMLS_DC);
index 7278fa9533facfd1988aefc3d451a013b62c8081..d3d01797d766e975720a48cff37889ecfad02f99 100644 (file)
@@ -668,7 +668,7 @@ static void zend_verify_missing_arg(zend_execute_data *execute_data, uint32_t ar
        }
 }
 
-static inline void zend_assign_to_object(zval *retval, zval *object_ptr, zval *property_name, int value_type, znode_op *value_op, const zend_execute_data *execute_data, int opcode, void **cache_slot TSRMLS_DC)
+static inline void zend_assign_to_object(zval *retval, zval *object_ptr, zval *property_name, int value_type, const znode_op *value_op, const zend_execute_data *execute_data, int opcode, void **cache_slot TSRMLS_DC)
 {
        zend_free_op free_value;
        zval *value = get_zval_ptr(value_type, value_op, execute_data, &free_value, BP_VAR_R);
@@ -1751,7 +1751,7 @@ ZEND_API void zend_init_execute_data(zend_execute_data *execute_data, zend_op_ar
 }
 /* }}} */
 
-static zend_always_inline zend_bool zend_is_by_ref_func_arg_fetch(zend_op *opline, zend_execute_data *call TSRMLS_DC) /* {{{ */
+static zend_always_inline zend_bool zend_is_by_ref_func_arg_fetch(const zend_op *opline, zend_execute_data *call TSRMLS_DC) /* {{{ */
 {
        uint32_t arg_num = opline->extended_value & ZEND_FETCH_ARG_MASK;
        return ARG_SHOULD_BE_SENT_BY_REF(call->func, arg_num);
index 18543aecfe88a6edf1d4ce68786af07a9ee6a060..266941c3202c49311ed91176971fb914ab5a815e 100644 (file)
@@ -219,7 +219,7 @@ struct _zend_executor_globals {
 
        zend_objects_store objects_store;
        zend_object *exception, *prev_exception;
-       zend_op *opline_before_exception;
+       const zend_op *opline_before_exception;
        zend_op exception_op[3];
 
        struct _zend_execute_data *current_execute_data;
index ff1a50376846dcf9806fe6703796f27ddc6845cb..230c84194e59a01797d70386b0d859c5c110ec79 100644 (file)
@@ -1815,7 +1815,7 @@ ZEND_VM_HELPER(zend_leave_helper, ANY, ANY)
                EG(scope) = EX(scope);
 
                if (UNEXPECTED(EG(exception) != NULL)) {
-                       zend_op *opline = EX(opline);
+                       const zend_op *opline = EX(opline);
                        zend_throw_exception_internal(NULL TSRMLS_CC);
                        if (RETURN_VALUE_USED(opline)) {
                                zval_ptr_dtor(EX_VAR(opline->result.var));
index 0780ded01fa9720a406e904ff5da0bce443c2cdb..7b5ad6b10fb4f40a57ce731d9440d885bfe9eb69 100644 (file)
@@ -306,7 +306,7 @@ static zend_uchar zend_user_opcodes[256] = {0,
        241,242,243,244,245,246,247,248,249,250,251,252,253,254,255
 };
 
-static opcode_handler_t zend_vm_get_opcode_handler(zend_uchar opcode, zend_op* op);
+static opcode_handler_t zend_vm_get_opcode_handler(zend_uchar opcode, const zend_op* op);
 
 
 #undef OPLINE
@@ -316,7 +316,7 @@ static opcode_handler_t zend_vm_get_opcode_handler(zend_uchar opcode, zend_op* o
 #undef SAVE_OPLINE
 #define OPLINE EX(opline)
 #define DCL_OPLINE
-#define USE_OPLINE zend_op *opline = EX(opline);
+#define USE_OPLINE const zend_op *opline = EX(opline);
 #define LOAD_OPLINE()
 #define SAVE_OPLINE()
 #undef CHECK_EXCEPTION
@@ -420,7 +420,7 @@ static int ZEND_FASTCALL zend_leave_helper_SPEC(ZEND_OPCODE_HANDLER_ARGS)
                EG(scope) = EX(scope);
 
                if (UNEXPECTED(EG(exception) != NULL)) {
-                       zend_op *opline = EX(opline);
+                       const zend_op *opline = EX(opline);
                        zend_throw_exception_internal(NULL TSRMLS_CC);
                        if (RETURN_VALUE_USED(opline)) {
                                zval_ptr_dtor(EX_VAR(opline->result.var));
@@ -47851,7 +47851,7 @@ void zend_init_opcodes_handlers(void)
   };
   zend_opcode_handlers = (opcode_handler_t*)labels;
 }
-static opcode_handler_t zend_vm_get_opcode_handler(zend_uchar opcode, zend_op* op)
+static opcode_handler_t zend_vm_get_opcode_handler(zend_uchar opcode, const zend_op* op)
 {
                static const int zend_vm_decode[] = {
                        _UNUSED_CODE, /* 0              */
index a65963ce915f2618c38a4d3bedbb937d256b8f1f..e9510535f79c33f195ef51baba88bce971be276d 100644 (file)
@@ -884,7 +884,7 @@ function gen_executor($f, $skl, $spec, $kind, $executor_name, $initializer_name,
                                        if (ZEND_VM_OLD_EXECUTOR && $spec) {
                                                out($f,"static int zend_vm_old_executor = 0;\n\n");
                                        }
-                                       out($f,"static opcode_handler_t zend_vm_get_opcode_handler(zend_uchar opcode, zend_op* op);\n\n");
+                                       out($f,"static opcode_handler_t zend_vm_get_opcode_handler(zend_uchar opcode, const zend_op* op);\n\n");
                                        switch ($kind) {
                                                case ZEND_VM_KIND_CALL:
                                                        out($f,"\n");                                                           
@@ -895,7 +895,7 @@ function gen_executor($f, $skl, $spec, $kind, $executor_name, $initializer_name,
                                                        out($f,"#undef SAVE_OPLINE\n");
                                                        out($f,"#define OPLINE EX(opline)\n");
                                                        out($f,"#define DCL_OPLINE\n");
-                                                       out($f,"#define USE_OPLINE zend_op *opline = EX(opline);\n");
+                                                       out($f,"#define USE_OPLINE const zend_op *opline = EX(opline);\n");
                                                        out($f,"#define LOAD_OPLINE()\n");
                                                        out($f,"#define SAVE_OPLINE()\n");
                                                        out($f,"#undef CHECK_EXCEPTION\n");
@@ -1333,7 +1333,7 @@ function gen_vm($def, $skel) {
        }
 
        // Generate zend_vm_get_opcode_handler() function
-       out($f, "static opcode_handler_t zend_vm_get_opcode_handler(zend_uchar opcode, zend_op* op)\n");
+       out($f, "static opcode_handler_t zend_vm_get_opcode_handler(zend_uchar opcode, const zend_op* op)\n");
        out($f, "{\n");
        if (!ZEND_VM_SPEC) {
                out($f, "\treturn zend_opcode_handlers[opcode];\n");
@@ -1386,7 +1386,7 @@ function gen_vm($def, $skel) {
                out($f,"#undef SAVE_OPLINE\n");
                out($f,"#define OPLINE EX(opline)\n");
                out($f,"#define DCL_OPLINE\n");
-               out($f,"#define USE_OPLINE zend_op *opline = EX(opline);\n");
+               out($f,"#define USE_OPLINE const zend_op *opline = EX(opline);\n");
                out($f,"#define LOAD_OPLINE()\n");
                out($f,"#define SAVE_OPLINE()\n");
                out($f,"#undef CHECK_EXCEPTION\n");
index 29b796698cffe07709ed0290e13cf26689872822..c3c7285c48cdfc8f5227e4fde7874843afba34fb 100644 (file)
@@ -235,7 +235,7 @@ typedef struct _zend_accel_globals {
        /* preallocated shared-memory block to save current script */
        void                   *mem;
        /* cache to save hash lookup on the same INCLUDE opcode */
-       zend_op                *cache_opline;
+       const zend_op          *cache_opline;
        zend_persistent_script *cache_persistent_script;
        /* preallocated buffer for keys */
        int                     key_len;