Skip to content

Commit ba1f3c9

Browse files
committed
Convert to C string inside WriteOutputFile
1 parent 3830040 commit ba1f3c9

File tree

1 file changed

+42
-57
lines changed

1 file changed

+42
-57
lines changed

src/librustc/back/link.rs

Lines changed: 42 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -61,23 +61,28 @@ pub fn llvm_err(sess: Session, msg: ~str) -> ! {
6161
6262
pub fn WriteOutputFile(sess: Session,
6363
PM: lib::llvm::PassManagerRef, M: ModuleRef,
64-
Triple: *c_char,
64+
Triple: &str,
65+
Output: &str,
6566
// FIXME: When #2334 is fixed, change
6667
// c_uint to FileType
67-
Output: *c_char, FileType: c_uint,
68+
FileType: c_uint,
6869
OptLevel: c_int,
6970
EnableSegmentedStacks: bool) {
7071
unsafe {
71-
let result = llvm::LLVMRustWriteOutputFile(
72-
PM,
73-
M,
74-
Triple,
75-
Output,
76-
FileType,
77-
OptLevel,
78-
EnableSegmentedStacks);
79-
if (!result) {
80-
llvm_err(sess, ~"Could not write output");
72+
do str::as_c_str(Triple) |Triple| {
73+
do str::as_c_str(Output) |Output| {
74+
let result = llvm::LLVMRustWriteOutputFile(
75+
PM,
76+
M,
77+
Triple,
78+
Output,
79+
FileType,
80+
OptLevel,
81+
EnableSegmentedStacks);
82+
if (!result) {
83+
llvm_err(sess, ~"Could not write output");
84+
}
85+
}
8186
}
8287
}
8388
}
@@ -310,66 +315,46 @@ pub mod write {
310315
llvm::LLVMWriteBitcodeToFile(llmod, buf)
311316
});
312317
pm = mk_pass_manager();
313-
// Save the assembly file if -S is used
314318

319+
// Save the assembly file if -S is used
315320
if output_type == output_type_assembly {
316-
let _: () = str::as_c_str(
321+
WriteOutputFile(
322+
sess,
323+
pm.llpm,
324+
llmod,
317325
sess.targ_cfg.target_strs.target_triple,
318-
|buf_t| {
319-
str::as_c_str(output.to_str(), |buf_o| {
320-
WriteOutputFile(
321-
sess,
322-
pm.llpm,
323-
llmod,
324-
buf_t,
325-
buf_o,
326-
lib::llvm::AssemblyFile as c_uint,
327-
CodeGenOptLevel,
328-
true)
329-
})
330-
});
326+
output.to_str(),
327+
lib::llvm::AssemblyFile as c_uint,
328+
CodeGenOptLevel,
329+
true);
331330
}
332331

333-
334332
// Save the object file for -c or --save-temps alone
335333
// This .o is needed when an exe is built
336334
if output_type == output_type_object ||
337335
output_type == output_type_exe {
338-
let _: () = str::as_c_str(
336+
WriteOutputFile(
337+
sess,
338+
pm.llpm,
339+
llmod,
339340
sess.targ_cfg.target_strs.target_triple,
340-
|buf_t| {
341-
str::as_c_str(output.to_str(), |buf_o| {
342-
WriteOutputFile(
343-
sess,
344-
pm.llpm,
345-
llmod,
346-
buf_t,
347-
buf_o,
348-
lib::llvm::ObjectFile as c_uint,
349-
CodeGenOptLevel,
350-
true)
351-
})
352-
});
341+
output.to_str(),
342+
lib::llvm::ObjectFile as c_uint,
343+
CodeGenOptLevel,
344+
true);
353345
}
354346
} else {
355347
// If we aren't saving temps then just output the file
356348
// type corresponding to the '-c' or '-S' flag used
357-
358-
let _: () = str::as_c_str(
349+
WriteOutputFile(
350+
sess,
351+
pm.llpm,
352+
llmod,
359353
sess.targ_cfg.target_strs.target_triple,
360-
|buf_t| {
361-
str::as_c_str(output.to_str(), |buf_o| {
362-
WriteOutputFile(
363-
sess,
364-
pm.llpm,
365-
llmod,
366-
buf_t,
367-
buf_o,
368-
FileType as c_uint,
369-
CodeGenOptLevel,
370-
true)
371-
})
372-
});
354+
output.to_str(),
355+
FileType as c_uint,
356+
CodeGenOptLevel,
357+
true);
373358
}
374359
// Clean up and return
375360

0 commit comments

Comments
 (0)