Skip to content

Commit

Permalink
Merge beac30e into 9c06f36
Browse files Browse the repository at this point in the history
  • Loading branch information
Swatinem authored Feb 24, 2023
2 parents 9c06f36 + beac30e commit 6452e44
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 16 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

**Features**:

- Replace internal usage of `LazyCell` by `OnceCell` and make `SourceBundleDebugSession`: `Send`, `Sync` and `AsSelf`. ([#767](https://github.com/getsentry/symbolic/pull/767))

## 12.0.0

**Features**:
Expand Down
8 changes: 4 additions & 4 deletions symbolic-debuginfo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ default = ["breakpad", "elf", "macho", "ms", "ppdb", "sourcebundle", "js", "wasm
# Breakpad text format parsing and processing
breakpad = ["nom", "nom-supreme", "regex"]
# DWARF processing.
dwarf = ["gimli", "lazycell"]
dwarf = ["gimli", "once_cell"]
# ELF reading
elf = [
"dwarf",
Expand Down Expand Up @@ -53,7 +53,7 @@ ms = [
"goblin/pe32",
"goblin/pe64",
"goblin/std",
"lazycell",
"once_cell",
"parking_lot",
"pdb-addr2line",
"scroll",
Expand All @@ -65,7 +65,7 @@ ppdb = [
# Source bundle creation
sourcebundle = [
"lazy_static",
"lazycell",
"once_cell",
"parking_lot",
"regex",
"serde_json",
Expand Down Expand Up @@ -94,7 +94,7 @@ gimli = { version = "0.27.0", optional = true, default-features = false, feature
] }
goblin = { version = "0.6.0", optional = true, default-features = false }
lazy_static = { version = "1.4.0", optional = true }
lazycell = { version = "1.2.1", optional = true }
once_cell = { version = "1.17.1", optional = true }
nom = { version = "7.0.0", optional = true }
nom-supreme = { version = "0.8.0", optional = true }
parking_lot = { version = "0.12.0", optional = true }
Expand Down
8 changes: 4 additions & 4 deletions symbolic-debuginfo/src/dwarf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use std::sync::Arc;
use fallible_iterator::FallibleIterator;
use gimli::read::{AttributeValue, Error as GimliError, Range};
use gimli::{constants, DwarfFileType, UnitSectionOffset};
use lazycell::LazyCell;
use once_cell::sync::OnceCell;
use thiserror::Error;

use symbolic_common::{AsSelf, Language, Name, NameMangling, SelfCell};
Expand Down Expand Up @@ -1109,7 +1109,7 @@ impl<'data> DwarfSections<'data> {
struct DwarfInfo<'data> {
inner: DwarfInner<'data>,
headers: Vec<UnitHeader<'data>>,
units: Vec<LazyCell<Option<Unit<'data>>>>,
units: Vec<OnceCell<Option<Unit<'data>>>>,
symbol_map: SymbolMap<'data>,
address_offset: i64,
kind: ObjectKind,
Expand Down Expand Up @@ -1153,7 +1153,7 @@ impl<'d> DwarfInfo<'d> {

// Prepare random access to unit headers.
let headers = inner.units().collect::<Vec<_>>()?;
let units = headers.iter().map(|_| LazyCell::new()).collect();
let units = headers.iter().map(|_| OnceCell::new()).collect();

Ok(DwarfInfo {
inner,
Expand All @@ -1173,7 +1173,7 @@ impl<'d> DwarfInfo<'d> {
None => return Ok(None),
};

let unit_opt = cell.try_borrow_with(|| {
let unit_opt = cell.get_or_try_init(|| {
// Parse the compilation unit from the header. This requires a top-level DIE that
// describes the unit itself. For some older DWARF files, this DIE might be missing
// which causes gimli to error out. We prefer to skip them silently as this simply marks
Expand Down
8 changes: 4 additions & 4 deletions symbolic-debuginfo/src/ppdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::collections::HashMap;
use std::fmt;
use std::iter;

use lazycell::LazyCell;
use once_cell::sync::OnceCell;
use symbolic_common::{Arch, CodeId, DebugId};
use symbolic_ppdb::EmbeddedSource;
use symbolic_ppdb::{Document, FormatError, PortablePdb};
Expand Down Expand Up @@ -143,7 +143,7 @@ impl fmt::Debug for PortablePdbObject<'_> {
/// A debug session for a Portable PDB object.
pub struct PortablePdbDebugSession<'data> {
ppdb: PortablePdb<'data>,
sources: LazyCell<HashMap<String, PPDBSource<'data>>>,
sources: OnceCell<HashMap<String, PPDBSource<'data>>>,
}

#[derive(Debug, Clone)]
Expand All @@ -156,7 +156,7 @@ impl<'data> PortablePdbDebugSession<'data> {
fn new(ppdb: &'_ PortablePdb<'data>) -> Result<Self, FormatError> {
Ok(PortablePdbDebugSession {
ppdb: ppdb.clone(),
sources: LazyCell::new(),
sources: OnceCell::new(),
})
}

Expand Down Expand Up @@ -196,7 +196,7 @@ impl<'data> PortablePdbDebugSession<'data> {
&self,
path: &str,
) -> Result<Option<SourceFileDescriptor<'_>>, FormatError> {
let sources = self.sources.borrow_with(|| self.init_sources());
let sources = self.sources.get_or_init(|| self.init_sources());
match sources.get(path) {
None => Ok(None),
Some(PPDBSource::Embedded(source)) => source.get_contents().map(|bytes| {
Expand Down
22 changes: 18 additions & 4 deletions symbolic-debuginfo/src/sourcebundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ use std::io::{BufReader, BufWriter, Read, Seek, Write};
use std::path::Path;
use std::sync::Arc;

use lazycell::LazyCell;
use once_cell::sync::OnceCell;
use parking_lot::Mutex;
use regex::Regex;
use serde::{Deserialize, Deserializer, Serialize};
Expand Down Expand Up @@ -676,7 +676,7 @@ impl<'data> SourceBundle<'data> {
Ok(SourceBundleDebugSession {
manifest: self.manifest.clone(),
archive: self.archive.clone(),
indexed_files: LazyCell::new(),
indexed_files: OnceCell::new(),
})
}

Expand Down Expand Up @@ -802,7 +802,7 @@ enum FileKey<'a> {
pub struct SourceBundleDebugSession<'data> {
manifest: Arc<SourceBundleManifest>,
archive: Arc<Mutex<zip::read::ZipArchive<std::io::Cursor<&'data [u8]>>>>,
indexed_files: LazyCell<HashMap<FileKey<'data>, Arc<String>>>,
indexed_files: OnceCell<HashMap<FileKey<'data>, Arc<String>>>,
}

impl<'data> SourceBundleDebugSession<'data> {
Expand All @@ -820,7 +820,7 @@ impl<'data> SourceBundleDebugSession<'data> {

/// Get the indexed file mapping.
fn indexed_files(&self) -> &HashMap<FileKey, Arc<String>> {
self.indexed_files.borrow_with(|| {
self.indexed_files.get_or_init(|| {
let files = &self.manifest.files;
let mut rv = HashMap::with_capacity(files.len());

Expand Down Expand Up @@ -928,6 +928,14 @@ impl<'data, 'session> DebugSession<'session> for SourceBundleDebugSession<'data>
}
}

impl<'slf, 'data: 'slf> AsSelf<'slf> for SourceBundleDebugSession<'data> {
type Ref = SourceBundleDebugSession<'slf>;

fn as_self(&'slf self) -> &Self::Ref {
unsafe { std::mem::transmute(self) }
}
}

/// An iterator over source files in a SourceBundle object.
pub struct SourceBundleFileIterator<'s> {
files: std::collections::btree_map::Values<'s, String, SourceFileInfo>,
Expand Down Expand Up @@ -1362,6 +1370,12 @@ mod tests {
Ok(())
}

#[test]
fn debugsession_is_sendsync() {
fn is_sendsync<T: Send + Sync>() {}
is_sendsync::<SourceBundleDebugSession>();
}

#[test]
fn test_source_descriptor() -> Result<(), SourceBundleError> {
let mut writer = Cursor::new(Vec::new());
Expand Down

0 comments on commit 6452e44

Please sign in to comment.