Skip to content

Commit d8e22dd

Browse files
committed
syntax: tweak the "no stack overflow" test
This test works by spinning up a thread with an atypically small stack size, parsing a regex into an Ast and then dropping it. We use a small stack size such that *if the Ast didn't have a custom Drop impl*, then its default recursive Drop impl would overflow the stack. (If we don't use a smaller stack size, then the default on some platforms is usually quite large and might require a much larger Ast to provoke a failure.) It turns out that the stack size we were using was quite tiny, and too tiny for some platforms such as FreeBSD. We therefore increase it a little bit, but not too much. We do the same for the corresponding test for the custom Drop impl for Hir. Fixes #967
1 parent a9b2e02 commit d8e22dd

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

regex-syntax/src/ast/mod.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -1492,8 +1492,19 @@ mod tests {
14921492

14931493
// We run our test on a thread with a small stack size so we can
14941494
// force the issue more easily.
1495+
//
1496+
// NOTE(2023-03-21): It turns out that some platforms (like FreeBSD)
1497+
// will just barf with very small stack sizes. So we bump this up a bit
1498+
// to give more room to breath. When I did this, I confirmed that if
1499+
// I remove the custom `Drop` impl for `Ast`, then this test does
1500+
// indeed still fail with a stack overflow. (At the time of writing, I
1501+
// had to bump it all the way up to 32K before the test would pass even
1502+
// without the custom `Drop` impl. So 16K seems like a safe number
1503+
// here.)
1504+
//
1505+
// See: https://github.com/rust-lang/regex/issues/967
14951506
thread::Builder::new()
1496-
.stack_size(1 << 10)
1507+
.stack_size(16 << 10)
14971508
.spawn(run)
14981509
.unwrap()
14991510
.join()

regex-syntax/src/hir/mod.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -2286,8 +2286,11 @@ mod tests {
22862286

22872287
// We run our test on a thread with a small stack size so we can
22882288
// force the issue more easily.
2289+
//
2290+
// NOTE(2023-03-21): See the corresponding test in 'crate::ast::tests'
2291+
// for context on the specific stack size chosen here.
22892292
thread::Builder::new()
2290-
.stack_size(1 << 10)
2293+
.stack_size(16 << 10)
22912294
.spawn(run)
22922295
.unwrap()
22932296
.join()

0 commit comments

Comments
 (0)