@@ -1177,14 +1177,20 @@ typedef struct {
1177
1177
php_phongo_bson_state visitor_data ;
1178
1178
} phongo_cursor_it ;
1179
1179
1180
- static void phongo_cursor_it_dtor (zend_object_iterator * iter TSRMLS_DC ) /* {{{ */
1180
+ static void phongo_cursor_it_invalidate_current (zend_object_iterator * iter TSRMLS_DC )
1181
1181
{
1182
1182
phongo_cursor_it * cursor_it = (phongo_cursor_it * )iter ;
1183
1183
1184
1184
if (cursor_it -> visitor_data .zchild ) {
1185
1185
zval_ptr_dtor (& cursor_it -> visitor_data .zchild );
1186
1186
cursor_it -> visitor_data .zchild = NULL ;
1187
1187
}
1188
+ }
1189
+ static void phongo_cursor_it_dtor (zend_object_iterator * iter TSRMLS_DC ) /* {{{ */
1190
+ {
1191
+ phongo_cursor_it * cursor_it = (phongo_cursor_it * )iter ;
1192
+
1193
+ iter -> funcs -> invalidate_current (iter TSRMLS_CC );
1188
1194
1189
1195
zval_ptr_dtor ((zval * * )& cursor_it -> iterator .data );
1190
1196
efree (cursor_it );
@@ -1205,11 +1211,9 @@ static void phongo_cursor_it_move_forward(zend_object_iterator *iter TSRMLS_DC)
1205
1211
phongo_cursor_it * cursor_it = (phongo_cursor_it * )iter ;
1206
1212
const bson_t * doc ;
1207
1213
1208
- if (cursor_it -> visitor_data .zchild ) {
1209
- zval_ptr_dtor (& cursor_it -> visitor_data .zchild );
1210
- cursor_it -> visitor_data .zchild = NULL ;
1211
- }
1214
+ iter -> funcs -> invalidate_current (iter TSRMLS_CC );
1212
1215
1216
+ iter -> index ++ ;
1213
1217
if (bson_iter_next (& cursor_it -> first_batch_iter )) {
1214
1218
if (BSON_ITER_HOLDS_DOCUMENT (& cursor_it -> first_batch_iter )) {
1215
1219
const uint8_t * data = NULL ;
@@ -1226,7 +1230,7 @@ static void phongo_cursor_it_move_forward(zend_object_iterator *iter TSRMLS_DC)
1226
1230
MAKE_STD_ZVAL (cursor_it -> visitor_data .zchild );
1227
1231
bson_to_zval (bson_get_data (doc ), doc -> len , & cursor_it -> visitor_data );
1228
1232
} else {
1229
- cursor_it -> visitor_data . zchild = NULL ;
1233
+ iter -> funcs -> invalidate_current ( iter TSRMLS_CC ) ;
1230
1234
}
1231
1235
1232
1236
} /* }}} */
@@ -1235,10 +1239,7 @@ static void phongo_cursor_it_rewind(zend_object_iterator *iter TSRMLS_DC) /* {{{
1235
1239
{
1236
1240
phongo_cursor_it * cursor_it = (phongo_cursor_it * )iter ;
1237
1241
1238
- if (cursor_it -> visitor_data .zchild ) {
1239
- zval_ptr_dtor (& cursor_it -> visitor_data .zchild );
1240
- cursor_it -> visitor_data .zchild = NULL ;
1241
- }
1242
+ iter -> funcs -> invalidate_current (iter TSRMLS_CC );
1242
1243
1243
1244
/* firstBatch is empty when the query simply didn't return any results */
1244
1245
if (cursor_it -> firstBatch ) {
@@ -1271,7 +1272,7 @@ zend_object_iterator_funcs phongo_cursor_it_funcs = {
1271
1272
NULL , /* void (*get_current_key)(zend_object_iterator *iter, zval *key TSRMLS_DC); */
1272
1273
phongo_cursor_it_move_forward ,
1273
1274
phongo_cursor_it_rewind ,
1274
- NULL /* void (*invalidate_current)(zend_object_iterator *iter TSRMLS_DC); */
1275
+ phongo_cursor_it_invalidate_current
1275
1276
};
1276
1277
zend_object_iterator_funcs zend_interface_iterator_funcs_iterator_default = {
1277
1278
phongo_cursor_it_dtor ,
0 commit comments