Skip to content

Commit

Permalink
Make PaStream a stronger type
Browse files Browse the repository at this point in the history
This changes PaStream* from a pointer to void to a pointer to an
undefined, but unique type. This ensures functions that take a PaStream*
reject incompatible types, for improved type safety.

While this is technically an API change, it is unlikely to break anyone
as it's unlikely user code depends on this type being void specifically
(unless they suffer from the bugs that this change is designed to
prevent!).

Fixes PortAudio#915
  • Loading branch information
dechamps committed May 28, 2024
1 parent 18a606e commit 0d8c084
Show file tree
Hide file tree
Showing 8 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion include/portaudio.h
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ PaError Pa_IsFormatSupported( const PaStreamParameters *inputParameters,
Pa_GetStreamTime, Pa_GetStreamCpuLoad
*/
typedef void PaStream;
typedef struct PaStream PaStream;


/** Can be passed as the framesPerBuffer parameter to Pa_OpenStream()
Expand Down
2 changes: 1 addition & 1 deletion src/common/pa_front.c
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ static void CloseOpenStreams( void )
logic is used for automatically closed streams */

while( firstOpenStream_ != NULL )
Pa_CloseStream( firstOpenStream_ );
Pa_CloseStream( (PaStream*)firstOpenStream_ );
}


Expand Down
4 changes: 2 additions & 2 deletions src/hostapi/alsa/pa_linux_alsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -3029,7 +3029,7 @@ static PaError StartStream( PaStream *s )
error:
if( streamStarted )
{
AbortStream( stream );
AbortStream( (PaStream*)stream );
}
stream->isActive = 0;

Expand Down Expand Up @@ -4549,7 +4549,7 @@ static PaError WriteStream( PaStream* s, const void *buffer, unsigned long frame
/* Start stream after one period of samples worth */

/* Frames residing in buffer */
PA_ENSURE( err = GetStreamWriteAvailable( stream ) );
PA_ENSURE( err = GetStreamWriteAvailable( (PaStream*)stream ) );
framesAvail = err;
hwAvail = stream->playback.alsaBufferSize - framesAvail;

Expand Down
2 changes: 1 addition & 1 deletion src/hostapi/coreaudio/pa_mac_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -2088,7 +2088,7 @@ static PaError OpenStream( struct PaUtilHostApiRepresentation *hostApi,
return result;

error:
CloseStream( stream );
CloseStream( (PaStream*)stream );
return result;
}

Expand Down
2 changes: 1 addition & 1 deletion src/hostapi/jack/pa_jack.c
Original file line number Diff line number Diff line change
Expand Up @@ -1756,7 +1756,7 @@ static PaError RealStop( PaJackStream *stream, int abort )
int i;

if( stream->isBlockingStream )
BlockingWaitEmpty ( stream );
BlockingWaitEmpty ( (PaStream*)stream );

ASSERT_CALL( pthread_mutex_lock( &stream->hostApi->mtx ), 0 );
if( abort )
Expand Down
2 changes: 1 addition & 1 deletion src/hostapi/pulseaudio/pa_linux_pulseaudio_cb.c
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,7 @@ PaError PaPulseAudio_StartStreamCb( PaStream * s )

if( pulseaudioPlaybackStarted || pulseaudioRecordStarted )
{
PaPulseAudio_AbortStreamCb( stream );
PaPulseAudio_AbortStreamCb( (PaStream*)stream );
}

stream->isActive = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/hostapi/sndio/pa_sndio.c
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ static PaError OpenStream( struct PaUtilHostApiRepresentation *hostApi, PaStream
sndioStream->mode = mode;
sndioStream->hdl = hdl;
sndioStream->par = par;
*paStream = sndioStream;
*paStream = (PaStream*)sndioStream;
PA_DEBUG( ( "OpenStream: done\n" ) );
return paNoError;
}
Expand Down
2 changes: 1 addition & 1 deletion src/hostapi/wasapi/pa_win_wasapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -4134,7 +4134,7 @@ static PaError OpenStream( struct PaUtilHostApiRepresentation *hostApi,
error:

if (stream != NULL)
CloseStream(stream);
CloseStream((PaStream*)stream);

return result;
}
Expand Down

0 comments on commit 0d8c084

Please sign in to comment.