mirror of
https://github.com/isar/rusqlite.git
synced 2025-10-30 21:38:57 +08:00
Merge remote-tracking branch 'origin/master' into ptr_as_ptr
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
use smallvec::{smallvec, SmallVec};
|
||||
use std::ffi::{CStr, CString, NulError};
|
||||
|
||||
/// Similar to std::ffi::CString, but avoids heap allocating if the string is
|
||||
/// Similar to `std::ffi::CString`, but avoids heap allocating if the string is
|
||||
/// small enough. Also guarantees it's input is UTF-8 -- used for cases where we
|
||||
/// need to pass a NUL-terminated string to SQLite, and we have a `&str`.
|
||||
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord)]
|
||||
@@ -10,7 +10,7 @@ pub(crate) struct SmallCString(smallvec::SmallVec<[u8; 16]>);
|
||||
impl SmallCString {
|
||||
#[inline]
|
||||
pub fn new(s: &str) -> Result<Self, NulError> {
|
||||
if s.as_bytes().contains(&0u8) {
|
||||
if s.as_bytes().contains(&0_u8) {
|
||||
return Err(Self::fabricate_nul_error(s));
|
||||
}
|
||||
let mut buf = SmallVec::with_capacity(s.len() + 1);
|
||||
@@ -31,7 +31,7 @@ impl SmallCString {
|
||||
/// Get the bytes not including the NUL terminator. E.g. the bytes which
|
||||
/// make up our `str`:
|
||||
/// - `SmallCString::new("foo").as_bytes_without_nul() == b"foo"`
|
||||
/// - `SmallCString::new("foo").as_bytes_with_nul() == b"foo\0"
|
||||
/// - `SmallCString::new("foo").as_bytes_with_nul() == b"foo\0"`
|
||||
#[inline]
|
||||
pub fn as_bytes_without_nul(&self) -> &[u8] {
|
||||
self.debug_checks();
|
||||
|
||||
@@ -38,7 +38,7 @@ pub(crate) struct SqliteMallocString {
|
||||
|
||||
impl SqliteMallocString {
|
||||
/// SAFETY: Caller must be certain that `m` a nul-terminated c string
|
||||
/// allocated by sqlite3_malloc, and that SQLite expects us to free it!
|
||||
/// allocated by `sqlite3_malloc`, and that SQLite expects us to free it!
|
||||
#[inline]
|
||||
pub(crate) unsafe fn from_raw_nonnull(ptr: NonNull<c_char>) -> Self {
|
||||
Self {
|
||||
@@ -48,7 +48,7 @@ impl SqliteMallocString {
|
||||
}
|
||||
|
||||
/// SAFETY: Caller must be certain that `m` a nul-terminated c string
|
||||
/// allocated by sqlite3_malloc, and that SQLite expects us to free it!
|
||||
/// allocated by `sqlite3_malloc`, and that SQLite expects us to free it!
|
||||
#[inline]
|
||||
pub(crate) unsafe fn from_raw(ptr: *mut c_char) -> Option<Self> {
|
||||
NonNull::new(ptr).map(|p| Self::from_raw_nonnull(p))
|
||||
@@ -95,13 +95,13 @@ impl SqliteMallocString {
|
||||
/// If `s` contains internal NULs, we'll replace them with
|
||||
/// `NUL_REPLACE_CHAR`.
|
||||
///
|
||||
/// Except for debug_asserts which may trigger during testing, this function
|
||||
/// Except for `debug_assert`s which may trigger during testing, this function
|
||||
/// never panics. If we hit integer overflow or the allocation fails, we
|
||||
/// call `handle_alloc_error` which aborts the program after calling a
|
||||
/// global hook.
|
||||
///
|
||||
/// This means it's safe to use in extern "C" functions even outside of
|
||||
/// catch_unwind.
|
||||
/// `catch_unwind`.
|
||||
pub(crate) fn from_str(s: &str) -> Self {
|
||||
use std::convert::TryFrom;
|
||||
let s = if s.as_bytes().contains(&0) {
|
||||
|
||||
Reference in New Issue
Block a user