Skip to content

Commit

Permalink
keep compat with rust 1.57.0
Browse files Browse the repository at this point in the history
  • Loading branch information
fredszaq committed Jul 21, 2023
1 parent 7fee32a commit 2f48952
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 30 deletions.
4 changes: 2 additions & 2 deletions src/bindgen/ir/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ impl ConditionWrite for Option<Condition> {
out.new_line();
}
Language::JavaJna => {
write!(out, "/* begin condition not supported {self:?} */");
write!(out, "/* begin condition not supported {:?} */", self);
out.new_line();
}
}
Expand All @@ -371,7 +371,7 @@ impl ConditionWrite for Option<Condition> {
}
Language::JavaJna => {
out.new_line();
write!(out, "/* end condition not supported {self:?} */");
write!(out, "/* end condition not supported {:?} */", &self);
}
}
}
Expand Down
44 changes: 22 additions & 22 deletions src/bindgen/language_backend/java_jna.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl LanguageBackend for JavaJnaLanguageBackend {
fn write_headers<W: Write>(&self, out: &mut SourceWriter<W>) {
if let Some(ref header) = self.config.header {
out.new_line_if_not_start();
write!(out, "{header}");
write!(out, "{}", header);
out.new_line();
}

Expand All @@ -42,13 +42,13 @@ impl LanguageBackend for JavaJnaLanguageBackend {
}
if let Some(ref autogen_warning) = self.config.autogen_warning {
out.new_line_if_not_start();
write!(out, "{autogen_warning}");
write!(out, "{}", autogen_warning);
out.new_line();
}

if let Some(ref package) = self.config.java_jna.package {
out.new_line_if_not_start();
write!(out, "package {package};");
write!(out, "package {};", package);
out.new_line();
out.new_line();
}
Expand All @@ -67,7 +67,7 @@ impl LanguageBackend for JavaJnaLanguageBackend {
.java_jna
.interface_name
.clone()
.unwrap_or("Bindings".to_string());
.unwrap_or_else(|| "Bindings".to_string());

write!(out, "enum {}Singleton", name);
out.open_brace();
Expand All @@ -90,7 +90,7 @@ impl LanguageBackend for JavaJnaLanguageBackend {
out.new_line();

if let Some(extra) = &self.config.java_jna.extra_defs {
write!(out, "{extra}");
write!(out, "{}", extra);
out.new_line();
}
} else {
Expand Down Expand Up @@ -174,13 +174,13 @@ fn write_integer_type<W: Write, F: FnOnce(&mut SourceWriter<W>)>(
out.open_brace();
write!(out, "public {}()", name);
out.open_brace();
write!(out, "super({size});");
write!(out, "super({});", size);
out.close_brace(false);
out.new_line();
out.new_line();
write!(out, "public {}(long value)", name);
out.open_brace();
write!(out, "super({size}, value);");
write!(out, "super({}, value);", size);
out.close_brace(false);
out.new_line();
out.new_line();
Expand All @@ -198,19 +198,19 @@ fn write_integer_type<W: Write, F: FnOnce(&mut SourceWriter<W>)>(
out.open_brace();
write!(out, "public {}ByReference()", name);
out.open_brace();
write!(out, "super({size});");
write!(out, "super({});", size);
out.close_brace(false);
out.new_line();
out.new_line();
write!(out, "public {}ByReference(Pointer p)", name);
out.open_brace();
write!(out, "super({size});");
write!(out, "super({});", size);
out.new_line();
out.write("setPointer(p);");
out.close_brace(false);
out.new_line();
out.new_line();
write!(out, "{name} getValue()");
write!(out, "{} getValue()", name);
out.open_brace();
write!(
out,
Expand All @@ -221,7 +221,7 @@ fn write_integer_type<W: Write, F: FnOnce(&mut SourceWriter<W>)>(
out.close_brace(false);
out.new_line();
out.new_line();
write!(out, "void setValue({name} value)");
write!(out, "void setValue({} value)", name);
out.open_brace();
write!(out, "getPointer().{};", jna_underlying_type.set_method());
out.close_brace(false);
Expand Down Expand Up @@ -730,7 +730,7 @@ impl Source<JavaJnaLanguageBackend> for Type {
}
}
};
write!(out, "{typ}")
write!(out, "{}", typ)
}
Type::Array(_, _) => out.write("Pointer"),
Type::FuncPtr { .. } => out.write("CallbackReference"),
Expand Down Expand Up @@ -767,7 +767,7 @@ impl Source<JavaJnaLanguageBackend> for Type {
}
}
};
write!(out, "{typ}")
write!(out, "{}", typ)
}
Type::Array(ty, _len) => {
ty.write(language_backend, out);
Expand All @@ -789,7 +789,7 @@ impl Source<JavaJnaLanguageBackend> for Documentation {
out.write("/**");
for line in &self.doc_comment {
out.new_line();
write!(out, " *{line}")
write!(out, " *{}", line)
}
out.new_line();
out.write(" */");
Expand All @@ -802,20 +802,20 @@ pub(crate) fn wrap_java_value(literal: &Literal, ty: &Type) -> Literal {
match literal {
Literal::Expr(expr) => match ty {
Type::Primitive(primitive) => match primitive {
PrimitiveType::Double => Literal::Expr(format!("{expr}d")),
PrimitiveType::Float => Literal::Expr(format!("{expr}f")),
PrimitiveType::Double => Literal::Expr(format!("{}d", expr)),
PrimitiveType::Float => Literal::Expr(format!("{}f", expr)),
PrimitiveType::Integer {
kind: IntKind::LongLong | IntKind::B64,
..
} => Literal::Expr(format!("{expr}L")),
} => Literal::Expr(format!("{}L", expr)),
PrimitiveType::Integer {
kind: IntKind::Long | IntKind::Size | IntKind::SizeT,
..
} => Literal::Expr(format!("new NativeLong({expr})")),
} => Literal::Expr(format!("new NativeLong({})", expr)),

_ => literal.clone(),
},
Type::Path(path) => Literal::Expr(format!("new {}({expr})", path.export_name())),
Type::Path(path) => Literal::Expr(format!("new {}({})", path.export_name(), expr)),
_ => literal.clone(),
},
_ => literal.clone(),
Expand All @@ -842,17 +842,17 @@ impl Source<JavaJnaLanguageBackend> for Literal {
) {
match &self {
Literal::Expr(expr) => {
write!(out, "{expr}")
write!(out, "{}", expr)
}
Literal::Struct { export_name, .. } => {
// There is an hashmap in there that doesn't have stable debug output
not_implemented(&format!("Struct Literal {export_name}"), out)
not_implemented(&format!("Struct Literal {}", export_name), out)
}
_ => not_implemented(self, out),
}
}
}

fn not_implemented<T: Debug, F: Write>(value: &T, out: &mut SourceWriter<F>) {
write!(out, "/* Not implemented yet : {value:?} */")
write!(out, "/* Not implemented yet : {:?} */", value)
}
10 changes: 4 additions & 6 deletions tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,8 @@ fn compile(
Language::JavaJna => {
let jna_jar = Path::new(env!("CARGO_TARGET_TMPDIR")).join("jna-5.13.0.jar");

println!("using {jna_jar:?}");
if !jna_jar.exists() {
if !Command::new("curl")
if !jna_jar.exists()
&& !Command::new("curl")
.arg("--output")
.arg(&jna_jar)
.arg(
Expand All @@ -199,9 +198,8 @@ fn compile(
.status()
.unwrap()
.success()
{
panic!("Failed to download JNA for java tests");
}
{
panic!("Failed to download JNA for java tests");
}

command.arg("-cp").arg(&jna_jar);
Expand Down

0 comments on commit 2f48952

Please sign in to comment.