Skip to content

Commit f69f3a5

Browse files
committed
Allow PDB to impl Send.
1 parent b052964 commit f69f3a5

File tree

3 files changed

+35
-10
lines changed

3 files changed

+35
-10
lines changed

src/msf/mod.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,14 @@ enum StreamTable<'s> {
5555

5656
// Given the table location, we can access the stream table itself
5757
Available {
58-
stream_table_view: Box<dyn SourceView<'s>>,
58+
stream_table_view: Box<dyn SourceView<'s> + Send>,
5959
},
6060
}
6161

62-
fn view<'s>(source: &mut dyn Source<'s>, page_list: &PageList) -> Result<Box<dyn SourceView<'s>>> {
62+
fn view<'s>(
63+
source: &mut dyn Source<'s>,
64+
page_list: &PageList,
65+
) -> Result<Box<dyn SourceView<'s> + Send + Sync>> {
6366
// view it
6467
let view = source.view(page_list.source_slices())?;
6568

@@ -120,7 +123,10 @@ mod big {
120123
}
121124

122125
impl<'s, S: Source<'s>> BigMSF<'s, S> {
123-
pub fn new(source: S, header_view: Box<dyn SourceView<'_>>) -> Result<BigMSF<'s, S>> {
126+
pub fn new(
127+
source: S,
128+
header_view: Box<dyn SourceView<'_> + Send>,
129+
) -> Result<BigMSF<'s, S>> {
124130
let mut buf = ParseBuffer::from(header_view.as_slice());
125131
let header: RawHeader = buf.parse()?;
126132

@@ -316,7 +322,7 @@ mod big {
316322
}
317323
}
318324

319-
impl<'s, S: Source<'s>> Msf<'s, S> for BigMSF<'s, S> {
325+
impl<'s, S: Source<'s> + Send> Msf<'s, S> for BigMSF<'s, S> {
320326
fn get(&mut self, stream_number: u32, limit: Option<usize>) -> Result<Stream<'s>> {
321327
// look up the stream
322328
let mut page_list = self.look_up_stream(stream_number)?;
@@ -345,7 +351,7 @@ mod small {
345351
/// Represents a single Stream within the multi-stream file.
346352
#[derive(Debug)]
347353
pub struct Stream<'s> {
348-
source_view: Box<dyn SourceView<'s>>,
354+
source_view: Box<dyn SourceView<'s> + Send + Sync>,
349355
}
350356

351357
impl<'s> Stream<'s> {
@@ -380,7 +386,9 @@ fn header_matches(actual: &[u8], expected: &[u8]) -> bool {
380386
actual.len() >= expected.len() && &actual[0..expected.len()] == expected
381387
}
382388

383-
pub fn open_msf<'s, S: Source<'s> + 's>(mut source: S) -> Result<Box<dyn Msf<'s, S> + 's>> {
389+
pub fn open_msf<'s, S: Source<'s> + Send + 's>(
390+
mut source: S,
391+
) -> Result<Box<dyn Msf<'s, S> + Send + 's>> {
384392
// map the header
385393
let mut header_location = PageList::new(4096);
386394
header_location.push(0);

src/pdb.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const IPI_STREAM: u32 = 4;
3434
#[derive(Debug)]
3535
pub struct PDB<'s, S> {
3636
/// `msf` provides access to the underlying data streams
37-
msf: Box<dyn Msf<'s, S> + 's>,
37+
msf: Box<dyn Msf<'s, S> + Send + 's>,
3838

3939
/// Memoize the `dbi::Header`, since it contains stream numbers we sometimes need
4040
dbi_header: Option<DBIHeader>,
@@ -43,6 +43,14 @@ pub struct PDB<'s, S> {
4343
dbi_extra_streams: Option<DBIExtraStreams>,
4444
}
4545

46+
// Assert that the PDB type is Send.
47+
const _: fn() = || {
48+
fn assert<T: ?Sized + Send>() {}
49+
// Use a dummy *const () for `S` as that will be !Send and !Sync.
50+
// In practice (e.g. to make a PDB) `S` will need to be Send, but it doesn't matter here.
51+
assert::<PDB<*const ()>>();
52+
};
53+
4654
impl<'s, S: Source<'s> + 's> PDB<'s, S> {
4755
/// Create a new `PDB` for a `Source`.
4856
///
@@ -56,7 +64,10 @@ impl<'s, S: Source<'s> + 's> PDB<'s, S> {
5664
/// * `Error::UnrecognizedFileFormat` if the `Source` does not appear to be a PDB file
5765
/// * `Error::IoError` if returned by the `Source`
5866
/// * `Error::PageReferenceOutOfRange`, `Error::InvalidPageSize` if the PDB file seems corrupt
59-
pub fn open(source: S) -> Result<PDB<'s, S>> {
67+
pub fn open(source: S) -> Result<PDB<'s, S>>
68+
where
69+
S: Send,
70+
{
6071
Ok(PDB {
6172
msf: msf::open_msf(source)?,
6273
dbi_header: None,

src/source.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ pub trait Source<'s>: fmt::Debug {
5151
///
5252
/// Note that the SourceView's as_slice() method cannot fail, so `view()` is the time to raise
5353
/// IO errors.
54-
fn view(&mut self, slices: &[SourceSlice]) -> Result<Box<dyn SourceView<'s>>, io::Error>;
54+
fn view(
55+
&mut self,
56+
slices: &[SourceSlice],
57+
) -> Result<Box<dyn SourceView<'s> + Send + Sync>, io::Error>;
5558
}
5659

5760
/// An owned, droppable, read-only view of the source file which can be referenced as a byte slice.
@@ -81,7 +84,10 @@ impl<'s, T> Source<'s> for T
8184
where
8285
T: io::Read + io::Seek + fmt::Debug + 's,
8386
{
84-
fn view(&mut self, slices: &[SourceSlice]) -> Result<Box<dyn SourceView<'s>>, io::Error> {
87+
fn view(
88+
&mut self,
89+
slices: &[SourceSlice],
90+
) -> Result<Box<dyn SourceView<'s> + Send + Sync>, io::Error> {
8591
let len = slices.iter().fold(0, |acc, s| acc + s.size);
8692

8793
let mut v = ReadView {

0 commit comments

Comments
 (0)