Skip to content

Commit 43865ca

Browse files
committed
Replace ::core::ffi::c_char with core::ffi::c_char
1 parent 93bdb87 commit 43865ca

147 files changed

Lines changed: 1690 additions & 1775 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎cpp2rust/converter/converter.cpp‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ bool Converter::VisitBuiltinType(clang::BuiltinType *type) {
124124
break;
125125
case clang::BuiltinType::Char_S:
126126
case clang::BuiltinType::Char_U:
127-
StrCat("::core::ffi::c_char");
127+
StrCat("core::ffi::c_char");
128128
break;
129129
case clang::BuiltinType::SChar:
130130
StrCat("i8");
@@ -1379,7 +1379,7 @@ bool Converter::GetFmtArg(clang::Expr *arg, std::string &fmt,
13791379
} else if (arg_str.contains("Setw")) {
13801380
fmt_width = Trim(ToString(arg));
13811381
} else if (!arg->getType()->isCharType() &&
1382-
Mapper::Map(arg->getType()) != "Vec<::core::ffi::c_char>") {
1382+
Mapper::Map(arg->getType()) != "Vec<core::ffi::c_char>") {
13831383
fmt += ("{:" + fmt_width + fmt_trait + "}");
13841384
fmt_width.clear(); // Reset setw after first usage
13851385
arg_str = ToString(arg);
@@ -1396,7 +1396,7 @@ bool Converter::GetFmtArg(clang::Expr *arg, std::string &fmt,
13961396
bool Converter::GetRawArg(clang::Expr *arg, std::string &raw_args) {
13971397
if (arg->getType()->isCharType()) {
13981398
raw_args += "(&[" + ToString(arg) + " as u8]";
1399-
} else if (Mapper::Map(arg->getType()) == "Vec<::core::ffi::c_char>") {
1399+
} else if (Mapper::Map(arg->getType()) == "Vec<core::ffi::c_char>") {
14001400
PushExprKind push(*this, ExprKind::RValue);
14011401
std::string str = ToString(arg);
14021402
raw_args += "(&(" + str + ").iter().take((" + str +
@@ -1921,7 +1921,7 @@ bool Converter::VisitStringLiteral(clang::StringLiteral *expr) {
19211921
if (auto *arr_ty = ctx_.getAsConstantArrayType(curr_init_type_.back())) {
19221922
uint64_t arr_size = arr_ty->getSize().getZExtValue();
19231923
if (expr->getString().empty()) {
1924-
StrCat(std::format("[0 as ::core::ffi::c_char; {}]", arr_size));
1924+
StrCat(std::format("[0 as core::ffi::c_char; {}]", arr_size));
19251925
return false;
19261926
}
19271927
uint64_t pad = arr_size > expr->getString().size()
@@ -3717,7 +3717,7 @@ void Converter::ConvertFunctionMain(const clang::FunctionDecl *decl,
37173717
pub fn main() {{
37183718
let mut args: Vec<Vec<u8>> = std::env::args().map(|arg| arg.as_bytes().to_vec()).collect();
37193719
args.iter_mut().for_each(|v| v.push(0));
3720-
let mut argv: Vec<*mut ::core::ffi::c_char> = args.iter().map(|arg| arg.as_ptr() as *mut ::core::ffi::c_char).collect();
3720+
let mut argv: Vec<*mut core::ffi::c_char> = args.iter().map(|arg| arg.as_ptr() as *mut core::ffi::c_char).collect();
37213721
argv.push(::std::ptr::null_mut());
37223722
unsafe {{
37233723
::std::process::exit(main_0((argv.len() - 1) as i32, argv.as_mut_ptr()) as i32)

‎cpp2rust/converter/mapper.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ void addBuiltinTypes(Model model) {
524524
}
525525

526526
// Char
527-
add_builtin_rule(ctx_->CharTy, "::core::ffi::c_char");
527+
add_builtin_rule(ctx_->CharTy, "core::ffi::c_char");
528528
add_builtin_rule(ctx_->SignedCharTy, "i8");
529529
add_builtin_rule(ctx_->UnsignedCharTy, "u8");
530530

‎cpp2rust/converter/models/converter_refcount.cpp‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,7 +1038,7 @@ bool ConverterRefCount::VisitStringLiteral(clang::StringLiteral *expr) {
10381038
uint64_t arr_size = arr_ty->getSize().getZExtValue();
10391039
if (expr->getString().empty()) {
10401040
StrCat(std::format(
1041-
"vec![0 as ::core::ffi::c_char; {}].into_boxed_slice()", arr_size));
1041+
"vec![0 as core::ffi::c_char; {}].into_boxed_slice()", arr_size));
10421042
return false;
10431043
}
10441044
pad = arr_size > expr->getString().size()
@@ -2098,7 +2098,7 @@ bool ConverterRefCount::ConvertCXXOperatorCallExpr(
20982098
void ConverterRefCount::ConvertFunctionParameters(clang::FunctionDecl *decl) {
20992099
PushConversionKind push(*this, ConversionKind::Unboxed);
21002100
if (decl->isMain() && (decl->getNumParams() != 0U)) {
2101-
StrCat(std::format("{}: i32, {}: Ptr<Ptr<::core::ffi::c_char>>",
2101+
StrCat(std::format("{}: i32, {}: Ptr<Ptr<core::ffi::c_char>>",
21022102
GetNamedDeclAsString(decl->getParamDecl(0)),
21032103
GetNamedDeclAsString(decl->getParamDecl(1))));
21042104
} else {
@@ -2181,10 +2181,10 @@ void ConverterRefCount::ConvertFunctionMain(
21812181
if (decl->getNumParams() != 0U) {
21822182
StrCat(std::format(R"(
21832183
pub fn main() {{
2184-
let argv: Vec<Value<Vec<::core::ffi::c_char>>> = ::std::env::args()
2185-
.map(|x| Rc::new(RefCell::new(x.bytes().map(|b| b as ::core::ffi::c_char).collect())))
2184+
let argv: Vec<Value<Vec<core::ffi::c_char>>> = ::std::env::args()
2185+
.map(|x| Rc::new(RefCell::new(x.bytes().map(|b| b as core::ffi::c_char).collect())))
21862186
.collect();
2187-
let mut argv: Value<Vec<Ptr<::core::ffi::c_char>>> = Rc::new(RefCell::new(
2187+
let mut argv: Value<Vec<Ptr<core::ffi::c_char>>> = Rc::new(RefCell::new(
21882188
argv.iter().map(|x| {{ x.borrow_mut().push(0); x.as_pointer() }}).collect(),
21892189
));
21902190
(*argv.borrow_mut()).push(Ptr::null());

‎rules/algorithm/tgt_refcount.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ fn f12<T1: Clone + ByteRepr>(a0: Ptr<T1>, a1: Ptr<T1>, a2: T1) {
104104

105105
// TODO: a2 should be passed as &mut
106106
fn f13(
107-
a0: Ptr<::core::ffi::c_char>,
108-
a1: Ptr<::core::ffi::c_char>,
107+
a0: Ptr<core::ffi::c_char>,
108+
a1: Ptr<core::ffi::c_char>,
109109
a2: &mut ::std::fs::File,
110110
) -> ::std::fs::File {
111111
a2.write_all(

‎rules/algorithm/tgt_unsafe.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ unsafe fn f12<T1: Clone>(a0: *mut T1, a1: *mut T1, a2: T1) {
102102
}
103103

104104
unsafe fn f13(
105-
a0: *const ::core::ffi::c_char,
106-
a1: *const ::core::ffi::c_char,
105+
a0: *const core::ffi::c_char,
106+
a1: *const core::ffi::c_char,
107107
a2: &mut ::std::fs::File,
108108
) -> ::std::fs::File {
109109
let __start = a0 as *const u8;

‎rules/arpa_inet/tgt_unsafe.rs‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,25 @@ unsafe fn f3(a0: u16) -> u16 {
1313
unsafe fn f4(a0: u32) -> u32 {
1414
u32::to_be(a0)
1515
}
16-
unsafe fn f5(a0: i32, a1: *const ::core::ffi::c_char, a2: *mut ::libc::c_void) -> i32 {
16+
unsafe fn f5(a0: i32, a1: *const core::ffi::c_char, a2: *mut ::libc::c_void) -> i32 {
1717
unsafe extern "C" {
18-
fn inet_pton(af: i32, src: *const ::core::ffi::c_char, dst: *mut ::libc::c_void) -> i32;
18+
fn inet_pton(af: i32, src: *const core::ffi::c_char, dst: *mut ::libc::c_void) -> i32;
1919
}
2020
inet_pton(a0, a1, a2)
2121
}
2222
unsafe fn f6(
2323
a0: i32,
2424
a1: *const ::libc::c_void,
25-
a2: *mut ::core::ffi::c_char,
25+
a2: *mut core::ffi::c_char,
2626
a3: u32,
27-
) -> *const ::core::ffi::c_char {
27+
) -> *const core::ffi::c_char {
2828
unsafe extern "C" {
2929
fn inet_ntop(
3030
af: i32,
3131
src: *const ::libc::c_void,
32-
dst: *mut ::core::ffi::c_char,
32+
dst: *mut core::ffi::c_char,
3333
size: u32,
34-
) -> *const ::core::ffi::c_char;
34+
) -> *const core::ffi::c_char;
3535
}
3636
inet_ntop(a0, a1, a2, a3)
3737
}

‎rules/cstdlib/tgt_unsafe.rs‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ unsafe fn f5(a0: usize, a1: usize) -> *mut ::libc::c_void {
2121
libcc2rs::calloc_unsafe(a0, a1)
2222
}
2323

24-
unsafe fn f6(a0: *const ::core::ffi::c_char) -> *mut ::core::ffi::c_char {
24+
unsafe fn f6(a0: *const core::ffi::c_char) -> *mut core::ffi::c_char {
2525
libc::getenv(a0)
2626
}
2727

28-
unsafe fn f7(a0: *const ::core::ffi::c_char, a1: *const ::core::ffi::c_char, a2: i32) -> i32 {
28+
unsafe fn f7(a0: *const core::ffi::c_char, a1: *const core::ffi::c_char, a2: i32) -> i32 {
2929
libc::setenv(a0, a1, a2)
3030
}
3131

@@ -65,9 +65,6 @@ unsafe fn f9(
6565
)
6666
}
6767

68-
unsafe fn f10(
69-
a0: *const ::core::ffi::c_char,
70-
a1: *mut ::core::ffi::c_char,
71-
) -> *mut ::core::ffi::c_char {
68+
unsafe fn f10(a0: *const core::ffi::c_char, a1: *mut core::ffi::c_char) -> *mut core::ffi::c_char {
7269
libc::realpath(a0, a1)
7370
}

‎rules/cstring/tgt_refcount.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ fn f4(a0: AnyPtr, a1: AnyPtr, a2: usize) -> AnyPtr {
2222
a0.clone()
2323
}
2424

25-
unsafe fn f7(a0: Ptr<::core::ffi::c_char>) -> usize {
25+
unsafe fn f7(a0: Ptr<core::ffi::c_char>) -> usize {
2626
a0.to_string_iterator().count()
2727
}

‎rules/cstring/tgt_unsafe.rs‎

Lines changed: 32 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -36,97 +36,91 @@ unsafe fn f4(a0: *mut u8, a1: *const u8, a2: usize) -> *mut u8 {
3636
a0
3737
}
3838

39-
unsafe fn f5(a0: *const ::core::ffi::c_char, a1: i32) -> *mut ::core::ffi::c_char {
39+
unsafe fn f5(a0: *const core::ffi::c_char, a1: i32) -> *mut core::ffi::c_char {
4040
libc::strchr(a0, a1)
4141
}
4242

43-
unsafe fn f6(a0: *const ::core::ffi::c_char, a1: i32) -> *const ::core::ffi::c_char {
44-
(libc::strchr(a0, a1) as *const ::core::ffi::c_char)
43+
unsafe fn f6(a0: *const core::ffi::c_char, a1: i32) -> *const core::ffi::c_char {
44+
(libc::strchr(a0, a1) as *const core::ffi::c_char)
4545
}
4646

47-
unsafe fn f7(a0: *const ::core::ffi::c_char) -> usize {
47+
unsafe fn f7(a0: *const core::ffi::c_char) -> usize {
4848
libc::strlen(a0)
4949
}
5050

51-
unsafe fn f8(a0: *const ::core::ffi::c_char, a1: *const ::core::ffi::c_char) -> i32 {
51+
unsafe fn f8(a0: *const core::ffi::c_char, a1: *const core::ffi::c_char) -> i32 {
5252
libc::strcmp(a0, a1)
5353
}
5454

55-
unsafe fn f9(a0: *const ::core::ffi::c_char, a1: *const ::core::ffi::c_char, a2: usize) -> i32 {
55+
unsafe fn f9(a0: *const core::ffi::c_char, a1: *const core::ffi::c_char, a2: usize) -> i32 {
5656
libc::strncmp(a0, a1, a2 as usize)
5757
}
5858

5959
unsafe fn f10(a0: *const u8, a1: i32, a2: usize) -> *mut ::libc::c_void {
6060
libc::memchr(a0 as *const ::libc::c_void, a1, a2 as usize)
6161
}
6262

63-
unsafe fn f11(a0: *const ::core::ffi::c_char, a1: i32) -> *mut ::core::ffi::c_char {
63+
unsafe fn f11(a0: *const core::ffi::c_char, a1: i32) -> *mut core::ffi::c_char {
6464
libc::strrchr(a0, a1)
6565
}
6666

6767
unsafe fn f12(a0: *const u8, a1: i32, a2: usize) -> *const ::libc::c_void {
6868
libc::memchr(a0 as *const ::libc::c_void, a1, a2 as usize) as *const ::libc::c_void
6969
}
7070

71-
unsafe fn f13(a0: *const ::core::ffi::c_char, a1: i32) -> *const ::core::ffi::c_char {
72-
(libc::strrchr(a0, a1) as *const ::core::ffi::c_char)
71+
unsafe fn f13(a0: *const core::ffi::c_char, a1: i32) -> *const core::ffi::c_char {
72+
(libc::strrchr(a0, a1) as *const core::ffi::c_char)
7373
}
7474

75-
unsafe fn f14(a0: *mut ::core::ffi::c_char, a1: i32) -> *mut ::core::ffi::c_char {
75+
unsafe fn f14(a0: *mut core::ffi::c_char, a1: i32) -> *mut core::ffi::c_char {
7676
libc::strrchr(a0, a1)
7777
}
7878

79-
unsafe fn f15(a0: *const ::core::ffi::c_char) -> *mut ::core::ffi::c_char {
79+
unsafe fn f15(a0: *const core::ffi::c_char) -> *mut core::ffi::c_char {
8080
libcc2rs::strdup_unsafe(a0)
8181
}
8282

83-
unsafe fn f16(a0: *const ::core::ffi::c_char, a1: *const ::core::ffi::c_char) -> usize {
83+
unsafe fn f16(a0: *const core::ffi::c_char, a1: *const core::ffi::c_char) -> usize {
8484
libc::strcspn(a0, a1)
8585
}
8686

87-
unsafe fn f17(a0: *const ::core::ffi::c_char, a1: *const ::core::ffi::c_char) -> usize {
87+
unsafe fn f17(a0: *const core::ffi::c_char, a1: *const core::ffi::c_char) -> usize {
8888
libc::strspn(a0, a1)
8989
}
9090

9191
unsafe fn f18(
92-
a0: *const ::core::ffi::c_char,
93-
a1: *const ::core::ffi::c_char,
94-
) -> *mut ::core::ffi::c_char {
92+
a0: *const core::ffi::c_char,
93+
a1: *const core::ffi::c_char,
94+
) -> *mut core::ffi::c_char {
9595
libc::strstr(a0, a1)
9696
}
9797

9898
unsafe fn f19(
99-
a0: *const ::core::ffi::c_char,
100-
a1: *const ::core::ffi::c_char,
101-
) -> *const ::core::ffi::c_char {
102-
(libc::strstr(a0, a1) as *const ::core::ffi::c_char)
99+
a0: *const core::ffi::c_char,
100+
a1: *const core::ffi::c_char,
101+
) -> *const core::ffi::c_char {
102+
(libc::strstr(a0, a1) as *const core::ffi::c_char)
103103
}
104104

105-
unsafe fn f20(
106-
a0: *mut ::core::ffi::c_char,
107-
a1: *const ::core::ffi::c_char,
108-
) -> *mut ::core::ffi::c_char {
105+
unsafe fn f20(a0: *mut core::ffi::c_char, a1: *const core::ffi::c_char) -> *mut core::ffi::c_char {
109106
libc::strstr(a0, a1)
110107
}
111108

112109
unsafe fn f21(
113-
a0: *const ::core::ffi::c_char,
114-
a1: *const ::core::ffi::c_char,
115-
) -> *mut ::core::ffi::c_char {
110+
a0: *const core::ffi::c_char,
111+
a1: *const core::ffi::c_char,
112+
) -> *mut core::ffi::c_char {
116113
libc::strpbrk(a0, a1)
117114
}
118115

119116
unsafe fn f22(
120-
a0: *const ::core::ffi::c_char,
121-
a1: *const ::core::ffi::c_char,
122-
) -> *const ::core::ffi::c_char {
123-
(libc::strpbrk(a0, a1) as *const ::core::ffi::c_char)
117+
a0: *const core::ffi::c_char,
118+
a1: *const core::ffi::c_char,
119+
) -> *const core::ffi::c_char {
120+
(libc::strpbrk(a0, a1) as *const core::ffi::c_char)
124121
}
125122

126-
unsafe fn f23(
127-
a0: *mut ::core::ffi::c_char,
128-
a1: *const ::core::ffi::c_char,
129-
) -> *mut ::core::ffi::c_char {
123+
unsafe fn f23(a0: *mut core::ffi::c_char, a1: *const core::ffi::c_char) -> *mut core::ffi::c_char {
130124
libc::strpbrk(a0, a1)
131125
}
132126

@@ -145,7 +139,7 @@ unsafe fn f26(a0: *mut u8, a1: i32, a2: usize) -> *mut ::libc::c_void {
145139
libc::memrchr(a0 as *const ::libc::c_void, a1, a2 as usize)
146140
}
147141

148-
unsafe fn f27(a0: *const ::core::ffi::c_char, a1: *const ::core::ffi::c_char) -> i32 {
142+
unsafe fn f27(a0: *const core::ffi::c_char, a1: *const core::ffi::c_char) -> i32 {
149143
libc::strcasecmp(a0, a1)
150144
}
151145

@@ -157,12 +151,12 @@ unsafe fn f27(a0: *const ::core::ffi::c_char, a1: *const ::core::ffi::c_char) ->
157151
//
158152
// So it's not 100% correct to always return a1. But the Rust libc version only returns int.
159153
#[cfg(target_os = "linux")]
160-
unsafe fn f28(a0: i32, a1: *mut ::core::ffi::c_char, a2: usize) -> *mut ::core::ffi::c_char {
154+
unsafe fn f28(a0: i32, a1: *mut core::ffi::c_char, a2: usize) -> *mut core::ffi::c_char {
161155
libc::strerror_r(a0, a1, a2 as usize);
162156
a1
163157
}
164158

165159
#[cfg(target_os = "macos")]
166-
unsafe fn f28(a0: i32, a1: *mut ::core::ffi::c_char, a2: usize) -> i32 {
160+
unsafe fn f28(a0: i32, a1: *mut core::ffi::c_char, a2: usize) -> i32 {
167161
libc::strerror_r(a0, a1, a2 as usize)
168162
}

‎rules/dirent/tgt_unsafe.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ fn t1() -> *mut ::libc::DIR {
55
std::ptr::null_mut()
66
}
77

8-
unsafe fn f1(a0: *const ::core::ffi::c_char) -> *mut ::libc::DIR {
8+
unsafe fn f1(a0: *const core::ffi::c_char) -> *mut ::libc::DIR {
99
libc::opendir(a0)
1010
}
1111

0 commit comments

Comments
 (0)