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

Provide original encoding for string constants #2101

Merged
merged 5 commits into from
Oct 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 additions & 5 deletions crates/libs/bindgen/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,30 @@ pub fn gen(gen: &Gen, def: Field) -> TokenStream {
let constant_type = gen.reader.constant_type(constant);

if ty == constant_type {
let value = gen.typed_value(&gen.reader.constant_value(constant));
quote! {
#doc
#features
pub const #name: #value;
if ty == Type::String {
let crate_name = gen.crate_name();
if gen.reader.field_is_ansi(def) {
let value = gen.value(&gen.reader.constant_value(constant));
quote! {
#doc
#features
pub const #name: ::#crate_name::core::PCSTR = ::#crate_name::s!(#value);
}
} else {
let value = gen.value(&gen.reader.constant_value(constant));
quote! {
#doc
#features
pub const #name: ::#crate_name::core::PCWSTR = ::#crate_name::w!(#value);
}
}
} else {
let value = gen.typed_value(&gen.reader.constant_value(constant));
quote! {
#doc
#features
pub const #name: #value;
}
}
} else {
let kind = gen.type_default_name(&ty);
Expand Down
2 changes: 1 addition & 1 deletion crates/libs/bindgen/src/gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ impl<'a> Gen<'a> {
tokens
}
}
fn crate_name(&self) -> TokenStream {
pub fn crate_name(&self) -> TokenStream {
if self.sys {
"windows_sys".into()
} else {
Expand Down
12 changes: 12 additions & 0 deletions crates/libs/metadata/src/reader/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,18 @@ impl<'a> Reader<'a> {
fn field_cfg_combine(&'a self, row: Field, enclosing: Option<TypeDef>, cfg: &mut Cfg<'a>) {
self.type_cfg_combine(&self.field_type(row, enclosing), cfg)
}
pub fn field_is_ansi(&self, row: Field) -> bool {
for attribute in self.field_attributes(row) {
if self.attribute_name(attribute) == "NativeEncodingAttribute" {
if let Some((_, Value::String(encoding))) = self.attribute_args(attribute).get(0) {
if encoding == "ansi" {
return true;
}
}
}
}
false
}

//
// GenericParam table queries
Expand Down
6 changes: 3 additions & 3 deletions crates/libs/sys/src/Windows/Win32/Data/HtmlHelp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -528,11 +528,11 @@ pub const STDPROP_USERPROP_BASE: u32 = 65536u32;
#[doc = "*Required features: `\"Win32_Data_HtmlHelp\"`*"]
pub const STDPROP_USERPROP_MAX: u32 = 2147483647u32;
#[doc = "*Required features: `\"Win32_Data_HtmlHelp\"`*"]
pub const SZ_WWDEST_GLOBAL: &str = "GLOBAL";
pub const SZ_WWDEST_GLOBAL: ::windows_sys::core::PCWSTR = ::windows_sys::w!("GLOBAL");
#[doc = "*Required features: `\"Win32_Data_HtmlHelp\"`*"]
pub const SZ_WWDEST_KEY: &str = "KEY";
pub const SZ_WWDEST_KEY: ::windows_sys::core::PCWSTR = ::windows_sys::w!("KEY");
#[doc = "*Required features: `\"Win32_Data_HtmlHelp\"`*"]
pub const SZ_WWDEST_OCC: &str = "OCC";
pub const SZ_WWDEST_OCC: ::windows_sys::core::PCWSTR = ::windows_sys::w!("OCC");
#[doc = "*Required features: `\"Win32_Data_HtmlHelp\"`*"]
pub const TYPE_POINTER: u32 = 1u32;
#[doc = "*Required features: `\"Win32_Data_HtmlHelp\"`*"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,9 @@ pub const DRM_AL_NOUI: u32 = 16u32;
#[doc = "*Required features: `\"Win32_Data_RightsManagement\"`*"]
pub const DRM_AUTO_GENERATE_KEY: u32 = 16u32;
#[doc = "*Required features: `\"Win32_Data_RightsManagement\"`*"]
pub const DRM_DEFAULTGROUPIDTYPE_PASSPORT: &str = "PassportAuthProvider";
pub const DRM_DEFAULTGROUPIDTYPE_PASSPORT: ::windows_sys::core::PCWSTR = ::windows_sys::w!("PassportAuthProvider");
#[doc = "*Required features: `\"Win32_Data_RightsManagement\"`*"]
pub const DRM_DEFAULTGROUPIDTYPE_WINDOWSAUTH: &str = "WindowsAuthProvider";
pub const DRM_DEFAULTGROUPIDTYPE_WINDOWSAUTH: ::windows_sys::core::PCWSTR = ::windows_sys::w!("WindowsAuthProvider");
#[doc = "*Required features: `\"Win32_Data_RightsManagement\"`*"]
pub const DRM_EL_CLIENTLICENSOR: u32 = 128u32;
#[doc = "*Required features: `\"Win32_Data_RightsManagement\"`*"]
Expand Down
2 changes: 1 addition & 1 deletion crates/libs/sys/src/Windows/Win32/Devices/AllJoyn/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1155,7 +1155,7 @@ pub const ALLJOYN_MESSAGE_FLAG_NO_REPLY_EXPECTED: u32 = 1u32;
#[doc = "*Required features: `\"Win32_Devices_AllJoyn\"`*"]
pub const ALLJOYN_MESSAGE_FLAG_SESSIONLESS: u32 = 16u32;
#[doc = "*Required features: `\"Win32_Devices_AllJoyn\"`*"]
pub const ALLJOYN_NAMED_PIPE_CONNECT_SPEC: &str = "npipe:";
pub const ALLJOYN_NAMED_PIPE_CONNECT_SPEC: ::windows_sys::core::PCWSTR = ::windows_sys::w!("npipe:");
#[doc = "*Required features: `\"Win32_Devices_AllJoyn\"`*"]
pub const ALLJOYN_PROP_ACCESS_READ: u8 = 1u8;
#[doc = "*Required features: `\"Win32_Devices_AllJoyn\"`*"]
Expand Down
18 changes: 9 additions & 9 deletions crates/libs/sys/src/Windows/Win32/Devices/Bluetooth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1603,23 +1603,23 @@ pub const STRING_NAME_OFFSET: u32 = 0u32;
#[doc = "*Required features: `\"Win32_Devices_Bluetooth\"`*"]
pub const STRING_PROVIDER_NAME_OFFSET: u32 = 2u32;
#[doc = "*Required features: `\"Win32_Devices_Bluetooth\"`*"]
pub const STR_ADDR_FMT: &str = "(%02x:%02x:%02x:%02x:%02x:%02x)";
pub const STR_ADDR_FMT: ::windows_sys::core::PCWSTR = ::windows_sys::w!("(%02x:%02x:%02x:%02x:%02x:%02x)");
#[doc = "*Required features: `\"Win32_Devices_Bluetooth\"`*"]
pub const STR_ADDR_FMTA: &str = "(%02x:%02x:%02x:%02x:%02x:%02x)";
pub const STR_ADDR_FMTA: ::windows_sys::core::PCSTR = ::windows_sys::s!("(%02x:%02x:%02x:%02x:%02x:%02x)");
#[doc = "*Required features: `\"Win32_Devices_Bluetooth\"`*"]
pub const STR_ADDR_FMTW: &str = "(%02x:%02x:%02x:%02x:%02x:%02x)";
pub const STR_ADDR_FMTW: ::windows_sys::core::PCWSTR = ::windows_sys::w!("(%02x:%02x:%02x:%02x:%02x:%02x)");
#[doc = "*Required features: `\"Win32_Devices_Bluetooth\"`*"]
pub const STR_ADDR_SHORT_FMT: &str = "%04x%08x";
pub const STR_ADDR_SHORT_FMT: ::windows_sys::core::PCWSTR = ::windows_sys::w!("%04x%08x");
#[doc = "*Required features: `\"Win32_Devices_Bluetooth\"`*"]
pub const STR_ADDR_SHORT_FMTA: &str = "%04x%08x";
pub const STR_ADDR_SHORT_FMTA: ::windows_sys::core::PCSTR = ::windows_sys::s!("%04x%08x");
#[doc = "*Required features: `\"Win32_Devices_Bluetooth\"`*"]
pub const STR_ADDR_SHORT_FMTW: &str = "%04x%08x";
pub const STR_ADDR_SHORT_FMTW: ::windows_sys::core::PCWSTR = ::windows_sys::w!("%04x%08x");
#[doc = "*Required features: `\"Win32_Devices_Bluetooth\"`*"]
pub const STR_USBHCI_CLASS_HARDWAREID: &str = "USB\\Class_E0&SubClass_01&Prot_01";
pub const STR_USBHCI_CLASS_HARDWAREID: ::windows_sys::core::PCWSTR = ::windows_sys::w!("USB\\Class_E0&SubClass_01&Prot_01");
#[doc = "*Required features: `\"Win32_Devices_Bluetooth\"`*"]
pub const STR_USBHCI_CLASS_HARDWAREIDA: &str = "USB\\Class_E0&SubClass_01&Prot_01";
pub const STR_USBHCI_CLASS_HARDWAREIDA: ::windows_sys::core::PCSTR = ::windows_sys::s!("USB\\Class_E0&SubClass_01&Prot_01");
#[doc = "*Required features: `\"Win32_Devices_Bluetooth\"`*"]
pub const STR_USBHCI_CLASS_HARDWAREIDW: &str = "USB\\Class_E0&SubClass_01&Prot_01";
pub const STR_USBHCI_CLASS_HARDWAREIDW: ::windows_sys::core::PCWSTR = ::windows_sys::w!("USB\\Class_E0&SubClass_01&Prot_01");
pub const SVCID_BTH_PROVIDER: ::windows_sys::core::GUID = ::windows_sys::core::GUID::from_u128(0x06aa63e0_7d60_41ff_afb2_3ee6d2d9392d);
#[doc = "*Required features: `\"Win32_Devices_Bluetooth\"`*"]
pub const SYNCH_DATA_STORE_CALENDAR: u32 = 3u32;
Expand Down
Loading