Skip to content
This repository was archived by the owner on Apr 20, 2022. It is now read-only.

Commit f3a8701

Browse files
committed
Fixup observe test failure
Change-Id: Ib10d39ab9bb8a85706189f8d88e94ce56b20fee9 Reviewed-on: http://review.couchbase.org/29202 Reviewed-by: Trond Norbye <trond.norbye@gmail.com> Tested-by: Trond Norbye <trond.norbye@gmail.com>
1 parent d09b663 commit f3a8701

File tree

1 file changed

+28
-36
lines changed

1 file changed

+28
-36
lines changed

observe.c

Lines changed: 28 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -124,24 +124,20 @@ static lcb_cas_t cas_from_zval(zval *zv)
124124
(Z_TYPE_P(zv) == IS_BOOL && Z_BVAL_P(zv) == 0)) {
125125
/* invalid, but fals-ish */
126126
return 0;
127-
128127
}
129128

130-
if (IS_STRING != Z_TYPE_P(zv) || Z_STRLEN_P(zv) > sizeof(casbuf)) {
131-
goto GT_ERR;
129+
if (Z_TYPE_P(zv) == IS_STRING) {
130+
char *e;
131+
ret = strtoull(Z_STRVAL_P(zv), &e, 10);
132+
if (*e == '\0') {
133+
return ret;
134+
}
132135
}
133136

134-
/* TODO: make this portable */
135-
memcpy(casbuf, Z_STRVAL_P(zv), Z_STRLEN_P(zv));
136-
ret = strtoull(casbuf, &endptr, 10);
137-
138-
if (*endptr != '\0') {
139-
goto GT_ERR;
137+
if (Z_TYPE_P(zv) == IS_LONG) {
138+
return Z_LVAL_P(zv);
140139
}
141140

142-
return ret;
143-
144-
GT_ERR:
145141
php_error(E_RECOVERABLE_ERROR,
146142
"Invalid CAS Specified (must be a numeric string)");
147143
return -1;
@@ -304,6 +300,7 @@ static int oks_extract_durability(php_couchbase_res *res,
304300
tmplong = Z_LVAL_P(tmpval); \
305301
if (tmplong < gt) { \
306302
php_error(E_RECOVERABLE_ERROR, k " must be greater than %d", gt); \
303+
return -1; \
307304
} \
308305
}
309306

@@ -733,14 +730,14 @@ void php_couchbase_observe_impl(INTERNAL_FUNCTION_PARAMETERS,
733730
array_init(return_value);
734731

735732
if (poll) {
736-
if (-1 == oks_extract_durability(couchbase_res,
737-
&expect, &pollprefs, adurability)) {
733+
if (oks_extract_durability(couchbase_res, &expect, &pollprefs,
734+
adurability) == -1) {
738735
RETURN_FALSE;
739736
}
740737
}
741738

742-
if (-1 == oks_build_context(couchbase_res,
743-
&ocoll, &expect, akey_to_cas, 1)) {
739+
if (oks_build_context(couchbase_res, &ocoll, &expect,
740+
akey_to_cas, 1) == -1) {
744741
RETURN_FALSE;
745742
}
746743

@@ -794,22 +791,18 @@ void php_couchbase_observe_impl(INTERNAL_FUNCTION_PARAMETERS,
794791
{
795792
int have_failure = 0;
796793
do {
797-
798794
if (poll) {
799-
if (-1 == oks_extract_durability(couchbase_res,
800-
&expect,
801-
&pollprefs,
802-
adurability)) {
803-
have_failure = 1;
804-
break;
805-
}
795+
have_failure = oks_extract_durability(couchbase_res,
796+
&expect,
797+
&pollprefs,
798+
adurability);
806799
}
807800

808-
if (-1 == oks_build_context(
809-
couchbase_res, &ocoll, &expect, akc_dummy, 0)) {
810-
811-
have_failure = 1;
812-
break;
801+
if (have_failure == 0) {
802+
have_failure = oks_build_context(couchbase_res,
803+
&ocoll,
804+
&expect,
805+
akc_dummy, 0);
813806
}
814807
} while (0);
815808

@@ -829,7 +822,6 @@ void php_couchbase_observe_impl(INTERNAL_FUNCTION_PARAMETERS,
829822

830823
if (poll) {
831824
observe_poll(couchbase_res, &ocoll, &pollprefs);
832-
833825
} else {
834826
observe_iterate(couchbase_res, &ocoll);
835827
}
@@ -840,6 +832,12 @@ void php_couchbase_observe_impl(INTERNAL_FUNCTION_PARAMETERS,
840832
oks_cleanup_context(&ocoll);
841833
}
842834

835+
PHP_COUCHBASE_LOCAL
836+
void php_couchbase_callbacks_observe_init(lcb_t handle)
837+
{
838+
lcb_set_observe_callback(handle, php_couchbase_observe_callback);
839+
}
840+
843841
/*
844842
* Local variables:
845843
* tab-width: 4
@@ -848,9 +846,3 @@ void php_couchbase_observe_impl(INTERNAL_FUNCTION_PARAMETERS,
848846
* vim600: noet sw=4 ts=4 fdm=marker
849847
* vim<600: noet sw=4 ts=4
850848
*/
851-
852-
PHP_COUCHBASE_LOCAL
853-
void php_couchbase_callbacks_observe_init(lcb_t handle)
854-
{
855-
lcb_set_observe_callback(handle, php_couchbase_observe_callback);
856-
}

0 commit comments

Comments
 (0)