Changeset 248

Show
Ignore:
Timestamp:
07/27/06 15:38:44 (2 years ago)
Author:
bart
Message:

Fix bug #145, objects are serialized when they are stored in shared memory.

Users don't have to do this in their code anymore.

Files:

Legend:

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

    r247 r248  
    77        * Some fixes to make eAccelerator compile with php 5.2, this fixes bug #150 
    88        * Restore __toString methods correctly with php 5.2 
     9        * Fix bug #145, objects are serialized when they are stored in shared memory. 
     10          Users don't have to do this in their code anymore. 
    911 
    10122006-07-25  Bart Vanbrabant <bart.vanbrabant at zoeloelip.be> 
  • eaccelerator/trunk/ea_restore.c

    r247 r248  
    144144        switch (Z_TYPE_P(zv) & ~IS_CONSTANT_INDEX) { 
    145145        case IS_CONSTANT:                       /* fallthrough */ 
     146    case IS_OBJECT:             /* fallthrough: object are serialized */ 
    146147        case IS_STRING: 
    147148                FIXUP(Z_STRVAL_P(zv)); 
     
    152153                fixup_zval_hash(Z_ARRVAL_P(zv)); 
    153154                break; 
    154         case IS_OBJECT: 
    155                 if (!EAG(compress)) { 
    156                         return; 
    157                 } 
    158 #ifndef ZEND_ENGINE_2 
    159                 FIXUP(Z_OBJCE_P(zv)); 
    160                 if (Z_OBJPROP_P(zv) != NULL) { 
    161                         FIXUP(Z_OBJPROP_P(zv)); 
    162                         fixup_zval_hash(Z_OBJPROP_P(zv)); 
    163                 } 
    164 #endif 
    165155        default: 
    166156                break; 
     
    372362        switch (zv->type & ~IS_CONSTANT_INDEX) { 
    373363        case IS_CONSTANT: 
     364    case IS_OBJECT: 
    374365        case IS_STRING: 
    375366                if (Z_STRVAL_P(zv) == NULL || Z_STRVAL_P(zv) == "" || Z_STRLEN_P(zv) == 0) { 
     
    391382                } 
    392383                return; 
    393  
    394         case IS_OBJECT: 
    395     { 
    396 #ifndef ZEND_ENGINE_2 
    397         zend_bool incomplete_class = 0; 
    398         char *class_name = (char *) Z_OBJCE_P(zv); 
    399         int name_len = 0; 
    400         if (!EAG(compress)) { 
    401             return; 
    402         } 
    403         if (class_name != NULL) { 
    404             zend_class_entry *ce = NULL; 
    405             name_len = strlen(class_name); 
    406             if (zend_hash_find(CG(class_table), (void *) class_name, name_len + 1, (void **) &ce) != SUCCESS) { 
    407                 char *lowercase_name = estrndup(INCOMPLETE_CLASS, sizeof(INCOMPLETE_CLASS)); 
    408                 zend_str_tolower(lowercase_name, sizeof(INCOMPLETE_CLASS)); 
    409                 if (zend_hash_find(CG(class_table), lowercase_name, sizeof(INCOMPLETE_CLASS), (void **) &ce) != SUCCESS) { 
    410                     efree(lowercase_name); 
    411                     zend_error(E_ERROR, "EACCELERATOR can't restore object's class \"%s\"", class_name); 
    412                 } else { 
    413                     efree(lowercase_name); 
    414                     Z_OBJCE_P(zv) = ce; 
    415                     incomplete_class = 1; 
    416                 } 
    417             } else { 
    418                 Z_OBJCE_P(zv) = ce; 
    419             } 
    420         } 
    421         if (Z_OBJPROP_P(zv) != NULL) { 
    422             Z_OBJPROP_P(zv) = restore_zval_hash(NULL, Z_OBJPROP_P(zv)); 
    423             Z_OBJPROP_P(zv)->pDestructor = ZVAL_PTR_DTOR; 
    424             /* Clearing references */ 
    425             { 
    426                 Bucket *p = Z_OBJPROP_P(zv)->pListHead; 
    427                 while (p != NULL) { 
    428                     ((zval *) (p->pDataPtr))->refcount = 1; 
    429                     p = p->pListNext; 
    430                 } 
    431             } 
    432         } 
    433         if (incomplete_class && class_name != NULL) { 
    434             zval *val; 
    435             MAKE_STD_ZVAL(val); 
    436             Z_TYPE_P(val) = IS_STRING; 
    437             Z_STRVAL_P(val) = estrndup(class_name, name_len); 
    438             Z_STRLEN_P(val) = name_len; 
    439             zend_hash_update(Z_OBJPROP_P(zv), MAGIC_MEMBER, sizeof(MAGIC_MEMBER), &val, sizeof(val), NULL); 
    440         } 
    441 #endif 
    442         return; 
    443     } 
    444384        } 
    445385} 
  • eaccelerator/trunk/ea_store.c

    r247 r248  
    115115        switch (Z_TYPE_P(zv) & ~IS_CONSTANT_INDEX) { 
    116116        case IS_CONSTANT: 
     117    case IS_OBJECT: /* object should have been serialized before storing them */ 
    117118        case IS_STRING: 
    118119                calc_string(Z_STRVAL_P(zv), Z_STRLEN_P(zv) + 1 TSRMLS_CC); 
     
    126127                } 
    127128                break; 
    128         case IS_OBJECT: 
    129 #ifndef ZEND_ENGINE_2 
    130                 if (Z_OBJCE_P(zv) != NULL) { 
    131                         zend_class_entry *ce = Z_OBJCE_P(zv); 
    132                         if (!EAG(compress)) { 
    133                                 DBG(ea_debug_error, ("[%d] EACCELERATOR can't cache objects\n", getpid())); 
    134                                 zend_bailout(); 
    135                         } 
    136                         while (ce != NULL) { 
    137                                 if (ce->type != ZEND_USER_CLASS && strcmp(ce->name, "stdClass") != 0) { 
    138                                         DBG(ea_debug_error, ("[%d] EACCELERATOR can't cache objects\n", getpid())); 
    139                                         zend_bailout(); 
    140                                 } 
    141                                 ce = ce->parent; 
    142                         } 
    143                         calc_string(Z_OBJCE_P(zv)->name, Z_OBJCE_P(zv)->name_length + 1 TSRMLS_CC); 
    144                 } 
    145                 if (Z_OBJPROP_P(zv) != NULL) { 
    146                         EACCELERATOR_ALIGN(EAG(mem)); 
    147                         EAG(mem) += sizeof(HashTable); 
    148                         calc_zval_hash(Z_OBJPROP_P(zv)); 
    149                 } 
    150 #endif 
    151                 return; 
    152129        case IS_RESOURCE: 
    153130                DBG(ea_debug_error, ("[%d] EACCELERATOR can't cache resources\n", getpid())); 
     
    476453        switch (Z_TYPE_P(zv) & ~IS_CONSTANT_INDEX) { 
    477454        case IS_CONSTANT: 
     455    case IS_OBJECT: /* object should have been serialized before storing them */ 
    478456        case IS_STRING: 
    479457                Z_STRVAL_P(zv) = store_string(Z_STRVAL_P(zv), Z_STRLEN_P(zv) + 1 TSRMLS_CC); 
     
    490468                } 
    491469                break; 
    492         case IS_OBJECT: 
    493                 if (!EAG(compress)) { 
    494                         return; 
    495                 } 
    496 #ifndef ZEND_ENGINE_2 
    497                 if (Z_OBJCE_P(zv) != NULL) { 
    498                         char *s = store_string(Z_OBJCE_P(zv)->name, Z_OBJCE_P(zv)->name_length + 1 TSRMLS_CC); 
    499                         zend_str_tolower(s, Z_OBJCE_P(zv)->name_length); 
    500                         Z_OBJCE_P(zv) = (zend_class_entry *) s; 
    501                 } 
    502                 if (Z_OBJPROP_P(zv) != NULL) { 
    503                         HashTable *p; 
    504                         EACCELERATOR_ALIGN(EAG(mem)); 
    505                         p = (HashTable *) EAG(mem); 
    506                         EAG(mem) += sizeof(HashTable); 
    507                         store_zval_hash(p, Z_OBJPROP_P(zv)); 
    508                         Z_OBJPROP_P(zv) = p; 
    509                 } 
    510 #endif 
    511470        default: 
    512471                break; 
  • eaccelerator/trunk/shm.c

    r182 r248  
    3838#include "zend_API.h" 
    3939#include "zend_extensions.h" 
     40#include "standard/php_var.h" 
    4041 
    4142/* where to cache the keys */ 
     
    102103        char *key; 
    103104        int key_len; 
    104         zval *val
     105        zval *val, *result
    105106        time_t ttl = 0; 
    106107        long where = eaccelerator_keys_cache_place; 
     
    109110                return; 
    110111 
    111         if (eaccelerator_put (key, key_len, val, ttl, where TSRMLS_CC)) { 
     112    if ((Z_TYPE_P(val) & ~IS_CONSTANT_INDEX) == IS_OBJECT) { 
     113        php_serialize_data_t var_hash; 
     114        smart_str buf = {0}; 
     115        result = (zval *)emalloc(sizeof(result)); 
     116 
     117        PHP_VAR_SERIALIZE_INIT(var_hash); 
     118        php_var_serialize(&buf, &val, &var_hash TSRMLS_CC); 
     119        PHP_VAR_SERIALIZE_DESTROY(var_hash); 
     120 
     121        Z_TYPE_P(result) = IS_NULL; 
     122        if (buf.c) { 
     123            ZVAL_STRINGL(result, buf.c, buf.len, 1); 
     124            Z_TYPE_P(result) = Z_TYPE_P(val); 
     125        } 
     126        INIT_PZVAL(result); 
     127    } else { 
     128        result = val; 
     129    } 
     130 
     131        if (eaccelerator_put (key, key_len, result, ttl, where TSRMLS_CC)) { 
    112132                RETURN_TRUE; 
    113133        } else { 
     
    121141        int key_len; 
    122142        long where = eaccelerator_keys_cache_place; 
     143    zval *value; 
    123144 
    124145        if (zend_parse_parameters (ZEND_NUM_ARGS ()TSRMLS_CC, "s|l", &key, &key_len, &where) == FAILURE) 
    125146                return; 
    126147 
    127         if (eaccelerator_get (key, key_len, return_value, where TSRMLS_CC)) { 
    128                 return; 
     148    ALLOC_ZVAL(value); 
     149    if (eaccelerator_get (key, key_len, value, where TSRMLS_CC)) { 
     150        if ((Z_TYPE_P(value) & ~IS_CONSTANT_INDEX) == IS_OBJECT) { 
     151            const unsigned char *p; 
     152            php_unserialize_data_t var_hash; 
     153 
     154            p = (const unsigned char*)Z_STRVAL_P(value); 
     155            PHP_VAR_UNSERIALIZE_INIT(var_hash); 
     156            if (!php_var_unserialize(&return_value, &p, p + Z_STRLEN_P(value),  &var_hash TSRMLS_CC)) { 
     157                PHP_VAR_UNSERIALIZE_DESTROY(var_hash); 
     158                zval_dtor(return_value); 
     159                php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error at offset %ld of %d bytes",  
     160                        (long)((char*)p - Z_STRVAL_P(value)), Z_STRLEN_P(value)); 
     161                ea_debug_error("Error unserializing (%s) with length %d\n", Z_STRVAL_P(value), Z_STRLEN_P(value)); 
     162            } 
     163            PHP_VAR_UNSERIALIZE_DESTROY(var_hash); 
     164        } 
     165        return; 
    129166        } else { 
    130167                RETURN_NULL ();