maxmind-db-rust 0.7.0-x86_64-linux → 0.8.0-x86_64-linux

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: 8ae049c72fb13a36bf088c0b129a71fe4cb788efdf712627ee531524d73d9bb5
4
- data.tar.gz: 92c8a7d1d93d2c4ece10a5aa37f112c52661231309307b02faf16aaf577e1936
3
+ metadata.gz: 90a01c8547edf928fb64ec2c3411f73904ae9bd1ae57b64bfad2d1b1d5300058
4
+ data.tar.gz: 297893b49d8257402f0b44aaf99c529487c9fcc771cd5306482ed32065727fc2
5
5
  SHA512:
6
- metadata.gz: 1ab0bbd100c6c4c53daeb9bd996d370b1f79b8a198af799ce98bc9dae5dab21065d884ae1746907261617694ec110a0d45f8d0ba70f3d03bc1cd266211a88bd5
7
- data.tar.gz: a7b321595c3c55291b81fd64ac17694e9b813a1d4007f38b345996a75afd88e5c37a899ade81cd049f0ff9156704f7cb205e9fc9e7f6f506a6d4b4c74d3aa26a
6
+ metadata.gz: 6a9fc6624bc187cc65d06c0f84a63778a7e247c7807e981d0064a2cab9a26c963971de3c74056c50ef0d53a12c03369d9b6b3a2f6735dd40bd03a3aa14053de4
7
+ data.tar.gz: befa28b31bb18b45604e43b8b29a885fc4f8b3cf9d797c06e3d63443a610f0c033a8f53dadeb4fe846823c7e81d74cadafeb3b4f813beeeaba52fb7428bd3713
data/CHANGELOG.md CHANGED
@@ -5,6 +5,94 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [0.8.0] - 2026-11-25
9
+
10
+ ### Changed
11
+
12
+ - **Breaking:** Ruby 3.3 or later is now required. Ruby 3.2 is end of life,
13
+ and `magnus` 0.9 no longer builds against it.
14
+ - **Breaking:** Building from source now requires Rust 1.85 or later, because
15
+ `magnus` 0.9 does.
16
+ - **Breaking:** Lookups no longer call `to_s` on an argument that is neither a
17
+ String nor an `IPAddr`, such as a Symbol. They pass it to `IPAddr.new`, as the
18
+ `maxmind-db` gem does, which raises `IPAddr::AddressFamilyError`.
19
+ - **Breaking:** `get_many` and `get_many_path` now raise the closed-reader
20
+ `RuntimeError` if the reader is closed before the last lookup, as `get` does.
21
+ Previously they finished with the database that was open at the start.
22
+ - **Breaking:** `Reader.new` now converts the path as `File.open` does. A UTF-16
23
+ path raises `Encoding::CompatibilityError`, unless Ruby converts it because
24
+ `Encoding.default_internal` is set. On Linux, any other path that is not in
25
+ UTF-8 is converted to UTF-8 only if `Encoding.default_internal` is set.
26
+ - Upgraded the `maxminddb` crate from 0.32.0 to 0.33.0, which fixes network
27
+ iteration omitting some IPv6 networks and decoding of some four-byte data
28
+ pointers.
29
+ - Opening a reader now builds a prefix index, which makes lookups that find no
30
+ record about 25% faster. Opening in a memory-mapped mode takes longer. With a
31
+ 111 MB GeoIP2 City database, it went from about 7 to 150 microseconds. Reuse
32
+ readers rather than opening one for each request.
33
+ - Upgraded `magnus` from 0.8 to 0.9 and updated other Rust dependencies.
34
+ - The source gem now includes `Cargo.lock` and the release build profile, so
35
+ installing from source builds the tested dependency versions with the same
36
+ optimizations as the native gems.
37
+ - `Reader#verify` and opening a database in `MODE_MEMORY` now release Ruby's
38
+ global VM lock while they work, so other Ruby threads are no longer stalled.
39
+ Verification still cannot be interrupted part way through.
40
+
41
+ ### Fixed
42
+
43
+ - Fixed a possible crash or memory corruption when GC compaction moved the
44
+ internal string cache. The cache is now pinned so compaction cannot move it.
45
+ - `Reader#get_path` and `Reader#get_many_path` no longer deadlock when a path
46
+ element defines `to_str` or `to_int` and that method calls back into the
47
+ reader or releases the GVL.
48
+ Ruby conversion methods no longer run while the path cache lock is held.
49
+ - Anything an argument's `to_str`, `to_ary` or `to_int` raises or throws now
50
+ reaches the caller. Previously it was replaced with an `ArgumentError`, or
51
+ ignored when another conversion succeeded. Only these are still treated as an
52
+ argument of the wrong type: a `TypeError`, a number such as `Float::INFINITY`
53
+ that has no Integer value, and a `Numeric` without `to_i`.
54
+ - `Reader` now matches the `maxmind-db` gem in several more calls:
55
+ - `Reader.new` accepts a `Pathname` or any object with `to_path`, and its
56
+ options as a positional Hash as well as keywords.
57
+ - `Reader` can be subclassed. `new` returns an instance of the subclass and
58
+ calls its `initialize`.
59
+ - Errors opening or memory-mapping the database file raise the matching
60
+ `Errno` exception, such as `Errno::EACCES` or `Errno::EISDIR`, instead of
61
+ `IOError`. Their messages keep the encoding of the path.
62
+ - Invalid IP addresses raise `IPAddr::InvalidAddressError`, a subclass of
63
+ `ArgumentError`. Lookups accept CIDR strings such as `"1.2.3.4/32"` and
64
+ scoped IPv6 addresses such as `"fe80::1%eth0"`, as `IPAddr.new` does.
65
+ - `metadata` works after `close`.
66
+ - `Reader#each(nil)` now iterates over the whole database, as documented,
67
+ instead of raising `ArgumentError`. `each` now raises `ArgumentError` for
68
+ extra arguments, and checks the network when called without a block rather
69
+ than when the returned enumerator is first used.
70
+ - `get_many` and `get_many_path` now raise a `StopIteration` that a non-Array
71
+ input raises from its `each`. Previously they treated it as the end of the
72
+ input and returned a short result. A lookup error, such as an invalid IP,
73
+ now stops a non-Array input's `each` and is raised even if that `each`
74
+ rescues it. If a lookup never finishes, such as because `each` catches a
75
+ `throw` from it, they raise `RuntimeError` instead of returning a short
76
+ result.
77
+ - `Metadata#search_tree_size` no longer wraps to a wrong value, such as 0,
78
+ for databases whose search tree is 4 GiB or larger. It is now computed in
79
+ 64 bits.
80
+ - Fixed a memory leak where an external enumerator from `Reader#each` that
81
+ was not run to the end kept the database mapped or in memory after `close`
82
+ and garbage collection.
83
+ - `require 'maxmind/db/rust'` no longer raises `LoadError` with the precompiled
84
+ gems. The gem now loads the extension from the Ruby version directory that
85
+ those gems use.
86
+ - `require 'maxmind/db/rust'` no longer fails if the application defines a
87
+ top-level `DB`, such as Sequel's usual `DB` constant. It also no longer skips
88
+ defining its own classes if there is a top-level `Reader`.
89
+ - The error raised for an IPv6 address in an IPv4-only database, and for an
90
+ `IPAddr` that claims to be IPv4 but holds a larger address, now builds its
91
+ message the way the `maxmind-db` gem does. An exception or `throw` from the
92
+ argument's `to_s` reaches the caller, and the message keeps the text's
93
+ encoding. Previously such an exception was ignored and the message showed
94
+ `#<IPAddr:0x...>` instead of the address.
95
+
8
96
  ## [0.7.0] - 2026-09-12
