@@ -61,26 +61,16 @@ impl MemoryBuffer {
61
61
Ok ( MemoryBuffer :: new ( memory_buffer) )
62
62
}
63
63
64
- // REVIEW: Does this make more sense to take a byte array as input?
65
- /// This will create a new `MemoryBuffer` from the given input.
66
- ///
67
64
/// This function is likely slightly cheaper than `create_from_memory_range_copy` since it intentionally
68
65
/// leaks data to LLVM so that it doesn't have to reallocate. `create_from_memory_range_copy` may be removed
69
66
/// in the future
70
- pub fn create_from_memory_range ( input : & str , name : & str ) -> Self {
71
- let input_c_string = CString :: new ( input) . expect ( "Conversion to CString failed unexpectedly" ) ;
67
+ pub fn create_from_memory_range ( input : & [ u8 ] , name : & str ) -> Self {
72
68
let name_c_string = CString :: new ( name) . expect ( "Conversion to CString failed unexpectedly" ) ;
73
69
74
70
let memory_buffer = unsafe {
75
- LLVMCreateMemoryBufferWithMemoryRange ( input_c_string . as_ptr ( ) , input. len ( ) , name_c_string. as_ptr ( ) , false as i32 )
71
+ LLVMCreateMemoryBufferWithMemoryRange ( input . as_ptr ( ) as * const i8 , input. len ( ) , name_c_string. as_ptr ( ) , false as i32 )
76
72
} ;
77
73
78
- // LLVM seems to want to take ownership of input_c_string, which is why we need to forget it
79
- // This originally was discovered when not forgetting it caused a subsequent as_slice call
80
- // to sometimes return partially garbage data
81
- // REVIEW: Does this apply to name_c_string as well?
82
- forget ( input_c_string) ;
83
-
84
74
MemoryBuffer :: new ( memory_buffer)
85
75
}
86
76
@@ -89,12 +79,11 @@ impl MemoryBuffer {
89
79
/// This function is likely slightly more expensive than `create_from_memory_range` since it does not leak
90
80
/// data to LLVM, forcing LLVM to make a copy. This function may be removed in the future in favor of
91
81
/// `create_from_memory_range`
92
- pub fn create_from_memory_range_copy ( input : & str , name : & str ) -> Self {
93
- let input_c_string = CString :: new ( input) . expect ( "Conversion to CString failed unexpectedly" ) ;
82
+ pub fn create_from_memory_range_copy ( input : & [ u8 ] , name : & str ) -> Self {
94
83
let name_c_string = CString :: new ( name) . expect ( "Conversion to CString failed unexpectedly" ) ;
95
84
96
85
let memory_buffer = unsafe {
97
- LLVMCreateMemoryBufferWithMemoryRangeCopy ( input_c_string . as_ptr ( ) , input. len ( ) , name_c_string. as_ptr ( ) )
86
+ LLVMCreateMemoryBufferWithMemoryRangeCopy ( input . as_ptr ( ) as * const i8 , input. len ( ) , name_c_string. as_ptr ( ) )
98
87
} ;
99
88
100
89
MemoryBuffer :: new ( memory_buffer)
0 commit comments