Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

revert libc removal #340

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion ethbloom/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ The format is based on [Keep a Changelog].
[Keep a Changelog]: http://keepachangelog.com/en/1.0.0/

## [Unreleased]
- Removed `libc` feature. [#317](https://github.com/paritytech/parity-common/pull/317)

## [0.8.1] - 2019-10-24
### Dependencies
Expand Down
3 changes: 2 additions & 1 deletion ethbloom/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ rand = "0.7.2"
hex-literal = "0.2.1"

[features]
default = ["std", "serialize", "rustc-hex"]
default = ["std", "serialize", "libc", "rustc-hex"]
std = ["fixed-hash/std", "crunchy/std"]
serialize = ["std", "impl-serde"]
libc = ["fixed-hash/libc"]
rustc-hex = ["fixed-hash/rustc-hex"]

[[bench]]
Expand Down
1 change: 0 additions & 1 deletion fixed-hash/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ The format is based on [Keep a Changelog].
[Keep a Changelog]: http://keepachangelog.com/en/1.0.0/

## [Unreleased]
- Removed `libc` feature. [#317](https://github.com/paritytech/parity-common/pull/317)

## [0.5.2] - 2019-12-19
### Fixed
Expand Down
7 changes: 5 additions & 2 deletions fixed-hash/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@ static_assertions = "1.0.0"

[dev-dependencies]
rand_xorshift = "0.2.0"
criterion = "0.3.0"
criterion = "0.3.1"

[target.'cfg(not(target_os = "unknown"))'.dependencies]
libc = { version = "0.2.65", optional = true, default-features = false }

[features]
default = ["std", "rand", "rustc-hex", "byteorder"]
default = ["std", "libc", "rand", "rustc-hex", "byteorder"]
std = ["rustc-hex/std", "rand/std", "byteorder/std"]

api-dummy = [] # Feature used by docs.rs to display documentation of hash types
Expand Down
58 changes: 56 additions & 2 deletions fixed-hash/src/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ macro_rules! construct_fixed_hash {

impl_byteorder_for_fixed_hash!($name);
impl_rand_for_fixed_hash!($name);
impl_cmp_for_fixed_hash!($name);
impl_libc_for_fixed_hash!($name);
impl_rustc_hex_for_fixed_hash!($name);
impl_quickcheck_for_fixed_hash!($name);
}
Expand Down Expand Up @@ -527,9 +527,17 @@ macro_rules! impl_rand_for_fixed_hash {
};
}

// Implementation for disabled libc crate support.
//
// # Note
//
// Feature guarded macro definitions instead of feature guarded impl blocks
// to work around the problems of introducing `libc` crate feature in
// a user crate.
#[cfg(not(all(feature = "libc", not(target_os = "unknown"))))]
#[macro_export]
#[doc(hidden)]
macro_rules! impl_cmp_for_fixed_hash {
macro_rules! impl_libc_for_fixed_hash {
( $name:ident ) => {
impl $crate::core_::cmp::PartialEq for $name {
#[inline]
Expand All @@ -547,6 +555,52 @@ macro_rules! impl_cmp_for_fixed_hash {
};
}

// Implementation for enabled libc crate support.
//
// # Note
//
// Feature guarded macro definitions instead of feature guarded impl blocks
// to work around the problems of introducing `libc` crate feature in
// a user crate.
#[cfg(all(feature = "libc", not(target_os = "unknown")))]
#[macro_export]
#[doc(hidden)]
macro_rules! impl_libc_for_fixed_hash {
( $name:ident ) => {
impl $crate::core_::cmp::PartialEq for $name {
#[inline]
fn eq(&self, other: &Self) -> bool {
unsafe {
$crate::libc::memcmp(
self.as_ptr() as *const $crate::libc::c_void,
other.as_ptr() as *const $crate::libc::c_void,
Self::len_bytes(),
) == 0
}
}
}

impl $crate::core_::cmp::Ord for $name {
fn cmp(&self, other: &Self) -> $crate::core_::cmp::Ordering {
let r = unsafe {
$crate::libc::memcmp(
self.as_ptr() as *const $crate::libc::c_void,
other.as_ptr() as *const $crate::libc::c_void,
Self::len_bytes(),
)
};
if r < 0 {
return $crate::core_::cmp::Ordering::Less;
}
if r > 0 {
return $crate::core_::cmp::Ordering::Greater;
}
$crate::core_::cmp::Ordering::Equal
}
}
};
}

// Implementation for disabled rustc-hex crate support.
//
// # Note
Expand Down
8 changes: 8 additions & 0 deletions fixed-hash/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ pub extern crate alloc as alloc_;
#[doc(hidden)]
pub use core as core_;

#[cfg(all(feature = "libc", not(target_os = "unknown")))]
#[doc(hidden)]
pub use libc;

// This disables a warning for unused #[macro_use(..)]
// which is incorrect since the compiler does not check
// for all available configurations.
Expand All @@ -34,6 +38,10 @@ pub use static_assertions::const_assert;
#[doc(hidden)]
pub use byteorder;

#[cfg(not(feature = "libc"))]
#[doc(hidden)]
pub mod libc {}

#[cfg(feature = "rustc-hex")]
#[doc(hidden)]
pub use rustc_hex;
Expand Down
1 change: 0 additions & 1 deletion primitive-types/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ The format is based on [Keep a Changelog].
[Keep a Changelog]: http://keepachangelog.com/en/1.0.0/

## [Unreleased]
- Removed `libc` feature. [#317](https://github.com/paritytech/parity-common/pull/317)

## [0.6.2] - 2019-01-03
- Expose to_hex and from_hex from impl-serde. [#302](https://github.com/paritytech/parity-common/pull/302)
Expand Down
1 change: 1 addition & 0 deletions primitive-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ impl-rlp = { version = "0.2", path = "impls/rlp", default-features = false, opti
default = ["std"]
std = ["uint/std", "fixed-hash/std", "impl-codec/std"]
byteorder = ["fixed-hash/byteorder"]
libc = ["fixed-hash/libc"]
rustc-hex = ["fixed-hash/rustc-hex"]
serde = ["std", "impl-serde"]
codec = ["impl-codec"]
Expand Down