Skip to content

Commit c277bcc

Browse files
committed
Return usize and input usize
1 parent a2ce948 commit c277bcc

3 files changed

Lines changed: 8 additions & 9 deletions

File tree

cpp2rust/converter/models/converter_refcount.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1315,8 +1315,7 @@ bool ConverterRefCount::VisitExplicitCastExpr(clang::ExplicitCastExpr *expr) {
13151315
dst_type = ToString(expr->getType());
13161316
}
13171317
if (expr->getCastKind() == clang::CastKind::CK_PointerToIntegral) {
1318-
StrCat(std::format("{}.to_int::<{}>()", ToString(expr->getSubExpr()),
1319-
dst_type));
1318+
StrCat(std::format("{}.to_int()", ToString(expr->getSubExpr())));
13201319
computed_expr_type_ = ComputedExprType::FreshValue;
13211320
} else {
13221321
StrCat(std::format("<{}>::from_int({})", dst_type,

libcc2rs/src/rc.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,25 +1212,25 @@ impl<T: 'static> ByteRepr for Ptr<T> {}
12121212
impl ByteRepr for AnyPtr {}
12131213

12141214
impl<T: 'static> Ptr<T> {
1215-
pub fn to_int<U: ByteRepr>(&self) -> U {
1215+
pub fn to_int(&self) -> usize {
12161216
let mut buf = vec![0u8; Self::byte_size()];
12171217
self.to_bytes(&mut buf);
1218-
U::from_bytes(&buf[..U::byte_size()])
1218+
usize::from_bytes(&buf[..std::mem::size_of::<usize>()])
12191219
}
12201220

1221-
pub fn from_int<U: ByteRepr>(value: U) -> Self {
1221+
pub fn from_int(value: usize) -> Self {
12221222
let mut buf = vec![0u8; Self::byte_size()];
1223-
value.to_bytes(&mut buf[..U::byte_size()]);
1223+
value.to_bytes(&mut buf[..std::mem::size_of::<usize>()]);
12241224
Self::from_bytes(&buf)
12251225
}
12261226
}
12271227

12281228
impl AnyPtr {
1229-
pub fn to_int<U: ByteRepr>(&self) -> U {
1229+
pub fn to_int(&self) -> usize {
12301230
self.reinterpret_cast::<u8>().to_int()
12311231
}
12321232

1233-
pub fn from_int<U: ByteRepr>(value: U) -> Self {
1233+
pub fn from_int(value: usize) -> Self {
12341234
Ptr::<u8>::from_int(value).to_any()
12351235
}
12361236
}

tests/unit/out/refcount/unconst.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ fn main_0() -> i32 {
1313
let a: Value<i32> = Rc::new(RefCell::new(1));
1414
let p: Value<Ptr<i32>> = Rc::new(RefCell::new((a.as_pointer())));
1515
let q: Value<Ptr<i32>> = Rc::new(RefCell::new(
16-
(<AnyPtr>::from_int(((*p.borrow()).clone() as Ptr<i32>).to_any().to_int::<u64>()))
16+
(<AnyPtr>::from_int(((*p.borrow()).clone() as Ptr<i32>).to_any().to_int()))
1717
.reinterpret_cast::<i32>(),
1818
));
1919
assert!({

0 commit comments

Comments
 (0)