Changeset 162

Show
Ignore:
Timestamp:
02/17/06 18:35:50 (3 years ago)
Author:
zoeloelip
Message:

Merged PHP_5_1 branch with HEAD

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • eaccelerator/trunk/AUTHORS

    r150 r162  
    22- Franck Tabary <franck34 at users.sourceforge.net> 
    33- Bart Vanbrabant <zoeloelip at users.sourceforge.net> 
     4- Hans Rakers <hrak at users.sourceforge.net> 
    45 
    56Inactive member(s) : 
  • eaccelerator/trunk/ChangeLog

    r159 r162  
     12006-02-16  Bart Vanbrabant <bart.vanbrabant at zoeloelip.be> 
     2 
     3        * Merged PHP_5_1 branch with HEAD 
     4 
     52006-02-17  Hans Rakers <hans at parse dot nl> 
     6 
     7        * PHP_5_1: Some final fixes before merging to HEAD: 
     8          - Fixed bug #1410723 (handling of class constants by the optimizer) 
     9          - Fixed backwards compatibility with PHP < 5.1 
     10          This revision works pretty well in my testing environment, PHP-5.1 support 
     11          seems to be coming along quite well. Please test with your applications/ 
     12          in your environment and report back with your experiences or possible problems! 
     13 
    1142006-02-15 Bart Vanbrabant <bart.vanbrabant at zoeloelip.be> 
    215 
    316        * Released version 0.9.4 
     17 
     182006-02-15  Hans Rakers <hans at parse dot nl> 
     19 
     20        * PHP_5_1: Fixes for five failing tests found using the test suite created by Bart 
     21          Tests that failed where: 
     22          -ctor_dtor_inheritance (failed because __construct, __destruct and __clone were not properly set) 
     23          -destructor_and_exceptions (failed because inheritance of parent methods was broken, fixed by making sure ea_store doesn't store methods outside scope) 
     24          -inheritance_002 (failed because __construct, __destruct and __clone were not properly set) 
     25          -private_members (failed because __construct, __destruct and __clone were not properly set) 
     26          -type_hinting_003 (failed because array_type_hint introduced in zend_arg_info in PHP-5.1 was ignored) 
     27 
     282006-02-14  Bart Vanbrabant <bart.vanbrabant at zoeloelip dot be> 
     29 
     30        * PHP_5_1: Changed cflags to -O2 from -O3 
    431 
    5322006-02-09 Bart Vanbrabant <bart.vanbrabant at zoeloelip.be> 
     
    2148        * Updated NEWS and bumped up version to 0.9.4-rc2 
    2249        * Released 0.9.4-rc2 
     50 
     512006-02-07  Hans Rakers <hans at parse dot nl> 
     52 
     53        * PHP_5_1: Fix for problems with __autoload 
     54        * PHP_5_1: Fixed compile problems with thread-safe PHP 
     55 
     562006-02-06  Hans Rakers <hans at parse dot nl> 
     57 
     58        * PHP_5_1: Quite some major changes, including but probably not limited to: 
     59          -Fixed numerous memory leaks 
     60          -Fixed the handling of empty string variables (as in ""), causing "String is not zero-terminated" warnings when PHP is compiled with --enable-debug 
     61          -More fixes to the handling of static properties (access checking/inheritance) 
     62          -Inheritance on restore is now handled by zend_do_inheritance 
     63          -Fixed handling of ZEND_OP_DATA and ZEND_INIT_METHOD_CALL by the optimizer 
     64          -Cosmetic fixes (spelling etc.) 
     65 
     662006-01-16  Hans Rakers <hans at parse dot nl> 
     67 
     68        * PHP_5_1: Fix for bug #1401474 (and most likely some more php-5.1 related trouble) 
     69          static_members handling was incorrect. 
     70 
     712006-01-12  Hans Rakers <hans at parse dot nl> 
     72 
     73        * First batch of PHP-5.1 related changes committed to the newly created 
     74          PHP_5_1 branch. This is a work in progress, so YMMV. 
    2375 
    24762006-01-10 Bart Vanbrabant <bart.vanbrabant at zoeloelip.be> 
  • eaccelerator/trunk/Makefile.in

    r134 r162  
    33LTLIBRARY_SHARED_NAME = eaccelerator.la 
    44 
    5 EXTRA_CFLAGS = -O3 
     5EXTRA_CFLAGS = -O2 
    66 
    77include $(top_srcdir)/build/dynlib.mk 
  • eaccelerator/trunk/content.c

    r123 r162  
    594594        eaccelerator_content_cache_place != eaccelerator_none) { 
    595595 
     596#ifndef ZEND_ENGINE_2_1 
     597/* Doesn't work with php >= 5.1.0 */ 
    596598      /* clean garbage */ 
    597599      while (EG(garbage_ptr)) { 
    598600        zval_ptr_dtor(&EG(garbage)[--EG(garbage_ptr)]); 
    599601      } 
     602#endif 
    600603 
    601604      eaccelerator_put(key, key_len, return_value, ttl, eaccelerator_content_cache_place TSRMLS_CC); 
  • eaccelerator/trunk/debug.c

    r144 r162  
    291291} 
    292292 
     293/* 
     294 * This dumps a HashTable to debug output. Taken from zend_hash.c and slightly adapted. 
     295 */ 
     296void ea_debug_hash_display(HashTable * ht) 
     297{ 
     298        Bucket *p; 
     299        uint i; 
     300 
     301        fprintf(F_fp, "ht->nTableSize: %d\n", ht->nTableSize); 
     302        fprintf(F_fp, "ht->nNumOfElements: %d\n", ht->nNumOfElements); 
     303 
     304        for (i = 0; i < ht->nTableSize; i++) { 
     305                p = ht->arBuckets[i]; 
     306                while (p != NULL) { 
     307                        fprintf(F_fp, "%s <==> 0x%lX\n", p->arKey, p->h); 
     308                        p = p->pNext; 
     309                } 
     310        } 
     311 
     312        p = ht->pListTail; 
     313        while (p != NULL) { 
     314                fprintf(F_fp, "%s <==> 0x%lX\n", p->arKey, p->h); 
     315                p = p->pListLast; 
     316        } 
     317        fflush(F_fp); 
     318} 
     319 
    293320#endif /* #ifdef HAVE_EACCELERATOR */ 
  • eaccelerator/trunk/debug.h

    r122 r162  
    7272long ea_debug_elapsed_time (struct timeval *tvstart); 
    7373 
     74void ea_debug_hash_display(HashTable * ht); 
     75 
    7476#endif /* INCLUDED_DEBUG_H */ 
  • eaccelerator/trunk/ea_restore.c

    r127 r162  
    4040#include "zend_API.h" 
    4141#include "zend_extensions.h" 
     42#ifdef ZEND_ENGINE_2_1 
     43#include "zend_vm.h" 
     44#endif 
    4245 
    4346#ifndef INCOMPLETE_CLASS 
     
    7073 
    7174        zend_hash_destroy(&dummy_class_entry.default_properties); 
     75        zend_hash_destroy(&dummy_class_entry.function_table); 
     76        zend_hash_destroy(&dummy_class_entry.constants_table); 
    7277        zend_hash_destroy(&dummy_class_entry.properties_info); 
     78#  ifdef ZEND_ENGINE_2_1 
     79        zend_hash_destroy(&dummy_class_entry.default_static_members); 
     80#  endif 
     81#  if defined(ZEND_ENGINE_2) && !defined(ZEND_ENGINE_2_1) 
    7382        zend_hash_destroy(dummy_class_entry.static_members); 
    74         zend_hash_destroy(&dummy_class_entry.function_table); 
    75         FREE_HASHTABLE(dummy_class_entry.static_members); 
    76         zend_hash_destroy(&dummy_class_entry.constants_table); 
    77  
     83        FREE_HASHTABLE(dummy_class_entry.static_members); 
     84#  endif 
    7885        return property_dtor; 
    7986} 
     
    93100{ 
    94101        FIXUP(from->name); 
     102#ifdef ZEND_ENGINE_2_1 
     103        FIXUP(from->doc_comment); 
     104#endif 
    95105} 
    96106#endif 
     
    222232                                break; 
    223233                        } 
     234#  ifdef ZEND_ENGINE_2_1 
     235                        ZEND_VM_SET_OPCODE_HANDLER(opline); 
     236#  else 
    224237                        opline->handler = get_opcode_handler(opline->opcode TSRMLS_CC); 
     238#  endif 
     239 
    225240#endif 
    226241                } 
     
    235250                fixup_zval_hash(from->static_variables); 
    236251        } 
     252#ifdef ZEND_ENGINE_2_1 
     253        if (from->vars != NULL) { 
     254                zend_uint i; 
     255                FIXUP(from->vars); 
     256                for (i = 0; i < from->last_var; i++) { 
     257                        FIXUP(from->vars[i].name); 
     258                } 
     259        } 
     260#endif 
    237261        FIXUP(from->filename); 
    238262#ifdef ZEND_ENGINE_2 
     
    252276        fixup_hash(&from->properties_info, 
    253277                           (fixup_bucket_t) fixup_property_info TSRMLS_CC); 
     278#  ifdef ZEND_ENGINE_2_1 
     279        fixup_zval_hash(&from->default_static_members); 
     280        if (from->static_members != NULL) { 
     281                FIXUP(from->static_members); 
     282                if (from->static_members != &from->default_static_members) { 
     283                        fixup_zval_hash(from->static_members); 
     284                } 
     285        } 
     286#  else 
    254287        if (from->static_members != NULL) { 
    255288                FIXUP(from->static_members); 
    256289                fixup_zval_hash(from->static_members); 
    257290        } 
     291#  endif 
    258292#else 
    259293        fixup_zval_hash(&from->default_properties); 
     
    278312        memcpy(p, from, sizeof(zval)); 
    279313        restore_zval(p TSRMLS_CC); 
     314        /* hrak: reset refcount to make sure there is one reference to this val, and prevent memleaks */ 
     315        p->refcount = 1; 
    280316        return p; 
    281317} 
     
    352388        case IS_STRING: 
    353389                if (zv->value.str.val == NULL ||  
    354                 zv->value.str.val == empty_string || zv->value.str.len == 0) { 
     390                zv->value.str.val == "" || zv->value.str.len == 0) { 
    355391                        zv->value.str.val = empty_string; 
    356392                        return; 
     
    442478 
    443479        ea_debug_pad(EA_DEBUG TSRMLS_CC); 
    444         ea_debug_printf(EA_DEBUG, "[%d] restore_op_array: %s\n", getpid(), 
    445                                         from->function_name ? from->function_name : "(top)"); 
     480        ea_debug_printf(EA_DEBUG, "[%d] restore_op_array: %s type=%x\n", getpid(), 
     481                                        from->function_name ? from->function_name : "(top)", from->type); 
    446482 
    447483        if (from->type == ZEND_INTERNAL_FUNCTION) { 
     
    500536        if (from->scope_name != NULL) { 
    501537                char *from_scope_lc = zend_str_tolower_dup(from->scope_name, from->scope_name_len); 
    502                 if (zend_hash_find (CG(class_table), (void *) from_scope_lc,  
    503                     from->scope_name_len + 1, (void **) &to->scope) != SUCCESS) { 
     538                if (zend_hash_find (CG(class_table), (void *) from_scope_lc, from->scope_name_len + 1, (void **) &to->scope) != SUCCESS) { 
    504539                        ea_debug_pad(EA_DEBUG TSRMLS_CC); 
    505                         ea_debug_printf(EA_DEBUG, "[%d]                   can't find '%s' in hash. use EAG(class_entry).\n", getpid(), from_scope_lc); 
     540                        ea_debug_printf(EA_DEBUG, "[%d]                   can't find '%s' in class_table. use EAG(class_entry).\n", getpid(), from->scope_name); 
    506541                        to->scope = EAG(class_entry); 
    507542                } else { 
    508543                        ea_debug_pad(EA_DEBUG TSRMLS_CC); 
    509                         ea_debug_printf(EA_DEBUG, "[%d]                   found '%s' in hash\n", getpid(), from_scope_lc); 
     544                        ea_debug_printf(EA_DEBUG, "[%d]                   found '%s' in hash\n", getpid(), from->scope_name); 
    510545                        to->scope = *(zend_class_entry **) to->scope; 
    511546                } 
    512547                efree(from_scope_lc); 
    513         } else {                                        // zoeloelip: is this needed? scope is always stored 
     548        } else {                                        // zoeloelip: is this needed? scope is always stored -> hra: no its not :P only if from->scope!=null in ea_store 
    514549                ea_debug_pad(EA_DEBUG TSRMLS_CC); 
    515550                ea_debug_printf(EA_DEBUG, "[%d]                   from is NULL\n", getpid());  
     
    563598                        ea_debug_pad(EA_DEBUG TSRMLS_CC); 
    564599                        ea_debug_printf(EA_DEBUG, "[%d]                                       can't find\n", getpid()); 
    565                 } 
     600                }                
     601#ifdef ZEND_ENGINE_2 
     602                /* hrak: slight memleak here. dont forget to free the lowercase function name! */ 
     603                if (fname_lc != NULL) { 
     604                        efree(fname_lc); 
     605                } 
     606                /* zend_internal_function also contains return_reference in ZE2 */ 
     607                to->return_reference = from->return_reference; 
     608                /* this gets set by zend_do_inheritance */ 
     609                to->prototype = NULL; 
     610#endif 
    566611                return to; 
    567612        } 
     613#ifdef ZEND_ENGINE_2 
     614        /* hrak: slight memleak here. dont forget to free the lowercase function name! */ 
     615        if (fname_lc != NULL) { 
     616                efree(fname_lc); 
     617        } 
     618#endif 
    568619        to->opcodes = from->opcodes; 
    569620        to->last = to->size = from->last; 
     
    571622        to->brk_cont_array = from->brk_cont_array; 
    572623        to->last_brk_cont = from->last_brk_cont; 
    573         /* 
     624         
    574625           to->current_brk_cont = -1; 
    575626           to->static_variables = from->static_variables; 
    576            to->start_op         = to->opcodes; 
     627/*         to->start_op         = to->opcodes; */ 
    577628           to->backpatch_count  = 0; 
    578         */ 
     629         
    579630        to->return_reference = from->return_reference; 
    580631        to->done_pass_two = 1; 
    581632        to->filename = from->filename; 
     633/*      if (from->filename != NULL) { 
     634                size_t len = strlen(from->filename) + 1; 
     635                to->filename = emalloc(len); 
     636                memcpy(to->filename, from->filename, len); 
     637        }*/ 
     638 
    582639#ifdef ZEND_ENGINE_2 
    583640        /* HOESH: try & catch support */ 
     
    613670        } 
    614671 
     672#ifdef ZEND_ENGINE_2_1 
     673        to->vars             = from->vars; 
     674        to->last_var         = from->last_var; 
     675        to->size_var         = 0; 
     676/*      if (from->vars) { 
     677                zend_uint i; 
     678                to->vars = (zend_compiled_variable*)emalloc(from->last_var*sizeof(zend_compiled_variable));              
     679                memcpy(to->vars, from->vars, sizeof(zend_compiled_variable) * from->last_var); 
     680                for (i = 0; i < from->last_var; i ++) { 
     681                        to->vars[i].name = estrndup(from->vars[i].name, from->vars[i].name_len); 
     682                } 
     683        }*/ 
     684#endif 
     685 
    615686        /* disable deletion in destroy_op_array */ 
    616687        ++EAG(refcount_helper); 
     
    634705        to->name = emalloc(from->name_length + 1); 
    635706        memcpy(to->name, from->name, from->name_length + 1); 
     707#ifdef ZEND_ENGINE_2_1 
     708        if (from->doc_comment != NULL) { 
     709                to->doc_comment = emalloc(from->doc_comment_len+1); 
     710                memcpy(to->doc_comment, from->doc_comment, from->doc_comment_len+1); 
     711        } 
     712#endif 
    636713        return to; 
    637714} 
     
    642719                                                  zend_class_entry * to TSRMLS_DC) 
    643720{ 
    644 #ifdef ZEND_ENGINE_2 
    645         char *name_lc = zend_str_tolower_dup(parent, len); 
    646         if (zend_hash_find(CG(class_table), (void *) name_lc, len + 1, (void **) &to->parent) != SUCCESS) 
     721        ea_debug_printf(EA_DEBUG, "restore_class_parent: restoring parent class %s of class %s\n", (char *) parent, to->name); 
     722#ifdef ZEND_ENGINE_2 
     723/*      char *name_lc = zend_str_tolower_dup(parent, len); 
     724        if (zend_hash_find(CG(class_table), (void *) name_lc, len + 1, (void **) &to->parent) != SUCCESS)*/ 
     725        zend_class_entry** parent_ptr = NULL; 
     726        if (zend_lookup_class(parent, len, &parent_ptr TSRMLS_CC) != SUCCESS) 
    647727#else 
    648728        if (zend_hash_find(CG(class_table), (void *) parent, len + 1, (void **) &to->parent) != SUCCESS) 
     
    655735#ifdef ZEND_ENGINE_2 
    656736                /* inherit parent methods */ 
    657                 to->parent = *(zend_class_entry **) to->parent; 
     737                to->parent = *parent_ptr; 
     738                to->parent->refcount++; 
     739                ea_debug_printf(EA_DEBUG, "restore_class_parent: found parent %s..\n", to->parent->name); 
     740                ea_debug_printf(EA_DEBUG, "restore_class_parent: parent type=%d child type=%d\n", to->parent->type, to->type); 
    658741                to->constructor = to->parent->constructor; 
    659742                to->destructor = to->parent->destructor; 
    660743                to->clone = to->parent->clone; 
    661               to->__get = to->parent->__get; 
     744/*            to->__get = to->parent->__get; 
    662745                to->__set = to->parent->__set; 
     746#  ifdef ZEND_ENGINE_2_1 
     747                to->__unset = to->parent->__unset; 
     748                to->__isset = to->parent->__isset; 
     749                to->serialize_func = to->parent->serialize_func; 
     750                to->unserialize_func = to->parent->unserialize_func; 
     751#  endif 
    663752                to->__call = to->parent->__call; 
    664753                to->create_object = to->parent->create_object; 
     
    666755                to->handle_property_get = to->parent->handle_property_get; 
    667756                to->handle_property_set = to->parent->handle_property_set; 
    668                 to->handle_function_call = to->parent->handle_function_call; 
    669 #endif 
    670         } 
    671 #ifdef ZEND_ENGINE_2 
    672         efree(name_lc); 
     757                to->handle_function_call = to->parent->handle_function_call;*/ 
     758#endif 
     759        } 
     760#ifdef ZEND_ENGINE_2 
     761        /*efree(name_lc);*/ 
    673762#endif 
    674763} 
     
    689778                fname_len = strlen(f->common.function_name); 
    690779                fname_lc = zend_str_tolower_dup(f->common.function_name, fname_len); 
     780                ea_debug_printf(EA_DEBUG, "restore_class_methods: restoring function:%s scope:%s parent=%x scope=%x\n", fname_lc, ZEND_FN_SCOPE_NAME(f), to->parent, f->common.scope); 
    691781 
    692782                if (fname_len == cname_len && !memcmp(fname_lc, cname_lc, fname_len) &&  
     
    709799                                         memcmp(fname_lc, ZEND_SET_FUNC_NAME, sizeof(ZEND_SET_FUNC_NAME)) == 0) 
    710800                                to->__set = f; 
     801#  ifdef ZEND_ENGINE_2_1 
     802                        else if (fname_len == sizeof(ZEND_UNSET_FUNC_NAME) - 1 && 
     803                                        memcmp(fname_lc, ZEND_UNSET_FUNC_NAME, sizeof(ZEND_UNSET_FUNC_NAME)) == 0) 
     804                                to->__unset = f; 
     805                        else if (fname_len == sizeof(ZEND_ISSET_FUNC_NAME) - 1 && 
     806                                        memcmp(fname_lc, ZEND_ISSET_FUNC_NAME, sizeof(ZEND_ISSET_FUNC_NAME)) == 0) 
     807                                to->__isset = f; 
     808#  endif 
    711809                        else if (fname_len == sizeof(ZEND_CALL_FUNC_NAME) - 1 && 
    712810                                         memcmp(fname_lc, ZEND_CALL_FUNC_NAME, sizeof(ZEND_CALL_FUNC_NAME)) == 0) 
     
    725823        zend_class_entry *old; 
    726824        zend_function *f = NULL; 
    727         int fname_len = 0; 
    728         char *fname_lc = NULL; 
    729 #ifdef ZEND_ENGINE_2 
    730         int cname_len; 
    731         char *cname_lc; 
     825/*      int fname_len = 0;              hrak: seems rather unused 
     826        char *fname_lc = NULL; */ 
     827#ifdef ZEND_ENGINE_2 
     828/*      int cname_len;                  hrak: same here 
     829        char *cname_lc; */ 
    732830        Bucket *p; 
    733831        union _zend_function *old_ctor; 
     
    735833 
    736834        ea_debug_pad(EA_DEBUG TSRMLS_CC); 
    737         ea_debug_printf(EA_DEBUG, "[%d] retore_class_entry: %s\n", getpid(), from->name ? from->name : "(top)"); 
     835        ea_debug_printf(EA_DEBUG, "[%d] restore_class_entry: %s\n", getpid(), from->name ? from->name : "(top)"); 
    738836#ifdef DEBUG 
    739837        EAG(xpad)++; 
    740838#endif 
    741  
    742839        if (to == NULL) { 
    743840                to = emalloc(sizeof(zend_class_entry)); 
     
    753850#ifdef ZEND_ENGINE_2 
    754851        to->ce_flags = from->ce_flags; 
    755         /* 
    756            to->static_members = NULL; 
    757          */ 
    758852        to->num_interfaces = from->num_interfaces; 
    759853        if (to->num_interfaces > 0) { 
     854                /* hrak: Allocate the slots which will later be populated by ZEND_ADD_INTERFACE */ 
    760855                to->interfaces = (zend_class_entry **) emalloc(sizeof(zend_class_entry *) * to->num_interfaces); 
    761                 // should find out class entry. what the hell !!! 
    762856                memset(to->interfaces, 0, sizeof(zend_class_entry *) * to->num_interfaces); 
    763857        } else { 
     
    766860 
    767861        to->iterator_funcs = from->iterator_funcs; 
     862        to->create_object = from->create_object; 
    768863        to->get_iterator = from->get_iterator; 
    769864        to->interface_gets_implemented = from->interface_gets_implemented; 
     
    776871        } 
    777872 
    778         if (from->parent != NULL) { 
    779                 restore_class_parent(from->parent, strlen(from->parent), to TSRMLS_CC); 
    780         } else { 
    781                 ea_debug_pad(EA_DEBUG TSRMLS_CC); 
    782                 ea_debug_printf(EA_DEBUG, "[%d] parent = NULL\n", getpid()); 
    783                 to->parent = NULL; 
    784         } 
    785  
    786873        old = EAG(class_entry); 
    787874        EAG(class_entry) = to; 
     
    793880        to->line_end = from->line_end; 
    794881        to->doc_comment_len = from->doc_comment_len; 
    795       if (from->filename != NULL) { 
     882/*    if (from->filename != NULL) { 
    796883                size_t len = strlen(from->filename) + 1; 
    797884                to->filename = emalloc(len); 
    798885                memcpy(to->filename, from->filename, len); 
    799         } 
     886        }*/ 
     887        to->filename = from->filename; 
    800888        if (from->doc_comment != NULL) { 
    801889                to->doc_comment = emalloc(from->doc_comment_len + 1); 
     
    814902        to->properties_info.pDestructor = properties_info_dtor; 
    815903 
     904#  ifdef ZEND_ENGINE_2_1 
     905        /* restore default_static_members */ 
     906        restore_zval_hash(&to->default_static_members, &from->default_static_members); 
     907        to->default_static_members.pDestructor = ZVAL_PTR_DTOR; 
     908         
     909        ea_debug_printf(EA_DEBUG, "restore_class_entry: static_members=%x, default_static_members=%x\n", from->static_members, &from->default_static_members); 
     910        if (from->static_members != &(from->default_static_members)) { 
     911                ALLOC_HASHTABLE(to->static_members); 
     912                restore_zval_hash(to->static_members, from->static_members); 
     913                to->static_members->pDestructor = ZVAL_PTR_DTOR; 
     914        } else { 
     915                to->static_members = &(to->default_static_members); 
     916        } 
     917        ea_debug_printf(EA_DEBUG, "restore_class_entry: to->static_members=%x, to->default_static_members=%x\n", to->static_members, &to->default_static_members); 
     918#  else 
    816919        if (from->static_members != NULL) { 
    817920                ALLOC_HASHTABLE(to->static_members); 
    818921                restore_zval_hash(to->static_members, from->static_members); 
    819922                to->static_members->pDestructor = ZVAL_PTR_DTOR; 
    820                 /* 
    821                    } else { 
    822                    ALLOC_HASHTABLE(to->static_members); 
    823                    zend_hash_init_ex(to->static_members, 0, NULL, ZVAL_PTR_DTOR, 0, 0); 
    824                  */ 
    825         } 
     923        } 
     924#  endif 
    826925#else 
    827926        to->refcount = emalloc(sizeof(*to->refcount)); 
     
    839938        } 
    840939#endif 
     940        if (from->parent != NULL) { 
     941                restore_class_parent(from->parent, strlen(from->parent), to TSRMLS_CC); 
     942        } else { 
     943                ea_debug_pad(EA_DEBUG TSRMLS_CC); 
     944                ea_debug_printf(EA_DEBUG, "[%d] parent = NULL\n", getpid()); 
     945                to->parent = NULL; 
     946        } 
     947 
    841948        restore_hash(&to->function_table, &from->function_table, 
    842949                                 (restore_bucket_t) restore_op_array_ptr TSRMLS_CC); 
     
    846953        restore_class_methods(to TSRMLS_CC); 
    847954#endif 
     955        if (to->parent) 
     956                zend_do_inheritance(to, to->parent TSRMLS_CC); 
    848957        EAG(class_entry) = old; 
    849958 
  • eaccelerator/trunk/ea_restore.h

    r124 r162  
    3535void fixup_class_entry (eaccelerator_class_entry * from TSRMLS_DC); 
    3636 
     37void restore_zval(zval * zv TSRMLS_DC); 
    3738void restore_class(mm_fc_entry *p TSRMLS_DC); 
    3839void restore_function(mm_fc_entry *p TSRMLS_DC); 
  • eaccelerator/trunk/ea_store.c

    r124 r162  
    8383        EAG(mem) += sizeof(zend_property_info); 
    8484        calc_string(from->name, from->name_length + 1 TSRMLS_CC); 
     85#ifdef ZEND_ENGINE_2_1 
     86        if (from->doc_comment != NULL) { 
     87                calc_string(from->doc_comment, from->doc_comment_len + 1 TSRMLS_CC); 
     88        } 
     89#endif 
    8590} 
    8691 
     
    118123        case IS_CONSTANT: 
    119124        case IS_STRING: 
    120                if (zv->value.str.val == NULL || zv->value.str.val == empty_string || zv->value.str.len == 0) { 
    121                 } else { 
     125/*             if (zv->value.str.val == NULL || zv->value.str.len == 0) { 
     126                } else {*/ 
    122127                        calc_string(zv->value.str.val, zv->value.str.len + 1 TSRMLS_CC); 
    123                 } 
     128/*              }*/ 
    124129                break; 
    125130        case IS_ARRAY: 
     
    247252                calc_zval_hash(from->static_variables); 
    248253        } 
     254#ifdef ZEND_ENGINE_2_1 
     255        if (from->vars != NULL) { 
     256                zend_uint i; 
     257                EACCELERATOR_ALIGN(EAG(mem)); 
     258                EAG(mem) += sizeof(zend_compiled_variable) * from->last_var; 
     259                for (i = 0; i < from->last_var; i ++) { 
     260                        calc_string(from->vars[i].name, from->vars[i].name_len+1 TSRMLS_CC); 
     261                } 
     262        } 
     263#endif 
    249264        if (from->filename != NULL) 
    250265                calc_string(from->filename, strlen(from->filename) + 1 TSRMLS_CC); 
     
    270285                calc_string(from->parent->name, from->parent->name_length + 1 TSRMLS_CC); 
    271286#ifdef ZEND_ENGINE_2 
    272 #if 0 
    273         // what's problem. why from->interfaces[i] == 0x5a5a5a5a ? 
    274         for (i = 0; i < from->num_interfaces; i++) { 
    275                 if (from->interfaces[i]) { 
    276                         calc_string(from->interfaces[i]->name, 
    277                                                 from->interfaces[i]->name_length); 
    278                 } 
    279         } 
    280 #endif 
    281287        if (from->filename != NULL) 
    282288                calc_string(from->filename, strlen(from->filename) + 1 TSRMLS_CC); 
     
    286292        calc_zval_hash(&from->constants_table); 
    287293        calc_zval_hash(&from->default_properties); 
     294 
    288295        calc_hash(&from->properties_info, (calc_bucket_t) calc_property_info); 
     296 
     297#  ifdef ZEND_ENGINE_2_1 
     298        calc_zval_hash(&from->default_static_members); 
     299        if ((from->static_members != NULL) && (from->static_members != &from->default_static_members)) { 
     300#  else 
    289301        if (from->static_members != NULL) { 
     302#  endif 
    290303                EACCELERATOR_ALIGN(EAG(mem)); 
    291304                EAG(mem) += sizeof(HashTable); 
     
    368381 
    369382typedef void *(*store_bucket_t) (void *TSRMLS_DC); 
    370  
    371 #define store_hash_ex(to, from, start, store_bucket) \ 
    372   store_hash_int(to, from, start, store_bucket TSRMLS_CC) 
    373  
    374 #define store_hash(to, from, store_bucket) \ 
    375   store_hash_ex(to, from, (from)->pListHead, store_bucket) 
     383typedef void *(*check_bucket_t) (Bucket*, va_list); 
     384 
     385#define store_hash_ex(to, from, start, store_bucket, check_bucket, ...) \ 
     386  store_hash_int(to, from, start, store_bucket, check_bucket, __VA_ARGS__) 
     387 
     388#define store_hash(to, from, store_bucket, check_bucket, ...) \ 
     389  store_hash_ex(to, from, (from)->pListHead, store_bucket, check_bucket, __VA_ARGS__) 
    376390 
    377391#define store_zval_hash(to, from) \ 
    378   store_hash(to, from, (store_bucket_t)store_zval_ptr
     392  store_hash(to, from, (store_bucket_t)store_zval_ptr, NULL, NULL
    379393 
    380394#define store_zval_hash_ex(to, from, start) \ 
    381   store_hash_ex(to, from, start, (store_bucket_t)store_zval_ptr
     395  store_hash_ex(to, from, start, (store_bucket_t)store_zval_ptr, NULL
    382396 
    383397static zval *store_zval_ptr(zval * from TSRMLS_DC) 
     
    393407 
    394408static void store_hash_int(HashTable * target, HashTable * source, 
    395                                                    Bucket * start, store_bucket_t copy_bucket TSRMLS_DC) 
     409                                                   Bucket * start, store_bucket_t copy_bucket, 
     410                                                                   check_bucket_t check_bucket, ...) 
    396411{ 
    397412        Bucket *p, *np, *prev_p; 
     413        TSRMLS_FETCH(); 
    398414 
    399415        memcpy(target, source, sizeof(HashTable)); 
     
    416432                np = NULL; 
    417433                while (p) { 
     434                        /* If a check function has been defined, run it */ 
     435                        if (check_bucket) { 
     436                                va_list args; 
     437                                va_start(args, check_bucket); 
     438 
     439                                /* If the check function returns ZEND_HASH_APPLY_REMOVE, don't store this record, skip over it */ 
     440                                if(check_bucket(p, args)) { 
     441                                        p = p->pListNext; 
     442                                        target->nNumOfElements--; 
     443                                        /* skip to next itteration */ 
     444                                        continue; 
     445                                } 
     446                                va_end(args); 
     447                        } 
     448 
    418449                        EACCELERATOR_ALIGN(EAG(mem)); 
    419450                        np = (Bucket *) EAG(mem); 
     
    466497        case IS_CONSTANT: 
    467498        case IS_STRING: 
    468                 if (zv->value.str.val == NULL || 
    469                         zv->value.str.val == empty_string || zv->value.str.len == 0) { 
    470                         zv->value.str.val = empty_string; 
    471                         zv->value.str.len = 0; 
    472                 } else { 
    473                         zv->value.str.val = store_string(zv->value.str.val, zv->value.str.len + 1 TSRMLS_CC); 
    474                 } 
     499                zv->value.str.val = store_string(zv->value.str.val, zv->value.str.len + 1 TSRMLS_CC); 
    475500                break; 
    476501        case IS_ARRAY: 
     
    516541 
    517542        ea_debug_pad(EA_DEBUG TSRMLS_CC); 
    518         ea_debug_printf(EA_DEBUG, "[%d] store_op_array: %s [scope=%s]\n",  
     543        ea_debug_printf(EA_DEBUG, "[%d] store_op_array: %s [scope=%s type=%x]\n",  
    519544            getpid(), from->function_name ? from->function_name : "(top)", 
    520545#ifdef ZEND_ENGINE_2 
     
    523548                        "NULL" 
    524549#endif 
     550                        , from->type 
    525551                ); 
    526552 
     
    555581                                to->arg_info[i].class_name_len = from->arg_info[i].class_name_len; 
    556582                        } 
     583#  ifdef ZEND_ENGINE_2_1 
     584                        /* php 5.1 introduces this in zend_arg_info for array type hinting */ 
     585                        to->arg_info[i].array_type_hint = from->arg_info[i].array_type_hint; 
     586#  endif 
    557587                        to->arg_info[i].allow_null = from->arg_info[i].allow_null; 
    558588                        to->arg_info[i].pass_by_reference = from->arg_info[i].pass_by_reference; 
     
    595625#endif 
    596626 
    597         if (from->type == ZEND_INTERNAL_FUNCTION) 
    598         return to; 
     627        if (from->type == ZEND_INTERNAL_FUNCTION) { 
     628#ifdef ZEND_ENGINE_2 
     629                /* zend_internal_function also contains return_reference in ZE2 */ 
     630                to->return_reference = from->return_reference; 
     631#endif           
     632                return to; 
     633        } 
    599634     
    600635        to->opcodes = from->opcodes; 
     
    672707                store_zval_hash(to->static_variables, from->static_variables); 
    673708        } 
     709#ifdef ZEND_ENGINE_2_1 
     710        if (from->vars != NULL) { 
     711                zend_uint i; 
     712                EACCELERATOR_ALIGN(EAG(mem)); 
     713                to->last_var = from->last_var; 
     714                to->vars = (zend_compiled_variable*)EAG(mem); 
     715                EAG(mem) += sizeof(zend_compiled_variable) * from->last_var; 
     716                        memcpy(to->vars, from->vars, sizeof(zend_compiled_variable) * from->last_var); 
     717                for (i = 0; i < from->last_var; i ++) { 
     718                        to->vars[i].name = store_string(from->vars[i].name, from->vars[i].name_len+1 TSRMLS_CC); 
     719                } 
     720        } else { 
     721                to->last_var = 0; 
     722                to->vars = NULL; 
     723        } 
     724#endif 
    674725        if (from->filename != NULL) { 
    675                 to->filename = store_string(to->filename, strlen(from->filename) + 1 TSRMLS_CC); 
     726                to->filename = store_string(from->filename, strlen(from->filename) + 1 TSRMLS_CC); 
    676727        } 
    677728#ifdef ZEND_ENGINE_2 
     
    694745        memcpy(to, from, sizeof(zend_property_info)); 
    695746        to->name = store_string(from->name, from->name_length + 1 TSRMLS_CC); 
     747#ifdef ZEND_ENGINE_2_1 
     748        to->doc_comment_len = from->doc_comment_len; 
     749        if (from->doc_comment != NULL) { 
     750                to->doc_comment = store_string(from->doc_comment, from->doc_comment_len + 1 TSRMLS_CC); 
     751        } 
     752#endif 
    696753        return to; 
    697754} 
    698 #endif 
     755 
     756/*  
     757 * The following two functions handle access checking of properties (public/private/protected)  
     758 * and control proper inheritance during copying of the properties_info and (default_)static_members hashes 
     759 * 
     760 * Both functions return ZEND_HASH_APPLY_REMOVE if the property to be copied needs to be skipped, or 
     761 * ZEND_HASH_APPLY_KEEP if the property needs to be copied over into the cache. 
     762 *   
     763 * If the property is skipped due to access restrictions, or it needs inheritance of its value from the 
     764 * parent, the restore phase will take care of that. 
     765 * 
     766 * Most of the logic behind all this can be found in zend_compile.c, functions zend_do_inheritance and 
     767 * zend_do_inherit_property_access_check 
     768*/ 
     769static int store_property_access_check(Bucket * p, va_list args) 
     770
     771        zend_class_entry *from = va_arg(args, zend_class_entry*); 
     772        zend_class_entry *parent = from->parent; 
     773         
     774        ea_debug_printf(EA_DEBUG, "[%d] store_property_access_check enter. from=%x parent=%x arKey=%s\n", getpid(), from, parent, p->arKey); 
     775         
     776        if (parent) { 
     777                // hra: TODO - do some usefull stuff :) 
     778                // check for ACC_PRIVATE etc. 
     779                // for now, just return keep 
     780        } 
     781        ea_debug_printf(EA_DEBUG, "[%d] store_property_access_check result: keep\n", getpid()); 
     782        return ZEND_HASH_APPLY_KEEP; 
     783
     784 
     785static int store_static_member_access_check(Bucket * p, va_list args) 
     786
     787        zend_class_entry *from = va_arg(args, zend_class_entry*); 
     788        zend_class_entry *parent = from->parent; 
     789        zend_property_info *pinfo, *cinfo = NULL; 
     790        zval **pprop = NULL; 
     791        zval **cprop = p->pData; 
     792        char *mname, *cname = NULL; 
     793 
     794        /* Check if this is a parent class. If so, copy unconditionally */ 
     795        if (parent) { 
     796                /* unpack the \0classname\0membername\0 style property name to seperate vars */ 
     797                zend_unmangle_property_name(p->arKey, &cname, &mname); 
     798                ea_debug_printf(EA_DEBUG, "[%d] store_static_member_access_check: cname=%s, mname=%s\n", getpid(), cname, mname); 
     799         
     800                /* lookup the member's info in parent and child */ 
     801                if((zend_hash_find(&parent->properties_info, mname, strlen(mname)+1, (void**)&pinfo) == SUCCESS) && 
     802                        (zend_hash_find(&from->properties_info, mname, strlen(mname)+1, (void**)&cinfo) == SUCCESS)) { 
     803                        /* don't copy this static property if protected in parent and static public in child. 
     804                           inheritance will handle this properly on restore */ 
     805                        if(cinfo->flags & ZEND_ACC_STATIC && (pinfo->flags & ZEND_ACC_PROTECTED && cinfo->flags & ZEND_ACC_PUBLIC)) { 
     806                                ea_debug_printf(EA_DEBUG, "[%d] store_static_member_access_check: child static public, parent protected, result: skip\n", getpid()); 
     807                                return ZEND_HASH_APPLY_REMOVE; 
     808                        } 
     809                        /* If the static member points to the same value in parent and child, remove for proper inheritance during restore */ 
     810#  ifdef ZEND_ENGINE_2_1 
     811                        if(zend_hash_quick_find(&parent->default_static_members, p->arKey, p->nKeyLength, p->h, (void**)&pprop) == SUCCESS) { 
     812#  else 
     813                        if(zend_hash_quick_find(&parent->static_members, p->arKey, p->nKeyLength, p->h, (void**)&pprop) == SUCCESS) { 
     814#  endif 
     815                                ea_debug_printf(EA_DEBUG, "[%d] store_static_member_access_check: SUCCESS looking up arKey\n",getpid()); 
     816                                ea_debug_printf(EA_DEBUG, "[%d] store_static_member_access_check: pprop=%x cprop=%x\n",getpid(), *pprop, *cprop); 
     817                                if(*pprop ==