-
Notifications
You must be signed in to change notification settings - Fork 208
PHPC-498: ReadPreference, ReadConcern, and WriteConcern should serialize to BSON #413
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PHPC-498: ReadPreference, ReadConcern, and WriteConcern should serialize to BSON #413
Conversation
} | ||
} /* }}} */ | ||
|
||
void php_phongo_write_concern_to_zval(zval *retval, const mongoc_write_concern_t *write_concern) /* {{{ */ | ||
{ | ||
const char *wtag = mongoc_write_concern_get_wtag(write_concern); | ||
const int32_t w = mongoc_write_concern_get_w(write_concern); | ||
const int32_t wtimeout = mongoc_write_concern_get_wtimeout(write_concern); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this count as mixing code and declarations? I actually would have thought the compiler would yell about the existing *wtag
and w
lines.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that's a problem for initializers.... but a good point. But we do this in many other places too:
858 php_phongo_server_description_type_t php_phongo_server_description_type(mongoc_server_description_t *sd)
859 {
860 const char* name = mongoc_server_description_type(sd);
861 int i;
862
872 void php_phongo_server_to_zval(zval *retval, mongoc_server_description_t *sd) /* {{{ */
873 {
874 mongoc_host_list_t *host = mongoc_server_description_host(sd);
875 const bson_t *is_master = mongoc_server_description_ismaster(sd);
876 bson_iter_t iter;
877
in the same file for example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Confirming that this doesn't appear to be a problem with my local builds.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to have a proper definitive answer on this somewhere. Can't be arsed to read the spec though :-)
*/ | ||
PHP_METHOD(ReadConcern, bsonSerialize) | ||
{ | ||
const mongoc_read_concern_t *read_concern = phongo_read_concern_from_zval(getThis() TSRMLS_CC); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For consistency with our other functions that take no arguments, I'd consider adding this:
if (zend_parse_parameters_none() == FAILURE) {
return;
}
Also, did we need the following suppressions for PHP 5.x?
SUPPRESS_UNUSED_WARNING(return_value_ptr) SUPPRESS_UNUSED_WARNING(return_value_used)
If these warnings didn't trigger for you, you can always omit this change. I'll add them back if I see them later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These warnings are IMO superfluous. I have never noticed this being necessary, and I have never seen this in other extensions either.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you configure phongo with --enable-developer-flags
it'll add -Wunused-parameter
, which would issue a warning for arguments that aren't used.
The PHP_METHOD() macro defines a c function that has all sorts of arguments, including return_value_ptr
and return_value_used
which are rarely used, which is why those macros meant to suppress them, so the flag can still be helpful for avoid accidentally declaring superfluous arguments in other functions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It appears that -Wno-unused-parameter
was introduced in e3e3c9d#diff-788d457a20b110cc38e571dec9ddc68cR126, builds have been ignoring unused variables since then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with not having warnings for unused function arguments though. Catching locally undefined vars is important though.
*/ | ||
PHP_METHOD(WriteConcern, bsonSerialize) | ||
{ | ||
const mongoc_write_concern_t *write_concern = phongo_write_concern_from_zval(getThis() TSRMLS_CC); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same changes as ReadConcern::bsonSerialize()
.
*/ | ||
PHP_METHOD(ReadPreference, bsonSerialize) | ||
{ | ||
const mongoc_read_prefs_t *read_preference = phongo_read_preference_from_zval(getThis() TSRMLS_CC); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same changes as ReadConcern::bsonSerialize()
.
bbf4389
to
ffa4262
Compare
*/ | ||
PHP_METHOD(ReadConcern, bsonSerialize) | ||
{ | ||
const mongoc_read_concern_t *read_concern = phongo_read_concern_from_zval(getThis() TSRMLS_CC); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It appears that -Wno-unused-parameter
was introduced in e3e3c9d#diff-788d457a20b110cc38e571dec9ddc68cR126, builds have been ignoring unused variables since then.
} | ||
} /* }}} */ | ||
|
||
void php_phongo_write_concern_to_zval(zval *retval, const mongoc_write_concern_t *write_concern) /* {{{ */ | ||
{ | ||
const char *wtag = mongoc_write_concern_get_wtag(write_concern); | ||
const int32_t w = mongoc_write_concern_get_w(write_concern); | ||
const int32_t wtimeout = mongoc_write_concern_get_wtimeout(write_concern); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Confirming that this doesn't appear to be a problem with my local builds.
case MONGOC_READ_PRIMARY_PREFERRED: ADD_ASSOC_STRING(retval, "mode", "primaryPreferred"); break; | ||
case MONGOC_READ_SECONDARY: ADD_ASSOC_STRING(retval, "mode", "secondary"); break; | ||
case MONGOC_READ_SECONDARY_PREFERRED: ADD_ASSOC_STRING(retval, "mode", "secondaryPreferred"); break; | ||
case MONGOC_READ_NEAREST: ADD_ASSOC_STRING(retval, "mode", "nearest"); break; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add_assoc_string_ex()
requires a char *
for the value string, so each of these will need (char *)
casting. Alternatively, I suppose we can just add that in the macro definition.
int(0) | ||
["journal"]=> | ||
NULL | ||
array(%d) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you're expecting an empty array here, array(0)
would be preferred.
LGTM. I'll add the |
ffa4262
to
8f9e6c8
Compare
These test fixes were missed in mongodb#413.
https://jira.mongodb.org/browse/PHPC-498