Changeset 327

Show
Ignore:
Timestamp:
08/19/07 18:42:47 (9 months ago)
Author:
bart
Message:

Improve storing of objects and fix bug #264

Files:

Legend:

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

    r326 r327  
    112007-08-19  Bart Vanbrabant <bart.vanbrabant at zoeloelip.be> 
    22        * Fix an E_NOTICE error in the control panel 
     3        * Improve storing of objects and fix bug #264 
    34 
    452007-08-16  Bart Vanbrabant <bart.vanbrabant at zoeloelip.be> 
  • eaccelerator/trunk/shm.c

    r302 r327  
    3939#include "zend_extensions.h" 
    4040#include "standard/php_var.h" 
     41#include "standard/php_smart_str.h" 
    4142 
    4243/* where to cache the keys */ 
     
    105106        time_t ttl = 0; 
    106107        long where = eaccelerator_keys_cache_place; 
     108    int ret_val = 0; 
     109    smart_str buf = {0}; 
    107110 
    108111        if (zend_parse_parameters (ZEND_NUM_ARGS ()TSRMLS_CC, "sz|ll", &key, &key_len, &val, &ttl, &where) == FAILURE) 
     
    111114    if ((Z_TYPE_P(val) & ~IS_CONSTANT_INDEX) == IS_OBJECT) { 
    112115        php_serialize_data_t var_hash; 
    113         smart_str buf = {0}; 
    114         result = (zval *)emalloc(sizeof(zval)); 
    115116 
    116117        PHP_VAR_SERIALIZE_INIT(var_hash); 
     
    118119        PHP_VAR_SERIALIZE_DESTROY(var_hash); 
    119120 
    120         Z_TYPE_P(result) = IS_NULL; 
    121121        if (buf.c) { 
     122            ALLOC_ZVAL(result); 
    122123            ZVAL_STRINGL(result, buf.c, buf.len, 1); 
    123124            Z_TYPE_P(result) = Z_TYPE_P(val); 
    124125        } 
    125         INIT_PZVAL(result); 
    126126    } else { 
    127127        result = val; 
    128128    } 
    129129 
    130         if (eaccelerator_put (key, key_len, result, ttl, where TSRMLS_CC)) { 
     130        ret_val = eaccelerator_put (key, key_len, result, ttl, where TSRMLS_CC); 
     131 
     132    if ((Z_TYPE_P(val) & ~IS_CONSTANT_INDEX) == IS_OBJECT) { 
     133        smart_str_free(&buf); 
     134    } 
     135 
     136    if (ret_val) { 
    131137                RETURN_TRUE; 
    132138        } else { 
     
    140146        int key_len; 
    141147        long where = eaccelerator_keys_cache_place; 
    142     zval *value; 
    143148 
    144149        if (zend_parse_parameters (ZEND_NUM_ARGS ()TSRMLS_CC, "s|l", &key, &key_len, &where) == FAILURE) 
    145150                return; 
    146151 
    147     ALLOC_ZVAL(value); 
    148     if (eaccelerator_get (key, key_len, value, where TSRMLS_CC)) { 
    149         if ((Z_TYPE_P(value) & ~IS_CONSTANT_INDEX) == IS_OBJECT) { 
     152    if (eaccelerator_get (key, key_len, return_value, where TSRMLS_CC)) { 
     153        if ((Z_TYPE_P(return_value) & ~IS_CONSTANT_INDEX) == IS_OBJECT) { 
    150154            const unsigned char *p; 
    151155            php_unserialize_data_t var_hash; 
    152  
    153             p = (const unsigned char*)Z_STRVAL_P(value); 
     156            zval *object; 
     157 
     158            /* 
     159             * We serialized the object to a string but stored the object type  
     160             * so it will be serialized here. 
     161             */ 
     162            Z_TYPE_P(return_value) = IS_STRING; 
     163 
    154164            PHP_VAR_UNSERIALIZE_INIT(var_hash); 
    155             if (!php_var_unserialize(&return_value, &p, p + Z_STRLEN_P(value),  &var_hash TSRMLS_CC)) { 
    156                 PHP_VAR_UNSERIALIZE_DESTROY(var_hash); 
    157                 zval_dtor(return_value); 
    158                 php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error at offset %ld of %d bytes",  
    159                         (long)((char*)p - Z_STRVAL_P(value)), Z_STRLEN_P(value)); 
     165            p = (const unsigned char *)Z_STRVAL_P(return_value); 
     166            if (!php_var_unserialize(&return_value, &p, p + Z_STRLEN_P(return_value), &var_hash TSRMLS_CC)) { 
     167                zval_dtor(object); 
     168                Z_TYPE_P(object) = IS_NULL; 
    160169            } 
    161170            PHP_VAR_UNSERIALIZE_DESTROY(var_hash);