Skip to content

Commit

Permalink
Re-add SDL_assert() with non boolean ptr syntax (libsdl-org#8530)
Browse files Browse the repository at this point in the history
  • Loading branch information
1bsyl authored Nov 11, 2023
1 parent b374105 commit 04b6b29
Show file tree
Hide file tree
Showing 35 changed files with 88 additions and 88 deletions.
32 changes: 16 additions & 16 deletions src/audio/SDL_audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ static int GetDefaultSampleFramesFromFreq(const int freq)

void OnAudioStreamCreated(SDL_AudioStream *stream)
{
SDL_assert(stream);
SDL_assert(stream != NULL);

// NOTE that you can create an audio stream without initializing the audio subsystem,
// but it will not be automatically destroyed during a later call to SDL_Quit!
Expand All @@ -159,7 +159,7 @@ void OnAudioStreamCreated(SDL_AudioStream *stream)

void OnAudioStreamDestroy(SDL_AudioStream *stream)
{
SDL_assert(stream);
SDL_assert(stream != NULL);

// NOTE that you can create an audio stream without initializing the audio subsystem,
// but it will not be automatically destroyed during a later call to SDL_Quit!
Expand Down Expand Up @@ -500,7 +500,7 @@ void RefPhysicalAudioDevice(SDL_AudioDevice *device)

static SDL_AudioDevice *CreatePhysicalAudioDevice(const char *name, SDL_bool iscapture, const SDL_AudioSpec *spec, void *handle, SDL_AtomicInt *device_count)
{
SDL_assert(name);
SDL_assert(name != NULL);

SDL_LockRWLockForReading(current_audio.device_hash_lock);
const int shutting_down = SDL_AtomicGet(&current_audio.shutting_down);
Expand Down Expand Up @@ -593,8 +593,8 @@ SDL_AudioDevice *SDL_AddAudioDevice(const SDL_bool iscapture, const char *name,
p->devid = device->instance_id;
p->next = NULL;
SDL_LockRWLockForWriting(current_audio.device_hash_lock);
SDL_assert(current_audio.pending_events_tail);
SDL_assert(!current_audio.pending_events_tail->next);
SDL_assert(current_audio.pending_events_tail != NULL);
SDL_assert(current_audio.pending_events_tail->next == NULL);
current_audio.pending_events_tail->next = p;
current_audio.pending_events_tail = p;
SDL_UnlockRWLock(current_audio.device_hash_lock);
Expand Down Expand Up @@ -670,8 +670,8 @@ void SDL_AudioDeviceDisconnected(SDL_AudioDevice *device)
if (first_disconnect) {
if (pending.next) { // NULL if event is disabled or disaster struck.
SDL_LockRWLockForWriting(current_audio.device_hash_lock);
SDL_assert(current_audio.pending_events_tail);
SDL_assert(!current_audio.pending_events_tail->next);
SDL_assert(current_audio.pending_events_tail != NULL);
SDL_assert(current_audio.pending_events_tail->next == NULL);
current_audio.pending_events_tail->next = pending.next;
current_audio.pending_events_tail = pending_tail;
SDL_UnlockRWLock(current_audio.device_hash_lock);
Expand Down Expand Up @@ -1127,7 +1127,7 @@ void SDL_OutputAudioThreadShutdown(SDL_AudioDevice *device)
static int SDLCALL OutputAudioThread(void *devicep) // thread entry point
{
SDL_AudioDevice *device = (SDL_AudioDevice *)devicep;
SDL_assert(device);
SDL_assert(device != NULL);
SDL_assert(!device->iscapture);
SDL_OutputAudioThreadSetup(device);

Expand Down Expand Up @@ -1233,7 +1233,7 @@ void SDL_CaptureAudioThreadShutdown(SDL_AudioDevice *device)
static int SDLCALL CaptureAudioThread(void *devicep) // thread entry point
{
SDL_AudioDevice *device = (SDL_AudioDevice *)devicep;
SDL_assert(device);
SDL_assert(device != NULL);
SDL_assert(device->iscapture);
SDL_CaptureAudioThreadSetup(device);

Expand Down Expand Up @@ -1726,7 +1726,7 @@ int SDL_BindAudioStreams(SDL_AudioDeviceID devid, SDL_AudioStream **streams, int
// !!! FIXME: Actually, why do we allow there to be an invalid format, again?

// make sure start of list is sane.
SDL_assert(!logdev->bound_streams || (!logdev->bound_streams->prev_binding));
SDL_assert(!logdev->bound_streams || (logdev->bound_streams->prev_binding == NULL));

// lock all the streams upfront, so we can verify they aren't bound elsewhere and add them all in one block, as this is intended to add everything or nothing.
for (int i = 0; i < num_streams; i++) {
Expand All @@ -1735,7 +1735,7 @@ int SDL_BindAudioStreams(SDL_AudioDeviceID devid, SDL_AudioStream **streams, int
retval = SDL_SetError("Stream #%d is NULL", i);
} else {
SDL_LockMutex(stream->lock);
SDL_assert((!stream->bound_device) == ((!stream->prev_binding) || (!stream->next_binding)));
SDL_assert((stream->bound_device == NULL) == ((stream->prev_binding == NULL) || (stream->next_binding == NULL)));
if (stream->bound_device) {
retval = SDL_SetError("Stream #%d is already bound to a device", i);
} else if (stream->simplified) { // You can get here if you closed the device instead of destroying the stream.
Expand Down Expand Up @@ -1892,7 +1892,7 @@ SDL_AudioStream *SDL_OpenAudioDeviceStream(SDL_AudioDeviceID devid, const SDL_Au
} else {
SDL_AtomicSet(&logdev->paused, 1); // start the device paused, to match SDL2.

SDL_assert(device);
SDL_assert(device != NULL);
const SDL_bool iscapture = device->iscapture;

if (iscapture) {
Expand Down Expand Up @@ -2105,8 +2105,8 @@ void SDL_DefaultAudioDeviceChanged(SDL_AudioDevice *new_default_device)

if (pending.next) {
SDL_LockRWLockForWriting(current_audio.device_hash_lock);
SDL_assert(current_audio.pending_events_tail);
SDL_assert(!current_audio.pending_events_tail->next);
SDL_assert(current_audio.pending_events_tail != NULL);
SDL_assert(current_audio.pending_events_tail->next == NULL);
current_audio.pending_events_tail->next = pending.next;
current_audio.pending_events_tail = pending_tail;
SDL_UnlockRWLock(current_audio.device_hash_lock);
Expand Down Expand Up @@ -2186,8 +2186,8 @@ int SDL_AudioDeviceFormatChangedAlreadyLocked(SDL_AudioDevice *device, const SDL

if (pending.next) {
SDL_LockRWLockForWriting(current_audio.device_hash_lock);
SDL_assert(current_audio.pending_events_tail);
SDL_assert(!current_audio.pending_events_tail->next);
SDL_assert(current_audio.pending_events_tail != NULL);
SDL_assert(current_audio.pending_events_tail->next == NULL);
current_audio.pending_events_tail->next = pending.next;
current_audio.pending_events_tail = pending_tail;
SDL_UnlockRWLock(current_audio.device_hash_lock);
Expand Down
6 changes: 3 additions & 3 deletions src/audio/SDL_audiocvt.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,8 @@ static SDL_bool SDL_IsSupportedChannelCount(const int channels)
void ConvertAudio(int num_frames, const void *src, SDL_AudioFormat src_format, int src_channels,
void *dst, SDL_AudioFormat dst_format, int dst_channels, void* scratch)
{
SDL_assert(src);
SDL_assert(dst);
SDL_assert(src != NULL);
SDL_assert(dst != NULL);
SDL_assert(SDL_IsSupportedAudioFormat(src_format));
SDL_assert(SDL_IsSupportedAudioFormat(dst_format));
SDL_assert(SDL_IsSupportedChannelCount(src_channels));
Expand Down Expand Up @@ -313,7 +313,7 @@ void ConvertAudio(int num_frames, const void *src, SDL_AudioFormat src_format, i
SDL_assert(dst_channels <= SDL_arraysize(channel_converters[0]));

channel_converter = channel_converters[src_channels - 1][dst_channels - 1];
SDL_assert(channel_converter);
SDL_assert(channel_converter != NULL);

// swap in some SIMD versions for a few of these.
if (channel_converter == SDL_ConvertStereoToMono) {
Expand Down
4 changes: 2 additions & 2 deletions src/audio/SDL_audioqueue.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ static int WriteToChunkedAudioTrack(void *ctx, const Uint8 *data, size_t len)
return SDL_OutOfMemory();
}

SDL_assert((!track->head) && (!track->tail) && (track->queued_bytes == 0));
SDL_assert((track->head == NULL) && (track->tail == NULL) && (track->queued_bytes == 0));
track->head = chunk;
track->tail = chunk;
}
Expand Down Expand Up @@ -423,7 +423,7 @@ void *SDL_BeginAudioQueueIter(SDL_AudioQueue *queue)
size_t SDL_NextAudioQueueIter(SDL_AudioQueue *queue, void **inout_iter, SDL_AudioSpec *out_spec, SDL_bool *out_flushed)
{
SDL_AudioTrack *iter = *inout_iter;
SDL_assert(iter);
SDL_assert(iter != NULL);

SDL_copyp(out_spec, &iter->spec);

Expand Down
4 changes: 2 additions & 2 deletions src/audio/alsa/SDL_alsa_audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ static const ALSA_Device default_capture_handle = {

static const char *get_audio_device(void *handle, const int channels)
{
SDL_assert(handle); // SDL2 used NULL to mean "default" but that's not true in SDL3.
SDL_assert(handle != NULL); // SDL2 used NULL to mean "default" but that's not true in SDL3.

ALSA_Device *dev = (ALSA_Device *)handle;
if (SDL_strcmp(dev->name, "default") == 0) {
Expand Down Expand Up @@ -723,7 +723,7 @@ static void add_device(const SDL_bool iscapture, const char *name, void *hint, A
desc = (char *)name;
}

SDL_assert(name);
SDL_assert(name != NULL);

// some strings have newlines, like "HDA NVidia, HDMI 0\nHDMI Audio Output".
// just chop the extra lines off, this seems to get a reasonable device
Expand Down
2 changes: 1 addition & 1 deletion src/audio/directsound/SDL_directsound.c
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ static int DSOUND_CaptureFromDevice(SDL_AudioDevice *device, void *buffer, int b
}

SDL_assert(ptr1len == (DWORD)buflen);
SDL_assert(!ptr2);
SDL_assert(ptr2 == NULL);
SDL_assert(ptr2len == 0);

SDL_memcpy(buffer, ptr1, ptr1len);
Expand Down
6 changes: 3 additions & 3 deletions src/audio/haiku/SDL_haikuaudio.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ extern "C"

static Uint8 *HAIKUAUDIO_GetDeviceBuf(SDL_AudioDevice *device, int *buffer_size)
{
SDL_assert(device->hidden->current_buffer);
SDL_assert(device->hidden->current_buffer != NULL);
SDL_assert(device->hidden->current_buffer_len > 0);
*buffer_size = device->hidden->current_buffer_len;
return device->hidden->current_buffer;
Expand All @@ -48,7 +48,7 @@ static Uint8 *HAIKUAUDIO_GetDeviceBuf(SDL_AudioDevice *device, int *buffer_size)
static int HAIKUAUDIO_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buffer_size)
{
// We already wrote our output right into the BSoundPlayer's callback's stream. Just clean up our stuff.
SDL_assert(device->hidden->current_buffer);
SDL_assert(device->hidden->current_buffer != NULL);
SDL_assert(device->hidden->current_buffer_len > 0);
device->hidden->current_buffer = NULL;
device->hidden->current_buffer_len = 0;
Expand All @@ -59,7 +59,7 @@ static int HAIKUAUDIO_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, i
static void FillSound(void *data, void *stream, size_t len, const media_raw_audio_format & format)
{
SDL_AudioDevice *device = (SDL_AudioDevice *)data;
SDL_assert(!device->hidden->current_buffer);
SDL_assert(device->hidden->current_buffer == NULL);
SDL_assert(device->hidden->current_buffer_len == 0);
device->hidden->current_buffer = (Uint8 *) stream;
device->hidden->current_buffer_len = (int) len;
Expand Down
4 changes: 2 additions & 2 deletions src/audio/pipewire/SDL_pipewire.c
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ static struct io_node *io_list_get_by_id(Uint32 id)

static void node_object_destroy(struct node_object *node)
{
SDL_assert(node);
SDL_assert(node != NULL);

spa_list_remove(&node->link);
spa_hook_remove(&node->node_listener);
Expand All @@ -373,7 +373,7 @@ static void node_object_destroy(struct node_object *node)
// The pending node list
static void pending_list_add(struct node_object *node)
{
SDL_assert(node);
SDL_assert(node != NULL);
spa_list_append(&hotplug_pending_list, &node->link);
}

Expand Down
12 changes: 6 additions & 6 deletions src/audio/pulseaudio/SDL_pulseaudio.c
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ static void OperationStateChangeCallback(pa_operation *o, void *userdata)
static void WaitForPulseOperation(pa_operation *o)
{
// This checks for NO errors currently. Either fix that, check results elsewhere, or do things you don't care about.
SDL_assert(pulseaudio_threaded_mainloop);
SDL_assert(pulseaudio_threaded_mainloop != NULL);
if (o) {
// note that if PULSEAUDIO_pa_operation_set_state_callback == NULL, then `o` must have a callback that will signal pulseaudio_threaded_mainloop.
// If not, on really old (earlier PulseAudio 4.0, from the year 2013!) installs, this call will block forever.
Expand Down Expand Up @@ -339,8 +339,8 @@ static int ConnectToPulseServer(void)
pa_mainloop_api *mainloop_api = NULL;
int state = 0;

SDL_assert(!pulseaudio_threaded_mainloop);
SDL_assert(!pulseaudio_context);
SDL_assert(pulseaudio_threaded_mainloop == NULL);
SDL_assert(pulseaudio_context == NULL);

// Set up a new main loop
if (!(pulseaudio_threaded_mainloop = PULSEAUDIO_pa_threaded_mainloop_new())) {
Expand All @@ -360,7 +360,7 @@ static int ConnectToPulseServer(void)
PULSEAUDIO_pa_threaded_mainloop_lock(pulseaudio_threaded_mainloop);

mainloop_api = PULSEAUDIO_pa_threaded_mainloop_get_api(pulseaudio_threaded_mainloop);
SDL_assert(mainloop_api); // this never fails, right?
SDL_assert(mainloop_api != NULL); // this never fails, right?

pulseaudio_context = PULSEAUDIO_pa_context_new(mainloop_api, getAppName());
if (!pulseaudio_context) {
Expand Down Expand Up @@ -609,8 +609,8 @@ static int PULSEAUDIO_OpenDevice(SDL_AudioDevice *device)
int format = PA_SAMPLE_INVALID;
int retval = 0;

SDL_assert(pulseaudio_threaded_mainloop);
SDL_assert(pulseaudio_context);
SDL_assert(pulseaudio_threaded_mainloop != NULL);
SDL_assert(pulseaudio_context != NULL);

// Initialize all variables that we clean on shutdown
h = device->hidden = (struct SDL_PrivateAudioData *)SDL_calloc(1, sizeof(*device->hidden));
Expand Down
10 changes: 5 additions & 5 deletions src/audio/wasapi/SDL_wasapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ static Uint8 *WASAPI_GetDeviceBuf(SDL_AudioDevice *device, int *buffer_size)

if (device->hidden->render) {
if (WasapiFailed(device, IAudioRenderClient_GetBuffer(device->hidden->render, device->sample_frames, &buffer))) {
SDL_assert(!buffer);
SDL_assert(buffer == NULL);
if (device->hidden->device_lost) { // just use an available buffer, we won't be playing it anyhow.
*buffer_size = 0; // we'll recover during WaitDevice and try again.
}
Expand Down Expand Up @@ -562,7 +562,7 @@ static int mgmtthrtask_PrepDevice(void *userdata)
const AUDCLNT_SHAREMODE sharemode = AUDCLNT_SHAREMODE_SHARED;

IAudioClient *client = device->hidden->client;
SDL_assert(client);
SDL_assert(client != NULL);

#if defined(__WINRT__) || defined(__GDK__) // CreateEventEx() arrived in Vista, so we need an #ifdef for XP.
device->hidden->event = CreateEventEx(NULL, NULL, 0, EVENT_ALL_ACCESS);
Expand All @@ -581,7 +581,7 @@ static int mgmtthrtask_PrepDevice(void *userdata)
if (FAILED(ret)) {
return WIN_SetErrorFromHRESULT("WASAPI can't determine mix format", ret);
}
SDL_assert(waveformat);
SDL_assert(waveformat != NULL);
device->hidden->waveformat = waveformat;

SDL_AudioSpec newspec;
Expand Down Expand Up @@ -662,7 +662,7 @@ static int mgmtthrtask_PrepDevice(void *userdata)
return WIN_SetErrorFromHRESULT("WASAPI can't get capture client service", ret);
}

SDL_assert(capture);
SDL_assert(capture != NULL);
device->hidden->capture = capture;
ret = IAudioClient_Start(client);
if (FAILED(ret)) {
Expand All @@ -677,7 +677,7 @@ static int mgmtthrtask_PrepDevice(void *userdata)
return WIN_SetErrorFromHRESULT("WASAPI can't get render client service", ret);
}

SDL_assert(render);
SDL_assert(render != NULL);
device->hidden->render = render;
ret = IAudioClient_Start(client);
if (FAILED(ret)) {
Expand Down
4 changes: 2 additions & 2 deletions src/audio/wasapi/SDL_wasapi_win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,11 @@ int WASAPI_ActivateDevice(SDL_AudioDevice *device)
IMMDevice_Release(immdevice);

if (FAILED(ret)) {
SDL_assert(!device->hidden->client);
SDL_assert(device->hidden->client == NULL);
return WIN_SetErrorFromHRESULT("WASAPI can't activate audio endpoint", ret);
}

SDL_assert(device->hidden->client);
SDL_assert(device->hidden->client != NULL);
if (WASAPI_PrepDevice(device) == -1) { // not async, fire it right away.
return -1;
}
Expand Down
6 changes: 3 additions & 3 deletions src/core/linux/SDL_evdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,8 @@ void SDL_EVDEV_Quit(void)

SDL_EVDEV_kbd_quit(_this->kbd);

SDL_assert(!_this->first);
SDL_assert(!_this->last);
SDL_assert(_this->first == NULL);
SDL_assert(_this->last == NULL);
SDL_assert(_this->num_devices == 0);

SDL_free(_this);
Expand Down Expand Up @@ -292,7 +292,7 @@ void SDL_EVDEV_SetVTSwitchCallbacks(void (*release_callback)(void*), void *relea
void (*acquire_callback)(void*), void *acquire_callback_data)
{
SDL_EVDEV_kbd_set_vt_switch_callbacks(_this->kbd,
release_callback, release_callback_data,
release_callback, release_callback_data,
acquire_callback, acquire_callback_data);
}

Expand Down
4 changes: 2 additions & 2 deletions src/core/windows/SDL_immdevice.c
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,8 @@ int SDL_IMMDevice_Get(SDL_AudioDevice *device, IMMDevice **immdevice, SDL_bool i
{
const Uint64 timeout = SDL_GetTicks() + 8000; /* intel's audio drivers can fail for up to EIGHT SECONDS after a device is connected or we wake from sleep. */

SDL_assert(device);
SDL_assert(immdevice);
SDL_assert(device != NULL);
SDL_assert(immdevice != NULL);

LPCWSTR devid = SDL_IMMDevice_GetDevID(device);
SDL_assert(devid != NULL);
Expand Down
2 changes: 1 addition & 1 deletion src/events/SDL_keyboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,7 @@ int SDL_SetKeyboardFocus(SDL_Window *window)
if (keyboard->focus && keyboard->focus != window) {

/* new window shouldn't think it has mouse captured. */
SDL_assert(!window || !(window->flags & SDL_WINDOW_MOUSE_CAPTURE));
SDL_assert(window == NULL || !(window->flags & SDL_WINDOW_MOUSE_CAPTURE));

/* old window must lose an existing mouse capture. */
if (keyboard->focus->flags & SDL_WINDOW_MOUSE_CAPTURE) {
Expand Down
2 changes: 1 addition & 1 deletion src/filesystem/haiku/SDL_sysfilesystem.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ char *SDL_GetBasePath(void)
rc = path.GetParent(&path); /* chop filename, keep directory. */
SDL_assert(rc == B_OK);
const char *str = path.Path();
SDL_assert(str);
SDL_assert(str != NULL);

const size_t len = SDL_strlen(str);
char *retval = (char *) SDL_malloc(len + 2);
Expand Down
2 changes: 1 addition & 1 deletion src/filesystem/unix/SDL_sysfilesystem.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ static char *search_path_for_binary(const char *bin)
return NULL;
}

SDL_assert(bin);
SDL_assert(bin != NULL);

alloc_size = SDL_strlen(bin) + SDL_strlen(envr) + 2;
exe = (char *)SDL_malloc(alloc_size);
Expand Down
2 changes: 1 addition & 1 deletion src/haptic/android/SDL_syshaptic.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ static SDL_hapticlist_item *HapticByOrder(int index)
return NULL;
}
while (index > 0) {
SDL_assert(item);
SDL_assert(item != NULL);
--index;
item = item->next;
}
Expand Down
Loading

0 comments on commit 04b6b29

Please sign in to comment.