Skip to content

Commit

Permalink
Do not use slice::as_ptr
Browse files Browse the repository at this point in the history
  • Loading branch information
ianks committed Jul 12, 2023
1 parent 7bd68b2 commit 8491f4b
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 43 deletions.
38 changes: 0 additions & 38 deletions crates/rb-sys-build/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,6 @@ pub fn is_mswin_or_mingw() -> bool {
}
}

/// Check if we are in debug mode.
pub fn is_debug_env() -> bool {
if std::env::var("CARGO_CFG_FEATURE")
.map(|ft| ft.contains("clippy"))
.unwrap_or(false)
{
return false;
}

let vars_to_check = ["DEBUG", "RB_SYS_DEBUG", "RB_SYS_DEBUG_BUILD"];

vars_to_check.iter().any(|var| {
std::env::var(var)
.map(|v| v == "1" || v == "true")
.unwrap_or(false)
})
}

/// Splits shell words.
pub fn shellsplit<S: AsRef<str>>(s: S) -> Vec<String> {
let s = s.as_ref();
Expand Down Expand Up @@ -66,25 +48,5 @@ macro_rules! memoize {
macro_rules! debug_log {
($($arg:tt)*) => {
eprintln!($($arg)*);

if $crate::utils::is_debug_env() {
use std::io::Write;

let dir = if let Ok(dir) = std::env::var("DEBUG_OUTPUT_DIR") {
std::path::PathBuf::from(dir)
} else {
std::env::var("CARGO_MANIFEST_DIR")
.map(|dir| std::path::PathBuf::from(dir))
.unwrap_or_else(|_| std::env::current_dir().unwrap())
};

let mut file = std::fs::OpenOptions::new()
.create(true)
.append(true)
.open(dir.join("rb-sys-build.log"))
.unwrap();

let _ = writeln!(file, $($arg)*);
}
};
}
2 changes: 1 addition & 1 deletion crates/rb-sys/src/stable_api/ruby_2_6.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl StableApiDefinition for Definition {
let is_heap = (flags & RSTRING_NOEMBED as VALUE) != 0;

if !is_heap {
rstring.as_.ary.as_ptr() as *const _
&rstring.as_.ary as *const _
} else {
rstring.as_.heap.ptr
}
Expand Down
2 changes: 1 addition & 1 deletion crates/rb-sys/src/stable_api/ruby_2_7.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl StableApiDefinition for Definition {
let is_heap = (flags & crate::ruby_rstring_flags::RSTRING_NOEMBED as VALUE) != 0;

if !is_heap {
rstring.as_.ary.as_ptr() as *const _
&rstring.as_.ary as *const _
} else {
rstring.as_.heap.ptr
}
Expand Down
2 changes: 1 addition & 1 deletion crates/rb-sys/src/stable_api/ruby_3_0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl StableApiDefinition for Definition {
let is_heap = (flags & crate::ruby_rstring_flags::RSTRING_NOEMBED as VALUE) != 0;

if !is_heap {
rstring.as_.ary.as_ptr() as *const _
&rstring.as_.ary as *const _
} else {
rstring.as_.heap.ptr
}
Expand Down
2 changes: 1 addition & 1 deletion crates/rb-sys/src/stable_api/ruby_3_1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl StableApiDefinition for Definition {
let is_heap = (flags & crate::ruby_rstring_flags::RSTRING_NOEMBED as VALUE) != 0;

if !is_heap {
rstring.as_.embed.ary.as_ptr() as *const c_char
&rstring.as_.embed.ary as *const _
} else {
rstring.as_.heap.ptr
}
Expand Down
2 changes: 1 addition & 1 deletion crates/rb-sys/src/stable_api/ruby_3_2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl StableApiDefinition for Definition {
let is_heap = (flags & crate::ruby_rstring_flags::RSTRING_NOEMBED as VALUE) != 0;

if !is_heap {
rstring.as_.embed.ary.as_ptr() as *const c_char
&rstring.as_.embed.ary as *const _
} else {
rstring.as_.heap.ptr
}
Expand Down

0 comments on commit 8491f4b

Please sign in to comment.