Skip to content

Commit 66d6621

Browse files
committed
Allow char*/void* <-> T* conversions in adapter
1 parent fd3a2a3 commit 66d6621

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

cpp2rust/converter/models/converter_refcount.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,18 @@ std::string ConverterRefCount::BuildFnAdapter(
196196
auto tgt_pty = target_proto->getParamType(i);
197197
if (ToString(src_pty) == ToString(tgt_pty)) {
198198
closure += std::format("a{}", i);
199-
} else if (src_pty->isPointerType() && tgt_pty->isVoidPointerType()) {
200-
closure += std::format("a{}.cast::<{}>().unwrap()", i,
201-
GetPointeeRustType(src_pty));
202-
} else if (src_pty->isVoidPointerType() && tgt_pty->isPointerType()) {
203-
closure += std::format("a{}.to_any()", i);
199+
} else if (src_pty->isPointerType() && tgt_pty->isPointerType()) {
200+
if (tgt_pty->isVoidPointerType()) {
201+
closure += std::format("a{}.cast::<{}>().unwrap()", i,
202+
GetPointeeRustType(src_pty));
203+
} else if (src_pty->isVoidPointerType()) {
204+
closure += std::format("a{}.to_any()", i);
205+
} else if (tgt_pty->getPointeeType()->isCharType()) {
206+
closure += std::format("a{}.reinterpret_cast::<{}>()", i,
207+
GetPointeeRustType(src_pty));
208+
} else if (src_pty->getPointeeType()->isCharType()) {
209+
closure += std::format("a{}.reinterpret_cast::<u8>()", i);
210+
}
204211
} else {
205212
// UB: Incompatible types
206213
return "None";

0 commit comments

Comments
 (0)