Skip to content
This repository has been archived by the owner on Sep 4, 2024. It is now read-only.

Commit

Permalink
Merge #123: Remove unnecessary unsafe code
Browse files Browse the repository at this point in the history
cf3ccbc Allow assigning_clones (Tobin C. Harding)
673d796 Whitelist cfg attributes (Tobin C. Harding)
7500f7a Remove unnecessary unsafe code (Tobin C. Harding)

Pull request description:

  We can initialize the `RESULTS` vector inside a mutex and remove a couple of unsafe blocks.

  `lazy_static` is already in use; this patch does not change the test coverage.

ACKs for top commit:
  apoelstra:
    ACK cf3ccbc also ran the integration tests this time

Tree-SHA512: b15ae623643147bdcb074738fb979f7d8552f46d64f9d67c6e956282948b292d460d1754212ae144ec058828e116b2a6f3316f22703029f0f95fb102f319d07f
  • Loading branch information
apoelstra committed May 31, 2024
2 parents be07587 + cf3ccbc commit 09bbc3d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,6 @@ socks = { version = "0.3.4", optional = true}

[workspace]
members = ["fuzz", "integration_test"]

[lints.rust]
unexpected_cfgs = { level = "deny", check-cfg = ['cfg(jsonrpc_fuzz)'] }
17 changes: 8 additions & 9 deletions integration_test/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
extern crate lazy_static;

use std::cell::RefCell;
use std::sync::Mutex;
use std::time::Duration;
use std::{fs, mem, panic};
use std::{fs, panic};

use backtrace::Backtrace;

Expand Down Expand Up @@ -75,16 +76,16 @@ fn make_client() -> Client {

lazy_static! {
static ref CLIENT: Client = make_client();

/// Here we will collect all the results of the individual tests, preserving ordering.
/// Ideally this would be preset with capacity, but static prevents this.
static ref RESULTS: Mutex<Vec<(&'static str, bool)>> = Mutex::new(Vec::new());
}

thread_local! {
static LAST_PANIC: RefCell<Option<(String, Backtrace)>> = RefCell::new(None);
}

/// Here we will collect all the results of the individual tests, preserving ordering.
/// Ideally this would be preset with capacity, but static prevents this.
static mut RESULTS: Vec<(&'static str, bool)> = Vec::new();

macro_rules! run_test {
($method:ident) => {
println!("Running {}...", stringify!($method));
Expand All @@ -98,9 +99,7 @@ macro_rules! run_test {
println!("--");
}

unsafe {
RESULTS.push((stringify!($method), result.is_ok()));
}
RESULTS.lock().unwrap().push((stringify!($method), result.is_ok()));
};
}

Expand All @@ -123,7 +122,7 @@ fn main() {
println!("");
println!("Summary:");
let mut error_count = 0;
for (name, success) in mem::replace(unsafe { &mut RESULTS }, Vec::new()).into_iter() {
for (name, success) in RESULTS.lock().unwrap().iter() {
if !success {
println!(" - {}: FAILED", name);
error_count += 1;
Expand Down
1 change: 1 addition & 0 deletions src/http/minreq_http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ impl Builder {
}

/// Sets the URL of the server to the transport.
#[allow(clippy::assigning_clones)] // clone_into is only available in Rust 1.63
pub fn url(mut self, url: &str) -> Result<Self, Error> {
self.tp.url = url.to_owned();
Ok(self)
Expand Down

0 comments on commit 09bbc3d

Please sign in to comment.