@@ -59,23 +59,19 @@ PHPAPI zend_class_entry *spl_ce_RecursiveArrayIterator;
59
59
#define SPL_ARRAY_CLONE_MASK 0x0300FFFF
60
60
61
61
typedef struct _spl_array_object {
62
- zend_object std ;
63
- zval * array ;
64
- zval * retval ;
65
- HashPosition pos ;
66
- ulong pos_h ;
67
- int ar_flags ;
68
- int is_self ;
69
- zend_function * fptr_offset_get ;
70
- zend_function * fptr_offset_set ;
71
- zend_function * fptr_offset_has ;
72
- zend_function * fptr_offset_del ;
73
- zend_function * fptr_count ;
74
- zend_function * fptr_serialize ;
75
- zend_function * fptr_unserialize ;
76
- zend_class_entry * ce_get_iterator ;
77
- php_serialize_data_t * serialize_data ;
78
- php_unserialize_data_t * unserialize_data ;
62
+ zend_object std ;
63
+ zval * array ;
64
+ zval * retval ;
65
+ HashPosition pos ;
66
+ ulong pos_h ;
67
+ int ar_flags ;
68
+ int is_self ;
69
+ zend_function * fptr_offset_get ;
70
+ zend_function * fptr_offset_set ;
71
+ zend_function * fptr_offset_has ;
72
+ zend_function * fptr_offset_del ;
73
+ zend_function * fptr_count ;
74
+ zend_class_entry * ce_get_iterator ;
79
75
HashTable * debug_info ;
80
76
} spl_array_object ;
81
77
@@ -161,8 +157,6 @@ static void spl_array_object_free_storage(void *object TSRMLS_DC)
161
157
/* }}} */
162
158
163
159
zend_object_iterator * spl_array_get_iterator (zend_class_entry * ce , zval * object , int by_ref TSRMLS_DC );
164
- int spl_array_serialize (zval * object , unsigned char * * buffer , zend_uint * buf_len , zend_serialize_data * data TSRMLS_DC );
165
- int spl_array_unserialize (zval * * object , zend_class_entry * ce , const unsigned char * buf , zend_uint buf_len , zend_unserialize_data * data TSRMLS_DC );
166
160
167
161
/* {{{ spl_array_object_new_ex */
168
162
static zend_object_value spl_array_object_new_ex (zend_class_entry * class_type , spl_array_object * * obj , zval * orig , int clone_orig TSRMLS_DC )
@@ -182,8 +176,6 @@ static zend_object_value spl_array_object_new_ex(zend_class_entry *class_type, s
182
176
object_properties_init (& intern -> std , class_type );
183
177
184
178
intern -> ar_flags = 0 ;
185
- intern -> serialize_data = NULL ;
186
- intern -> unserialize_data = NULL ;
187
179
intern -> debug_info = NULL ;
188
180
intern -> ce_get_iterator = spl_ce_ArrayIterator ;
189
181
if (orig ) {
@@ -250,14 +242,6 @@ static zend_object_value spl_array_object_new_ex(zend_class_entry *class_type, s
250
242
if (intern -> fptr_count -> common .scope == parent ) {
251
243
intern -> fptr_count = NULL ;
252
244
}
253
- zend_hash_find (& class_type -> function_table , "serialize" , sizeof ("serialize" ), (void * * ) & intern -> fptr_serialize );
254
- if (intern -> fptr_serialize -> common .scope == parent ) {
255
- intern -> fptr_serialize = NULL ;
256
- }
257
- zend_hash_find (& class_type -> function_table , "unserialize" , sizeof ("unserialize" ), (void * * ) & intern -> fptr_unserialize );
258
- if (intern -> fptr_unserialize -> common .scope == parent ) {
259
- intern -> fptr_unserialize = NULL ;
260
- }
261
245
}
262
246
/* Cache iterator functions if ArrayIterator or derived. Check current's */
263
247
/* cache since only current is always required */
@@ -1567,27 +1551,35 @@ SPL_METHOD(Array, getChildren)
1567
1551
}
1568
1552
/* }}} */
1569
1553
1570
- smart_str spl_array_serialize_helper (spl_array_object * intern , php_serialize_data_t * var_hash_p TSRMLS_DC ) { /* {{{ */
1554
+ /* {{{ proto string ArrayObject::serialize()
1555
+ Serialize the object */
1556
+ SPL_METHOD (Array , serialize )
1557
+ {
1558
+ zval * object = getThis ();
1559
+ spl_array_object * intern = (spl_array_object * )zend_object_store_get_object (object TSRMLS_CC );
1571
1560
HashTable * aht = spl_array_get_hash_table (intern , 0 TSRMLS_CC );
1572
1561
zval members , * pmembers ;
1562
+ php_serialize_data_t var_hash ;
1573
1563
smart_str buf = {0 };
1574
1564
zval * flags ;
1575
1565
1576
1566
if (!aht ) {
1577
1567
php_error_docref (NULL TSRMLS_CC , E_NOTICE , "Array was modified outside object and is no longer an array" );
1578
- return buf ;
1568
+ return ;
1579
1569
}
1580
1570
1571
+ PHP_VAR_SERIALIZE_INIT (var_hash );
1572
+
1581
1573
MAKE_STD_ZVAL (flags );
1582
1574
ZVAL_LONG (flags , (intern -> ar_flags & SPL_ARRAY_CLONE_MASK ));
1583
1575
1584
1576
/* storage */
1585
1577
smart_str_appendl (& buf , "x:" , 2 );
1586
- php_var_serialize (& buf , & flags , var_hash_p TSRMLS_CC );
1578
+ php_var_serialize (& buf , & flags , & var_hash TSRMLS_CC );
1587
1579
zval_ptr_dtor (& flags );
1588
1580
1589
1581
if (!(intern -> ar_flags & SPL_ARRAY_IS_SELF )) {
1590
- php_var_serialize (& buf , & intern -> array , var_hash_p TSRMLS_CC );
1582
+ php_var_serialize (& buf , & intern -> array , & var_hash TSRMLS_CC );
1591
1583
smart_str_appendc (& buf , ';' );
1592
1584
}
1593
1585
@@ -1600,34 +1592,10 @@ smart_str spl_array_serialize_helper(spl_array_object *intern, php_serialize_dat
1600
1592
Z_ARRVAL (members ) = intern -> std .properties ;
1601
1593
Z_TYPE (members ) = IS_ARRAY ;
1602
1594
pmembers = & members ;
1603
- php_var_serialize (& buf , & pmembers , var_hash_p TSRMLS_CC ); /* finishes the string */
1595
+ php_var_serialize (& buf , & pmembers , & var_hash TSRMLS_CC ); /* finishes the string */
1604
1596
1605
1597
/* done */
1606
- return buf ;
1607
- }
1608
- /* }}} */
1609
-
1610
- /* {{{ proto string ArrayObject::serialize()
1611
- Serialize the object */
1612
- SPL_METHOD (Array , serialize )
1613
- {
1614
- zval * object = getThis ();
1615
- spl_array_object * intern = (spl_array_object * )zend_object_store_get_object (object TSRMLS_CC );
1616
- int was_in_serialize = intern -> serialize_data != NULL ;
1617
- smart_str buf ;
1618
-
1619
- if (!was_in_serialize ) {
1620
- intern -> serialize_data = emalloc (sizeof (php_serialize_data_t ));
1621
- PHP_VAR_SERIALIZE_INIT (* intern -> serialize_data );
1622
- }
1623
-
1624
- buf = spl_array_serialize_helper (intern , intern -> serialize_data TSRMLS_CC );
1625
-
1626
- if (!was_in_serialize ) {
1627
- PHP_VAR_SERIALIZE_DESTROY (* intern -> serialize_data );
1628
- efree (intern -> serialize_data );
1629
- intern -> serialize_data = NULL ;
1630
- }
1598
+ PHP_VAR_SERIALIZE_DESTROY (var_hash );
1631
1599
1632
1600
if (buf .c ) {
1633
1601
RETURN_STRINGL (buf .c , buf .len , 0 );
@@ -1636,55 +1604,40 @@ SPL_METHOD(Array, serialize)
1636
1604
RETURN_NULL ();
1637
1605
} /* }}} */
1638
1606
1639
- int spl_array_serialize (zval * object , unsigned char * * buffer , zend_uint * buf_len , zend_serialize_data * data TSRMLS_DC ) /* {{{ */
1607
+ /* {{{ proto void ArrayObject::unserialize(string serialized)
1608
+ * unserialize the object
1609
+ */
1610
+ SPL_METHOD (Array , unserialize )
1640
1611
{
1641
- spl_array_object * intern = (spl_array_object * )zend_object_store_get_object (object TSRMLS_CC );
1642
-
1643
- if (intern -> fptr_serialize ) {
1644
- int retval ;
1645
- php_serialize_data_t * before ;
1646
-
1647
- before = intern -> serialize_data ;
1648
- intern -> serialize_data = (php_serialize_data_t * )data ;
1649
-
1650
- retval = zend_user_serialize (object , buffer , buf_len , data TSRMLS_CC );
1651
-
1652
- intern -> serialize_data = before ;
1653
-
1654
- return retval ;
1655
- } else {
1656
- smart_str buf ;
1657
-
1658
- buf = spl_array_serialize_helper (intern , (php_serialize_data_t * )data TSRMLS_CC );
1659
-
1660
- if (buf .c ) {
1661
- * buffer = (unsigned char * )estrndup (buf .c , buf .len );
1662
- * buf_len = buf .len ;
1663
- efree (buf .c );
1664
- return SUCCESS ;
1665
- } else {
1666
- return FAILURE ;
1667
- }
1668
- }
1669
- }
1670
- /* }}} */
1612
+ spl_array_object * intern = (spl_array_object * )zend_object_store_get_object (getThis () TSRMLS_CC );
1671
1613
1672
- void spl_array_unserialize_helper ( spl_array_object * intern , const unsigned char * buf , int buf_len , php_unserialize_data_t * var_hash_p TSRMLS_DC ) /* {{{ */
1673
- {
1614
+ char * buf ;
1615
+ int buf_len ;
1674
1616
const unsigned char * p , * s ;
1617
+ php_unserialize_data_t var_hash ;
1675
1618
zval * pmembers , * pflags = NULL ;
1676
1619
long flags ;
1620
+
1621
+ if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC , "s" , & buf , & buf_len ) == FAILURE ) {
1622
+ return ;
1623
+ }
1624
+
1625
+ if (buf_len == 0 ) {
1626
+ zend_throw_exception_ex (spl_ce_UnexpectedValueException , 0 TSRMLS_CC , "Empty serialized string cannot be empty" );
1627
+ return ;
1628
+ }
1677
1629
1678
1630
/* storage */
1679
- s = p = buf ;
1631
+ s = p = (const unsigned char * )buf ;
1632
+ PHP_VAR_UNSERIALIZE_INIT (var_hash );
1680
1633
1681
1634
if (* p != 'x' || * ++ p != ':' ) {
1682
1635
goto outexcept ;
1683
1636
}
1684
1637
++ p ;
1685
1638
1686
1639
ALLOC_INIT_ZVAL (pflags );
1687
- if (!php_var_unserialize (& pflags , & p , s + buf_len , var_hash_p TSRMLS_CC ) || Z_TYPE_P (pflags ) != IS_LONG ) {
1640
+ if (!php_var_unserialize (& pflags , & p , s + buf_len , & var_hash TSRMLS_CC ) || Z_TYPE_P (pflags ) != IS_LONG ) {
1688
1641
zval_ptr_dtor (& pflags );
1689
1642
goto outexcept ;
1690
1643
}
@@ -1710,7 +1663,7 @@ void spl_array_unserialize_helper(spl_array_object *intern, const unsigned char
1710
1663
intern -> ar_flags |= flags & SPL_ARRAY_CLONE_MASK ;
1711
1664
zval_ptr_dtor (& intern -> array );
1712
1665
ALLOC_INIT_ZVAL (intern -> array );
1713
- if (!php_var_unserialize (& intern -> array , & p , s + buf_len , var_hash_p TSRMLS_CC )) {
1666
+ if (!php_var_unserialize (& intern -> array , & p , s + buf_len , & var_hash TSRMLS_CC )) {
1714
1667
goto outexcept ;
1715
1668
}
1716
1669
}
@@ -1726,7 +1679,7 @@ void spl_array_unserialize_helper(spl_array_object *intern, const unsigned char
1726
1679
++ p ;
1727
1680
1728
1681
ALLOC_INIT_ZVAL (pmembers );
1729
- if (!php_var_unserialize (& pmembers , & p , s + buf_len , var_hash_p TSRMLS_CC )) {
1682
+ if (!php_var_unserialize (& pmembers , & p , s + buf_len , & var_hash TSRMLS_CC )) {
1730
1683
zval_ptr_dtor (& pmembers );
1731
1684
goto outexcept ;
1732
1685
}
@@ -1739,80 +1692,17 @@ void spl_array_unserialize_helper(spl_array_object *intern, const unsigned char
1739
1692
zval_ptr_dtor (& pmembers );
1740
1693
1741
1694
/* done reading $serialized */
1695
+
1696
+ PHP_VAR_UNSERIALIZE_DESTROY (var_hash );
1742
1697
return ;
1743
1698
1744
1699
outexcept :
1745
- zend_throw_exception_ex (spl_ce_UnexpectedValueException , 0 TSRMLS_CC , "Error at offset %ld of %d bytes" , (long )((char * )p - (char * )buf ), buf_len );
1700
+ PHP_VAR_UNSERIALIZE_DESTROY (var_hash );
1701
+ zend_throw_exception_ex (spl_ce_UnexpectedValueException , 0 TSRMLS_CC , "Error at offset %ld of %d bytes" , (long )((char * )p - buf ), buf_len );
1746
1702
return ;
1747
1703
1748
- }
1749
- /* }}} */
1750
-
1751
- /* {{{ proto void ArrayObject::unserialize(string serialized)
1752
- Unserialize the object */
1753
- SPL_METHOD (Array , unserialize )
1754
- {
1755
- char * buf ;
1756
- int buf_len ;
1757
- spl_array_object * intern = (spl_array_object * )zend_object_store_get_object (getThis () TSRMLS_CC );
1758
- int was_in_unserialize = intern -> unserialize_data != NULL ;
1759
-
1760
- if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC , "s" , & buf , & buf_len ) == FAILURE ) {
1761
- return ;
1762
- }
1763
-
1764
- if (buf_len == 0 ) {
1765
- zend_throw_exception_ex (spl_ce_UnexpectedValueException , 0 TSRMLS_CC , "Empty serialized string cannot be empty" );
1766
- return ;
1767
- }
1768
-
1769
- if (!was_in_unserialize ) {
1770
- intern -> unserialize_data = emalloc (sizeof (php_unserialize_data_t ));
1771
- PHP_VAR_UNSERIALIZE_INIT (* intern -> unserialize_data );
1772
- }
1773
-
1774
- spl_array_unserialize_helper (intern , (const unsigned char * )buf , buf_len , intern -> unserialize_data TSRMLS_CC );
1775
-
1776
- if (!was_in_unserialize ) {
1777
- PHP_VAR_UNSERIALIZE_DESTROY (* intern -> unserialize_data );
1778
- efree (intern -> unserialize_data );
1779
- intern -> unserialize_data = NULL ;
1780
- }
1781
1704
} /* }}} */
1782
1705
1783
- int spl_array_unserialize (zval * * object , zend_class_entry * ce , const unsigned char * buf , zend_uint buf_len , zend_unserialize_data * data TSRMLS_DC )
1784
- {
1785
- spl_array_object * intern ;
1786
-
1787
- object_init_ex (* object , ce );
1788
- intern = (spl_array_object * )zend_object_store_get_object (* object TSRMLS_CC );
1789
-
1790
- if (intern -> fptr_unserialize ) {
1791
- zval * zdata ;
1792
- php_unserialize_data_t * before ;
1793
- MAKE_STD_ZVAL (zdata );
1794
- ZVAL_STRINGL (zdata , (char * )buf , buf_len , 1 );
1795
-
1796
- before = intern -> unserialize_data ;
1797
- intern -> unserialize_data = (php_unserialize_data_t * )data ;
1798
-
1799
- zend_call_method_with_1_params (object , ce , & ce -> unserialize_func , "unserialize" , NULL , zdata );
1800
-
1801
- intern -> unserialize_data = before ;
1802
-
1803
- zval_ptr_dtor (& zdata );
1804
- } else {
1805
- spl_array_unserialize_helper (intern , buf , buf_len , (php_unserialize_data_t * )data TSRMLS_CC );
1806
- }
1807
-
1808
- if (EG (exception )) {
1809
- return FAILURE ;
1810
- } else {
1811
- return SUCCESS ;
1812
- }
1813
- }
1814
- /* }}} */
1815
-
1816
1706
/* {{{ arginfo and function tbale */
1817
1707
ZEND_BEGIN_ARG_INFO (arginfo_array___construct , 0 )
1818
1708
ZEND_ARG_INFO (0 , array )
@@ -1928,8 +1818,6 @@ PHP_MINIT_FUNCTION(spl_array)
1928
1818
REGISTER_SPL_IMPLEMENTS (ArrayObject , Aggregate );
1929
1819
REGISTER_SPL_IMPLEMENTS (ArrayObject , ArrayAccess );
1930
1820
REGISTER_SPL_IMPLEMENTS (ArrayObject , Serializable );
1931
- spl_ce_ArrayObject -> serialize = spl_array_serialize ;
1932
- spl_ce_ArrayObject -> unserialize = spl_array_unserialize ;
1933
1821
memcpy (& spl_handler_ArrayObject , zend_get_std_object_handlers (), sizeof (zend_object_handlers ));
1934
1822
1935
1823
spl_handler_ArrayObject .clone_obj = spl_array_object_clone ;
@@ -1952,8 +1840,6 @@ PHP_MINIT_FUNCTION(spl_array)
1952
1840
REGISTER_SPL_IMPLEMENTS (ArrayIterator , ArrayAccess );
1953
1841
REGISTER_SPL_IMPLEMENTS (ArrayIterator , SeekableIterator );
1954
1842
REGISTER_SPL_IMPLEMENTS (ArrayIterator , Serializable );
1955
- spl_ce_ArrayIterator -> serialize = spl_array_serialize ;
1956
- spl_ce_ArrayIterator -> unserialize = spl_array_unserialize ;
1957
1843
memcpy (& spl_handler_ArrayIterator , & spl_handler_ArrayObject , sizeof (zend_object_handlers ));
1958
1844
spl_ce_ArrayIterator -> get_iterator = spl_array_get_iterator ;
1959
1845
0 commit comments