diff options
| author | bors <bors@rust-lang.org> | 2023-09-24 20:36:44 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-09-24 20:36:44 +0000 |
| commit | 37390d65636dd67e263753a3c04fbc60dcc4348e (patch) | |
| tree | af4b235a3e66ba529247f3f64ac917ce6f552ed1 /compiler/rustc_data_structures/src/small_c_str.rs | |
| parent | a1c7a1c89f61adc43e9674af3c9c120eb6271a91 (diff) | |
| parent | 3409ca65d835b858d9cefbe8949552f0f5ad0788 (diff) | |
| download | rust-37390d65636dd67e263753a3c04fbc60dcc4348e.tar.gz rust-37390d65636dd67e263753a3c04fbc60dcc4348e.zip | |
Auto merge of #115911 - nebulark:refactor_targetmachine, r=Nilstrieb
Add OwnedTargetMachine to manage llvm:TargetMachine LLVMRustDisposeTargetMachine taking a &mut could be undefined behaviour. Wrapping it with a struct and using pointers instead avoids this problem. In addition the TargetMachine is now automatically freed via the Wrappers drop impl. This should fix some memory leaks when create_informational_target_machine was used, e.g. https://github.com/rust-lang/rust/blob/327e6cf55cc5211e19ed46e92e05eef29dc75dd0/compiler/rustc_codegen_llvm/src/llvm_util.rs#L291-L314 r? `@Nilstrieb`
Diffstat (limited to 'compiler/rustc_data_structures/src/small_c_str.rs')
| -rw-r--r-- | compiler/rustc_data_structures/src/small_c_str.rs | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/compiler/rustc_data_structures/src/small_c_str.rs b/compiler/rustc_data_structures/src/small_c_str.rs index 719e4e3d974..349fd7f9769 100644 --- a/compiler/rustc_data_structures/src/small_c_str.rs +++ b/compiler/rustc_data_structures/src/small_c_str.rs @@ -79,3 +79,9 @@ impl<'a> FromIterator<&'a str> for SmallCStr { Self { data } } } + +impl From<&ffi::CStr> for SmallCStr { + fn from(s: &ffi::CStr) -> Self { + Self { data: SmallVec::from_slice(s.to_bytes()) } + } +} |
