Permalink
Browse files

Refactor huge php parameter boilerplate

Now the code is much easier to read

Change-Id: I4624530e21604f474f6f27c9c9f121df46323a14
Reviewed-on: http://review.couchbase.org/22620
Reviewed-by: Trond Norbye <trond.norbye@gmail.com>
Tested-by: Trond Norbye <trond.norbye@gmail.com>
  • Loading branch information...
1 parent 02109fb commit 969cd0a15a1a9322de9af1d3dd302ddaaaa11f86 @mnunberg mnunberg committed with trondn Nov 18, 2012
Showing with 261 additions and 628 deletions.
  1. +5 −14 apidecl.c
  2. +6 −27 arithmetic.c
  3. +22 −119 couchbase.c
  4. +47 −115 get.c
  5. +4 −0 internal.h
  6. +2 −26 misc.c
  7. +14 −61 observe.c
  8. +6 −27 remove.c
  9. +99 −18 resget.h
  10. +10 −12 resmgr.c
  11. +23 −80 store.c
  12. +4 −46 timeout.c
  13. +12 −45 touch.c
  14. +7 −38 views.c
View
@@ -782,16 +782,9 @@ PHP_METHOD(couchbase, flush)
*/
PHP_METHOD(couchbase, getResultCode)
{
- zval *res;
php_couchbase_res *couchbase_res;
-
- res = zend_read_property(couchbase_ce, getThis(), ZEND_STRL(COUCHBASE_PROPERTY_HANDLE), 1 TSRMLS_CC);
- if (ZVAL_IS_NULL(res) || IS_RESOURCE != Z_TYPE_P(res)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "unintilized couchbase");
- RETURN_FALSE;
- }
-
- ZEND_FETCH_RESOURCE2(couchbase_res, php_couchbase_res *, &res, -1, PHP_COUCHBASE_RESOURCE, le_couchbase, le_pcouchbase);
+ PHP_COUCHBASE_GET_PARAMS(couchbase_res,
+ PHP_COUCHBASE_ARG_F_OO | PHP_COUCHBASE_ARG_F_ONLYVALID, "");
RETURN_LONG(couchbase_res->rc);
}
/* }}} */
@@ -1067,13 +1060,11 @@ PHP_FUNCTION(couchbase_flush)
*/
PHP_FUNCTION(couchbase_get_result_code)
{
- zval *res;
php_couchbase_res *couchbase_res;
+ PHP_COUCHBASE_GET_PARAMS(couchbase_res,
+ PHP_COUCHBASE_ARG_F_FUNCTIONAL|PHP_COUCHBASE_ARG_F_ONLYVALID,
+ "");
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &res) == FAILURE) {
- return;
- }
- ZEND_FETCH_RESOURCE2(couchbase_res, php_couchbase_res *, &res, -1, PHP_COUCHBASE_RESOURCE, le_couchbase, le_pcouchbase);
RETURN_LONG(couchbase_res->rc);
}
/* }}} */
View
@@ -32,43 +32,22 @@ php_couchbase_arithmetic_callback(lcb_t instance,
PHP_COUCHBASE_LOCAL
void php_couchbase_arithmetic_impl(INTERNAL_FUNCTION_PARAMETERS, char op, int oo) /* {{{ */
{
- zval *res, *akc, *adurability = NULL;
+ zval *akc, *adurability = NULL;
char *key;
time_t exp = {0};
long klen = 0, offset = 1, expire = 0;
long create = 0, initial = 0;
+ php_couchbase_res *couchbase_res;
+ int argflags = oo ? PHP_COUCHBASE_ARG_F_OO : PHP_COUCHBASE_ARG_F_FUNCTIONAL;
+
+ PHP_COUCHBASE_GET_PARAMS(couchbase_res, argflags,
+ "s|lllla", &key, &klen, &offset, &create, &expire, &initial, &adurability);
- if (oo) {
- zval *self = getThis();
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|lllla", &key, &klen, &offset, &create, &expire, &initial, &adurability) == FAILURE) {
- return;
- }
- res = zend_read_property(couchbase_ce, self, ZEND_STRL(COUCHBASE_PROPERTY_HANDLE), 1 TSRMLS_CC);
- if (ZVAL_IS_NULL(res) || IS_RESOURCE != Z_TYPE_P(res)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "unintilized couchbase");
- RETURN_FALSE;
- }
- } else {
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs|lllla", &res, &key, &klen, &offset, &create, &expire, &initial, &adurability) == FAILURE) {
- return;
- }
- }
{
lcb_error_t retval;
- php_couchbase_res *couchbase_res;
php_couchbase_ctx *ctx;
long delta = (op == '+') ? offset : -offset;
- ZEND_FETCH_RESOURCE2(couchbase_res, php_couchbase_res *, &res, -1, PHP_COUCHBASE_RESOURCE, le_couchbase, le_pcouchbase);
- if (!couchbase_res->is_connected) {
- php_error(E_WARNING, "There is no active connection to couchbase.");
- RETURN_FALSE;
- }
- if (couchbase_res->async) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "there are some results should be fetched before do any sync request");
- RETURN_FALSE;
- }
-
if (expire) {
exp = pcbc_check_expiry(expire);
}
View
@@ -542,35 +542,15 @@ void php_couchbase_create_impl(INTERNAL_FUNCTION_PARAMETERS, int oo) /* {{{ */
PHP_COUCHBASE_LOCAL
void php_couchbase_flush_impl(INTERNAL_FUNCTION_PARAMETERS, int oo) /* {{{ */
{
- zval *res;
+ php_couchbase_res* couchbase_res;
+
+ int argflags = oo ? PHP_COUCHBASE_ARG_F_OO : PHP_COUCHBASE_ARG_F_FUNCTIONAL;
+ PHP_COUCHBASE_GET_PARAMS(couchbase_res, argflags, "");
- if (oo) {
- zval *self = getThis();
- res = zend_read_property(couchbase_ce, self, ZEND_STRL(COUCHBASE_PROPERTY_HANDLE), 1 TSRMLS_CC);
- if (ZVAL_IS_NULL(res) || IS_RESOURCE != Z_TYPE_P(res)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "unintilized couchbase");
- RETURN_FALSE;
- }
- } else {
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &res) == FAILURE) {
- return;
- }
- }
{
lcb_error_t retval;
- php_couchbase_res *couchbase_res;
php_couchbase_ctx *ctx;
- ZEND_FETCH_RESOURCE2(couchbase_res, php_couchbase_res *, &res, -1, PHP_COUCHBASE_RESOURCE, le_couchbase, le_pcouchbase);
- if (!couchbase_res->is_connected) {
- php_error(E_WARNING, "There is no active connection to couchbase.");
- RETURN_FALSE;
- }
- if (couchbase_res->async) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "there are some results should be fetched before do any sync request");
- RETURN_FALSE;
- }
-
ctx = ecalloc(1, sizeof(php_couchbase_ctx));
ctx->res = couchbase_res;
{
@@ -619,35 +599,14 @@ void php_couchbase_flush_impl(INTERNAL_FUNCTION_PARAMETERS, int oo) /* {{{ */
PHP_COUCHBASE_LOCAL
void php_couchbase_stats_impl(INTERNAL_FUNCTION_PARAMETERS, int oo) /* {{{ */
{
- zval *res;
+ php_couchbase_res *couchbase_res;
+ int argflags = oo ? PHP_COUCHBASE_ARG_F_OO : PHP_COUCHBASE_ARG_F_FUNCTIONAL;
+ PHP_COUCHBASE_GET_PARAMS(couchbase_res, argflags, "");
- if (oo) {
- zval *self = getThis();
- res = zend_read_property(couchbase_ce, self, ZEND_STRL(COUCHBASE_PROPERTY_HANDLE), 1 TSRMLS_CC);
- if (ZVAL_IS_NULL(res) || IS_RESOURCE != Z_TYPE_P(res)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "unintilized couchbase");
- RETURN_FALSE;
- }
- } else {
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &res) == FAILURE) {
- return;
- }
- }
{
lcb_error_t retval;
- php_couchbase_res *couchbase_res;
php_couchbase_ctx *ctx;
- ZEND_FETCH_RESOURCE2(couchbase_res, php_couchbase_res *, &res, -1, PHP_COUCHBASE_RESOURCE, le_couchbase, le_pcouchbase);
- if (!couchbase_res->is_connected) {
- php_error(E_WARNING, "There is no active connection to couchbase.");
- RETURN_FALSE;
- }
- if (couchbase_res->async) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "there are some results should be fetched before do any sync request");
- RETURN_FALSE;
- }
-
ctx = ecalloc(1, sizeof(php_couchbase_ctx));
ctx->res = couchbase_res;
ctx->rv = return_value;
@@ -682,35 +641,14 @@ void php_couchbase_stats_impl(INTERNAL_FUNCTION_PARAMETERS, int oo) /* {{{ */
PHP_COUCHBASE_LOCAL
void php_couchbase_version_impl(INTERNAL_FUNCTION_PARAMETERS, int oo) /* {{{ */
{
- zval *res;
+ php_couchbase_res *couchbase_res;
+ int argflags = oo ? PHP_COUCHBASE_ARG_F_OO : PHP_COUCHBASE_ARG_F_FUNCTIONAL;
+ PHP_COUCHBASE_GET_PARAMS(couchbase_res, argflags, "");
- if (oo) {
- zval *self = getThis();
- res = zend_read_property(couchbase_ce, self, ZEND_STRL(COUCHBASE_PROPERTY_HANDLE), 1 TSRMLS_CC);
- if (ZVAL_IS_NULL(res) || IS_RESOURCE != Z_TYPE_P(res)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "uninitialized couchbase");
- RETURN_FALSE;
- }
- } else {
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &res) == FAILURE) {
- return;
- }
- }
{
lcb_error_t retval;
- php_couchbase_res *couchbase_res;
php_couchbase_ctx *ctx;
- ZEND_FETCH_RESOURCE2(couchbase_res, php_couchbase_res *, &res, -1, PHP_COUCHBASE_RESOURCE, le_couchbase, le_pcouchbase);
- if (!couchbase_res->is_connected) {
- php_error(E_WARNING, "There is no active connection to couchbase.");
- RETURN_FALSE;
- }
- if (couchbase_res->async) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "there are some results should be fetched before do any sync request");
- RETURN_FALSE;
- }
-
ctx = ecalloc(1, sizeof(php_couchbase_ctx));
ctx->res = couchbase_res;
ctx->rv = return_value;
@@ -749,22 +687,11 @@ void php_couchbase_set_option_impl(INTERNAL_FUNCTION_PARAMETERS, int oo) /* {{{
long option;
zval *res, *value;
php_couchbase_res *couchbase_res;
+ int argflags =
+ (oo ? PHP_COUCHBASE_ARG_F_OO : PHP_COUCHBASE_ARG_F_FUNCTIONAL) |
+ PHP_COUCHBASE_ARG_F_NOCONN | PHP_COUCHBASE_ARG_F_ASYNC;
- if (oo) {
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lz", &option, &value) == FAILURE) {
- return;
- }
- res = zend_read_property(couchbase_ce, getThis(), ZEND_STRL(COUCHBASE_PROPERTY_HANDLE), 1 TSRMLS_CC);
- if (ZVAL_IS_NULL(res) || IS_RESOURCE != Z_TYPE_P(res)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "unintilized couchbase");
- RETURN_FALSE;
- }
- } else {
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlz", &res, &option, &value) == FAILURE) {
- return;
- }
- }
- ZEND_FETCH_RESOURCE2(couchbase_res, php_couchbase_res *, &res, -1, PHP_COUCHBASE_RESOURCE, le_couchbase, le_pcouchbase);
+ PHP_COUCHBASE_GET_PARAMS(couchbase_res, argflags, "lz", &option, &value);
switch (option) {
case COUCHBASE_OPT_SERIALIZER: {
@@ -831,26 +758,13 @@ void php_couchbase_set_option_impl(INTERNAL_FUNCTION_PARAMETERS, int oo) /* {{{
PHP_COUCHBASE_LOCAL
void php_couchbase_get_option_impl(INTERNAL_FUNCTION_PARAMETERS, int oo) /* {{{ */
{
- zval *res;
- php_couchbase_res *couchbase_res;
long option;
+ php_couchbase_res *couchbase_res;
+ int argflags =
+ (oo ? PHP_COUCHBASE_ARG_F_OO : PHP_COUCHBASE_ARG_F_FUNCTIONAL) |
+ PHP_COUCHBASE_ARG_F_ONLYVALID;
- if (oo) {
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &option) == FAILURE) {
- return;
- }
- res = zend_read_property(couchbase_ce, getThis(), ZEND_STRL(COUCHBASE_PROPERTY_HANDLE), 1 TSRMLS_CC);
- if (ZVAL_IS_NULL(res) || IS_RESOURCE != Z_TYPE_P(res)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "unintilized couchbase");
- RETURN_FALSE;
- }
- } else {
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &res, &option) == FAILURE) {
- return;
- }
- }
-
- ZEND_FETCH_RESOURCE2(couchbase_res, php_couchbase_res *, &res, -1, PHP_COUCHBASE_RESOURCE, le_couchbase, le_pcouchbase);
+ PHP_COUCHBASE_GET_PARAMS(couchbase_res, argflags, "l", &option);
switch (option) {
case COUCHBASE_OPT_SERIALIZER:
@@ -881,24 +795,13 @@ void php_couchbase_get_option_impl(INTERNAL_FUNCTION_PARAMETERS, int oo) /* {{{
PHP_COUCHBASE_LOCAL
void php_couchbase_get_result_message_impl(INTERNAL_FUNCTION_PARAMETERS, int oo) /* {{{ */
{
- zval *res;
php_couchbase_res *couchbase_res;
char *str;
int str_len;
+ int argflags = (oo ? PHP_COUCHBASE_ARG_F_OO : PHP_COUCHBASE_ARG_F_FUNCTIONAL)
+ | PHP_COUCHBASE_ARG_F_ONLYVALID;
+ PHP_COUCHBASE_GET_PARAMS(couchbase_res, argflags, "");
- if (oo) {
- res = zend_read_property(couchbase_ce, getThis(), ZEND_STRL(COUCHBASE_PROPERTY_HANDLE), 1 TSRMLS_CC);
- if (ZVAL_IS_NULL(res) || IS_RESOURCE != Z_TYPE_P(res)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "unintilized couchbase");
- RETURN_FALSE;
- }
- } else {
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &res) == FAILURE) {
- return;
- }
- }
-
- ZEND_FETCH_RESOURCE2(couchbase_res, php_couchbase_res *, &res, -1, PHP_COUCHBASE_RESOURCE, le_couchbase, le_pcouchbase);
str_len = spprintf(&str, 0, "%s", lcb_strerror(couchbase_res->handle, couchbase_res->rc));
RETURN_STRINGL(str, str_len, 0);
}
Oops, something went wrong.

0 comments on commit 969cd0a

Please sign in to comment.