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

Parse fields in classes and generate correct class structs #276

Closed
wants to merge 0 commits into from
Closed

Parse fields in classes and generate correct class structs #276

wants to merge 0 commits into from

Conversation

eugene2k
Copy link
Contributor

This pull request makes it possible for the generator to generate proper class structs, which is very useful for creating custom widgets for example. I haven't tested it much, mostly because I'm not very familiar with gtk-rs (or gtk+, for that matter), so if you see any problems with it, please point them out to me.

@@ -72,6 +72,7 @@ fn generate_lib(w: &mut Write, env: &Env) -> Result<()>{

try!(writeln!(w, "\n}}"));


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this empty line?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly, I have no idea what is going on here. My local repository doesn't have that line and git says "nothing to commit" and "everything up to date"...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, my whole file is different... wth...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, this was stupid, but forgot to switch branches :)

try!(writeln!(w, "{}#[repr(C)]\n{0}pub struct {} {{", comment, klass.c_type));

for line in lines {
try!(writeln!(w, "{}{}", comment, line));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't a comma missing in here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

err... where?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aren't you writing struct's fields? (It's totally possible that I misunderstood what you were doing here.)

Copy link
Contributor Author

@eugene2k eugene2k Oct 20, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not quite. The fields are in generate_fields, which generates indented lines that end with a comma. I could move the comma out of generate_fields, though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, the original code wasn't written by me (I think @EPashkin wrote it), I simply modified it to work with classes as well as records, as I didn't see any reason it shouldn't.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, so it confirms what I thought. My bad. :p


let comment = if commented { "//" } else { "" };
if lines.is_empty() {
try!(writeln!(w, "{}#[repr(C)]\n{0}pub struct {}(c_void);\n", comment, klass.c_type));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you use named parameters instead of {} and {0} please?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. FYI, though, I copied the style from generate_records.

try!(writeln!(w, "{}#[repr(C)]\n{0}pub struct {}(c_void);\n", comment, klass.c_type));
}
else {
try!(writeln!(w, "{}#[repr(C)]\n{0}pub struct {} {{", comment, klass.c_type));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above.

@GuillaumeGomez
Copy link
Member

Sorry for the delay.

cc @EPashkin @gkoz

@GuillaumeGomez
Copy link
Member

All good for me now. Waiting for @EPashkin and @gkoz.

@EPashkin
Copy link
Member

EPashkin commented Oct 20, 2016

Changes made by this PR in sys crate: EPashkin/rust-gnome-sys@be6f7c5
Not sure that we want show gtk internals, but for custom widget it may be needed (don't know how do create custom widget).

@EPashkin
Copy link
Member

May be this need be separated as special mode.

@eugene2k
Copy link
Contributor Author

eugene2k commented Oct 21, 2016

Hmm... seeing as how the same types of fields are randomly private or public, I can force them all to be private, until someone actually raises an issue...

@gkoz
Copy link
Member

gkoz commented Oct 27, 2016

I'm coming round to making all fields public as requested in gtk-rs/sys#25. Given the advances in bindgen and apparent intention of the Rust project to integrate more C interoperability in 2017, it seems undesirable to diverge from C headers too much, and C doesn't have private fields.

@eugene2k
Copy link
Contributor Author

eugene2k commented Oct 27, 2016

C doesn't have private fields

Which doesn't seem to be much of a problem for the GTK developers who create them...
/rant

@EPashkin
Copy link
Member

EPashkin commented Dec 7, 2016

@GuillaumeGomez, how you think, better make all fields public?
While pub priv_: gpointer look strange, it may be solve some problem with custom objects.

@EPashkin
Copy link
Member

EPashkin commented Dec 7, 2016

On other side, if we find, that all pub is wrong and unneeded changing it back it's be breaking change

@GuillaumeGomez
Copy link
Member

I think that all FFI struct's fields should be public. Otherwise, it depends if it is an internal mechanism or not.

@EPashkin
Copy link
Member

EPashkin commented Dec 8, 2016

@GuillaumeGomez, seems it works, as you say.
@eugene2k, sorry for long wait, can you squash commits to one?

@EPashkin
Copy link
Member

EPashkin commented Dec 8, 2016

@GuillaumeGomez, about extra empty lines from https://github.com/gtk-rs/gir/blob/master/src/codegen/sys/lib_.rs#L245 etc: I think that better be replaced later with something like

if(!interfaces.is_empty()) {
    try!(writeln!(w, "//Interfaces"));
}

@GuillaumeGomez
Copy link
Member

@EPashkin: You mean // Interfaces, right? :p
@eugene2k: Just like @EPashkin said: please squash your commits into one and then I merge.

@eugene2k eugene2k closed this Dec 8, 2016
@eugene2k
Copy link
Contributor Author

eugene2k commented Dec 8, 2016

@EPashkin, @GuillaumeGomez
I seem to have messed up my repo branches, so I'll resubmit the pull request in a moment

@GuillaumeGomez
Copy link
Member

Sure, no worries.

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

Successfully merging this pull request may close these issues.

4 participants