Skip to content

Commit 06b6adc

Browse files
committed
fix: add stacker and maybe_grow on recursion guard
1 parent a4fa9e0 commit 06b6adc

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ serde = { version = "1.0", features = ["derive"], optional = true }
5252
# https://github.com/rust-lang/cargo/issues/1596
5353
serde_json = { version = "1.0", optional = true }
5454
sqlparser_derive = { version = "0.2.0", path = "derive", optional = true }
55+
stacker = "0.1.17"
5556

5657
[dev-dependencies]
5758
simple_logger = "5.0"

src/parser/mod.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,16 @@ mod recursion {
6565

6666
use super::ParserError;
6767

68+
#[cfg(debug_assertions)]
69+
fn maybe_grow() {
70+
stacker::maybe_grow(512 << 10, 8 << 20, || {});
71+
}
72+
73+
#[cfg(not(debug_assertions))]
74+
fn maybe_grow() {
75+
stacker::maybe_grow(128 << 10, 2 << 20, || {});
76+
}
77+
6878
/// Tracks remaining recursion depth. This value is decremented on
6979
/// each call to [`RecursionCounter::try_decrease()`], when it reaches 0 an error will
7080
/// be returned.
@@ -93,10 +103,12 @@ mod recursion {
93103
/// remaining depth upon drop;
94104
pub fn try_decrease(&self) -> Result<DepthGuard, ParserError> {
95105
let old_value = self.remaining_depth.get();
96-
// ran out of space
106+
97107
if old_value == 0 {
98108
Err(ParserError::RecursionLimitExceeded)
99109
} else {
110+
maybe_grow();
111+
100112
self.remaining_depth.set(old_value - 1);
101113
Ok(DepthGuard::new(Rc::clone(&self.remaining_depth)))
102114
}

0 commit comments

Comments
 (0)