Skip to content

Commit

Permalink
rust: Switch to new core::ffi types
Browse files Browse the repository at this point in the history
CStr is now here. This gets rid of three vendored deps, whee.

Signed-off-by: Hector Martin <[email protected]>
  • Loading branch information
marcan committed Apr 9, 2024
1 parent 313547d commit 396d1d7
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 44 deletions.
9 changes: 0 additions & 9 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,9 @@
[submodule "rust/vendor/cfg-if"]
path = rust/vendor/cfg-if
url = https://github.com/alexcrichton/cfg-if
[submodule "rust/vendor/cstr_core"]
path = rust/vendor/cstr_core
url = https://github.com/Amanieu/cstr_core
[submodule "rust/vendor/cty"]
path = rust/vendor/cty
url = https://github.com/japaric/cty
[submodule "rust/vendor/uuid"]
path = rust/vendor/uuid
url = https://github.com/uuid-rs/uuid
[submodule "rust/vendor/log"]
path = rust/vendor/log
url = https://github.com/rust-lang/log
[submodule "rust/vendor/memchr"]
path = rust/vendor/memchr
url = https://github.com/BurntSushi/memchr
18 changes: 0 additions & 18 deletions rust/Cargo.lock

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

5 changes: 0 additions & 5 deletions rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,10 @@ crate-type = [ "staticlib" ]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
fatfs = { path = "vendor/rust-fatfs", default-features = false, features = ["lfn", "alloc"] }
cstr_core = "0.2.5"
uuid = { version = "1.7.0", default-features = false }
cty = "0.2.2"

[patch.crates-io]
uuid = { path = "vendor/uuid" }
cty = { path = "vendor/cty" }
cstr_core = { path = "vendor/cstr_core" }
memchr = { path = "vendor/memchr" }
log = { path = "vendor/log" }
bitflags = { path = "vendor/bitflags" }
cfg-if = { path = "vendor/cfg-if" }
7 changes: 3 additions & 4 deletions rust/src/chainload.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
// SPDX-License-Identifier: MIT
#![deny(unsafe_op_in_unsafe_fn)]

use crate::c_size_t;
use crate::gpt;
use crate::nvme;
use crate::println;
use alloc::vec::Vec;
use core::ffi::c_void;
use cstr_core::CStr;
use cty::*;
use core::ffi::{c_char, c_int, c_void, CStr};
use fatfs::{FileSystem, FsOptions, Read, Seek, SeekFrom};
use uuid::Uuid;

Expand Down Expand Up @@ -81,7 +80,7 @@ fn load_image(spec: &str) -> Result<Vec<u8>, Error> {
pub unsafe extern "C" fn rust_load_image(
raw_spec: *const c_char,
image: *mut *mut c_void,
size: *mut size_t,
size: *mut c_size_t,
) -> c_int {
let spec = unsafe { CStr::from_ptr(raw_spec).to_str().unwrap() };

Expand Down
10 changes: 5 additions & 5 deletions rust/src/dlmalloc.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// SPDX-License-Identifier: MIT

use crate::c_size_t;
use core::alloc::{GlobalAlloc, Layout};
use core::ffi::c_void;
use core::ffi::{c_int, c_void};
use core::ptr;
use cty::*;

extern "C" {
pub fn malloc(size: size_t) -> *mut c_void;
pub fn realloc_in_place(p: *mut c_void, size: size_t) -> *mut c_void;
pub fn malloc(size: c_size_t) -> *mut c_void;
pub fn realloc_in_place(p: *mut c_void, size: c_size_t) -> *mut c_void;
pub fn free(p: *mut c_void);
pub fn posix_memalign(p: *mut *mut c_void, alignment: size_t, size: size_t) -> c_int;
pub fn posix_memalign(p: *mut *mut c_void, alignment: c_size_t, size: c_size_t) -> c_int;
}

pub struct DLMalloc;
Expand Down
4 changes: 4 additions & 0 deletions rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ pub mod print;

use crate::dlmalloc::DLMalloc;

// This is unstable in core::ffi, let's just declare it ourselves
#[allow(non_camel_case_types)]
type c_size_t = usize;

#[global_allocator]
static GLOBAL: DLMalloc = dlmalloc::DLMalloc;

Expand Down
1 change: 0 additions & 1 deletion rust/vendor/cstr_core
Submodule cstr_core deleted from 35e44d
1 change: 0 additions & 1 deletion rust/vendor/cty
Submodule cty deleted from dcc347
1 change: 0 additions & 1 deletion rust/vendor/memchr
Submodule memchr deleted from 8e1da9

0 comments on commit 396d1d7

Please sign in to comment.