Skip to content

Translate va_list references and pointers - #522

Merged
nunoplopes merged 6 commits into
Cpp2Rust:masterfrom
lucic71:16-va-list-field
Oct 11, 2026
Merged

nunoplopes merged 6 commits into
Cpp2Rust:masterfrom
lucic71:16-va-list-field

Conversation

@lucic71

@lucic71 lucic71 commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

No description provided.

@lucic71 lucic71 changed the title Translate va_list references and pointers in fields Translate va_list references and pointers Oct 9, 2026
Comment thread libcc2rs/src/va_args.rs Outdated
args: &'a [VaArg],
#[derive(Clone, Default)]
pub struct VaList {
args: Rc<[VaArg]>,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rc seems wrong as it may extend the lifetime of objects? Should it be Weak?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right. After applying your suggestion I realised that we can transform VaList into a Ptr<VaArg>. That makes sure the lifetime is not extended and uses the existing infrastructure.

pub fn sum_0(n: i32, __args: &[VaArg]) -> i32 {
let n: Value<i32> = Rc::new(RefCell::new(n));
let ap: Value<VaList> = Rc::new(RefCell::new(VaList::default()));
(*ap.borrow_mut()) = VaList::new(__args);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this line not folded in the one above?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First line is the declaration, second line is the call to va_start. There can be arbitrary many lines between the two.

@nunoplopes
nunoplopes merged commit 25d52d1 into Cpp2Rust:master Oct 11, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants