Repository navigation
ctest: support variadics in function pointers #4367
Description
Activity
- addedctestIssues relating to the ctest crateIssues relating to the ctest crate
on Apr 3, 2025 We have the
c_variadicfeature stabilizing in the next version rust-lang/rust#155697, this should make things more workable.@mbyx I think that with
c_variadicbeing stabilized this may "just work" now (assuming we test on nightly of course). Would you mind submitting a PR testing it?Actually some of the syntax bits may have to be updated to emit
...Actually, since the way foreign functions are tested changed in the new ctest, we don't construct the type at all. The variadic part remains in the C source, but is never used in the .C test (because we cast to a void pointer), nor in the Rust test (since we just call the
foreign_fn_ptrfunction that takes no arguments and just returns a function pointer with no type information).It would really only affect structs that have a function pointer I think.
That PR pretty much fixed everything but it would be good to handle function pointers as well, so I'll reopen for that
- changed the title
[-]ctest: support variadics[/-][+]ctest: support variadics in function pointers[/+]on Aug 9, 2026 I believe the PR also handles function pointers as well. I just checked locally by adding a variadic function pointer to a struct field in the
tests, and the tests seem to pass:struct Person { const char *name; uint8_t age; void (*job)(uint8_t, const char *, ...); enum Color favorite_color; };
Which generates this test (among others):
typedef void (**ctest_field_ty__Person__job)(uint8_t, const char *, ...); CTEST_EXTERN ctest_field_ty__Person__job ctest_field_ptr__Person__job(struct Person *b) { ctest_field_ty__Person__job ptr; ptr = &b->job; (void)ptr; return &b->job; }
If this is enough, then when I eventually make a PR regarding testing improvements, I'll add in this specific test as well.
Oh awesome! Yeah that's all, a test would be great
ctest should be able to generate tests for functions that make use of varidics. See JohnTitor/ctest2#58 for context.
Edit: The above works since #5385, but we should ideallly cover variadics in function pointer aliases and struct/union fields as well.