]> granicus.if.org Git - php/commitdiff
- Make use of get_debug_info handler in SplObjectStorage
authorMarcus Boerger <helly@php.net>
Fri, 19 Jan 2007 23:23:08 +0000 (23:23 +0000)
committerMarcus Boerger <helly@php.net>
Fri, 19 Jan 2007 23:23:08 +0000 (23:23 +0000)
ext/spl/php_spl.c
ext/spl/php_spl.h
ext/spl/spl_observer.c
ext/spl/tests/observer_004.phpt
ext/spl/tests/observer_005.phpt

index a73cbd347e23909df62ee3e68db404ab66865d4f..908f2675ab99a23070bd3cb15af4997a9d9f600f 100755 (executable)
@@ -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) /* {{{ */
 {
index 87e7d4c5fc3ac2662f7440340eede2fa588fe10c..b180291215fd5a50846beed88fe83c5984f51815 100755 (executable)
@@ -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 */
 
 /*
index cfc9570a000625f755c66cb3730c787a83c4f7b5..febb33a0dade85ca4a0e519dac2e4f3157783aae 100755 (executable)
@@ -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);
index 2664904162e7a77731281e413ea3b8013341d1c7..afa2eab338910dff73ac18055d4e5c05d1534328 100755 (executable)
@@ -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===
index a8fe114057c9e1c7ad1126aa78d6097e4c8d7196..df6e49a9ef7722ffe08b463d44792fea54643204 100755 (executable)
@@ -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===