Skip to content

Commit

Permalink
Silence unwind cfg lint warnings
Browse files Browse the repository at this point in the history
```
warning: unexpected `cfg` condition name: `unwind`
  --> src/python_spy.rs:38:11
   |
38 |     #[cfg(unwind)]
   |           ^^^^^^ help: found config with similar value: `panic =
"unwind"`
   |
   = help: consider using a Cargo feature instead
   = help: or consider adding in `Cargo.toml` the `check-cfg` lint
config for the lint:
            [lints.rust]
            unexpected_cfgs = { level = "warn", check-cfg =
['cfg(unwind)'] }
   = help: or consider adding
`println!("cargo::rustc-check-cfg=cfg(unwind)");` to the top of the
`build.rs`
   = note: see
<https://doc.rust-lang.org/nightly/rustc/check-cfg/cargo-specifics.html>
for more information about checking conditional configuration
```
  • Loading branch information
andrewjcg committed Sep 3, 2024
1 parent 8dd5492 commit 093e3ba
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 22 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[features]
unwind = []

[package]
name = "py-spy"
version = "0.3.14"
Expand Down
2 changes: 1 addition & 1 deletion src/binary_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub struct BinaryInfo {
}

impl BinaryInfo {
#[cfg(unwind)]
#[cfg(feature = "unwind")]
pub fn contains(&self, addr: u64) -> bool {
addr >= self.addr && addr < (self.addr + self.size)
}
Expand Down
10 changes: 5 additions & 5 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ impl Config {
.help("PID of a running python program to spy on")
.takes_value(true);

#[cfg(unwind)]
#[cfg(feature = "unwind")]
let native = Arg::new("native")
.short('n')
.long("native")
Expand Down Expand Up @@ -328,11 +328,11 @@ impl Config {
);

// add native unwinding if appropriate
#[cfg(unwind)]
#[cfg(feature = "unwind")]
let record = record.arg(native.clone());
#[cfg(unwind)]
#[cfg(feature = "unwind")]
let top = top.arg(native.clone());
#[cfg(unwind)]
#[cfg(feature = "unwind")]
let dump = dump.arg(native.clone());

// Nonblocking isn't an option for freebsd, remove
Expand Down Expand Up @@ -429,7 +429,7 @@ impl Config {
.value_of("pid")
.map(|p| p.parse().expect("invalid pid"));
config.full_filenames = matches.occurrences_of("full_filenames") > 0;
if cfg!(unwind) {
if cfg!(feature = "unwind") {
config.native = matches.occurrences_of("native") > 0;
}

Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ pub mod binary_parser;
pub mod config;
#[cfg(target_os = "linux")]
pub mod coredump;
#[cfg(unwind)]
#[cfg(feature = "unwind")]
mod cython;
pub mod dump;
#[cfg(unwind)]
#[cfg(feature = "unwind")]
mod native_stack_trace;
mod python_bindings;
mod python_data_access;
Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ mod config;
mod console_viewer;
#[cfg(target_os = "linux")]
mod coredump;
#[cfg(unwind)]
#[cfg(feature = "unwind")]
mod cython;
mod dump;
mod flamegraph;
#[cfg(unwind)]
#[cfg(feature = "unwind")]
mod native_stack_trace;
mod python_bindings;
mod python_data_access;
Expand Down
20 changes: 10 additions & 10 deletions src/python_spy.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
#[cfg(windows)]
use regex::RegexBuilder;
use std::collections::HashMap;
#[cfg(all(target_os = "linux", unwind))]
#[cfg(all(target_os = "linux", feature = "unwind"))]
use std::collections::HashSet;
#[cfg(all(target_os = "linux", unwind))]
#[cfg(all(target_os = "linux", feature = "unwind"))]
use std::iter::FromIterator;
use std::path::Path;

use anyhow::{Context, Error, Result};
use remoteprocess::{Pid, Process, ProcessMemory, Tid};

use crate::config::{Config, LockingStrategy};
#[cfg(unwind)]
#[cfg(feature = "unwind")]
use crate::native_stack_trace::NativeStack;
use crate::python_bindings::{
v2_7_15, v3_10_0, v3_11_0, v3_3_7, v3_5_5, v3_6_6, v3_7_0, v3_8_0, v3_9_5,
Expand All @@ -35,7 +35,7 @@ pub struct PythonSpy {
pub python_filename: std::path::PathBuf,
pub version_string: String,
pub config: Config,
#[cfg(unwind)]
#[cfg(feature = "unwind")]
pub native: Option<NativeStack>,
pub short_filenames: HashMap<String, Option<String>>,
pub python_thread_ids: HashMap<u64, Tid>,
Expand Down Expand Up @@ -70,7 +70,7 @@ impl PythonSpy {

let version_string = format!("python{}.{}", version.major, version.minor);

#[cfg(unwind)]
#[cfg(feature = "unwind")]
let native = if config.native {
Some(NativeStack::new(
pid,
Expand All @@ -89,7 +89,7 @@ impl PythonSpy {
threadstate_address,
python_filename: python_info.python_filename,
version_string,
#[cfg(unwind)]
#[cfg(feature = "unwind")]
native,
#[cfg(target_os = "linux")]
dockerized: python_info.dockerized,
Expand Down Expand Up @@ -291,7 +291,7 @@ impl PythonSpy {
}

// Merge in the native stack frames if necessary
#[cfg(unwind)]
#[cfg(feature = "unwind")]
{
if self.config.native {
if let Some(native) = self.native.as_mut() {
Expand Down Expand Up @@ -389,7 +389,7 @@ impl PythonSpy {
Ok(None)
}

#[cfg(all(target_os = "linux", not(unwind)))]
#[cfg(all(target_os = "linux", not(feature = "unwind")))]
fn _get_os_thread_id<I: InterpreterState>(
&mut self,
_python_thread_id: u64,
Expand All @@ -398,7 +398,7 @@ impl PythonSpy {
Ok(None)
}

#[cfg(all(target_os = "linux", unwind))]
#[cfg(all(target_os = "linux", feature = "unwind"))]
fn _get_os_thread_id<I: InterpreterState>(
&mut self,
python_thread_id: u64,
Expand Down Expand Up @@ -483,7 +483,7 @@ impl PythonSpy {
Ok(None)
}

#[cfg(all(target_os = "linux", unwind))]
#[cfg(all(target_os = "linux", feature = "unwind"))]
pub fn _get_pthread_id(
&self,
unwinder: &remoteprocess::Unwinder,
Expand Down
2 changes: 1 addition & 1 deletion src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[cfg(unwind)]
#[cfg(feature = "unwind")]
pub fn resolve_filename(filename: &str, modulename: &str) -> Option<String> {
// check the filename first, if it exists use it
use std::path::Path;
Expand Down
2 changes: 1 addition & 1 deletion tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ fn test_busy_loop() {
assert!(traces[0].active);
}

#[cfg(unwind)]
#[cfg(feature = "unwind")]
#[test]
fn test_thread_reuse() {
// on linux we had an issue with the pthread -> native thread id caching
Expand Down

0 comments on commit 093e3ba

Please sign in to comment.