Permalink
Browse files

context.c: fix error with marking a deleted context

Change-Id: I80079eaab015f6b0e248dd592616c3606b49120e
Reviewed-on: http://review.couchbase.org/23502
Reviewed-by: Sergey Avseyev <sergey.avseyev@gmail.com>
Tested-by: Sergey Avseyev <sergey.avseyev@gmail.com>
  • Loading branch information...
1 parent da420c7 commit c6ad2fd3056de226f646ca2186f1874813d29775 @funny-falcon funny-falcon committed with avsej Dec 23, 2012
Showing with 23 additions and 18 deletions.
  1. +8 −1 ext/couchbase_ext/bucket.c
  2. +11 −14 ext/couchbase_ext/context.c
  3. +2 −1 ext/couchbase_ext/couchbase_ext.h
  4. +2 −2 ext/couchbase_ext/utils.c
@@ -42,6 +42,13 @@ cb_bucket_free(void *ptr)
}
}
+ static int
+cb_bucket_mark_object_i(st_index_t key, st_data_t value, st_data_t arg)
+{
+ ((mark_f)value)((void*)key, (struct cb_bucket_st*)arg);
+ return ST_CONTINUE;
+}
+
void
cb_bucket_mark(void *ptr)
{
@@ -57,7 +64,7 @@ cb_bucket_mark(void *ptr)
rb_gc_mark(bucket->exception);
rb_gc_mark(bucket->on_error_proc);
rb_gc_mark(bucket->key_prefix_val);
- rb_mark_tbl(bucket->object_space);
+ st_foreach(bucket->object_space, cb_bucket_mark_object_i, (st_data_t)bucket);
}
}
@@ -18,30 +18,27 @@
#include "couchbase_ext.h"
static void
-cb_context_mark(void *p)
+cb_context_mark(void *p, struct cb_bucket_st* bucket)
{
- if (p) {
- struct cb_context_st *ctx = p;
- rb_gc_mark(ctx->proc);
- rb_gc_mark(ctx->rv);
- rb_gc_mark(ctx->exception);
- rb_gc_mark(ctx->observe_options);
- rb_gc_mark(ctx->force_format);
- rb_gc_mark(ctx->operation);
- rb_gc_mark(ctx->headers_val);
- }
+ struct cb_context_st *ctx = p;
+ rb_gc_mark(ctx->proc);
+ rb_gc_mark(ctx->rv);
+ rb_gc_mark(ctx->exception);
+ rb_gc_mark(ctx->observe_options);
+ rb_gc_mark(ctx->force_format);
+ rb_gc_mark(ctx->operation);
+ rb_gc_mark(ctx->headers_val);
+ (void)bucket;
}
struct cb_context_st *
cb_context_alloc(struct cb_bucket_st* bucket)
{
- VALUE obj;
struct cb_context_st *ctx = calloc(1, sizeof(*ctx));
if (ctx == NULL) {
rb_raise(cb_eClientNoMemoryError, "failed to allocate memory for context");
}
- obj = Data_Wrap_Struct(rb_cObject, cb_context_mark, 0, ctx);
- cb_gc_protect_ptr(bucket, ctx, obj);
+ cb_gc_protect_ptr(bucket, ctx, cb_context_mark);
ctx->bucket = bucket;
ctx->exception = Qnil;
return ctx;
@@ -304,10 +304,11 @@ extern VALUE cb_vStrDefault;
extern VALUE cb_vStrEmpty;
extern VALUE cb_vStrLocalhost;
+typedef void (*mark_f)(void *, struct cb_bucket_st*);
void cb_strip_key_prefix(struct cb_bucket_st *bucket, VALUE key);
VALUE cb_check_error(lcb_error_t rc, const char *msg, VALUE key);
VALUE cb_check_error_with_status(lcb_error_t rc, const char *msg, VALUE key, lcb_http_status_t status);
-void cb_gc_protect_ptr(struct cb_bucket_st *bucket, void *ptr, VALUE val);
+void cb_gc_protect_ptr(struct cb_bucket_st *bucket, void *ptr, mark_f mark_func);
void cb_gc_unprotect_ptr(struct cb_bucket_st *bucket, void *ptr);
VALUE cb_proc_call(struct cb_bucket_st *bucket, VALUE recv, int argc, ...);
int cb_first_value_i(VALUE key, VALUE value, VALUE arg);
@@ -18,9 +18,9 @@
#include "couchbase_ext.h"
void
-cb_gc_protect_ptr(struct cb_bucket_st *bucket, void *ptr, VALUE val)
+cb_gc_protect_ptr(struct cb_bucket_st *bucket, void *ptr, mark_f mark_func)
{
- st_insert(bucket->object_space, (st_index_t)ptr, (st_data_t)val);
+ st_insert(bucket->object_space, (st_index_t)ptr, (st_data_t)mark_func);
}
void

0 comments on commit c6ad2fd

Please sign in to comment.