Skip to content

Commit 7757f11

Browse files
committed
PHPC-425: WC ctor should accept int/string $w args w/o casting
1 parent 6b5e7ca commit 7757f11

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

src/MongoDB/WriteConcern.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,18 @@ PHP_METHOD(WriteConcern, __construct)
5353
{
5454
php_phongo_writeconcern_t *intern;
5555
zend_error_handling error_handling;
56-
char *wstring;
57-
int wstring_len;
56+
zval *w;
5857
long wtimeout = 0;
5958
zend_bool journal = 0;
6059
zend_bool fsync = 0;
61-
long w;
60+
6261
(void)return_value; (void)return_value_ptr; (void)return_value_used;
6362

6463

6564
zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling TSRMLS_CC);
6665
intern = (php_phongo_writeconcern_t *)zend_object_store_get_object(getThis() TSRMLS_CC);
6766

68-
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|lbb", &wstring, &wstring_len, &wtimeout, &journal, &fsync) == FAILURE) {
67+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|lbb", &w, &wtimeout, &journal, &fsync) == FAILURE) {
6968
zend_restore_error_handling(&error_handling TSRMLS_CC);
7069
return;
7170
}
@@ -74,13 +73,13 @@ PHP_METHOD(WriteConcern, __construct)
7473

7574
intern->write_concern = mongoc_write_concern_new();
7675

77-
if (IS_LONG == is_numeric_string(wstring, wstring_len, &w, NULL, 0)) {
78-
mongoc_write_concern_set_w(intern->write_concern, w);
79-
} else {
80-
if (strcmp(wstring, PHONGO_WRITE_CONCERN_W_MAJORITY) == 0) {
76+
if (Z_TYPE_P(w) == IS_LONG) {
77+
mongoc_write_concern_set_w(intern->write_concern, Z_LVAL_P(w));
78+
} else if (Z_TYPE_P(w) == IS_STRING) {
79+
if (strcmp(Z_STRVAL_P(w), PHONGO_WRITE_CONCERN_W_MAJORITY) == 0) {
8180
mongoc_write_concern_set_w(intern->write_concern, MONGOC_WRITE_CONCERN_W_MAJORITY);
8281
} else {
83-
mongoc_write_concern_set_wtag(intern->write_concern, wstring);
82+
mongoc_write_concern_set_wtag(intern->write_concern, Z_STRVAL_P(w));
8483
}
8584
}
8685

tests/writeConcern/writeconcern-getw-001.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ $tests = array(
1515
1,
1616
2,
1717
'tag',
18+
'2',
1819
);
1920

2021
foreach ($tests as $test) {
@@ -34,4 +35,5 @@ int(0)
3435
int(1)
3536
int(2)
3637
string(3) "tag"
38+
string(1) "2"
3739
===DONE===

0 commit comments

Comments
 (0)