8000 Avoid usage of atomic types if not supported by the target arch by bigspider · Pull Request #1705 · rust-bitcoin/rust-bitcoin · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Avoid usage of atomic types if not supported by the target arch #1705

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

Merged
merged 1 commit into from
Mar 17, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion bitcoin/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fn main() {
.parse::<u64>()
.expect("invalid Rust minor version");

for activate_version in &[46, 53] {
for activate_version in &[46, 53, 60] {
if minor >= *activate_version {
println!("cargo:rustc-cfg=rust_v_1_{}", activate_version);
}
Expand Down
8000 4 changes: 4 additions & 0 deletions bitcoin/src/blockdata/script/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
//! is minimal but we may extend it in the future if needed.

use alloc::rc::Rc;
#[cfg(any(not(rust_v_1_60), target_has_atomic = "ptr"))]
use alloc::sync::Arc;

use core::cmp::Ordering;
Expand Down Expand Up @@ -279,6 +280,9 @@ impl<'a> From<&'a Script> for Cow<'a, Script> {
}
}

/// Note: This will fail to compile on old Rust for targets that don't support atomics
#[cfg(any(not(rust_v_1_60), target_has_atomic = "ptr"))]
#[cfg_attr(docsrs, doc(cfg(target_has_atomic = "ptr")))]
impl<'a> From<&'a Script> for Arc<Script> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apart from different cfg, this needs docsrs too.

fn from(value: &'a Script) -> Self {
let rw: *const [u8] = Arc::into_raw(Arc::from(&value.0));
Expand Down
3 changes: 3 additions & 0 deletions bitcoin/src/consensus/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,9 @@ impl<T: Encodable> Encodable for rc::Rc<T> {
}
}

/// Note: This will fail to compile on old Rust for targets that don't support atomics
#[cfg(any(not(rust_v_1_60), target_has_atomic = "ptr"))]
#[cfg_attr(docsrs, doc(cfg(target_has_atomic = "ptr")))]
impl<T: Encodable> Encodable for sync::Arc<T> {
fn consensus_encode<W: io::Write + ?Sized>(&self, w: &mut W) -> Result<usize, io::Error> {
(**self).consensus_encode(w)
Expand Down
5 changes: 4 additions & 1 deletion bitcoin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,10 @@ mod io_extras {
#[rustfmt::skip]
mod prelude {
#[cfg(all(not(feature = "std"), not(test)))]
pub use alloc::{string::{String, ToString}, vec::Vec, boxed::Box, borrow::{Borrow, Cow, ToOwned}, slice, rc, sync};
pub use alloc::{string::{String, ToString}, vec::Vec, boxed::Box, borrow::{Borrow, Cow, ToOwned}, slice, rc};

#[cfg(all(not(feature = "std"), not(test), any(not(rust_v_1_60), target_has_atomic = "ptr")))]
pub use alloc::sync;

#[cfg(any(feature = "std", test))]
pub use std::{string::{String, ToString}, vec::Vec, boxed::Box, borrow::{Borrow, Cow, ToOwned}, slice, rc, sync};
Expand Down
0