Skip to content
This repository has been archived by the owner on Jun 8, 2021. It is now read-only.

Add new types #125

Merged
merged 8 commits into from
Jun 27, 2018
Merged

Add new types #125

merged 8 commits into from
Jun 27, 2018

Conversation

GuillaumeGomez
Copy link
Member


impl Subprocess {
//#[cfg(any(feature = "v2_40", feature = "dox"))]
//pub fn new<'a, P: Into<Option<&'a Error>>>(flags: SubprocessFlags, error: P, argv0: &str, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs) -> Subprocess {
Copy link
Member Author

Choose a reason for hiding this comment

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

I have a crate that we could use to give VarArgs: https://crates.io/crates/va_list-rs (apparently, you can just give a va_list as a VarArgs argument so why not enjoying this?). Should we give it a try?

Copy link
Member

Choose a reason for hiding this comment

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

IMHO it worth to try but not in this PR (or if PR not merged until next release)

Copy link
Member

Choose a reason for hiding this comment

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

Also we discussed that a while ago on IRC and I believe there are some safety concerns there. Have to look again, I can't remember :)

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't intend to put it in this PR but since I had the chance to talk about it... 😛

Copy link
Member

Choose a reason for hiding this comment

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

Also the newv variant is equivalent and more Rust-y :)

