Skip to content

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

Merged

Conversation

derickr
Copy link
Contributor

@derickr derickr commented Sep 19, 2016

}
} /* }}} */

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);
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

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);
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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

Copy link
Member

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.

Copy link
Contributor Author

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);
Copy link
Member

@jmikola jmikola Sep 19, 2016

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);
Copy link
Member

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().

@derickr derickr force-pushed the PHPC-498-read-preference-concern-serialization branch from bbf4389 to ffa4262 Compare September 19, 2016 16:33
*/
PHP_METHOD(ReadConcern, bsonSerialize)
{
const mongoc_read_concern_t *read_concern = phongo_read_concern_from_zval(getThis() TSRMLS_CC);
Copy link
Member

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);
Copy link
Member

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;
Copy link
Member

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) {
Copy link
Member

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.

@jmikola
Copy link
Member

jmikola commented Sep 19, 2016

LGTM. I'll add the (char *) casts to ADD_ASSOC_STRING() on my own after this is merged.

@derickr derickr force-pushed the PHPC-498-read-preference-concern-serialization branch from ffa4262 to 8f9e6c8 Compare September 19, 2016 19:33
@derickr derickr merged commit 8f9e6c8 into mongodb:master Sep 19, 2016
derickr added a commit that referenced this pull request Sep 19, 2016
jmikola added a commit to jmikola/mongo-php-driver that referenced this pull request Sep 19, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants