Skip to content

ctest: support variadics in function pointers #4367

Description

@tgross35

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.

Activity

  1. added
    ctestIssues relating to the ctest crate
    on Apr 3, 2025
  2. tgross35 commented on Aug 4, 2026

    @tgross35
    MemberAuthor

    We have the c_variadic feature stabilizing in the next version rust-lang/rust#155697, this should make things more workable.

  3. tgross35 commented on Aug 4, 2026

    @tgross35
    MemberAuthor

    @mbyx I think that with c_variadic being stabilized this may "just work" now (assuming we test on nightly of course). Would you mind submitting a PR testing it?

  4. tgross35 commented on Aug 4, 2026

    @tgross35
    MemberAuthor

    Actually some of the syntax bits may have to be updated to emit ...

  5. mbyx commented on Aug 7, 2026

    @mbyx
    Contributor

    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_ptr function 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.

  6. changed the title [-]ctest: support varidics[/-] [+]ctest: support variadics[/+] on Aug 9, 2026
  7. tgross35 commented on Aug 9, 2026

    @tgross35
    MemberAuthor

    That PR pretty much fixed everything but it would be good to handle function pointers as well, so I'll reopen for that

  8. changed the title [-]ctest: support variadics[/-] [+]ctest: support variadics in function pointers[/+] on Aug 9, 2026
  9. mbyx commented on Aug 9, 2026

    @mbyx
    Contributor

    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.

  10. tgross35 commented on Aug 9, 2026

    @tgross35
    MemberAuthor

    Oh awesome! Yeah that's all, a test would be great

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    ctestIssues relating to the ctest crate

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions