Skip to content

Commit 3bae966

Browse files
committed
regex_macros: Fix valgrind errors
While speedier to not perform initialization, these calls to mem::init() are causing valgrind errors when using compiled macros. Closes rust-lang#13969
1 parent cba66bc commit 3bae966

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

src/libregex_macros/lib.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -247,15 +247,11 @@ fn exec<'t>(which: ::regex::native::MatchKind, input: &'t str,
247247
fn new(which: MatchKind) -> Threads {
248248
Threads {
249249
which: which,
250-
// These unsafe blocks are used for performance reasons, as it
251-
// gives us a zero-cost initialization of a sparse set. The
252-
// trick is described in more detail here:
253-
// http://research.swtch.com/sparse
254-
// The idea here is to avoid initializing threads that never
255-
// need to be initialized, particularly for larger regexs with
256-
// a lot of instructions.
257-
queue: unsafe { ::std::mem::uninit() },
258-
sparse: unsafe { ::std::mem::uninit() },
250+
queue: [Thread {
251+
pc: 0,
252+
captures: [None, ..$num_cap_locs];
253+
}, ..$num_insts],
254+
sparse: [0, ..$num_insts],
259255
size: 0,
260256
}
261257
}

0 commit comments

Comments
 (0)