Skip to content

Commit

Permalink
api: make Regex UnwindSafe again
Browse files Browse the repository at this point in the history
This commit fixes a regression introduced in 1.1.3 where Regex was no
longer UnwindSafe. The underlying reason is that the new AhoCorasick
type in aho-corasick 0.7 was not UnwindSafe. This has been fixed in
aho-corasick 0.7.4, so all we need to do to fix it is to increase the
minimum aho-corasick version, which we do here.

We also add an oibits test that ensures this particular regression can't
happen again. (Along with testing Send and Sync, which surprisingly did
not have seem to have tests before this.)

Fixes #568
  • Loading branch information
BurntSushi committed Mar 31, 2019
1 parent 89074f8 commit c706552
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
13 changes: 13 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,16 @@
1.1.4 (2019-03-31)
==================
This release fixes a backwards compatibility regression where Regex was no
longer UnwindSafe. This was caused by the upgrade to aho-corasick 0.7, whose
AhoCorasick type was itself not UnwindSafe. This has been fixed in aho-corasick
0.7.4, which we now require.

Bug fixes:

* [BUG #568](https://github.com/rust-lang/regex/pull/568):
Fix an API regression where Regex was no longer UnwindSafe.


1.1.3 (2019-03-30)
==================
This releases fixes a few bugs and adds a performance improvement when a regex
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Expand Up @@ -26,7 +26,7 @@ members = [

[dependencies]
# For very fast prefix literal matching.
aho-corasick = "0.7.1"
aho-corasick = "0.7.3"
# For skipping along search text quickly when a leading byte is known.
memchr = "2.0.2"
# For managing regex caches quickly across multiple threads.
Expand Down
34 changes: 34 additions & 0 deletions tests/test_default.rs
Expand Up @@ -85,3 +85,37 @@ fn disallow_octal() {
fn allow_octal() {
assert!(regex::RegexBuilder::new(r"\0").octal(true).build().is_ok());
}

#[test]
fn oibits() {
use std::panic::UnwindSafe;
use regex::{Regex, RegexBuilder};
use regex::bytes;

fn assert_send<T: Send>() {}
fn assert_sync<T: Sync>() {}
fn assert_unwind_safe<T: UnwindSafe>() {}

assert_send::<Regex>();
assert_sync::<Regex>();
assert_unwind_safe::<Regex>();
assert_send::<RegexBuilder>();
assert_sync::<RegexBuilder>();
assert_unwind_safe::<RegexBuilder>();

assert_send::<bytes::Regex>();
assert_sync::<bytes::Regex>();
assert_unwind_safe::<bytes::Regex>();
assert_send::<bytes::RegexBuilder>();
assert_sync::<bytes::RegexBuilder>();
assert_unwind_safe::<bytes::RegexBuilder>();
}

// See: https://github.com/rust-lang/regex/issues/568
#[test]
fn oibits_regression() {
use std::panic;
use regex::Regex;

let _ = panic::catch_unwind(|| Regex::new("a").unwrap());
}

0 comments on commit c706552

Please sign in to comment.