pub trait InetAddressMaskExt {
fn equal(&self, mask2: &InetAddressMask) -> bool;

fn get_address(&self) -> Option<InetAddress>;
Copy link
Member

Choose a reason for hiding this comment

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

Can this really return None?

Copy link
Member Author

Choose a reason for hiding this comment

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

I suppose it cannot.

//}

#[cfg(any(feature = "v2_40", feature = "dox"))]
pub fn newv(argv: &[&std::path::Path], flags: SubprocessFlags) -> Result<Subprocess, Error> {
Copy link
Member

Choose a reason for hiding this comment

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

The argv should be an OsString AFAIU

//fn spawn(&self, error: &mut Error, argv0: &str, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs) -> Option<Subprocess>;

#[cfg(any(feature = "v2_40", feature = "dox"))]
fn spawnv(&self, argv: &[&std::path::Path]) -> Result<Subprocess, Error>;
Copy link
Member

Choose a reason for hiding this comment

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

OsString as above

fn set_stdout_file_path<P: AsRef<std::path::Path>>(&self, path: P);

#[cfg(any(feature = "v2_40", feature = "dox"))]
fn setenv<P: AsRef<std::path::Path>, Q: AsRef<std::path::Path>>(&self, variable: P, value: Q, overwrite: bool);
Copy link
Member

Choose a reason for hiding this comment

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

OsString as above (or rather they should all be &OsStr, there's a gir parameter for this)

fn spawnv(&self, argv: &[&std::path::Path]) -> Result<Subprocess, Error>;

#[cfg(any(feature = "v2_40", feature = "dox"))]
fn take_fd(&self, source_fd: i32, target_fd: i32);
Copy link
Member

Choose a reason for hiding this comment

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

These should be wrappers around RawFd on UNIX and Handle on Windows. All the fd related functions

Copy link
Member

Choose a reason for hiding this comment

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

These fd functions are also unsafe, as you can safely create a random fd (it's just a type alias for an integer) and then having GLib use that will cause problems

Copy link
Member

Choose a reason for hiding this comment

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

I mean they must be marked as unsafe

fn take_stdout_fd(&self, fd: i32);

#[cfg(any(feature = "v2_40", feature = "dox"))]
fn unsetenv<P: AsRef<std::path::Path>>(&self, variable: P);
Copy link
Member

Choose a reason for hiding this comment

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

OsString

@sdroege
Copy link
Member

sdroege commented Jun 19, 2018

Looks generally good except for those comments above. Thanks for working on this :) This will become a good release for GIO!

@GuillaumeGomez
Copy link
Member Author

GuillaumeGomez commented Jun 19, 2018

I hope it'll! I need to understand what's happening on the appveyor failure as well. Some duplicate implementations apparently...

@EPashkin
Copy link
Member

Duplicate trait happened on travis too.
Only objects have buildin Eq (added long ago gtk-rs/glib@10745ad).
Not sure what we can do (IMHO ignoring equals remove generated Eq but it not rigth)

@GuillaumeGomez
Copy link
Member Author

I'll test and we'll see. In worst case, I'll just copy/paste the whole file and ignore its generation...

@sdroege
Copy link
Member

sdroege commented Jun 20, 2018

The Eq thing is somewhat related to gtk-rs/glib#247

We need a way to opt-out of the automatic Eq, Debug, etc impls and have custom ones.

@sdroege
Copy link
Member

sdroege commented Jun 20, 2018

I'll test and we'll see. In worst case, I'll just copy/paste the whole file and ignore its generation...

You can ignore the equal function in gir too probably. But it's all not a solution really :)

@GuillaumeGomez
Copy link
Member Author

Updated.

use ffi;
use glib;
use glib::object::IsA;
use GtkRawFd;
Copy link
Member

Choose a reason for hiding this comment

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

I don't like this one, and it will also make the API unsafe as you can pass random integers in there now. There's a reason why I said to use the proper traits for this :)


pub trait SubprocessLauncherExtManual {
#[cfg(any(feature = "v2_40", feature = "dox"))]
fn take_fd(&self, source_fd: GtkRawFd, target_fd: GtkRawFd);
Copy link
Member

Choose a reason for hiding this comment

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

These should all take a https://doc.rust-lang.org/nightly/std/os/unix/io/trait.IntoRawFd.html on UNIX and https://doc.rust-lang.org/nightly/std/os/windows/io/trait.IntoRawHandle.html on Windows to be safe (the safety aspect is then moved to the implementors of that trait and people can safely pass various types in there)

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Was wrong, my link only for sockets

Copy link
Member

Choose a reason for hiding this comment

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

Basically same thing though, yes

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I had unsafe in mind, but I don't get why I didn't think about AsRawFd and AsRawHandle...

Copy link
Member

Choose a reason for hiding this comment

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

Into, not As :) this takes ownership. And it does not have to be unsafe then because the trait impls already take care of that being safe

Copy link
Member Author

Choose a reason for hiding this comment

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

True!

@GuillaumeGomez
Copy link
Member Author

Okay, the safe version is now here!

@GuillaumeGomez GuillaumeGomez force-pushed the new-types2 branch 4 times, most recently from 32b8e6e to 32928bb Compare June 23, 2018 14:35
@GuillaumeGomez
Copy link
Member Author

After multiple windows fixes, does it seem good?

@EPashkin EPashkin mentioned this pull request Jun 23, 2018
@EPashkin
Copy link
Member

Travis don't think so 😭

@EPashkin
Copy link
Member

By way, seems manual function in SubProcessLauncher is not_windows only, I can't find it in libgio-2.0-0.dll while g_subprocess_launcher_new is present

@GuillaumeGomez
Copy link
Member Author

Another bug in gio I assume... I just switch to cfg(not(windows)) for SubProcessLauncher then?

@EPashkin
Copy link
Member

Futures bug now in beta too :(
Also errors and warnings in stable https://travis-ci.org/gtk-rs/gio/jobs/395928392 IMHO legit and need fix

@sdroege
Copy link
Member

sdroege commented Jun 24, 2018

Also errors and warnings in stable https://travis-ci.org/gtk-rs/gio/jobs/395928392 IMHO legit and need fix

These are missing imports in the subprocess.rs in this PR (@GuillaumeGomez). And some type mismatches in there. All the other futures code seems to be fine.

Same for the beta problems.

Gir.toml Outdated
name = "communicate_utf8_async"
ignore = true
[[object.function]]
name = "communicate_utf8_async_future"
Copy link
Member

Choose a reason for hiding this comment

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

You don't have to ignore that one here. It is generated as a result of the non-futures function and does not exist as such in C

use send_cell::SendCell;

let stdin_buf = stdin_buf.into();
let stdin_buf = stdin_buf.map(ToOwned::to_owned);
Copy link
Member

Choose a reason for hiding this comment

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

It already is a String, there's nothing to convert here. But you could make it take a &str and do the copy internally here like you do already

let stdin_buf = stdin_buf.to_glib_none();
let cancellable = cancellable.into();
let cancellable = cancellable.to_glib_none();
let user_data: Box<Box<(R, *mut i8)>> = Box::new(Box::new((callback, stdin_buf.0)));
Copy link
Member

Choose a reason for hiding this comment

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

The stdin_buf has to be the result of to_glib_full() as you want to keep it alive until the trampoline ran and then free it there.

@GuillaumeGomez
Copy link
Member Author

Updated!

#[cfg(any(feature = "v2_40", feature = "dox"))]
use SubprocessLauncher;
#[cfg(any(feature = "v2_40", feature = "dox"))]
use ffi;
Copy link
Member

Choose a reason for hiding this comment

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

This better have same cfg as functions, see warning in appveyor

#[cfg(any(all(feature = "v2_40", not(windows)), all(feature = "dox", not(windows))))]
use std::os::unix::io::IntoRawFd;
#[cfg(all(feature = "dox", windows))]
pub trait IntoRawFd {}
Copy link
Member

Choose a reason for hiding this comment

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

IMHO better use unix and not(unix) instead

@EPashkin
Copy link
Member

Looks good, thanks

@sdroege
Copy link
Member

sdroege commented Jun 26, 2018

Go for it then :)

@GuillaumeGomez
Copy link
Member Author

I want to update following @EPashkin's comments first. Then I merge. :) Thanks a lot to both of you for your reviews!

/// Replacement for "real" [`IntoRawFd`] trait for non-unix targets.
///
/// [`IntoRawFd`]: https://doc.rust-lang.org/std/os/unix/io/trait.IntoRawFd.html
pub trait IntoRawFd {}
Copy link
Member

Choose a reason for hiding this comment

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

Your check don't allow doc comments here, you need add it to lgpl-docs, but not sure that it restored in right place.
Also IMHO better not mixing windows and unix and use only unix (in all this file)

@EPashkin
Copy link
Member

for futures all v0.2.* yanked

@sdroege
Copy link
Member

sdroege commented Jun 27, 2018

for futures all v0.2.* yanked

Great! Complained about that here, let's see what they reply https://users.rust-lang.org/t/futures-0-2-has-been-moved-to-futures-preview/18329/2?u=slomo

@sdroege
Copy link
Member

sdroege commented Jun 27, 2018

Maybe only needs moving to the futures-preview crates instead, I'll check later

@@ -1,36 +1,36 @@
#[cfg(any(feature = "v2_40", feature = "dox"))]
use SubprocessLauncher;
#[cfg(any(all(feature = "v2_40", not(windows)), feature = "dox"))]
#[cfg(any(all(feature = "v2_40", not(unix)), feature = "dox"))]
Copy link
Member

Choose a reason for hiding this comment

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

This is wrong change, as windows ~= not(unix)

Copy link
Member Author

Choose a reason for hiding this comment

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

Oups indeed!

@GuillaumeGomez
Copy link
Member Author

I fixed conditions.

@sdroege
Copy link
Member

sdroege commented Jun 27, 2018

Currently preparing gio-futures PR, then this can be merged IMHO

@GuillaumeGomez GuillaumeGomez merged commit a4eee77 into gtk-rs:master Jun 27, 2018
@GuillaumeGomez GuillaumeGomez deleted the new-types2 branch June 27, 2018 11:47
@EPashkin
Copy link
Member

@GuillaumeGomez Docs on windows failed
https://ci.appveyor.com/project/GuillaumeGomez/gio/build/job/ujoevof6anec5ur7

error: string literal with a suffix is invalid
  --> src\subprocess_launcher.rs:12:9
   |
12 | #[doc = "Replacement for "real" [`IntoRawFd`] trait for non-unix targets.
   |         ^^^^^^^^^^^^^^^^^^^^^^
error: unexpected token: `" [`IntoRawFd`] trait for non-unix targets.
[`IntoRawFd`]: https://doc.rust-lang.org/std/os/unix/io/trait.IntoRawFd.html"`
  --> src\subprocess_launcher.rs:12:31
   |
12 |   #[doc = "Replacement for "real" [`IntoRawFd`] trait for non-unix targets.
   |  _______________________________^
13 | |
14 | | [`IntoRawFd`]: https://doc.rust-lang.org/std/os/unix/io/trait.IntoRawFd.html"]
   | |_____________________________________________________________________________^ unexpected token after this
error: Could not document `gio`.

@EPashkin
Copy link
Member

.. and doc comments will be not accepted anyway it need be added to lgpl-docs

@GuillaumeGomez
Copy link
Member Author

This is really annoying. :-/ I'll open a PR to remove it from here.

vhdirk pushed a commit to vhdirk/gio-rs that referenced this pull request Jan 16, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants