Skip to content

Commit 0983668

Browse files
committed
Fix CI regressions
SDL_CommonEvent needed to be marked as packed Closing audio streams atexit seems to cause race conditions Remove outdated Sphinx directives
1 parent 39d28d4 commit 0983668

File tree

3 files changed

+20
-23
lines changed

3 files changed

+20
-23
lines changed

build_sdl.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
"SDL_TouchFingerEvent",
5252
"SDL_MultiGestureEvent",
5353
"SDL_DollarGestureEvent",
54+
"SDL_CommonEvent",
5455
)
5556

5657
# Other defined names which sometimes cause issues when parsed.

tcod/sdl/audio.py

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737

3838
from __future__ import annotations
3939

40-
import atexit
4140
import contextlib
4241
import enum
4342
import sys
@@ -483,14 +482,6 @@ class AudioStreamCallbackData:
483482
_audio_stream_registry: weakref.WeakValueDictionary[int, AudioStream] = weakref.WeakValueDictionary()
484483

485484

486-
@atexit.register
487-
def _unlink_audio_callbacks() -> None:
488-
"""Deletes AudioStream callbacks to ensure a graceful application exit."""
489-
for stream in _audio_stream_registry.values():
490-
stream.getter_callback = None
491-
stream.putter_callback = None
492-
493-
494485
class AudioStream:
495486
"""An SDL audio stream.
496487
@@ -674,11 +665,13 @@ def getter_callback(self) -> Callable[[AudioStream, AudioStreamCallbackData], An
674665
@getter_callback.setter
675666
def getter_callback(self, callback: Callable[[AudioStream, AudioStreamCallbackData], Any] | None, /) -> None:
676667
if callback is None:
677-
lib.SDL_SetAudioStreamGetCallback(self._stream_p, ffi.NULL, ffi.NULL)
668+
_check(lib.SDL_SetAudioStreamGetCallback(self._stream_p, ffi.NULL, ffi.NULL))
678669
_audio_stream_get_callbacks.pop(self, None)
679670
else:
680671
_audio_stream_get_callbacks[self] = callback
681-
lib.SDL_SetAudioStreamGetCallback(self._stream_p, lib._sdl_audio_stream_callback, ffi.cast("void*", 0))
672+
_check(
673+
lib.SDL_SetAudioStreamGetCallback(self._stream_p, lib._sdl_audio_stream_callback, ffi.cast("void*", 0))
674+
)
682675

683676
@property
684677
def putter_callback(self) -> Callable[[AudioStream, AudioStreamCallbackData], Any] | None:
@@ -692,11 +685,13 @@ def putter_callback(self) -> Callable[[AudioStream, AudioStreamCallbackData], An
692685
@putter_callback.setter
693686
def putter_callback(self, callback: Callable[[AudioStream, AudioStreamCallbackData], Any] | None, /) -> None:
694687
if callback is None:
695-
lib.SDL_SetAudioStreamPutCallback(self._stream_p, ffi.NULL, ffi.NULL)
688+
_check(lib.SDL_SetAudioStreamPutCallback(self._stream_p, ffi.NULL, ffi.NULL))
696689
_audio_stream_put_callbacks.pop(self, None)
697690
else:
698691
_audio_stream_put_callbacks[self] = callback
699-
lib.SDL_SetAudioStreamPutCallback(self._stream_p, lib._sdl_audio_stream_callback, ffi.cast("void*", 0))
692+
_check(
693+
lib.SDL_SetAudioStreamPutCallback(self._stream_p, lib._sdl_audio_stream_callback, ffi.cast("void*", 1))
694+
)
700695

701696

702697
class _LoopSoundFunc:
@@ -1032,17 +1027,10 @@ def open( # noqa: A001, PLR0913
10321027
paused:
10331028
If True then the device will begin in a paused state.
10341029
It can then be unpaused by assigning False to :any:`AudioDevice.paused`.
1035-
callback:
1036-
If None then this device will be opened in push mode and you'll have to use :any:`AudioDevice.queue_audio`
1037-
to send audio data or :any:`AudioDevice.dequeue_audio` to receive it.
1038-
If a callback is given then you can change it later, but you can not enable or disable the callback on an
1039-
opened device.
1040-
If True then a default callback which plays silence will be used, this is useful if you need the audio
1041-
device before your callback is ready.
1030+
callback: An optional callback to use, this is deprecated.
10421031
10431032
If a callback is given then it will be called with the `AudioDevice` and a Numpy buffer of the data stream.
10441033
This callback will be run on a separate thread.
1045-
Exceptions not handled by the callback become unraiseable and will be handled by :any:`sys.unraisablehook`.
10461034
10471035
.. versionchanged:: Unreleased
10481036
SDL3 returns audio devices differently, exact formatting is set with :any:`AudioDevice.new_stream` instead.

tests/test_sdl_audio.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,19 @@
1414
# ruff: noqa: D103
1515

1616

17+
def device_works(device: tcod.sdl.audio.AudioDevice) -> bool:
18+
try:
19+
device.open().close()
20+
except RuntimeError:
21+
return False
22+
return True
23+
24+
1725
needs_audio_device = pytest.mark.xfail(
18-
not list(tcod.sdl.audio.get_devices()), reason="This test requires an audio device"
26+
not device_works(tcod.sdl.audio.get_default_playback()), reason="This test requires an audio device"
1927
)
2028
needs_audio_capture = pytest.mark.xfail(
21-
not list(tcod.sdl.audio.get_capture_devices()), reason="This test requires an audio capture device"
29+
not device_works(tcod.sdl.audio.get_default_recording()), reason="This test requires an audio capture device"
2230
)
2331

2432

0 commit comments

Comments
 (0)