فهرست منبع

Revert "dynapi: Remove unused ENABLE_SDL_CALL_LOGGING code."

This reverts commit 9128f92f38aef54a674ae574111818b8cd56b069.

Apparently this is useful for debugging from time to time!
Ryan C. Gordon 1 سال پیش
والد
کامیت
acf811a06b
1فایلهای تغییر یافته به همراه121 افزوده شده و 0 حذف شده
  1. 121 0
      src/dynapi/SDL_dynapi.c

+ 121 - 0
src/dynapi/SDL_dynapi.c

@@ -230,6 +230,111 @@ SDL_DYNAPI_VARARGS(static, _DEFAULT, SDL_InitDynamicAPI())
 #undef SDL_DYNAPI_PROC_NO_VARARGS
 SDL_DYNAPI_VARARGS(, , )
 
+#define ENABLE_SDL_CALL_LOGGING 0
+#if ENABLE_SDL_CALL_LOGGING
+static int SDLCALL SDL_SetError_LOGSDLCALLS(SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
+{
+    char buf[512]; /* !!! FIXME: dynamic allocation */
+    va_list ap;
+    SDL_Log_REAL("SDL3CALL SDL_SetError");
+    va_start(ap, fmt);
+    SDL_vsnprintf_REAL(buf, sizeof(buf), fmt, ap);
+    va_end(ap);
+    return SDL_SetError_REAL("%s", buf);
+}
+static int SDLCALL SDL_sscanf_LOGSDLCALLS(const char *buf, SDL_SCANF_FORMAT_STRING const char *fmt, ...)
+{
+    int retval;
+    va_list ap;
+    SDL_Log_REAL("SDL3CALL SDL_sscanf");
+    va_start(ap, fmt);
+    retval = SDL_vsscanf_REAL(buf, fmt, ap);
+    va_end(ap);
+    return retval;
+}
+static int SDLCALL SDL_snprintf_LOGSDLCALLS(SDL_OUT_Z_CAP(maxlen) char *buf, size_t maxlen, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
+{
+    int retval;
+    va_list ap;
+    SDL_Log_REAL("SDL3CALL SDL_snprintf");
+    va_start(ap, fmt);
+    retval = SDL_vsnprintf_REAL(buf, maxlen, fmt, ap);
+    va_end(ap);
+    return retval;
+}
+static int SDLCALL SDL_asprintf_LOGSDLCALLS(char **strp, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
+{
+    int retval;
+    va_list ap;
+    SDL_Log_REAL("SDL3CALL SDL_asprintf");
+    va_start(ap, fmt);
+    retval = SDL_vasprintf_REAL(strp, fmt, ap);
+    va_end(ap);
+    return retval;
+}
+static int SDLCALL SDL_swprintf_LOGSDLCALLS(SDL_OUT_Z_CAP(maxlen) wchar_t *buf, size_t maxlen, SDL_PRINTF_FORMAT_STRING const wchar_t *fmt, ...)
+{
+    int retval;
+    va_list ap;
+    SDL_Log_REAL("SDL3CALL SDL_swprintf");
+    va_start(ap, fmt);
+    retval = SDL_vswprintf_REAL(buf, maxlen, fmt, ap);
+    va_end(ap);
+    return retval;
+}
+_static size_t SDLCALL SDL_IOprintf_LOGSDLCALLS(SDL_IOStream *context, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
+{
+    size_t retval;
+    va_list ap;
+    SDL_Log_REAL("SDL3CALL SDL_IOprintf");
+    va_start(ap, fmt);
+    retval = SDL_IOvprintf_REAL(context, fmt, ap);
+    va_end(ap);
+    return retval;
+}
+static void SDLCALL SDL_Log_LOGSDLCALLS(SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
+{
+    va_list ap;
+    SDL_Log_REAL("SDL3CALL SDL_Log");
+    va_start(ap, fmt);
+    SDL_LogMessageV_REAL(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, fmt, ap);
+    va_end(ap);
+}
+static void SDLCALL SDL_LogMessage_LOGSDLCALLS(int category, SDL_LogPriority priority, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
+{
+    va_list ap;
+    SDL_Log_REAL("SDL3CALL SDL_LogMessage");
+    va_start(ap, fmt);
+    SDL_LogMessageV_REAL(category, priority, fmt, ap);
+    va_end(ap);
+}
+#define SDL_DYNAPI_VARARGS_LOGFN_LOGSDLCALLS(logname, prio)                                                         \
+    static void SDLCALL SDL_Log##logname##_LOGSDLCALLS(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) \
+    {                                                                                                               \
+        va_list ap;                                                                                                 \
+        va_start(ap, fmt);                                                                                          \
+        SDL_Log_REAL("SDL3CALL SDL_Log%s", #logname);                                                               \
+        SDL_LogMessageV_REAL(category, SDL_LOG_PRIORITY_##prio, fmt, ap);                                           \
+        va_end(ap);                                                                                                 \
+    }
+SDL_DYNAPI_VARARGS_LOGFN_LOGSDLCALLS(Verbose, VERBOSE)
+SDL_DYNAPI_VARARGS_LOGFN_LOGSDLCALLS(Debug, DEBUG)
+SDL_DYNAPI_VARARGS_LOGFN_LOGSDLCALLS(Info, INFO)
+SDL_DYNAPI_VARARGS_LOGFN_LOGSDLCALLS(Warn, WARN)
+SDL_DYNAPI_VARARGS_LOGFN_LOGSDLCALLS(Error, ERROR)
+SDL_DYNAPI_VARARGS_LOGFN_LOGSDLCALLS(Critical, CRITICAL)
+#define SDL_DYNAPI_PROC(rc, fn, params, args, ret) \
+    rc SDLCALL fn##_LOGSDLCALLS params             \
+    {                                              \
+        SDL_Log_REAL("SDL3CALL %s", #fn);          \
+        ret fn##_REAL args;                        \
+    }
+#define SDL_DYNAPI_PROC_NO_VARARGS 1
+#include "SDL_dynapi_procs.h"
+#undef SDL_DYNAPI_PROC
+#undef SDL_DYNAPI_PROC_NO_VARARGS
+#endif
+
 /* we make this a static function so we can call the correct one without the
    system's dynamic linker resolving to the wrong version of this. */
 static Sint32 initialize_jumptable(Uint32 apiver, void *table, Uint32 tablesize)
@@ -244,9 +349,25 @@ static Sint32 initialize_jumptable(Uint32 apiver, void *table, Uint32 tablesize)
     }
 
 /* Init our jump table first. */
+#if ENABLE_SDL_CALL_LOGGING
+    {
+        const char *env = SDL_getenv_REAL("SDL_DYNAPI_LOG_CALLS");
+        const SDL_bool log_calls = (env && SDL_atoi_REAL(env));
+        if (log_calls) {
+#define SDL_DYNAPI_PROC(rc, fn, params, args, ret) jump_table.fn = fn##_LOGSDLCALLS;
+#include "SDL_dynapi_procs.h"
+#undef SDL_DYNAPI_PROC
+        } else {
+#define SDL_DYNAPI_PROC(rc, fn, params, args, ret) jump_table.fn = fn##_REAL;
+#include "SDL_dynapi_procs.h"
+#undef SDL_DYNAPI_PROC
+        }
+    }
+#else
 #define SDL_DYNAPI_PROC(rc, fn, params, args, ret) jump_table.fn = fn##_REAL;
 #include "SDL_dynapi_procs.h"
 #undef SDL_DYNAPI_PROC
+#endif
 
     /* Then the external table... */
     if (output_jump_table != &jump_table) {