1- use crate :: error:: { Result , bail} ;
1+ use crate :: error:: { OutOfMemory , Result , bail} ;
22use crate :: module:: {
33 FuncRefIndex , Initializer , MemoryInitialization , MemoryInitializer , Module , TableSegment ,
44 TableSegmentElements ,
@@ -7,10 +7,10 @@ use crate::prelude::*;
77use crate :: {
88 ConstExpr , ConstOp , DataIndex , DefinedFuncIndex , ElemIndex , EngineOrModuleTypeIndex ,
99 EntityIndex , EntityType , FuncIndex , FuncKey , GlobalIndex , IndexType , InitMemory , MemoryIndex ,
10- ModuleInternedTypeIndex , ModuleTypesBuilder , PrimaryMap , SizeOverflow , StaticMemoryInitializer ,
11- StaticModuleIndex , TableIndex , TableInitialValue , Tag , TagIndex , Tunables , TypeConvert ,
12- TypeIndex , WasmError , WasmHeapTopType , WasmHeapType , WasmResult , WasmValType ,
13- WasmparserTypeConverter ,
10+ ModuleInternedTypeIndex , ModuleTypesBuilder , PanicOnOom as _ , PrimaryMap , SizeOverflow ,
11+ StaticMemoryInitializer , StaticModuleIndex , TableIndex , TableInitialValue , Tag , TagIndex ,
12+ Tunables , TypeConvert , TypeIndex , WasmError , WasmHeapTopType , WasmHeapType , WasmResult ,
13+ WasmValType , WasmparserTypeConverter ,
1414} ;
1515use cranelift_entity:: SecondaryMap ;
1616use cranelift_entity:: packed_option:: ReservedValue ;
@@ -373,7 +373,7 @@ impl<'a, 'data> ModuleEnvironment<'a, 'data> {
373373 bail ! ( "custom-descriptors proposal not implemented yet" ) ;
374374 }
375375 } ;
376- self . declare_import ( import. module , import. name , ty) ;
376+ self . declare_import ( import. module , import. name , ty) ? ;
377377 }
378378 }
379379
@@ -469,7 +469,7 @@ impl<'a, 'data> ModuleEnvironment<'a, 'data> {
469469 self . validator . export_section ( & exports) ?;
470470
471471 let cnt = usize:: try_from ( exports. count ( ) ) . unwrap ( ) ;
472- self . result . module . exports . reserve ( cnt) ;
472+ self . result . module . exports . reserve ( cnt) ? ;
473473
474474 for entry in exports {
475475 let wasmparser:: Export { name, kind, index } = entry?;
@@ -484,10 +484,8 @@ impl<'a, 'data> ModuleEnvironment<'a, 'data> {
484484 ExternalKind :: Global => EntityIndex :: Global ( GlobalIndex :: from_u32 ( index) ) ,
485485 ExternalKind :: Tag => EntityIndex :: Tag ( TagIndex :: from_u32 ( index) ) ,
486486 } ;
487- self . result
488- . module
489- . exports
490- . insert ( String :: from ( name) , entity) ;
487+ let name = self . result . module . strings . insert ( name) ?;
488+ self . result . module . exports . insert ( name, entity) ?;
491489 }
492490 }
493491
@@ -812,13 +810,19 @@ and for re-adding support for interface types you can see this issue:
812810 /// When the module linking proposal is disabled, however, disregard this
813811 /// logic and instead work directly with two-level imports since no
814812 /// instances are defined.
815- fn declare_import ( & mut self , module : & ' data str , field : & ' data str , ty : EntityType ) {
813+ fn declare_import (
814+ & mut self ,
815+ module : & ' data str ,
816+ field : & ' data str ,
817+ ty : EntityType ,
818+ ) -> Result < ( ) , OutOfMemory > {
816819 let index = self . push_type ( ty) ;
817820 self . result . module . initializers . push ( Initializer :: Import {
818- name : module. to_owned ( ) ,
819- field : field . to_owned ( ) ,
821+ name : self . result . module . strings . insert ( module ) ? ,
822+ field : self . result . module . strings . insert ( field ) ? ,
820823 index,
821824 } ) ;
825+ Ok ( ( ) )
822826 }
823827
824828 fn push_type ( & mut self , ty : EntityType ) -> EntityIndex {
@@ -877,7 +881,8 @@ and for re-adding support for interface types you can see this issue:
877881 }
878882 }
879883 wasmparser:: Name :: Module { name, .. } => {
880- self . result . module . name = Some ( name. to_string ( ) ) ;
884+ self . result . module . name =
885+ Some ( self . result . module . strings . insert ( name) . panic_on_oom ( ) ) ;
881886 if self . tunables . debug_native {
882887 self . result . debuginfo . name_section . module_name = Some ( name) ;
883888 }
0 commit comments