Skip to content

Commit

Permalink
Merge pull request #398 from wasmerio/macos_sections_fix
Browse files Browse the repository at this point in the history
Fix macOS section handling that already have a comma in ther name
  • Loading branch information
TheDan64 committed Feb 11, 2023
2 parents 4683209 + 92b6606 commit a21e68b
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/values/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,14 @@ impl<'ctx> Value<'ctx> {

// On MacOS we need to remove ',' before section name
if cfg!(target_os = "macos") {
Some(unsafe { CStr::from_ptr(ptr.add(1)) })
let name = unsafe { CStr::from_ptr(ptr) };
let name_string = name.to_string_lossy();
let mut chars = name_string.chars();
if Some(',') == chars.next() {
Some(unsafe { CStr::from_ptr(ptr.add(1)) })
} else {
Some(name)
}
} else {
Some(unsafe { CStr::from_ptr(ptr) })
}
Expand All @@ -195,7 +202,7 @@ impl<'ctx> Value<'ctx> {
/// Sets the section of the global value
fn set_section(self, section: Option<&str>) {
#[cfg(target_os = "macos")]
let section = section.map(|s| format!(",{}", s));
let section = section.map(|s| if s.contains(",") { format!("{}", s) } else { format!(",{}", s) });

let c_string = section.as_deref().map(to_c_str);

Expand Down

0 comments on commit a21e68b

Please sign in to comment.