9
97
 
10
98
  ### Changed
@@ -229,6 +317,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
229
317
  - MODE_FILE support (use MODE_MMAP instead)
230
318
  - File descriptor support in constructor
231
319
 
320
+ [0.8.0]: https://github.com/oschwald/maxmind-db-rust-ruby/compare/v0.7.0...v0.8.0
232
321
  [0.7.0]: https://github.com/oschwald/maxmind-db-rust-ruby/compare/v0.6.0...v0.7.0
233
322
  [0.6.0]: https://github.com/oschwald/maxmind-db-rust-ruby/compare/v0.5.0...v0.6.0
234
323
  [0.5.0]: https://github.com/oschwald/maxmind-db-rust-ruby/compare/v0.4.0...v0.5.0
data/CONTRIBUTING.md CHANGED
@@ -18,7 +18,7 @@ Thank you for your interest in contributing to maxmind-db-rust! This document pr
18
18
 
19
19
  ### Prerequisites
20
20
 
21
- - Ruby 3.2 or higher
21
+ - Ruby 3.3 or higher
22
22
  - Rust toolchain (stable)
23
23
  - Bundler
24
24
  - Git
@@ -59,11 +59,16 @@ This will enable the pre-commit hook that runs `precious lint` on staged files b
59
59
  bundle exec rake compile
