Skip to content

Commit

Permalink
Merge pull request #824 from sdroege/0.16-backports
Browse files Browse the repository at this point in the history
0.16 backports
  • Loading branch information
sdroege committed Nov 13, 2022
2 parents 0fff9d9 + f7c0406 commit f5daa90
Show file tree
Hide file tree
Showing 40 changed files with 150 additions and 162 deletions.
2 changes: 1 addition & 1 deletion gdk-pixbuf/src/auto/versions.txt
@@ -1,2 +1,2 @@
Generated by gir (https://github.com/gtk-rs/gir @ f92952f3f7ea)
Generated by gir (https://github.com/gtk-rs/gir @ e79806af2905)
from gir-files (https://github.com/gtk-rs/gir-files @ 89a11aa6a362)
20 changes: 8 additions & 12 deletions gdk-pixbuf/sys/tests/abi.rs
Expand Up @@ -40,7 +40,7 @@ impl Compiler {
cmd.arg(out);
let status = cmd.spawn()?.wait()?;
if !status.success() {
return Err(format!("compilation command {:?} failed, {}", &cmd, status).into());
return Err(format!("compilation command {cmd:?} failed, {status}").into());
}
Ok(())
}
Expand All @@ -56,7 +56,7 @@ fn get_var(name: &str, default: &str) -> Result<Vec<String>, Box<dyn Error>> {
match env::var(name) {
Ok(value) => Ok(shell_words::split(&value)?),
Err(env::VarError::NotPresent) => Ok(shell_words::split(default)?),
Err(err) => Err(format!("{} {}", name, err).into()),
Err(err) => Err(format!("{name} {err}").into()),
}
}

Expand All @@ -70,7 +70,7 @@ fn pkg_config_cflags(packages: &[&str]) -> Result<Vec<String>, Box<dyn Error>> {
cmd.args(packages);
let out = cmd.output()?;
if !out.status.success() {
return Err(format!("command {:?} returned {}", &cmd, out.status).into());
return Err(format!("command {cmd:?} returned {}", out.status).into());
}
let stdout = str::from_utf8(&out.stdout)?;
Ok(shell_words::split(stdout.trim())?)
Expand Down Expand Up @@ -126,15 +126,14 @@ fn cross_validate_constants_with_c() {
{
if rust_name != c_name {
results.record_failed();
eprintln!("Name mismatch:\nRust: {:?}\nC: {:?}", rust_name, c_name,);
eprintln!("Name mismatch:\nRust: {rust_name:?}\nC: {c_name:?}");
continue;
}

if rust_value != c_value {
results.record_failed();
eprintln!(
"Constant value mismatch for {}\nRust: {:?}\nC: {:?}",
rust_name, rust_value, &c_value
"Constant value mismatch for {rust_name}\nRust: {rust_value:?}\nC: {c_value:?}",
);
continue;
}
Expand Down Expand Up @@ -164,16 +163,13 @@ fn cross_validate_layout_with_c() {
{
if rust_name != c_name {
results.record_failed();
eprintln!("Name mismatch:\nRust: {:?}\nC: {:?}", rust_name, c_name,);
eprintln!("Name mismatch:\nRust: {rust_name:?}\nC: {c_name:?}");
continue;
}

if rust_layout != c_layout {
results.record_failed();
eprintln!(
"Layout mismatch for {}\nRust: {:?}\nC: {:?}",
rust_name, rust_layout, &c_layout
);
eprintln!("Layout mismatch for {rust_name}\nRust: {rust_layout:?}\nC: {c_layout:?}",);
continue;
}

Expand All @@ -194,7 +190,7 @@ fn get_c_output(name: &str) -> Result<String, Box<dyn Error>> {
let mut abi_cmd = Command::new(exe);
let output = abi_cmd.output()?;
if !output.status.success() {
return Err(format!("command {:?} failed, {:?}", &abi_cmd, &output).into());
return Err(format!("command {abi_cmd:?} failed, {output:?}").into());
}

Ok(String::from_utf8(output.stdout)?)
Expand Down
2 changes: 1 addition & 1 deletion gdk-pixbuf/sys/versions.txt
@@ -1,2 +1,2 @@
Generated by gir (https://github.com/gtk-rs/gir @ f92952f3f7ea)
Generated by gir (https://github.com/gtk-rs/gir @ e79806af2905)
from gir-files (https://github.com/gtk-rs/gir-files @ 89a11aa6a362)
2 changes: 1 addition & 1 deletion gdk-pixbuf/tests/check_gir.rs
Expand Up @@ -3,6 +3,6 @@
#[test]
fn check_gir_file() {
let res = gir_format_check::check_gir_file("Gir.toml");
println!("{}", res);
println!("{res}");
assert_eq!(res.nb_errors, 0);
}
3 changes: 3 additions & 0 deletions gio/Gir.toml
Expand Up @@ -398,6 +398,9 @@ manual_traits = ["CancellableExtManual"]
name = "cancelled"
# Racy, use 'connect' and 'disconnect' instead
ignore = true
[[object.function]]
name = "set_error_if_cancelled"
manual = true

[[object]]
name = "Gio.CharsetConverter"
Expand Down
20 changes: 0 additions & 20 deletions gio/src/auto/cancellable.rs
Expand Up @@ -5,7 +5,6 @@
use glib::object::IsA;
use glib::translate::*;
use std::fmt;
use std::ptr;

glib::wrapper! {
#[doc(alias = "GCancellable")]
Expand Down Expand Up @@ -62,9 +61,6 @@ pub trait CancellableExt: 'static {

#[doc(alias = "g_cancellable_release_fd")]
fn release_fd(&self);

#[doc(alias = "g_cancellable_set_error_if_cancelled")]
fn set_error_if_cancelled(&self) -> Result<(), glib::Error>;
}

impl<O: IsA<Cancellable>> CancellableExt for O {
Expand Down Expand Up @@ -107,22 +103,6 @@ impl<O: IsA<Cancellable>> CancellableExt for O {
ffi::g_cancellable_release_fd(self.as_ref().to_glib_none().0);
}
}

fn set_error_if_cancelled(&self) -> Result<(), glib::Error> {
unsafe {
let mut error = ptr::null_mut();
let is_ok = ffi::g_cancellable_set_error_if_cancelled(
self.as_ref().to_glib_none().0,
&mut error,
);
assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
if error.is_null() {
Ok(())
} else {
Err(from_glib_full(error))
}
}
}
}

impl fmt::Display for Cancellable {
Expand Down
2 changes: 1 addition & 1 deletion gio/src/auto/versions.txt
@@ -1,2 +1,2 @@
Generated by gir (https://github.com/gtk-rs/gir @ f92952f3f7ea)
Generated by gir (https://github.com/gtk-rs/gir @ e79806af2905)
from gir-files (https://github.com/gtk-rs/gir-files @ 89a11aa6a362)
29 changes: 29 additions & 0 deletions gio/src/cancellable.rs
Expand Up @@ -75,6 +75,10 @@ pub trait CancellableExtManual {
/// Returns a `Future` that completes when the cancellable becomes cancelled. Completes
/// immediately if the cancellable is already cancelled.
fn future(&self) -> std::pin::Pin<Box<dyn Future<Output = ()> + Send + Sync + 'static>>;
// rustdoc-stripper-ignore-next
/// Set an error if the cancellable is already cancelled.
#[doc(alias = "g_cancellable_set_error_if_cancelled")]
fn set_error_if_cancelled(&self) -> Result<(), glib::Error>;
}

impl<O: IsA<Cancellable>> CancellableExtManual for O {
Expand Down Expand Up @@ -136,6 +140,24 @@ impl<O: IsA<Cancellable>> CancellableExtManual for O {
}
})
}

fn set_error_if_cancelled(&self) -> Result<(), glib::Error> {
unsafe {
let mut error = std::ptr::null_mut();
let is_ok = ffi::g_cancellable_set_error_if_cancelled(
self.as_ref().to_glib_none().0,
&mut error,
);
// Here's the special case, this function has an inverted
// return value for the error case.
assert_eq!(is_ok == glib::ffi::GFALSE, error.is_null());
if error.is_null() {
Ok(())
} else {
Err(from_glib_full(error))
}
}
}
}

#[cfg(test)]
Expand All @@ -158,6 +180,13 @@ mod tests {
c.disconnect_cancelled(id.unwrap());
}

#[test]
fn cancellable_error_if_cancelled() {
let c = Cancellable::new();
c.cancel();
assert!(c.set_error_if_cancelled().is_err());
}

#[test]
fn cancellable_future() {
let c = Cancellable::new();
Expand Down
1 change: 0 additions & 1 deletion gio/src/subclass/async_initable.rs
Expand Up @@ -9,7 +9,6 @@ use glib::subclass::prelude::*;

use std::ptr;

use crate::prelude::CancellableExt;
use crate::prelude::CancellableExtManual;
use crate::AsyncInitable;
use crate::AsyncResult;
Expand Down
20 changes: 8 additions & 12 deletions gio/sys/tests/abi.rs
Expand Up @@ -40,7 +40,7 @@ impl Compiler {
cmd.arg(out);
let status = cmd.spawn()?.wait()?;
if !status.success() {
return Err(format!("compilation command {:?} failed, {}", &cmd, status).into());
return Err(format!("compilation command {cmd:?} failed, {status}").into());
}
Ok(())
}
Expand All @@ -56,7 +56,7 @@ fn get_var(name: &str, default: &str) -> Result<Vec<String>, Box<dyn Error>> {
match env::var(name) {
Ok(value) => Ok(shell_words::split(&value)?),
Err(env::VarError::NotPresent) => Ok(shell_words::split(default)?),
Err(err) => Err(format!("{} {}", name, err).into()),
Err(err) => Err(format!("{name} {err}").into()),
}
}

Expand All @@ -70,7 +70,7 @@ fn pkg_config_cflags(packages: &[&str]) -> Result<Vec<String>, Box<dyn Error>> {
cmd.args(packages);
let out = cmd.output()?;
if !out.status.success() {
return Err(format!("command {:?} returned {}", &cmd, out.status).into());
return Err(format!("command {cmd:?} returned {}", out.status).into());
}
let stdout = str::from_utf8(&out.stdout)?;
Ok(shell_words::split(stdout.trim())?)
Expand Down Expand Up @@ -126,15 +126,14 @@ fn cross_validate_constants_with_c() {
{
if rust_name != c_name {
results.record_failed();
eprintln!("Name mismatch:\nRust: {:?}\nC: {:?}", rust_name, c_name,);
eprintln!("Name mismatch:\nRust: {rust_name:?}\nC: {c_name:?}");
continue;
}

if rust_value != c_value {
results.record_failed();
eprintln!(
"Constant value mismatch for {}\nRust: {:?}\nC: {:?}",
rust_name, rust_value, &c_value
"Constant value mismatch for {rust_name}\nRust: {rust_value:?}\nC: {c_value:?}",
);
continue;
}
Expand Down Expand Up @@ -164,16 +163,13 @@ fn cross_validate_layout_with_c() {
{
if rust_name != c_name {
results.record_failed();
eprintln!("Name mismatch:\nRust: {:?}\nC: {:?}", rust_name, c_name,);
eprintln!("Name mismatch:\nRust: {rust_name:?}\nC: {c_name:?}");
continue;
}

if rust_layout != c_layout {
results.record_failed();
eprintln!(
"Layout mismatch for {}\nRust: {:?}\nC: {:?}",
rust_name, rust_layout, &c_layout
);
eprintln!("Layout mismatch for {rust_name}\nRust: {rust_layout:?}\nC: {c_layout:?}",);
continue;
}

Expand All @@ -194,7 +190,7 @@ fn get_c_output(name: &str) -> Result<String, Box<dyn Error>> {
let mut abi_cmd = Command::new(exe);
let output = abi_cmd.output()?;
if !output.status.success() {
return Err(format!("command {:?} failed, {:?}", &abi_cmd, &output).into());
return Err(format!("command {abi_cmd:?} failed, {output:?}").into());
}

Ok(String::from_utf8(output.stdout)?)
Expand Down
2 changes: 1 addition & 1 deletion gio/sys/versions.txt
@@ -1,2 +1,2 @@
Generated by gir (https://github.com/gtk-rs/gir @ f92952f3f7ea)
Generated by gir (https://github.com/gtk-rs/gir @ e79806af2905)
from gir-files (https://github.com/gtk-rs/gir-files @ 89a11aa6a362)
2 changes: 1 addition & 1 deletion gio/tests/check_gir.rs
Expand Up @@ -3,6 +3,6 @@
#[test]
fn check_gir_file() {
let res = gir_format_check::check_gir_file("Gir.toml");
println!("{}", res);
println!("{res}");
assert_eq!(res.nb_errors, 0);
}
2 changes: 1 addition & 1 deletion gir
Submodule gir updated 1 files
+8 −11 src/codegen/sys/tests.rs
4 changes: 2 additions & 2 deletions glib-macros/tests/clone.rs
Expand Up @@ -84,8 +84,8 @@ fn clone_failures() {
for (index, (expr, err)) in TESTS.iter().enumerate() {
let prefix = "fn main() { use glib::clone; let v = std::rc::Rc::new(1); ";
let suffix = "; }";
let output = format!("{}{}{}", prefix, expr, suffix);
let output = format!("{prefix}{expr}{suffix}");

t.compile_fail_inline_check_sub(&format!("test_{}", index), &output, err);
t.compile_fail_inline_check_sub(&format!("test_{index}"), &output, err);
}
}
20 changes: 8 additions & 12 deletions glib/gobject-sys/tests/abi.rs
Expand Up @@ -40,7 +40,7 @@ impl Compiler {
cmd.arg(out);
let status = cmd.spawn()?.wait()?;
if !status.success() {
return Err(format!("compilation command {:?} failed, {}", &cmd, status).into());
return Err(format!("compilation command {cmd:?} failed, {status}").into());
}
Ok(())
}
Expand All @@ -56,7 +56,7 @@ fn get_var(name: &str, default: &str) -> Result<Vec<String>, Box<dyn Error>> {
match env::var(name) {
Ok(value) => Ok(shell_words::split(&value)?),
Err(env::VarError::NotPresent) => Ok(shell_words::split(default)?),
Err(err) => Err(format!("{} {}", name, err).into()),
Err(err) => Err(format!("{name} {err}").into()),
}
}

Expand All @@ -70,7 +70,7 @@ fn pkg_config_cflags(packages: &[&str]) -> Result<Vec<String>, Box<dyn Error>> {
cmd.args(packages);
let out = cmd.output()?;
if !out.status.success() {
return Err(format!("command {:?} returned {}", &cmd, out.status).into());
return Err(format!("command {cmd:?} returned {}", out.status).into());
}
let stdout = str::from_utf8(&out.stdout)?;
Ok(shell_words::split(stdout.trim())?)
Expand Down Expand Up @@ -126,15 +126,14 @@ fn cross_validate_constants_with_c() {
{
if rust_name != c_name {
results.record_failed();
eprintln!("Name mismatch:\nRust: {:?}\nC: {:?}", rust_name, c_name,);
eprintln!("Name mismatch:\nRust: {rust_name:?}\nC: {c_name:?}");
continue;
}

if rust_value != c_value {
results.record_failed();
eprintln!(
"Constant value mismatch for {}\nRust: {:?}\nC: {:?}",
rust_name, rust_value, &c_value
"Constant value mismatch for {rust_name}\nRust: {rust_value:?}\nC: {c_value:?}",
);
continue;
}
Expand Down Expand Up @@ -164,16 +163,13 @@ fn cross_validate_layout_with_c() {
{
if rust_name != c_name {
results.record_failed();
eprintln!("Name mismatch:\nRust: {:?}\nC: {:?}", rust_name, c_name,);
eprintln!("Name mismatch:\nRust: {rust_name:?}\nC: {c_name:?}");
continue;
}

if rust_layout != c_layout {
results.record_failed();
eprintln!(
"Layout mismatch for {}\nRust: {:?}\nC: {:?}",
rust_name, rust_layout, &c_layout
);
eprintln!("Layout mismatch for {rust_name}\nRust: {rust_layout:?}\nC: {c_layout:?}",);
continue;
}

Expand All @@ -194,7 +190,7 @@ fn get_c_output(name: &str) -> Result<String, Box<dyn Error>> {
let mut abi_cmd = Command::new(exe);
let output = abi_cmd.output()?;
if !output.status.success() {
return Err(format!("command {:?} failed, {:?}", &abi_cmd, &output).into());
return Err(format!("command {abi_cmd:?} failed, {output:?}").into());
}

Ok(String::from_utf8(output.stdout)?)
Expand Down
2 changes: 1 addition & 1 deletion glib/gobject-sys/versions.txt
@@ -1,2 +1,2 @@
Generated by gir (https://github.com/gtk-rs/gir @ f92952f3f7ea)
Generated by gir (https://github.com/gtk-rs/gir @ e79806af2905)
from gir-files (https://github.com/gtk-rs/gir-files @ 89a11aa6a362)
2 changes: 1 addition & 1 deletion glib/src/auto/versions.txt
@@ -1,2 +1,2 @@
Generated by gir (https://github.com/gtk-rs/gir @ f92952f3f7ea)
Generated by gir (https://github.com/gtk-rs/gir @ e79806af2905)
from gir-files (https://github.com/gtk-rs/gir-files @ 89a11aa6a362)
2 changes: 1 addition & 1 deletion glib/src/gstring_builder.rs
Expand Up @@ -248,7 +248,7 @@ mod tests {
#[test]
fn display() {
let s: crate::GStringBuilder = crate::GStringBuilder::new("This is a string.");
assert_eq!(&format!("{}", s), "This is a string.");
assert_eq!(&format!("{s}"), "This is a string.");
}

#[test]
Expand Down

0 comments on commit f5daa90

Please sign in to comment.