Skip to content

Commit 99eac5b

Browse files
committed
---
yaml --- r: 152939 b: refs/heads/try2 c: 569f13a h: refs/heads/master i: 152937: c28b5fc 152935: 1daf5f5 v: v3
1 parent 3a8fb78 commit 99eac5b

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
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: d4d4bc4fe944c1b0627d104127352046879f9dc0
8+
refs/heads/try2: 569f13a5217f1a699059707b1eccbdefd011ba12
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/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)