From: Marcus Boerger Date: Fri, 19 Jan 2007 23:23:08 +0000 (+0000) Subject: - Make use of get_debug_info handler in SplObjectStorage X-Git-Tag: RELEASE_1_0_0RC1~196 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4c0b85ba26d7f1a605fa36ad1eff0323f4e15d40;p=php - Make use of get_debug_info handler in SplObjectStorage --- diff --git a/ext/spl/php_spl.c b/ext/spl/php_spl.c index a73cbd347e..908f2675ab 100755 --- a/ext/spl/php_spl.c +++ b/ext/spl/php_spl.c @@ -593,16 +593,26 @@ PHP_FUNCTION(spl_autoload_functions) PHP_FUNCTION(spl_object_hash) { zval *obj; - int len; - char *hash; - char md5str[33]; - PHP_MD5_CTX context; - unsigned char digest[16]; + char* md5str; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &obj) == FAILURE) { return; } + md5str = emalloc(33); + php_spl_object_hash(obj, md5str TSRMLS_CC); + + RETVAL_STRING(md5str, 0); +} +/* }}} */ + +PHPAPI void php_spl_object_hash(zval *obj, char *md5str TSRMLS_DC) /* {{{*/ +{ + int len; + char *hash; + PHP_MD5_CTX context; + unsigned char digest[16]; + len = spprintf(&hash, 0, "%p:%d", Z_OBJ_HT_P(obj), Z_OBJ_HANDLE_P(obj)); md5str[0] = '\0'; @@ -610,9 +620,9 @@ PHP_FUNCTION(spl_object_hash) PHP_MD5Update(&context, (unsigned char*)hash, len); PHP_MD5Final(digest, &context); make_digest(md5str, digest); - RETVAL_STRING(md5str, 1); efree(hash); } +/* }}} */ int spl_build_class_list_string(zval **entry, char **list TSRMLS_DC) /* {{{ */ { diff --git a/ext/spl/php_spl.h b/ext/spl/php_spl.h index 87e7d4c5fc..b180291215 100755 --- a/ext/spl/php_spl.h +++ b/ext/spl/php_spl.h @@ -73,6 +73,8 @@ PHP_FUNCTION(spl_classes); PHP_FUNCTION(class_parents); PHP_FUNCTION(class_implements); +PHPAPI void php_spl_object_hash(zval *obj, char* md5str TSRMLS_DC); + #endif /* PHP_SPL_H */ /* diff --git a/ext/spl/spl_observer.c b/ext/spl/spl_observer.c index cfc9570a00..febb33a0da 100755 --- a/ext/spl/spl_observer.c +++ b/ext/spl/spl_observer.c @@ -116,6 +116,53 @@ static zend_object_value spl_object_storage_new_ex(zend_class_entry *class_type, } /* }}} */ +static HashTable* spl_object_storage_debug_infos(zval *obj, int *is_temp TSRMLS_DC) /* {{{ */ +{ + spl_SplObjectStorage *intern = (spl_SplObjectStorage*)zend_object_store_get_object(obj TSRMLS_CC); + HashTable *rv, *props; + HashPosition pos; + zval *tmp, *storage, **entry; + char md5str[33], *name; + int name_len; + zstr zname, zclass, zprop; + + *is_temp = 1; + + props = Z_OBJPROP_P(obj); + ALLOC_HASHTABLE(rv); + ZEND_INIT_SYMTABLE_EX(rv, zend_hash_num_elements(props) + 1, 0); + + zend_hash_copy(rv, props, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *)); + + MAKE_STD_ZVAL(storage); + array_init(storage); + + zend_hash_internal_pointer_reset_ex(&intern->storage, &pos); + while (zend_hash_get_current_data_ex(&intern->storage, (void **)&entry, &pos) == SUCCESS) { + php_spl_object_hash(*entry, md5str TSRMLS_CC); + zval_add_ref(entry); + add_assoc_zval_ex(storage, md5str, 33, *entry); + zend_hash_move_forward_ex(&intern->storage, &pos); + } + + if (UG(unicode)) { + zclass.u = USTR_MAKE("SplObjectStorage"); + zprop.u = USTR_MAKE("storage"); + zend_u_mangle_property_name(&zname, &name_len, IS_UNICODE, zclass, sizeof("SplObjectStorage")-1, zprop, sizeof("storage")-1, 0); + zend_u_symtable_update(rv, IS_UNICODE, zname, name_len+1, &storage, sizeof(zval *), NULL); + efree(zname.v); + efree(zclass.v); + efree(zprop.v); + } else { + zend_mangle_property_name(&name, &name_len, "SplObjectStorage", sizeof("SplObjectStorage")-1, "storage", sizeof("storage")-1, 0); + zend_symtable_update(rv, name, name_len+1, &storage, sizeof(zval *), NULL); + efree(name); + } + + return rv; +} +/* }}} */ + /* {{{ spl_array_object_new */ static zend_object_value spl_SplObjectStorage_new(zend_class_entry *class_type TSRMLS_DC) { @@ -437,6 +484,7 @@ PHP_MINIT_FUNCTION(spl_observer) REGISTER_SPL_STD_CLASS_EX(SplObjectStorage, spl_SplObjectStorage_new, spl_funcs_SplObjectStorage); memcpy(&spl_handler_SplObjectStorage, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); + spl_handler_SplObjectStorage.get_debug_info = spl_object_storage_debug_infos; REGISTER_SPL_IMPLEMENTS(SplObjectStorage, Countable); REGISTER_SPL_IMPLEMENTS(SplObjectStorage, Iterator); diff --git a/ext/spl/tests/observer_004.phpt b/ext/spl/tests/observer_004.phpt index 2664904162..afa2eab338 100755 --- a/ext/spl/tests/observer_004.phpt +++ b/ext/spl/tests/observer_004.phpt @@ -62,35 +62,87 @@ var_dump($storage2); int(2) int(1) int(2) -object(MyStorage)#%d (1) { +object(MyStorage)#%d (2) { ["bla"]=> int(26) + ["storage":"SplObjectStorage":private]=> + array(2) { + ["%s"]=> + object(TestClass)#%d (1) { + ["test"]=> + int(1) + } + ["%s"]=> + object(TestClass)#%d (1) { + ["test"]=> + int(2) + } + } } string(%d) "%s" ===UNSERIALIZE=== int(2) int(1) int(2) -object(MyStorage)#%d (1) { +object(MyStorage)#%d (2) { ["bla"]=> int(26) + ["storage":"SplObjectStorage":private]=> + array(2) { + ["%s"]=> + object(TestClass)#%d (1) { + ["test"]=> + int(1) + } + ["%s"]=> + object(TestClass)#%d (1) { + ["test"]=> + int(2) + } + } } ===DONE=== --UEXPECTF-- int(2) int(1) int(2) -object(MyStorage)#%d (1) { +object(MyStorage)#%d (2) { [u"bla"]=> int(26) + [u"storage":u"SplObjectStorage":private]=> + array(2) { + ["%s"]=> + object(TestClass)#%d (1) { + [u"test"]=> + int(1) + } + ["%s"]=> + object(TestClass)#%d (1) { + [u"test"]=> + int(2) + } + } } unicode(%d) "%s" ===UNSERIALIZE=== int(2) int(1) int(2) -object(MyStorage)#%d (1) { +object(MyStorage)#%d (2) { [u"bla"]=> int(26) + [u"storage":u"SplObjectStorage":private]=> + array(2) { + ["%s"]=> + object(TestClass)#%d (1) { + [u"test"]=> + int(1) + } + ["%s"]=> + object(TestClass)#%d (1) { + [u"test"]=> + int(2) + } + } } ===DONE=== diff --git a/ext/spl/tests/observer_005.phpt b/ext/spl/tests/observer_005.phpt index a8fe114057..df6e49a9ef 100755 --- a/ext/spl/tests/observer_005.phpt +++ b/ext/spl/tests/observer_005.phpt @@ -98,7 +98,7 @@ object(TestClass)#%d (4) { ["pri":"TestClass":private]=> int(9) } -object(MyStorage)#%d (4) { +object(MyStorage)#%d (5) { ["def"]=> int(24) ["pub"]=> @@ -107,6 +107,31 @@ object(MyStorage)#%d (4) { int(2) ["pri":"MyStorage":private]=> int(3) + ["storage":"SplObjectStorage":private]=> + array(2) { + ["%s"]=> + object(TestClass)#%d (4) { + ["def"]=> + int(24) + ["pub"]=> + int(4) + ["pro":protected]=> + int(5) + ["pri":"TestClass":private]=> + int(6) + } + ["%s"]=> + object(TestClass)#%d (4) { + ["def"]=> + int(24) + ["pub"]=> + int(7) + ["pro":protected]=> + int(8) + ["pri":"TestClass":private]=> + int(9) + } + } } string(%d) "%s" ===UNSERIALIZE=== @@ -131,7 +156,7 @@ object(TestClass)#%d (4) { ["pri":"TestClass":private]=> int(9) } -object(MyStorage)#%d (4) { +object(MyStorage)#%d (5) { ["def"]=> int(24) ["pub"]=> @@ -140,6 +165,31 @@ object(MyStorage)#%d (4) { int(2) ["pri":"MyStorage":private]=> int(3) + ["storage":"SplObjectStorage":private]=> + array(2) { + ["%s"]=> + object(TestClass)#%d (4) { + ["def"]=> + int(24) + ["pub"]=> + int(4) + ["pro":protected]=> + int(5) + ["pri":"TestClass":private]=> + int(6) + } + ["%s"]=> + object(TestClass)#%d (4) { + ["def"]=> + int(24) + ["pub"]=> + int(7) + ["pro":protected]=> + int(8) + ["pri":"TestClass":private]=> + int(9) + } + } } ===DONE=== --UEXPECTF-- @@ -164,7 +214,7 @@ object(TestClass)#%d (4) { [u"pri":u"TestClass":private]=> int(9) } -object(MyStorage)#%d (4) { +object(MyStorage)#%d (5) { [u"def"]=> int(24) [u"pub"]=> @@ -173,6 +223,31 @@ object(MyStorage)#%d (4) { int(2) [u"pri":u"MyStorage":private]=> int(3) + [u"storage":u"SplObjectStorage":private]=> + array(2) { + ["%s"]=> + object(TestClass)#%d (4) { + [u"def"]=> + int(24) + [u"pub"]=> + int(4) + [u"pro":protected]=> + int(5) + [u"pri":u"TestClass":private]=> + int(6) + } + ["%s"]=> + object(TestClass)#%d (4) { + [u"def"]=> + int(24) + [u"pub"]=> + int(7) + [u"pro":protected]=> + int(8) + [u"pri":u"TestClass":private]=> + int(9) + } + } } unicode(%d) "%s" ===UNSERIALIZE=== @@ -197,7 +272,7 @@ object(TestClass)#%d (4) { [u"pri":u"TestClass":private]=> int(9) } -object(MyStorage)#%d (4) { +object(MyStorage)#%d (5) { [u"def"]=> int(24) [u"pub"]=> @@ -206,5 +281,30 @@ object(MyStorage)#%d (4) { int(2) [u"pri":u"MyStorage":private]=> int(3) + [u"storage":u"SplObjectStorage":private]=> + array(2) { + ["%s"]=> + object(TestClass)#%d (4) { + [u"def"]=> + int(24) + [u"pub"]=> + int(4) + [u"pro":protected]=> + int(5) + [u"pri":u"TestClass":private]=> + int(6) + } + ["%s"]=> + object(TestClass)#%d (4) { + [u"def"]=> + int(24) + [u"pub"]=> + int(7) + [u"pro":protected]=> + int(8) + [u"pri":u"TestClass":private]=> + int(9) + } + } } ===DONE===