40
40
41
41
zend_class_entry * php_phongo_bulkwritecommandresult_ce ;
42
42
43
- static bool php_phongo_bulkwritecommandresult_get_writeconcernerrors (php_phongo_bulkwritecommandresult_t * intern , zval * return_value )
43
+ /* Populates return_value with a list of WriteConcernError objects. Returns true
44
+ * on success; otherwise, false is returned and an exception is thrown. */
45
+ static bool phongo_bulkwritecommandresult_get_writeconcernerrors (php_phongo_bulkwritecommandresult_t * intern , zval * return_value )
44
46
{
45
47
bson_iter_t iter ;
46
48
47
49
array_init (return_value );
48
50
49
- if (!intern -> write_concern_errors ) {
50
- return true;
51
- }
51
+ if (intern -> write_concern_errors && bson_iter_init (& iter , intern -> write_concern_errors )) {
52
+ while (bson_iter_next (& iter )) {
53
+ bson_t bson ;
54
+ uint32_t len ;
55
+ const uint8_t * data ;
56
+ zval write_concern_error ;
52
57
53
- for (bson_iter_init (& iter , intern -> write_concern_errors ); bson_iter_next (& iter );) {
54
- bson_t bson ;
55
- uint32_t len ;
56
- const uint8_t * data ;
57
- zval write_concern_error ;
58
+ if (!BSON_ITER_HOLDS_DOCUMENT (& iter )) {
59
+ continue ;
60
+ }
58
61
59
- if (!BSON_ITER_HOLDS_DOCUMENT (& iter )) {
60
- continue ;
61
- }
62
+ bson_iter_document (& iter , & len , & data );
62
63
63
- bson_iter_document (& iter , & len , & data );
64
+ if (!bson_init_static (& bson , data , len )) {
65
+ continue ;
66
+ }
64
67
65
- if (!bson_init_static (& bson , data , len )) {
66
- continue ;
67
- }
68
+ if (!phongo_writeconcernerror_init (& write_concern_error , & bson )) {
69
+ /* Exception already thrown */
70
+ zval_ptr_dtor (& write_concern_error );
71
+ return false;
72
+ }
68
73
69
- if (!phongo_writeconcernerror_init (& write_concern_error , & bson )) {
70
- zval_ptr_dtor (& write_concern_error );
71
- continue ;
74
+ add_next_index_zval (return_value , & write_concern_error );
72
75
}
73
-
74
- add_next_index_zval (return_value , & write_concern_error );
75
76
}
76
77
77
78
return true;
78
79
}
79
80
80
- static bool php_phongo_bulkwritecommandresult_get_writeerrors (php_phongo_bulkwritecommandresult_t * intern , zval * return_value )
81
+ /* Populates return_value with a map of WriteError objects indexed by the offset
82
+ * of the corresponding operation. Returns true on success; otherwise, false is
83
+ * returned and an exception is thrown. */
84
+ static bool phongo_bulkwritecommandresult_get_writeerrors (php_phongo_bulkwritecommandresult_t * intern , zval * return_value )
81
85
{
82
86
bson_iter_t iter ;
83
87
84
88
array_init (return_value );
85
89
86
- if (!intern -> write_errors ) {
87
- return true;
88
- }
90
+ if (intern -> write_errors && bson_iter_init (& iter , intern -> write_errors )) {
91
+ while (bson_iter_next (& iter )) {
92
+ bson_t bson ;
93
+ uint32_t len ;
94
+ const uint8_t * data ;
95
+ zval write_error ;
96
+ zend_ulong index ;
89
97
90
- for (bson_iter_init (& iter , intern -> write_errors ); bson_iter_next (& iter );) {
91
- bson_t bson ;
92
- uint32_t len ;
93
- const uint8_t * data ;
94
- zval write_error ;
95
- zend_ulong index ;
98
+ if (!BSON_ITER_HOLDS_DOCUMENT (& iter )) {
99
+ continue ;
100
+ }
96
101
97
- if (!BSON_ITER_HOLDS_DOCUMENT (& iter )) {
98
- continue ;
99
- }
102
+ bson_iter_document (& iter , & len , & data );
100
103
101
- bson_iter_document (& iter , & len , & data );
104
+ if (!bson_init_static (& bson , data , len )) {
105
+ continue ;
106
+ }
102
107
103
- if (!bson_init_static (& bson , data , len )) {
104
- continue ;
105
- }
108
+ index = (zend_ulong ) ZEND_STRTOUL (bson_iter_key (& iter ), NULL , 10 );
106
109
107
- index = (zend_ulong ) ZEND_STRTOUL (bson_iter_key (& iter ), NULL , 10 );
110
+ if (!phongo_writeerror_init_ex (& write_error , & bson , (int32_t ) index )) {
111
+ /* Exception already thrown */
112
+ zval_ptr_dtor (& write_error );
113
+ return false;
114
+ }
108
115
109
- if (!phongo_writeerror_init_ex (& write_error , & bson , (int32_t ) index )) {
110
- zval_ptr_dtor (& write_error );
111
- continue ;
116
+ add_index_zval (return_value , index , & write_error );
112
117
}
113
-
114
- add_index_zval (return_value , index , & write_error );
115
118
}
116
119
117
120
return true;
@@ -258,7 +261,7 @@ static PHP_METHOD(MongoDB_Driver_BulkWriteCommandResult, getWriteConcernErrors)
258
261
259
262
PHONGO_PARSE_PARAMETERS_NONE ();
260
263
261
- php_phongo_bulkwritecommandresult_get_writeconcernerrors (intern , return_value );
264
+ phongo_bulkwritecommandresult_get_writeconcernerrors (intern , return_value );
262
265
}
263
266
264
267
/* Returns any write errors that occurred */
@@ -270,7 +273,7 @@ static PHP_METHOD(MongoDB_Driver_BulkWriteCommandResult, getWriteErrors)
270
273
271
274
PHONGO_PARSE_PARAMETERS_NONE ();
272
275
273
- php_phongo_bulkwritecommandresult_get_writeerrors (intern , return_value );
276
+ phongo_bulkwritecommandresult_get_writeerrors (intern , return_value );
274
277
}
275
278
276
279
static PHP_METHOD (MongoDB_Driver_BulkWriteCommandResult , getErrorReply )
@@ -378,14 +381,14 @@ static HashTable* php_phongo_bulkwritecommandresult_get_debug_info(zend_object*
378
381
{
379
382
zval writeerrors ;
380
383
381
- php_phongo_bulkwritecommandresult_get_writeerrors (intern , & writeerrors );
384
+ phongo_bulkwritecommandresult_get_writeerrors (intern , & writeerrors );
382
385
ADD_ASSOC_ZVAL_EX (& retval , "writeErrors" , & writeerrors );
383
386
}
384
387
385
388
{
386
389
zval writeconcernerrors ;
387
390
388
- php_phongo_bulkwritecommandresult_get_writeconcernerrors (intern , & writeconcernerrors );
391
+ phongo_bulkwritecommandresult_get_writeconcernerrors (intern , & writeconcernerrors );
389
392
ADD_ASSOC_ZVAL_EX (& retval , "writeConcernErrors" , & writeconcernerrors );
390
393
}
391
394
0 commit comments