Skip to content

allow for native mod functions to initialize records #1487

Closed
@erickt

Description

@erickt

Some C libraries want you to create a structure on the stack and pass it off to be initialized by some function. Right now the typestate requires all structures to be fully defined before being passed to a function, so I'm finding myself having to write:

type foo_t = { p: *ctypes::void, i: ctypes::c_int };

native mod foo {
    fn f(foo: foo_t);
}

fn bar() {
    let x = { p: ptr::null(), i: 0 as ctypes::c_int };
    foo::f(x);
    ...
}

Since I'm passing raw pointers to c, it's naturally unsafe, so it'd be nice if we could allow foo_t to be opaque to the typestate system. What if we allow native module functions to have a flag saying they can initialize an uninitialized value? It'd help simplify binding to third party libraries.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-type-systemArea: Type systemC-enhancementCategory: An issue proposing an enhancement or a PR with one.E-hardCall for participation: Hard difficulty. Experience needed to fix: A lot.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions