Skip to content

Commit

Permalink
Merge branch 'main' into feature/platform-primitives-sleep-clock
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisBiryukov91 authored Mar 6, 2024
2 parents 870bc06 + 31dac73 commit a063067
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
sphinx==4.5.0
sphinx_c_autodoc
sphinx_rtd_theme
clang==14
sphinx==7.2.6
sphinx_c_autodoc==1.3.0
sphinx_rtd_theme==2.0.0
clang==14.0
5 changes: 5 additions & 0 deletions include/zenoh_commons.h
Original file line number Diff line number Diff line change
Expand Up @@ -1928,6 +1928,11 @@ ZENOHC_API struct z_owned_queryable_t z_queryable_null(void);
* Constructs the default value for :c:type:`z_query_reply_options_t`.
*/
ZENOHC_API struct z_queryable_options_t z_queryable_options_default(void);
ZENOHC_API void z_random_fill(void *buf, size_t len);
ZENOHC_API uint16_t z_random_u16(void);
ZENOHC_API uint32_t z_random_u32(void);
ZENOHC_API uint64_t z_random_u64(void);
ZENOHC_API uint8_t z_random_u8(void);
/**
* Calls the closure. Calling an uninitialized closure is a no-op.
*/
Expand Down
3 changes: 3 additions & 0 deletions src/platform/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ pub use sleep::*;
mod sleep;
pub use synchronization::*;
mod synchronization;

pub use random::*;
mod random;
34 changes: 34 additions & 0 deletions src/platform/random.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use std::slice::from_raw_parts_mut;

use libc::c_void;
use rand::{random, thread_rng, RngCore};

#[no_mangle]
pub extern "C" fn z_random_u8() -> u8 {
random::<u8>()
}

#[no_mangle]
pub extern "C" fn z_random_u16() -> u16 {
random::<u16>()
}

#[no_mangle]
pub extern "C" fn z_random_u32() -> u32 {
random::<u32>()
}

#[no_mangle]
pub extern "C" fn z_random_u64() -> u64 {
random::<u64>()
}

#[no_mangle]
#[allow(clippy::missing_safety_doc)]
pub unsafe extern "C" fn z_random_fill(buf: *mut c_void, len: usize) {
if buf.is_null() || len == 0 {
return;
}
let b: &mut [u8] = from_raw_parts_mut(buf as *mut u8, len);
thread_rng().fill_bytes(b);
}

0 comments on commit a063067

Please sign in to comment.