-
Notifications
You must be signed in to change notification settings - Fork 280
Open
Description
When the va_list type appears by value in a function parameter, c2rust translates it as a Rust VaList. That's correct. But when a function takes va_list * by pointer, then that gets translated as Rust *mut VaList, which is not correct. To see why, consider what such a pointer actually points to on architectures that use a dedicated struct type for va_list, such as x86-64 or Linux aarch64:
- In C,
va_listis a struct or array containing a struct. A pointerva_list *is thus a pointer to this struct or array. Dereferencing the pointer gives you the struct. - In Rust,
VaListdoes not contain the struct, which is inVaListImpl.VaListonly contains a reference to the struct. Thus, dereferencing*mut VaListgives you theVaList, which is not the struct but that reference. You need to dereferenceVaListagain to get the struct insideVaListImpl.
Clearly, these two are not equivalent and therefore not ABI compatible. The correct translation would be to use VaListImpl normally, but VaList if and only if C passes va_list by value. va_list * by pointer should always be translated to *mut VaListImpl.
Metadata
Metadata
Assignees
Labels
No labels