Skip to content

Commit

Permalink
Delete alloc feature
Browse files Browse the repository at this point in the history
gimli can't do anything useful without allocating, and the alloc crate
is now stable, so having a separate alloc feature is not required.
Instead, you should simply disable all features.

Also fix `cargo test` with features disabled.
  • Loading branch information
philipc committed Dec 9, 2019
1 parent ac13c19 commit 4da9dc4
Show file tree
Hide file tree
Showing 37 changed files with 195 additions and 208 deletions.
18 changes: 5 additions & 13 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@ script: ./ci/script.sh

env:
matrix:
- GIMLI_JOB="test" GIMLI_PROFILE=
- GIMLI_JOB="build" GIMLI_PROFILE="--no-default-features --features read,std"
- GIMLI_JOB="build" GIMLI_PROFILE="--no-default-features --features write"
- GIMLI_JOB="test"
- GIMLI_JOB="features"

matrix:
fast_finish: true
Expand All @@ -42,32 +41,25 @@ matrix:
- rust: nightly
os: linux
sudo: required
env: GIMLI_JOB="coverage" GIMLI_PROFILE=
env: GIMLI_JOB="coverage"
# Building docs only needs to happen on one os and only on stable.
- rust: stable
os: linux
env: GIMLI_JOB="doc" GIMLI_PROFILE=
env: GIMLI_JOB="doc"
# Benching should only happen on nightly.
- rust: nightly
env: GIMLI_JOB="bench" GIMLI_PROFILE=
# The no-std/alloc build should only happen on nightly.
- rust: nightly
env: GIMLI_JOB="alloc" GIMLI_PROFILE=
env: GIMLI_JOB="bench"
# Build a 32 bit target.
- rust: stable
sudo: required
services: docker
env:
- TARGET=i686-unknown-linux-gnu
- GIMLI_JOB=cross
- GIMLI_PROFILE=
# Build a big-endian target.
- rust: stable
sudo: required
services: docker
env:
- TARGET=powerpc64-unknown-linux-gnu
- GIMLI_JOB=cross
- GIMLI_PROFILE=
allow_failures:
- env: GIMLI_JOB="alloc" GIMLI_PROFILE=
17 changes: 14 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ byteorder = { version = "1.0", default-features = false }
fallible-iterator = { version = "0.2.0", default-features = false }
indexmap = { version = "1.0.2", optional = true }
smallvec = { version = "0.6.10", default-features = false }
stable_deref_trait = { version = "1.1.0", default-features = false }
stable_deref_trait = { version = "1.1.0", default-features = false, optional = true }

[dev-dependencies]
crossbeam = "0.7.1"
Expand All @@ -37,12 +37,23 @@ typed-arena = "1"
target-lexicon = "0.8"

[features]
read = []
read = ["stable_deref_trait"]
write = ["std", "indexmap"]
std = ["fallible-iterator/std", "stable_deref_trait/std"]
alloc = ["fallible-iterator/alloc", "stable_deref_trait/alloc"]
default = ["read", "write", "std"]

[profile.bench]
debug = true
codegen-units = 1

[[example]]
name = "simple"
required-features = ["read"]

[[example]]
name = "dwarfdump"
required-features = ["read", "std"]

