Skip to content

Commit 6a37692

Browse files
committed
Document that CStrings live in the libc heap
Closes issue #17067 and improves pr #17355
1 parent 9ce2c51 commit 6a37692

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/librustrt/c_str.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ not tied to the lifetime of the original string/data buffer). If C strings are
3636
heavily used in applications, then caching may be advisable to prevent
3737
unnecessary amounts of allocations.
3838
39-
Be carefull to remember that the memory is managed by libc's malloc and not
40-
by jemalloc which is the 'normal' rust memory allocator.
41-
That means that the CString pointers should only be freed with
42-
alloc::libc_heap::malloc_raw if you intend to do that on your own.
39+
Be carefull to remember that the memory is managed by C allocator API and not
40+
by Rust allocator API.
41+
That means that the CString pointers should only be freed with C allocator API
42+
if you intend to do that on your own.
4343
4444
An example of creating and using a C string would be:
4545
@@ -97,7 +97,7 @@ pub struct CString {
9797
impl Clone for CString {
9898
/// Clone this CString into a new, uniquely owned CString. For safety
9999
/// reasons, this is always a deep clone with the memory allocated
100-
/// with libc's malloc, rather than the usual shallow clone.
100+
/// with C's allocator API, rather than the usual shallow clone.
101101
fn clone(&self) -> CString {
102102
let len = self.len() + 1;
103103
let buf = unsafe { malloc_raw(len) } as *mut libc::c_char;
@@ -136,8 +136,9 @@ impl<S: hash::Writer> hash::Hash<S> for CString {
136136
}
137137

138138
impl CString {
139-
/// Create a C String from a pointer, with memory managed by libc's malloc,
140-
/// so do not call it with a pointer allocated by jemalloc.
139+
/// Create a C String from a pointer, with memory managed by C's allocator
140+
/// API, so do not call it with a pointer to memory managed by Rust's
141+
/// allocator API.
141142
///
142143
///# Failure
143144
///

0 commit comments

Comments
 (0)