Changeset 291
- Timestamp:
- 02/13/07 16:11:14 (1 year ago)
- Files:
-
- eaccelerator/trunk/ChangeLog (modified) (1 diff)
- eaccelerator/trunk/ea_restore.c (modified) (8 diffs)
- eaccelerator/trunk/ea_store.c (modified) (21 diffs)
- eaccelerator/trunk/eaccelerator.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
eaccelerator/trunk/ChangeLog
r290 r291 5 5 * Fixed a nullpointer dereference in some special cases in ea_restore.c:509 6 6 * Always compile a ea_debug_error message in ea_restore.c 7 * Cleanup: Removed some commented out code, changed some debug statements, 8 reordered some conditional includes to reduce ifdef statements 7 9 8 10 2007-01-29 Bart Vanbrabant <bart.vanbrabant at zoeloelip.be> eaccelerator/trunk/ea_restore.c
r290 r291 583 583 } 584 584 #endif 585 to->opcodes = from->opcodes; 586 to->last = to->size = from->last; 587 to->T = from->T; 588 to->brk_cont_array = from->brk_cont_array; 589 to->last_brk_cont = from->last_brk_cont; 590 591 to->current_brk_cont = -1; 592 to->static_variables = from->static_variables; 593 /* to->start_op = to->opcodes; */ 594 to->backpatch_count = 0; 595 596 to->return_reference = from->return_reference; 597 to->done_pass_two = 1; 598 to->filename = from->filename; 599 /* if (from->filename != NULL) { 600 size_t len = strlen(from->filename) + 1; 601 to->filename = emalloc(len); 602 memcpy(to->filename, from->filename, len); 603 }*/ 604 605 #ifdef ZEND_ENGINE_2 606 /* HOESH: try & catch support */ 607 to->try_catch_array = from->try_catch_array; 608 to->last_try_catch = from->last_try_catch; 585 to->opcodes = from->opcodes; 586 to->last = to->size = from->last; 587 to->T = from->T; 588 to->brk_cont_array = from->brk_cont_array; 589 to->last_brk_cont = from->last_brk_cont; 590 591 to->current_brk_cont = -1; 592 to->static_variables = from->static_variables; 593 to->backpatch_count = 0; 594 595 to->return_reference = from->return_reference; 596 to->done_pass_two = 1; 597 to->filename = from->filename; 598 599 #ifdef ZEND_ENGINE_2 600 to->try_catch_array = from->try_catch_array; 601 to->last_try_catch = from->last_try_catch; 609 602 to->uses_this = from->uses_this; 610 603 … … 639 632 to->last_var = from->last_var; 640 633 to->size_var = 0; 641 /* if (from->vars) {642 zend_uint i;643 to->vars = (zend_compiled_variable*)emalloc(from->last_var*sizeof(zend_compiled_variable));644 memcpy(to->vars, from->vars, sizeof(zend_compiled_variable) * from->last_var);645 for (i = 0; i < from->last_var; i ++) {646 to->vars[i].name = estrndup(from->vars[i].name, from->vars[i].name_len);647 }648 }*/649 634 #endif 650 635 … … 795 780 memset(to, 0, sizeof(zend_class_entry)); 796 781 to->type = from->type; 797 /*798 to->name = NULL;799 to->name_length = from->name_length;800 to->constants_updated = 0;801 to->parent = NULL;802 */803 #ifdef ZEND_ENGINE_2804 to->ce_flags = from->ce_flags;805 to->num_interfaces = from->num_interfaces;806 to->interfaces = NULL;807 808 if (to->num_interfaces > 0) {809 /* hrak: Allocate the slots which will later be populated by ZEND_ADD_INTERFACE */810 to->interfaces = (zend_class_entry **) emalloc(sizeof(zend_class_entry *) * to->num_interfaces);811 memset(to->interfaces, 0, sizeof(zend_class_entry *) * to->num_interfaces);812 }813 #endif814 782 815 783 if (from->name != NULL) { … … 823 791 824 792 #ifdef ZEND_ENGINE_2 793 to->ce_flags = from->ce_flags; 794 to->num_interfaces = from->num_interfaces; 795 to->interfaces = NULL; 825 796 to->refcount = 1; 826 827 797 to->line_start = from->line_start; 828 798 to->line_end = from->line_end; 799 800 if (to->num_interfaces > 0) { 801 /* hrak: Allocate the slots which will later be populated by ZEND_ADD_INTERFACE */ 802 to->interfaces = (zend_class_entry **) emalloc(sizeof(zend_class_entry *) * to->num_interfaces); 803 memset(to->interfaces, 0, sizeof(zend_class_entry *) * to->num_interfaces); 804 } 829 805 #ifdef INCLUDE_DOC_COMMENTS 830 806 to->doc_comment_len = from->doc_comment_len; 807 if (from->doc_comment != NULL) { 808 to->doc_comment = emalloc(from->doc_comment_len + 1); 809 memcpy(to->doc_comment, from->doc_comment, from->doc_comment_len + 1); 810 } 831 811 #else 832 812 to->doc_comment_len = 0; 833 813 to->doc_comment = NULL; 834 814 #endif 835 /* if (from->filename != NULL) { 836 size_t len = strlen(from->filename) + 1; 837 to->filename = emalloc(len); 838 memcpy(to->filename, from->filename, len); 839 }*/ 840 to->filename = from->filename; 841 #ifdef INCLUDE_DOC_COMMENTS 842 if (from->doc_comment != NULL) { 843 to->doc_comment = emalloc(from->doc_comment_len + 1); 844 memcpy(to->doc_comment, from->doc_comment, from->doc_comment_len + 1); 845 } 846 #endif 815 816 to->filename = from->filename; 847 817 848 818 /* restore constants table */ … … 853 823 to->default_properties.pDestructor = ZVAL_PTR_DTOR; 854 824 /* restore properties */ 855 restore_hash(&to->properties_info, &from->properties_info, 856 (restore_bucket_t) restore_property_info TSRMLS_CC); 825 restore_hash(&to->properties_info, &from->properties_info, (restore_bucket_t) restore_property_info TSRMLS_CC); 857 826 to->properties_info.pDestructor = properties_info_dtor; 858 827 … … 891 860 } 892 861 #endif 862 893 863 if (from->parent != NULL) { 894 864 restore_class_parent(from->parent, strlen(from->parent), to TSRMLS_CC); … … 905 875 restore_class_methods(to TSRMLS_CC); 906 876 #endif 907 if (to->parent) 877 878 if (to->parent) { 908 879 #ifdef ZEND_ENGINE_2 909 880 zend_do_inheritance(to, to->parent TSRMLS_CC); … … 911 882 zend_do_inheritance(to, to->parent); 912 883 #endif 884 } 913 885 EAG(class_entry) = old; 914 886 eaccelerator/trunk/ea_store.c
r286 r291 191 191 EAG(compress) = 0; 192 192 for (; opline < end; opline++) { 193 /*194 if (opline->result.op_type == IS_CONST) calc_zval(&opline->result.u.constant TSRMLS_CC);195 */196 193 if (opline->op1.op_type == IS_CONST) 197 194 calc_zval(&opline->op1.u.constant TSRMLS_CC); … … 206 203 } 207 204 #ifdef ZEND_ENGINE_2 208 /* HOESH: try & catch support */209 205 if (from->try_catch_array != NULL) { 210 206 EACCELERATOR_ALIGN(EAG(mem)); … … 261 257 calc_zval_hash(&from->constants_table); 262 258 calc_zval_hash(&from->default_properties); 263 264 259 calc_hash(&from->properties_info, (calc_bucket_t) calc_property_info); 265 260 … … 592 587 to->last_try_catch = from->last_try_catch; 593 588 to->uses_this = from->uses_this; 589 if (from->try_catch_array != NULL) { 590 EACCELERATOR_ALIGN(EAG(mem)); 591 to->try_catch_array = (zend_try_catch_element *) EAG(mem); 592 EAG(mem) += sizeof(zend_try_catch_element) * from->last_try_catch; 593 memcpy(to->try_catch_array, from->try_catch_array, sizeof(zend_try_catch_element) * from->last_try_catch); 594 } else { 595 to->last_try_catch = 0; 596 } 594 597 #else 595 598 to->uses_globals = from->uses_globals; 596 599 #endif 600 597 601 to->static_variables = from->static_variables; 598 602 to->return_reference = from->return_reference; … … 609 613 EAG(compress) = 0; 610 614 for (; opline < end; opline++) { 611 /*612 if (opline->result.op_type == IS_CONST)613 store_zval(&opline->result.u.constant TSRMLS_CC);614 */615 615 if (opline->op1.op_type == IS_CONST) 616 616 store_zval(&opline->op1.u.constant TSRMLS_CC); … … 641 641 to->last_brk_cont = 0; 642 642 } 643 #ifdef ZEND_ENGINE_2 644 if (from->try_catch_array != NULL) { 645 EACCELERATOR_ALIGN(EAG(mem)); 646 to->try_catch_array = (zend_try_catch_element *) EAG(mem); 647 EAG(mem) += sizeof(zend_try_catch_element) * from->last_try_catch; 648 memcpy(to->try_catch_array, from->try_catch_array, sizeof(zend_try_catch_element) * from->last_try_catch); 649 } else { 650 to->last_try_catch = 0; 651 } 652 #endif 643 653 644 if (from->static_variables != NULL) { 654 645 EACCELERATOR_ALIGN(EAG(mem)); … … 672 663 to->vars = NULL; 673 664 } 674 #endif 675 if (from->filename != NULL) { 676 to->filename = store_string(from->filename, strlen(from->filename) + 1 TSRMLS_CC); 677 } 678 #ifdef ZEND_ENGINE_2 679 to->line_start = from->line_start; 680 to->line_end = from->line_end; 681 #ifdef INCLUDE_DOC_COMMENTS 665 to->line_start = from->line_start; 666 to->line_end = from->line_end; 667 # ifdef INCLUDE_DOC_COMMENTS 682 668 to->doc_comment_len = from->doc_comment_len; 683 669 if (from->doc_comment != NULL) 684 670 to->doc_comment = store_string(from->doc_comment, from->doc_comment_len + 1 TSRMLS_CC); 685 #endif 686 #endif 671 # endif 672 #endif 673 674 if (from->filename != NULL) { 675 to->filename = store_string(from->filename, strlen(from->filename) + 1 TSRMLS_CC); 676 } 687 677 return to; 688 678 } … … 698 688 to->name = store_string(from->name, from->name_length + 1 TSRMLS_CC); 699 689 #ifdef ZEND_ENGINE_2_1 700 # ifdef INCLUDE_DOC_COMMENTS701 to->doc_comment_len = from->doc_comment_len;702 if (from->doc_comment != NULL) {690 # ifdef INCLUDE_DOC_COMMENTS 691 to->doc_comment_len = from->doc_comment_len; 692 if (from->doc_comment != NULL) { 703 693 to->doc_comment = store_string(from->doc_comment, from->doc_comment_len + 1 TSRMLS_CC); 704 }705 # else694 } 695 # else 706 696 to->doc_comment_len = 0; 707 697 to->doc_comment = NULL; … … 816 806 to->name_length = from->name_length; 817 807 to->parent = NULL; 818 #ifdef ZEND_ENGINE_2819 to->ce_flags = from->ce_flags;820 to->static_members = NULL;821 822 /*823 * Scan the interfaces looking for the first one which isn't 0824 * This is the first inherited interface and should not be counted in the stored object825 */826 for (i = 0 ; i < from->num_interfaces ; i++) {827 if (from->interfaces[i] != 0) {828 break;829 }830 }831 to->num_interfaces = i;832 DBG(ea_debug_printf, (EA_DEBUG, "from->num_interfaces=%d, to->num_interfaces=%d\n", from->num_interfaces, to->num_interfaces));833 834 /*835 * hrak: no need to really store the interfaces since these get populated836 * at/after restore by zend_do_inheritance and ZEND_ADD_INTERFACE837 */838 #endif839 808 840 809 DBG(ea_debug_pad, (EA_DEBUG TSRMLS_CC)); … … 846 815 #endif 847 816 848 if (from->name != NULL) 817 if (from->name != NULL) { 849 818 to->name = store_string(from->name, from->name_length + 1 TSRMLS_CC); 850 if (from->parent != NULL && from->parent->name) 851 to->parent = store_string(from->parent->name, from->parent->name_length + 1 TSRMLS_CC); 852 853 #ifdef ZEND_ENGINE_2 819 } 820 if (from->parent != NULL && from->parent->name) { 821 to->parent = store_string(from->parent->name, from->parent->name_length + 1 TSRMLS_CC); 822 } 823 824 #ifdef ZEND_ENGINE_2 /* php >= 5.0 */ 825 to->ce_flags = from->ce_flags; 826 to->static_members = NULL; 827 828 /* 829 * Scan the interfaces looking for the first one which isn't 0 830 * This is the first inherited interface and should not be counted in the stored object 831 */ 832 for (i = 0 ; i < from->num_interfaces ; i++) { 833 if (from->interfaces[i] != 0) { 834 break; 835 } 836 } 837 to->num_interfaces = i; 838 839 /* 840 * hrak: no need to really store the interfaces since these get populated 841 * at/after restore by zend_do_inheritance and ZEND_ADD_INTERFACE 842 */ 843 854 844 to->line_start = from->line_start; 855 845 to->line_end = from->line_end; … … 867 857 store_zval_hash(&to->constants_table, &from->constants_table); 868 858 store_zval_hash(&to->default_properties, &from->default_properties); 869 //store_hash(&to->properties_info, &from->properties_info, (store_bucket_t) store_property_info, NULL, NULL);870 859 store_hash(&to->properties_info, &from->properties_info, (store_bucket_t) store_property_info, (check_bucket_t) store_property_access_check, from); 871 # ifdef ZEND_ENGINE_2_1 872 if((from->static_members != NULL) && (from->static_members != &from->default_static_members)) { 860 861 # ifdef ZEND_ENGINE_2_1 /* php >= 5.1 */ 862 if ((from->static_members != NULL) && (from->static_members != &from->default_static_members)) { 873 863 store_zval_hash(&to->default_static_members, &from->default_static_members); 874 864 EACCELERATOR_ALIGN(EAG(mem)); … … 877 867 store_hash(to->static_members, from->static_members, (store_bucket_t) store_zval_ptr, (check_bucket_t) store_static_member_access_check, from); 878 868 } else { 879 /*EACCELERATOR_ALIGN(EAG(mem));880 to->static_members = (HashTable *) EAG(mem);881 EAG(mem) += sizeof(HashTable);*/882 869 store_hash(&to->default_static_members, &from->default_static_members, (store_bucket_t) store_zval_ptr, (check_bucket_t) store_static_member_access_check, from); 883 870 to->static_members = &to->default_static_members; 884 871 } 885 # elif defined(ZEND_ENGINE_2) && !defined(ZEND_ENGINE_2_1) 886 /* for php-5.0 */ 887 if(from->static_members != NULL) { 872 # else /* php == 5.0 */ 873 if (from->static_members != NULL) { 888 874 EACCELERATOR_ALIGN(EAG(mem)); 889 875 to->static_members = (HashTable *) EAG(mem); … … 892 878 } 893 879 # endif 894 #else 880 store_hash(&to->function_table, &from->function_table, (store_bucket_t) store_op_array, (check_bucket_t) store_function_inheritance_check, from); 881 882 #else /* PHP 4 */ 895 883 store_zval_hash(&to->default_properties, &from->default_properties); 896 #endif 897 898 #ifdef ZEND_ENGINE_2 899 store_hash(&to->function_table, &from->function_table, (store_bucket_t) store_op_array, (check_bucket_t) store_function_inheritance_check, from); 900 #else 901 store_hash(&to->function_table, &from->function_table, (store_bucket_t) store_op_array, NULL, NULL); 884 store_hash(&to->function_table, &from->function_table, (store_bucket_t) store_op_array, NULL, NULL); 902 885 #endif 903 886 … … 911 894 /* Create a cache entry from the given op_array, functions and classes of a 912 895 script */ 913 ea_cache_entry *eaccelerator_store_int (char *key, int len,896 ea_cache_entry *eaccelerator_store_int(char *key, int len, 914 897 zend_op_array *op_array, Bucket *f, Bucket *c TSRMLS_DC) 915 898 { … … 920 903 921 904 DBG(ea_debug_pad, (EA_DEBUG TSRMLS_CC)); 922 DBG(ea_debug_printf, (EA_DEBUG, "[%d] eaccelerator_store_int: key='%s'\n", 923 getpid (), key)); 924 925 EAG (compress) = 1; 926 zend_hash_init (&EAG (strings), 0, NULL, NULL, 0); 905 DBG(ea_debug_printf, (EA_DEBUG, "[%d] eaccelerator_store_int: key='%s'\n", getpid (), key)); 906 907 EAG(compress) = 1; 908 zend_hash_init(&EAG(strings), 0, NULL, NULL, 0); 927 909 p = (ea_cache_entry *) EAG (mem); 928 EAG (mem) += offsetof(ea_cache_entry, realfilename) + len + 1;910 EAG(mem) += offsetof(ea_cache_entry, realfilename) + len + 1; 929 911 930 912 p->nhits = 0; … … 933 915 p->f_head = NULL; 934 916 p->c_head = NULL; 935 memcpy (p->realfilename, key, len + 1);917 memcpy(p->realfilename, key, len + 1); 936 918 x = p->realfilename; 937 zend_hash_add (&EAG (strings), key, len + 1, &x, sizeof(char *), NULL);919 zend_hash_add(&EAG(strings), key, len + 1, &x, sizeof(char *), NULL); 938 920 939 921 q = NULL; 940 922 while (c != NULL) { 941 923 DBG(ea_debug_pad, (EA_DEBUG TSRMLS_CC)); 942 DBG(ea_debug_printf, (EA_DEBUG, 943 "[%d] eaccelerator_store_int: class hashkey=", getpid ())); 924 DBG(ea_debug_printf, (EA_DEBUG, "[%d] eaccelerator_store_int: class hashkey=", getpid ())); 944 925 DBG(ea_debug_binary_print, (EA_DEBUG, c->arKey, c->nKeyLength)); 945 926 946 EACCELERATOR_ALIGN (EAG(mem));947 fc = (ea_fc_entry *) EAG (mem);948 EAG (mem) += offsetof(ea_fc_entry, htabkey) + c->nKeyLength;949 memcpy (fc->htabkey, c->arKey, c->nKeyLength);927 EACCELERATOR_ALIGN(EAG(mem)); 928 fc = (ea_fc_entry *) EAG(mem); 929 EAG(mem) += offsetof(ea_fc_entry, htabkey) + c->nKeyLength; 930 memcpy(fc->htabkey, c->arKey, c->nKeyLength); 950 931 fc->htablen = c->nKeyLength; 951 932 fc->next = NULL; … … 957 938 c = c->pListNext; 958 939 x = fc->htabkey; 959 zend_hash_add (&EAG (strings), fc->htabkey, fc->htablen, &x, 960 sizeof (char *), NULL); 940 zend_hash_add(&EAG(strings), fc->htabkey, fc->htablen, &x, sizeof(char *), NULL); 961 941 if (q == NULL) { 962 942 p->c_head = fc; … … 970 950 while (f != NULL) { 971 951 DBG(ea_debug_pad, (EA_DEBUG TSRMLS_CC)); 972 DBG(ea_debug_printf, (EA_DEBUG, 973 "[%d] eaccelerator_store_int: function hashkey='%s'\n", getpid (), f->arKey)); 974 975 EACCELERATOR_ALIGN (EAG (mem)); 976 fc = (ea_fc_entry *) EAG (mem); 977 EAG (mem) += offsetof (ea_fc_entry, htabkey) + f->nKeyLength; 978 memcpy (fc->htabkey, f->arKey, f->nKeyLength); 952 DBG(ea_debug_printf, (EA_DEBUG, "[%d] eaccelerator_store_int: function hashkey='%s'\n", getpid (), f->arKey)); 953 954 EACCELERATOR_ALIGN(EAG(mem)); 955 fc = (ea_fc_entry *) EAG(mem); 956 EAG(mem) += offsetof (ea_fc_entry, htabkey) + f->nKeyLength; 957 memcpy(fc->htabkey, f->arKey, f->nKeyLength); 979 958 fc->htablen = f->nKeyLength; 980 959 fc->next = NULL; … … 982 961 f = f->pListNext; 983 962 x = fc->htabkey; 984 zend_hash_add (&EAG (strings), fc->htabkey, fc->htablen, &x, 985 sizeof (char *), NULL); 963 zend_hash_add(&EAG(strings), fc->htabkey, fc->htablen, &x, sizeof(char *), NULL); 986 964 if (q == NULL) { 987 965 p->f_head = fc; … … 994 972 q = p->c_head; 995 973 while (q != NULL) { 996 q->fc = store_class_entry ((zend_class_entry *) q->fc TSRMLS_CC);974 q->fc = store_class_entry((zend_class_entry *) q->fc TSRMLS_CC); 997 975 q = q->next; 998 976 } … … 1000 978 q = p->f_head; 1001 979 while (q != NULL) { 1002 q->fc = store_op_array ((zend_op_array *) q->fc TSRMLS_CC);980 q->fc = store_op_array((zend_op_array *) q->fc TSRMLS_CC); 1003 981 q = q->next; 1004 982 } 1005 p->op_array = store_op_array (op_array TSRMLS_CC);1006 1007 zend_hash_destroy (&EAG(strings));983 p->op_array = store_op_array(op_array TSRMLS_CC); 984 985 zend_hash_destroy(&EAG(strings)); 1008 986 return p; 1009 987 } eaccelerator/trunk/eaccelerator.c
r287 r291 803 803 return 0; 804 804 } 805 DBG(ea_debug_printf, (EA_DEBUG, "[%d] eaccelerator_store: calc_size returned %d, mm=%x", getpid(), size, eaccelerator_mm_instance->mm)); 805 806 DBG(ea_debug_pad, (EA_DEBUG TSRMLS_CC)); 807 DBG(ea_debug_printf, (EA_DEBUG, "[%d] eaccelerator_store: returned %d, mm=%x\n", getpid(), size, eaccelerator_mm_instance->mm)); 808 806 809 EACCELERATOR_UNPROTECT(); 807 810 EAG(mem) = eaccelerator_malloc(size); … … 1361 1364 for (i=0;i<EAG(profile_level);i++) 1362 1365 DBG(ea_debug_put, (EA_PROFILE_OPCODES, " ")); 1363 ea_debug_printf(EA_DEBUG, "zend_op_array compile: %s (%ld)\n", file_handle->filename, usec);1364 1366 return t; 1365 1367 }