Skip to content

Commit

Permalink
Rollup merge of rust-lang#36741 - matklad:no-flacky-test, r=alexcrichton
Browse files Browse the repository at this point in the history
Remove CString drop test.

The test relies on the undefined behavior, and so may fail in some
circumstances. This can be worked around by stubbing a memory allocator
in the test, but it is a bit of work, and LLVM could still theoretically
eliminate the write of the zero byte in release mode (which is
intended).

So let's just remove the test and mark the function as inline. It
shouldn't be optimized away when inlined into the debug build of user's
code.

Supersedes rust-lang#36607

r? @alexcrichton
  • Loading branch information
Jonathan Turner authored Sep 29, 2016
2 parents 725d0f5 + 300e138 commit 8f2c000
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 50 deletions.
4 changes: 3 additions & 1 deletion src/libstd/ffi/c_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,9 +314,11 @@ impl CString {
}

// Turns this `CString` into an empty string to prevent
// memory unsafe code from working by accident.
// memory unsafe code from working by accident. Inline
// to prevent LLVM from optimizing it away in debug builds.
#[stable(feature = "cstring_drop", since = "1.13.0")]
impl Drop for CString {
#[inline]
fn drop(&mut self) {
unsafe { *self.inner.get_unchecked_mut(0) = 0; }
}
Expand Down
49 changes: 0 additions & 49 deletions src/test/run-pass/cstring-drop.rs

This file was deleted.

0 comments on commit 8f2c000

Please # to comment.