lmdb 0.6.3 → 0.6.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e28bee640bdc0adcca93b5efa23e98116257bdb3f933d9c5104c6aa289d824bd
4
- data.tar.gz: a4f5f2fde8b1591c3dda79f9d84f006ce7deef2fbdc9aef1525505397d05df92
3
+ metadata.gz: 6d6a2b5d9eb4d0c1a93c0d807bb890ad33bd7eafe6e55d7a132796096296f078
4
+ data.tar.gz: 9ef7004f7734571bebb5352a99287f1de65e3392c7490d089de959c5a3502a68
5
5
  SHA512:
6
- metadata.gz: a792888943a2cec0cd5733f5deaa48dd22991373d1b3af00c9a21ee35cd3ae6bbb563b85c26830684b8deef40bd4b5f7e9c62bec2281a0bc7d72bd6cb1c8ca9c
7
- data.tar.gz: 32a600c64648a588dc57025260c39f1df79b9c47b2e36fe76fe281620ed1b64a04276653ba9f384811905eb1dc5ee6427f1783bf09be111fe9249b2ebf5f4f16
6
+ metadata.gz: bf624d2a0e988a764d1cbdd23c30fe48d249d79f855aa5cc3bb3c3c079474edc59df57a68a47aa85b723d4dc6e28621f01c529d1f09efa948d66205e392e485c
7
+ data.tar.gz: a659a1329886ffd36f6c901c9db4fb64f3f463bf085d17115b2a7b2bda9bf5cf365d5ab90850043395a66566a20d56c3548fa56997563ef714a91a5c3f764202
@@ -248,7 +248,7 @@ static void stop_txn_begin(void *arg)
248
248
 
249
249
  /**
250
250
  * This is the code that opens transactions. Read-write transactions
251
- * have to be called outside the GVL because they will block without
251
+ * have to be called outside the GVL because they will block otherwise.
252
252
  *
253
253
  *
254
254
  * Here is the basic problem with LMDB transactions:
@@ -910,6 +910,53 @@ static VALUE environment_database(int argc, VALUE *argv, VALUE self) {
910
910
  return vdb;
911
911
  }
912
912
 
913
+ /**
914
+ * @overload databases()
915
+ * Returns a list of the names of all databases in the environment, or
916
+ * an empty list if there are no named databases but only the defaut database.
917
+ *
918
+ * @return [Array] The names of all databases in the environment.
919
+ * @raise [Error] If there is an error opening the main database.
920
+ */
921
+ static VALUE environment_databases(VALUE self) {
922
+ ENVIRONMENT(self, environment);
923
+ if (!active_txn(self))
924
+ return call_with_transaction(self, self, "databases", 0, 0, MDB_RDONLY);
925
+
926
+ MDB_dbi dbi;
927
+ MDB_cursor *cursor;
928
+ MDB_txn *txn = need_txn(self);
929
+ MDB_val key;
930
+
931
+ check(mdb_dbi_open(txn, NULL, 0, &dbi));
932
+ check(mdb_cursor_open(txn, dbi, &cursor));
933
+
934
+ VALUE ret = rb_ary_new();
935
+ while (mdb_cursor_get(cursor, &key, NULL, MDB_NEXT_NODUP) == MDB_SUCCESS) {
936
+ char *intern_db_name;
937
+ MDB_dbi db;
938
+ VALUE db_name;
939
+
940
+ if (memchr(key.mv_data, '\0', key.mv_size))
941
+ continue;
942
+
943
+ intern_db_name = malloc(key.mv_size + 1);
944
+ memcpy(intern_db_name, key.mv_data, key.mv_size);
945
+ intern_db_name[key.mv_size] = '\0';
946
+
947
+ if (mdb_dbi_open(txn, intern_db_name, 0, &db) == MDB_SUCCESS) {
948
+ mdb_dbi_close(environment->env, db);
949
+ db_name = rb_str_new(key.mv_data, key.mv_size);
950
+ rb_ary_push(ret, db_name);
951
+ }
952
+ free(intern_db_name);
953
+ }
954
+
955
+ mdb_cursor_close(cursor);
956
+
957
+ return ret;
958
+ }
959
+
913
960
  /**
914
961
  * @overload stat
915
962
  * Return useful statistics about a database.
@@ -1337,9 +1384,10 @@ static VALUE cursor_next_range(VALUE self, VALUE upper_bound_key) {
1337
1384
  MDB_dbi dbi = mdb_cursor_dbi(cursor->cur);
1338
1385
 
1339
1386
  if (mdb_cmp(txn, dbi, &key, &ub_key) <= 0) {
1340
- return rb_assoc_new(rb_str_new(key.mv_data, key.mv_size), rb_str_new(value.mv_data, value.mv_size));
1387
+ return rb_assoc_new(rb_str_new(key.mv_data, key.mv_size),
1388
+ rb_str_new(value.mv_data, value.mv_size));
1341
1389
  } else {
1342
- return Qnil;
1390
+ return Qnil;
1343
1391
  }
1344
1392
  }
1345
1393
 
@@ -1360,19 +1408,32 @@ static VALUE cursor_next_range(VALUE self, VALUE upper_bound_key) {
1360
1408
 
1361
1409
  rb_scan_args(argc, argv, "11", &vkey, &vval);
1362
1410
 
1411
+ /*
1412
+ XXX TODO: this was a nasty segfault: the key (and any
1413
+ non-nil value) should be asserted to be strings, but then
1414
+ if the database is `integerkeys` then perhaps we should
1415
+ coerce?
1416
+ */
1417
+
1418
+ if (TYPE(vkey) != T_STRING)
1419
+ rb_raise(rb_eArgError, "key must be a string");
1420
+
1363
1421
  key.mv_size = RSTRING_LEN(vkey);
