Skip to content

PaStream being void is type-unsafe and error-prone #915

@dechamps

Description

@dechamps

In dechamps/FlexASIO@59f75ce, I introduced a severe bug (dechamps/FlexASIO#231) because I accidentally wrote:

Pa_GetStreamInfo(&stream)

Instead of:

Pa_GetStreamInfo(stream)

It is very sad that the obviously wrong code was able to compile.

The reason why that code managed to sift through the cracks is because PaStream* is defined as void*:

typedef void PaStream;

The problem with void* is that any pointer can be implicitly converted to it, making it very type-unsafe. You could write the following and the compiler won't bat an eye:

int a;
Pa_GetStreamInfo(&a);

I believe it would be more developer-friendly to make PaStream a type-safe opaque type, for example:

typedef struct PaStream PaStream;

This change shouldn't break anyone as long as user code does not rely on PaStream specifically being an alias to void - which seems unlikely. If it does break it's a compile-time error so it shouldn't take anyone by surprise.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Priority: Normalpublic-apiThe public API defined in include/PortAudio.h

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions