diff options
Diffstat (limited to 'test_ffi/src/lib.rs')
-rw-r--r-- | test_ffi/src/lib.rs | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/test_ffi/src/lib.rs b/test_ffi/src/lib.rs index 95b7d900c..bc89bd66c 100644 --- a/test_ffi/src/lib.rs +++ b/test_ffi/src/lib.rs @@ -95,6 +95,16 @@ pub extern "C" fn add_f64(a: f64, b: f64) -> f64 { } #[no_mangle] +unsafe extern "C" fn hash(ptr: *const u8, length: u32) -> u32 { + let buf = std::slice::from_raw_parts(ptr, length as usize); + let mut hash: u32 = 0; + for byte in buf { + hash = hash.wrapping_mul(0x10001000).wrapping_add(*byte as u32); + } + hash +} + +#[no_mangle] pub extern "C" fn sleep_blocking(ms: u64) { let duration = Duration::from_millis(ms); sleep(duration); |