@@ -1075,14 +1075,6 @@ PHP_METHOD(SplPriorityQueue, __debugInfo)
1075
1075
RETURN_ARR (spl_heap_object_get_debug_info (spl_ce_SplPriorityQueue , Z_OBJ_P (ZEND_THIS )));
1076
1076
} /* }}} */
1077
1077
1078
- static void spl_heap_serialize_properties (zval * return_value , spl_heap_object * intern )
1079
- {
1080
- HashTable * props = zend_std_get_properties (& intern -> std );
1081
-
1082
- ZVAL_ARR (return_value , props );
1083
- GC_ADDREF (props );
1084
- }
1085
-
1086
1078
static void spl_heap_serialize_internal_state (zval * return_value , spl_heap_object * intern , bool is_pqueue )
1087
1079
{
1088
1080
zval heap_elements ;
@@ -1113,16 +1105,6 @@ static void spl_heap_serialize_internal_state(zval *return_value, spl_heap_objec
1113
1105
add_assoc_zval (return_value , "heap_elements" , & heap_elements );
1114
1106
}
1115
1107
1116
- static void spl_heap_unserialize_properties (HashTable * props_ht , spl_heap_object * intern )
1117
- {
1118
- object_properties_load (& intern -> std , props_ht );
1119
- if (!EG (exception )) {
1120
- return ;
1121
- }
1122
-
1123
- zend_throw_exception_ex (NULL , 0 , "Invalid serialization data for %s object" , ZSTR_VAL (intern -> std .ce -> name ));
1124
- }
1125
-
1126
1108
static void spl_heap_unserialize_internal_state (HashTable * state_ht , spl_heap_object * intern , zval * this_ptr , bool is_pqueue )
1127
1109
{
1128
1110
zval * flags_val = zend_hash_str_find (state_ht , "flags" , strlen ("flags" ));
@@ -1132,7 +1114,7 @@ static void spl_heap_unserialize_internal_state(HashTable *state_ht, spl_heap_ob
1132
1114
}
1133
1115
1134
1116
zend_long flags_value = Z_LVAL_P (flags_val );
1135
-
1117
+
1136
1118
if (is_pqueue ) {
1137
1119
flags_value &= SPL_PQUEUE_EXTR_MASK ;
1138
1120
if (!flags_value ) {
@@ -1148,27 +1130,28 @@ static void spl_heap_unserialize_internal_state(HashTable *state_ht, spl_heap_ob
1148
1130
zend_throw_exception_ex (NULL , 0 , "Invalid serialization data for %s object" , ZSTR_VAL (intern -> std .ce -> name ));
1149
1131
return ;
1150
1132
}
1151
-
1133
+
1152
1134
if (Z_TYPE_P (heap_elements ) != IS_ARRAY ) {
1153
1135
zend_throw_exception_ex (NULL , 0 , "Invalid serialization data for %s object" , ZSTR_VAL (intern -> std .ce -> name ));
1154
1136
return ;
1155
1137
}
1156
-
1138
+
1157
1139
ZEND_HASH_FOREACH_VAL (Z_ARRVAL_P (heap_elements ), zval * val ) {
1158
1140
if (is_pqueue ) {
1159
- if (Z_TYPE_P (val ) != IS_ARRAY ) {
1141
+ /* PriorityQueue elements are serialized as arrays with 'data' and 'priority' keys */
1142
+ if (Z_TYPE_P (val ) != IS_ARRAY || zend_hash_num_elements (Z_ARRVAL_P (val )) != 2 ) {
1160
1143
zend_throw_exception_ex (NULL , 0 , "Invalid serialization data for %s object" , ZSTR_VAL (intern -> std .ce -> name ));
1161
1144
return ;
1162
1145
}
1163
-
1146
+
1164
1147
zval * data_val = zend_hash_str_find (Z_ARRVAL_P (val ), "data" , strlen ("data" ) );
1165
1148
zval * priority_val = zend_hash_str_find (Z_ARRVAL_P (val ), "priority" , strlen ("priority" ));
1166
-
1149
+
1167
1150
if (!data_val || !priority_val ) {
1168
1151
zend_throw_exception_ex (NULL , 0 , "Invalid serialization data for %s object" , ZSTR_VAL (intern -> std .ce -> name ));
1169
1152
return ;
1170
1153
}
1171
-
1154
+
1172
1155
spl_pqueue_elem elem ;
1173
1156
ZVAL_COPY (& elem .data , data_val );
1174
1157
ZVAL_COPY (& elem .priority , priority_val );
@@ -1193,7 +1176,8 @@ PHP_METHOD(SplPriorityQueue, __serialize)
1193
1176
1194
1177
array_init (return_value );
1195
1178
1196
- spl_heap_serialize_properties (& props , intern );
1179
+ ZVAL_ARR (& props , zend_std_get_properties (& intern -> std ));
1180
+ Z_TRY_ADDREF (props );
1197
1181
zend_hash_next_index_insert (Z_ARRVAL_P (return_value ), & props );
1198
1182
1199
1183
spl_heap_serialize_internal_state (& state , intern , true);
@@ -1220,8 +1204,9 @@ PHP_METHOD(SplPriorityQueue, __unserialize)
1220
1204
RETURN_THROWS ();
1221
1205
}
1222
1206
1223
- spl_heap_unserialize_properties ( Z_ARRVAL_P (props ), intern );
1207
+ object_properties_load ( & intern -> std , Z_ARRVAL_P (props ));
1224
1208
if (EG (exception )) {
1209
+ zend_throw_exception_ex (NULL , 0 , "Invalid serialization data for %s object" , ZSTR_VAL (intern -> std .ce -> name ));
1225
1210
RETURN_THROWS ();
1226
1211
}
1227
1212
@@ -1250,7 +1235,8 @@ PHP_METHOD(SplHeap, __serialize)
1250
1235
1251
1236
array_init (return_value );
1252
1237
1253
- spl_heap_serialize_properties (& props , intern );
1238
+ ZVAL_ARR (& props , zend_std_get_properties (& intern -> std ));
1239
+ Z_TRY_ADDREF (props );
1254
1240
zend_hash_next_index_insert (Z_ARRVAL_P (return_value ), & props );
1255
1241
1256
1242
spl_heap_serialize_internal_state (& state , intern , false);
@@ -1277,8 +1263,9 @@ PHP_METHOD(SplHeap, __unserialize)
1277
1263
RETURN_THROWS ();
1278
1264
}
1279
1265
1280
- spl_heap_unserialize_properties ( Z_ARRVAL_P (props ), intern );
1266
+ object_properties_load ( & intern -> std , Z_ARRVAL_P (props ));
1281
1267
if (EG (exception )) {
1268
+ zend_throw_exception_ex (NULL , 0 , "Invalid serialization data for %s object" , ZSTR_VAL (intern -> std .ce -> name ));
1282
1269
RETURN_THROWS ();
1283
1270
}
1284
1271
0 commit comments