Skip to content

Commit b71c7d8

Browse files
committed
---
yaml --- r: 122599 b: refs/heads/snap-stage3 c: 569f13a h: refs/heads/master i: 122597: 1146ad8 122595: b319aad 122591: c2a98ab v: v3
1 parent edc8427 commit b71c7d8

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
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 1bff1ff810dcfa8064c11e2b84473f053d1f69f1
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: d4d4bc4fe944c1b0627d104127352046879f9dc0
4+
refs/heads/snap-stage3: 569f13a5217f1a699059707b1eccbdefd011ba12
55
refs/heads/try: 2e9d9477b848cec778ca3f07ecdf0aea6ade23de
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/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)