Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In the C API, conduit_node is void which allows for surprising conversions #782

Closed
mathstuf opened this issue Jun 22, 2021 · 3 comments · Fixed by #795
Closed

In the C API, conduit_node is void which allows for surprising conversions #782

mathstuf opened this issue Jun 22, 2021 · 3 comments · Fixed by #795
Labels
Milestone

Comments

@mathstuf
Copy link
Contributor

Currently, the C API does:

typedef void conduit_node;

which means the APIs are all really:

void conduit_node_some_api(const void* node);

to the compiler. This means that:

std::vector<int> vec;
conduit_node_some_api(&vec);

typechecks and compiles just fine (and probably crashes or causes some other kinds of fireworks at runtime). Instead, it should be something like:

struct _conduit_node;
typedef struct _conduit_node conduit_node;

so that there is a distinct type associated with the call and the compiler can at least complain that types don't match (or that the user has to explicitly do a C cast or reinterpret_cast in which case the fault is squarely in their code).

Cc: @cyrush @utkarshayachit

@mathstuf
Copy link
Contributor Author

mathstuf commented Jul 4, 2021

I'd like to investigate fixing this in some way. Who else should be involved in such a discussion?

@cyrush
Copy link
Member

cyrush commented Jul 6, 2021

@mathstuf sorry for the delay. I agree this is an improvement. First step would be making the change and seeing if there are any surprises in CI.

@cyrush cyrush added this to the 0.8.0 milestone Jul 6, 2021
mathstuf added a commit to mathstuf/conduit that referenced this issue Jul 19, 2021
Using `typedef void` meant that the APIs were all taking `void*` which
in turn means that any pointer is valid to pass to these types. Instead,
use a unique opaque type so that callers must either do the unsafe
casting themselves or use the `cpp_to_c` APIs to do the casting the
intended way.

The actual definition of the structs themselves are empty; they are just
used it as a way to smuggle the C++ pointer around under an opaque name.

Fixes: LLNL#782
@mathstuf
Copy link
Contributor Author

See #795. The fix is pretty simple and doesn't seem to break the build here at least. Hopefully Catalyst and ParaView have been as careful…

@cyrush cyrush added the design label Jul 20, 2021
mathstuf added a commit to mathstuf/conduit that referenced this issue Jul 20, 2021
Using `typedef void` meant that the APIs were all taking `void*` which
in turn means that any pointer is valid to pass to these types. Instead,
use a unique opaque type so that callers must either do the unsafe
casting themselves or use the `cpp_to_c` APIs to do the casting the
intended way.

The actual definition of the structs themselves are empty; they are just
used it as a way to smuggle the C++ pointer around under an opaque name.

Fixes: LLNL#782
cyrush pushed a commit that referenced this issue Jul 20, 2021
Using `typedef void` meant that the APIs were all taking `void*` which
in turn means that any pointer is valid to pass to these types. Instead,
use a unique opaque type so that callers must either do the unsafe
casting themselves or use the `cpp_to_c` APIs to do the casting the
intended way.

The actual definition of the structs themselves are empty; they are just
used it as a way to smuggle the C++ pointer around under an opaque name.

Fixes: #782
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants