Changeset 248
- Timestamp:
- 07/27/06 15:38:44 (2 years ago)
- Files:
-
- eaccelerator/trunk/ChangeLog (modified) (1 diff)
- eaccelerator/trunk/ea_restore.c (modified) (4 diffs)
- eaccelerator/trunk/ea_store.c (modified) (4 diffs)
- eaccelerator/trunk/shm.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
eaccelerator/trunk/ChangeLog
r247 r248 7 7 * Some fixes to make eAccelerator compile with php 5.2, this fixes bug #150 8 8 * 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. 9 11 10 12 2006-07-25 Bart Vanbrabant <bart.vanbrabant at zoeloelip.be> eaccelerator/trunk/ea_restore.c
r247 r248 144 144 switch (Z_TYPE_P(zv) & ~IS_CONSTANT_INDEX) { 145 145 case IS_CONSTANT: /* fallthrough */ 146 case IS_OBJECT: /* fallthrough: object are serialized */ 146 147 case IS_STRING: 147 148 FIXUP(Z_STRVAL_P(zv)); … … 152 153 fixup_zval_hash(Z_ARRVAL_P(zv)); 153 154 break; 154 case IS_OBJECT:155 if (!EAG(compress)) {156 return;157 }158 #ifndef ZEND_ENGINE_2159 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 #endif165 155 default: 166 156 break; … … 372 362 switch (zv->type & ~IS_CONSTANT_INDEX) { 373 363 case IS_CONSTANT: 364 case IS_OBJECT: 374 365 case IS_STRING: 375 366 if (Z_STRVAL_P(zv) == NULL || Z_STRVAL_P(zv) == "" || Z_STRLEN_P(zv) == 0) { … … 391 382 } 392 383 return; 393 394 case IS_OBJECT:395 {396 #ifndef ZEND_ENGINE_2397 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 #endif442 return;443 }444 384 } 445 385 } eaccelerator/trunk/ea_store.c
r247 r248 115 115 switch (Z_TYPE_P(zv) & ~IS_CONSTANT_INDEX) { 116 116 case IS_CONSTANT: 117 case IS_OBJECT: /* object should have been serialized before storing them */ 117 118 case IS_STRING: 118 119 calc_string(Z_STRVAL_P(zv), Z_STRLEN_P(zv) + 1 TSRMLS_CC); … … 126 127 } 127 128 break; 128 case IS_OBJECT:129 #ifndef ZEND_ENGINE_2130 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 #endif151 return;152 129 case IS_RESOURCE: 153 130 DBG(ea_debug_error, ("[%d] EACCELERATOR can't cache resources\n", getpid())); … … 476 453 switch (Z_TYPE_P(zv) & ~IS_CONSTANT_INDEX) { 477 454 case IS_CONSTANT: 455 case IS_OBJECT: /* object should have been serialized before storing them */ 478 456 case IS_STRING: 479 457 Z_STRVAL_P(zv) = store_string(Z_STRVAL_P(zv), Z_STRLEN_P(zv) + 1 TSRMLS_CC); … … 490 468 } 491 469 break; 492 case IS_OBJECT:493 if (!EAG(compress)) {494 return;495 }496 #ifndef ZEND_ENGINE_2497 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 #endif511 470 default: 512 471 break; eaccelerator/trunk/shm.c
r182 r248 38 38 #include "zend_API.h" 39 39 #include "zend_extensions.h" 40 #include "standard/php_var.h" 40 41 41 42 /* where to cache the keys */ … … 102 103 char *key; 103 104 int key_len; 104 zval *val ;105 zval *val, *result; 105 106 time_t ttl = 0; 106 107 long where = eaccelerator_keys_cache_place; … … 109 110 return; 110 111 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)) { 112 132 RETURN_TRUE; 113 133 } else { … … 121 141 int key_len; 122 142 long where = eaccelerator_keys_cache_place; 143 zval *value; 123 144 124 145 if (zend_parse_parameters (ZEND_NUM_ARGS ()TSRMLS_CC, "s|l", &key, &key_len, &where) == FAILURE) 125 146 return; 126 147 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; 129 166 } else { 130 167 RETURN_NULL ();