Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use $crate in s! and w! macros #2011

Merged
merged 1 commit into from Sep 8, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 6 additions & 6 deletions crates/libs/windows/src/core/strings/literals.rs
Expand Up @@ -2,7 +2,7 @@
#[macro_export]
macro_rules! s {
($s:literal) => {
::windows::core::PCSTR::from_raw(::std::concat!($s, '\0').as_ptr())
$crate::core::PCSTR::from_raw(::std::concat!($s, '\0').as_ptr())
};
}

Expand All @@ -15,16 +15,16 @@ macro_rules! s {
macro_rules! w {
($s:literal) => {{
const INPUT: &[u8] = $s.as_bytes();
const OUTPUT_LEN: usize = ::windows::core::utf16_len(INPUT) + 1;
const RESULT: ::windows::core::HSTRING = {
const OUTPUT_LEN: usize = $crate::core::utf16_len(INPUT) + 1;
const RESULT: $crate::core::HSTRING = {
if OUTPUT_LEN == 1 {
unsafe { ::std::mem::transmute(::std::ptr::null::<u16>()) }
} else {
const OUTPUT: &[u16; OUTPUT_LEN] = {
let mut buffer = [0; OUTPUT_LEN];
let mut input_pos = 0;
let mut output_pos = 0;
while let Some((mut code_point, new_pos)) = ::windows::core::decode_utf8_char(INPUT, input_pos) {
while let Some((mut code_point, new_pos)) = $crate::core::decode_utf8_char(INPUT, input_pos) {
input_pos = new_pos;
if code_point <= 0xffff {
buffer[output_pos] = code_point as u16;
Expand All @@ -39,9 +39,9 @@ macro_rules! w {
}
&{ buffer }
};
const HEADER: ::windows::core::HSTRING_HEADER = ::windows::core::HSTRING_HEADER { flags: 0x11, len: (OUTPUT_LEN - 1) as u32, padding1: 0, padding2: 0, ptr: OUTPUT.as_ptr() };
const HEADER: $crate::core::HSTRING_HEADER = $crate::core::HSTRING_HEADER { flags: 0x11, len: (OUTPUT_LEN - 1) as u32, padding1: 0, padding2: 0, ptr: OUTPUT.as_ptr() };
// SAFETY: an `HSTRING` is exactly equivalent to a pointer to an `HSTRING_HEADER`
unsafe { ::std::mem::transmute::<&::windows::core::HSTRING_HEADER, ::windows::core::HSTRING>(&HEADER) }
unsafe { ::std::mem::transmute::<&$crate::core::HSTRING_HEADER, $crate::core::HSTRING>(&HEADER) }
}
};
&RESULT
Expand Down