The current element is already freed at the top of this function. After that point, the element could only be intialized from first_batch_iter (after which we return immediately) or if mongoc_cursor_next() returns true (in which case we wouldn't be in this else clause).
This removes the invalidate_current handler. Due to SPL's implementation, our handler was being invoked between rewinding and checking if the current position was valid. Given that our validity check depends on inspecting a pointer to the current element (like MySQLi's result iterator), we cannot use invalidate_current.
The current element must still be freed during iteration, so we will instead call a php_phongo_cursor_free_current() function as needed. Additionally, we should track a reference to the Cursor object zval on the iterator itself, which will ensure it is not garbage-collected during iteration (demonstrated in the segfault backtrace in PHPC-215).
Lastly, this commit renames the Cursor object and iterator structs and related functions to be more consistent with implementions in PHP core.
There is a shutdown race condition in the mongoc counters segment
allocation where zend mm will free the counters during RSHUTDOWN.
This happens as there is no "persistent alloc" callback from the bson
allocators that we can pemalloc() for.
Instead, we'll let mongoc_init use its own alloctors -- but we have to
remember to reset the alloc callbacks before mongoc_cleanup()
If a socket write returns EWOULDBLOCK PHP will poll() using the socket
read timeout.
This is only an issue when writing crazy amount of data to a
non-blocking socket in multiple iterations... which we do.
We copy the write concern struct rather than store an is_acknowledged boolean, which allows us to include the write concern in the debug output. Down the line, we may decide to implement a getWriteConcern() method to help users in handling/logging write concern errors.
This mainly removes logic where no fields were included in the debug output if "w" was equal to MONGOC_WRITE_CONCERN_W_DEFAULT.
Although the "wmajority" boolean exists, we can still report the actual "w" value, which will be sent to the server.
For execute[Insert|Update|Delete]() we unroll the BulkWrite exception
and throw the inner errors.
Note: WriteConcern failure now throws WriteConcernException!