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

rust: Remove empty_static_cstr() in favour of new cstr!() macro.

Isis Lovecruft 6 лет назад
Родитель
Сommit
081e99c16f
2 измененных файлов с 1 добавлено и 41 удалено
  1. 1 2
      src/rust/protover/ffi.rs
  2. 0 39
      src/rust/tor_util/strings.rs

+ 1 - 2
src/rust/protover/ffi.rs

@@ -13,7 +13,6 @@ use protover::*;
 use smartlist::*;
 use tor_allocate::allocate_and_copy_string;
 use tor_util::strings::byte_slice_is_c_like;
-use tor_util::strings::empty_static_cstr;
 
 /// Translate C enums to Rust Proto enums, using the integer value of the C
 /// enum to map to its associated Rust enum
@@ -192,7 +191,7 @@ pub extern "C" fn protover_compute_for_old_tor(version: *const c_char) -> *const
     let supported: &'static CStr;
     let empty: &'static CStr;
 
-    empty = empty_static_cstr();
+    empty = cstr!("");
 
     if version.is_null() {
         return empty.as_ptr();

+ 0 - 39
src/rust/tor_util/strings.rs

@@ -3,8 +3,6 @@
 
 //! Utilities for working with static strings.
 
-use std::ffi::CStr;
-
 /// A byte-array containing a single NUL byte (`b"\0"`).
 pub const NUL_BYTE: &'static [u8] = b"\0";
 
@@ -44,43 +42,6 @@ pub fn byte_slice_is_c_like(bytes: &[u8]) -> bool {
     false
 }
 
-/// Get a static `CStr` containing a single `NUL_BYTE`.
-///
-/// # Examples
-///
-/// When used as follows in a Rust FFI function, which could be called
-/// from C:
-///
-/// ```
-/// # extern crate libc;
-/// # extern crate tor_util;
-/// #
-/// # use tor_util::strings::empty_static_cstr;
-/// use libc::c_char;
-/// use std::ffi::CStr;
-///
-/// pub extern "C" fn give_c_code_an_empty_static_string() -> *const c_char {
-///     let empty: &'static CStr = empty_static_cstr();
-///
-///     empty.as_ptr()
-/// }
-///
-/// # fn main() {
-/// #     give_c_code_an_empty_static_string();
-/// # }
-/// ```
-///
-/// This equates to an "empty" `const char*` static string in C.
-pub fn empty_static_cstr() -> &'static CStr {
-    let empty: &'static CStr;
-
-    unsafe {
-        empty = CStr::from_bytes_with_nul_unchecked(NUL_BYTE);
-    }
-
-    empty
-}
-
 /// Create a `CStr` from a literal byte slice, appending a NUL byte to it first.
 ///
 /// # Warning