Skip to content

Commit

Permalink
RCBC-60 Protect exceptions from GC
Browse files Browse the repository at this point in the history
Change-Id: Ic7e4c9f33d857ceb6529d452c13eabbcc4d0211a
Reviewed-on: http://review.couchbase.org/18874
Tested-by: Sergey Avseyev <sergey.avseyev@gmail.com>
Reviewed-by: Chris Anderson <jchris@couchbase.com>
  • Loading branch information
avsej authored and Chris Anderson committed Jul 26, 2012
1 parent 3a414a6 commit 7a5254d
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions ext/couchbase_ext/couchbase_ext.c
Expand Up @@ -590,6 +590,7 @@ storage_callback(libcouchbase_t handle, const void *cookie,
rb_ivar_set(exc, id_iv_operation, o);
if (NIL_P(ctx->exception)) {
ctx->exception = exc;
cb_gc_protect(bucket, ctx->exception);
}
}
if (bucket->async) { /* asynchronous */
Expand Down Expand Up @@ -630,6 +631,7 @@ delete_callback(libcouchbase_t handle, const void *cookie,
rb_ivar_set(exc, id_iv_operation, sym_delete);
if (NIL_P(ctx->exception)) {
ctx->exception = exc;
cb_gc_protect(bucket, ctx->exception);
}
}
}
Expand Down Expand Up @@ -671,26 +673,27 @@ get_callback(libcouchbase_t handle, const void *cookie,
rb_ivar_set(exc, id_iv_operation, sym_get);
if (NIL_P(ctx->exception)) {
ctx->exception = exc;
cb_gc_protect(bucket, ctx->exception);
}
}
}

f = ULONG2NUM(flags);
c = ULL2NUM(cas);
v = Qnil;
if (nbytes != 0) {
v = decode_value(rb_str_new((const char*)bytes, nbytes), flags, ctx->force_format);
if (v == Qundef) {
if (ctx->exception != Qnil) {
cb_gc_unprotect(bucket, ctx->exception);
}
ctx->exception = rb_exc_new2(eValueFormatError, "unable to convert value");
rb_ivar_set(ctx->exception, id_iv_operation, sym_get);
rb_ivar_set(ctx->exception, id_iv_key, k);
v = Qnil;
}
} else {
if (flags_get_format(flags) == sym_plain) {
v = rb_str_new2("");
} else {
v = Qnil;
cb_gc_protect(bucket, ctx->exception);
}
} else if (flags_get_format(flags) == sym_plain) {
v = rb_str_new2("");
}
if (bucket->async) { /* asynchronous */
if (ctx->proc != Qnil) {
Expand Down Expand Up @@ -734,6 +737,7 @@ flush_callback(libcouchbase_t handle, const void* cookie,
rb_ivar_set(exc, id_iv_operation, sym_flush);
if (NIL_P(ctx->exception)) {
ctx->exception = exc;
cb_gc_protect(bucket, ctx->exception);
}
success = Qfalse;
}
Expand Down Expand Up @@ -779,6 +783,7 @@ version_callback(libcouchbase_t handle, const void *cookie,
rb_ivar_set(exc, id_iv_operation, sym_flush);
if (NIL_P(ctx->exception)) {
ctx->exception = exc;
cb_gc_protect(bucket, ctx->exception);
}
}

Expand Down Expand Up @@ -825,6 +830,7 @@ stat_callback(libcouchbase_t handle, const void* cookie,
rb_ivar_set(exc, id_iv_operation, sym_stats);
if (NIL_P(ctx->exception)) {
ctx->exception = exc;
cb_gc_protect(bucket, ctx->exception);
}
}
if (authority) {
Expand Down Expand Up @@ -877,6 +883,7 @@ touch_callback(libcouchbase_t handle, const void *cookie,
rb_ivar_set(exc, id_iv_operation, sym_touch);
if (NIL_P(ctx->exception)) {
ctx->exception = exc;
cb_gc_protect(bucket, ctx->exception);
}
}
}
Expand Down Expand Up @@ -933,6 +940,7 @@ arithmetic_callback(libcouchbase_t handle, const void *cookie,
}
if (NIL_P(ctx->exception)) {
ctx->exception = exc;
cb_gc_protect(bucket, ctx->exception);
}
}
v = ULL2NUM(value);
Expand Down Expand Up @@ -1795,6 +1803,7 @@ cb_bucket_delete(int argc, VALUE *argv, VALUE self)
exc = ctx->exception;
xfree(ctx);
if (exc != Qnil) {
cb_gc_unprotect(bucket, exc);
rb_exc_raise(exc);
}
return rv;
Expand Down Expand Up @@ -1881,6 +1890,7 @@ cb_bucket_store(libcouchbase_storage_t cmd, int argc, VALUE *argv, VALUE self)
exc = ctx->exception;
xfree(ctx);
if (exc != Qnil) {
cb_gc_unprotect(bucket, exc);
rb_exc_raise(exc);
}
if (bucket->exception != Qnil) {
Expand Down Expand Up @@ -1968,6 +1978,7 @@ cb_bucket_arithmetic(int sign, int argc, VALUE *argv, VALUE self)
exc = ctx->exception;
xfree(ctx);
if (exc != Qnil) {
cb_gc_unprotect(bucket, exc);
rb_exc_raise(exc);
}
return rv;
Expand Down Expand Up @@ -2300,6 +2311,7 @@ cb_bucket_get(int argc, VALUE *argv, VALUE self)
extended = ctx->extended;
xfree(ctx);
if (exc != Qnil) {
cb_gc_unprotect(bucket, exc);
rb_exc_raise(exc);
}
if (bucket->exception != Qnil) {
Expand Down Expand Up @@ -2440,6 +2452,7 @@ cb_bucket_touch(int argc, VALUE *argv, VALUE self)
exc = ctx->exception;
xfree(ctx);
if (exc != Qnil) {
cb_gc_unprotect(bucket, exc);
rb_exc_raise(exc);
}
if (bucket->exception != Qnil) {
Expand Down Expand Up @@ -2526,6 +2539,7 @@ cb_bucket_flush(VALUE self)
exc = ctx->exception;
xfree(ctx);
if (exc != Qnil) {
cb_gc_unprotect(bucket, exc);
rb_exc_raise(exc);
}
return rv;
Expand Down Expand Up @@ -2604,6 +2618,7 @@ cb_bucket_version(VALUE self)
exc = ctx->exception;
xfree(ctx);
if (exc != Qnil) {
cb_gc_unprotect(bucket, exc);
rb_exc_raise(exc);
}
return rv;
Expand Down Expand Up @@ -2706,6 +2721,7 @@ cb_bucket_stats(int argc, VALUE *argv, VALUE self)
exc = ctx->exception;
xfree(ctx);
if (exc != Qnil) {
cb_gc_unprotect(bucket, exc);
rb_exc_raise(exc);
}
if (bucket->exception != Qnil) {
Expand Down

0 comments on commit 7a5254d

Please sign in to comment.