60
60
  ```
61
61
 
62
- This will:
62
+ This runs `build.sh`, which:
63
63
 
64
- 1. Run `extconf.rb` to generate the Makefile
65
- 2. Compile the Rust code using rb-sys
66
- 3. Place the compiled extension in `lib/maxmind/db/`
64
+ 1. Runs `cargo build --release --locked` in `ext/maxmind_db_rust`
65
+ 2. Removes extensions in Ruby version directories, such as
66
+ `lib/maxmind/db/3.4/`, which `rust.rb` would load first
67
+ 3. Copies the compiled extension from the workspace `target/` directory into
68
+ `lib/maxmind/db/`
69
+
70
+ `extconf.rb` is only used when the gem is installed from source and when
71
+ building the native gems in CI.
67
72
 
68
73
  ### Clean Build
69
74
 
@@ -75,17 +80,20 @@ bundle exec rake clean
75
80
  bundle exec rake clobber compile
76
81
  ```
77
82
 
78
- ### Development Build (Debug)
83
+ ### Rust Dependencies
84
+
85
+ The workspace `Cargo.toml` (with the release profile) and `Cargo.lock` at the
86
+ repository root are shipped in the source gem, and builds use `--locked`.
87
+ After changing dependencies in `ext/maxmind_db_rust/Cargo.toml`, run
88
+ `cargo update -p <crate>` (or `cargo build`) and commit the updated lockfile.
79
89
 
80
- The default rake task builds in release mode. For faster compile times during development:
90
+ ### Rust Unit Tests
81
91
 
82
92
  ```bash
83
- # Set environment variable for debug builds
84
- CARGO_PROFILE=dev bundle exec rake compile
93
+ cd ext/maxmind_db_rust
94
+ cargo test --locked
85
95
  ```
86
96
 
87
- Note: Debug builds are significantly slower at runtime but compile faster.
88
-
89
97
  ## Running Tests
90
98
 
91
99
  ### Test Organization
@@ -192,11 +200,20 @@ cargo fmt -- --check
192
200
 
193
201
  ```
194
202
  maxmind-db-rust-ruby/
203
+ ├── Cargo.toml # Cargo workspace and release profile
204
+ ├── Cargo.lock # Locked dependency versions
195
205
  ├── ext/maxmind_db_rust/ # Rust extension code
196
206
  │ ├── Cargo.toml # Rust dependencies
197
- │ ├── extconf.rb # Ruby build configuration
207
+ │ ├── extconf.rb # Build configuration for source installs
198
208
  │ └── src/
199
- │ └── lib.rs # Main Rust implementation
209
+ │ ├── lib.rs # Extension entry point and shared constants
210
+ │ ├── reader.rs # Reader class and lookups
211
+ │ ├── convert.rs # Argument type conversion
212
+ │ ├── decoder.rs # Decoding database values to Ruby objects
213
+ │ ├── gvl.rs # Running Rust work without the GVL
214
+ │ ├── metadata.rs # Metadata class
215
+ │ ├── path.rs # Path lookup support
216
+ │ └── initialization.rs # Ruby module and class setup
200
217
  ├── lib/ # Ruby integration layer
201
218
  │ └── maxmind/
202
219
  │ └── db/
@@ -227,7 +244,7 @@ maxmind-db-rust-ruby/
227
244
  ```
228
245
 
229
246
  2. **Make your changes**:
230
- - Rust code: `ext/maxmind_db_rust/src/lib.rs`
247
+ - Rust code: `ext/maxmind_db_rust/src/`
231
248
  - Ruby wrapper: `lib/maxmind/db/rust.rb`
232
249
  - Tests: Add tests in `test/` directory
233
250
 
