@@ -35,22 +35,17 @@ type SocketErrorStorage = Arc<Mutex<Option<(String, String)>>>;
3535
3636/// Container for data that needs to be retained by the Store for WASI functionality.
3737/// This includes Ruby procs (for GC marking) and error storages (for error propagation).
38- #[ derive( TypedData ) ]
39- #[ magnus( class = "Wasmtime::WasiRetainedData" , mark, free_immediately) ]
4038pub struct WasiRetainedData {
4139 proc : Option < Opaque < Proc > > ,
4240 error_storage : Option < SocketErrorStorage > ,
4341}
4442
45- impl DataTypeFunctions for WasiRetainedData {
46- fn mark ( & self , marker : & Marker ) {
43+ impl WasiRetainedData {
44+ pub fn mark ( & self , marker : & Marker ) {
4745 if let Some ( proc) = self . proc {
4846 marker. mark ( proc) ;
4947 }
5048 }
51- }
52-
53- impl WasiRetainedData {
5449 pub fn new ( proc : Option < Proc > , error_storage : Option < SocketErrorStorage > ) -> Self {
5550 Self {
5651 proc : proc. map ( |p| p. into ( ) ) ,
@@ -505,19 +500,19 @@ impl WasiConfig {
505500 rb_self
506501 }
507502
508- pub fn build_p1 ( & self , ruby : & Ruby ) -> Result < ( WasiP1Ctx , Option < Value > ) , Error > {
503+ pub fn build_p1 ( & self , ruby : & Ruby ) -> Result < ( WasiP1Ctx , Option < WasiRetainedData > ) , Error > {
509504 let ( mut builder, retained_data) = self . build_impl ( ruby) ?;
510505 let ctx = builder. build_p1 ( ) ;
511506 Ok ( ( ctx, retained_data) )
512507 }
513508
514- pub fn build ( & self , ruby : & Ruby ) -> Result < ( WasiCtx , Option < Value > ) , Error > {
509+ pub fn build ( & self , ruby : & Ruby ) -> Result < ( WasiCtx , Option < WasiRetainedData > ) , Error > {
515510 let ( mut builder, retained_data) = self . build_impl ( ruby) ?;
516511 let ctx = builder. build ( ) ;
517512 Ok ( ( ctx, retained_data) )
518513 }
519514
520- fn build_impl ( & self , ruby : & Ruby ) -> Result < ( WasiCtxBuilder , Option < Value > ) , Error > {
515+ fn build_impl ( & self , ruby : & Ruby ) -> Result < ( WasiCtxBuilder , Option < WasiRetainedData > ) , Error > {
521516 let mut builder = WasiCtxBuilder :: new ( ) ;
522517 let inner = self . inner . borrow ( ) ;
523518 let mut proc_to_retain = None ;
@@ -631,15 +626,17 @@ impl WasiConfig {
631626 . map_err ( |e| error ! ( "{}" , e) ) ?;
632627 }
633628
634- // Wrap retained data in a single Ruby object if we have anything to retain
635- let retained_value = if proc_to_retain. is_some ( ) || error_storage_to_retain. is_some ( ) {
636- let retained_data = WasiRetainedData :: new ( proc_to_retain, error_storage_to_retain) ;
637- Some ( ruby. obj_wrap ( retained_data) . as_value ( ) )
629+ // Return retained data directly if we have anything to retain
630+ let retained_data = if proc_to_retain. is_some ( ) || error_storage_to_retain. is_some ( ) {
631+ Some ( WasiRetainedData :: new (
632+ proc_to_retain,
633+ error_storage_to_retain,
634+ ) )
638635 } else {
639636 None
640637 } ;
641638
642- Ok ( ( builder, retained_value ) )
639+ Ok ( ( builder, retained_data ) )
643640 }
644641
645642 fn check_determinism ( & self ) -> Result < ( ) , Error > {
@@ -671,9 +668,6 @@ pub fn file_w(path: RString) -> Result<File, Error> {
671668}
672669
673670pub fn init ( ruby : & Ruby ) -> Result < ( ) , Error > {
674- // Register internal WasiRetainedData class (not exposed to Ruby API)
675- root ( ) . define_class ( "WasiRetainedData" , ruby. class_object ( ) ) ?;
676-
677671 let class = root ( ) . define_class ( "WasiConfig" , ruby. class_object ( ) ) ?;
678672 class. define_singleton_method ( "new" , function ! ( WasiConfig :: new, 0 ) ) ?;
679673
0 commit comments