Remove cstr macro

This commit is contained in:
konstin 2019-03-18 11:01:55 +01:00
parent d8dc3a17bd
commit 09883574e5
3 changed files with 4 additions and 13 deletions

View File

@ -279,7 +279,7 @@ impl PyBuffer {
#[inline]
pub fn format(&self) -> &CStr {
if self.0.format.is_null() {
cstr!("B")
CStr::from_bytes_with_nul("B".as_bytes()).unwrap()
} else {
unsafe { CStr::from_ptr(self.0.format) }
}

View File

@ -340,10 +340,10 @@ impl UnicodeDecodeError {
let pos = err.valid_up_to();
UnicodeDecodeError::new_err(
py,
cstr!("utf-8"),
CStr::from_bytes_with_nul("utf-8".as_bytes()).unwrap(),
input,
pos..pos + 1,
cstr!("invalid utf-8"),
CStr::from_bytes_with_nul("invalid utf-8".as_bytes()).unwrap(),
)
}
}

View File

@ -147,19 +147,10 @@ mod ffi2;
#[cfg(Py_3)]
mod ffi3;
pub mod class;
/// Constructs a `&'static CStr` literal.
macro_rules! cstr {
($s: tt) => {
// TODO: verify that $s is a string literal without nuls
unsafe { ::std::ffi::CStr::from_ptr(concat!($s, "\0").as_ptr() as *const _) }
};
}
pub mod buffer;
#[doc(hidden)]
pub mod callback;
pub mod class;
mod conversion;
#[doc(hidden)]
pub mod derive_utils;