@@ -5,16 +5,16 @@ use crate::*;
55include ! ( concat!( env!( "OUT_DIR" ) , "/std_files.rs" ) ) ;
66
77
8- #[ no_mangle]
9- pub unsafe extern fn wasm_assemble (
8+ #[ unsafe ( no_mangle) ]
9+ pub unsafe extern "C" fn wasm_assemble (
1010 format_str : * const String ,
1111 src : * mut String )
1212 -> * mut String
1313{
1414 let virtual_filename = "asm" ;
1515
16- let format_str = std:: mem:: transmute :: < _ , & String > ( format_str) ;
17- let src = std:: mem:: transmute :: < _ , & String > ( src) ;
16+ let format_str = unsafe { std:: mem:: transmute :: < _ , & String > ( format_str) } ;
17+ let src = unsafe { std:: mem:: transmute :: < _ , & String > ( src) } ;
1818
1919 let mut report = diagn:: Report :: new ( ) ;
2020
@@ -38,8 +38,8 @@ pub unsafe extern fn wasm_assemble(
3838 {
3939 let mut err = Vec :: < u8 > :: new ( ) ;
4040 report. print_all ( & mut err, & fileserver, true ) ;
41- return wasm_string_new_with (
42- String :: from_utf8 ( err) . unwrap ( ) ) ;
41+ return unsafe { wasm_string_new_with (
42+ String :: from_utf8 ( err) . unwrap ( ) ) } ;
4343 }
4444 }
4545 } ;
@@ -56,12 +56,12 @@ pub unsafe extern fn wasm_assemble(
5656 & output,
5757 & format) ;
5858
59- wasm_string_new_with ( String :: from_utf8_lossy ( & formatted) )
59+ unsafe { wasm_string_new_with ( String :: from_utf8_lossy ( & formatted) ) }
6060}
6161
6262
63- #[ no_mangle]
64- pub unsafe extern fn wasm_get_version ( ) -> * mut String
63+ #[ unsafe ( no_mangle) ]
64+ pub unsafe extern "C" fn wasm_get_version ( ) -> * mut String
6565{
6666 let version =
6767 if let Some ( hash) = option_env ! ( "CUSTOMASM_COMMIT_HASH" ) {
@@ -73,12 +73,12 @@ pub unsafe extern fn wasm_get_version() -> *mut String
7373 else {
7474 env ! ( "CUSTOMASM_VERSION" ) . to_string ( )
7575 } ;
76- wasm_string_new_with ( version)
76+ unsafe { wasm_string_new_with ( version) }
7777}
7878
7979
80- #[ no_mangle]
81- pub unsafe extern fn wasm_string_new ( len : u32 ) -> * mut String
80+ #[ unsafe ( no_mangle) ]
81+ pub unsafe extern "C" fn wasm_string_new ( len : u32 ) -> * mut String
8282{
8383 let mut s = Box :: new ( String :: new ( ) ) ;
8484 for _ in 0 ..len
@@ -98,37 +98,41 @@ where S: Into<String>
9898}
9999
100100
101- #[ no_mangle]
102- pub unsafe extern fn wasm_string_drop ( s : * mut String )
101+ #[ unsafe ( no_mangle) ]
102+ pub unsafe extern "C" fn wasm_string_drop ( s : * mut String )
103103{
104- let s = Box :: from_raw ( s) ;
104+ let s = unsafe { Box :: from_raw ( s) } ;
105105 drop ( s) ;
106106}
107107
108108
109- #[ no_mangle]
110- pub unsafe extern fn wasm_string_get_len ( s : * mut String ) -> u32
109+ #[ unsafe ( no_mangle) ]
110+ pub unsafe extern "C" fn wasm_string_get_len ( s : * mut String ) -> u32
111111{
112- std:: mem:: transmute :: < _ , & mut String > ( s) . len ( ) as u32
112+ unsafe { std:: mem:: transmute :: < _ , & mut String > ( s) } . len ( ) as u32
113113}
114114
115115
116- #[ no_mangle]
117- pub unsafe extern fn wasm_string_get_byte ( s : * mut String , index : u32 ) -> u8
116+ #[ unsafe ( no_mangle) ]
117+ pub unsafe extern "C" fn wasm_string_get_byte ( s : * mut String , index : u32 ) -> u8
118118{
119- std:: ptr:: read (
120- std:: mem:: transmute :: < _ , & mut String > ( s)
121- . as_ptr ( )
122- . offset ( index as isize ) )
119+ unsafe {
120+ std:: ptr:: read (
121+ std:: mem:: transmute :: < _ , & mut String > ( s)
122+ . as_ptr ( )
123+ . offset ( index as isize ) )
124+ }
123125}
124126
125127
126- #[ no_mangle]
127- pub unsafe extern fn wasm_string_set_byte ( s : * mut String , index : u32 , value : u8 )
128+ #[ unsafe ( no_mangle) ]
129+ pub unsafe extern "C" fn wasm_string_set_byte ( s : * mut String , index : u32 , value : u8 )
128130{
129- let bytes = std:: mem:: transmute :: < _ , & mut String > ( s) . as_ptr ( ) ;
130- std:: ptr:: write (
131- std:: mem:: transmute :: < _ , * mut u8 > ( bytes)
132- . offset ( index as isize ) ,
133- value)
131+ let bytes = unsafe { std:: mem:: transmute :: < _ , & mut String > ( s) } . as_ptr ( ) ;
132+ unsafe {
133+ std:: ptr:: write (
134+ std:: mem:: transmute :: < _ , * mut u8 > ( bytes)
135+ . offset ( index as isize ) ,
136+ value)
137+ }
134138}
0 commit comments