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

Assertion at analyze.cpp:5576 when compiling -- implicit cast to *c_void problem #4357

Closed
wilsonk opened this issue Feb 1, 2020 · 0 comments
Labels
bug Observed behavior contradicts documented or intended behavior stage1 The process of building from source via WebAssembly and the C backend.
Milestone

Comments

@wilsonk
Copy link
Contributor

wilsonk commented Feb 1, 2020

This may be a duplicate of #4246 (or just similar) but I ran int an error when trying to use SDL audio ala:

pub usingnamespace @cImport({
     @cInclude("SDL.h");
     @cDefine("SDL_WINDOWPOS_UNDEFINED", "0x1fff000");
 });
 
 const SdlAudioRingBuffer = struct {
     size: usize,
     write_cursor: usize,
     play_cursor: usize,
     data: [*]u8,
 };
 
 var AudioRingBuffer: SdlAudioRingBuffer = undefined;
 pub fn SDLAudioCallback(user_data: ?*c_void, audio_data: ?[*]u8, length: c_int) callconv(.C) void {}
 
 test "bad implicit cast to extern *c_void" {
     var audio_settings: SDL_AudioSpec = undefined;
 
     audio_settings.freq = @intCast(c_int, 1);
     audio_settings.format = 32784;
     audio_settings.channels = 2;
     audio_settings.samples = 1024;
     audio_settings.callback = SDLAudioCallback;
     audio_settings.userdata = &AudioRingBuffer; // works with explicit cast - @ptrCast(*c_void, &AudioRingBuffer);
 
     return;
 }

Hopefully this is minimized enough. Of course, I am just working around the problem with the explicit
cast, as per the comment in the code.

Thanks

LemonBoy added a commit to LemonBoy/zig that referenced this issue Feb 1, 2020
Calling type_has_bits instead of type_has_bits2 makes the compiler crash
and burn if one of the two types passed in are not resolved yet.

Closes ziglang#4357
@andrewrk andrewrk added bug Observed behavior contradicts documented or intended behavior stage1 The process of building from source via WebAssembly and the C backend. labels Feb 10, 2020
@andrewrk andrewrk added this to the 0.7.0 milestone Feb 10, 2020
@andrewrk andrewrk modified the milestones: 0.7.0, 0.6.0 Mar 4, 2020
alexnask pushed a commit to alexnask/zig that referenced this issue Mar 5, 2020
And fix most of the fallout. This also makes optional pointers not
require resolving zero bits, because the comptime value struct layout no
longer depends on whether the type has zero bits.

Thanks to @LemonBoy for the behavior test case

Closes ziglang#4357
Closes ziglang#4359
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior stage1 The process of building from source via WebAssembly and the C backend.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants