gtk-rs / sys

DEPRECATED, each crate has its own sys folder now.
http://gtk-rs.org/
MIT License
31 stars 25 forks source link

SocketFamily::Ipv6 definition is wrong because it's OS dependent #178

Closed xanathar closed 3 years ago

xanathar commented 3 years ago

This issue involves many repos (sys, gio, and gir-files), so I'm not 100% sure this is the correct one to open the issue to. I've tried to solve the issue, but could not find a similar case to copy so, in case, guidance is needed.

TL;DR: The value of the constant gio_sys::G_SOCKET_FAMILY_IPV6 is operating system dependent, and so code using it (directly or indirectly) fails on non-Linux OSs (Linux is safe because gir files are generated from Ubuntu's .debs).

Repro/Symptom

Running a simple code like:

    if let Err(e) = Socket::new(SocketFamily::Ipv6, SocketType::Datagram, SocketProtocol::Udp) {
        println!("ERROR: {:?}", e);
    }

fails on MacOS (and Windows) with the following output:

(process:7858): GLib-GObject-WARNING **: 20:12:12.881: value "((GSocketFamily) 10)" of type 'GSocketFamily' is invalid or out of range for property 'family' of type 'GSocketFamily'
ERROR: Error { domain: g-io-error-quark, code: 13, message: "Unable to create socket: Unknown family was specified" }

on the other hand the following works (on MacOS):

    if let Err(e) = Socket::new(SocketFamily::__Unknown(30), SocketType::Datagram, SocketProtocol::Udp) {
        println!("ERROR: {:?}", e);
    }

Root cause

sdroege commented 3 years ago

This means that we should ignore these constants from the .gir file and instead point at libc::AF_INET etc. manually.

We already do similar things in https://github.com/gtk-rs/sys/blob/master/glib-sys/src/manual.rs for example.

Do you want to provide a PR for this?

xanathar commented 3 years ago

Sure! I just needed this pointer :)

sdroege commented 3 years ago

Ignoring can be done via the Gir.toml file btw :)