From 2b76bf1b0ff1d2b7f20dfd83850ca470a89fdf97 Mon Sep 17 00:00:00 2001 From: Takashi Tamura Date: Tue, 19 May 2015 16:42:47 +0900 Subject: [PATCH 1/2] Environment should have flags and call_with_transaction should use it --- ext/lmdb_ext/lmdb_ext.c | 4 ++++ ext/lmdb_ext/lmdb_ext.h | 1 + 2 files changed, 5 insertions(+) diff --git a/ext/lmdb_ext/lmdb_ext.c b/ext/lmdb_ext/lmdb_ext.c index de26fd6..f9a4f93 100644 --- a/ext/lmdb_ext/lmdb_ext.c +++ b/ext/lmdb_ext/lmdb_ext.c @@ -179,7 +179,10 @@ static VALUE call_with_transaction_helper(VALUE arg) { #endif static VALUE call_with_transaction(VALUE venv, VALUE self, const char* name, int argc, const VALUE* argv, int flags) { + ENVIRONMENT(venv, environment); HelperArgs arg = { self, name, argc, argv }; + if(environment->flags & MDB_RDONLY) + flags |= MDB_RDONLY; return with_transaction(venv, call_with_transaction_helper, (VALUE)&arg, flags); } @@ -490,6 +493,7 @@ static VALUE environment_new(int argc, VALUE *argv, VALUE klass) { environment->env = env; environment->thread_txn_hash = rb_hash_new(); environment->txn_thread_hash = rb_hash_new(); + environment->flags = options.flags; if (options.maxreaders > 0) check(mdb_env_set_maxreaders(env, options.maxreaders)); diff --git a/ext/lmdb_ext/lmdb_ext.h b/ext/lmdb_ext/lmdb_ext.h index cf52b64..7f1a784 100644 --- a/ext/lmdb_ext/lmdb_ext.h +++ b/ext/lmdb_ext/lmdb_ext.h @@ -59,6 +59,7 @@ typedef struct { MDB_env* env; VALUE thread_txn_hash; VALUE txn_thread_hash; + int flags; } Environment; typedef struct { From 00c58fa5a282a05f106c963046e0d8d1d64528f2 Mon Sep 17 00:00:00 2001 From: Takashi Tamura Date: Tue, 19 May 2015 21:25:16 +0900 Subject: [PATCH 2/2] check flags in with_transaction --- ext/lmdb_ext/lmdb_ext.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ext/lmdb_ext/lmdb_ext.c b/ext/lmdb_ext/lmdb_ext.c index f9a4f93..079c99b 100644 --- a/ext/lmdb_ext/lmdb_ext.c +++ b/ext/lmdb_ext/lmdb_ext.c @@ -179,10 +179,7 @@ static VALUE call_with_transaction_helper(VALUE arg) { #endif static VALUE call_with_transaction(VALUE venv, VALUE self, const char* name, int argc, const VALUE* argv, int flags) { - ENVIRONMENT(venv, environment); HelperArgs arg = { self, name, argc, argv }; - if(environment->flags & MDB_RDONLY) - flags |= MDB_RDONLY; return with_transaction(venv, call_with_transaction_helper, (VALUE)&arg, flags); } @@ -209,6 +206,8 @@ static void stop_txn_begin(void *arg) static VALUE with_transaction(VALUE venv, VALUE(*fn)(VALUE), VALUE arg, int flags) { ENVIRONMENT(venv, environment); + if(environment->flags & MDB_RDONLY) + flags |= MDB_RDONLY; MDB_txn* txn; TxnArgs txn_args;