Commit 5fdceeed authored by Libretro-Admin's avatar Libretro-Admin
Browse files

Remove trio remnants

parent 97721f60
Pipeline #44257 passed with stage
in 48 seconds
......@@ -21,7 +21,6 @@
#include "mednafen.h"
#include "error.h"
#include <trio/trio.h>
namespace Mednafen
{
......@@ -33,11 +32,13 @@ MDFN_Error::MDFN_Error()
MDFN_Error::MDFN_Error(int errno_code_new, const char *format, ...)
{
va_list ap;
char* ret = NULL;
errno_code = errno_code_new;
va_list ap;
va_start(ap, format);
error_message = trio_vaprintf(format, ap);
if (vasprintf(&ret, format, ap) != -1)
error_message = ret;
va_end(ap);
}
......
......@@ -20,7 +20,6 @@
#include "string/string.h"
#include "MemoryStream.h"
#include <trio/trio.h>
#include "state.h"
#include "video/Deinterlacer.h"
......@@ -316,7 +315,7 @@ static void StateAction_RINP(StateMem* sm, const unsigned load, const bool data_
{
for(unsigned x = 0; x < 16; x++)
{
trio_snprintf(namebuf[x], sizeof(namebuf[x]), "%02x%08x", x, PortDevice[x]);
snprintf(namebuf[x], sizeof(namebuf[x]), "%02x%08x", x, PortDevice[x]);
}
}
......@@ -354,8 +353,8 @@ void MDFN_indent(int indent)
static uint8 lastchar = 0;
void MDFN_printf(const char *format, ...)
{
char *format_temp;
char *temp;
char *format_temp = NULL;
char *temp = NULL;
unsigned int x, newlen;
va_list ap;
......@@ -394,7 +393,9 @@ void MDFN_printf(const char *format, ...)
format_temp[newlen] = 0;
temp = trio_vaprintf(format_temp, ap);
char* ret = NULL;
if (vasprintf(&ret, format_temp, ap) != -1)
temp = ret;
free(format_temp);
MDFND_OutputInfo(temp);
......@@ -405,17 +406,16 @@ void MDFN_printf(const char *format, ...)
void MDFN_Notify(MDFN_NoticeType t, const char* format, ...)
{
char* s;
va_list ap;
char*ret = NULL;
char* s = NULL;
va_start(ap, format);
s = trio_vaprintf(format, ap);
if(!s)
{
MDFND_OutputNotice(t, "Error allocating memory for the message!");
}
else
if(vasprintf(&ret, format, ap) != -1)
s = ret;
if(s)
{
MDFND_OutputNotice(t, s);
free(s);
......
......@@ -43,43 +43,6 @@ namespace MThreading
using namespace Win32Common;
#if 0
typedef struct
{
union
{
void* something;
unsigned char lalala[64];
};
} NAKED_CONDITION_VARIABLE;
static int use_cv = -1;
static HMODULE kdh = NULL;
static void WINAPI (*p_InitializeConditionVariable)(NAKED_CONDITION_VARIABLE*) = NULL;
static BOOL WINAPI (*p_SleepConditionVariableCS)(NAKED_CONDITION_VARIABLE*, PCRITICAL_SECTION, DWORD) = NULL;
static void WINAPI (*p_WakeConditionVariable)(NAKED_CONDITION_VARIABLE*) = NULL;
template<typename T>
static bool GetPAW(HMODULE dll_handle, T& pf, const char *name)
{
pf = (T)GetProcAddress(dll_handle, name);
return(pf != NULL);
}
static void InitCVStuff(void)
{
kdh = LoadLibrary("Kernel32.dll");
GetPAW(kdh, p_InitializeConditionVariable, "InitializeConditionVariable");
GetPAW(kdh, p_SleepConditionVariableCS, "SleepConditionVariableCS");
GetPAW(kdh, p_WakeConditionVariable, "WakeConditionVariable");
use_cv = (p_InitializeConditionVariable && p_SleepConditionVariableCS && p_WakeConditionVariable);
fprintf(stderr, "use_cv=%d\n", use_cv);
}
#endif
struct Thread
{
HANDLE thr;
......@@ -89,13 +52,6 @@ struct Thread
struct Cond
{
#if 0
union
{
HANDLE evt;
NAKED_CONDITION_VARIABLE cv;
};
#endif
HANDLE evt;
};
......@@ -109,26 +65,9 @@ struct Mutex
CRITICAL_SECTION cs;
};
static NO_INLINE void TestStackAlign(void)
{
alignas(16) char test_array[17];
unsigned volatile memloc = ((unsigned long long)&test_array[0]);
assert((memloc & 0xF) == 0);
//unsigned char memloc = ((unsigned long long)&test_array[0]) & 0xFF;
//assert(((((memloc * 0x80200802ULL) & 0x0884422110ULL) * 0x0101010101ULL) >> 36) == 0);
//printf("%02x\n", memloc);
//trio_snprintf(test_array, sizeof(test_array), "%02x", memloc);
//assert(test_array[1] == '0');
}
static unsigned __stdcall ThreadPivot(void* data) __attribute__((force_align_arg_pointer));
static unsigned __stdcall ThreadPivot(void* data)
{
TestStackAlign();
Thread* t = (Thread*)data;
return t->fn(t->data);
......@@ -138,11 +77,6 @@ Thread* Thread_Create(int (*fn)(void *), void *data, const char* debug_name)
{
Thread* ret = NULL;
#if 0
if(use_cv < 0)
InitCVStuff();
#endif
if(!(ret = (Thread*)calloc(1, sizeof(Thread))))
{
return NULL;
......@@ -227,88 +161,33 @@ bool Mutex_Unlock(Mutex* mutex)
Cond* Cond_Create(void)
{
#if 0
if(use_cv < 0)
InitCVStuff();
#endif
Cond* ret;
if(!(ret = (Cond*)calloc(1, sizeof(Cond))))
{
return NULL;
}
#if 0
if(use_cv)
{
memset(ret->cv.lalala, 0xAA, 64);
p_InitializeConditionVariable(&ret->cv);
for(int i = 0; i < 64; i++)
{
printf("%2d: %02x\n", i, ret->cv.lalala[i]);
}
}
else
#endif
{
if(!(ret->evt = CreateEvent(NULL, FALSE, FALSE, NULL)))
{
free(ret);
throw MDFN_Error(0, _("%s failed: %s"), "CreateEvent()", ErrCodeToString(GetLastError()).c_str());
}
}
return ret;
}
void Cond_Destroy(Cond* cond)
{
#if 0
if(use_cv)
{
}
else
#endif
{
CloseHandle(cond->evt);
}
free(cond);
}
bool Cond_Signal(Cond* cond)
{
#if 0
if(use_cv)
{
p_WakeConditionVariable(&cond->cv);
return true;
}
else
#endif
{
return SetEvent(cond->evt) != 0;
}
}
bool Cond_Wait(Cond* cond, Mutex* mutex)
{
#if 0
if(use_cv)
{
if(p_SleepConditionVariableCS(&cond->cv, &mutex->cs, INFINITE) == 0)
{
fprintf(stderr, "SleepConditionVariableCS() failed.\n");
return false;
}
return true;
}
else
#endif
{
LeaveCriticalSection(&mutex->cs);
WaitForSingleObject(cond->evt, INFINITE);
......@@ -316,26 +195,12 @@ bool Cond_Wait(Cond* cond, Mutex* mutex)
EnterCriticalSection(&mutex->cs);
return true;
}
}
bool Cond_TimedWait(Cond* cond, Mutex* mutex, unsigned ms)
{
bool ret = true;
#if 0
if(use_cv)
{
if(p_SleepConditionVariableCS(&cond->cv, &mutex->cs, ms) == 0)
{
fprintf(stderr, "SleepConditionVariableCS() failed.\n");
ret = false;
}
return ret;
}
else
#endif
{
ResetEvent(cond->evt); // Reset before unlocking mutex.
LeaveCriticalSection(&mutex->cs);
......@@ -355,7 +220,6 @@ bool Cond_TimedWait(Cond* cond, Mutex* mutex, unsigned ms)
}
EnterCriticalSection(&mutex->cs);
}
return ret;
}
......
......@@ -96,7 +96,7 @@ static bool MR_StringToDouble(const char* string_value, double* dvalue)
if(!MR_Radix)
{
char buf[64]; // Use extra-large buffer since we're using sprintf() instead of snprintf() for portability reasons. //4];
// Use libc snprintf() and not trio_snprintf() here for out little abomination.
// Use libc snprintf() and not snprintf() here for out little abomination.
//snprintf(buf, 4, "%.1f", (double)1);
sprintf(buf, "%.1f", (double)1);
if(buf[0] == '1' && buf[2] == '0' && buf[3] == 0)
......
#define trio_vsnprintf vsnprintf
#define trio_sprintf sprintf
#define trio_snprintf snprintf
#define trio_vasprintf vasprintf
static inline char* trio_vaprintf(const char* format, va_list ap)
{
char* ret = nullptr;
if(vasprintf(&ret, format, ap) == -1)
{
//errno = ENOMEM;
return nullptr;
}
return ret;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment