Update for SDL3 coding style (#6717)

I updated .clang-format and ran clang-format 14 over the src and test directories to standardize the code base.

In general I let clang-format have it's way, and added markup to prevent formatting of code that would break or be completely unreadable if formatted.

The script I ran for the src directory is added as build-scripts/clang-format-src.sh

This fixes:
#6592
#6593
#6594

(cherry picked from commit 5750bcb174)
This commit is contained in:
Sam Lantinga
2022-11-30 12:51:59 -08:00
parent 5c4bc807f7
commit b8d85c6939
764 changed files with 50598 additions and 54407 deletions

View File

@@ -37,15 +37,14 @@ struct SDL_cond
};
/* Create a condition variable */
extern "C"
SDL_cond *
extern "C" SDL_cond *
SDL_CreateCond(void)
{
/* Allocate and initialize the condition variable */
try {
SDL_cond * cond = new SDL_cond;
SDL_cond *cond = new SDL_cond;
return cond;
} catch (std::system_error & ex) {
} catch (std::system_error &ex) {
SDL_SetError("unable to create a C++ condition variable: code=%d; %s", ex.code(), ex.what());
return NULL;
} catch (std::bad_alloc &) {
@@ -55,9 +54,8 @@ SDL_CreateCond(void)
}
/* Destroy a condition variable */
extern "C"
void
SDL_DestroyCond(SDL_cond * cond)
extern "C" void
SDL_DestroyCond(SDL_cond *cond)
{
if (cond != NULL) {
delete cond;
@@ -65,9 +63,8 @@ SDL_DestroyCond(SDL_cond * cond)
}
/* Restart one of the threads that are waiting on the condition variable */
extern "C"
int
SDL_CondSignal(SDL_cond * cond)
extern "C" int
SDL_CondSignal(SDL_cond *cond)
{
if (cond == NULL) {
return SDL_InvalidParamError("cond");
@@ -78,9 +75,8 @@ SDL_CondSignal(SDL_cond * cond)
}
/* Restart all threads that are waiting on the condition variable */
extern "C"
int
SDL_CondBroadcast(SDL_cond * cond)
extern "C" int
SDL_CondBroadcast(SDL_cond *cond)
{
if (cond == NULL) {
return SDL_InvalidParamError("cond");
@@ -111,9 +107,8 @@ Thread B:
SDL_CondSignal(cond);
SDL_UnlockMutex(lock);
*/
extern "C"
int
SDL_CondWaitTimeout(SDL_cond * cond, SDL_mutex * mutex, Uint32 ms)
extern "C" int
SDL_CondWaitTimeout(SDL_cond *cond, SDL_mutex *mutex, Uint32 ms)
{
if (cond == NULL) {
return SDL_InvalidParamError("cond");
@@ -127,15 +122,13 @@ SDL_CondWaitTimeout(SDL_cond * cond, SDL_mutex * mutex, Uint32 ms)
std::unique_lock<std::recursive_mutex> cpp_lock(mutex->cpp_mutex, std::adopt_lock_t());
if (ms == SDL_MUTEX_MAXWAIT) {
cond->cpp_cond.wait(
cpp_lock
);
cpp_lock);
cpp_lock.release();
return 0;
} else {
auto wait_result = cond->cpp_cond.wait_for(
cpp_lock,
std::chrono::duration<Uint32, std::milli>(ms)
);
std::chrono::duration<Uint32, std::milli>(ms));
cpp_lock.release();
if (wait_result == std::cv_status::timeout) {
return SDL_MUTEX_TIMEDOUT;
@@ -143,15 +136,14 @@ SDL_CondWaitTimeout(SDL_cond * cond, SDL_mutex * mutex, Uint32 ms)
return 0;
}
}
} catch (std::system_error & ex) {
} catch (std::system_error &ex) {
return SDL_SetError("unable to wait on a C++ condition variable: code=%d; %s", ex.code(), ex.what());
}
}
/* Wait on the condition variable forever */
extern "C"
int
SDL_CondWait(SDL_cond * cond, SDL_mutex * mutex)
extern "C" int
SDL_CondWait(SDL_cond *cond, SDL_mutex *mutex)
{
return SDL_CondWaitTimeout(cond, mutex, SDL_MUTEX_MAXWAIT);
}

View File

@@ -30,17 +30,15 @@ extern "C" {
#include "SDL_sysmutex_c.h"
#include <Windows.h>
/* Create a mutex */
extern "C"
SDL_mutex *
extern "C" SDL_mutex *
SDL_CreateMutex(void)
{
/* Allocate and initialize the mutex */
try {
SDL_mutex * mutex = new SDL_mutex;
SDL_mutex *mutex = new SDL_mutex;
return mutex;
} catch (std::system_error & ex) {
} catch (std::system_error &ex) {
SDL_SetError("unable to create a C++ mutex: code=%d; %s", ex.code(), ex.what());
return NULL;
} catch (std::bad_alloc &) {
@@ -50,9 +48,8 @@ SDL_CreateMutex(void)
}
/* Free the mutex */
extern "C"
void
SDL_DestroyMutex(SDL_mutex * mutex)
extern "C" void
SDL_DestroyMutex(SDL_mutex *mutex)
{
if (mutex != NULL) {
delete mutex;
@@ -60,9 +57,8 @@ SDL_DestroyMutex(SDL_mutex * mutex)
}
/* Lock the semaphore */
extern "C"
int
SDL_mutexP(SDL_mutex * mutex)
extern "C" int
SDL_mutexP(SDL_mutex *mutex)
{
if (mutex == NULL) {
return SDL_InvalidParamError("mutex");
@@ -71,14 +67,13 @@ SDL_mutexP(SDL_mutex * mutex)
try {
mutex->cpp_mutex.lock();
return 0;
} catch (std::system_error & ex) {
} catch (std::system_error &ex) {
return SDL_SetError("unable to lock a C++ mutex: code=%d; %s", ex.code(), ex.what());
}
}
/* TryLock the mutex */
int
SDL_TryLockMutex(SDL_mutex * mutex)
int SDL_TryLockMutex(SDL_mutex *mutex)
{
int retval = 0;
if (mutex == NULL) {
@@ -92,9 +87,8 @@ SDL_TryLockMutex(SDL_mutex * mutex)
}
/* Unlock the mutex */
extern "C"
int
SDL_mutexV(SDL_mutex * mutex)
extern "C" int
SDL_mutexV(SDL_mutex *mutex)
{
if (mutex == NULL) {
return SDL_InvalidParamError("mutex");

View File

@@ -36,30 +36,27 @@ extern "C" {
#include <Windows.h>
#endif
static void
RunThread(void *args)
static void RunThread(void *args)
{
SDL_RunThread((SDL_Thread *) args);
SDL_RunThread((SDL_Thread *)args);
}
extern "C"
int
SDL_SYS_CreateThread(SDL_Thread * thread)
extern "C" int
SDL_SYS_CreateThread(SDL_Thread *thread)
{
try {
// !!! FIXME: no way to set a thread stack size here.
std::thread cpp_thread(RunThread, thread);
thread->handle = (void *) new std::thread(std::move(cpp_thread));
thread->handle = (void *)new std::thread(std::move(cpp_thread));
return 0;
} catch (std::system_error & ex) {
} catch (std::system_error &ex) {
return SDL_SetError("unable to start a C++ thread: code=%d; %s", ex.code(), ex.what());
} catch (std::bad_alloc &) {
return SDL_OutOfMemory();
}
}
extern "C"
void
extern "C" void
SDL_SYS_SetupThread(const char *name)
{
// Make sure a thread ID gets assigned ASAP, for debugging purposes:
@@ -67,8 +64,7 @@ SDL_SYS_SetupThread(const char *name)
return;
}
extern "C"
SDL_threadID
extern "C" SDL_threadID
SDL_ThreadID(void)
{
#ifdef __WINRT__
@@ -89,8 +85,7 @@ SDL_ThreadID(void)
#endif
}
extern "C"
int
extern "C" int
SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
{
#ifdef __WINRT__
@@ -116,16 +111,15 @@ SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
#endif
}
extern "C"
void
SDL_SYS_WaitThread(SDL_Thread * thread)
extern "C" void
SDL_SYS_WaitThread(SDL_Thread *thread)
{
if ( ! thread) {
if (!thread) {
return;
}
try {
std::thread * cpp_thread = (std::thread *) thread->handle;
std::thread *cpp_thread = (std::thread *)thread->handle;
if (cpp_thread->joinable()) {
cpp_thread->join();
}
@@ -136,16 +130,15 @@ SDL_SYS_WaitThread(SDL_Thread * thread)
}
}
extern "C"
void
SDL_SYS_DetachThread(SDL_Thread * thread)
extern "C" void
SDL_SYS_DetachThread(SDL_Thread *thread)
{
if ( ! thread) {
if (!thread) {
return;
}
try {
std::thread * cpp_thread = (std::thread *) thread->handle;
std::thread *cpp_thread = (std::thread *)thread->handle;
if (cpp_thread->joinable()) {
cpp_thread->detach();
}
@@ -156,15 +149,13 @@ SDL_SYS_DetachThread(SDL_Thread * thread)
}
}
extern "C"
SDL_TLSData *
extern "C" SDL_TLSData *
SDL_SYS_GetTLSData(void)
{
return SDL_Generic_GetTLSData();
}
extern "C"
int
extern "C" int
SDL_SYS_SetTLSData(SDL_TLSData *data)
{
return SDL_Generic_SetTLSData(data);

View File

@@ -21,6 +21,6 @@
#include "SDL_config.h"
/* For a thread handle, use a void pointer to a std::thread */
typedef void * SYS_ThreadHandle;
typedef void *SYS_ThreadHandle;
/* vi: set ts=4 sw=4 expandtab: */