Skip to content

Commit

Permalink
normalize rids (denoland#9832)
Browse files Browse the repository at this point in the history
  • Loading branch information
crowlKats committed Mar 19, 2021
1 parent 277e19f commit 1973059
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 58 deletions.
4 changes: 2 additions & 2 deletions op_crates/fetch/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ pub async fn op_fetch_request_write(
let resource = state
.borrow()
.resource_table
.get::<FetchRequestBodyResource>(rid as u32)
.get::<FetchRequestBodyResource>(rid)
.ok_or_else(bad_resource_id)?;
let body = RcRef::map(&resource, |r| &r.body).borrow_mut().await;
let cancel = RcRef::map(resource, |r| &r.cancel);
Expand Down Expand Up @@ -325,7 +325,7 @@ pub async fn op_fetch_response_read(
let resource = state
.borrow()
.resource_table
.get::<FetchResponseBodyResource>(rid as u32)
.get::<FetchResponseBodyResource>(rid)
.ok_or_else(bad_resource_id)?;
let mut reader = RcRef::map(&resource, |r| &r.reader).borrow_mut().await;
let cancel = RcRef::map(resource, |r| &r.cancel);
Expand Down
35 changes: 17 additions & 18 deletions runtime/ops/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,13 +208,13 @@ async fn op_open_async(
#[derive(Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SeekArgs {
rid: i32,
rid: u32,
offset: i64,
whence: i32,
}

fn seek_helper(args: SeekArgs) -> Result<(u32, SeekFrom), AnyError> {
let rid = args.rid as u32;
let rid = args.rid;
let offset = args.offset;
let whence = args.whence as u32;
// Translate seek mode to Rust repr.
Expand Down Expand Up @@ -273,15 +273,15 @@ async fn op_seek_async(
#[derive(Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct FdatasyncArgs {
rid: i32,
rid: u32,
}

fn op_fdatasync_sync(
state: &mut OpState,
args: FdatasyncArgs,
_zero_copy: &mut [ZeroCopyBuf],
) -> Result<Value, AnyError> {
let rid = args.rid as u32;
let rid = args.rid;
StdFileResource::with(state, rid, |r| match r {
Ok(std_file) => std_file.sync_data().map_err(AnyError::from),
Err(_) => Err(type_error("cannot sync this type of resource".to_string())),
Expand All @@ -294,7 +294,7 @@ async fn op_fdatasync_async(
args: FdatasyncArgs,
_zero_copy: BufVec,
) -> Result<Value, AnyError> {
let rid = args.rid as u32;
let rid = args.rid;

let resource = state
.borrow_mut()
Expand All @@ -317,15 +317,15 @@ async fn op_fdatasync_async(
#[derive(Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct FsyncArgs {
rid: i32,
rid: u32,
}

fn op_fsync_sync(
state: &mut OpState,
args: FsyncArgs,
_zero_copy: &mut [ZeroCopyBuf],
) -> Result<Value, AnyError> {
let rid = args.rid as u32;
let rid = args.rid;
StdFileResource::with(state, rid, |r| match r {
Ok(std_file) => std_file.sync_all().map_err(AnyError::from),
Err(_) => Err(type_error("cannot sync this type of resource".to_string())),
Expand All @@ -338,7 +338,7 @@ async fn op_fsync_async(
args: FsyncArgs,
_zero_copy: BufVec,
) -> Result<Value, AnyError> {
let rid = args.rid as u32;
let rid = args.rid;

let resource = state
.borrow_mut()
Expand All @@ -361,7 +361,7 @@ async fn op_fsync_async(
#[derive(Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct FstatArgs {
rid: i32,
rid: u32,
}

fn op_fstat_sync(
Expand All @@ -370,8 +370,7 @@ fn op_fstat_sync(
_zero_copy: &mut [ZeroCopyBuf],
) -> Result<Value, AnyError> {
super::check_unstable(state, "Deno.fstat");
let rid = args.rid as u32;
let metadata = StdFileResource::with(state, rid, |r| match r {
let metadata = StdFileResource::with(state, args.rid, |r| match r {
Ok(std_file) => std_file.metadata().map_err(AnyError::from),
Err(_) => Err(type_error("cannot stat this type of resource".to_string())),
})?;
Expand All @@ -385,7 +384,7 @@ async fn op_fstat_async(
) -> Result<Value, AnyError> {
super::check_unstable2(&state, "Deno.fstat");

let rid = args.rid as u32;
let rid = args.rid;

let resource = state
.borrow_mut()
Expand Down Expand Up @@ -1314,7 +1313,7 @@ async fn op_read_link_async(
#[derive(Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct FtruncateArgs {
rid: i32,
rid: u32,
len: i32,
}

Expand All @@ -1324,7 +1323,7 @@ fn op_ftruncate_sync(
_zero_copy: &mut [ZeroCopyBuf],
) -> Result<Value, AnyError> {
super::check_unstable(state, "Deno.ftruncate");
let rid = args.rid as u32;
let rid = args.rid;
let len = args.len as u64;
StdFileResource::with(state, rid, |r| match r {
Ok(std_file) => std_file.set_len(len).map_err(AnyError::from),
Expand All @@ -1339,7 +1338,7 @@ async fn op_ftruncate_async(
_zero_copy: BufVec,
) -> Result<Value, AnyError> {
super::check_unstable2(&state, "Deno.ftruncate");
let rid = args.rid as u32;
let rid = args.rid;
let len = args.len as u64;

let resource = state
Expand Down Expand Up @@ -1586,7 +1585,7 @@ async fn op_make_temp_file_async(
#[derive(Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct FutimeArgs {
rid: i32,
rid: u32,
atime: (i64, u32),
mtime: (i64, u32),
}
Expand All @@ -1597,7 +1596,7 @@ fn op_futime_sync(
_zero_copy: &mut [ZeroCopyBuf],
) -> Result<Value, AnyError> {
super::check_unstable(state, "Deno.futimeSync");
let rid = args.rid as u32;
let rid = args.rid;
let atime = filetime::FileTime::from_unix_time(args.atime.0, args.atime.1);
let mtime = filetime::FileTime::from_unix_time(args.mtime.0, args.mtime.1);

Expand All @@ -1620,7 +1619,7 @@ async fn op_futime_async(
_zero_copy: BufVec,
) -> Result<Value, AnyError> {
super::check_unstable2(&state, "Deno.futime");
let rid = args.rid as u32;
let rid = args.rid;
let atime = filetime::FileTime::from_unix_time(args.atime.0, args.atime.1);
let mtime = filetime::FileTime::from_unix_time(args.mtime.0, args.mtime.1);

Expand Down
14 changes: 7 additions & 7 deletions runtime/ops/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub fn init(rt: &mut deno_core::JsRuntime) {

#[derive(Deserialize)]
pub(crate) struct AcceptArgs {
pub rid: i32,
pub rid: u32,
pub transport: String,
}

Expand All @@ -64,7 +64,7 @@ async fn accept_tcp(
args: AcceptArgs,
_zero_copy: BufVec,
) -> Result<Value, AnyError> {
let rid = args.rid as u32;
let rid = args.rid;

let resource = state
.borrow()
Expand Down Expand Up @@ -125,7 +125,7 @@ async fn op_accept(

#[derive(Deserialize)]
pub(crate) struct ReceiveArgs {
pub rid: i32,
pub rid: u32,
pub transport: String,
}

Expand All @@ -137,7 +137,7 @@ async fn receive_udp(
assert_eq!(zero_copy.len(), 1, "Invalid number of arguments");
let mut zero_copy = zero_copy[0].clone();

let rid = args.rid as u32;
let rid = args.rid;

let resource = state
.borrow_mut()
Expand Down Expand Up @@ -181,7 +181,7 @@ async fn op_datagram_receive(

#[derive(Deserialize)]
struct SendArgs {
rid: i32,
rid: u32,
transport: String,
#[serde(flatten)]
transport_args: ArgsEnum,
Expand Down Expand Up @@ -215,7 +215,7 @@ async fn op_datagram_send(
let resource = state
.borrow_mut()
.resource_table
.get::<UdpSocketResource>(rid as u32)
.get::<UdpSocketResource>(rid)
.ok_or_else(|| bad_resource("Socket has been closed"))?;
let socket = RcRef::map(&resource, |r| &r.socket).borrow().await;
let byte_length = socket.send_to(&zero_copy, &addr).await?;
Expand All @@ -235,7 +235,7 @@ async fn op_datagram_send(
let resource = state
.borrow()
.resource_table
.get::<net_unix::UnixDatagramResource>(rid as u32)
.get::<net_unix::UnixDatagramResource>(rid)
.ok_or_else(|| {
custom_error("NotConnected", "Socket has been closed")
})?;
Expand Down
4 changes: 2 additions & 2 deletions runtime/ops/net_unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub(crate) async fn accept_unix(
args: AcceptArgs,
_bufs: BufVec,
) -> Result<Value, AnyError> {
let rid = args.rid as u32;
let rid = args.rid;

let resource = state
.borrow()
Expand Down Expand Up @@ -104,7 +104,7 @@ pub(crate) async fn receive_unix_packet(
) -> Result<Value, AnyError> {
assert_eq!(bufs.len(), 1, "Invalid number of arguments");

let rid = args.rid as u32;
let rid = args.rid;
let mut buf = bufs.into_iter().next().unwrap();

let resource = state
Expand Down
4 changes: 2 additions & 2 deletions runtime/ops/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,15 +178,15 @@ fn op_run(
#[derive(Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct RunStatusArgs {
rid: i32,
rid: u32,
}

async fn op_run_status(
state: Rc<RefCell<OpState>>,
args: RunStatusArgs,
_zero_copy: BufVec,
) -> Result<Value, AnyError> {
let rid = args.rid as u32;
let rid = args.rid;

{
let s = state.borrow();
Expand Down
6 changes: 3 additions & 3 deletions runtime/ops/signal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pub struct BindSignalArgs {
#[cfg(unix)]
#[derive(Deserialize)]
pub struct SignalArgs {
rid: i32,
rid: u32,
}

#[cfg(unix)]
Expand Down Expand Up @@ -93,7 +93,7 @@ async fn op_signal_poll(
_zero_copy: BufVec,
) -> Result<Value, AnyError> {
super::check_unstable2(&state, "Deno.signal");
let rid = args.rid as u32;
let rid = args.rid;

let resource = state
.borrow_mut()
Expand All @@ -116,7 +116,7 @@ pub fn op_signal_unbind(
_zero_copy: &mut [ZeroCopyBuf],
) -> Result<Value, AnyError> {
super::check_unstable(state, "Deno.signal");
let rid = args.rid as u32;
let rid = args.rid;
state
.resource_table
.close(rid)
Expand Down
6 changes: 3 additions & 3 deletions runtime/ops/tls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ async fn op_start_tls(
args: StartTLSArgs,
_zero_copy: BufVec,
) -> Result<Value, AnyError> {
let rid = args.rid as u32;
let rid = args.rid;

let mut domain = args.hostname.as_str();
if domain.is_empty() {
Expand Down Expand Up @@ -350,15 +350,15 @@ fn op_listen_tls(

#[derive(Deserialize)]
pub struct AcceptTlsArgs {
rid: i32,
rid: u32,
}

async fn op_accept_tls(
state: Rc<RefCell<OpState>>,
args: AcceptTlsArgs,
_zero_copy: BufVec,
) -> Result<Value, AnyError> {
let rid = args.rid as u32;
let rid = args.rid;

let resource = state
.borrow()
Expand Down
41 changes: 20 additions & 21 deletions runtime/ops/tty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,27 +225,26 @@ fn op_isatty(
) -> Result<Value, AnyError> {
let rid = args.rid;

let isatty: bool =
StdFileResource::with(state, rid as u32, move |r| match r {
Ok(std_file) => {
#[cfg(windows)]
{
use winapi::um::consoleapi;

let handle = get_windows_handle(&std_file)?;
let mut test_mode: DWORD = 0;
// If I cannot get mode out of console, it is not a console.
Ok(unsafe { consoleapi::GetConsoleMode(handle, &mut test_mode) != 0 })
}
#[cfg(unix)]
{
use std::os::unix::io::AsRawFd;
let raw_fd = std_file.as_raw_fd();
Ok(unsafe { libc::isatty(raw_fd as libc::c_int) == 1 })
}
let isatty: bool = StdFileResource::with(state, rid, move |r| match r {
Ok(std_file) => {
#[cfg(windows)]
{
use winapi::um::consoleapi;

let handle = get_windows_handle(&std_file)?;
let mut test_mode: DWORD = 0;
// If I cannot get mode out of console, it is not a console.
Ok(unsafe { consoleapi::GetConsoleMode(handle, &mut test_mode) != 0 })
}
_ => Ok(false),
})?;
#[cfg(unix)]
{
use std::os::unix::io::AsRawFd;
let raw_fd = std_file.as_raw_fd();
Ok(unsafe { libc::isatty(raw_fd as libc::c_int) == 1 })
}
}
_ => Ok(false),
})?;
Ok(json!(isatty))
}

Expand All @@ -269,7 +268,7 @@ fn op_console_size(

let rid = args.rid;

let size = StdFileResource::with(state, rid as u32, move |r| match r {
let size = StdFileResource::with(state, rid, move |r| match r {
Ok(std_file) => {
#[cfg(windows)]
{
Expand Down

0 comments on commit 1973059

Please sign in to comment.