Module: LMDB
- Defined in:
- lib/lmdb/version.rb,
lib/lmdb/database.rb,
ext/lmdb_ext/lmdb_ext.c
Defined Under Namespace
Classes: Cursor, Database, Environment, Error, Transaction
Constant Summary collapse
- VERSION =
'0.4.0'
- LIB_VERSION =
rb_str_new2(MDB_VERSION_STRING)
Class Method Summary collapse
Class Method Details
.new(*args) ⇒ Object
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 |
# File 'ext/lmdb_ext/lmdb_ext.c', line 232
static VALUE environment_new(int argc, VALUE *argv, VALUE klass) {
VALUE path, option_hash;
rb_scan_args(argc, argv, "1:", &path, &option_hash);
EnvironmentOptions options = {
.flags = MDB_NOTLS,
.maxreaders = -1,
.maxdbs = 128,
.mapsize = 0,
.mode = 0755,
};
if (!NIL_P(option_hash))
rb_hash_foreach(option_hash, environment_options, (VALUE)&options);
MDB_env* env;
check(mdb_env_create(&env));
Environment* environment;
VALUE venv = Data_Make_Struct(cEnvironment, Environment, environment_mark, environment_free, environment);
environment->env = env;
environment->thread_txn_hash = rb_hash_new();
environment->txn_thread_hash = rb_hash_new();
if (options.maxreaders > 0)
check(mdb_env_set_maxreaders(env, options.maxreaders));
if (options.mapsize > 0)
check(mdb_env_set_mapsize(env, options.mapsize));
check(mdb_env_set_maxdbs(env, options.maxdbs <= 0 ? 1 : options.maxdbs));
check(mdb_env_open(env, StringValueCStr(path), options.flags, options.mode));
if (rb_block_given_p())
return rb_ensure(rb_yield, venv, environment_close, venv);
return venv;
}
|