Canonicalize some wide string imports

wchar.rs should not import let alone reexport FFI strings.
Stop re-exporting utf32str! because we use L! instead.

In wchar_ffi.rs, stop re-exporting cxx::CxxWString because that hasn't
seen adoption.

I think we should use re-exports only for aliases like "wstr" or for aliases
into internal modules.
So I'd probably remove `pub use wchar_ffi::wcharz_t = crate::ffi::wcharz_t`
as well.
This commit is contained in:
Johannes Altmanninger 2023-03-05 09:24:44 +01:00
parent e6994ea3ac
commit c6756e9324
9 changed files with 19 additions and 21 deletions

View File

@ -5,7 +5,8 @@ use super::shared::{
builtin_print_help, io_streams_t, HelpOnlyCmdOpts, STATUS_CMD_OK, STATUS_INVALID_ARGS, builtin_print_help, io_streams_t, HelpOnlyCmdOpts, STATUS_CMD_OK, STATUS_INVALID_ARGS,
}; };
use crate::ffi::{self, parser_t, Repin}; use crate::ffi::{self, parser_t, Repin};
use crate::wchar_ffi::{wstr, W0String, WCharToFFI}; use crate::wchar::wstr;
use crate::wchar_ffi::{W0String, WCharToFFI};
use crate::wutil::format::printf::sprintf; use crate::wutil::format::printf::sprintf;
#[widestrs] #[widestrs]

View File

@ -1,7 +1,8 @@
use crate::ffi; use crate::ffi;
use crate::wchar::{wstr, WString};
use crate::wchar_ext::WExt; use crate::wchar_ext::WExt;
use crate::wchar_ffi::c_str; use crate::wchar_ffi::c_str;
use crate::wchar_ffi::{wstr, WCharFromFFI, WString}; use crate::wchar_ffi::WCharFromFFI;
use std::os::fd::AsRawFd; use std::os::fd::AsRawFd;
use std::{ffi::c_uint, mem}; use std::{ffi::c_uint, mem};

View File

@ -1,7 +1,8 @@
//! This file supports specifying and applying redirections. //! This file supports specifying and applying redirections.
use crate::wchar::L; use crate::ffi::wcharz_t;
use crate::wchar_ffi::{wcharz_t, WCharToFFI, WString}; use crate::wchar::{WString, L};
use crate::wchar_ffi::WCharToFFI;
use crate::wutil::fish_wcstoi; use crate::wutil::fish_wcstoi;
use cxx::{CxxVector, CxxWString, SharedPtr, UniquePtr}; use cxx::{CxxVector, CxxWString, SharedPtr, UniquePtr};
use libc::{c_int, O_APPEND, O_CREAT, O_EXCL, O_RDONLY, O_TRUNC, O_WRONLY}; use libc::{c_int, O_APPEND, O_CREAT, O_EXCL, O_RDONLY, O_TRUNC, O_WRONLY};

View File

@ -1,6 +1,7 @@
use crate::ffi; use crate::ffi;
use crate::topic_monitor::{generation_t, invalid_generations, topic_monitor_principal, topic_t}; use crate::topic_monitor::{generation_t, invalid_generations, topic_monitor_principal, topic_t};
use crate::wchar_ffi::{c_str, wstr}; use crate::wchar::wstr;
use crate::wchar_ffi::c_str;
use widestring::U32CStr; use widestring::U32CStr;
/// A sigint_detector_t can be used to check if a SIGINT (or SIGHUP) has been delivered. /// A sigint_detector_t can be used to check if a SIGINT (or SIGHUP) has been delivered.

View File