1364
1422
  key.mv_data = StringValuePtr(vkey);
1365
1423
 
1366
1424
  if (!NIL_P(vval)) {
1367
- op = MDB_GET_BOTH;
1368
- value.mv_size = RSTRING_LEN(vval);
1369
- value.mv_data = StringValuePtr(vval);
1425
+ if (TYPE(vval) != T_STRING)
1426
+ rb_raise(rb_eArgError, "non-nil value must be a string");
1427
+
1428
+ op = MDB_GET_BOTH;
1429
+ value.mv_size = RSTRING_LEN(vval);
1430
+ value.mv_data = StringValuePtr(vval);
1370
1431
  }
1371
1432
 
1372
1433
  ret = mdb_cursor_get(cursor->cur, &key, &value, op);
1373
1434
 
1374
1435
  if (!NIL_P(vval) && ret == MDB_NOTFOUND)
1375
- return Qnil;
1436
+ return Qnil;
1376
1437
 
1377
1438
  check(ret);
1378
1439
 
@@ -1603,6 +1664,7 @@ void Init_lmdb_ext() {
1603
1664
  rb_undef_alloc_func(cEnvironment);
1604
1665
  rb_define_singleton_method(cEnvironment, "new", environment_new, -1);
1605
1666
  rb_define_method(cEnvironment, "database", environment_database, -1);
1667
+ rb_define_method(cEnvironment, "databases", environment_databases, 0);
1606
1668
  rb_define_method(cEnvironment, "active_txn", environment_active_txn, 0);
1607
1669
  rb_define_method(cEnvironment, "close", environment_close, 0);
1608
1670
  rb_define_method(cEnvironment, "stat", environment_stat, 0);
@@ -156,6 +156,7 @@ static VALUE environment_clear_flags(int argc, VALUE* argv, VALUE self);
156
156
  static VALUE environment_close(VALUE self);
157
157
  static VALUE environment_copy(VALUE self, VALUE path);
158
158
  static VALUE environment_database(int argc, VALUE *argv, VALUE self);
159
+ static VALUE environment_databases(VALUE self);
159
160
  static VALUE environment_flags(VALUE self);
160
161
  static void environment_free(Environment *environment);
161
162
  static VALUE environment_info(VALUE self);
data/lib/lmdb/database.rb CHANGED
@@ -122,6 +122,8 @@ module LMDB
122
122
  return true if value.nil? or value.to_s == v
123
123
  return false unless dupsort?
124
124
 
125
+ # warn "checking dupsort value `#{value.inspect}` (#{value.class})"
126
+
125
127
  ret = false
126
128
  # read-only txn was having trouble being nested inside a read-write
127
129
  maybe_txn true do
@@ -152,9 +154,11 @@ module LMDB
152
154
  # going to do this (djt; 2020-02-10)
153
155
  def maybe_txn(readonly, &block)
154
156
  if t = env.active_txn
157
+ # warn "reusing #{t.readonly? ? 'read-only ' : ''}txn #{t.inspect}"
155
158
  yield t
156
159
  else
157
160
  env.transaction !!readonly do |t|
161
+ # warn "new #{t.readonly? ? 'read-only ' : ''}txn #{t.inspect}"
158
162
  yield t
159
163
  end
160
164
  end
data/lib/lmdb/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module LMDB
2
- VERSION = '0.6.3'.freeze
2
+ VERSION = '0.6.5'.freeze
3
3
  end
data/lmdb.gemspec CHANGED
@@ -22,8 +22,8 @@ Gem::Specification.new do |s|
22
22
 
23
23
  s.required_ruby_version = '>= 2.7'
24
24
 
25
- s.add_development_dependency 'rake', '~> 13'
25
+ s.add_development_dependency 'rake', '~> 13'
26
26
  s.add_development_dependency 'rake-compiler', '~> 1.2'
27
- s.add_development_dependency 'rspec', '~> 3'
28
- s.add_development_dependency 'ruby_memcheck', '~> 2'
27
+ s.add_development_dependency 'rspec', '~> 3'
28
+ s.add_development_dependency 'ruby_memcheck', '~> 3'
29
29
  end
data/spec/lmdb_spec.rb CHANGED
@@ -100,6 +100,27 @@ describe LMDB do
100
100
  subject.flags.should_not include(:nosync)
101
101
  end
102
102
 
103
+ describe 'databases' do
104
+ it 'returns empty list when there are no named databases' do
105
+ subject.databases.should == []
106
+ end
107
+
108
+ it 'returns list of named databases' do
109
+ db1 = subject.database 'db1', create: true
110
+ db2 = subject.database 'db2', create: true
111
+ subject.databases.should == ['db1', 'db2']
112
+ end
113
+
114
+ it 'returns list of named databases when there are non-database kes in the main db' do
115
+ main = subject.database
116
+ main['key'] = 'value'
117
+ subject.database 'db1', create: true
118
+ subject.database 'db2', create: true
119
+
120
+ subject.databases.should == ['db1', 'db2']
121
+ end
122
+ end
123
+
103
124
  describe LMDB::Transaction do
104
125
  subject { env }
105
126
 
@@ -418,5 +439,21 @@ describe LMDB do
418
439
  db.put 'hurr', 'durr' unless db.has? 'hurr', 'durr'
419
440
  end
420
441
  end
442
+
443
+ it 'should croak when cursor key is not given a string' do
444
+ proc do
445
+ db.cursor do |c|
446
+ c.set 1
447
+ end
448
+ end.should raise_error(ArgumentError)
449
+ end
450
+
451
+ it 'should croak when cursor value is not given a string' do
452
+ proc do
453
+ db.cursor do |c|
454
+ c.set 'hi', 1
455
+ end
456
+ end.should raise_error(ArgumentError)
457
+ end
421
458
  end
422
459
  end
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lmdb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.3
4
+ version: 0.6.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Mendler
8
8
  - Dorian Taylor
9
- autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2024-11-18 00:00:00.000000000 Z
11
+ date: 2025-05-07 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rake
@@ -59,14 +58,14 @@ dependencies:
59
58
  requirements:
60
59
  - - "~>"
61
60
  - !ruby/object:Gem::Version
62
- version: '2'
61
+ version: '3'
63
62
  type: :development
64
63
  prerelease: false
65
64
  version_requirements: !ruby/object:Gem::Requirement
66
65
  requirements:
67
66
  - - "~>"
68
67
  - !ruby/object:Gem::Version
69
- version: '2'
68
+ version: '3'
70
69
  description: lmdb is a Ruby binding to OpenLDAP Lightning MDB.
71
70
  email: code@doriantaylor.com
72
71
  executables: []
@@ -130,7 +129,6 @@ homepage: https://github.com/doriantaylor/rb-lmdb
130
129
  licenses:
131
130
  - MIT
132
131
  metadata: {}
133
- post_install_message:
134
132
  rdoc_options: []
135
133
  require_paths:
136
134
  - lib
@@ -145,8 +143,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
145
143
  - !ruby/object:Gem::Version
146
144
  version: '0'
147
145
  requirements: []
148
- rubygems_version: 3.4.20
149
- signing_key:
146
+ rubygems_version: 3.6.3
150
147
  specification_version: 4
151
148
  summary: Ruby bindings to Lightning MDB
152
149
  test_files: