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

support @asyncCall with null as the result pointer #3068

Closed
andrewrk opened this issue Aug 15, 2019 · 0 comments
Closed

support @asyncCall with null as the result pointer #3068

andrewrk opened this issue Aug 15, 2019 · 0 comments
Labels
enhancement Solving this issue will likely involve adding new logic or components to the codebase. stage1 The process of building from source via WebAssembly and the C backend.
Milestone

Comments

@andrewrk
Copy link
Member

This should work:

const std = @import("std");
const expect = std.testing.expect;

test "async fn pointer in a struct field" {
    var data: i32 = 1;
    const Foo = struct {
        bar: async fn (*i32) i32,
    };
    var foo = Foo{ .bar = simpleAsyncFn2 };
    var bytes: [64]u8 = undefined;
    const f = @asyncCall(&bytes, null, foo.bar, &data);
    comptime expect(@typeOf(f) == anyframe->i32);
    expect(data == 2);
    resume f;
    expect(data == 4);
}

async fn simpleAsyncFn2(y: *i32) i32 {
    defer y.* += 2;
    y.* += 1;
    suspend;
    return 1234;
}

Current output:

Segmentation fault at address 0x0
@andrewrk andrewrk added enhancement Solving this issue will likely involve adding new logic or components to the codebase. stage1 The process of building from source via WebAssembly and the C backend. labels Aug 15, 2019
@andrewrk andrewrk added this to the 0.5.0 milestone Aug 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Solving this issue will likely involve adding new logic or components to the codebase. stage1 The process of building from source via WebAssembly and the C backend.
Projects
None yet
Development

No branches or pull requests

1 participant