Skip to content

Commit

Permalink
fix: use unsafe extern as needed by Rust 2024, doc. safety invariants
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexTMjugador committed Dec 3, 2024
1 parent d215d93 commit b2dc7c2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
11 changes: 7 additions & 4 deletions packages/packsquash/src/squash_zip/system_id/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ pub(super) fn get_kernel_host_id() -> Option<SystemId> {
use std::ptr;
use uuid::Uuid;

extern "C" {
#[allow(unsafe_code)] // SAFETY: the system call definition is correct
unsafe extern "C" {
/// `int sysctlbyname(const char* name, void* oldp, size_t* oldlenp, void* newp, size_t newlen)`, from `#include <sys/sysctl.h>`.
///
/// Documentation: <https://www.freebsd.org/cgi/man.cgi?query=sysctlbyname&apropos=0&sektion=0&manpath=FreeBSD+14.0-current&arch=default&format=html>
Expand Down Expand Up @@ -133,7 +134,8 @@ pub(super) fn get_dmi_product_id() -> Option<SystemId> {
use std::os::raw::{c_char, c_int};
use uuid::Uuid;

extern "C" {
#[allow(unsafe_code)] // SAFETY: the system call definition is correct
unsafe extern "C" {
/// `int kenv(int action, const char* name, char* value, int len)`, from `#include <kenv.h>`.
///
/// Documentation: <https://www.freebsd.org/cgi/man.cgi?query=kenv&sektion=2&format=html>
Expand Down Expand Up @@ -210,8 +212,9 @@ pub(super) fn get_platform_serial_number() -> Option<SystemId> {
type io_service_t = io_object_t;
type IOOptionBits = u32;

#[allow(unsafe_code)] // SAFETY: the system call definition is correct
#[link(name = "IOKit", kind = "framework")]
extern "C" {
unsafe extern "C" {
static kIOMasterPortDefault: mach_port_t;

/// Documentation: <https://developer.apple.com/documentation/iokit/1514687-ioservicematching?language=objc>
Expand Down Expand Up @@ -305,7 +308,7 @@ pub(super) fn get_platform_serial_number() -> Option<SystemId> {
pub(super) fn get_host_id() -> Option<SystemId> {
use std::os::raw::c_long;

#[allow(unsafe_code)]
#[allow(unsafe_code)] // SAFETY: the system call definition is correct
unsafe extern "C" {
/// `long gethostid()`, from `#include <unistd.h>`.
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ fn controlling_terminal() -> Option<PathBuf> {
use std::ffi::CStr;
use std::os::raw::c_char;

#[allow(unsafe_code)]
#[allow(unsafe_code)] // SAFETY: the system call definition is correct
unsafe extern "C" {
/// `char* ctermid(char* s)`, from `#include <stdio.h>`.
///
Expand Down

0 comments on commit b2dc7c2

Please sign in to comment.