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
Generate Debug for sys types #488
Conversation
All green. :) |
try!(writeln!( | ||
w, | ||
"{comment}#[repr(C)]\n{comment}pub struct {name} {{", | ||
"{comment}#[repr(C)]\n{debug}{comment}pub struct {name} {{", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line seems generated struct with extra line:
#[repr(C)]
pub struct AtkAttribute {
pub name: *mut c_char,
pub value: *mut c_char,
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wo. Where does this backline comes from? Oo
src/codegen/sys/lib_.rs
Outdated
{fields_name})\n\ | ||
\t}}\n\ | ||
}}\n", | ||
name = klass.c_type, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, but this unreadable, and seems repeated at minimum twice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True. I'll write a function and maybe comment or create temporary variables in order to make this less horrible.
src/codegen/sys/lib_.rs
Outdated
@@ -456,15 +572,26 @@ fn generate_records(w: &mut Write, env: &Env, records: &[&Record]) -> Result<()> | |||
} | |||
try!(writeln!( | |||
w, | |||
"{}#[repr(C)]\n{0}pub struct {} {{", | |||
"{}#[repr(C)]\n{}\n{0}pub struct {} {{", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@EPashkin: It comes from here actually.
6f120d0
to
3283e71
Compare
src/codegen/sys/lib_.rs
Outdated
\t\twrite!(f, \"{name} @ {{:?}}\", self as *const _)\n\ | ||
\t}}\n\ | ||
}}\n", | ||
name=record.c_type)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO this better extract as function too and maybe use raw string for format
This intended that inner fields not comma-separated?
|
Hum yes. Do you want comma? |
Then its normal, just strange. |
I'll add the comma tomorrow then. ;) |
3283e71
to
5a15289
Compare
Updated. |
For printing things struct-like, please use the functions from Formatter like debug_struct() |
src/codegen/sys/lib_.rs
Outdated
w, | ||
name, | ||
&format!( | ||
"write!(f, \"{name} @ {{:?}} {{{{ {fields}}}}}\",\n\ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO extra space needed {{{{ {fields} }}}}
src/codegen/sys/lib_.rs
Outdated
impl_content) | ||
} | ||
|
||
fn generate_fields_with_debug(w: &mut Write, name: &str, lines: &[String]) -> Result<()> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not generate_debug_with_fields
?
Updated and improved. Thanks for the suggestion @sdroege! |
} else { | ||
let field_name = field.split(":").next().unwrap().trim().replace("pub ", ""); | ||
Some(if field.replace(",", "").trim().ends_with("c_void") { | ||
format!("\t\t .field(\"{name}\", &\"c_void\")\n", name=field_name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is really need write constant string in debug result?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant: maybe better just skip this field?
Current results:
//gobject
impl ::std::fmt::Debug for GParamSpecString {
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
f.debug_struct(&format!("GParamSpecString @ {:?}", self as *const _))
.field("parent_instance", &self.parent_instance)
.field("default_value", &self.default_value)
.field("cset_first", &self.cset_first)
.field("cset_nth", &self.cset_nth)
.field("substitutor", &self.substitutor)
.field("_truncated_record_marker", &"c_void")
.finish()
}
}
//gtk
impl ::std::fmt::Debug for GtkRcStyle {
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
f.debug_struct(&format!("GtkRcStyle @ {:?}", self as *const _))
.field("parent_instance", &self.parent_instance)
.field("name", &self.name)
.field("bg_pixmap_name", &self.bg_pixmap_name)
.field("font_desc", &self.font_desc)
.field("color_flags", &self.color_flags)
.field("fg", &self.fg)
.field("bg", &self.bg)
.field("text", &self.text)
.field("base", &self.base)
.field("xthickness", &self.xthickness)
.field("ythickness", &self.ythickness)
.field("rc_properties", &self.rc_properties)
.field("rc_style_lists", &self.rc_style_lists)
.field("icon_factories", &self.icon_factories)
.field("_truncated_record_marker", &"c_void")
.finish()
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want all fields to be there. So better having a useless "c_void" string than nothing from my point of view.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok
@sdroege, is good for you now? |
w, | ||
&klass.c_type, | ||
&format!("write!(f, \"{name} @ {{:?}}\", self as *const _)", | ||
name=klass.c_type) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could use debug_tuple(name).field(the_pointer_string).build() here
w, | ||
&interface.c_type, | ||
&format!("write!(f, \"{name} @ {{:?}}\", self as *const _)", | ||
name=interface.c_type) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And here
w, | ||
&record.c_type, | ||
&format!("write!(f, \"{name} @ {{:?}}\", self as *const _)", | ||
name=record.c_type) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And here
Feel free to ignore that comment, it's all good to go for me. |
I'll let you handle the merging @EPashkin. |
Sorry but I want to quickly move towards the next release so I'll merge this and make a PR for the sys repository. |
Thanks, @GuillaumeGomez |
Generate Debug for sys types
Fixes #486.
cc @EPashkin @sdroege