Skip to content

Commit 574ecf0

Browse files
committed
Use c_char in unsafe and u8 in refcount
1 parent 49bea74 commit 574ecf0

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

cpp2rust/converter/mapper.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,14 @@ void addBuiltinTypes(Model model) {
530530
}
531531

532532
// Char
533-
add_builtin_rule(ctx_->CharTy, "core::ffi::c_char");
533+
switch (model) {
534+
case Model::kUnsafe:
535+
add_builtin_rule(ctx_->CharTy, "libc::c_char");
536+
break;
537+
case Model::kRefCount:
538+
add_builtin_rule(ctx_->CharTy, "u8");
539+
break;
540+
}
534541
add_builtin_rule(ctx_->SignedCharTy, "i8");
535542
add_builtin_rule(ctx_->UnsignedCharTy, "u8");
536543

cpp2rust/converter/models/converter_refcount.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,16 +1097,14 @@ bool ConverterRefCount::VisitStringLiteral(clang::StringLiteral *expr) {
10971097
if (auto *arr_ty = ctx_.getAsConstantArrayType(curr_init_type_.back())) {
10981098
uint64_t arr_size = arr_ty->getSize().getZExtValue();
10991099
if (expr->getString().empty()) {
1100-
StrCat(std::format(
1101-
"vec![0 as core::ffi::c_char; {}].into_boxed_slice()", arr_size));
1100+
StrCat(std::format("vec![0u8; {}].into_boxed_slice()", arr_size));
11021101
return false;
11031102
}
11041103
pad = arr_size > expr->getString().size()
11051104
? arr_size - expr->getString().size()
11061105
: 0;
11071106
}
1108-
StrCat(std::format("Box::from(libcc2rs::char_array(b{}))",
1109-
GetEscapedStringLiteral(expr, pad)));
1107+
StrCat(std::format("Box::from(*b{})", GetEscapedStringLiteral(expr, pad)));
11101108
return false;
11111109
}
11121110
StrCat(std::format("b{}", GetEscapedStringLiteral(expr, 0)));

0 commit comments

Comments
 (0)