Skip to content

Commit 686db52

Browse files
committed
feat: remove self mut from wiggle generate
Signed-off-by: Harald Hoyer <[email protected]>
1 parent 00bbf9a commit 686db52

File tree

4 files changed

+102
-111
lines changed

4 files changed

+102
-111
lines changed

crates/wasi-common/src/ctx.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ use crate::table::Table;
77
use crate::Error;
88
use cap_rand::RngCore;
99
use std::path::{Path, PathBuf};
10-
use std::sync::Arc;
10+
use std::sync::{Arc, RwLock};
1111

1212
pub struct WasiCtx {
1313
pub args: StringArray,
1414
pub env: StringArray,
15-
pub random: Box<dyn RngCore + Send + Sync>,
15+
pub random: RwLock<Box<dyn RngCore + Send + Sync>>,
1616
pub clocks: WasiClocks,
1717
pub sched: Box<dyn WasiSched>,
1818
pub table: Table,
@@ -28,7 +28,7 @@ impl WasiCtx {
2828
let s = WasiCtx {
2929
args: StringArray::new(),
3030
env: StringArray::new(),
31-
random,
31+
random: RwLock::new(random),
3232
clocks,
3333
sched,
3434
table,

crates/wasi-common/src/snapshots/preview_0.rs

Lines changed: 46 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -389,40 +389,40 @@ convert_flags_bidirectional!(
389389
#[wiggle::async_trait]
390390
impl wasi_unstable::WasiUnstable for WasiCtx {
391391
async fn args_get<'a>(
392-
&mut self,
392+
&self,
393393
argv: &GuestPtr<'a, GuestPtr<'a, u8>>,
394394
argv_buf: &GuestPtr<'a, u8>,
395395
) -> Result<(), Error> {
396396
Snapshot1::args_get(self, argv, argv_buf).await?;
397397
Ok(())
398398
}
399399

400-
async fn args_sizes_get(&mut self) -> Result<(types::Size, types::Size), Error> {
400+
async fn args_sizes_get(&self) -> Result<(types::Size, types::Size), Error> {
401401
let s = Snapshot1::args_sizes_get(self).await?;
402402
Ok(s)
403403
}
404404

405405
async fn environ_get<'a>(
406-
&mut self,
406+
&self,
407407
environ: &GuestPtr<'a, GuestPtr<'a, u8>>,
408408
environ_buf: &GuestPtr<'a, u8>,
409409
) -> Result<(), Error> {
410410
Snapshot1::environ_get(self, environ, environ_buf).await?;
411411
Ok(())
412412
}
413413

414-
async fn environ_sizes_get(&mut self) -> Result<(types::Size, types::Size), Error> {
414+
async fn environ_sizes_get(&self) -> Result<(types::Size, types::Size), Error> {
415415
let s = Snapshot1::environ_sizes_get(self).await?;
416416
Ok(s)
417417
}
418418

419-
async fn clock_res_get(&mut self, id: types::Clockid) -> Result<types::Timestamp, Error> {
419+
async fn clock_res_get(&self, id: types::Clockid) -> Result<types::Timestamp, Error> {
420420
let t = Snapshot1::clock_res_get(self, id.into()).await?;
421421
Ok(t)
422422
}
423423

424424
async fn clock_time_get(
425-
&mut self,
425+
&self,
426426
id: types::Clockid,
427427
precision: types::Timestamp,
428428
) -> Result<types::Timestamp, Error> {
@@ -431,7 +431,7 @@ impl wasi_unstable::WasiUnstable for WasiCtx {
431431
}
432432

433433
async fn fd_advise(
434-
&mut self,
434+
&self,
435435
fd: types::Fd,
436436
offset: types::Filesize,
437437
len: types::Filesize,
@@ -442,7 +442,7 @@ impl wasi_unstable::WasiUnstable for WasiCtx {
442442
}
443443

444444
async fn fd_allocate(
445-
&mut self,
445+
&self,
446446
fd: types::Fd,
447447
offset: types::Filesize,
448448
len: types::Filesize,
@@ -451,31 +451,27 @@ impl wasi_unstable::WasiUnstable for WasiCtx {
451451
Ok(())
452452
}
453453

454-
async fn fd_close(&mut self, fd: types::Fd) -> Result<(), Error> {
454+
async fn fd_close(&self, fd: types::Fd) -> Result<(), Error> {
455455
Snapshot1::fd_close(self, fd.into()).await?;
456456
Ok(())
457457
}
458458

459-
async fn fd_datasync(&mut self, fd: types::Fd) -> Result<(), Error> {
459+
async fn fd_datasync(&self, fd: types::Fd) -> Result<(), Error> {
460460
Snapshot1::fd_datasync(self, fd.into()).await?;
461461
Ok(())
462462
}
463463

464-
async fn fd_fdstat_get(&mut self, fd: types::Fd) -> Result<types::Fdstat, Error> {
464+
async fn fd_fdstat_get(&self, fd: types::Fd) -> Result<types::Fdstat, Error> {
465465
Ok(Snapshot1::fd_fdstat_get(self, fd.into()).await?.into())
466466
}
467467

468-
async fn fd_fdstat_set_flags(
469-
&mut self,
470-
fd: types::Fd,
471-
flags: types::Fdflags,
472-
) -> Result<(), Error> {
468+
async fn fd_fdstat_set_flags(&self, fd: types::Fd, flags: types::Fdflags) -> Result<(), Error> {
473469
Snapshot1::fd_fdstat_set_flags(self, fd.into(), flags.into()).await?;
474470
Ok(())
475471
}
476472

477473
async fn fd_fdstat_set_rights(
478-
&mut self,
474+
&self,
479475
fd: types::Fd,
480476
fs_rights_base: types::Rights,
481477
fs_rights_inheriting: types::Rights,
@@ -490,12 +486,12 @@ impl wasi_unstable::WasiUnstable for WasiCtx {
490486
Ok(())
491487
}
492488

493-
async fn fd_filestat_get(&mut self, fd: types::Fd) -> Result<types::Filestat, Error> {
489+
async fn fd_filestat_get(&self, fd: types::Fd) -> Result<types::Filestat, Error> {
494490
Ok(Snapshot1::fd_filestat_get(self, fd.into()).await?.into())
495491
}
496492

497493
async fn fd_filestat_set_size(
498-
&mut self,
494+
&self,
499495
fd: types::Fd,
500496
size: types::Filesize,
501497
) -> Result<(), Error> {
@@ -504,7 +500,7 @@ impl wasi_unstable::WasiUnstable for WasiCtx {
504500
}
505501

506502
async fn fd_filestat_set_times(
507-
&mut self,
503+
&self,
508504
fd: types::Fd,
509505
atim: types::Timestamp,
510506
mtim: types::Timestamp,
@@ -523,7 +519,7 @@ impl wasi_unstable::WasiUnstable for WasiCtx {
523519
// representation to a std::io::IoSlice(Mut) representation.
524520

525521
async fn fd_read<'a>(
526-
&mut self,
522+
&self,
527523
fd: types::Fd,
528524
iovs: &types::IovecArray<'a>,
529525
) -> Result<types::Size, Error> {
@@ -551,7 +547,7 @@ impl wasi_unstable::WasiUnstable for WasiCtx {
551547
}
552548

553549
async fn fd_pread<'a>(
554-
&mut self,
550+
&self,
555551
fd: types::Fd,
556552
iovs: &types::IovecArray<'a>,
557553
offset: types::Filesize,
@@ -580,7 +576,7 @@ impl wasi_unstable::WasiUnstable for WasiCtx {
580576
}
581577

582578
async fn fd_write<'a>(
583-
&mut self,
579+
&self,
584580
fd: types::Fd,
585581
ciovs: &types::CiovecArray<'a>,
586582
) -> Result<types::Size, Error> {
@@ -610,7 +606,7 @@ impl wasi_unstable::WasiUnstable for WasiCtx {
610606
}
611607

612608
async fn fd_pwrite<'a>(
613-
&mut self,
609+
&self,
614610
fd: types::Fd,
615611
ciovs: &types::CiovecArray<'a>,
616612
offset: types::Filesize,
@@ -640,12 +636,12 @@ impl wasi_unstable::WasiUnstable for WasiCtx {
640636
Ok(types::Size::try_from(bytes_written)?)
641637
}
642638

643-
async fn fd_prestat_get(&mut self, fd: types::Fd) -> Result<types::Prestat, Error> {
639+
async fn fd_prestat_get(&self, fd: types::Fd) -> Result<types::Prestat, Error> {
644640
Ok(Snapshot1::fd_prestat_get(self, fd.into()).await?.into())
645641
}
646642

647643
async fn fd_prestat_dir_name<'a>(
648-
&mut self,
644+
&self,
649645
fd: types::Fd,
650646
path: &GuestPtr<'a, u8>,
651647
path_max_len: types::Size,
@@ -654,31 +650,31 @@ impl wasi_unstable::WasiUnstable for WasiCtx {
654650
Ok(())
655651
}
656652

657-
async fn fd_renumber(&mut self, from: types::Fd, to: types::Fd) -> Result<(), Error> {
653+
async fn fd_renumber(&self, from: types::Fd, to: types::Fd) -> Result<(), Error> {
658654
Snapshot1::fd_renumber(self, from.into(), to.into()).await?;
659655
Ok(())
660656
}
661657

662658
async fn fd_seek(
663-
&mut self,
659+
&self,
664660
fd: types::Fd,
665661
offset: types::Filedelta,
666662
whence: types::Whence,
667663
) -> Result<types::Filesize, Error> {
668664
Ok(Snapshot1::fd_seek(self, fd.into(), offset, whence.into()).await?)
669665
}
670666

671-
async fn fd_sync(&mut self, fd: types::Fd) -> Result<(), Error> {
667+
async fn fd_sync(&self, fd: types::Fd) -> Result<(), Error> {
672668
Snapshot1::fd_sync(self, fd.into()).await?;
673669
Ok(())
674670
}
675671

676-
async fn fd_tell(&mut self, fd: types::Fd) -> Result<types::Filesize, Error> {
672+
async fn fd_tell(&self, fd: types::Fd) -> Result<types::Filesize, Error> {
677673
Ok(Snapshot1::fd_tell(self, fd.into()).await?)
678674
}
679675

680676
async fn fd_readdir<'a>(
681-
&mut self,
677+
&self,
682678
fd: types::Fd,
683679
buf: &GuestPtr<'a, u8>,
684680
buf_len: types::Size,
@@ -688,7 +684,7 @@ impl wasi_unstable::WasiUnstable for WasiCtx {
688684
}
689685

690686
async fn path_create_directory<'a>(
691-
&mut self,
687+
&self,
692688
dirfd: types::Fd,
693689
path: &GuestPtr<'a, str>,
694690
) -> Result<(), Error> {
@@ -697,7 +693,7 @@ impl wasi_unstable::WasiUnstable for WasiCtx {
697693
}
698694

699695
async fn path_filestat_get<'a>(
700-
&mut self,
696+
&self,
701697
dirfd: types::Fd,
702698
flags: types::Lookupflags,
703699
path: &GuestPtr<'a, str>,
@@ -710,7 +706,7 @@ impl wasi_unstable::WasiUnstable for WasiCtx {
710706
}
711707

712708
async fn path_filestat_set_times<'a>(
713-
&mut self,
709+
&self,
714710
dirfd: types::Fd,
715711
flags: types::Lookupflags,
716712
path: &GuestPtr<'a, str>,
@@ -732,7 +728,7 @@ impl wasi_unstable::WasiUnstable for WasiCtx {
732728
}
733729

734730
async fn path_link<'a>(
735-
&mut self,
731+
&self,
736732
src_fd: types::Fd,
737733
src_flags: types::Lookupflags,
738734
src_path: &GuestPtr<'a, str>,
@@ -752,7 +748,7 @@ impl wasi_unstable::WasiUnstable for WasiCtx {
752748
}
753749

754750
async fn path_open<'a>(
755-
&mut self,
751+
&self,
756752
dirfd: types::Fd,
757753
dirflags: types::Lookupflags,
758754
path: &GuestPtr<'a, str>,
@@ -776,7 +772,7 @@ impl wasi_unstable::WasiUnstable for WasiCtx {
776772
}
777773

778774
async fn path_readlink<'a>(
779-
&mut self,
775+
&self,
780776
dirfd: types::Fd,
781777
path: &GuestPtr<'a, str>,
782778
buf: &GuestPtr<'a, u8>,
@@ -786,7 +782,7 @@ impl wasi_unstable::WasiUnstable for WasiCtx {
786782
}
787783

788784
async fn path_remove_directory<'a>(
789-
&mut self,
785+
&self,
790786
dirfd: types::Fd,
791787
path: &GuestPtr<'a, str>,
792788
) -> Result<(), Error> {
@@ -795,7 +791,7 @@ impl wasi_unstable::WasiUnstable for WasiCtx {
795791
}
796792

797793
async fn path_rename<'a>(
798-
&mut self,
794+
&self,
799795
src_fd: types::Fd,
800796
src_path: &GuestPtr<'a, str>,
801797
dest_fd: types::Fd,
@@ -806,7 +802,7 @@ impl wasi_unstable::WasiUnstable for WasiCtx {
806802
}
807803

808804
async fn path_symlink<'a>(
809-
&mut self,
805+
&self,
810806
src_path: &GuestPtr<'a, str>,
811807
dirfd: types::Fd,
812808
dest_path: &GuestPtr<'a, str>,
@@ -816,7 +812,7 @@ impl wasi_unstable::WasiUnstable for WasiCtx {
816812
}
817813

818814
async fn path_unlink_file<'a>(
819-
&mut self,
815+
&self,
820816
dirfd: types::Fd,
821817
path: &GuestPtr<'a, str>,
822818
) -> Result<(), Error> {
@@ -832,7 +828,7 @@ impl wasi_unstable::WasiUnstable for WasiCtx {
832828
// The bodies of these functions is mostly about converting the GuestPtr and types::-based
833829
// representation to use the Poll abstraction.
834830
async fn poll_oneoff<'a>(
835-
&mut self,
831+
&self,
836832
subs: &GuestPtr<'a, types::Subscription>,
837833
events: &GuestPtr<'a, types::Event>,
838834
nsubscriptions: types::Size,
@@ -866,7 +862,7 @@ impl wasi_unstable::WasiUnstable for WasiCtx {
866862
}
867863
}
868864

869-
let table = &mut self.table;
865+
let table = &self.table;
870866
let mut sub_fds: HashSet<types::Fd> = HashSet::new();
871867
// We need these refmuts to outlive Poll, which will hold the &mut dyn WasiFile inside
872868
let mut reads: Vec<(u32, Userdata)> = Vec::new();
@@ -1011,21 +1007,21 @@ impl wasi_unstable::WasiUnstable for WasiCtx {
10111007
Ok(num_results.try_into().expect("results fit into memory"))
10121008
}
10131009

1014-
async fn proc_exit(&mut self, status: types::Exitcode) -> anyhow::Error {
1010+
async fn proc_exit(&self, status: types::Exitcode) -> anyhow::Error {
10151011
Snapshot1::proc_exit(self, status).await
10161012
}
10171013

1018-
async fn proc_raise(&mut self, _sig: types::Signal) -> Result<(), Error> {
1014+
async fn proc_raise(&self, _sig: types::Signal) -> Result<(), Error> {
10191015
Err(Error::trap(anyhow::Error::msg("proc_raise unsupported")))
10201016
}
10211017

1022-
async fn sched_yield(&mut self) -> Result<(), Error> {
1018+
async fn sched_yield(&self) -> Result<(), Error> {
10231019
Snapshot1::sched_yield(self).await?;
10241020
Ok(())
10251021
}
10261022

10271023
async fn random_get<'a>(
1028-
&mut self,
1024+
&self,
10291025
buf: &GuestPtr<'a, u8>,
10301026
buf_len: types::Size,
10311027
) -> Result<(), Error> {
@@ -1034,7 +1030,7 @@ impl wasi_unstable::WasiUnstable for WasiCtx {
10341030
}
10351031

10361032
async fn sock_recv<'a>(
1037-
&mut self,
1033+
&self,
10381034
_fd: types::Fd,
10391035
_ri_data: &types::IovecArray<'a>,
10401036
_ri_flags: types::Riflags,
@@ -1043,15 +1039,15 @@ impl wasi_unstable::WasiUnstable for WasiCtx {
10431039
}
10441040

10451041
async fn sock_send<'a>(
1046-
&mut self,
1042+
&self,
10471043
_fd: types::Fd,
10481044
_si_data: &types::CiovecArray<'a>,
10491045
_si_flags: types::Siflags,
10501046
) -> Result<types::Size, Error> {
10511047
Err(Error::trap(anyhow::Error::msg("sock_send unsupported")))
10521048
}
10531049

1054-
async fn sock_shutdown(&mut self, _fd: types::Fd, _how: types::Sdflags) -> Result<(), Error> {
1050+
async fn sock_shutdown(&self, _fd: types::Fd, _how: types::Sdflags) -> Result<(), Error> {
10551051
Err(Error::trap(anyhow::Error::msg("sock_shutdown unsupported")))
10561052
}
10571053
}

0 commit comments

Comments
 (0)