Skip to content

Commit 061f9b7

Browse files
committed
---
yaml --- r: 131362 b: refs/heads/dist-snap c: 569f13a h: refs/heads/master v: v3
1 parent 95f69e8 commit 061f9b7

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: 457a3c991d79b971be07fce75f9d0c12848fb37c
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
9-
refs/heads/dist-snap: d4d4bc4fe944c1b0627d104127352046879f9dc0
9+
refs/heads/dist-snap: 569f13a5217f1a699059707b1eccbdefd011ba12
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1212
refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0

branches/dist-snap/src/librustrt/c_str.rs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -122,17 +122,6 @@ impl CString {
122122
CString { buf: buf, owns_buffer_: owns_buffer }
123123
}
124124

125-
/// Unwraps the wrapped `*libc::c_char` from the `CString` wrapper.
126-
///
127-
/// The original object is destructed after this method is called, and if
128-
/// the underlying pointer was previously allocated, care must be taken to
129-
/// ensure that it is deallocated properly.
130-
pub unsafe fn unwrap(self) -> *const libc::c_char {
131-
let mut c_str = self;
132-
c_str.owns_buffer_ = false;
133-
c_str.buf
134-
}
135-
136125
/// Return a pointer to the NUL-terminated string data.
137126
///
138127
/// `.as_ptr` returns an internal pointer into the `CString`, and
@@ -289,6 +278,22 @@ impl CString {
289278
marker: marker::ContravariantLifetime,
290279
}
291280
}
281+
282+
/// Unwraps the wrapped `*libc::c_char` from the `CString` wrapper.
283+
///
284+
/// Any ownership of the buffer by the `CString` wrapper is
285+
/// forgotten, meaning that the backing allocation of this
286+
/// `CString` is not automatically freed if it owns the
287+
/// allocation. In this case, a user of `.unwrap()` should ensure
288+
/// the allocation is freed, to avoid leaking memory.
289+
///
290+
/// Prefer `.as_ptr()` when just retrieving a pointer to the
291+
/// string data, as that does not relinquish ownership.
292+
pub unsafe fn unwrap(mut self) -> *const libc::c_char {
293+
self.owns_buffer_ = false;
294+
self.buf
295+
}
296+
292297
}
293298

294299
impl Drop for CString {

0 commit comments

Comments
 (0)