Disable socket import on wasm

This commit is contained in:
lynskylate
2019-08-07 23:48:53 +08:00
parent c9c580d2fe
commit fccb0d2ade
3 changed files with 5 additions and 13 deletions

View File

@@ -24,7 +24,6 @@ sha2 = "0.8"
sha3 = "0.8"
blake2 = "0.8"
gethostname = "0.2.0"
num-complex = { version = "0.2", features = ["serde"] }
num-bigint = { version = "0.2", features = ["serde"] }
num-traits = "=0.2.6"
@@ -70,3 +69,6 @@ flamer = { version = "0.3", optional = true }
[target.'cfg(all(unix, not(any(target_os = "android", target_os = "redox"))))'.dependencies]
pwd = "1"
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
gethostname = "0.2.0"

View File

@@ -17,6 +17,7 @@ mod platform;
mod pystruct;
mod random;
mod re;
#[cfg(not(target_arch = "wasm32"))]
pub mod socket;
mod string;
#[cfg(feature = "rustpython-compiler")]

View File

@@ -5,9 +5,8 @@ use std::io::Write;
use std::net::{Ipv4Addr, SocketAddr, TcpListener, TcpStream, ToSocketAddrs, UdpSocket};
#[cfg(unix)]
use nix::unistd::{gethostname, sethostname};
use nix::unistd::sethostname;
#[cfg(windows)]
use gethostname::gethostname;
use byteorder::{BigEndian, ByteOrder};
@@ -382,16 +381,6 @@ fn get_addr_tuple(vm: &VirtualMachine, addr: SocketAddr) -> PyResult {
Ok(vm.ctx.new_tuple(vec![ip, port]))
}
#[cfg(unix)]
fn socket_gethostname(vm: &VirtualMachine) -> PyResult {
let mut buf = [0u8; 1024];
match gethostname(&mut buf) {
Ok(cstr) => Ok(vm.new_str(String::from(cstr.to_str().unwrap()))),
Err(e) => Err(convert_nix_error(vm, e)),
}
}
#[cfg(windows)]
fn socket_gethostname(vm: &VirtualMachine) -> PyResult {
gethostname()
.into_string()