@@ -1057,10 +1057,7 @@ void php_phongo_cursor_new_from_result(zval *object, php_phongo_result_t *result
1057
1057
object_init_ex (object , php_phongo_cursor_ce );
1058
1058
1059
1059
intern = (php_phongo_cursor_t * )zend_object_store_get_object (object TSRMLS_CC );
1060
- intern -> cursor = result -> cursor ;
1061
- intern -> is_command_cursor = result -> is_command_cursor ;
1062
- intern -> firstBatch = result -> firstBatch ;
1063
- intern -> hint = result -> hint ;
1060
+ intern -> result = result ;
1064
1061
} /* }}} */
1065
1062
1066
1063
void php_phongo_objectid_new_from_oid (zval * object , const bson_oid_t * oid TSRMLS_DC ) /* {{{ */
@@ -1169,48 +1166,58 @@ void php_phongo_result_free(php_phongo_result_t *result)
1169
1166
/* {{{ Iterator */
1170
1167
typedef struct {
1171
1168
zend_object_iterator iterator ;
1172
- mongoc_cursor_t * cursor ;
1173
- bson_t * firstBatch ;
1174
1169
bson_iter_t first_batch_iter ;
1175
- int hint ;
1176
- zend_bool is_command_cursor ;
1177
- php_phongo_bson_state visitor_data ;
1178
1170
} phongo_cursor_it ;
1179
1171
1180
- static void phongo_cursor_it_invalidate_current (zend_object_iterator * iter TSRMLS_DC )
1172
+ static void phongo_cursor_it_invalidate_current (zend_object_iterator * iter TSRMLS_DC ) /* {{{ */
1181
1173
{
1182
- phongo_cursor_it * cursor_it = ( phongo_cursor_it * ) iter ;
1174
+ php_phongo_result_t * result = NULL ;
1183
1175
1184
- if (cursor_it -> visitor_data .zchild ) {
1185
- zval_ptr_dtor (& cursor_it -> visitor_data .zchild );
1186
- cursor_it -> visitor_data .zchild = NULL ;
1176
+ result = ((phongo_cursor_it * )iter )-> iterator .data ;
1177
+ if (result -> visitor_data .zchild ) {
1178
+ zval_ptr_dtor (& result -> visitor_data .zchild );
1179
+ result -> visitor_data .zchild = NULL ;
1187
1180
}
1188
- }
1181
+ } /* }}} */
1182
+
1189
1183
static void phongo_cursor_it_dtor (zend_object_iterator * iter TSRMLS_DC ) /* {{{ */
1190
1184
{
1191
1185
phongo_cursor_it * cursor_it = (phongo_cursor_it * )iter ;
1192
1186
1193
1187
iter -> funcs -> invalidate_current (iter TSRMLS_CC );
1194
1188
1195
- zval_ptr_dtor ((zval * * )& cursor_it -> iterator .data );
1196
1189
efree (cursor_it );
1197
1190
} /* }}} */
1198
1191
1199
1192
static int phongo_cursor_it_valid (zend_object_iterator * iter TSRMLS_DC ) /* {{{ */
1200
1193
{
1201
- return ((phongo_cursor_it * )iter )-> visitor_data .zchild ? SUCCESS : FAILURE ;
1194
+ php_phongo_result_t * result = NULL ;
1195
+
1196
+ result = ((phongo_cursor_it * )iter )-> iterator .data ;
1197
+
1198
+ if (result -> visitor_data .zchild ) {
1199
+ return SUCCESS ;
1200
+ }
1201
+
1202
+ return FAILURE ;
1202
1203
} /* }}} */
1203
1204
1204
1205
static void phongo_cursor_it_get_current_data (zend_object_iterator * iter , zval * * * data TSRMLS_DC ) /* {{{ */
1205
1206
{
1206
- * data = & ((phongo_cursor_it * )iter )-> visitor_data .zchild ;
1207
+ php_phongo_result_t * result = NULL ;
1208
+
1209
+ result = ((phongo_cursor_it * )iter )-> iterator .data ;
1210
+
1211
+ * data = & result -> visitor_data .zchild ;
1207
1212
} /* }}} */
1208
1213
1209
1214
static void phongo_cursor_it_move_forward (zend_object_iterator * iter TSRMLS_DC ) /* {{{ */
1210
1215
{
1216
+ php_phongo_result_t * result = NULL ;
1211
1217
phongo_cursor_it * cursor_it = (phongo_cursor_it * )iter ;
1212
1218
const bson_t * doc ;
1213
1219
1220
+ result = ((phongo_cursor_it * )iter )-> iterator .data ;
1214
1221
iter -> funcs -> invalidate_current (iter TSRMLS_CC );
1215
1222
1216
1223
iter -> index ++ ;
@@ -1221,14 +1228,14 @@ static void phongo_cursor_it_move_forward(zend_object_iterator *iter TSRMLS_DC)
1221
1228
1222
1229
bson_iter_document (& cursor_it -> first_batch_iter , & data_len , & data );
1223
1230
1224
- MAKE_STD_ZVAL (cursor_it -> visitor_data .zchild );
1225
- bson_to_zval (data , data_len , & cursor_it -> visitor_data );
1231
+ MAKE_STD_ZVAL (result -> visitor_data .zchild );
1232
+ bson_to_zval (data , data_len , & result -> visitor_data );
1226
1233
return ;
1227
1234
}
1228
1235
}
1229
- if (mongoc_cursor_next (cursor_it -> cursor , & doc )) {
1230
- MAKE_STD_ZVAL (cursor_it -> visitor_data .zchild );
1231
- bson_to_zval (bson_get_data (doc ), doc -> len , & cursor_it -> visitor_data );
1236
+ if (mongoc_cursor_next (result -> cursor , & doc )) {
1237
+ MAKE_STD_ZVAL (result -> visitor_data .zchild );
1238
+ bson_to_zval (bson_get_data (doc ), doc -> len , & result -> visitor_data );
1232
1239
} else {
1233
1240
iter -> funcs -> invalidate_current (iter TSRMLS_CC );
1234
1241
}
@@ -1237,14 +1244,17 @@ static void phongo_cursor_it_move_forward(zend_object_iterator *iter TSRMLS_DC)
1237
1244
1238
1245
static void phongo_cursor_it_rewind (zend_object_iterator * iter TSRMLS_DC ) /* {{{ */
1239
1246
{
1240
- phongo_cursor_it * cursor_it = (phongo_cursor_it * )iter ;
1247
+ php_phongo_result_t * result = NULL ;
1248
+ phongo_cursor_it * cursor_it = (phongo_cursor_it * )iter ;
1249
+
1250
+ result = ((phongo_cursor_it * )iter )-> iterator .data ;
1241
1251
1242
1252
iter -> funcs -> invalidate_current (iter TSRMLS_CC );
1243
1253
1244
1254
/* firstBatch is empty when the query simply didn't return any results */
1245
- if (cursor_it -> firstBatch ) {
1246
- if (cursor_it -> is_command_cursor ) {
1247
- if (!bson_iter_init (& cursor_it -> first_batch_iter , cursor_it -> firstBatch )) {
1255
+ if (result -> firstBatch ) {
1256
+ if (result -> is_command_cursor ) {
1257
+ if (!bson_iter_init (& cursor_it -> first_batch_iter , result -> firstBatch )) {
1248
1258
return ;
1249
1259
}
1250
1260
if (bson_iter_next (& cursor_it -> first_batch_iter )) {
@@ -1253,13 +1263,13 @@ static void phongo_cursor_it_rewind(zend_object_iterator *iter TSRMLS_DC) /* {{{
1253
1263
uint32_t data_len = 0 ;
1254
1264
1255
1265
bson_iter_document (& cursor_it -> first_batch_iter , & data_len , & data );
1256
- MAKE_STD_ZVAL (cursor_it -> visitor_data .zchild );
1257
- bson_to_zval (data , data_len , & cursor_it -> visitor_data );
1266
+ MAKE_STD_ZVAL (result -> visitor_data .zchild );
1267
+ bson_to_zval (data , data_len , & result -> visitor_data );
1258
1268
}
1259
1269
}
1260
1270
} else {
1261
- MAKE_STD_ZVAL (cursor_it -> visitor_data .zchild );
1262
- bson_to_zval (bson_get_data (cursor_it -> firstBatch ), cursor_it -> firstBatch -> len , & cursor_it -> visitor_data );
1271
+ MAKE_STD_ZVAL (result -> visitor_data .zchild );
1272
+ bson_to_zval (bson_get_data (result -> firstBatch ), result -> firstBatch -> len , & result -> visitor_data );
1263
1273
}
1264
1274
}
1265
1275
} /* }}} */
@@ -1296,30 +1306,25 @@ zend_object_iterator *phongo_cursor_get_iterator(zend_class_entry *ce, zval *obj
1296
1306
1297
1307
cursor_it = ecalloc (1 , sizeof (phongo_cursor_it ));
1298
1308
1299
- Z_ADDREF_P (object );
1300
- cursor_it -> iterator .data = (void * )object ;
1309
+ cursor_it -> iterator .data = intern -> result ;
1301
1310
cursor_it -> iterator .funcs = & phongo_cursor_it_funcs ;
1302
- cursor_it -> cursor = intern -> cursor ;
1303
- cursor_it -> is_command_cursor = intern -> is_command_cursor ;
1304
- cursor_it -> firstBatch = intern -> firstBatch ;
1305
- cursor_it -> hint = intern -> hint ;
1306
1311
1307
1312
return (zend_object_iterator * )cursor_it ;
1308
1313
} /* }}} */
1309
1314
zend_object_iterator * phongo_result_get_iterator (zend_class_entry * ce , zval * object , int by_ref TSRMLS_DC ) /* {{{ */
1310
1315
{
1311
- php_phongo_result_t * intern = (php_phongo_result_t * )zend_object_store_get_object (object TSRMLS_CC );
1316
+ php_phongo_result_t * result = (php_phongo_result_t * )zend_object_store_get_object (object TSRMLS_CC );
1312
1317
1313
1318
if (by_ref ) {
1314
1319
zend_error (E_ERROR , "An iterator cannot be used with foreach by reference" );
1315
1320
}
1316
1321
1317
1322
/* If we have a custom iterator */
1318
- if (intern -> ce_get_iterator != NULL ) {
1323
+ if (result -> ce_get_iterator != NULL ) {
1319
1324
zend_user_iterator * iterator = NULL ;
1320
1325
1321
1326
zval_ptr_dtor (& object );
1322
- object_init_ex (object , intern -> ce_get_iterator );
1327
+ object_init_ex (object , result -> ce_get_iterator );
1323
1328
1324
1329
iterator = emalloc (sizeof (zend_user_iterator ));
1325
1330
@@ -1334,18 +1339,12 @@ zend_object_iterator *phongo_result_get_iterator(zend_class_entry *ce, zval *obj
1334
1339
1335
1340
cursor_it = ecalloc (1 , sizeof (phongo_cursor_it ));
1336
1341
1337
- if (cursor_it -> visitor_data .zchild ) {
1338
- zval_ptr_dtor (& cursor_it -> visitor_data .zchild );
1339
- cursor_it -> visitor_data .zchild = NULL ;
1342
+ if (result -> visitor_data .zchild ) {
1343
+ zval_ptr_dtor (& result -> visitor_data .zchild );
1344
+ result -> visitor_data .zchild = NULL ;
1340
1345
}
1341
- Z_ADDREF_P (object );
1342
- cursor_it -> iterator .data = (void * )object ;
1346
+ cursor_it -> iterator .data = (void * )result ;
1343
1347
cursor_it -> iterator .funcs = & phongo_cursor_it_funcs ;
1344
- cursor_it -> cursor = intern -> cursor ;
1345
- cursor_it -> firstBatch = intern -> firstBatch ;
1346
- cursor_it -> hint = intern -> hint ;
1347
- cursor_it -> is_command_cursor = intern -> is_command_cursor ;
1348
- cursor_it -> visitor_data = intern -> visitor_data ;
1349
1348
1350
1349
return (zend_object_iterator * )cursor_it ;
1351
1350
}
0 commit comments