Просмотр исходного кода

Use cffi::MallocAllocator__new() so that
if the signature ever changes, it will be sure to
cause a compile time error rather than runtime.

Caleb James DeLisle 3 лет назад
Родитель
Сommit
79bc6fa901
4 измененных файлов с 30 добавлено и 7 удалено
  1. 21 0
      Cargo.lock
  2. 1 0
      rust/cjdns_sys/cffi.h
  3. 7 0
      rust/cjdns_sys/src/cffi.rs
  4. 1 7
      rust/cjdns_sys/src/interface/wire/message.rs

+ 21 - 0
Cargo.lock

@@ -126,6 +126,7 @@ dependencies = [
  "cbindgen",
  "cc",
  "sodiumoxide",
+ "thiserror",
 ]
 
 [[package]]
@@ -585,6 +586,26 @@ dependencies = [
  "unicode-width",
 ]
 
+[[package]]
+name = "thiserror"
+version = "1.0.22"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0e9ae34b84616eedaaf1e9dd6026dbe00dcafa92aa0c8077cb69df1fcfe5e53e"
+dependencies = [
+ "thiserror-impl",
+]
+
+[[package]]
+name = "thiserror-impl"
+version = "1.0.22"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9ba20f23e85b10754cd195504aebf6a27e2e6cbe28c17778a0c930724628dd56"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
 [[package]]
 name = "thread_local"
 version = "1.0.1"

+ 1 - 0
rust/cjdns_sys/cffi.h

@@ -16,6 +16,7 @@
 // This file is used to generate src/cffi.rs using bindgen
 
 #include "memory/Allocator.h"
+#include "memory/MallocAllocator.h"
 #include "interface/Iface.h"
 #include "interface/test/RustIface_test.h"
 

+ 7 - 0
rust/cjdns_sys/src/cffi.rs

@@ -147,6 +147,13 @@ extern "C" {
         lineNum: ::std::os::raw::c_int,
     ) -> *mut Allocator;
 }
+extern "C" {
+    pub fn MallocAllocator__new(
+        sizeLimit: ::std::os::raw::c_ulong,
+        file: *const ::std::os::raw::c_char,
+        line: ::std::os::raw::c_int,
+    ) -> *mut Allocator;
+}
 #[repr(u32)]
 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
 pub enum Error_e {

+ 1 - 7
rust/cjdns_sys/src/interface/wire/message.rs

@@ -294,16 +294,10 @@ mod tests {
     use super::Message;
 
     mod alloc {
-        use std::os::raw::{c_char, c_int, c_ulong};
-
         use crate::cffi::Allocator;
 
-        extern "C" {
-            pub fn MallocAllocator__new(size_limit: c_ulong, file_name: *const c_char, line_num: c_int) -> *mut Allocator;
-        }
-
         pub(super) fn new_allocator(size_limit: u64) -> *mut Allocator {
-            unsafe { MallocAllocator__new(size_limit, "".as_ptr() as *const i8, 0) }
+            unsafe { crate::cffi::MallocAllocator__new(size_limit, "".as_ptr() as *const i8, 0) }
         }
     }