Skip to content

allow for native mod functions to initialize records #1487

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
erickt opened this issue Jan 10, 2012 · 4 comments
Closed

allow for native mod functions to initialize records #1487

erickt opened this issue Jan 10, 2012 · 4 comments
Labels
A-type-system Area: Type system C-enhancement Category: An issue proposing an enhancement or a PR with one. E-hard Call for participation: Hard difficulty. Experience needed to fix: A lot.

Comments

@erickt
Copy link
Contributor

erickt commented Jan 10, 2012

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.

@graydon
Copy link
Contributor

graydon commented Feb 15, 2012

I don't think this is invasive enough to warrant an RFC, un-tagging.

It's not a bad idea, and I don't object; we'd just need support for function postconditions (#586) and a way to denote the init predicate. Certainly an unsafe operation.

@catamorphism
Copy link
Contributor

@graydon : now that we don't have typestate, can liveness do this or is it too hard now?

@yichoi
Copy link
Contributor

yichoi commented Apr 25, 2013

Rust does not support record anymore

@catamorphism
Copy link
Contributor

It's still relevant with structs, but I think we have a good enough solution for this (passing in a reference to a zeroed-out struct; for example, as with libc::stat). Closing.

celinval pushed a commit to celinval/rust-dev that referenced this issue Jun 4, 2024
…ctions (rust-lang#1487)

* Update intrinsics table

* Test new orderings
Kobzol pushed a commit to Kobzol/rust that referenced this issue Dec 30, 2024
bors pushed a commit to rust-lang-ci/rust that referenced this issue Jan 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-type-system Area: Type system C-enhancement Category: An issue proposing an enhancement or a PR with one. E-hard Call for participation: Hard difficulty. Experience needed to fix: A lot.
Projects
None yet
Development

No branches or pull requests

4 participants