[[example]]
name = "dwarf-validate"
required-features = ["read", "std"]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Add this to your `Cargo.toml`:
gimli = "0.19.0"
```

The minimum supported Rust version is 1.32.0.
The minimum supported Rust version is 1.36.0.

## Documentation

Expand Down
28 changes: 12 additions & 16 deletions ci/script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,11 @@
set -ex

case "$GIMLI_JOB" in
"build")
cargo build $GIMLI_PROFILE
cargo build --release $GIMLI_PROFILE
;;

"test")
cargo build $GIMLI_PROFILE
cargo test $GIMLI_PROFILE
cargo build --release $GIMLI_PROFILE
cargo test --release $GIMLI_PROFILE
cargo build
cargo test
cargo build --release
cargo test --release
case "$TRAVIS_OS_NAME" in
"osx")
with_debug_info=$(find ./target/debug -type f | grep DWARF | grep gimli | head -n 1)
Expand All @@ -28,14 +23,15 @@ case "$GIMLI_JOB" in
cargo run --release --example dwarfdump -- "$with_debug_info" > /dev/null
;;

"doc")
cargo doc
"features")
cargo test --no-default-features
cargo test --no-default-features --features read
cargo test --no-default-features --features read,std
cargo test --no-default-features --features write
;;

"alloc")
test "$TRAVIS_RUST_VERSION" == "nightly"
cargo build --no-default-features --features read,alloc $GIMLI_PROFILE
cargo build --release --no-default-features --features read,alloc $GIMLI_PROFILE
"doc")
cargo doc
;;

"bench")
Expand All @@ -50,7 +46,7 @@ case "$GIMLI_JOB" in
"cross")
rustup target add $TARGET
cargo install cross --force
cross test --target $TARGET $GIMLI_PROFILE
cross test --target $TARGET
;;

*)
Expand Down
2 changes: 1 addition & 1 deletion src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#![allow(non_upper_case_globals)]
#![allow(missing_docs)]

use std::fmt;
use core::fmt;

// The `dw!` macro turns this:
//
Expand Down
2 changes: 1 addition & 1 deletion src/endianity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use byteorder;
use byteorder::ByteOrder;
use std::fmt::Debug;
use core::fmt::Debug;

/// A trait describing the endianity of some buffer.
pub trait Endianity: Debug + Default + Clone + Copy + PartialEq + Eq {
Expand Down
19 changes: 10 additions & 9 deletions src/leb128.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//! Read and write signed integers:
//!
//! ```
//! # #[cfg(all(feature = "read", feature = "write"))] {
//! use gimli::{EndianSlice, NativeEndian, leb128};
//!
//! let mut buf = [0; 1024];
Expand All @@ -21,11 +22,13 @@
//! let mut readable = EndianSlice::new(&buf[..], NativeEndian);
//! let val = leb128::read::signed(&mut readable).expect("Should read number");
//! assert_eq!(val, -12345);
//! # }
//! ```
//!
//! Or read and write unsigned integers:
//!
//! ```
//! # #[cfg(all(feature = "read", feature = "write"))] {
//! use gimli::{EndianSlice, NativeEndian, leb128};
//!
//! let mut buf = [0; 1024];
Expand All @@ -38,10 +41,9 @@
//! let mut readable = EndianSlice::new(&buf[..], NativeEndian);
//! let val = leb128::read::unsigned(&mut readable).expect("Should read number");
//! assert_eq!(val, 98765);
//! # }
//! ```
use std;

const CONTINUATION_BIT: u8 = 1 << 7;
const SIGN_BIT: u8 = 1 << 6;

Expand All @@ -53,7 +55,7 @@ fn low_bits_of_byte(byte: u8) -> u8 {
#[inline]
#[allow(dead_code)]
fn low_bits_of_u64(val: u64) -> u8 {
let byte = val & u64::from(std::u8::MAX);
let byte = val & u64::from(core::u8::MAX);
low_bits_of_byte(byte as u8)
}

Expand Down Expand Up @@ -208,12 +210,11 @@ pub mod write {
}

#[cfg(test)]
#[cfg(all(feature = "read", feature = "write"))]
mod tests {
use super::{low_bits_of_byte, low_bits_of_u64, read, write, CONTINUATION_BIT};
use crate::endianity::NativeEndian;
use crate::read::{EndianSlice, Error, ReaderOffsetId};
use std;
use std::io;

trait ResultExt {
fn map_eof(self, input: &[u8]) -> Self;
Expand Down Expand Up @@ -395,7 +396,7 @@ mod tests {
let mut buf = [0; 1];
let mut writable = &mut buf[..];
match write::unsigned(&mut writable, 128) {
Err(e) => assert_eq!(e.kind(), io::ErrorKind::WriteZero),
Err(e) => assert_eq!(e.kind(), std::io::ErrorKind::WriteZero),
otherwise => panic!("Unexpected: {:?}", otherwise),
}
}
Expand All @@ -405,7 +406,7 @@ mod tests {
let mut buf = [0; 1];
let mut writable = &mut buf[..];
match write::signed(&mut writable, 128) {
Err(e) => assert_eq!(e.kind(), io::ErrorKind::WriteZero),
Err(e) => assert_eq!(e.kind(), std::io::ErrorKind::WriteZero),
otherwise => panic!("Unexpected: {:?}", otherwise),
}
}
Expand All @@ -427,7 +428,7 @@ mod tests {
for i in -513..513 {
inner(i);
}
inner(std::i64::MIN);
inner(core::i64::MIN);
}

#[test]
Expand Down Expand Up @@ -568,7 +569,7 @@ mod tests {
.iter()
{
let mut readable = EndianSlice::new(buf, NativeEndian);
assert!(read::u16(&mut readable).is_err(), format!("{:?}", buf));
assert!(read::u16(&mut readable).is_err(), "{:?}", buf);
}
}
}
46 changes: 7 additions & 39 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,10 @@
//! * `std`: Enabled by default. Use the `std` library. Disabling this feature
//! allows using `gimli` in embedded environments that do not have access to
//! `std`. Note that even when `std` is disabled, `gimli` still requires an
//! implementation of the `alloc` crate, and you must enable the `nightly`
//! feature.
//! implementation of the `alloc` crate.
//!
//! * `alloc`: Nightly only. Enables usage of the unstable, nightly-only
//! `#![feature(alloc)]` Rust feature that allows `gimli` to use boxes and
//! collection types in a `#[no_std]` environment.
//!
//! * `read`: Enabled by default. Enables the `read` module. Requires
//! either `alloc` or `std` to also be enabled.
//! * `read`: Enabled by default. Enables the `read` module. Use of `std` is
//! optional.
//!
//! * `write`: Enabled by default. Enables the `write` module. Automatically
//! enables `std` too.
Expand All @@ -40,43 +35,16 @@
// False positives when block expressions are used inside an assertion.
#![allow(clippy::panic_params)]
#![no_std]
#![cfg_attr(feature = "alloc", feature(alloc))]

#[cfg(feature = "std")]
#[macro_use]
extern crate std;

#[cfg(not(feature = "std"))]
#[allow(unused_imports)]
#[macro_use]
extern crate alloc;
#[cfg(not(feature = "std"))]
#[macro_use]
extern crate core as std;

#[cfg(feature = "std")]
mod imports {
pub use std::borrow;
pub use std::boxed;
pub use std::collections;
pub use std::rc;
pub use std::string;
pub use std::sync::Arc;
pub use std::vec;
}

#[cfg(not(feature = "std"))]
mod imports {
pub use alloc::borrow;
pub use alloc::boxed;
pub use alloc::collections;
pub use alloc::rc;
pub use alloc::string;
pub use alloc::sync::Arc;
pub use alloc::vec;
}

use crate::imports::*;
#[macro_use]
extern crate std;

#[cfg(feature = "read")]
pub use stable_deref_trait::{CloneStableDeref, StableDeref};

mod common;
Expand Down
10 changes: 5 additions & 5 deletions src/read/abbrev.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Functions for parsing DWARF debugging abbreviations.
use crate::collections::btree_map;
use crate::vec::Vec;
use alloc::collections::btree_map;
use alloc::vec::Vec;
use smallvec::SmallVec;

use crate::common::{DebugAbbrevOffset, SectionId};
Expand Down Expand Up @@ -122,7 +122,7 @@ impl Abbreviations {
/// Returns `Ok` if it is the first abbreviation in the set with its code,
/// `Err` if the code is a duplicate and there already exists an
/// abbreviation in the set with the given abbreviation's code.
fn insert(&mut self, abbrev: Abbreviation) -> ::std::result::Result<(), ()> {
fn insert(&mut self, abbrev: Abbreviation) -> ::core::result::Result<(), ()> {
let code_usize = abbrev.code as usize;
if code_usize as u64 == abbrev.code {
// Optimize for sequential abbreviation codes by storing them
Expand Down Expand Up @@ -418,9 +418,9 @@ pub mod tests {
use crate::endianity::LittleEndian;
use crate::read::{EndianSlice, Error};
use crate::test_util::GimliSectionMethods;
use smallvec::smallvec;
#[cfg(target_pointer_width = "32")]
use std::u32;
use core::u32;
use smallvec::smallvec;
use test_assembler::Section;

pub trait AbbrevSectionMethods {
Expand Down
6 changes: 3 additions & 3 deletions src/read/aranges.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use core::cmp::Ordering;
use core::marker::PhantomData;
use fallible_iterator::FallibleIterator;
use std::cmp::Ordering;
use std::marker::PhantomData;

use crate::common::{DebugInfoOffset, Encoding, SectionId};
use crate::endianity::Endianity;
Expand Down Expand Up @@ -250,7 +250,7 @@ impl<R: Reader> FallibleIterator for ArangeEntryIter<R> {
type Item = ArangeEntry<R::Offset>;
type Error = Error;

fn next(&mut self) -> ::std::result::Result<Option<Self::Item>, Self::Error> {
fn next(&mut self) -> ::core::result::Result<Option<Self::Item>, Self::Error> {
self.0.next()
}
}
Expand Down
Loading

0 comments on commit 4da9dc4

Please sign in to comment.