lmdb 0.7.0 → 0.7.3

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: c098384d91381d0f7c66a4794f88ea55c1c8a1e54d60480a75a379704407252d
4
- data.tar.gz: 11c4e5b74f9b552ad9f89d5a189bf812340ab409b43b54361cb84f7d47dfd906
3
+ metadata.gz: ec26115e9cc3611f3305c308a5a26959e0f2ff6438c191968a562c85808fb6ed
4
+ data.tar.gz: 866b32d018335fa61dbefdc30234c976573a307ad11ae31c260a902cba6812e8
5
5
  SHA512:
6
- metadata.gz: da3b52d345951ad527b67ce32998c749b17267b7b0d075f695e841d1b2a0891df4e0064e021e7db9ac21f41c0b81a4fb590ff88a98250675e15ad14baf185680
7
- data.tar.gz: 12ae851f60db43dec61730f8497a06bf952e56242bff2e8fe64153a852c34582441556320cb1627fa65b7c29dfe417ba312c929d242511c0ab9c3888b12075b4
6
+ metadata.gz: '0356608ed8065cb4065a752fff8e4aa657fc29c38630e45d278c7edcad4fd211f8129e87eba2e323f2f72a8751b6a43ead97501ece2c8a504cfc9eb0e3b0174c'
7
+ data.tar.gz: 7f1e02c62e406c108bd7db8875cf528c2ec43cca0beb2ab1ae6380a71b3054b74b66beddd98404e3de93de0928d9221aca9e73c6b309caa5734a0ef78d2d1313
@@ -137,6 +137,28 @@ static VALUE transaction_is_readonly(VALUE self) {
137
137
  return (transaction->flags & MDB_RDONLY) ? Qtrue : Qfalse;
138
138
  }
139
139
 
140
+ /**
141
+ * @overload finished?
142
+ * @note This predicate is considered *unstable*; do not get used to it.
143
+ * @return [false,true] whether the transaction is finished.
144
+ */
145
+ static VALUE transaction_is_finished(VALUE self) {
146
+ TRANSACTION(self, transaction);
147
+ // MDB_TXN_FINISHED
148
+ return (transaction->flags & 0x01) ? Qtrue : Qfalse;
149
+ }
150
+
151
+ /**
152
+ * @overload error?
153
+ * @note This predicate is considered *unstable*; do not get used to it.
154
+ * @return [false,true] whether the transaction incurred an error.
155
+ */
156
+ static VALUE transaction_is_error(VALUE self) {
157
+ TRANSACTION(self, transaction);
158
+ // MDB_TXN_ERROR
159
+ return (transaction->flags & 0x02) ? Qtrue : Qfalse;
160
+ }
161
+
140
162
 
141
163
  static void transaction_finish(VALUE self, int commit) {
142
164
  TRANSACTION(self, transaction);
@@ -312,16 +334,21 @@ static VALUE with_transaction(VALUE venv, VALUE(*fn)(VALUE), VALUE arg, int flag
312
334
  */
313
335
 
314
336
  if (tparent && flags & MDB_RDONLY) {
337
+ // We are reusing the parent transaction.
338
+
315
339
  int exception;
316
340
  VALUE ret = rb_protect(fn, NIL_P(arg) ? vparent : arg, &exception);
341
+
317
342
  if (exception) {
318
- if (vparent == environment_active_txn(venv))
319
- transaction_abort(vparent);
343
+ // this is a cargo cult; i just copied it from below
344
+ if (vparent == environment_active_txn(venv)) transaction_abort(vparent);
320
345
  rb_jump_tag(exception);
321
346
  }
322
347
  return ret;
323
348
  }
324
349
  else {
350
+ // We are creating a new transaction.
351
+
325
352
  // XXX note this is a cursed goto loop that could almost certainly
326
353
  // be rewritten as a do-while
327
354
  retry:
@@ -1802,6 +1829,8 @@ void Init_lmdb_ext() {
1802
1829
  rb_define_method(cTransaction, "abort", transaction_abort, 0);
1803
1830
  rb_define_method(cTransaction, "env", transaction_env, 0);
1804
1831
  rb_define_method(cTransaction, "readonly?", transaction_is_readonly, 0);
1832
+ rb_define_method(cTransaction, "finished?", transaction_is_finished, 0);
1833
+ rb_define_method(cTransaction, "error?", transaction_is_error, 0);
1805
1834
 
1806
1835
  /**
1807
1836
  * Document-class: LMDB::Cursor
data/lib/lmdb/database.rb CHANGED
@@ -126,11 +126,8 @@ module LMDB
126
126
 
127
127
  ret = false
128
128
  # read-only txn was having trouble being nested inside a read-write
129
- maybe_txn true do
130
- # env.transaction true do
131
- # env.transaction do
132
- cursor { |c| ret = !!c.set(key, value) }
133
- end
129
+ maybe_txn(true) { cursor { |c| ret = !!c.set(key, value) } }
130
+
134
131
  ret
135
132
  end
136
133
 
@@ -145,16 +142,19 @@ module LMDB
145
142
  # @return [void]
146
143
  #
147
144
  def put?(key, value = nil, **options)
145
+ # early bailout
146
+ return if value.nil?
147
+
148
148
  flags = { (dupsort? ? :nodupdata : :nooverwrite) => true }
149
- begin
150
- put key, value, **options.merge(flags)
151
- rescue LMDB::Error::KEYEXIST
152
- nil
149
+
150
+ env.transaction do |txn|
151
+ put(key, value, **options.merge(flags)) unless has?(key, value)
153
152
  end
154
153
  end
155
154
 
156
155
  # Delete the key (and optional value pair) if it exists; do not
157
156
  # complain about missing keys.
157
+ #
158
158
  # @param key [#to_s] The key of the record
159
159
  # @param value [#to_s, nil] The optional value
160
160
  #
@@ -163,11 +163,7 @@ module LMDB
163
163
  # @return [void]
164
164
  #
165
165
  def delete?(key, value = nil)
166
- begin
167
- delete key, value
168
- rescue LMDB::Error::NOTFOUND
169
- nil
170
- end
166
+ env.transaction { |txn| delete(key, value) if has?(key, value) }
171
167
  end
172
168
 
173
169
  # Return how many records there are in this database.
data/lib/lmdb/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module LMDB
2
- VERSION = '0.7.0'.freeze
2
+ VERSION = '0.7.3'.freeze
3
3
  end
data/spec/helper.rb CHANGED
@@ -1,12 +1,12 @@
1
1
  require 'lmdb'
2
2
  require 'rspec'
3
3
  require 'fileutils'
4
+ require 'tmpdir'
4
5
 
5
6
  # for valgrind
6
7
  at_exit { GC.start }
7
8
 
8
- SPEC_ROOT = File.dirname(__FILE__)
9
- TEMP_ROOT = File.join(SPEC_ROOT, 'tmp')
9
+ TEMP_ROOT = File.join(Dir.tmpdir, 'lmdb-spec')
10
10
 
11
11
  module LMDB::SpecHelper
12
12
  def mkpath(name = 'env')
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lmdb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.7.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Mendler
8
8
  - Dorian Taylor
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-11-23 00:00:00.000000000 Z
11
+ date: 2026-05-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -143,7 +143,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
143
143
  - !ruby/object:Gem::Version
144
144
  version: '0'
145
145
  requirements: []
146
- rubygems_version: 3.6.3
146
+ rubygems_version: 3.6.7
147
147
  specification_version: 4
148
148
  summary: Ruby bindings to Lightning MDB
149
149
  test_files: