Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

For every variadic function, add a va_list function to the public api #10907

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

madebr
Copy link
Contributor

@madebr madebr commented Sep 20, 2024

By providing these va_list alternatives, SDL_dynapi.c can be simplified.
It should also help #9580.

What changed:
SDL_dynapi_proc.h now uses 3 macros:

  • SDL_DYNAPI_PROC: behavior does not change
  • SDL_DYNAPI_VPROC: variadic function returning something
  • SDL_DYNAPI_VOID_VPROC: variadic function returning void

The *_VPROC macros accept 2 additional arguments: forwardfn and last_arg. This is the va_list ap function to which it should forward its arguments. The last_arg is used as 2nd argument to va_start.

I simply appended a V to the va_list alternatives.

Homework for slouken and icculus:

  • come up with better names for the macros and functions
  • review whether my changes to the headers are good, and orderered okay (perhaps you want to move all V declarations to the bottom)

@slouken slouken added this to the 3.0 ABI milestone Sep 20, 2024
@slouken
Copy link
Collaborator

slouken commented Sep 20, 2024

My initial reaction is that it adds a bunch of entry points to the API and doesn't actually reduce or simplify much code, it just moves the complexity around. In addition, SDL_SetError() is now slightly slower, which is probably okay, but not a great selling point.

@icculus might be super happy about it though, so I'll defer to him. :)

va_start(ap, last_arg); \
jump_table.forwardfn args; \
va_end(ap); \
}
#define SDL_DYNAPI_PROC_NO_VARARGS 1
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These can go

@madebr
Copy link
Contributor Author

madebr commented Sep 20, 2024

In addition, SDL_SetError() is now slightly slower, which is probably okay, but not a great selling point.

I see the contrary on my system (which I don't understand).
Compiling the following source:

#include <SDL3/SDL.h>
#include <SDL3/SDL_main.h>
int main(int argc, char *argv[]) {
    Uint32 i;
    for (i = 0; i < 10000000; i++) {
        SDL_SetError("Time me %" SDL_PRIu32, i);
    }
    return 0;
}

and comparing times of SDL3 of current main and this pr branch, I see faster times on this pr branch.
I used "hyperfine" to do the benchmark.
I see 1.3s on current main, and 0.9s on this branch.

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