@@ -22,20 +22,6 @@ strings can validly contain a null-byte in the middle of the string (0 is a
22
22
valid Unicode codepoint). This means that not all Rust strings can actually be
23
23
translated to C strings.
24
24
25
- # Creation of a C string
26
-
27
- A C string is managed through the `CString` type defined in this module. It
28
- "owns" the internal buffer of characters and will automatically deallocate the
29
- buffer when the string is dropped. The `ToCStr` trait is implemented for `&str`
30
- and `&[u8]`, but the conversions can fail due to some of the limitations
31
- explained above.
32
-
33
- This also means that currently whenever a C string is created, an allocation
34
- must be performed to place the data elsewhere (the lifetime of the C string is
35
- not tied to the lifetime of the original string/data buffer). If C strings are
36
- heavily used in applications, then caching may be advisable to prevent
37
- unnecessary amounts of allocations.
38
-
39
25
Be carefull to remember that the memory is managed by C allocator API and not
40
26
by Rust allocator API.
41
27
That means that the CString pointers should be freed with C allocator API
@@ -432,7 +418,7 @@ impl ToCStr for [u8] {
432
418
ptr:: copy_memory ( buf, self . as_ptr ( ) , self_len) ;
433
419
* buf. offset ( self_len as int ) = 0 ;
434
420
435
- CString :: new_owned ( buf as * mut i8 )
421
+ CString :: new_owned ( buf as * mut libc :: c_char )
436
422
}
437
423
438
424
fn with_c_str < T > ( & self , f : |* const libc:: c_char | -> T ) -> T {
0 commit comments