PHP_FUNCTION(spl_object_hash)
{
zval *obj;
- char hash[33];
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &obj) == FAILURE) {
return;
}
- php_spl_object_hash(obj, hash TSRMLS_CC);
-
- RETURN_STRING(hash);
+ RETURN_NEW_STR(php_spl_object_hash(obj TSRMLS_CC));
}
/* }}} */
-PHPAPI void php_spl_object_hash(zval *obj, char *result TSRMLS_DC) /* {{{*/
+PHPAPI zend_string *php_spl_object_hash(zval *obj TSRMLS_DC) /* {{{*/
{
intptr_t hash_handle, hash_handlers;
- char *hex;
if (!SPL_G(hash_mask_init)) {
if (!BG(mt_rand_is_seeded)) {
hash_handle = SPL_G(hash_mask_handle)^(intptr_t)Z_OBJ_HANDLE_P(obj);
hash_handlers = SPL_G(hash_mask_handlers)^(intptr_t)Z_OBJ_HT_P(obj);
- spprintf(&hex, 32, "%016lx%016lx", hash_handle, hash_handlers);
-
- strlcpy(result, hex, 33);
- efree(hex);
+ return strpprintf(32, "%016lx%016lx", hash_handle, hash_handlers);
}
/* }}} */
PHP_FUNCTION(class_implements);
PHP_FUNCTION(class_uses);
-PHPAPI void php_spl_object_hash(zval *obj, char* md5str TSRMLS_DC);
+PHPAPI zend_string *php_spl_object_hash(zval *obj TSRMLS_DC);
#endif /* PHP_SPL_H */
spl_SplObjectStorageElement *element;
HashTable *props;
zval tmp, storage;
- char md5str[33];
+ zend_string *md5str;
zend_string *zname;
*is_temp = 0;
array_init(&storage);
ZEND_HASH_FOREACH_PTR(&intern->storage, element) {
- php_spl_object_hash(&element->obj, md5str TSRMLS_CC);
+ md5str = php_spl_object_hash(&element->obj TSRMLS_CC);
array_init(&tmp);
/* Incrementing the refcount of obj and inf would confuse the garbage collector.
* Prefer to null the destructor */
Z_ARRVAL_P(&tmp)->pDestructor = NULL;
add_assoc_zval_ex(&tmp, "obj", sizeof("obj") - 1, &element->obj);
add_assoc_zval_ex(&tmp, "inf", sizeof("inf") - 1, &element->inf);
- add_assoc_zval_ex(&storage, md5str, 32, &tmp);
+ zend_hash_update(Z_ARRVAL(storage), md5str, &tmp);
+ STR_RELEASE(md5str);
} ZEND_HASH_FOREACH_END();
zname = spl_gen_private_prop_name(spl_ce_SplObjectStorage, "storage", sizeof("storage")-1 TSRMLS_CC);
SPL_METHOD(SplObjectStorage, getHash)
{
zval *obj;
- char *hash;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &obj) == FAILURE) {
return;
}
-
- hash = emalloc(33);
- php_spl_object_hash(obj, hash TSRMLS_CC);
- RETVAL_STRING(hash);
+ RETURN_NEW_STR(php_spl_object_hash(obj TSRMLS_CC));
} /* }}} */