@@ -449,6 +466,7 @@ We follow [Semantic Versioning](https://semver.org/):
449
466
  - `arm64-darwin` (macOS Apple Silicon)
450
467
  - `x64-mingw-ucrt` (Windows)
451
468
  - `x86_64-linux-musl` (Alpine Linux)
469
+ - Install and load each native gem on every supported Ruby version
452
470
  - Build a source gem (fallback for unsupported platforms)
453
471
  - Push all gems to RubyGems.org
454
472
 
data/README.md CHANGED
@@ -40,8 +40,8 @@ gem install maxmind-db-rust
40
40
 
41
41
  ## Requirements
42
42
 
43
- - Ruby 3.2 or higher
44
- - Rust toolchain (for building from source)
43
+ - Ruby 3.3 or higher
44
+ - Rust 1.85 or higher (for building from source)
45
45
 
46
46
  ## Usage
47
47
 
@@ -161,6 +161,12 @@ modified or truncated while the reader is alive. To refresh a database, write
161
161
  the replacement to a new file and atomically rename it over the old path. Use
162
162
  `MODE_MEMORY` if the file lifecycle cannot be controlled this way.
163
163
 
164
+ `MODE_MEMORY` reads the file without holding Ruby's global VM lock, so other
165
+ threads keep running while a large database loads. The read cannot be
166
+ interrupted, so a path that never finishes reading, such as a hung network
167
+ mount, blocks the opening thread (and `Timeout` or `Thread#kill` on it) until
168
+ the read returns.
169
+
164
170
  ### Accessing Metadata
165
171
 
166
172
  ```ruby
@@ -224,15 +230,15 @@ Create a new Reader instance.
224
230
 
225
231
  **Parameters:**
226
232
 
227
- - `database` (String): Path to the MaxMind DB file, or database bytes when using `:MODE_PARAM_IS_BUFFER`
228
- - `options` (Hash): Optional configuration
233
+ - `database` (String or Pathname): Path to the MaxMind DB file, or database bytes when using `:MODE_PARAM_IS_BUFFER`. Any object that responds to `to_path` is accepted as a path.
234
+ - `options` (Hash): Optional configuration, passed as keywords or as a positional Hash
229
235
  - `:mode` (Symbol): One of `:MODE_AUTO`, `:MODE_FILE`, `:MODE_MEMORY`, `:MODE_MMAP`, or `:MODE_PARAM_IS_BUFFER`
230
236
 
231
- **Returns:** Reader instance
237
+ **Returns:** Reader instance. `Reader` can be subclassed, and `new` calls the subclass's `initialize`.
232
238
 
233
239
  **Raises:**
234
240
 
235
- - `Errno::ENOENT`: If the database file does not exist
241
+ - `SystemCallError`: If the database file cannot be opened, for example `Errno::ENOENT`, `Errno::EACCES` or `Errno::EISDIR`
236
242
  - `MaxMind::DB::Rust::InvalidDatabaseError`: If the file is not a valid MaxMind DB
237
243
 
238
244
  #### `get(ip_address)`
@@ -241,12 +247,13 @@ Look up an IP address in the database.
241
247
 
242
248
  **Parameters:**
243
249
 
244
- - `ip_address` (String or IPAddr): The IP address to look up
250
+ - `ip_address` (String or IPAddr): The IP address to look up. Strings are parsed like `IPAddr.new`, so CIDR strings such as `"1.2.3.4/32"` and scoped IPv6 addresses such as `"fe80::1%eth0"` are accepted.
245
251
 
246
252
  **Returns:** Hash with the record data, or `nil` if not found
247
253
 
248
254
  **Raises:**
249
255
 
256
+ - `IPAddr::InvalidAddressError`: If the IP address is invalid (a subclass of `ArgumentError`)
250
257
  - `ArgumentError`: If looking up IPv6 in an IPv4-only database
251
258
  - `MaxMind::DB::Rust::InvalidDatabaseError`: If the database is corrupt
252
259
 
@@ -294,7 +301,7 @@ Look up one path for multiple IP addresses.
294
301
 
295
302
  #### `metadata()`
296
303
 
297
- Get metadata about the database.
304
+ Get metadata about the database. Like the official gem, this still works after `close`.
298
305
 
299
306
  **Returns:** `MaxMind::DB::Rust::Metadata` instance
300
307
 
@@ -306,6 +313,11 @@ entire database and may use memory proportional to the number of distinct
306
313
  referenced values, so it is intended for explicit integrity checks rather than
307
314
  the lookup hot path.
308
315
 
316
+ Verification runs without holding Ruby's global VM lock, so other Ruby threads
317
+ keep running while it works. It cannot be cancelled part way through:
318
+ `Thread#raise`, `Timeout`, and signals such as Ctrl-C take effect once
319
+ verification finishes.
320
+
309
321
  **Returns:** `true` when the database passes verification
310
322
 
311
323
  **Raises:** `MaxMind::DB::Rust::InvalidDatabaseError` when verification fails
@@ -326,7 +338,7 @@ Iterate over networks in the database.
326
338
 
327
339
  **Parameters:**
328
340
 
329
- - `network` (String or IPAddr, optional): Network CIDR to iterate within (e.g., "192.168.0.0/16"). If omitted, iterates over all networks in the database.
341
+ - `network` (String or IPAddr, optional): Network CIDR to iterate within (e.g., "192.168.0.0/16"). If omitted or `nil`, iterates over all networks in the database.
330
342
 
331
343
  **Yields:** IPAddr network and Hash data for each entry
332
344
 
@@ -334,7 +346,7 @@ Iterate over networks in the database.
334
346
 
335
347
  **Raises:**
336
348
 
337
- - `ArgumentError`: If network CIDR is invalid or IPv6 network specified for IPv4-only database
349
+ - `ArgumentError`: If network CIDR is invalid, IPv6 network specified for IPv4-only database, or more than one argument is given. These are raised even when no block is given.
338
350
 
339
351
  ### `MaxMind::DB::Rust::Metadata`
340
352
 
@@ -379,6 +391,12 @@ Metadata attributes:
379
391
  | Iterator support | ✗ | ✓ |
380
392
  | Thread-safe | ✓ | ✓ |
381
393
 
394
+ Known differences from the official gem:
395
+
396
+ - Lookups on a closed reader raise `RuntimeError` rather than `IOError`.
397
+ - Unknown options raise `ArgumentError`. The official gem ignores them.
398
+ - Readers cannot be copied with `dup` or `clone`.
399
+
382
400
  ## Performance
383
401
 
384
402
  Lookup performance depends on hardware, Ruby version, database, and workload.
Binary file
Binary file
Binary file
@@ -1,7 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'ipaddr'
4
- require 'maxmind/db/maxmind_db_rust'
4
+ require 'rbconfig'
5
+
6
+ # Precompiled gems store the extension under a Ruby version directory. Source
7
+ # builds do not. Fall back only when the versioned file is absent so that a
8
+ # real load failure of that file is not hidden.
9
+ versioned_extension = File.join(__dir__, RUBY_VERSION[/\d+\.\d+/], 'maxmind_db_rust')
10
+ if File.exist?("#{versioned_extension}.#{RbConfig::CONFIG['DLEXT']}")
11
+ require versioned_extension
12
+ else
13
+ require 'maxmind/db/maxmind_db_rust'
14
+ end
5
15
 
6
16
  module MaxMind
7
17
  # Check if DB is already defined as a Class (official gem)
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: maxmind-db-rust
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.0
5
5
  platform: x86_64-linux
6
6
  authors:
7
7
  - Gregory Oschwald
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-09-12 00:00:00.000000000 Z
11
+ date: 2026-11-25 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bigdecimal
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: minitest
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -162,8 +176,6 @@ files:
162
176
  - CONTRIBUTING.md
163
177
  - LICENSE
164
178
  - README.md
165
- - ext/maxmind_db_rust/lib/maxmind/db/rust.rb
166
- - lib/maxmind/db/3.2/maxmind_db_rust.so
167
179
  - lib/maxmind/db/3.3/maxmind_db_rust.so
168
180
  - lib/maxmind/db/3.4/maxmind_db_rust.so
169
181
  - lib/maxmind/db/4.0/maxmind_db_rust.so
@@ -186,7 +198,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
186
198
  requirements:
187
199
  - - ">="
188
200
  - !ruby/object:Gem::Version
189
- version: '3.2'
201
+ version: '3.3'
190
202
  - - "<"
191
203
  - !ruby/object:Gem::Version
192
204
  version: 4.1.dev
@@ -1,16 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'ipaddr'
4
- require 'maxmind/db/maxmind_db_rust'
5
-
6
- module MaxMind
7
- module DB
8
- module Rust
9
- # The native extension defines:
10
- # - Reader class
11
- # - Metadata class
12
- # - InvalidDatabaseError exception
13
- # - MODE_AUTO, MODE_FILE, MODE_MEMORY, MODE_MMAP, MODE_PARAM_IS_BUFFER constants
14
- end
15
- end
16
- end
Binary file