File tree Expand file tree Collapse file tree 3 files changed +14
-12
lines changed
compiler/rustc_codegen_llvm/src/back Expand file tree Collapse file tree 3 files changed +14
-12
lines changed Original file line number Diff line number Diff line change @@ -6,32 +6,34 @@ mod tests;
6
6
///
7
7
/// The result is intended to be informational, for embedding in debug metadata,
8
8
/// and might not be properly quoted/escaped for actual command-line use.
9
- pub ( crate ) fn quote_command_line_args ( args : & [ String ] ) -> String {
9
+ pub ( crate ) fn quote_command_line_args ( args : & [ String ] ) -> Vec < u8 > {
10
10
// Start with a decent-sized buffer, since rustc invocations tend to be long.
11
- let mut buf = String :: with_capacity ( 128 ) ;
11
+ let mut buf = Vec :: with_capacity ( 128 ) ;
12
12
13
13
for arg in args {
14
14
if !buf. is_empty ( ) {
15
- buf. push ( ' ' ) ;
15
+ buf. push ( b ' ') ;
16
16
}
17
17
18
18
print_arg_quoted ( & mut buf, arg) ;
19
19
}
20
20
21
+ debug_assert ! ( str :: from_utf8( & buf) . is_ok( ) ) ;
22
+
21
23
buf
22
24
}
23
25
24
26
/// Equivalent to LLVM's `sys::printArg` with quoting always enabled
25
27
/// (see llvm/lib/Support/Program.cpp).
26
- fn print_arg_quoted ( buf : & mut String , arg : & str ) {
28
+ fn print_arg_quoted ( buf : & mut Vec < u8 > , arg : & str ) {
27
29
buf. reserve ( arg. len ( ) + 2 ) ;
28
30
29
- buf. push ( '"' ) ;
30
- for ch in arg. chars ( ) {
31
- if matches ! ( ch , '"' | '\\' | '$' ) {
32
- buf. push ( '\\' ) ;
31
+ buf. push ( b '"') ;
32
+ for & byte in arg. as_bytes ( ) {
33
+ if matches ! ( byte , b '"' | b '\\' | b '$') {
34
+ buf. push ( b '\\') ;
33
35
}
34
- buf. push ( ch ) ;
36
+ buf. push ( byte ) ;
35
37
}
36
- buf. push ( '"' ) ;
38
+ buf. push ( b '"') ;
37
39
}
Original file line number Diff line number Diff line change @@ -20,6 +20,6 @@ fn quote_command_line_args() {
20
20
for & Case { args, expected } in cases {
21
21
let args = args. iter ( ) . copied ( ) . map ( str:: to_owned) . collect :: < Vec < _ > > ( ) ;
22
22
let actual = quote_command_line_args ( & args) ;
23
- assert_eq ! ( actual, expected, "args {args:?}" ) ;
23
+ assert_eq ! ( str :: from_utf8 ( & actual) , Ok ( expected) , "args {args:?}" ) ;
24
24
}
25
25
}
Original file line number Diff line number Diff line change @@ -39,7 +39,7 @@ impl OwnedTargetMachine {
39
39
debug_info_compression : & CStr ,
40
40
use_emulated_tls : bool ,
41
41
argv0 : & str ,
42
- command_line_args : & str ,
42
+ command_line_args : & [ u8 ] ,
43
43
use_wasm_eh : bool ,
44
44
) -> Result < Self , LlvmError < ' static > > {
45
45
// SAFETY: llvm::LLVMRustCreateTargetMachine copies pointed to data
You can’t perform that action at this time.
0 commit comments