Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More Rust 1.79 enhancements #116

Merged
merged 2 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ mutex-trait = "0.2"

bare-metal = "1"

# Only used for shell, where a macro is described to take a string literal and
# in the macro implementation turns it into a CStr.
cstr = "^0.2.11"

heapless = "^0.8"
Expand Down
2 changes: 1 addition & 1 deletion src/gcoap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ where
/// [coap_handler::Handler], you can wrap it in [crate::coap_handler::GcoapHandler] to for adaptation.
pub fn new_catch_all(handler: &'a mut H) -> Self {
Self::new(
cstr::cstr!("/"),
c"/",
riot_sys::COAP_GET
| riot_sys::COAP_POST
| riot_sys::COAP_PUT
Expand Down
2 changes: 1 addition & 1 deletion src/gnrc/ipv6.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ impl<M: Mode> Pktsnip<M> {
// unsafe: C API, and requirement on a Pktsnip that typed snips follow that type's
// conventions
let ptr = unsafe { riot_sys::gnrc_ipv6_get_header(self.ptr) };
if ptr == 0 as _ {
if ptr.is_null() {
None
} else {
// unsafe: Header is a transparent wrapper around the actual ipv6_hdr_t, and the
Expand Down
2 changes: 1 addition & 1 deletion src/gnrc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl Netif {

#[doc(alias = "gnrc_netif_get_by_pid")]
pub fn by_pid(pid: KernelPID) -> Option<Self> {
const NULL: *mut riot_sys::gnrc_netif_t = 0 as _;
const NULL: *mut riot_sys::gnrc_netif_t = core::ptr::null_mut();
// Not using as_ref: We can't guarantee that even for the short period between we're making
// it into a reference and casting it back to a pointer again, it is not used by anyone
// else
Expand Down
2 changes: 1 addition & 1 deletion src/gnrc_pktbuf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ impl<'a> Pktsnip<Shared> {
// unsafe: The C functions justify the new type
unsafe {
let new = riot_sys::gnrc_pktbuf_start_write(self.to_ptr());
if new == 0 as _ {
if new.is_null() {
Err(NotEnoughSpace)
} else {
Ok(Pktsnip::<Writable>::from_ptr(new))
Expand Down
2 changes: 1 addition & 1 deletion src/panic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fn panic(info: &::core::panic::PanicInfo) -> ! {
unsafe {
riot_sys::core_panic(
riot_sys::core_panic_t_PANIC_GENERAL_ERROR,
cstr::cstr!("RUST PANIC").as_ptr() as _,
c"RUST PANIC".as_ptr() as _,
)
};
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/saul/registration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ where
) -> Self {
Registration {
reg: riot_sys::saul_reg_t {
next: 0 as _,
next: core::ptr::null_mut(),
dev: device as *const _ as *mut _,
name: name.map(|n| n.as_ptr() as _).unwrap_or(core::ptr::null()),
driver: &driver.driver as *const _,
Expand Down
2 changes: 1 addition & 1 deletion src/ztimer/periodic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl<H: Handler, const HZ: u32> Timer<H, HZ> {
clock.0,
timer.as_mut_ptr(),
Some(Self::callback),
0 as _,
core::ptr::null_mut(),
ticks.0,
);
timer.assume_init()
Expand Down
Loading