Skip to content

R_CallMethodDef callMethods[] mostly don't specify the number of arguments. #7948

Open

Description

@aitap

WRE 5.4 specifies that R can check the number of arguments given to .Call when invoking package-registered routines. (The actual code doing this is a bit scary, because FFI is hard.) This is important because calling a function through an incompatible function pointer is undefined behaviour in C. The exact consequences can range from almost harmless (the missing argument contains garbage, which you can ignore / the extra argument is just invisible to the function) to complete stack corruption and a quick crash.

Most functions registered for use with .Call in data.table specify -1 instead of the number of arguments. While I'm sure that all calls from R to C code in data.table currently use the correct number of arguments, explicitly specifying this will surface accidental future mistakes immediately instead of causing hard-to-debug crashes.

Tagging this for @igorsteinmacher.

Activity

  1. MichaelChirico commented on Oct 27, 2026

    @MichaelChirico
    Member

    The old justification for this from Matt, IIRC, was just avoiding churn with making sure those numbers remain correct through the development life cycle.

    I'm not compelled that that's a good reason to keep using -1 -- the API is relatively stable at this point, and we can easily write a linter to prevent backsliding if that's seen as a major concern.

    So +1 to making the change here.

  2. aitap commented on Oct 27, 2026

    @aitap
    MemberAuthor

    That's useful to know, thank you!

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions