libretro-mirrors / libretro-arb

For proposed improvements to libretro API.
8 stars 2 forks source link

Use va_lists in retro_log_callback #28

Closed heuripedes closed 9 years ago

heuripedes commented 9 years ago

retro_log_callback is currently defined as

typedef void (*retro_log_printf_t)(enum retro_log_level level, const char *fmt, ...);

struct retro_log_callback
{
   retro_log_printf_t log;
};

Due to the lack of va_call macro/function in the C language, providing only a variadic function pointer is an inflexible way to support callbacks because it does not allow the developer to make wrappers if he so desires/needs. One use case for this would be preprocessing (e.g. adding extra data to the log message) or displaying the log message on the screen (e.g. in-game debug console).

What I propose is vprintf()-style callback that could either replace retro_log_printf_t or be appended to the retro_log_callback:

typedef void (*retro_log_vprintf_t)(enum retro_log_level level, const char *fmt,
                                    va_list args);

The first option does break the ABI but I'm not entirely sure about the effects of second one.

Alcaro commented 9 years ago

This structure is allocated by the core, and written by the front. If the front thinks it sees the new structure, but the core has only allocated enough space for the old one, the front will scribble over something random, for example a return address. That is indeed an ABI break, and you know our policy on that.

I don't want to introduce a new env for this either, for various reasons:

For libretro v2, I want this logger replaced with a plain const char*. It's kinda irritating to work with ...s outside of C/C++.

You're very welcome to use va_start in the front, though. Or asprintf()/vasprintf() and do whatever with the resulting char*.