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
This commit is contained in:
Sam Lantinga
2022-11-30 12:51:59 -08:00
committed by GitHub
parent 14b902faca
commit 5750bcb174
781 changed files with 51659 additions and 55763 deletions

View File

@@ -26,7 +26,6 @@
implementation, written by Christopher Tate and Owen Smith. Thanks!
*/
#include "../generic/SDL_syscond_c.h"
/* If two implementations are to be compiled into SDL (the active one
@@ -57,7 +56,7 @@ SDL_CreateCond_generic(void)
{
SDL_cond_generic *cond;
cond = (SDL_cond_generic *) SDL_malloc(sizeof(SDL_cond_generic));
cond = (SDL_cond_generic *)SDL_malloc(sizeof(SDL_cond_generic));
if (cond) {
cond->lock = SDL_CreateMutex();
cond->wait_sem = SDL_CreateSemaphore(0);
@@ -74,8 +73,7 @@ SDL_CreateCond_generic(void)
}
/* Destroy a condition variable */
void
SDL_DestroyCond_generic(SDL_cond * _cond)
void SDL_DestroyCond_generic(SDL_cond *_cond)
{
SDL_cond_generic *cond = (SDL_cond_generic *)_cond;
if (cond) {
@@ -93,8 +91,7 @@ SDL_DestroyCond_generic(SDL_cond * _cond)
}
/* Restart one of the threads that are waiting on the condition variable */
int
SDL_CondSignal_generic(SDL_cond * _cond)
int SDL_CondSignal_generic(SDL_cond *_cond)
{
SDL_cond_generic *cond = (SDL_cond_generic *)_cond;
if (cond == NULL) {
@@ -118,8 +115,7 @@ SDL_CondSignal_generic(SDL_cond * _cond)
}
/* Restart all threads that are waiting on the condition variable */
int
SDL_CondBroadcast_generic(SDL_cond * _cond)
int SDL_CondBroadcast_generic(SDL_cond *_cond)
{
SDL_cond_generic *cond = (SDL_cond_generic *)_cond;
if (cond == NULL) {
@@ -173,8 +169,7 @@ Thread B:
SDL_CondSignal(cond);
SDL_UnlockMutex(lock);
*/
int
SDL_CondWaitTimeout_generic(SDL_cond * _cond, SDL_mutex * mutex, Uint32 ms)
int SDL_CondWaitTimeout_generic(SDL_cond *_cond, SDL_mutex *mutex, Uint32 ms)
{
SDL_cond_generic *cond = (SDL_cond_generic *)_cond;
int retval;
@@ -229,8 +224,7 @@ SDL_CondWaitTimeout_generic(SDL_cond * _cond, SDL_mutex * mutex, Uint32 ms)
}
/* Wait on the condition variable forever */
int
SDL_CondWait_generic(SDL_cond * cond, SDL_mutex * mutex)
int SDL_CondWait_generic(SDL_cond *cond, SDL_mutex *mutex)
{
return SDL_CondWaitTimeout_generic(cond, mutex, SDL_MUTEX_MAXWAIT);
}

View File

@@ -20,19 +20,18 @@
*/
#include "SDL_internal.h"
#ifndef SDL_syscond_generic_h_
#define SDL_syscond_generic_h_
#if SDL_THREAD_GENERIC_COND_SUFFIX
SDL_cond * SDL_CreateCond_generic(void);
void SDL_DestroyCond_generic(SDL_cond * cond);
int SDL_CondSignal_generic(SDL_cond * cond);
int SDL_CondBroadcast_generic(SDL_cond * cond);
int SDL_CondWait_generic(SDL_cond * cond, SDL_mutex * mutex);
int SDL_CondWaitTimeout_generic(SDL_cond * cond,
SDL_mutex * mutex, Uint32 ms);
SDL_cond *SDL_CreateCond_generic(void);
void SDL_DestroyCond_generic(SDL_cond *cond);
int SDL_CondSignal_generic(SDL_cond *cond);
int SDL_CondBroadcast_generic(SDL_cond *cond);
int SDL_CondWait_generic(SDL_cond *cond, SDL_mutex *mutex);
int SDL_CondWaitTimeout_generic(SDL_cond *cond,
SDL_mutex *mutex, Uint32 ms);
#endif /* SDL_THREAD_GENERIC_COND_SUFFIX */

View File

@@ -24,7 +24,6 @@
#include "SDL_systhread_c.h"
struct SDL_mutex
{
int recursive;
@@ -39,7 +38,7 @@ SDL_CreateMutex(void)
SDL_mutex *mutex;
/* Allocate mutex memory */
mutex = (SDL_mutex *) SDL_calloc(1, sizeof(*mutex));
mutex = (SDL_mutex *)SDL_calloc(1, sizeof(*mutex));
#if !SDL_THREADS_DISABLED
if (mutex) {
@@ -60,8 +59,7 @@ SDL_CreateMutex(void)
}
/* Free the mutex */
void
SDL_DestroyMutex(SDL_mutex * mutex)
void SDL_DestroyMutex(SDL_mutex *mutex)
{
if (mutex) {
if (mutex->sem) {
@@ -72,8 +70,7 @@ SDL_DestroyMutex(SDL_mutex * mutex)
}
/* Lock the mutex */
int
SDL_LockMutex(SDL_mutex * mutex)
int SDL_LockMutex(SDL_mutex *mutex)
{
#if SDL_THREADS_DISABLED
return 0;
@@ -102,8 +99,7 @@ SDL_LockMutex(SDL_mutex * mutex)
}
/* try Lock the mutex */
int
SDL_TryLockMutex(SDL_mutex * mutex)
int SDL_TryLockMutex(SDL_mutex *mutex)
{
#if SDL_THREADS_DISABLED
return 0;
@@ -135,8 +131,7 @@ SDL_TryLockMutex(SDL_mutex * mutex)
}
/* Unlock the mutex */
int
SDL_mutexV(SDL_mutex * mutex)
int SDL_mutexV(SDL_mutex *mutex)
{
#if SDL_THREADS_DISABLED
return 0;

View File

@@ -24,47 +24,41 @@
#include "SDL_systhread_c.h"
#if SDL_THREADS_DISABLED
SDL_sem *
SDL_CreateSemaphore(Uint32 initial_value)
{
SDL_SetError("SDL not built with thread support");
return (SDL_sem *) 0;
return (SDL_sem *)0;
}
void
SDL_DestroySemaphore(SDL_sem * sem)
void SDL_DestroySemaphore(SDL_sem *sem)
{
}
int
SDL_SemTryWait(SDL_sem * sem)
int SDL_SemTryWait(SDL_sem *sem)
{
return SDL_SetError("SDL not built with thread support");
}
int
SDL_SemWaitTimeout(SDL_sem * sem, Uint32 timeout)
int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout)
{
return SDL_SetError("SDL not built with thread support");
}
int
SDL_SemWait(SDL_sem * sem)
int SDL_SemWait(SDL_sem *sem)
{
return SDL_SetError("SDL not built with thread support");
}
Uint32
SDL_SemValue(SDL_sem * sem)
SDL_SemValue(SDL_sem *sem)
{
return 0;
}
int
SDL_SemPost(SDL_sem * sem)
int SDL_SemPost(SDL_sem *sem)
{
return SDL_SetError("SDL not built with thread support");
}
@@ -84,7 +78,7 @@ SDL_CreateSemaphore(Uint32 initial_value)
{
SDL_sem *sem;
sem = (SDL_sem *) SDL_malloc(sizeof(*sem));
sem = (SDL_sem *)SDL_malloc(sizeof(*sem));
if (sem == NULL) {
SDL_OutOfMemory();
return NULL;
@@ -105,8 +99,7 @@ SDL_CreateSemaphore(Uint32 initial_value)
/* WARNING:
You cannot call this function when another thread is using the semaphore.
*/
void
SDL_DestroySemaphore(SDL_sem * sem)
void SDL_DestroySemaphore(SDL_sem *sem)
{
if (sem) {
sem->count = 0xFFFFFFFF;
@@ -124,8 +117,7 @@ SDL_DestroySemaphore(SDL_sem * sem)
}
}
int
SDL_SemTryWait(SDL_sem * sem)
int SDL_SemTryWait(SDL_sem *sem)
{
int retval;
@@ -144,8 +136,7 @@ SDL_SemTryWait(SDL_sem * sem)
return retval;
}
int
SDL_SemWaitTimeout(SDL_sem * sem, Uint32 timeout)
int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout)
{
int retval;
@@ -174,14 +165,13 @@ SDL_SemWaitTimeout(SDL_sem * sem, Uint32 timeout)
return retval;
}
int
SDL_SemWait(SDL_sem * sem)
int SDL_SemWait(SDL_sem *sem)
{
return SDL_SemWaitTimeout(sem, SDL_MUTEX_MAXWAIT);
}
Uint32
SDL_SemValue(SDL_sem * sem)
SDL_SemValue(SDL_sem *sem)
{
Uint32 value;
@@ -194,8 +184,7 @@ SDL_SemValue(SDL_sem * sem)
return value;
}
int
SDL_SemPost(SDL_sem * sem)
int SDL_SemPost(SDL_sem *sem)
{
if (sem == NULL) {
return SDL_InvalidParamError("sem");

View File

@@ -25,20 +25,17 @@
#include "../SDL_systhread.h"
#ifdef SDL_PASSED_BEGINTHREAD_ENDTHREAD
int
SDL_SYS_CreateThread(SDL_Thread * thread,
pfnSDL_CurrentBeginThread pfnBeginThread,
pfnSDL_CurrentEndThread pfnEndThread)
int SDL_SYS_CreateThread(SDL_Thread *thread,
pfnSDL_CurrentBeginThread pfnBeginThread,
pfnSDL_CurrentEndThread pfnEndThread)
#else
int
SDL_SYS_CreateThread(SDL_Thread * thread)
int SDL_SYS_CreateThread(SDL_Thread *thread)
#endif /* SDL_PASSED_BEGINTHREAD_ENDTHREAD */
{
return SDL_SetError("Threads are not supported on this platform");
}
void
SDL_SYS_SetupThread(const char *name)
void SDL_SYS_SetupThread(const char *name)
{
return;
}
@@ -49,20 +46,17 @@ SDL_ThreadID(void)
return 0;
}
int
SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
int SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
{
return 0;
}
void
SDL_SYS_WaitThread(SDL_Thread * thread)
void SDL_SYS_WaitThread(SDL_Thread *thread)
{
return;
}
void
SDL_SYS_DetachThread(SDL_Thread * thread)
void SDL_SYS_DetachThread(SDL_Thread *thread)
{
return;
}

View File

@@ -22,15 +22,13 @@
#include "SDL_internal.h"
#include "../SDL_thread_c.h"
SDL_TLSData *
SDL_SYS_GetTLSData(void)
{
return SDL_Generic_GetTLSData();
}
int
SDL_SYS_SetTLSData(SDL_TLSData *data)
int SDL_SYS_SetTLSData(SDL_TLSData *data)
{
return SDL_Generic_SetTLSData(data);
}