@ -5,8 +5,8 @@ use crate::ffi::{valid_var_name_char, wcharz_t};
use crate::future_feature_flags::{feature_test, FeatureFlag}; use crate::future_feature_flags::{feature_test, FeatureFlag};
use crate::parse_constants::SOURCE_OFFSET_INVALID; use crate::parse_constants::SOURCE_OFFSET_INVALID;
use crate::redirection::RedirectionMode; use crate::redirection::RedirectionMode;
use crate::wchar::{WExt, L}; use crate::wchar::{wstr, WExt, WString, L};
use crate::wchar_ffi::{wchar_t, wstr, WCharFromFFI, WCharToFFI, WString}; use crate::wchar_ffi::{wchar_t, WCharFromFFI, WCharToFFI};
use crate::wutil::wgettext; use crate::wutil::wgettext;
use cxx::{CxxWString, SharedPtr, UniquePtr}; use cxx::{CxxWString, SharedPtr, UniquePtr};
use libc::{c_int, STDIN_FILENO, STDOUT_FILENO}; use libc::{c_int, STDIN_FILENO, STDOUT_FILENO};

View File

@ -4,10 +4,6 @@
//! - wstr: a string slice without a nul terminator. Like `&str` but wide chars. //! - wstr: a string slice without a nul terminator. Like `&str` but wide chars.
//! - WString: an owning string without a nul terminator. Like `String` but wide chars. //! - WString: an owning string without a nul terminator. Like `String` but wide chars.
use crate::ffi;
pub use cxx::CxxWString;
pub use ffi::{wchar_t, wcharz_t};
pub use widestring::utf32str;
pub use widestring::{Utf32Str as wstr, Utf32String as WString}; pub use widestring::{Utf32Str as wstr, Utf32String as WString};
/// Creates a wstr string slice, like the "L" prefix of C++. /// Creates a wstr string slice, like the "L" prefix of C++.

View File

@ -6,13 +6,11 @@
//! - wcharz_t: a "newtyped" pointer to a nul-terminated string, implemented in C++. //! - wcharz_t: a "newtyped" pointer to a nul-terminated string, implemented in C++.
//! This is useful for FFI boundaries, to work around autocxx limitations on pointers. //! This is useful for FFI boundaries, to work around autocxx limitations on pointers.
use crate::ffi; pub use crate::ffi::{wchar_t, wcharz_t};
pub use cxx::CxxWString; use crate::wchar::{wstr, WString};
pub use ffi::{wchar_t, wcharz_t};
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
pub use widestring::u32cstr;
pub use widestring::U32CString as W0String; pub use widestring::U32CString as W0String;
pub use widestring::{u32cstr, utf32str};
pub use widestring::{Utf32Str as wstr, Utf32String as WString};
/// \return the length of a nul-terminated raw string. /// \return the length of a nul-terminated raw string.
pub fn wcslen(str: *const wchar_t) -> usize { pub fn wcslen(str: *const wchar_t) -> usize {
@ -64,7 +62,7 @@ macro_rules! c_str {
/// Convert a wstr to a wcharz_t. /// Convert a wstr to a wcharz_t.
macro_rules! wcharz { macro_rules! wcharz {
($string:expr) => { ($string:expr) => {
crate::wchar::wcharz_t { crate::wchar_ffi::wcharz_t {
str_: crate::wchar_ffi::c_str!($string), str_: crate::wchar_ffi::c_str!($string),
} }
}; };

View File

@ -23,7 +23,7 @@ License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave, not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */ Cambridge, MA 02139, USA. */
use crate::wchar::{utf32str, wstr, WExt}; use crate::wchar::{wstr, WExt, L};
/// Describe how to deal with options that follow non-option ARGV-elements. /// Describe how to deal with options that follow non-option ARGV-elements.
/// ///
@ -344,7 +344,7 @@ impl<'opts, 'args, 'argarray> wgetopter_t<'opts, 'args, 'argarray> {
let temp = match self.shortopts.chars().position(|sc| sc == c) { let temp = match self.shortopts.chars().position(|sc| sc == c) {
Some(pos) => &self.shortopts[pos..], Some(pos) => &self.shortopts[pos..],
None => utf32str!(""), None => L!(""),
}; };
// Increment `woptind' when we start to process its last character. // Increment `woptind' when we start to process its last character.

View File

@ -1,6 +1,6 @@
use crate::ffi; use crate::ffi;
use crate::wchar::{wchar_t, wstr}; use crate::wchar::wstr;
use crate::wchar_ffi::wcslen; use crate::wchar_ffi::{wchar_t, wcslen};
/// Support for wgettext. /// Support for wgettext.