diff --git a/php_phongo.c b/php_phongo.c index f46e8fcdb..7292a3447 100644 --- a/php_phongo.c +++ b/php_phongo.c @@ -482,14 +482,7 @@ PHP_FUNCTION(MongoDB_disabled___construct) /* {{{ */ PHP_FUNCTION(MongoDB_disabled___wakeup) /* {{{ */ { - zend_error_handling error_handling; - - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); phongo_throw_exception(PHONGO_ERROR_RUNTIME, "%s", "MongoDB\\Driver objects cannot be serialized"); } /* }}} */ diff --git a/src/BSON/Binary.c b/src/BSON/Binary.c index 27922981b..3f993d7bf 100644 --- a/src/BSON/Binary.c +++ b/src/BSON/Binary.c @@ -94,7 +94,6 @@ static HashTable* php_phongo_binary_get_properties_hash(phongo_compat_object_han Construct a new BSON binary type */ static PHP_METHOD(Binary, __construct) { - zend_error_handling error_handling; php_phongo_binary_t* intern; char* data; size_t data_len; @@ -102,12 +101,10 @@ static PHP_METHOD(Binary, __construct) intern = Z_BINARY_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "sl", &data, &data_len, &type) == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_START(2, 2) + Z_PARAM_STRING(data, data_len) + Z_PARAM_LONG(type) + PHONGO_PARSE_PARAMETERS_END(); php_phongo_binary_init(intern, data, data_len, type); } /* }}} */ @@ -116,17 +113,13 @@ static PHP_METHOD(Binary, __construct) */ static PHP_METHOD(Binary, __set_state) { - zend_error_handling error_handling; php_phongo_binary_t* intern; HashTable* props; zval* array; - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "a", &array) == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_ARRAY(array) + PHONGO_PARSE_PARAMETERS_END(); object_init_ex(return_value, php_phongo_binary_ce); @@ -140,15 +133,9 @@ static PHP_METHOD(Binary, __set_state) Return the Binary's data string. */ static PHP_METHOD(Binary, __toString) { - zend_error_handling error_handling; php_phongo_binary_t* intern; - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); intern = Z_BINARY_OBJ_P(getThis()); @@ -159,17 +146,11 @@ static PHP_METHOD(Binary, __toString) */ static PHP_METHOD(Binary, getData) { - zend_error_handling error_handling; php_phongo_binary_t* intern; intern = Z_BINARY_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); RETURN_STRINGL(intern->data, intern->data_len); } /* }}} */ @@ -178,17 +159,11 @@ static PHP_METHOD(Binary, getData) */ static PHP_METHOD(Binary, getType) { - zend_error_handling error_handling; php_phongo_binary_t* intern; intern = Z_BINARY_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); RETURN_LONG(intern->type); } /* }}} */ @@ -197,17 +172,11 @@ static PHP_METHOD(Binary, getType) */ static PHP_METHOD(Binary, jsonSerialize) { - zend_error_handling error_handling; php_phongo_binary_t* intern; char type[3]; int type_len; - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); intern = Z_BINARY_OBJ_P(getThis()); @@ -227,7 +196,6 @@ static PHP_METHOD(Binary, jsonSerialize) */ static PHP_METHOD(Binary, serialize) { - zend_error_handling error_handling; php_phongo_binary_t* intern; zval retval; php_serialize_data_t var_hash; @@ -235,12 +203,7 @@ static PHP_METHOD(Binary, serialize) intern = Z_BINARY_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); array_init_size(&retval, 2); ADD_ASSOC_STRINGL(&retval, "data", intern->data, intern->data_len); @@ -261,7 +224,6 @@ static PHP_METHOD(Binary, serialize) */ static PHP_METHOD(Binary, unserialize) { - zend_error_handling error_handling; php_phongo_binary_t* intern; char* serialized; size_t serialized_len; @@ -270,12 +232,9 @@ static PHP_METHOD(Binary, unserialize) intern = Z_BINARY_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &serialized, &serialized_len) == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_STRING(serialized, serialized_len) + PHONGO_PARSE_PARAMETERS_END(); PHP_VAR_UNSERIALIZE_INIT(var_hash); if (!php_var_unserialize(&props, (const unsigned char**) &serialized, (unsigned char*) serialized + serialized_len, &var_hash)) { diff --git a/src/BSON/DBPointer.c b/src/BSON/DBPointer.c index 9c11f7176..e1d954876 100644 --- a/src/BSON/DBPointer.c +++ b/src/BSON/DBPointer.c @@ -94,17 +94,11 @@ HashTable* php_phongo_dbpointer_get_properties_hash(phongo_compat_object_handler Return the DBPointer's namespace string and ObjectId. */ static PHP_METHOD(DBPointer, __toString) { - zend_error_handling error_handling; php_phongo_dbpointer_t* intern; char* retval; int retval_len; - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); intern = Z_DBPOINTER_OBJ_P(getThis()); @@ -117,17 +111,11 @@ static PHP_METHOD(DBPointer, __toString) */ static PHP_METHOD(DBPointer, jsonSerialize) { - zend_error_handling error_handling; php_phongo_dbpointer_t* intern; zval zdb_pointer; zval zoid; - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); intern = Z_DBPOINTER_OBJ_P(getThis()); @@ -145,7 +133,6 @@ static PHP_METHOD(DBPointer, jsonSerialize) */ static PHP_METHOD(DBPointer, serialize) { - zend_error_handling error_handling; php_phongo_dbpointer_t* intern; zval retval; php_serialize_data_t var_hash; @@ -153,12 +140,7 @@ static PHP_METHOD(DBPointer, serialize) intern = Z_DBPOINTER_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); array_init_size(&retval, 2); ADD_ASSOC_STRINGL(&retval, "ref", intern->ref, intern->ref_len); @@ -179,7 +161,6 @@ static PHP_METHOD(DBPointer, serialize) */ static PHP_METHOD(DBPointer, unserialize) { - zend_error_handling error_handling; php_phongo_dbpointer_t* intern; char* serialized; size_t serialized_len; @@ -188,12 +169,9 @@ static PHP_METHOD(DBPointer, unserialize) intern = Z_DBPOINTER_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &serialized, &serialized_len) == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_STRING(serialized, serialized_len) + PHONGO_PARSE_PARAMETERS_END(); PHP_VAR_UNSERIALIZE_INIT(var_hash); if (!php_var_unserialize(&props, (const unsigned char**) &serialized, (unsigned char*) serialized + serialized_len, &var_hash)) { diff --git a/src/BSON/Decimal128.c b/src/BSON/Decimal128.c index 64b6283c1..21c5a9d1c 100644 --- a/src/BSON/Decimal128.c +++ b/src/BSON/Decimal128.c @@ -84,19 +84,15 @@ static HashTable* php_phongo_decimal128_get_properties_hash(phongo_compat_object Construct a new BSON Decimal128 type */ static PHP_METHOD(Decimal128, __construct) { - zend_error_handling error_handling; php_phongo_decimal128_t* intern; char* value; size_t value_len; intern = Z_DECIMAL128_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &value, &value_len) == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_STRING(value, value_len) + PHONGO_PARSE_PARAMETERS_END(); php_phongo_decimal128_init(intern, value); } /* }}} */ @@ -105,17 +101,13 @@ static PHP_METHOD(Decimal128, __construct) */ static PHP_METHOD(Decimal128, __set_state) { - zend_error_handling error_handling; php_phongo_decimal128_t* intern; HashTable* props; zval* array; - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "a", &array) == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_ARRAY(array) + PHONGO_PARSE_PARAMETERS_END(); object_init_ex(return_value, php_phongo_decimal128_ce); @@ -129,18 +121,12 @@ static PHP_METHOD(Decimal128, __set_state) */ static PHP_METHOD(Decimal128, __toString) { - zend_error_handling error_handling; php_phongo_decimal128_t* intern; char outbuf[BSON_DECIMAL128_STRING]; intern = Z_DECIMAL128_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); bson_decimal128_to_string(&intern->decimal, outbuf); @@ -151,16 +137,10 @@ static PHP_METHOD(Decimal128, __toString) */ static PHP_METHOD(Decimal128, jsonSerialize) { - zend_error_handling error_handling; php_phongo_decimal128_t* intern; char outbuf[BSON_DECIMAL128_STRING] = ""; - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); intern = Z_DECIMAL128_OBJ_P(getThis()); @@ -173,7 +153,6 @@ static PHP_METHOD(Decimal128, jsonSerialize) */ static PHP_METHOD(Decimal128, serialize) { - zend_error_handling error_handling; php_phongo_decimal128_t* intern; zval retval; php_serialize_data_t var_hash; @@ -182,12 +161,7 @@ static PHP_METHOD(Decimal128, serialize) intern = Z_DECIMAL128_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); bson_decimal128_to_string(&intern->decimal, outbuf); array_init_size(&retval, 1); @@ -208,7 +182,6 @@ static PHP_METHOD(Decimal128, serialize) */ static PHP_METHOD(Decimal128, unserialize) { - zend_error_handling error_handling; php_phongo_decimal128_t* intern; char* serialized; size_t serialized_len; @@ -217,12 +190,9 @@ static PHP_METHOD(Decimal128, unserialize) intern = Z_DECIMAL128_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &serialized, &serialized_len) == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_STRING(serialized, serialized_len) + PHONGO_PARSE_PARAMETERS_END(); PHP_VAR_UNSERIALIZE_INIT(var_hash); if (!php_var_unserialize(&props, (const unsigned char**) &serialized, (unsigned char*) serialized + serialized_len, &var_hash)) { diff --git a/src/BSON/Int64.c b/src/BSON/Int64.c index 4bb52ab4f..f570a3cec 100644 --- a/src/BSON/Int64.c +++ b/src/BSON/Int64.c @@ -89,15 +89,9 @@ HashTable* php_phongo_int64_get_properties_hash(phongo_compat_object_handler_typ Return the Int64's value as a string. */ static PHP_METHOD(Int64, __toString) { - zend_error_handling error_handling; php_phongo_int64_t* intern; - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); intern = Z_INT64_OBJ_P(getThis()); @@ -108,15 +102,9 @@ static PHP_METHOD(Int64, __toString) */ static PHP_METHOD(Int64, jsonSerialize) { - zend_error_handling error_handling; php_phongo_int64_t* intern; - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); intern = Z_INT64_OBJ_P(getThis()); @@ -129,18 +117,12 @@ static PHP_METHOD(Int64, jsonSerialize) */ static PHP_METHOD(Int64, serialize) { - zend_error_handling error_handling; php_phongo_int64_t* intern; zval retval; php_serialize_data_t var_hash; smart_str buf = { 0 }; - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); intern = Z_INT64_OBJ_P(getThis()); @@ -162,7 +144,6 @@ static PHP_METHOD(Int64, serialize) */ static PHP_METHOD(Int64, unserialize) { - zend_error_handling error_handling; php_phongo_int64_t* intern; char* serialized; size_t serialized_len; @@ -171,12 +152,9 @@ static PHP_METHOD(Int64, unserialize) intern = Z_INT64_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &serialized, &serialized_len) == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_STRING(serialized, serialized_len) + PHONGO_PARSE_PARAMETERS_END(); PHP_VAR_UNSERIALIZE_INIT(var_hash); if (!php_var_unserialize(&props, (const unsigned char**) &serialized, (unsigned char*) serialized + serialized_len, &var_hash)) { diff --git a/src/BSON/Javascript.c b/src/BSON/Javascript.c index a0432ac2d..d157b1d85 100644 --- a/src/BSON/Javascript.c +++ b/src/BSON/Javascript.c @@ -120,7 +120,6 @@ HashTable* php_phongo_javascript_get_properties_hash(phongo_compat_object_handle be evaluated. Note that this type cannot be represented as Extended JSON. */ static PHP_METHOD(Javascript, __construct) { - zend_error_handling error_handling; php_phongo_javascript_t* intern; char* code; size_t code_len; @@ -128,12 +127,11 @@ static PHP_METHOD(Javascript, __construct) intern = Z_JAVASCRIPT_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|A!", &code, &code_len, &scope) == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_START(1, 2) + Z_PARAM_STRING(code, code_len) + Z_PARAM_OPTIONAL + Z_PARAM_ARRAY_OR_OBJECT_EX(scope, 1, 0) + PHONGO_PARSE_PARAMETERS_END(); php_phongo_javascript_init(intern, code, code_len, scope); } /* }}} */ @@ -142,17 +140,13 @@ static PHP_METHOD(Javascript, __construct) */ static PHP_METHOD(Javascript, __set_state) { - zend_error_handling error_handling; php_phongo_javascript_t* intern; HashTable* props; zval* array; - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "a", &array) == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_ARRAY(array) + PHONGO_PARSE_PARAMETERS_END(); object_init_ex(return_value, php_phongo_javascript_ce); @@ -166,15 +160,9 @@ static PHP_METHOD(Javascript, __set_state) Return the Javascript's code string. */ static PHP_METHOD(Javascript, __toString) { - zend_error_handling error_handling; php_phongo_javascript_t* intern; - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); intern = Z_JAVASCRIPT_OBJ_P(getThis()); @@ -185,15 +173,9 @@ static PHP_METHOD(Javascript, __toString) */ static PHP_METHOD(Javascript, getCode) { - zend_error_handling error_handling; php_phongo_javascript_t* intern; - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); intern = Z_JAVASCRIPT_OBJ_P(getThis()); @@ -204,15 +186,9 @@ static PHP_METHOD(Javascript, getCode) */ static PHP_METHOD(Javascript, getScope) { - zend_error_handling error_handling; php_phongo_javascript_t* intern; - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); intern = Z_JAVASCRIPT_OBJ_P(getThis()); @@ -240,15 +216,9 @@ static PHP_METHOD(Javascript, getScope) */ static PHP_METHOD(Javascript, jsonSerialize) { - zend_error_handling error_handling; php_phongo_javascript_t* intern; - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); intern = Z_JAVASCRIPT_OBJ_P(getThis()); @@ -272,7 +242,6 @@ static PHP_METHOD(Javascript, jsonSerialize) */ static PHP_METHOD(Javascript, serialize) { - zend_error_handling error_handling; php_phongo_javascript_t* intern; zval retval; php_phongo_bson_state state; @@ -283,12 +252,7 @@ static PHP_METHOD(Javascript, serialize) intern = Z_JAVASCRIPT_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); if (intern->scope && intern->scope->len) { if (!php_phongo_bson_to_zval_ex(bson_get_data(intern->scope), intern->scope->len, &state)) { @@ -318,7 +282,6 @@ static PHP_METHOD(Javascript, serialize) */ static PHP_METHOD(Javascript, unserialize) { - zend_error_handling error_handling; php_phongo_javascript_t* intern; char* serialized; size_t serialized_len; @@ -327,12 +290,9 @@ static PHP_METHOD(Javascript, unserialize) intern = Z_JAVASCRIPT_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &serialized, &serialized_len) == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_STRING(serialized, serialized_len) + PHONGO_PARSE_PARAMETERS_END(); PHP_VAR_UNSERIALIZE_INIT(var_hash); if (!php_var_unserialize(&props, (const unsigned char**) &serialized, (unsigned char*) serialized + serialized_len, &var_hash)) { diff --git a/src/BSON/MaxKey.c b/src/BSON/MaxKey.c index 8d0b14ad9..a1f4ed8b3 100644 --- a/src/BSON/MaxKey.c +++ b/src/BSON/MaxKey.c @@ -28,15 +28,11 @@ zend_class_entry* php_phongo_maxkey_ce; */ static PHP_METHOD(MaxKey, __set_state) { - zend_error_handling error_handling; - zval* array; + zval* array; - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "a", &array) == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_ARRAY(array) + PHONGO_PARSE_PARAMETERS_END(); object_init_ex(return_value, php_phongo_maxkey_ce); } /* }}} */ @@ -45,14 +41,7 @@ static PHP_METHOD(MaxKey, __set_state) */ static PHP_METHOD(MaxKey, jsonSerialize) { - zend_error_handling error_handling; - - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); array_init_size(return_value, 1); ADD_ASSOC_LONG_EX(return_value, "$maxKey", 1); @@ -62,14 +51,7 @@ static PHP_METHOD(MaxKey, jsonSerialize) */ static PHP_METHOD(MaxKey, serialize) { - zend_error_handling error_handling; - - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); RETURN_STRING(""); } /* }}} */ @@ -78,16 +60,12 @@ static PHP_METHOD(MaxKey, serialize) */ static PHP_METHOD(MaxKey, unserialize) { - zend_error_handling error_handling; - char* serialized; - size_t serialized_len; - - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &serialized, &serialized_len) == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + char* serialized; + size_t serialized_len; + + PHONGO_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_STRING(serialized, serialized_len) + PHONGO_PARSE_PARAMETERS_END(); } /* }}} */ /* {{{ proto array MongoDB\Driver\MaxKey::__serialize() diff --git a/src/BSON/MinKey.c b/src/BSON/MinKey.c index d3e775eeb..e5bdc8d75 100644 --- a/src/BSON/MinKey.c +++ b/src/BSON/MinKey.c @@ -28,15 +28,11 @@ zend_class_entry* php_phongo_minkey_ce; */ static PHP_METHOD(MinKey, __set_state) { - zend_error_handling error_handling; - zval* array; + zval* array; - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "a", &array) == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_ARRAY(array) + PHONGO_PARSE_PARAMETERS_END(); object_init_ex(return_value, php_phongo_minkey_ce); } /* }}} */ @@ -45,14 +41,7 @@ static PHP_METHOD(MinKey, __set_state) */ static PHP_METHOD(MinKey, jsonSerialize) { - zend_error_handling error_handling; - - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); array_init_size(return_value, 1); ADD_ASSOC_LONG_EX(return_value, "$minKey", 1); @@ -62,14 +51,7 @@ static PHP_METHOD(MinKey, jsonSerialize) */ static PHP_METHOD(MinKey, serialize) { - zend_error_handling error_handling; - - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); RETURN_STRING(""); } /* }}} */ @@ -78,16 +60,12 @@ static PHP_METHOD(MinKey, serialize) */ static PHP_METHOD(MinKey, unserialize) { - zend_error_handling error_handling; - char* serialized; - size_t serialized_len; - - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &serialized, &serialized_len) == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + char* serialized; + size_t serialized_len; + + PHONGO_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_STRING(serialized, serialized_len) + PHONGO_PARSE_PARAMETERS_END(); } /* }}} */ /* {{{ proto array MongoDB\Driver\MinKey::__serialize() diff --git a/src/BSON/ObjectId.c b/src/BSON/ObjectId.c index 351b79471..388c4a16a 100644 --- a/src/BSON/ObjectId.c +++ b/src/BSON/ObjectId.c @@ -105,19 +105,16 @@ static HashTable* php_phongo_objectid_get_properties_hash(phongo_compat_object_h Constructs a new BSON ObjectId type, optionally from a hex string. */ static PHP_METHOD(ObjectId, __construct) { - zend_error_handling error_handling; php_phongo_objectid_t* intern; char* id = NULL; size_t id_len; intern = Z_OBJECTID_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "|s!", &id, &id_len) == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_START(0, 1) + Z_PARAM_OPTIONAL + Z_PARAM_STRING_OR_NULL(id, id_len) + PHONGO_PARSE_PARAMETERS_END(); if (id) { php_phongo_objectid_init_from_hex_string(intern, id, id_len); @@ -130,18 +127,12 @@ static PHP_METHOD(ObjectId, __construct) */ static PHP_METHOD(ObjectId, getTimestamp) { - zend_error_handling error_handling; php_phongo_objectid_t* intern; bson_oid_t tmp_oid; intern = Z_OBJECTID_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); bson_oid_init_from_string(&tmp_oid, intern->oid); RETVAL_LONG(bson_oid_get_time_t(&tmp_oid)); @@ -151,17 +142,13 @@ static PHP_METHOD(ObjectId, getTimestamp) */ static PHP_METHOD(ObjectId, __set_state) { - zend_error_handling error_handling; php_phongo_objectid_t* intern; HashTable* props; zval* array; - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "a", &array) == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_ARRAY(array) + PHONGO_PARSE_PARAMETERS_END(); object_init_ex(return_value, php_phongo_objectid_ce); @@ -175,17 +162,11 @@ static PHP_METHOD(ObjectId, __set_state) */ static PHP_METHOD(ObjectId, __toString) { - zend_error_handling error_handling; php_phongo_objectid_t* intern; intern = Z_OBJECTID_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); RETURN_STRINGL(intern->oid, PHONGO_OID_LEN); } /* }}} */ @@ -194,15 +175,9 @@ static PHP_METHOD(ObjectId, __toString) */ static PHP_METHOD(ObjectId, jsonSerialize) { - zend_error_handling error_handling; php_phongo_objectid_t* intern; - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); intern = Z_OBJECTID_OBJ_P(getThis()); @@ -214,7 +189,6 @@ static PHP_METHOD(ObjectId, jsonSerialize) */ static PHP_METHOD(ObjectId, serialize) { - zend_error_handling error_handling; php_phongo_objectid_t* intern; zval retval; php_serialize_data_t var_hash; @@ -222,12 +196,7 @@ static PHP_METHOD(ObjectId, serialize) intern = Z_OBJECTID_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); array_init_size(&retval, 1); ADD_ASSOC_STRINGL(&retval, "oid", intern->oid, PHONGO_OID_LEN); @@ -247,7 +216,6 @@ static PHP_METHOD(ObjectId, serialize) */ static PHP_METHOD(ObjectId, unserialize) { - zend_error_handling error_handling; php_phongo_objectid_t* intern; char* serialized; size_t serialized_len; @@ -256,12 +224,9 @@ static PHP_METHOD(ObjectId, unserialize) intern = Z_OBJECTID_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &serialized, &serialized_len) == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_STRING(serialized, serialized_len) + PHONGO_PARSE_PARAMETERS_END(); PHP_VAR_UNSERIALIZE_INIT(var_hash); if (!php_var_unserialize(&props, (const unsigned char**) &serialized, (unsigned char*) serialized + serialized_len, &var_hash)) { diff --git a/src/BSON/Regex.c b/src/BSON/Regex.c index 8dfe34f6b..f21d55fb7 100644 --- a/src/BSON/Regex.c +++ b/src/BSON/Regex.c @@ -108,7 +108,6 @@ static HashTable* php_phongo_regex_get_properties_hash(phongo_compat_object_hand Constructs a new BSON regular expression type. */ static PHP_METHOD(Regex, __construct) { - zend_error_handling error_handling; php_phongo_regex_t* intern; char* pattern; size_t pattern_len; @@ -117,12 +116,11 @@ static PHP_METHOD(Regex, __construct) intern = Z_REGEX_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|s", &pattern, &pattern_len, &flags, &flags_len) == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_START(1, 2) + Z_PARAM_STRING(pattern, pattern_len) + Z_PARAM_OPTIONAL + Z_PARAM_STRING(flags, flags_len) + PHONGO_PARSE_PARAMETERS_END(); php_phongo_regex_init(intern, pattern, pattern_len, flags, flags_len); } /* }}} */ @@ -131,17 +129,11 @@ static PHP_METHOD(Regex, __construct) */ static PHP_METHOD(Regex, getPattern) { - zend_error_handling error_handling; php_phongo_regex_t* intern; intern = Z_REGEX_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); RETURN_STRINGL(intern->pattern, intern->pattern_len); } /* }}} */ @@ -150,17 +142,11 @@ static PHP_METHOD(Regex, getPattern) */ static PHP_METHOD(Regex, getFlags) { - zend_error_handling error_handling; php_phongo_regex_t* intern; intern = Z_REGEX_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); RETURN_STRINGL(intern->flags, intern->flags_len); } /* }}} */ @@ -169,17 +155,13 @@ static PHP_METHOD(Regex, getFlags) */ static PHP_METHOD(Regex, __set_state) { - zend_error_handling error_handling; php_phongo_regex_t* intern; HashTable* props; zval* array; - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "a", &array) == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_ARRAY(array) + PHONGO_PARSE_PARAMETERS_END(); object_init_ex(return_value, php_phongo_regex_ce); @@ -193,19 +175,13 @@ static PHP_METHOD(Regex, __set_state) Returns a string in the form: /pattern/flags */ static PHP_METHOD(Regex, __toString) { - zend_error_handling error_handling; php_phongo_regex_t* intern; char* regex; int regex_len; intern = Z_REGEX_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); regex_len = spprintf(®ex, 0, "/%s/%s", intern->pattern, intern->flags); RETVAL_STRINGL(regex, regex_len); @@ -216,15 +192,9 @@ static PHP_METHOD(Regex, __toString) */ static PHP_METHOD(Regex, jsonSerialize) { - zend_error_handling error_handling; php_phongo_regex_t* intern; - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); intern = Z_REGEX_OBJ_P(getThis()); @@ -237,7 +207,6 @@ static PHP_METHOD(Regex, jsonSerialize) */ static PHP_METHOD(Regex, serialize) { - zend_error_handling error_handling; php_phongo_regex_t* intern; zval retval; php_serialize_data_t var_hash; @@ -245,12 +214,7 @@ static PHP_METHOD(Regex, serialize) intern = Z_REGEX_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); array_init_size(&retval, 2); ADD_ASSOC_STRINGL(&retval, "pattern", intern->pattern, intern->pattern_len); @@ -271,7 +235,6 @@ static PHP_METHOD(Regex, serialize) */ static PHP_METHOD(Regex, unserialize) { - zend_error_handling error_handling; php_phongo_regex_t* intern; char* serialized; size_t serialized_len; @@ -280,12 +243,9 @@ static PHP_METHOD(Regex, unserialize) intern = Z_REGEX_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &serialized, &serialized_len) == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_STRING(serialized, serialized_len) + PHONGO_PARSE_PARAMETERS_END(); PHP_VAR_UNSERIALIZE_INIT(var_hash); if (!php_var_unserialize(&props, (const unsigned char**) &serialized, (unsigned char*) serialized + serialized_len, &var_hash)) { diff --git a/src/BSON/Symbol.c b/src/BSON/Symbol.c index c547be373..20f36f4c6 100644 --- a/src/BSON/Symbol.c +++ b/src/BSON/Symbol.c @@ -80,15 +80,9 @@ HashTable* php_phongo_symbol_get_properties_hash(phongo_compat_object_handler_ty Return the Symbol's symbol string. */ static PHP_METHOD(Symbol, __toString) { - zend_error_handling error_handling; php_phongo_symbol_t* intern; - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); intern = Z_SYMBOL_OBJ_P(getThis()); @@ -99,15 +93,9 @@ static PHP_METHOD(Symbol, __toString) */ static PHP_METHOD(Symbol, jsonSerialize) { - zend_error_handling error_handling; php_phongo_symbol_t* intern; - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); intern = Z_SYMBOL_OBJ_P(getThis()); @@ -119,7 +107,6 @@ static PHP_METHOD(Symbol, jsonSerialize) */ static PHP_METHOD(Symbol, serialize) { - zend_error_handling error_handling; php_phongo_symbol_t* intern; zval retval; php_serialize_data_t var_hash; @@ -127,12 +114,7 @@ static PHP_METHOD(Symbol, serialize) intern = Z_SYMBOL_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); array_init_size(&retval, 1); ADD_ASSOC_STRINGL(&retval, "symbol", intern->symbol, intern->symbol_len); @@ -152,7 +134,6 @@ static PHP_METHOD(Symbol, serialize) */ static PHP_METHOD(Symbol, unserialize) { - zend_error_handling error_handling; php_phongo_symbol_t* intern; char* serialized; size_t serialized_len; @@ -161,12 +142,9 @@ static PHP_METHOD(Symbol, unserialize) intern = Z_SYMBOL_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &serialized, &serialized_len) == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_STRING(serialized, serialized_len) + PHONGO_PARSE_PARAMETERS_END(); PHP_VAR_UNSERIALIZE_INIT(var_hash); if (!php_var_unserialize(&props, (const unsigned char**) &serialized, (unsigned char*) serialized + serialized_len, &var_hash)) { diff --git a/src/BSON/Timestamp.c b/src/BSON/Timestamp.c index 23d141ce0..c4b77863c 100644 --- a/src/BSON/Timestamp.c +++ b/src/BSON/Timestamp.c @@ -124,18 +124,15 @@ static HashTable* php_phongo_timestamp_get_properties_hash(phongo_compat_object_ 4-byte timestamp. */ static PHP_METHOD(Timestamp, __construct) { - zend_error_handling error_handling; php_phongo_timestamp_t* intern; zval * increment = NULL, *timestamp = NULL; intern = Z_TIMESTAMP_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "zz", &increment, ×tamp) == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_START(2, 2) + Z_PARAM_ZVAL(increment) + Z_PARAM_ZVAL(timestamp) + PHONGO_PARSE_PARAMETERS_END(); if (Z_TYPE_P(increment) == IS_LONG && Z_TYPE_P(timestamp) == IS_LONG) { php_phongo_timestamp_init(intern, Z_LVAL_P(increment), Z_LVAL_P(timestamp)); @@ -167,17 +164,11 @@ static PHP_METHOD(Timestamp, __construct) */ static PHP_METHOD(Timestamp, getIncrement) { - zend_error_handling error_handling; php_phongo_timestamp_t* intern; intern = Z_TIMESTAMP_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); RETVAL_LONG(intern->increment); } /* }}} */ @@ -186,17 +177,11 @@ static PHP_METHOD(Timestamp, getIncrement) */ static PHP_METHOD(Timestamp, getTimestamp) { - zend_error_handling error_handling; php_phongo_timestamp_t* intern; intern = Z_TIMESTAMP_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); RETVAL_LONG(intern->timestamp); } /* }}} */ @@ -205,17 +190,13 @@ static PHP_METHOD(Timestamp, getTimestamp) */ static PHP_METHOD(Timestamp, __set_state) { - zend_error_handling error_handling; php_phongo_timestamp_t* intern; HashTable* props; zval* array; - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "a", &array) == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_ARRAY(array) + PHONGO_PARSE_PARAMETERS_END(); object_init_ex(return_value, php_phongo_timestamp_ce); @@ -229,19 +210,13 @@ static PHP_METHOD(Timestamp, __set_state) Returns a string in the form: [increment:timestamp] */ static PHP_METHOD(Timestamp, __toString) { - zend_error_handling error_handling; php_phongo_timestamp_t* intern; char* retval; int retval_len; intern = Z_TIMESTAMP_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); retval_len = spprintf(&retval, 0, "[%" PRIu32 ":%" PRIu32 "]", intern->increment, intern->timestamp); RETVAL_STRINGL(retval, retval_len); @@ -252,15 +227,9 @@ static PHP_METHOD(Timestamp, __toString) */ static PHP_METHOD(Timestamp, jsonSerialize) { - zend_error_handling error_handling; php_phongo_timestamp_t* intern; - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); intern = Z_TIMESTAMP_OBJ_P(getThis()); @@ -280,7 +249,6 @@ static PHP_METHOD(Timestamp, jsonSerialize) */ static PHP_METHOD(Timestamp, serialize) { - zend_error_handling error_handling; php_phongo_timestamp_t* intern; zval retval; php_serialize_data_t var_hash; @@ -292,12 +260,7 @@ static PHP_METHOD(Timestamp, serialize) intern = Z_TIMESTAMP_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); s_increment_len = snprintf(s_increment, sizeof(s_increment), "%" PRIu32, intern->increment); s_timestamp_len = snprintf(s_timestamp, sizeof(s_timestamp), "%" PRIu32, intern->timestamp); @@ -321,7 +284,6 @@ static PHP_METHOD(Timestamp, serialize) */ static PHP_METHOD(Timestamp, unserialize) { - zend_error_handling error_handling; php_phongo_timestamp_t* intern; char* serialized; size_t serialized_len; @@ -330,12 +292,9 @@ static PHP_METHOD(Timestamp, unserialize) intern = Z_TIMESTAMP_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &serialized, &serialized_len) == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_STRING(serialized, serialized_len) + PHONGO_PARSE_PARAMETERS_END(); PHP_VAR_UNSERIALIZE_INIT(var_hash); if (!php_var_unserialize(&props, (const unsigned char**) &serialized, (unsigned char*) serialized + serialized_len, &var_hash)) { diff --git a/src/BSON/UTCDateTime.c b/src/BSON/UTCDateTime.c index 3c4671534..e057fdc8f 100644 --- a/src/BSON/UTCDateTime.c +++ b/src/BSON/UTCDateTime.c @@ -131,18 +131,15 @@ static HashTable* php_phongo_utcdatetime_get_properties_hash(phongo_compat_objec current time. */ static PHP_METHOD(UTCDateTime, __construct) { - zend_error_handling error_handling; php_phongo_utcdatetime_t* intern; zval* milliseconds = NULL; intern = Z_UTCDATETIME_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "|z!", &milliseconds) == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_START(0, 1) + Z_PARAM_OPTIONAL + Z_PARAM_ZVAL_OR_NULL(milliseconds) + PHONGO_PARSE_PARAMETERS_END(); if (milliseconds == NULL) { php_phongo_utcdatetime_init_from_current_time(intern); @@ -187,17 +184,13 @@ static PHP_METHOD(UTCDateTime, __construct) */ static PHP_METHOD(UTCDateTime, __set_state) { - zend_error_handling error_handling; php_phongo_utcdatetime_t* intern; HashTable* props; zval* array; - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "a", &array) == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_ARRAY(array) + PHONGO_PARSE_PARAMETERS_END(); object_init_ex(return_value, php_phongo_utcdatetime_ce); @@ -211,17 +204,11 @@ static PHP_METHOD(UTCDateTime, __set_state) Returns the UTCDateTime's milliseconds as a string */ static PHP_METHOD(UTCDateTime, __toString) { - zend_error_handling error_handling; php_phongo_utcdatetime_t* intern; intern = Z_UTCDATETIME_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); ZVAL_INT64_STRING(return_value, intern->milliseconds); } /* }}} */ @@ -230,7 +217,6 @@ static PHP_METHOD(UTCDateTime, __toString) Returns a DateTime object representing this UTCDateTime */ static PHP_METHOD(UTCDateTime, toDateTime) { - zend_error_handling error_handling; php_phongo_utcdatetime_t* intern; php_date_obj* datetime_obj; char* sec; @@ -238,12 +224,7 @@ static PHP_METHOD(UTCDateTime, toDateTime) intern = Z_UTCDATETIME_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); object_init_ex(return_value, php_date_get_date_ce()); datetime_obj = Z_PHPDATE_P(return_value); @@ -260,15 +241,9 @@ static PHP_METHOD(UTCDateTime, toDateTime) */ static PHP_METHOD(UTCDateTime, jsonSerialize) { - zend_error_handling error_handling; php_phongo_utcdatetime_t* intern; - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); intern = Z_UTCDATETIME_OBJ_P(getThis()); @@ -287,7 +262,6 @@ static PHP_METHOD(UTCDateTime, jsonSerialize) */ static PHP_METHOD(UTCDateTime, serialize) { - zend_error_handling error_handling; php_phongo_utcdatetime_t* intern; zval retval; php_serialize_data_t var_hash; @@ -295,12 +269,7 @@ static PHP_METHOD(UTCDateTime, serialize) intern = Z_UTCDATETIME_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); array_init_size(&retval, 1); ADD_ASSOC_INT64_AS_STRING(&retval, "milliseconds", intern->milliseconds); @@ -320,7 +289,6 @@ static PHP_METHOD(UTCDateTime, serialize) */ static PHP_METHOD(UTCDateTime, unserialize) { - zend_error_handling error_handling; php_phongo_utcdatetime_t* intern; char* serialized; size_t serialized_len; @@ -329,12 +297,9 @@ static PHP_METHOD(UTCDateTime, unserialize) intern = Z_UTCDATETIME_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &serialized, &serialized_len) == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_STRING(serialized, serialized_len) + PHONGO_PARSE_PARAMETERS_END(); PHP_VAR_UNSERIALIZE_INIT(var_hash); if (!php_var_unserialize(&props, (const unsigned char**) &serialized, (unsigned char*) serialized + serialized_len, &var_hash)) { diff --git a/src/BSON/Undefined.c b/src/BSON/Undefined.c index 5244e500d..f6e0253ce 100644 --- a/src/BSON/Undefined.c +++ b/src/BSON/Undefined.c @@ -28,14 +28,7 @@ zend_class_entry* php_phongo_undefined_ce; Return the empty string. */ static PHP_METHOD(Undefined, __toString) { - zend_error_handling error_handling; - - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); RETURN_STRINGL("", 0); } /* }}} */ @@ -44,14 +37,7 @@ static PHP_METHOD(Undefined, __toString) */ static PHP_METHOD(Undefined, jsonSerialize) { - zend_error_handling error_handling; - - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); array_init_size(return_value, 1); ADD_ASSOC_BOOL_EX(return_value, "$undefined", 1); @@ -61,14 +47,7 @@ static PHP_METHOD(Undefined, jsonSerialize) */ static PHP_METHOD(Undefined, serialize) { - zend_error_handling error_handling; - - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); RETURN_STRING(""); } /* }}} */ @@ -77,16 +56,12 @@ static PHP_METHOD(Undefined, serialize) */ static PHP_METHOD(Undefined, unserialize) { - zend_error_handling error_handling; - char* serialized; - size_t serialized_len; - - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &serialized, &serialized_len) == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + char* serialized; + size_t serialized_len; + + PHONGO_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_STRING(serialized, serialized_len) + PHONGO_PARSE_PARAMETERS_END(); } /* }}} */ /* {{{ proto array MongoDB\Driver\Undefined::__serialize() diff --git a/src/BSON/functions.c b/src/BSON/functions.c index 0f8a50a8b..e95921c9f 100644 --- a/src/BSON/functions.c +++ b/src/BSON/functions.c @@ -32,16 +32,12 @@ typedef enum { Returns the BSON representation of a PHP value */ PHP_FUNCTION(MongoDB_BSON_fromPHP) { - zend_error_handling error_handling; - zval* data; - bson_t* bson; + zval* data; + bson_t* bson; - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "A", &data) == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_START(1, 1) + PHONGO_PARAM_ARRAY_OR_OBJECT(data) + PHONGO_PARSE_PARAMETERS_END(); bson = bson_new(); php_phongo_zval_to_bson(data, PHONGO_BSON_NONE, bson, NULL); @@ -54,7 +50,6 @@ PHP_FUNCTION(MongoDB_BSON_fromPHP) Returns the PHP representation of a BSON value, optionally converting it into a custom class */ PHP_FUNCTION(MongoDB_BSON_toPHP) { - zend_error_handling error_handling; char* data; size_t data_len; zval* typemap = NULL; @@ -62,12 +57,11 @@ PHP_FUNCTION(MongoDB_BSON_toPHP) PHONGO_BSON_INIT_STATE(state); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|a!", &data, &data_len, &typemap) == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_START(1, 2) + Z_PARAM_STRING(data, data_len) + Z_PARAM_OPTIONAL + Z_PARAM_ARRAY_OR_NULL(typemap) + PHONGO_PARSE_PARAMETERS_END(); if (!php_phongo_bson_typemap_to_state(typemap, &state.map)) { return; @@ -88,18 +82,14 @@ PHP_FUNCTION(MongoDB_BSON_toPHP) Returns the BSON representation of a JSON value */ PHP_FUNCTION(MongoDB_BSON_fromJSON) { - zend_error_handling error_handling; - char* json; - size_t json_len; - bson_t bson = BSON_INITIALIZER; - bson_error_t error = { 0 }; - - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &json, &json_len) == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + char* json; + size_t json_len; + bson_t bson = BSON_INITIALIZER; + bson_error_t error = { 0 }; + + PHONGO_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_STRING(json, json_len) + PHONGO_PARSE_PARAMETERS_END(); if (bson_init_from_json(&bson, (const char*) json, json_len, &error)) { RETVAL_STRINGL((const char*) bson_get_data(&bson), bson.len); @@ -111,21 +101,17 @@ PHP_FUNCTION(MongoDB_BSON_fromJSON) static void phongo_bson_to_json(INTERNAL_FUNCTION_PARAMETERS, php_phongo_json_mode_t mode) { - zend_error_handling error_handling; - char* data; - size_t data_len; - const bson_t* bson; - bool eof = false; - bson_reader_t* reader; - char* json = NULL; - size_t json_len; - - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &data, &data_len) == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + char* data; + size_t data_len; + const bson_t* bson; + bool eof = false; + bson_reader_t* reader; + char* json = NULL; + size_t json_len; + + PHONGO_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_STRING(data, data_len) + PHONGO_PARSE_PARAMETERS_END(); reader = bson_reader_new_from_data((const unsigned char*) data, data_len); bson = bson_reader_read(reader, NULL); diff --git a/src/MongoDB/BulkWrite.c b/src/MongoDB/BulkWrite.c index 74c8915ec..7bc2fad19 100644 --- a/src/MongoDB/BulkWrite.c +++ b/src/MongoDB/BulkWrite.c @@ -313,19 +313,16 @@ static bool php_phongo_bulkwrite_delete_apply_options(bson_t* boptions, zval* zo Constructs a new BulkWrite */ static PHP_METHOD(BulkWrite, __construct) { - zend_error_handling error_handling; php_phongo_bulkwrite_t* intern; zval* options = NULL; zend_bool ordered = 1; intern = Z_BULKWRITE_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "|a!", &options) == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_START(0, 1) + Z_PARAM_OPTIONAL + Z_PARAM_ARRAY_OR_NULL(options) + PHONGO_PARSE_PARAMETERS_END(); if (options && php_array_existsc(options, "ordered")) { ordered = php_array_fetchc_bool(options, "ordered"); @@ -381,7 +378,6 @@ static PHP_METHOD(BulkWrite, __construct) Adds an insert operation to the BulkWrite */ static PHP_METHOD(BulkWrite, insert) { - zend_error_handling error_handling; php_phongo_bulkwrite_t* intern; zval* zdocument; bson_t bdocument = BSON_INITIALIZER, boptions = BSON_INITIALIZER; @@ -391,12 +387,9 @@ static PHP_METHOD(BulkWrite, insert) intern = Z_BULKWRITE_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "A", &zdocument) == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_START(1, 1) + PHONGO_PARAM_ARRAY_OR_OBJECT(zdocument) + PHONGO_PARSE_PARAMETERS_END(); bson_flags |= PHONGO_BSON_RETURN_ID; @@ -430,7 +423,6 @@ static PHP_METHOD(BulkWrite, insert) Adds an update operation to the BulkWrite */ static PHP_METHOD(BulkWrite, update) { - zend_error_handling error_handling; php_phongo_bulkwrite_t* intern; zval * zquery, *zupdate, *zoptions = NULL; bson_t bquery = BSON_INITIALIZER, bupdate = BSON_INITIALIZER, boptions = BSON_INITIALIZER; @@ -438,12 +430,12 @@ static PHP_METHOD(BulkWrite, update) intern = Z_BULKWRITE_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "AA|a!", &zquery, &zupdate, &zoptions) == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_START(2, 3) + PHONGO_PARAM_ARRAY_OR_OBJECT(zquery) + PHONGO_PARAM_ARRAY_OR_OBJECT(zupdate) + Z_PARAM_OPTIONAL + Z_PARAM_ARRAY_OR_NULL(zoptions) + PHONGO_PARSE_PARAMETERS_END(); php_phongo_zval_to_bson(zquery, PHONGO_BSON_NONE, &bquery, NULL); @@ -497,7 +489,6 @@ static PHP_METHOD(BulkWrite, update) Adds a delete operation to the BulkWrite */ static PHP_METHOD(BulkWrite, delete) { - zend_error_handling error_handling; php_phongo_bulkwrite_t* intern; zval * zquery, *zoptions = NULL; bson_t bquery = BSON_INITIALIZER, boptions = BSON_INITIALIZER; @@ -505,12 +496,11 @@ static PHP_METHOD(BulkWrite, delete) intern = Z_BULKWRITE_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "A|a!", &zquery, &zoptions) == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_START(1, 2) + PHONGO_PARAM_ARRAY_OR_OBJECT(zquery) + Z_PARAM_OPTIONAL + Z_PARAM_ARRAY_OR_NULL(zoptions) + PHONGO_PARSE_PARAMETERS_END(); php_phongo_zval_to_bson(zquery, PHONGO_BSON_NONE, &bquery, NULL); @@ -545,17 +535,11 @@ static PHP_METHOD(BulkWrite, delete) Returns the number of operations that have been added to the BulkWrite */ static PHP_METHOD(BulkWrite, count) { - zend_error_handling error_handling; php_phongo_bulkwrite_t* intern; intern = Z_BULKWRITE_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); RETURN_LONG(intern->num_ops); } /* }}} */ diff --git a/src/MongoDB/ClientEncryption.c b/src/MongoDB/ClientEncryption.c index f9811e6b6..65c215ae3 100644 --- a/src/MongoDB/ClientEncryption.c +++ b/src/MongoDB/ClientEncryption.c @@ -57,17 +57,15 @@ static PHP_METHOD(ClientEncryption, createDataKey) char* kms_provider = NULL; size_t kms_provider_len = 0; zval* options = NULL; - zend_error_handling error_handling; php_phongo_clientencryption_t* intern; intern = Z_CLIENTENCRYPTION_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|a!", &kms_provider, &kms_provider_len, &options) == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_START(1, 2) + Z_PARAM_STRING(kms_provider, kms_provider_len) + Z_PARAM_OPTIONAL + Z_PARAM_ARRAY_OR_NULL(options) + PHONGO_PARSE_PARAMETERS_END(); phongo_clientencryption_create_datakey(intern, return_value, kms_provider, options); } /* }}} */ @@ -78,17 +76,15 @@ static PHP_METHOD(ClientEncryption, encrypt) { zval* value = NULL; zval* options = NULL; - zend_error_handling error_handling; php_phongo_clientencryption_t* intern; intern = Z_CLIENTENCRYPTION_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "z|a!", &value, &options) == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_START(1, 2) + Z_PARAM_ZVAL(value) + Z_PARAM_OPTIONAL + Z_PARAM_ARRAY_OR_NULL(options) + PHONGO_PARSE_PARAMETERS_END(); phongo_clientencryption_encrypt(intern, value, return_value, options); } /* }}} */ @@ -98,17 +94,13 @@ static PHP_METHOD(ClientEncryption, encrypt) static PHP_METHOD(ClientEncryption, decrypt) { zval* ciphertext; - zend_error_handling error_handling; php_phongo_clientencryption_t* intern; intern = Z_CLIENTENCRYPTION_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &ciphertext, php_phongo_binary_interface_ce) == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_OBJECT_OF_CLASS(ciphertext, php_phongo_binary_interface_ce) + PHONGO_PARSE_PARAMETERS_END(); phongo_clientencryption_decrypt(intern, ciphertext, return_value); } /* }}} */ diff --git a/src/MongoDB/Command.c b/src/MongoDB/Command.c index 4745ab645..d0c3f2333 100644 --- a/src/MongoDB/Command.c +++ b/src/MongoDB/Command.c @@ -100,19 +100,17 @@ static bool php_phongo_command_init(php_phongo_command_t* intern, zval* filter, Constructs a new Command */ static PHP_METHOD(Command, __construct) { - zend_error_handling error_handling; php_phongo_command_t* intern; zval* document; zval* options = NULL; intern = Z_COMMAND_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "A|a!", &document, &options) == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_START(1, 2) + PHONGO_PARAM_ARRAY_OR_OBJECT(document) + Z_PARAM_OPTIONAL + Z_PARAM_ARRAY_OR_NULL(options) + PHONGO_PARSE_PARAMETERS_END(); php_phongo_command_init(intern, document, options); } /* }}} */ diff --git a/src/MongoDB/Cursor.c b/src/MongoDB/Cursor.c index 0eada5ff0..4778e45c1 100644 --- a/src/MongoDB/Cursor.c +++ b/src/MongoDB/Cursor.c @@ -56,7 +56,6 @@ static void php_phongo_cursor_free_current(php_phongo_cursor_t* cursor) /* {{{ * Sets a type map to use for BSON unserialization */ static PHP_METHOD(Cursor, setTypeMap) { - zend_error_handling error_handling; php_phongo_cursor_t* intern; php_phongo_bson_state state; zval* typemap = NULL; @@ -66,12 +65,9 @@ static PHP_METHOD(Cursor, setTypeMap) intern = Z_CURSOR_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "a!", &typemap) == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_ARRAY_OR_NULL(typemap) + PHONGO_PARSE_PARAMETERS_END(); if (!php_phongo_bson_typemap_to_state(typemap, &state.map)) { return; @@ -133,14 +129,7 @@ static void php_phongo_cursor_id_new_from_id(zval* object, int64_t cursorid) /* Returns an array of all result documents for this cursor */ static PHP_METHOD(Cursor, toArray) { - zend_error_handling error_handling; - - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); array_init(return_value); @@ -154,17 +143,11 @@ static PHP_METHOD(Cursor, toArray) Returns the CursorId for this cursor */ static PHP_METHOD(Cursor, getId) { - zend_error_handling error_handling; php_phongo_cursor_t* intern; intern = Z_CURSOR_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); php_phongo_cursor_id_new_from_id(return_value, mongoc_cursor_get_id(intern->cursor)); } /* }}} */ @@ -173,17 +156,11 @@ static PHP_METHOD(Cursor, getId) Returns the Server object to which this cursor is attached */ static PHP_METHOD(Cursor, getServer) { - zend_error_handling error_handling; php_phongo_cursor_t* intern; intern = Z_CURSOR_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); phongo_server_init(return_value, &intern->manager, intern->server_id); } /* }}} */ @@ -192,33 +169,21 @@ static PHP_METHOD(Cursor, getServer) Checks if a cursor is still alive */ static PHP_METHOD(Cursor, isDead) { - zend_error_handling error_handling; php_phongo_cursor_t* intern; intern = Z_CURSOR_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); RETURN_BOOL(!mongoc_cursor_more(intern->cursor)); } /* }}} */ PHP_METHOD(Cursor, current) { - zend_error_handling error_handling; php_phongo_cursor_t* intern = Z_CURSOR_OBJ_P(getThis()); zval* data; - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); data = &intern->visitor_data.zchild; @@ -231,15 +196,9 @@ PHP_METHOD(Cursor, current) PHP_METHOD(Cursor, key) { - zend_error_handling error_handling; php_phongo_cursor_t* intern = Z_CURSOR_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); if (Z_ISUNDEF(intern->visitor_data.zchild)) { RETURN_NULL(); @@ -250,16 +209,10 @@ PHP_METHOD(Cursor, key) PHP_METHOD(Cursor, next) { - zend_error_handling error_handling; php_phongo_cursor_t* intern = Z_CURSOR_OBJ_P(getThis()); const bson_t* doc; - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); php_phongo_cursor_free_current(intern); @@ -294,31 +247,19 @@ PHP_METHOD(Cursor, next) PHP_METHOD(Cursor, valid) { - zend_error_handling error_handling; php_phongo_cursor_t* intern = Z_CURSOR_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); RETURN_BOOL(!Z_ISUNDEF(intern->visitor_data.zchild)); } PHP_METHOD(Cursor, rewind) { - zend_error_handling error_handling; php_phongo_cursor_t* intern = Z_CURSOR_OBJ_P(getThis()); const bson_t* doc; - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); /* If the intern was never advanced (e.g. command intern), do so now */ if (!intern->advanced) { diff --git a/src/MongoDB/CursorId.c b/src/MongoDB/CursorId.c index 7acc96d7c..e9730a855 100644 --- a/src/MongoDB/CursorId.c +++ b/src/MongoDB/CursorId.c @@ -94,17 +94,13 @@ static HashTable* php_phongo_cursorid_get_properties_hash(phongo_compat_object_h */ static PHP_METHOD(CursorId, __set_state) { - zend_error_handling error_handling; php_phongo_cursorid_t* intern; HashTable* props; zval* array; - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "a", &array) == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_ARRAY(array) + PHONGO_PARSE_PARAMETERS_END(); object_init_ex(return_value, php_phongo_cursorid_ce); @@ -118,19 +114,13 @@ static PHP_METHOD(CursorId, __set_state) Returns the string representation of the CursorId */ static PHP_METHOD(CursorId, __toString) { - zend_error_handling error_handling; php_phongo_cursorid_t* intern; char* tmp; int tmp_len; intern = Z_CURSORID_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); tmp_len = spprintf(&tmp, 0, "%" PRId64, intern->id); RETVAL_STRINGL(tmp, tmp_len); @@ -141,18 +131,12 @@ static PHP_METHOD(CursorId, __toString) */ static PHP_METHOD(CursorId, serialize) { - zend_error_handling error_handling; php_phongo_cursorid_t* intern; zval retval; php_serialize_data_t var_hash; smart_str buf = { 0 }; - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); intern = Z_CURSORID_OBJ_P(getThis()); @@ -174,7 +158,6 @@ static PHP_METHOD(CursorId, serialize) */ static PHP_METHOD(CursorId, unserialize) { - zend_error_handling error_handling; php_phongo_cursorid_t* intern; char* serialized; size_t serialized_len; @@ -183,12 +166,9 @@ static PHP_METHOD(CursorId, unserialize) intern = Z_CURSORID_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &serialized, &serialized_len) == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_STRING(serialized, serialized_len) + PHONGO_PARSE_PARAMETERS_END(); PHP_VAR_UNSERIALIZE_INIT(var_hash); if (!php_var_unserialize(&props, (const unsigned char**) &serialized, (unsigned char*) serialized + serialized_len, &var_hash)) { diff --git a/src/MongoDB/Exception/CommandException.c b/src/MongoDB/Exception/CommandException.c index a2dae4bc8..afd165953 100644 --- a/src/MongoDB/Exception/CommandException.c +++ b/src/MongoDB/Exception/CommandException.c @@ -25,16 +25,10 @@ zend_class_entry* php_phongo_commandexception_ce; Returns the result document from the failed command. */ static PHP_METHOD(CommandException, getResultDocument) { - zend_error_handling error_handling; - zval* resultdocument; - zval rv; + zval* resultdocument; + zval rv; - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); resultdocument = zend_read_property(php_phongo_commandexception_ce, PHONGO_COMPAT_OBJ_P(getThis()), ZEND_STRL("resultDocument"), 0, &rv); diff --git a/src/MongoDB/Exception/RuntimeException.c b/src/MongoDB/Exception/RuntimeException.c index e06e70c52..954786c38 100644 --- a/src/MongoDB/Exception/RuntimeException.c +++ b/src/MongoDB/Exception/RuntimeException.c @@ -53,18 +53,14 @@ static bool php_phongo_has_string_array_element(zval* labels, char* label) Returns whether a specific error label has been set */ static PHP_METHOD(RuntimeException, hasErrorLabel) { - zend_error_handling error_handling; - char* label; - size_t label_len; - zval* error_labels; - zval rv; - - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &label, &label_len) == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + char* label; + size_t label_len; + zval* error_labels; + zval rv; + + PHONGO_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_STRING(label, label_len) + PHONGO_PARSE_PARAMETERS_END(); error_labels = zend_read_property(php_phongo_runtimeexception_ce, PHONGO_COMPAT_OBJ_P(getThis()), ZEND_STRL("errorLabels"), 0, &rv); diff --git a/src/MongoDB/Exception/WriteException.c b/src/MongoDB/Exception/WriteException.c index ecad4a323..91b01a208 100644 --- a/src/MongoDB/Exception/WriteException.c +++ b/src/MongoDB/Exception/WriteException.c @@ -25,16 +25,10 @@ zend_class_entry* php_phongo_writeexception_ce; Returns the WriteResult from the failed write operation. */ static PHP_METHOD(WriteException, getWriteResult) { - zend_error_handling error_handling; - zval* writeresult; - zval rv; + zval* writeresult; + zval rv; - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); writeresult = zend_read_property(php_phongo_writeexception_ce, PHONGO_COMPAT_OBJ_P(getThis()), ZEND_STRL("writeResult"), 0, &rv); diff --git a/src/MongoDB/Manager.c b/src/MongoDB/Manager.c index 09b844c81..e43bcef5e 100644 --- a/src/MongoDB/Manager.c +++ b/src/MongoDB/Manager.c @@ -245,7 +245,6 @@ static bool php_phongo_manager_select_server(bool for_writes, bool inherit_read_ Constructs a new Manager */ static PHP_METHOD(Manager, __construct) { - zend_error_handling error_handling; php_phongo_manager_t* intern; char* uri_string = NULL; size_t uri_string_len = 0; @@ -257,12 +256,12 @@ static PHP_METHOD(Manager, __construct) /* Separate the options and driverOptions zvals, since we may end up * modifying them in php_phongo_manager_prep_uri_options() and * php_phongo_manager_merge_context_options() below, respectively. */ - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "|s!a/!a/!", &uri_string, &uri_string_len, &options, &driverOptions) == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_START(0, 3) + Z_PARAM_OPTIONAL + Z_PARAM_STRING_OR_NULL(uri_string, uri_string_len) + Z_PARAM_ARRAY_EX(options, 1, 1) + Z_PARAM_ARRAY_EX(driverOptions, 1, 1) + PHONGO_PARSE_PARAMETERS_END(); if (options) { php_phongo_manager_prep_uri_options(options); @@ -327,7 +326,6 @@ static PHP_METHOD(Manager, createClientEncryption) Execute a Command */ static PHP_METHOD(Manager, executeCommand) { - zend_error_handling error_handling; php_phongo_manager_t* intern; char* db; size_t db_len; @@ -338,12 +336,12 @@ static PHP_METHOD(Manager, executeCommand) zval* zsession = NULL; uint32_t server_id = 0; - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "sO|z!", &db, &db_len, &command, php_phongo_command_ce, &options) == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_START(2, 3) + Z_PARAM_STRING_OR_NULL(db, db_len) + Z_PARAM_OBJECT_OF_CLASS(command, php_phongo_command_ce) + Z_PARAM_OPTIONAL + Z_PARAM_ZVAL_OR_NULL(options) + PHONGO_PARSE_PARAMETERS_END(); intern = Z_MANAGER_OBJ_P(getThis()); @@ -381,7 +379,6 @@ static PHP_METHOD(Manager, executeCommand) Execute a ReadCommand */ static PHP_METHOD(Manager, executeReadCommand) { - zend_error_handling error_handling; php_phongo_manager_t* intern; char* db; size_t db_len; @@ -391,12 +388,12 @@ static PHP_METHOD(Manager, executeReadCommand) uint32_t server_id = 0; zval* zsession = NULL; - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "sO|a!", &db, &db_len, &command, php_phongo_command_ce, &options) == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_START(2, 3) + Z_PARAM_STRING_OR_NULL(db, db_len) + Z_PARAM_OBJECT_OF_CLASS(command, php_phongo_command_ce) + Z_PARAM_OPTIONAL + Z_PARAM_ARRAY_OR_NULL(options) + PHONGO_PARSE_PARAMETERS_END(); intern = Z_MANAGER_OBJ_P(getThis()); @@ -427,7 +424,6 @@ static PHP_METHOD(Manager, executeReadCommand) Execute a WriteCommand */ static PHP_METHOD(Manager, executeWriteCommand) { - zend_error_handling error_handling; php_phongo_manager_t* intern; char* db; size_t db_len; @@ -436,12 +432,12 @@ static PHP_METHOD(Manager, executeWriteCommand) uint32_t server_id = 0; zval* zsession = NULL; - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "sO|a!", &db, &db_len, &command, php_phongo_command_ce, &options) == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_START(2, 3) + Z_PARAM_STRING_OR_NULL(db, db_len) + Z_PARAM_OBJECT_OF_CLASS(command, php_phongo_command_ce) + Z_PARAM_OPTIONAL + Z_PARAM_ARRAY_OR_NULL(options) + PHONGO_PARSE_PARAMETERS_END(); intern = Z_MANAGER_OBJ_P(getThis()); @@ -467,7 +463,6 @@ static PHP_METHOD(Manager, executeWriteCommand) Execute a ReadWriteCommand */ static PHP_METHOD(Manager, executeReadWriteCommand) { - zend_error_handling error_handling; php_phongo_manager_t* intern; char* db; size_t db_len; @@ -476,12 +471,12 @@ static PHP_METHOD(Manager, executeReadWriteCommand) uint32_t server_id = 0; zval* zsession = NULL; - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "sO|a!", &db, &db_len, &command, php_phongo_command_ce, &options) == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_START(2, 3) + Z_PARAM_STRING_OR_NULL(db, db_len) + Z_PARAM_OBJECT_OF_CLASS(command, php_phongo_command_ce) + Z_PARAM_OPTIONAL + Z_PARAM_ARRAY_OR_NULL(options) + PHONGO_PARSE_PARAMETERS_END(); intern = Z_MANAGER_OBJ_P(getThis()); @@ -507,7 +502,6 @@ static PHP_METHOD(Manager, executeReadWriteCommand) Execute a Query */ static PHP_METHOD(Manager, executeQuery) { - zend_error_handling error_handling; php_phongo_manager_t* intern; char* namespace; size_t namespace_len; @@ -518,12 +512,12 @@ static PHP_METHOD(Manager, executeQuery) uint32_t server_id = 0; zval* zsession = NULL; - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "sO|z!", &namespace, &namespace_len, &query, php_phongo_query_ce, &options) == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_START(2, 3) + Z_PARAM_STRING_OR_NULL(namespace, namespace_len) + Z_PARAM_OBJECT_OF_CLASS(query, php_phongo_query_ce) + Z_PARAM_OPTIONAL + Z_PARAM_ZVAL_OR_NULL(options) + PHONGO_PARSE_PARAMETERS_END(); intern = Z_MANAGER_OBJ_P(getThis()); @@ -561,7 +555,6 @@ static PHP_METHOD(Manager, executeQuery) Executes a BulkWrite (i.e. any number of insert, update, and delete ops) */ static PHP_METHOD(Manager, executeBulkWrite) { - zend_error_handling error_handling; php_phongo_manager_t* intern; char* namespace; size_t namespace_len; @@ -572,12 +565,12 @@ static PHP_METHOD(Manager, executeBulkWrite) uint32_t server_id = 0; zval* zsession = NULL; - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "sO|z!", &namespace, &namespace_len, &zbulk, php_phongo_bulkwrite_ce, &options) == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_START(2, 3) + Z_PARAM_STRING_OR_NULL(namespace, namespace_len) + Z_PARAM_OBJECT_OF_CLASS(zbulk, php_phongo_bulkwrite_ce) + Z_PARAM_OPTIONAL + Z_PARAM_ZVAL_OR_NULL(options) + PHONGO_PARSE_PARAMETERS_END(); intern = Z_MANAGER_OBJ_P(getThis()); bulk = Z_BULKWRITE_OBJ_P(zbulk); @@ -625,17 +618,11 @@ static PHP_METHOD(Manager, getEncryptedFieldsMap) Returns the ReadConcern associated with this Manager */ static PHP_METHOD(Manager, getReadConcern) { - zend_error_handling error_handling; php_phongo_manager_t* intern; intern = Z_MANAGER_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); phongo_readconcern_init(return_value, mongoc_client_get_read_concern(intern->client)); } /* }}} */ @@ -644,17 +631,11 @@ static PHP_METHOD(Manager, getReadConcern) Returns the ReadPreference associated with this Manager */ static PHP_METHOD(Manager, getReadPreference) { - zend_error_handling error_handling; php_phongo_manager_t* intern; intern = Z_MANAGER_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); phongo_readpreference_init(return_value, mongoc_client_get_read_prefs(intern->client)); } /* }}} */ @@ -663,19 +644,13 @@ static PHP_METHOD(Manager, getReadPreference) Returns the Servers associated with this Manager */ static PHP_METHOD(Manager, getServers) { - zend_error_handling error_handling; php_phongo_manager_t* intern; mongoc_server_description_t** sds; size_t i, n = 0; intern = Z_MANAGER_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); sds = mongoc_client_get_server_descriptions(intern->client, &n); array_init_size(return_value, n); @@ -694,17 +669,11 @@ static PHP_METHOD(Manager, getServers) Returns the WriteConcern associated with this Manager */ static PHP_METHOD(Manager, getWriteConcern) { - zend_error_handling error_handling; php_phongo_manager_t* intern; intern = Z_MANAGER_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); phongo_writeconcern_init(return_value, mongoc_client_get_write_concern(intern->client)); } /* }}} */ @@ -757,7 +726,6 @@ static PHP_METHOD(Manager, selectServer) Returns a new client session */ static PHP_METHOD(Manager, startSession) { - zend_error_handling error_handling; php_phongo_manager_t* intern; zval* options = NULL; mongoc_session_opt_t* cs_opts = NULL; @@ -767,12 +735,10 @@ static PHP_METHOD(Manager, startSession) intern = Z_MANAGER_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "|a!", &options) == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_START(0, 1) + Z_PARAM_OPTIONAL + Z_PARAM_ARRAY_OR_NULL(options) + PHONGO_PARSE_PARAMETERS_END(); if (options && php_array_existsc(options, "causalConsistency")) { cs_opts = mongoc_session_opts_new(); diff --git a/src/MongoDB/Monitoring/CommandFailedEvent.c b/src/MongoDB/Monitoring/CommandFailedEvent.c index 340eec2c7..117b7e0bf 100644 --- a/src/MongoDB/Monitoring/CommandFailedEvent.c +++ b/src/MongoDB/Monitoring/CommandFailedEvent.c @@ -32,17 +32,11 @@ zend_class_entry* php_phongo_commandfailedevent_ce; Returns the command name for this event */ PHP_METHOD(CommandFailedEvent, getCommandName) { - zend_error_handling error_handling; php_phongo_commandfailedevent_t* intern; intern = Z_COMMANDFAILEDEVENT_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); RETVAL_STRING(intern->command_name); } /* }}} */ @@ -51,17 +45,11 @@ PHP_METHOD(CommandFailedEvent, getCommandName) Returns the event's duration in microseconds */ PHP_METHOD(CommandFailedEvent, getDurationMicros) { - zend_error_handling error_handling; php_phongo_commandfailedevent_t* intern; intern = Z_COMMANDFAILEDEVENT_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); RETURN_LONG(intern->duration_micros); } /* }}} */ @@ -70,17 +58,11 @@ PHP_METHOD(CommandFailedEvent, getDurationMicros) Returns the error document associated with the event */ PHP_METHOD(CommandFailedEvent, getError) { - zend_error_handling error_handling; php_phongo_commandfailedevent_t* intern; intern = Z_COMMANDFAILEDEVENT_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); RETURN_ZVAL(&intern->z_error, 1, 0); } /* }}} */ @@ -89,18 +71,12 @@ PHP_METHOD(CommandFailedEvent, getError) Returns the event's operation ID */ PHP_METHOD(CommandFailedEvent, getOperationId) { - zend_error_handling error_handling; php_phongo_commandfailedevent_t* intern; char int_as_string[20]; intern = Z_COMMANDFAILEDEVENT_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); sprintf(int_as_string, "%" PRIu64, intern->operation_id); RETVAL_STRING(int_as_string); @@ -110,7 +86,6 @@ PHP_METHOD(CommandFailedEvent, getOperationId) Returns the reply document associated with the event */ PHP_METHOD(CommandFailedEvent, getReply) { - zend_error_handling error_handling; php_phongo_commandfailedevent_t* intern; php_phongo_bson_state state; @@ -118,12 +93,7 @@ PHP_METHOD(CommandFailedEvent, getReply) intern = Z_COMMANDFAILEDEVENT_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); if (!php_phongo_bson_to_zval_ex(bson_get_data(intern->reply), intern->reply->len, &state)) { zval_ptr_dtor(&state.zchild); @@ -137,18 +107,12 @@ PHP_METHOD(CommandFailedEvent, getReply) Returns the event's request ID */ PHP_METHOD(CommandFailedEvent, getRequestId) { - zend_error_handling error_handling; php_phongo_commandfailedevent_t* intern; char int_as_string[20]; intern = Z_COMMANDFAILEDEVENT_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); sprintf(int_as_string, "%" PRIu64, intern->request_id); RETVAL_STRING(int_as_string); @@ -158,17 +122,11 @@ PHP_METHOD(CommandFailedEvent, getRequestId) Returns the Server from which the event originated */ PHP_METHOD(CommandFailedEvent, getServer) { - zend_error_handling error_handling; php_phongo_commandfailedevent_t* intern; intern = Z_COMMANDFAILEDEVENT_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); phongo_server_init(return_value, &intern->manager, intern->server_id); } /* }}} */ diff --git a/src/MongoDB/Monitoring/CommandStartedEvent.c b/src/MongoDB/Monitoring/CommandStartedEvent.c index 4b1a56a5e..18f7c6896 100644 --- a/src/MongoDB/Monitoring/CommandStartedEvent.c +++ b/src/MongoDB/Monitoring/CommandStartedEvent.c @@ -32,7 +32,6 @@ zend_class_entry* php_phongo_commandstartedevent_ce; Returns the command document associated with the event */ PHP_METHOD(CommandStartedEvent, getCommand) { - zend_error_handling error_handling; php_phongo_commandstartedevent_t* intern; php_phongo_bson_state state; @@ -40,12 +39,7 @@ PHP_METHOD(CommandStartedEvent, getCommand) intern = Z_COMMANDSTARTEDEVENT_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); if (!php_phongo_bson_to_zval_ex(bson_get_data(intern->command), intern->command->len, &state)) { zval_ptr_dtor(&state.zchild); @@ -59,17 +53,11 @@ PHP_METHOD(CommandStartedEvent, getCommand) Returns the command name for this event */ PHP_METHOD(CommandStartedEvent, getCommandName) { - zend_error_handling error_handling; php_phongo_commandstartedevent_t* intern; intern = Z_COMMANDSTARTEDEVENT_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); RETVAL_STRING(intern->command_name); } /* }}} */ @@ -78,17 +66,11 @@ PHP_METHOD(CommandStartedEvent, getCommandName) Returns the database name for this event */ PHP_METHOD(CommandStartedEvent, getDatabaseName) { - zend_error_handling error_handling; php_phongo_commandstartedevent_t* intern; intern = Z_COMMANDSTARTEDEVENT_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); RETVAL_STRING(intern->database_name); } /* }}} */ @@ -97,18 +79,12 @@ PHP_METHOD(CommandStartedEvent, getDatabaseName) Returns the event's operation ID */ PHP_METHOD(CommandStartedEvent, getOperationId) { - zend_error_handling error_handling; php_phongo_commandstartedevent_t* intern; char int_as_string[20]; intern = Z_COMMANDSTARTEDEVENT_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); sprintf(int_as_string, "%" PRIu64, intern->operation_id); RETVAL_STRING(int_as_string); @@ -118,18 +94,12 @@ PHP_METHOD(CommandStartedEvent, getOperationId) Returns the event's request ID */ PHP_METHOD(CommandStartedEvent, getRequestId) { - zend_error_handling error_handling; php_phongo_commandstartedevent_t* intern; char int_as_string[20]; intern = Z_COMMANDSTARTEDEVENT_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); sprintf(int_as_string, "%" PRIu64, intern->request_id); RETVAL_STRING(int_as_string); @@ -139,17 +109,11 @@ PHP_METHOD(CommandStartedEvent, getRequestId) Returns the Server from which the event originated */ PHP_METHOD(CommandStartedEvent, getServer) { - zend_error_handling error_handling; php_phongo_commandstartedevent_t* intern; intern = Z_COMMANDSTARTEDEVENT_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); phongo_server_init(return_value, &intern->manager, intern->server_id); } /* }}} */ diff --git a/src/MongoDB/Monitoring/CommandSucceededEvent.c b/src/MongoDB/Monitoring/CommandSucceededEvent.c index efbdeff85..2f6ffc8c1 100644 --- a/src/MongoDB/Monitoring/CommandSucceededEvent.c +++ b/src/MongoDB/Monitoring/CommandSucceededEvent.c @@ -32,17 +32,11 @@ zend_class_entry* php_phongo_commandsucceededevent_ce; Returns the command name for this event */ PHP_METHOD(CommandSucceededEvent, getCommandName) { - zend_error_handling error_handling; php_phongo_commandsucceededevent_t* intern; intern = Z_COMMANDSUCCEEDEDEVENT_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); RETVAL_STRING(intern->command_name); } /* }}} */ @@ -51,17 +45,11 @@ PHP_METHOD(CommandSucceededEvent, getCommandName) Returns the event's duration in microseconds */ PHP_METHOD(CommandSucceededEvent, getDurationMicros) { - zend_error_handling error_handling; php_phongo_commandsucceededevent_t* intern; intern = Z_COMMANDSUCCEEDEDEVENT_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); RETURN_LONG(intern->duration_micros); } /* }}} */ @@ -70,18 +58,12 @@ PHP_METHOD(CommandSucceededEvent, getDurationMicros) Returns the event's operation ID */ PHP_METHOD(CommandSucceededEvent, getOperationId) { - zend_error_handling error_handling; php_phongo_commandsucceededevent_t* intern; char int_as_string[20]; intern = Z_COMMANDSUCCEEDEDEVENT_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); sprintf(int_as_string, "%" PRIu64, intern->operation_id); RETVAL_STRING(int_as_string); @@ -91,7 +73,6 @@ PHP_METHOD(CommandSucceededEvent, getOperationId) Returns the reply document associated with the event */ PHP_METHOD(CommandSucceededEvent, getReply) { - zend_error_handling error_handling; php_phongo_commandsucceededevent_t* intern; php_phongo_bson_state state; @@ -99,12 +80,7 @@ PHP_METHOD(CommandSucceededEvent, getReply) intern = Z_COMMANDSUCCEEDEDEVENT_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); if (!php_phongo_bson_to_zval_ex(bson_get_data(intern->reply), intern->reply->len, &state)) { zval_ptr_dtor(&state.zchild); @@ -118,18 +94,12 @@ PHP_METHOD(CommandSucceededEvent, getReply) Returns the event's request ID */ PHP_METHOD(CommandSucceededEvent, getRequestId) { - zend_error_handling error_handling; php_phongo_commandsucceededevent_t* intern; char int_as_string[20]; intern = Z_COMMANDSUCCEEDEDEVENT_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); sprintf(int_as_string, "%" PRIu64, intern->request_id); RETVAL_STRING(int_as_string); @@ -139,17 +109,11 @@ PHP_METHOD(CommandSucceededEvent, getRequestId) Returns the Server from which the event originated */ PHP_METHOD(CommandSucceededEvent, getServer) { - zend_error_handling error_handling; php_phongo_commandsucceededevent_t* intern; intern = Z_COMMANDSUCCEEDEDEVENT_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); phongo_server_init(return_value, &intern->manager, intern->server_id); } /* }}} */ diff --git a/src/MongoDB/Query.c b/src/MongoDB/Query.c index 50a0fba6d..338b90158 100644 --- a/src/MongoDB/Query.c +++ b/src/MongoDB/Query.c @@ -391,19 +391,17 @@ static bool php_phongo_query_init(php_phongo_query_t* intern, zval* filter, zval Constructs a new Query */ static PHP_METHOD(Query, __construct) { - zend_error_handling error_handling; php_phongo_query_t* intern; zval* filter; zval* options = NULL; intern = Z_QUERY_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "A|a!", &filter, &options) == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_START(1, 2) + PHONGO_PARAM_ARRAY_OR_OBJECT(filter) + Z_PARAM_OPTIONAL + Z_PARAM_ARRAY_OR_NULL(options) + PHONGO_PARSE_PARAMETERS_END(); php_phongo_query_init(intern, filter, options); } /* }}} */ diff --git a/src/MongoDB/ReadConcern.c b/src/MongoDB/ReadConcern.c index edb58e0fe..087ebee86 100644 --- a/src/MongoDB/ReadConcern.c +++ b/src/MongoDB/ReadConcern.c @@ -56,19 +56,16 @@ static bool php_phongo_readconcern_init_from_hash(php_phongo_readconcern_t* inte Constructs a new ReadConcern */ static PHP_METHOD(ReadConcern, __construct) { - zend_error_handling error_handling; php_phongo_readconcern_t* intern; char* level = NULL; size_t level_len = 0; intern = Z_READCONCERN_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "|s!", &level, &level_len) == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_START(0, 1) + Z_PARAM_OPTIONAL + Z_PARAM_STRING_OR_NULL(level, level_len) + PHONGO_PARSE_PARAMETERS_END(); intern->read_concern = mongoc_read_concern_new(); @@ -81,17 +78,13 @@ static PHP_METHOD(ReadConcern, __construct) */ static PHP_METHOD(ReadConcern, __set_state) { - zend_error_handling error_handling; php_phongo_readconcern_t* intern; HashTable* props; zval* array; - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "a", &array) == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_ARRAY(array) + PHONGO_PARSE_PARAMETERS_END(); object_init_ex(return_value, php_phongo_readconcern_ce); @@ -105,18 +98,12 @@ static PHP_METHOD(ReadConcern, __set_state) Returns the ReadConcern "level" option */ static PHP_METHOD(ReadConcern, getLevel) { - zend_error_handling error_handling; php_phongo_readconcern_t* intern; const char* level; intern = Z_READCONCERN_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); level = mongoc_read_concern_get_level(intern->read_concern); @@ -132,17 +119,11 @@ static PHP_METHOD(ReadConcern, getLevel) without a level or from a Manager with no read concern URI options). */ static PHP_METHOD(ReadConcern, isDefault) { - zend_error_handling error_handling; php_phongo_readconcern_t* intern; intern = Z_READCONCERN_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); RETURN_BOOL(mongoc_read_concern_is_default(intern->read_concern)); } /* }}} */ @@ -177,14 +158,7 @@ static HashTable* php_phongo_readconcern_get_properties_hash(phongo_compat_objec */ static PHP_METHOD(ReadConcern, bsonSerialize) { - zend_error_handling error_handling; - - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); ZVAL_ARR(return_value, php_phongo_readconcern_get_properties_hash(PHONGO_COMPAT_OBJ_P(getThis()), true)); convert_to_object(return_value); @@ -194,7 +168,6 @@ static PHP_METHOD(ReadConcern, bsonSerialize) */ static PHP_METHOD(ReadConcern, serialize) { - zend_error_handling error_handling; php_phongo_readconcern_t* intern; zval retval; php_serialize_data_t var_hash; @@ -203,12 +176,7 @@ static PHP_METHOD(ReadConcern, serialize) intern = Z_READCONCERN_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); if (!intern->read_concern) { return; @@ -238,7 +206,6 @@ static PHP_METHOD(ReadConcern, serialize) */ static PHP_METHOD(ReadConcern, unserialize) { - zend_error_handling error_handling; php_phongo_readconcern_t* intern; char* serialized; size_t serialized_len; @@ -247,12 +214,9 @@ static PHP_METHOD(ReadConcern, unserialize) intern = Z_READCONCERN_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &serialized, &serialized_len) == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_STRING(serialized, serialized_len) + PHONGO_PARSE_PARAMETERS_END(); if (!serialized_len) { return; diff --git a/src/MongoDB/ReadPreference.c b/src/MongoDB/ReadPreference.c index 3dafcbdb4..6b3a216e5 100644 --- a/src/MongoDB/ReadPreference.c +++ b/src/MongoDB/ReadPreference.c @@ -184,7 +184,6 @@ static const char* php_phongo_readpreference_get_mode_string(mongoc_read_mode_t Constructs a new ReadPreference */ static PHP_METHOD(ReadPreference, __construct) { - zend_error_handling error_handling; php_phongo_readpreference_t* intern; zval* mode; zval* tagSets = NULL; @@ -194,12 +193,12 @@ static PHP_METHOD(ReadPreference, __construct) /* Separate the tagSets zval, since we may end up modifying it in * php_phongo_read_preference_prep_tagsets() below. */ - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "z|a/!a!", &mode, &tagSets, &options) == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_START(1, 3) + Z_PARAM_ZVAL(mode) + Z_PARAM_OPTIONAL + Z_PARAM_ARRAY_EX(tagSets, 1, 1) + Z_PARAM_ARRAY_OR_NULL(options) + PHONGO_PARSE_PARAMETERS_END(); if (Z_TYPE_P(mode) == IS_LONG) { switch (Z_LVAL_P(mode)) { @@ -314,7 +313,6 @@ static PHP_METHOD(ReadPreference, __construct) */ static PHP_METHOD(ReadPreference, __set_state) { - zend_error_handling error_handling; php_phongo_readpreference_t* intern; HashTable* props; zval* array; @@ -322,12 +320,9 @@ static PHP_METHOD(ReadPreference, __set_state) /* Separate the zval, since we may end up modifying the "tags" element in * php_phongo_read_preference_prep_tagsets(), which is called from * php_phongo_readpreference_init_from_hash. */ - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "a/", &array) == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_ARRAY_EX(array, 0, 1) + PHONGO_PARSE_PARAMETERS_END(); object_init_ex(return_value, php_phongo_readpreference_ce); @@ -341,18 +336,12 @@ static PHP_METHOD(ReadPreference, __set_state) Returns the ReadPreference hedge document */ static PHP_METHOD(ReadPreference, getHedge) { - zend_error_handling error_handling; php_phongo_readpreference_t* intern; const bson_t* hedge; intern = Z_READPREFERENCE_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); hedge = mongoc_read_prefs_get_hedge(intern->read_preference); @@ -376,17 +365,11 @@ static PHP_METHOD(ReadPreference, getHedge) Returns the ReadPreference maxStalenessSeconds value */ static PHP_METHOD(ReadPreference, getMaxStalenessSeconds) { - zend_error_handling error_handling; php_phongo_readpreference_t* intern; intern = Z_READPREFERENCE_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); RETURN_LONG(mongoc_read_prefs_get_max_staleness_seconds(intern->read_preference)); } /* }}} */ @@ -395,17 +378,11 @@ static PHP_METHOD(ReadPreference, getMaxStalenessSeconds) Returns the ReadPreference mode */ static PHP_METHOD(ReadPreference, getMode) { - zend_error_handling error_handling; php_phongo_readpreference_t* intern; intern = Z_READPREFERENCE_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); RETURN_LONG(mongoc_read_prefs_get_mode(intern->read_preference)); } /* }}} */ @@ -414,18 +391,12 @@ static PHP_METHOD(ReadPreference, getMode) Returns the ReadPreference mode as string */ static PHP_METHOD(ReadPreference, getModeString) { - zend_error_handling error_handling; php_phongo_readpreference_t* intern; const char* mode_string; intern = Z_READPREFERENCE_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); mode_string = php_phongo_readpreference_get_mode_string(mongoc_read_prefs_get_mode(intern->read_preference)); if (!mode_string) { @@ -440,18 +411,12 @@ static PHP_METHOD(ReadPreference, getModeString) Returns the ReadPreference tag sets */ static PHP_METHOD(ReadPreference, getTagSets) { - zend_error_handling error_handling; php_phongo_readpreference_t* intern; const bson_t* tags; intern = Z_READPREFERENCE_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); tags = mongoc_read_prefs_get_tags(intern->read_preference); @@ -547,14 +512,7 @@ static HashTable* php_phongo_readpreference_get_properties_hash(phongo_compat_ob */ static PHP_METHOD(ReadPreference, bsonSerialize) { - zend_error_handling error_handling; - - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); ZVAL_ARR(return_value, php_phongo_readpreference_get_properties_hash(PHONGO_COMPAT_OBJ_P(getThis()), true)); convert_to_object(return_value); @@ -564,7 +522,6 @@ static PHP_METHOD(ReadPreference, bsonSerialize) */ static PHP_METHOD(ReadPreference, serialize) { - zend_error_handling error_handling; php_phongo_readpreference_t* intern; zval retval; php_serialize_data_t var_hash; @@ -577,12 +534,7 @@ static PHP_METHOD(ReadPreference, serialize) intern = Z_READPREFERENCE_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); if (!intern->read_preference) { return; @@ -645,7 +597,6 @@ static PHP_METHOD(ReadPreference, serialize) */ static PHP_METHOD(ReadPreference, unserialize) { - zend_error_handling error_handling; php_phongo_readpreference_t* intern; char* serialized; size_t serialized_len; @@ -654,12 +605,9 @@ static PHP_METHOD(ReadPreference, unserialize) intern = Z_READPREFERENCE_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &serialized, &serialized_len) == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_STRING(serialized, serialized_len) + PHONGO_PARSE_PARAMETERS_END(); if (!serialized_len) { return; diff --git a/src/MongoDB/Server.c b/src/MongoDB/Server.c index 63624c15c..9b4476982 100644 --- a/src/MongoDB/Server.c +++ b/src/MongoDB/Server.c @@ -36,7 +36,6 @@ zend_class_entry* php_phongo_server_ce; Executes a Command on this Server */ static PHP_METHOD(Server, executeCommand) { - zend_error_handling error_handling; php_phongo_server_t* intern; char* db; size_t db_len; @@ -46,12 +45,12 @@ static PHP_METHOD(Server, executeCommand) intern = Z_SERVER_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "sO|z!", &db, &db_len, &command, php_phongo_command_ce, &options) == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_START(2, 3) + Z_PARAM_STRING(db, db_len) + Z_PARAM_OBJECT_OF_CLASS(command, php_phongo_command_ce) + Z_PARAM_OPTIONAL + Z_PARAM_ZVAL_OR_NULL(options) + PHONGO_PARSE_PARAMETERS_END(); options = php_phongo_prep_legacy_option(options, "readPreference", &free_options); @@ -71,7 +70,6 @@ static PHP_METHOD(Server, executeCommand) Executes a ReadCommand on this Server */ static PHP_METHOD(Server, executeReadCommand) { - zend_error_handling error_handling; php_phongo_server_t* intern; char* db; size_t db_len; @@ -80,12 +78,12 @@ static PHP_METHOD(Server, executeReadCommand) intern = Z_SERVER_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "sO|a!", &db, &db_len, &command, php_phongo_command_ce, &options) == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_START(2, 3) + Z_PARAM_STRING(db, db_len) + Z_PARAM_OBJECT_OF_CLASS(command, php_phongo_command_ce) + Z_PARAM_OPTIONAL + Z_PARAM_ARRAY_OR_NULL(options) + PHONGO_PARSE_PARAMETERS_END(); /* If the Server was created in a different process, reset the client so * that cursors created by this process can be differentiated and its @@ -99,7 +97,6 @@ static PHP_METHOD(Server, executeReadCommand) Executes a WriteCommand on this Server */ static PHP_METHOD(Server, executeWriteCommand) { - zend_error_handling error_handling; php_phongo_server_t* intern; char* db; size_t db_len; @@ -108,12 +105,12 @@ static PHP_METHOD(Server, executeWriteCommand) intern = Z_SERVER_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "sO|a!", &db, &db_len, &command, php_phongo_command_ce, &options) == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_START(2, 3) + Z_PARAM_STRING(db, db_len) + Z_PARAM_OBJECT_OF_CLASS(command, php_phongo_command_ce) + Z_PARAM_OPTIONAL + Z_PARAM_ARRAY_OR_NULL(options) + PHONGO_PARSE_PARAMETERS_END(); /* If the Server was created in a different process, reset the client so * that cursors created by this process can be differentiated. and its @@ -127,7 +124,6 @@ static PHP_METHOD(Server, executeWriteCommand) Executes a ReadWriteCommand on this Server */ static PHP_METHOD(Server, executeReadWriteCommand) { - zend_error_handling error_handling; php_phongo_server_t* intern; char* db; size_t db_len; @@ -136,12 +132,12 @@ static PHP_METHOD(Server, executeReadWriteCommand) intern = Z_SERVER_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "sO|a!", &db, &db_len, &command, php_phongo_command_ce, &options) == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_START(2, 3) + Z_PARAM_STRING(db, db_len) + Z_PARAM_OBJECT_OF_CLASS(command, php_phongo_command_ce) + Z_PARAM_OPTIONAL + Z_PARAM_ARRAY_OR_NULL(options) + PHONGO_PARSE_PARAMETERS_END(); /* If the Server was created in a different process, reset the client so * that cursors created by this process can be differentiated and its @@ -155,7 +151,6 @@ static PHP_METHOD(Server, executeReadWriteCommand) Executes a Query on this Server */ static PHP_METHOD(Server, executeQuery) { - zend_error_handling error_handling; php_phongo_server_t* intern; char* namespace; size_t namespace_len; @@ -165,12 +160,12 @@ static PHP_METHOD(Server, executeQuery) intern = Z_SERVER_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "sO|z!", &namespace, &namespace_len, &query, php_phongo_query_ce, &options) == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_START(2, 3) + Z_PARAM_STRING(namespace, namespace_len) + Z_PARAM_OBJECT_OF_CLASS(query, php_phongo_query_ce) + Z_PARAM_OPTIONAL + Z_PARAM_ZVAL_OR_NULL(options) + PHONGO_PARSE_PARAMETERS_END(); options = php_phongo_prep_legacy_option(options, "readPreference", &free_options); @@ -191,7 +186,6 @@ static PHP_METHOD(Server, executeQuery) this Server */ static PHP_METHOD(Server, executeBulkWrite) { - zend_error_handling error_handling; php_phongo_server_t* intern; char* namespace; size_t namespace_len; @@ -202,12 +196,12 @@ static PHP_METHOD(Server, executeBulkWrite) intern = Z_SERVER_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "sO|z!", &namespace, &namespace_len, &zbulk, php_phongo_bulkwrite_ce, &options, php_phongo_writeconcern_ce) == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_START(2, 3) + Z_PARAM_STRING(namespace, namespace_len) + Z_PARAM_OBJECT_OF_CLASS(zbulk, php_phongo_bulkwrite_ce) + Z_PARAM_OPTIONAL + Z_PARAM_ZVAL_OR_NULL(options) + PHONGO_PARSE_PARAMETERS_END(); bulk = Z_BULKWRITE_OBJ_P(zbulk); @@ -228,18 +222,12 @@ static PHP_METHOD(Server, executeBulkWrite) Returns the hostname for this Server */ static PHP_METHOD(Server, getHost) { - zend_error_handling error_handling; php_phongo_server_t* intern; mongoc_server_description_t* sd; intern = Z_SERVER_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); if ((sd = mongoc_client_get_server_description(Z_MANAGER_OBJ_P(&intern->manager)->client, intern->server_id))) { RETVAL_STRING(mongoc_server_description_host(sd)->host); @@ -254,18 +242,12 @@ static PHP_METHOD(Server, getHost) Returns the currently configured tags for this Server */ static PHP_METHOD(Server, getTags) { - zend_error_handling error_handling; php_phongo_server_t* intern; mongoc_server_description_t* sd; intern = Z_SERVER_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); if ((sd = mongoc_client_get_server_description(Z_MANAGER_OBJ_P(&intern->manager)->client, intern->server_id))) { const bson_t* hello_response = mongoc_server_description_hello_response(sd); @@ -386,18 +368,12 @@ static PHP_METHOD(Server, getLatency) Returns the port for this Server */ static PHP_METHOD(Server, getPort) { - zend_error_handling error_handling; php_phongo_server_t* intern; mongoc_server_description_t* sd; intern = Z_SERVER_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); if ((sd = mongoc_client_get_server_description(Z_MANAGER_OBJ_P(&intern->manager)->client, intern->server_id))) { RETVAL_LONG(mongoc_server_description_host(sd)->port); @@ -427,18 +403,12 @@ static PHP_METHOD(Server, getServerDescription) Returns the node type of this Server */ static PHP_METHOD(Server, getType) { - zend_error_handling error_handling; php_phongo_server_t* intern; mongoc_server_description_t* sd; intern = Z_SERVER_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); if ((sd = mongoc_client_get_server_description(Z_MANAGER_OBJ_P(&intern->manager)->client, intern->server_id))) { RETVAL_LONG(php_phongo_server_description_type(sd)); @@ -453,18 +423,12 @@ static PHP_METHOD(Server, getType) Returns whether this Server is a primary member of a replica set */ static PHP_METHOD(Server, isPrimary) { - zend_error_handling error_handling; php_phongo_server_t* intern; mongoc_server_description_t* sd; intern = Z_SERVER_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); if ((sd = mongoc_client_get_server_description(Z_MANAGER_OBJ_P(&intern->manager)->client, intern->server_id))) { RETVAL_BOOL(!strcmp(mongoc_server_description_type(sd), php_phongo_server_description_type_map[PHONGO_SERVER_RS_PRIMARY].name)); @@ -479,18 +443,12 @@ static PHP_METHOD(Server, isPrimary) Returns whether this Server is a secondary member of a replica set */ static PHP_METHOD(Server, isSecondary) { - zend_error_handling error_handling; php_phongo_server_t* intern; mongoc_server_description_t* sd; intern = Z_SERVER_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); if ((sd = mongoc_client_get_server_description(Z_MANAGER_OBJ_P(&intern->manager)->client, intern->server_id))) { RETVAL_BOOL(!strcmp(mongoc_server_description_type(sd), php_phongo_server_description_type_map[PHONGO_SERVER_RS_SECONDARY].name)); @@ -505,18 +463,12 @@ static PHP_METHOD(Server, isSecondary) Returns whether this Server is an arbiter member of a replica set */ static PHP_METHOD(Server, isArbiter) { - zend_error_handling error_handling; php_phongo_server_t* intern; mongoc_server_description_t* sd; intern = Z_SERVER_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); if ((sd = mongoc_client_get_server_description(Z_MANAGER_OBJ_P(&intern->manager)->client, intern->server_id))) { RETVAL_BOOL(!strcmp(mongoc_server_description_type(sd), php_phongo_server_description_type_map[PHONGO_SERVER_RS_ARBITER].name)); @@ -531,18 +483,12 @@ static PHP_METHOD(Server, isArbiter) Returns whether this Server is a hidden member of a replica set */ static PHP_METHOD(Server, isHidden) { - zend_error_handling error_handling; php_phongo_server_t* intern; mongoc_server_description_t* sd; intern = Z_SERVER_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); if ((sd = mongoc_client_get_server_description(Z_MANAGER_OBJ_P(&intern->manager)->client, intern->server_id))) { bson_iter_t iter; @@ -559,18 +505,12 @@ static PHP_METHOD(Server, isHidden) Returns whether this Server is a passive member of a replica set */ static PHP_METHOD(Server, isPassive) { - zend_error_handling error_handling; php_phongo_server_t* intern; mongoc_server_description_t* sd; intern = Z_SERVER_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); if ((sd = mongoc_client_get_server_description(Z_MANAGER_OBJ_P(&intern->manager)->client, intern->server_id))) { bson_iter_t iter; diff --git a/src/MongoDB/Session.c b/src/MongoDB/Session.c index c8a647114..794beb9fa 100644 --- a/src/MongoDB/Session.c +++ b/src/MongoDB/Session.c @@ -163,7 +163,6 @@ static void php_phongo_transaction_options_to_zval(mongoc_client_session_t* cs, Advances the cluster time for this Session */ static PHP_METHOD(Session, advanceClusterTime) { - zend_error_handling error_handling; php_phongo_session_t* intern; zval* zcluster_time; bson_t cluster_time = BSON_INITIALIZER; @@ -171,12 +170,9 @@ static PHP_METHOD(Session, advanceClusterTime) intern = Z_SESSION_OBJ_P(getThis()); SESSION_CHECK_LIVELINESS(intern, "advanceClusterTime") - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "A", &zcluster_time) == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_START(1, 1) + PHONGO_PARAM_ARRAY_OR_OBJECT(zcluster_time) + PHONGO_PARSE_PARAMETERS_END(); php_phongo_zval_to_bson(zcluster_time, PHONGO_BSON_NONE, &cluster_time, NULL); @@ -195,7 +191,6 @@ static PHP_METHOD(Session, advanceClusterTime) Advances the operation time for this Session */ static PHP_METHOD(Session, advanceOperationTime) { - zend_error_handling error_handling; php_phongo_session_t* intern; zval* ztimestamp; uint32_t timestamp = 0; @@ -204,12 +199,9 @@ static PHP_METHOD(Session, advanceOperationTime) intern = Z_SESSION_OBJ_P(getThis()); SESSION_CHECK_LIVELINESS(intern, "advanceOperationTime") - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &ztimestamp, php_phongo_timestamp_interface_ce) == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_OBJECT_OF_CLASS(ztimestamp, php_phongo_timestamp_interface_ce) + PHONGO_PARSE_PARAMETERS_END(); if (!php_phongo_session_get_timestamp_parts(ztimestamp, ×tamp, &increment)) { return; @@ -222,7 +214,6 @@ static PHP_METHOD(Session, advanceOperationTime) Returns the cluster time for this Session */ static PHP_METHOD(Session, getClusterTime) { - zend_error_handling error_handling; php_phongo_session_t* intern; const bson_t* cluster_time; php_phongo_bson_state state; @@ -232,12 +223,7 @@ static PHP_METHOD(Session, getClusterTime) intern = Z_SESSION_OBJ_P(getThis()); SESSION_CHECK_LIVELINESS(intern, "getClusterTime") - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); cluster_time = mongoc_client_session_get_cluster_time(intern->client_session); @@ -258,7 +244,6 @@ static PHP_METHOD(Session, getClusterTime) Returns the logical session ID for this Session */ static PHP_METHOD(Session, getLogicalSessionId) { - zend_error_handling error_handling; php_phongo_session_t* intern; const bson_t* lsid; php_phongo_bson_state state; @@ -268,12 +253,7 @@ static PHP_METHOD(Session, getLogicalSessionId) intern = Z_SESSION_OBJ_P(getThis()); SESSION_CHECK_LIVELINESS(intern, "getLogicalSessionId") - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); lsid = mongoc_client_session_get_lsid(intern->client_session); @@ -290,19 +270,13 @@ static PHP_METHOD(Session, getLogicalSessionId) Returns the operation time for this Session */ static PHP_METHOD(Session, getOperationTime) { - zend_error_handling error_handling; php_phongo_session_t* intern; uint32_t timestamp, increment; intern = Z_SESSION_OBJ_P(getThis()); SESSION_CHECK_LIVELINESS(intern, "getOperationTime") - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); mongoc_client_session_get_operation_time(intern->client_session, ×tamp, &increment); @@ -320,19 +294,13 @@ static PHP_METHOD(Session, getOperationTime) Returns the server this session is pinned to */ static PHP_METHOD(Session, getServer) { - zend_error_handling error_handling; php_phongo_session_t* intern; uint32_t server_id = 0; intern = Z_SESSION_OBJ_P(getThis()); SESSION_CHECK_LIVELINESS(intern, "getServer") - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); server_id = mongoc_client_session_get_server_id(intern->client_session); @@ -348,18 +316,12 @@ static PHP_METHOD(Session, getServer) Returns options for the currently running transaction */ static PHP_METHOD(Session, getTransactionOptions) { - zend_error_handling error_handling; php_phongo_session_t* intern; intern = Z_SESSION_OBJ_P(getThis()); SESSION_CHECK_LIVELINESS(intern, "getTransactionOptions") - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); php_phongo_transaction_options_to_zval(intern->client_session, return_value); } /* }}} */ @@ -368,19 +330,13 @@ static PHP_METHOD(Session, getTransactionOptions) Returns the current transaction state for this session */ static PHP_METHOD(Session, getTransactionState) { - zend_error_handling error_handling; php_phongo_session_t* intern; const char* state; intern = Z_SESSION_OBJ_P(getThis()); SESSION_CHECK_LIVELINESS(intern, "getTransactionState") - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); state = php_phongo_get_transaction_state_string(mongoc_client_session_get_transaction_state(intern->client_session)); if (!state) { @@ -492,7 +448,6 @@ mongoc_transaction_opt_t* php_mongodb_session_parse_transaction_options(zval* op Starts a new transaction */ static PHP_METHOD(Session, startTransaction) { - zend_error_handling error_handling; php_phongo_session_t* intern; zval* options = NULL; mongoc_transaction_opt_t* txn_options = NULL; @@ -501,12 +456,10 @@ static PHP_METHOD(Session, startTransaction) intern = Z_SESSION_OBJ_P(getThis()); SESSION_CHECK_LIVELINESS(intern, "startTransaction") - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "|a!", &options) == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_START(0, 1) + Z_PARAM_OPTIONAL + Z_PARAM_ARRAY_OR_NULL(options) + PHONGO_PARSE_PARAMETERS_END(); if (options) { txn_options = php_mongodb_session_parse_transaction_options(options); @@ -528,7 +481,6 @@ static PHP_METHOD(Session, startTransaction) Commits an existing transaction */ static PHP_METHOD(Session, commitTransaction) { - zend_error_handling error_handling; php_phongo_session_t* intern; bson_error_t error; bson_t reply; @@ -536,12 +488,7 @@ static PHP_METHOD(Session, commitTransaction) intern = Z_SESSION_OBJ_P(getThis()); SESSION_CHECK_LIVELINESS(intern, "commitTransaction") - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); if (!mongoc_client_session_commit_transaction(intern->client_session, &reply, &error)) { phongo_throw_exception_from_bson_error_t_and_reply(&error, &reply); @@ -554,19 +501,13 @@ static PHP_METHOD(Session, commitTransaction) Aborts (rolls back) an existing transaction */ static PHP_METHOD(Session, abortTransaction) { - zend_error_handling error_handling; php_phongo_session_t* intern; bson_error_t error; intern = Z_SESSION_OBJ_P(getThis()); SESSION_CHECK_LIVELINESS(intern, "abortTransaction") - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); if (!mongoc_client_session_abort_transaction(intern->client_session, &error)) { phongo_throw_exception_from_bson_error_t(&error); @@ -577,17 +518,11 @@ static PHP_METHOD(Session, abortTransaction) Ends the session, and a running transaction if active */ static PHP_METHOD(Session, endSession) { - zend_error_handling error_handling; php_phongo_session_t* intern; intern = Z_SESSION_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); mongoc_client_session_destroy(intern->client_session); intern->client_session = NULL; @@ -612,18 +547,12 @@ static PHP_METHOD(Session, isDirty) Returns whether a multi-document transaction is in progress */ static PHP_METHOD(Session, isInTransaction) { - zend_error_handling error_handling; php_phongo_session_t* intern; intern = Z_SESSION_OBJ_P(getThis()); SESSION_CHECK_LIVELINESS(intern, "isInTransaction") - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); RETURN_BOOL(mongoc_client_session_in_transaction(intern->client_session)); } /* }}} */ diff --git a/src/MongoDB/WriteConcern.c b/src/MongoDB/WriteConcern.c index 10eebd143..8d31b9f76 100644 --- a/src/MongoDB/WriteConcern.c +++ b/src/MongoDB/WriteConcern.c @@ -110,19 +110,18 @@ static bool php_phongo_writeconcern_init_from_hash(php_phongo_writeconcern_t* in Constructs a new WriteConcern */ static PHP_METHOD(WriteConcern, __construct) { - zend_error_handling error_handling; php_phongo_writeconcern_t* intern; - zval * w, *journal; + zval * w, *journal = NULL; zend_long wtimeout = 0; intern = Z_WRITECONCERN_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "z|lz", &w, &wtimeout, &journal) == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_START(1, 3) + Z_PARAM_ZVAL(w) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(wtimeout) + Z_PARAM_ZVAL(journal) + PHONGO_PARSE_PARAMETERS_END(); intern->write_concern = mongoc_write_concern_new(); @@ -145,7 +144,7 @@ static PHP_METHOD(WriteConcern, __construct) switch (ZEND_NUM_ARGS()) { case 3: - if (Z_TYPE_P(journal) != IS_NULL) { + if (journal && Z_TYPE_P(journal) != IS_NULL) { if (zend_is_true(journal) && (mongoc_write_concern_get_w(intern->write_concern) == MONGOC_WRITE_CONCERN_W_UNACKNOWLEDGED || mongoc_write_concern_get_w(intern->write_concern) == MONGOC_WRITE_CONCERN_W_ERRORS_IGNORED)) { phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Cannot enable journaling when using w = 0"); return; @@ -174,17 +173,13 @@ static PHP_METHOD(WriteConcern, __construct) */ static PHP_METHOD(WriteConcern, __set_state) { - zend_error_handling error_handling; php_phongo_writeconcern_t* intern; HashTable* props; zval* array; - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "a", &array) == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_ARRAY(array) + PHONGO_PARSE_PARAMETERS_END(); object_init_ex(return_value, php_phongo_writeconcern_ce); @@ -198,18 +193,12 @@ static PHP_METHOD(WriteConcern, __set_state) Returns the WriteConcern "w" option */ static PHP_METHOD(WriteConcern, getW) { - zend_error_handling error_handling; php_phongo_writeconcern_t* intern; const char* wtag; intern = Z_WRITECONCERN_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); wtag = mongoc_write_concern_get_wtag(intern->write_concern); @@ -232,18 +221,12 @@ static PHP_METHOD(WriteConcern, getW) Returns the WriteConcern "wtimeout" option */ static PHP_METHOD(WriteConcern, getWtimeout) { - zend_error_handling error_handling; php_phongo_writeconcern_t* intern; int64_t wtimeout; intern = Z_WRITECONCERN_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); wtimeout = mongoc_write_concern_get_wtimeout_int64(intern->write_concern); @@ -260,17 +243,11 @@ static PHP_METHOD(WriteConcern, getWtimeout) Returns the WriteConcern "journal" option */ static PHP_METHOD(WriteConcern, getJournal) { - zend_error_handling error_handling; php_phongo_writeconcern_t* intern; intern = Z_WRITECONCERN_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); if (mongoc_write_concern_journal_is_set(intern->write_concern)) { RETURN_BOOL(mongoc_write_concern_get_journal(intern->write_concern)); @@ -284,17 +261,11 @@ static PHP_METHOD(WriteConcern, getJournal) with no write concern URI options). */ static PHP_METHOD(WriteConcern, isDefault) { - zend_error_handling error_handling; php_phongo_writeconcern_t* intern; intern = Z_WRITECONCERN_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); RETURN_BOOL(mongoc_write_concern_is_default(intern->write_concern)); } /* }}} */ @@ -374,14 +345,7 @@ static HashTable* php_phongo_writeconcern_get_properties_hash(phongo_compat_obje */ static PHP_METHOD(WriteConcern, bsonSerialize) { - zend_error_handling error_handling; - - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); ZVAL_ARR(return_value, php_phongo_writeconcern_get_properties_hash(PHONGO_COMPAT_OBJ_P(getThis()), true, true, false)); convert_to_object(return_value); @@ -391,7 +355,6 @@ static PHP_METHOD(WriteConcern, bsonSerialize) */ static PHP_METHOD(WriteConcern, serialize) { - zend_error_handling error_handling; php_phongo_writeconcern_t* intern; zval retval; php_serialize_data_t var_hash; @@ -402,12 +365,7 @@ static PHP_METHOD(WriteConcern, serialize) intern = Z_WRITECONCERN_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); if (!intern->write_concern) { return; @@ -454,7 +412,6 @@ static PHP_METHOD(WriteConcern, serialize) */ static PHP_METHOD(WriteConcern, unserialize) { - zend_error_handling error_handling; php_phongo_writeconcern_t* intern; char* serialized; size_t serialized_len; @@ -463,12 +420,9 @@ static PHP_METHOD(WriteConcern, unserialize) intern = Z_WRITECONCERN_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &serialized, &serialized_len) == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_STRING(serialized, serialized_len) + PHONGO_PARSE_PARAMETERS_END(); if (!serialized_len) { return; diff --git a/src/MongoDB/WriteConcernError.c b/src/MongoDB/WriteConcernError.c index afc8a71bd..bbe2b7765 100644 --- a/src/MongoDB/WriteConcernError.c +++ b/src/MongoDB/WriteConcernError.c @@ -30,17 +30,11 @@ zend_class_entry* php_phongo_writeconcernerror_ce; Returns the MongoDB error code */ static PHP_METHOD(WriteConcernError, getCode) { - zend_error_handling error_handling; php_phongo_writeconcernerror_t* intern; intern = Z_WRITECONCERNERROR_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); RETURN_LONG(intern->code); } /* }}} */ @@ -49,17 +43,11 @@ static PHP_METHOD(WriteConcernError, getCode) Returns additional metadata for the error */ static PHP_METHOD(WriteConcernError, getInfo) { - zend_error_handling error_handling; php_phongo_writeconcernerror_t* intern; intern = Z_WRITECONCERNERROR_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); if (!Z_ISUNDEF(intern->info)) { RETURN_ZVAL(&intern->info, 1, 0); @@ -70,17 +58,11 @@ static PHP_METHOD(WriteConcernError, getInfo) Returns the actual error message from the server */ static PHP_METHOD(WriteConcernError, getMessage) { - zend_error_handling error_handling; php_phongo_writeconcernerror_t* intern; intern = Z_WRITECONCERNERROR_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); RETURN_STRING(intern->message); } /* }}} */ diff --git a/src/MongoDB/WriteError.c b/src/MongoDB/WriteError.c index e5fed4abc..9015b2f06 100644 --- a/src/MongoDB/WriteError.c +++ b/src/MongoDB/WriteError.c @@ -30,17 +30,11 @@ zend_class_entry* php_phongo_writeerror_ce; Returns the MongoDB error code */ static PHP_METHOD(WriteError, getCode) { - zend_error_handling error_handling; php_phongo_writeerror_t* intern; intern = Z_WRITEERROR_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); RETURN_LONG(intern->code); } /* }}} */ @@ -50,17 +44,11 @@ static PHP_METHOD(WriteError, getCode) corresponds. */ static PHP_METHOD(WriteError, getIndex) { - zend_error_handling error_handling; php_phongo_writeerror_t* intern; intern = Z_WRITEERROR_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); RETURN_LONG(intern->index); } /* }}} */ @@ -69,17 +57,11 @@ static PHP_METHOD(WriteError, getIndex) Returns the actual error message from the server */ static PHP_METHOD(WriteError, getMessage) { - zend_error_handling error_handling; php_phongo_writeerror_t* intern; intern = Z_WRITEERROR_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); RETURN_STRING(intern->message); } /* }}} */ @@ -88,17 +70,11 @@ static PHP_METHOD(WriteError, getMessage) Returns additional metadata for the error */ static PHP_METHOD(WriteError, getInfo) { - zend_error_handling error_handling; php_phongo_writeerror_t* intern; intern = Z_WRITEERROR_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); if (!Z_ISUNDEF(intern->info)) { RETURN_ZVAL(&intern->info, 1, 0); diff --git a/src/MongoDB/WriteResult.c b/src/MongoDB/WriteResult.c index 759fa0b60..1e29c5bcc 100644 --- a/src/MongoDB/WriteResult.c +++ b/src/MongoDB/WriteResult.c @@ -113,18 +113,12 @@ static bool php_phongo_writeresult_get_writeerrors(php_phongo_writeresult_t* int Returns the number of documents that were inserted */ static PHP_METHOD(WriteResult, getInsertedCount) { - zend_error_handling error_handling; bson_iter_t iter; php_phongo_writeresult_t* intern; intern = Z_WRITERESULT_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); PHONGO_WRITERESULT_RETURN_LONG_FROM_BSON_INT32(&iter, intern->reply, "nInserted"); } /* }}} */ @@ -133,18 +127,12 @@ static PHP_METHOD(WriteResult, getInsertedCount) Returns the number of documents that matched the update criteria */ static PHP_METHOD(WriteResult, getMatchedCount) { - zend_error_handling error_handling; bson_iter_t iter; php_phongo_writeresult_t* intern; intern = Z_WRITERESULT_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); PHONGO_WRITERESULT_RETURN_LONG_FROM_BSON_INT32(&iter, intern->reply, "nMatched"); } /* }}} */ @@ -153,18 +141,12 @@ static PHP_METHOD(WriteResult, getMatchedCount) Returns the number of documents that were actually modified by an update */ static PHP_METHOD(WriteResult, getModifiedCount) { - zend_error_handling error_handling; bson_iter_t iter; php_phongo_writeresult_t* intern; intern = Z_WRITERESULT_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); PHONGO_WRITERESULT_RETURN_LONG_FROM_BSON_INT32(&iter, intern->reply, "nModified"); } /* }}} */ @@ -173,18 +155,12 @@ static PHP_METHOD(WriteResult, getModifiedCount) Returns the number of documents that were deleted */ static PHP_METHOD(WriteResult, getDeletedCount) { - zend_error_handling error_handling; bson_iter_t iter; php_phongo_writeresult_t* intern; intern = Z_WRITERESULT_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); PHONGO_WRITERESULT_RETURN_LONG_FROM_BSON_INT32(&iter, intern->reply, "nRemoved"); } /* }}} */ @@ -193,18 +169,12 @@ static PHP_METHOD(WriteResult, getDeletedCount) Returns the number of documents that were upserted */ static PHP_METHOD(WriteResult, getUpsertedCount) { - zend_error_handling error_handling; bson_iter_t iter; php_phongo_writeresult_t* intern; intern = Z_WRITERESULT_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); PHONGO_WRITERESULT_RETURN_LONG_FROM_BSON_INT32(&iter, intern->reply, "nUpserted"); } /* }}} */ @@ -213,17 +183,11 @@ static PHP_METHOD(WriteResult, getUpsertedCount) Returns the Server from which the result originated */ static PHP_METHOD(WriteResult, getServer) { - zend_error_handling error_handling; php_phongo_writeresult_t* intern; intern = Z_WRITERESULT_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); phongo_server_init(return_value, &intern->manager, intern->server_id); } /* }}} */ @@ -232,18 +196,12 @@ static PHP_METHOD(WriteResult, getServer) Returns the identifiers generated by the server for upsert operations. */ static PHP_METHOD(WriteResult, getUpsertedIds) { - zend_error_handling error_handling; bson_iter_t iter, child; php_phongo_writeresult_t* intern; intern = Z_WRITERESULT_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); array_init(return_value); @@ -279,17 +237,11 @@ static PHP_METHOD(WriteResult, getUpsertedIds) Return any write concern error that occurred */ static PHP_METHOD(WriteResult, getWriteConcernError) { - zend_error_handling error_handling; php_phongo_writeresult_t* intern; intern = Z_WRITERESULT_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); php_phongo_writeresult_get_writeconcernerror(intern, return_value); } /* }}} */ @@ -298,17 +250,11 @@ static PHP_METHOD(WriteResult, getWriteConcernError) Returns any write errors that occurred */ static PHP_METHOD(WriteResult, getWriteErrors) { - zend_error_handling error_handling; php_phongo_writeresult_t* intern; intern = Z_WRITERESULT_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); php_phongo_writeresult_get_writeerrors(intern, return_value); } /* }}} */ @@ -318,17 +264,11 @@ static PHP_METHOD(WriteResult, getWriteErrors) concern). */ static PHP_METHOD(WriteResult, isAcknowledged) { - zend_error_handling error_handling; php_phongo_writeresult_t* intern; intern = Z_WRITERESULT_OBJ_P(getThis()); - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters_none() == FAILURE) { - zend_restore_error_handling(&error_handling); - return; - } - zend_restore_error_handling(&error_handling); + PHONGO_PARSE_PARAMETERS_NONE(); RETURN_BOOL(mongoc_write_concern_is_acknowledged(intern->write_concern)); } /* }}} */ diff --git a/src/phongo_compat.h b/src/phongo_compat.h index 0345e66d7..ddf9e5422 100644 --- a/src/phongo_compat.h +++ b/src/phongo_compat.h @@ -235,12 +235,34 @@ static inline zend_bool zend_ini_parse_bool(zend_string* str) } while (0) #endif -/* Z_PARAM_OBJECT_OF_CLASS_OR_NULL was introduced in PHP 8.0. +/* Z_PARAM_*_OR_NULL macros were introduced in PHP 8.0. * See: https://github.com/php/php-src/commit/e93d20ad7ebc1075ef1248a663935ee5ea69f1cd */ #ifndef Z_PARAM_OBJECT_OF_CLASS_OR_NULL #define Z_PARAM_OBJECT_OF_CLASS_OR_NULL(dest, _ce) \ Z_PARAM_OBJECT_OF_CLASS_EX(dest, _ce, 1, 0) #endif +#ifndef Z_PARAM_STRING_OR_NULL +#define Z_PARAM_STRING_OR_NULL(dest, dest_len) \ + Z_PARAM_STRING_EX(dest, dest_len, 1, 0) +#endif +#ifndef Z_PARAM_ARRAY_OR_NULL +#define Z_PARAM_ARRAY_OR_NULL(dest) \ + Z_PARAM_ARRAY_EX(dest, 1, 0) +#endif +#ifndef Z_PARAM_ZVAL_OR_NULL +#define Z_PARAM_ZVAL_OR_NULL(dest) \ + Z_PARAM_ZVAL_EX(dest, 1, 0) +#endif + +/* Z_PARAM_ARRAY_OR_OBJECT requires 3 arguments in PHP < 7.3. + * See: https://github.com/php/php-src/commit/a595b0f75bf8bc0d3da8ca5cb03f8b1a694d26b2 */ +#if PHP_VERSION_ID < 70300 +#define PHONGO_PARAM_ARRAY_OR_OBJECT(dest) \ + Z_PARAM_ARRAY_OR_OBJECT(dest, 0, 0) +#else +#define PHONGO_PARAM_ARRAY_OR_OBJECT(dest) \ + Z_PARAM_ARRAY_OR_OBJECT(dest) +#endif /* Per https://wiki.php.net/rfc/internal_method_return_types, "Non-final * internal method return types - when possible - are declared tentatively in