Skip to content

Commit

Permalink
Be sure to treat &str as UTF8
Browse files Browse the repository at this point in the history
  • Loading branch information
eqrion committed Nov 9, 2017
1 parent 8279373 commit a0068c6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
3 changes: 2 additions & 1 deletion compile-tests/constant.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const FOO: i32 = 10;
const BAR: &'static libc::c_char = "hello world";
const BAR: &'static str = "hello world";
const ZOM: f32 = 3.14;

#[repr(C)]
struct Foo {
Expand Down
2 changes: 1 addition & 1 deletion src/bindgen/ir/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ impl LiteralExpr {
pub fn load(expr: &syn::Expr) -> Result<LiteralExpr, String> {
match &expr.node {
&syn::ExprKind::Lit(syn::Lit::Str(ref text, ..)) => {
Ok(LiteralExpr(format!("\"{}\"", text)))
Ok(LiteralExpr(format!("u8\"{}\"", text)))
}
&syn::ExprKind::Lit(syn::Lit::Byte(value)) => {
Ok(LiteralExpr(format!("{}", value)))
Expand Down
4 changes: 4 additions & 0 deletions src/bindgen/ir/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ pub enum PrimitiveType {
Float,
Double,
SizeT,
Str,
}

impl PrimitiveType {
Expand Down Expand Up @@ -79,6 +80,7 @@ impl PrimitiveType {
"f32" => Some(PrimitiveType::Float),
"f64" => Some(PrimitiveType::Double),
"size_t" => Some(PrimitiveType::SizeT),
"str" => Some(PrimitiveType::Str),
_ => None,
}
}
Expand Down Expand Up @@ -112,6 +114,7 @@ impl PrimitiveType {
&PrimitiveType::Float => "f32",
&PrimitiveType::Double => "f64",
&PrimitiveType::SizeT => "size_t",
&PrimitiveType::Str => "str",
}
}

Expand Down Expand Up @@ -144,6 +147,7 @@ impl PrimitiveType {
&PrimitiveType::Float => "float",
&PrimitiveType::Double => "double",
&PrimitiveType::SizeT => "size_t",
&PrimitiveType::Str => "char",
}
}

Expand Down

0 comments on commit a0068c6

Please sign in to comment.