Skip to content

@TypeInfo on @cImport crashes the compiler #4997

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

Closed
hollmmax opened this issue Apr 10, 2020 · 2 comments
Closed

@TypeInfo on @cImport crashes the compiler #4997

hollmmax opened this issue Apr 10, 2020 · 2 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

@hollmmax
Copy link
Contributor

using version 0.5.0+487134554

const std = @import("std");
const warn = std.debug.warn;
const c = @cImport({
    @cInclude("stdio.h");
});

const TypeId = @import("builtin").TypeId;

test "libC reflection" {
    switch (@typeInfo(c)) {
        TypeId.Struct => |items| {
            warn("{}\n", .{items.decls.len});
        },
        else => warn("{}\n", .{@typeName(c)}),
    }
}
@Vexu
Copy link
Member

Vexu commented Apr 10, 2020

By doing items.decls.len you are forcing all declarations in the translated stdio.h into existence. That includes many long double related macros which are causing you to hit TODOs in the compiler since c_longdouble is currently completely broken #1188.

@andrewrk andrewrk added the bug Observed behavior contradicts documented or intended behavior label Apr 10, 2020
@andrewrk andrewrk added this to the 0.7.0 milestone Apr 10, 2020
@andrewrk andrewrk added the stage1 The process of building from source via WebAssembly and the C backend. label Apr 10, 2020
@lodi
Copy link

lodi commented Jul 18, 2020

I also ran into this issue today. I thought maybe a simpler header would work...

const c = @cImport({
    @cInclude("stdbool.h");
});

But I get the same "TODO" compiler panic as OP. In fact, I also get a panic with an empty import...

const c = @cImport({
});

(zig 0.6.0)


Would be amazing if this worked though; we could use zig to generate c library bindings for other languages.

@andrewrk andrewrk modified the milestones: 0.7.0, 0.8.0 Aug 13, 2020
@andrewrk andrewrk modified the milestones: 0.8.0, 0.9.0 Nov 6, 2020
@andrewrk andrewrk modified the milestones: 0.9.0, 0.10.0 May 19, 2021
Vexu added a commit to Vexu/zig that referenced this issue Dec 31, 2022
Vexu added a commit to Vexu/zig that referenced this issue Dec 31, 2022
@andrewrk andrewrk modified the milestones: 0.12.0, 0.11.0 Jan 1, 2023
TUSF pushed a commit to TUSF/zig that referenced this issue May 9, 2024
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

No branches or pull requests

4 participants