]> granicus.if.org Git - php/commitdiff
fix serialize:
authorThies C. Arntzen <thies@php.net>
Sat, 4 Aug 2001 17:29:54 +0000 (17:29 +0000)
committerThies C. Arntzen <thies@php.net>
Sat, 4 Aug 2001 17:29:54 +0000 (17:29 +0000)
- keys no longer have a trailing \0
- no leak on calling __wakeup (also saved 2* malloc & free)
- serializing objects that implement __sleep() works again
- make test works again:-)

ext/standard/var.c

index 0185862d6056c756dbee13e98f05667a1093e834..ae8add2b809e606392c1238c62220ed3ea226df6 100644 (file)
@@ -201,6 +201,9 @@ static void php_var_serialize_class(smart_str *buf, zval **struc, zval *retval_p
 
        php_var_serialize_class_name(buf, struc TSRMLS_CC);
 
+       smart_str_append_long(buf, count);
+       smart_str_appendl(buf, ":{", 2);
+
        if (count > 0) {
                char *key;
                zval **d, **name;
@@ -284,15 +287,13 @@ static void php_var_serialize_intern(smart_str *buf, zval **struc, HashTable *va
 
                case IS_OBJECT: {
                                zval *retval_ptr = NULL;
-                               zval *fname;
+                               zval fname;
                                int res;
 
-                               MAKE_STD_ZVAL(fname);
-                               ZVAL_STRINGL(fname, "__sleep", sizeof("__sleep") - 1, 0);
-
-                               res = call_user_function_ex(CG(function_table), struc, fname, 
+                               INIT_PZVAL(&fname);
+                               ZVAL_STRINGL(&fname, "__sleep", sizeof("__sleep") - 1, 0);
+                               res = call_user_function_ex(CG(function_table), struc, &fname, 
                                                &retval_ptr, 0, 0, 1, NULL TSRMLS_CC);
-                               FREE_ZVAL(fname);
 
                                if (res == SUCCESS) {
                                        if (retval_ptr) {
@@ -342,7 +343,7 @@ static void php_var_serialize_intern(smart_str *buf, zval **struc, HashTable *va
                                                        php_var_serialize_long(buf, index);
                                                        break;
                                                case HASH_KEY_IS_STRING:
-                                                       php_var_serialize_string(buf, key, key_len);
+                                                       php_var_serialize_string(buf, key, key_len - 1);
                                                        break;
                                        }
                                        php_var_serialize_intern(buf, data, var_hash TSRMLS_CC);
@@ -592,13 +593,11 @@ PHPAPI int php_var_unserialize(zval **rval, const char **p, const char *max, Has
 
                        if ((*rval)->type == IS_OBJECT) {
                                zval *retval_ptr = NULL;
-                               zval *fname;
-
-                               MAKE_STD_ZVAL(fname);
-                               ZVAL_STRINGL(fname, "__wakeup", sizeof("__wakeup") - 1, 1);
+                               zval fname;
 
-                               call_user_function_ex(CG(function_table), rval, fname, &retval_ptr, 0, 0, 1, NULL TSRMLS_CC);
-                               FREE_ZVAL(fname);
+                               INIT_PZVAL(&fname);
+                               ZVAL_STRINGL(&fname, "__wakeup", sizeof("__wakeup") - 1, 0);
+                               call_user_function_ex(CG(function_table), rval, &fname, &retval_ptr, 0, 0, 1, NULL TSRMLS_CC);
 
                                if (retval_ptr)
                                        zval_ptr_dtor(&retval_ptr);