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

Not clear how to test const <type> <obj>; fields #31

Open
quodlibetor opened this issue May 30, 2018 · 2 comments
Open

Not clear how to test const <type> <obj>; fields #31

quodlibetor opened this issue May 30, 2018 · 2 comments

Comments

@quodlibetor
Copy link

See this comment in git2-rs for details: https://github.com/alexcrichton/git2-rs/pull/315#issuecomment-393006101

@gnzlbg
Copy link
Owner

gnzlbg commented Oct 16, 2018

Given:

// rust
#[repr(C)]
struct Foo {
  pub bar: i32
}

and

// c
struct Foo {
   const int32_t bar;
};

the Rust code does not expose any information about whether the C field is cv-qualified or not. That is, I don't think we can generate appropriate C tests for the struct field type just from only looking at the Rust code.

We could, conservatively, assume that C struct fields are always const qualified. I've implemented that approach in #41 .

This won't, however, work if the C struct fields are cv-qualified in general. Maybe we could add a way in the future to specify that certain fields from certain structs are cv-qualified, e.g., via a method to the test generator.

Maybe someday we could replace most methods with attributes:

// rust
#[repr(C)]
struct Foo {
  #[cfg_attr(ctest, const_qualified)]
  pub bar: i32
}

@gnzlbg
Copy link
Owner

gnzlbg commented Jul 29, 2019

I think a better idea is to expose a method in the builder that allows you to tell ctest that a particular field of a struct is cv-qualified. That shouldn't be to hard to hack in, and I think we already have such a method for volatile.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants